rb4xx.patch 740 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294
  1. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/ar71xx.c linux-2.6.39/arch/mips/ar71xx/ar71xx.c
  2. --- linux-2.6.39.orig/arch/mips/ar71xx/ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.39/arch/mips/ar71xx/ar71xx.c 2011-08-24 02:41:55.227990426 +0200
  4. @@ -0,0 +1,230 @@
  5. +/*
  6. + * AR71xx SoC routines
  7. + *
  8. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  9. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10. + *
  11. + * This program is free software; you can redistribute it and/or modify it
  12. + * under the terms of the GNU General Public License version 2 as published
  13. + * by the Free Software Foundation.
  14. + */
  15. +
  16. +#include <linux/kernel.h>
  17. +#include <linux/module.h>
  18. +#include <linux/types.h>
  19. +#include <linux/mutex.h>
  20. +#include <linux/spinlock.h>
  21. +
  22. +#include <asm/mach-ar71xx/ar71xx.h>
  23. +
  24. +static DEFINE_MUTEX(ar71xx_flash_mutex);
  25. +static DEFINE_SPINLOCK(ar71xx_device_lock);
  26. +
  27. +void __iomem *ar71xx_ddr_base;
  28. +EXPORT_SYMBOL_GPL(ar71xx_ddr_base);
  29. +
  30. +void __iomem *ar71xx_pll_base;
  31. +EXPORT_SYMBOL_GPL(ar71xx_pll_base);
  32. +
  33. +void __iomem *ar71xx_reset_base;
  34. +EXPORT_SYMBOL_GPL(ar71xx_reset_base);
  35. +
  36. +void __iomem *ar71xx_gpio_base;
  37. +EXPORT_SYMBOL_GPL(ar71xx_gpio_base);
  38. +
  39. +void __iomem *ar71xx_usb_ctrl_base;
  40. +EXPORT_SYMBOL_GPL(ar71xx_usb_ctrl_base);
  41. +
  42. +void ar71xx_device_stop(u32 mask)
  43. +{
  44. + unsigned long flags;
  45. + u32 mask_inv;
  46. + u32 t;
  47. +
  48. + switch (ar71xx_soc) {
  49. + case AR71XX_SOC_AR7130:
  50. + case AR71XX_SOC_AR7141:
  51. + case AR71XX_SOC_AR7161:
  52. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  53. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  54. + ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t | mask);
  55. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  56. + break;
  57. +
  58. + case AR71XX_SOC_AR7240:
  59. + case AR71XX_SOC_AR7241:
  60. + case AR71XX_SOC_AR7242:
  61. + mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
  62. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  63. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  64. + t |= mask;
  65. + t &= ~mask_inv;
  66. + ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
  67. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  68. + break;
  69. +
  70. + case AR71XX_SOC_AR9130:
  71. + case AR71XX_SOC_AR9132:
  72. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  73. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  74. + ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t | mask);
  75. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  76. + break;
  77. +
  78. + case AR71XX_SOC_AR9330:
  79. + case AR71XX_SOC_AR9331:
  80. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  81. + t = ar71xx_reset_rr(AR933X_RESET_REG_RESET_MODULE);
  82. + ar71xx_reset_wr(AR933X_RESET_REG_RESET_MODULE, t | mask);
  83. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  84. + break;
  85. +
  86. + case AR71XX_SOC_AR9341:
  87. + case AR71XX_SOC_AR9342:
  88. + case AR71XX_SOC_AR9344:
  89. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  90. + t = ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE);
  91. + ar71xx_reset_wr(AR934X_RESET_REG_RESET_MODULE, t | mask);
  92. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  93. + break;
  94. +
  95. + default:
  96. + BUG();
  97. + }
  98. +}
  99. +EXPORT_SYMBOL_GPL(ar71xx_device_stop);
  100. +
  101. +void ar71xx_device_start(u32 mask)
  102. +{
  103. + unsigned long flags;
  104. + u32 mask_inv;
  105. + u32 t;
  106. +
  107. + switch (ar71xx_soc) {
  108. + case AR71XX_SOC_AR7130:
  109. + case AR71XX_SOC_AR7141:
  110. + case AR71XX_SOC_AR7161:
  111. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  112. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  113. + ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t & ~mask);
  114. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  115. + break;
  116. +
  117. + case AR71XX_SOC_AR7240:
  118. + case AR71XX_SOC_AR7241:
  119. + case AR71XX_SOC_AR7242:
  120. + mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
  121. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  122. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  123. + t &= ~mask;
  124. + t |= mask_inv;
  125. + ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
  126. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  127. + break;
  128. +
  129. + case AR71XX_SOC_AR9130:
  130. + case AR71XX_SOC_AR9132:
  131. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  132. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  133. + ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t & ~mask);
  134. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  135. + break;
  136. +
  137. + case AR71XX_SOC_AR9330:
  138. + case AR71XX_SOC_AR9331:
  139. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  140. + t = ar71xx_reset_rr(AR933X_RESET_REG_RESET_MODULE);
  141. + ar71xx_reset_wr(AR933X_RESET_REG_RESET_MODULE, t & ~mask);
  142. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  143. + break;
  144. +
  145. + case AR71XX_SOC_AR9341:
  146. + case AR71XX_SOC_AR9342:
  147. + case AR71XX_SOC_AR9344:
  148. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  149. + t = ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE);
  150. + ar71xx_reset_wr(AR934X_RESET_REG_RESET_MODULE, t & ~mask);
  151. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  152. + break;
  153. +
  154. + default:
  155. + BUG();
  156. + }
  157. +}
  158. +EXPORT_SYMBOL_GPL(ar71xx_device_start);
  159. +
  160. +int ar71xx_device_stopped(u32 mask)
  161. +{
  162. + unsigned long flags;
  163. + u32 t;
  164. +
  165. + switch (ar71xx_soc) {
  166. + case AR71XX_SOC_AR7130:
  167. + case AR71XX_SOC_AR7141:
  168. + case AR71XX_SOC_AR7161:
  169. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  170. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  171. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  172. + break;
  173. +
  174. + case AR71XX_SOC_AR7240:
  175. + case AR71XX_SOC_AR7241:
  176. + case AR71XX_SOC_AR7242:
  177. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  178. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  179. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  180. + break;
  181. +
  182. + case AR71XX_SOC_AR9130:
  183. + case AR71XX_SOC_AR9132:
  184. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  185. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  186. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  187. + break;
  188. +
  189. + case AR71XX_SOC_AR9330:
  190. + case AR71XX_SOC_AR9331:
  191. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  192. + t = ar71xx_reset_rr(AR933X_RESET_REG_RESET_MODULE);
  193. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  194. + break;
  195. +
  196. + case AR71XX_SOC_AR9341:
  197. + case AR71XX_SOC_AR9342:
  198. + case AR71XX_SOC_AR9344:
  199. + spin_lock_irqsave(&ar71xx_device_lock, flags);
  200. + t = ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE);
  201. + spin_unlock_irqrestore(&ar71xx_device_lock, flags);
  202. + break;
  203. +
  204. + default:
  205. + BUG();
  206. + }
  207. +
  208. + return ((t & mask) == mask);
  209. +}
  210. +EXPORT_SYMBOL_GPL(ar71xx_device_stopped);
  211. +
  212. +void ar71xx_ddr_flush(u32 reg)
  213. +{
  214. + ar71xx_ddr_wr(reg, 1);
  215. + while ((ar71xx_ddr_rr(reg) & 0x1))
  216. + ;
  217. +
  218. + ar71xx_ddr_wr(reg, 1);
  219. + while ((ar71xx_ddr_rr(reg) & 0x1))
  220. + ;
  221. +}
  222. +EXPORT_SYMBOL_GPL(ar71xx_ddr_flush);
  223. +
  224. +void ar71xx_flash_acquire(void)
  225. +{
  226. + mutex_lock(&ar71xx_flash_mutex);
  227. +}
  228. +EXPORT_SYMBOL_GPL(ar71xx_flash_acquire);
  229. +
  230. +void ar71xx_flash_release(void)
  231. +{
  232. + mutex_unlock(&ar71xx_flash_mutex);
  233. +}
  234. +EXPORT_SYMBOL_GPL(ar71xx_flash_release);
  235. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ap91-pci.c linux-2.6.39/arch/mips/ar71xx/dev-ap91-pci.c
  236. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ap91-pci.c 1970-01-01 01:00:00.000000000 +0100
  237. +++ linux-2.6.39/arch/mips/ar71xx/dev-ap91-pci.c 2011-08-24 02:41:55.277990824 +0200
  238. @@ -0,0 +1,71 @@
  239. +/*
  240. + * Atheros AP91 reference board PCI initialization
  241. + *
  242. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  243. + *
  244. + * This program is free software; you can redistribute it and/or modify it
  245. + * under the terms of the GNU General Public License version 2 as published
  246. + * by the Free Software Foundation.
  247. + */
  248. +
  249. +#include <linux/pci.h>
  250. +#include <linux/ath9k_platform.h>
  251. +#include <linux/delay.h>
  252. +
  253. +#include <asm/mach-ar71xx/ar71xx.h>
  254. +#include <asm/mach-ar71xx/pci.h>
  255. +
  256. +#include "dev-ap91-pci.h"
  257. +#include "pci-ath9k-fixup.h"
  258. +
  259. +static struct ath9k_platform_data ap91_wmac_data = {
  260. + .led_pin = -1,
  261. +};
  262. +static char ap91_wmac_mac[6];
  263. +
  264. +static struct ar71xx_pci_irq ap91_pci_irqs[] __initdata = {
  265. + {
  266. + .slot = 0,
  267. + .pin = 1,
  268. + .irq = AR71XX_PCI_IRQ_DEV0,
  269. + }
  270. +};
  271. +
  272. +static int ap91_pci_plat_dev_init(struct pci_dev *dev)
  273. +{
  274. + switch (PCI_SLOT(dev->devfn)) {
  275. + case 0:
  276. + dev->dev.platform_data = &ap91_wmac_data;
  277. + break;
  278. + }
  279. +
  280. + return 0;
  281. +}
  282. +
  283. +__init void ap91_pci_setup_wmac_led_pin(int pin)
  284. +{
  285. + ap91_wmac_data.led_pin = pin;
  286. +}
  287. +
  288. +__init void ap91_pci_setup_wmac_gpio(u32 mask, u32 val)
  289. +{
  290. + ap91_wmac_data.gpio_mask = mask;
  291. + ap91_wmac_data.gpio_val = val;
  292. +}
  293. +
  294. +void __init ap91_pci_init(u8 *cal_data, u8 *mac_addr)
  295. +{
  296. + if (cal_data)
  297. + memcpy(ap91_wmac_data.eeprom_data, cal_data,
  298. + sizeof(ap91_wmac_data.eeprom_data));
  299. +
  300. + if (mac_addr) {
  301. + memcpy(ap91_wmac_mac, mac_addr, sizeof(ap91_wmac_mac));
  302. + ap91_wmac_data.macaddr = ap91_wmac_mac;
  303. + }
  304. +
  305. + ar71xx_pci_plat_dev_init = ap91_pci_plat_dev_init;
  306. + ar71xx_pci_init(ARRAY_SIZE(ap91_pci_irqs), ap91_pci_irqs);
  307. +
  308. + pci_enable_ath9k_fixup(0, ap91_wmac_data.eeprom_data);
  309. +}
  310. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ap91-pci.h linux-2.6.39/arch/mips/ar71xx/dev-ap91-pci.h
  311. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ap91-pci.h 1970-01-01 01:00:00.000000000 +0100
  312. +++ linux-2.6.39/arch/mips/ar71xx/dev-ap91-pci.h 2011-08-24 02:41:55.287981779 +0200
  313. @@ -0,0 +1,25 @@
  314. +/*
  315. + * Atheros AP91 reference board PCI initialization
  316. + *
  317. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  318. + *
  319. + * This program is free software; you can redistribute it and/or modify it
  320. + * under the terms of the GNU General Public License version 2 as published
  321. + * by the Free Software Foundation.
  322. + */
  323. +
  324. +#ifndef _AR71XX_DEV_AP91_PCI_H
  325. +#define _AR71XX_DEV_AP91_PCI_H
  326. +
  327. +#if defined(CONFIG_AR71XX_DEV_AP91_PCI)
  328. +void ap91_pci_init(u8 *cal_data, u8 *mac_addr) __init;
  329. +void ap91_pci_setup_wmac_led_pin(int pin) __init;
  330. +void ap91_pci_setup_wmac_gpio(u32 mask, u32 val) __init;
  331. +#else
  332. +static inline void ap91_pci_init(u8 *cal_data, u8 *mac_addr) { }
  333. +static inline void ap91_pci_setup_wmac_led_pin(int pin) { }
  334. +static inline void ap91_pci_setup_wmac_gpio(u32 mask, u32 gpio) { }
  335. +#endif
  336. +
  337. +#endif /* _AR71XX_DEV_AP91_PCI_H */
  338. +
  339. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ap94-pci.c linux-2.6.39/arch/mips/ar71xx/dev-ap94-pci.c
  340. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ap94-pci.c 1970-01-01 01:00:00.000000000 +0100
  341. +++ linux-2.6.39/arch/mips/ar71xx/dev-ap94-pci.c 2011-08-24 02:41:55.287981779 +0200
  342. @@ -0,0 +1,109 @@
  343. +/*
  344. + * Atheros AP94 reference board PCI initialization
  345. + *
  346. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  347. + *
  348. + * This program is free software; you can redistribute it and/or modify it
  349. + * under the terms of the GNU General Public License version 2 as published
  350. + * by the Free Software Foundation.
  351. + */
  352. +
  353. +#include <linux/pci.h>
  354. +#include <linux/ath9k_platform.h>
  355. +#include <linux/delay.h>
  356. +
  357. +#include <asm/mach-ar71xx/ar71xx.h>
  358. +#include <asm/mach-ar71xx/pci.h>
  359. +
  360. +#include "dev-ap94-pci.h"
  361. +#include "pci-ath9k-fixup.h"
  362. +
  363. +static struct ath9k_platform_data ap94_wmac0_data = {
  364. + .led_pin = -1,
  365. +};
  366. +static struct ath9k_platform_data ap94_wmac1_data = {
  367. + .led_pin = -1,
  368. +};
  369. +static char ap94_wmac0_mac[6];
  370. +static char ap94_wmac1_mac[6];
  371. +
  372. +static struct ar71xx_pci_irq ap94_pci_irqs[] __initdata = {
  373. + {
  374. + .slot = 0,
  375. + .pin = 1,
  376. + .irq = AR71XX_PCI_IRQ_DEV0,
  377. + }, {
  378. + .slot = 1,
  379. + .pin = 1,
  380. + .irq = AR71XX_PCI_IRQ_DEV1,
  381. + }
  382. +};
  383. +
  384. +static int ap94_pci_plat_dev_init(struct pci_dev *dev)
  385. +{
  386. + switch (PCI_SLOT(dev->devfn)) {
  387. + case 17:
  388. + dev->dev.platform_data = &ap94_wmac0_data;
  389. + break;
  390. +
  391. + case 18:
  392. + dev->dev.platform_data = &ap94_wmac1_data;
  393. + break;
  394. + }
  395. +
  396. + return 0;
  397. +}
  398. +
  399. +__init void ap94_pci_setup_wmac_led_pin(unsigned wmac, int pin)
  400. +{
  401. + switch (wmac) {
  402. + case 0:
  403. + ap94_wmac0_data.led_pin = pin;
  404. + break;
  405. + case 1:
  406. + ap94_wmac1_data.led_pin = pin;
  407. + break;
  408. + }
  409. +}
  410. +
  411. +__init void ap94_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
  412. +{
  413. + switch (wmac) {
  414. + case 0:
  415. + ap94_wmac0_data.gpio_mask = mask;
  416. + ap94_wmac0_data.gpio_val = val;
  417. + break;
  418. + case 1:
  419. + ap94_wmac1_data.gpio_mask = mask;
  420. + ap94_wmac1_data.gpio_val = val;
  421. + break;
  422. + }
  423. +}
  424. +
  425. +void __init ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  426. + u8 *cal_data1, u8 *mac_addr1)
  427. +{
  428. + if (cal_data0)
  429. + memcpy(ap94_wmac0_data.eeprom_data, cal_data0,
  430. + sizeof(ap94_wmac0_data.eeprom_data));
  431. +
  432. + if (cal_data1)
  433. + memcpy(ap94_wmac1_data.eeprom_data, cal_data1,
  434. + sizeof(ap94_wmac1_data.eeprom_data));
  435. +
  436. + if (mac_addr0) {
  437. + memcpy(ap94_wmac0_mac, mac_addr0, sizeof(ap94_wmac0_mac));
  438. + ap94_wmac0_data.macaddr = ap94_wmac0_mac;
  439. + }
  440. +
  441. + if (mac_addr1) {
  442. + memcpy(ap94_wmac1_mac, mac_addr1, sizeof(ap94_wmac1_mac));
  443. + ap94_wmac1_data.macaddr = ap94_wmac1_mac;
  444. + }
  445. +
  446. + ar71xx_pci_plat_dev_init = ap94_pci_plat_dev_init;
  447. + ar71xx_pci_init(ARRAY_SIZE(ap94_pci_irqs), ap94_pci_irqs);
  448. +
  449. + pci_enable_ath9k_fixup(17, ap94_wmac0_data.eeprom_data);
  450. + pci_enable_ath9k_fixup(18, ap94_wmac1_data.eeprom_data);
  451. +}
  452. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ap94-pci.h linux-2.6.39/arch/mips/ar71xx/dev-ap94-pci.h
  453. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ap94-pci.h 1970-01-01 01:00:00.000000000 +0100
  454. +++ linux-2.6.39/arch/mips/ar71xx/dev-ap94-pci.h 2011-08-24 02:41:55.287981779 +0200
  455. @@ -0,0 +1,31 @@
  456. +/*
  457. + * Atheros AP94 reference board PCI initialization
  458. + *
  459. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  460. + *
  461. + * This program is free software; you can redistribute it and/or modify it
  462. + * under the terms of the GNU General Public License version 2 as published
  463. + * by the Free Software Foundation.
  464. + */
  465. +
  466. +#ifndef _AR71XX_DEV_AP94_PCI_H
  467. +#define _AR71XX_DEV_AP94_PCI_H
  468. +
  469. +#if defined(CONFIG_AR71XX_DEV_AP94_PCI)
  470. +void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  471. + u8 *cal_data1, u8 *mac_addr1) __init;
  472. +
  473. +void ap94_pci_setup_wmac_led_pin(unsigned wmac, int pin) __init;
  474. +void ap94_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val) __init;
  475. +
  476. +#else
  477. +static inline void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  478. + u8 *cal_data1, u8 *mac_addr1) {}
  479. +
  480. +static inline void ap94_pci_setup_wmac_led_pin(unsigned wmac, int pin) {}
  481. +static inline void ap94_pci_setup_wmac_gpio(unsigned wmac,
  482. + u32 mask, u32 val) {}
  483. +#endif
  484. +
  485. +#endif /* _AR71XX_DEV_AP94_PCI_H */
  486. +
  487. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ar9xxx-wmac.c linux-2.6.39/arch/mips/ar71xx/dev-ar9xxx-wmac.c
  488. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ar9xxx-wmac.c 1970-01-01 01:00:00.000000000 +0100
  489. +++ linux-2.6.39/arch/mips/ar71xx/dev-ar9xxx-wmac.c 2011-08-24 02:41:55.287981779 +0200
  490. @@ -0,0 +1,154 @@
  491. +/*
  492. + * Atheros AR9XXX SoCs built-in WMAC device support
  493. + *
  494. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  495. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  496. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  497. + *
  498. + * Parts of this file are based on Atheros 2.6.15/2.6.31 BSP
  499. + *
  500. + * This program is free software; you can redistribute it and/or modify it
  501. + * under the terms of the GNU General Public License version 2 as published
  502. + * by the Free Software Foundation.
  503. + */
  504. +
  505. +#include <linux/kernel.h>
  506. +#include <linux/init.h>
  507. +#include <linux/delay.h>
  508. +#include <linux/etherdevice.h>
  509. +#include <linux/platform_device.h>
  510. +#include <linux/ath9k_platform.h>
  511. +
  512. +#include <asm/mach-ar71xx/ar71xx.h>
  513. +
  514. +#include "dev-ar9xxx-wmac.h"
  515. +
  516. +#define MHZ_25 (25 * 1000 * 1000)
  517. +
  518. +static struct ath9k_platform_data ar9xxx_wmac_data = {
  519. + .led_pin = -1,
  520. +};
  521. +static char ar9xxx_wmac_mac[6];
  522. +
  523. +static struct resource ar9xxx_wmac_resources[] = {
  524. + {
  525. + /* .start and .end fields are filled dynamically */
  526. + .flags = IORESOURCE_MEM,
  527. + }, {
  528. + .start = AR71XX_CPU_IRQ_IP2,
  529. + .end = AR71XX_CPU_IRQ_IP2,
  530. + .flags = IORESOURCE_IRQ,
  531. + },
  532. +};
  533. +
  534. +static struct platform_device ar9xxx_wmac_device = {
  535. + .name = "ath9k",
  536. + .id = -1,
  537. + .resource = ar9xxx_wmac_resources,
  538. + .num_resources = ARRAY_SIZE(ar9xxx_wmac_resources),
  539. + .dev = {
  540. + .platform_data = &ar9xxx_wmac_data,
  541. + },
  542. +};
  543. +
  544. +static void ar913x_wmac_init(void)
  545. +{
  546. + ar71xx_device_stop(RESET_MODULE_AMBA2WMAC);
  547. + mdelay(10);
  548. +
  549. + ar71xx_device_start(RESET_MODULE_AMBA2WMAC);
  550. + mdelay(10);
  551. +
  552. + ar9xxx_wmac_resources[0].start = AR91XX_WMAC_BASE;
  553. + ar9xxx_wmac_resources[0].end = AR91XX_WMAC_BASE + AR91XX_WMAC_SIZE - 1;
  554. +}
  555. +
  556. +static int ar933x_r1_get_wmac_revision(void)
  557. +{
  558. + return ar71xx_soc_rev;
  559. +}
  560. +
  561. +static int ar933x_wmac_reset(void)
  562. +{
  563. + unsigned retries = 0;
  564. +
  565. + ar71xx_device_stop(AR933X_RESET_WMAC);
  566. + ar71xx_device_start(AR933X_RESET_WMAC);
  567. +
  568. + while (1) {
  569. + u32 bootstrap;
  570. +
  571. + bootstrap = ar71xx_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  572. + if ((bootstrap & AR933X_BOOTSTRAP_EEPBUSY) == 0)
  573. + return 0;
  574. +
  575. + if (retries > 20)
  576. + break;
  577. +
  578. + udelay(10000);
  579. + retries++;
  580. + }
  581. +
  582. + pr_err("ar93xx: WMAC reset timed out");
  583. + return -ETIMEDOUT;
  584. +}
  585. +
  586. +static void ar933x_wmac_init(void)
  587. +{
  588. + ar9xxx_wmac_device.name = "ar933x_wmac";
  589. + ar9xxx_wmac_resources[0].start = AR933X_WMAC_BASE;
  590. + ar9xxx_wmac_resources[0].end = AR933X_WMAC_BASE + AR933X_WMAC_SIZE - 1;
  591. + if (ar71xx_ref_freq == MHZ_25)
  592. + ar9xxx_wmac_data.is_clk_25mhz = true;
  593. +
  594. + if (ar71xx_soc_rev == 1)
  595. + ar9xxx_wmac_data.get_mac_revision = ar933x_r1_get_wmac_revision;
  596. +
  597. + ar9xxx_wmac_data.external_reset = ar933x_wmac_reset;
  598. +
  599. + ar933x_wmac_reset();
  600. +}
  601. +
  602. +static void ar934x_wmac_init(void)
  603. +{
  604. + ar9xxx_wmac_device.name = "ar934x_wmac";
  605. + ar9xxx_wmac_resources[0].start = AR934X_WMAC_BASE;
  606. + ar9xxx_wmac_resources[0].end = AR934X_WMAC_BASE + AR934X_WMAC_SIZE - 1;
  607. + if (ar71xx_ref_freq == MHZ_25)
  608. + ar9xxx_wmac_data.is_clk_25mhz = true;
  609. +}
  610. +
  611. +void __init ar9xxx_add_device_wmac(u8 *cal_data, u8 *mac_addr)
  612. +{
  613. + switch (ar71xx_soc) {
  614. + case AR71XX_SOC_AR9130:
  615. + case AR71XX_SOC_AR9132:
  616. + ar913x_wmac_init();
  617. + break;
  618. +
  619. + case AR71XX_SOC_AR9330:
  620. + case AR71XX_SOC_AR9331:
  621. + ar933x_wmac_init();
  622. + break;
  623. +
  624. + case AR71XX_SOC_AR9341:
  625. + case AR71XX_SOC_AR9342:
  626. + case AR71XX_SOC_AR9344:
  627. + ar934x_wmac_init();
  628. + break;
  629. +
  630. + default:
  631. + BUG();
  632. + }
  633. +
  634. + if (cal_data)
  635. + memcpy(ar9xxx_wmac_data.eeprom_data, cal_data,
  636. + sizeof(ar9xxx_wmac_data.eeprom_data));
  637. +
  638. + if (mac_addr) {
  639. + memcpy(ar9xxx_wmac_mac, mac_addr, sizeof(ar9xxx_wmac_mac));
  640. + ar9xxx_wmac_data.macaddr = ar9xxx_wmac_mac;
  641. + }
  642. +
  643. + platform_device_register(&ar9xxx_wmac_device);
  644. +}
  645. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-ar9xxx-wmac.h linux-2.6.39/arch/mips/ar71xx/dev-ar9xxx-wmac.h
  646. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-ar9xxx-wmac.h 1970-01-01 01:00:00.000000000 +0100
  647. +++ linux-2.6.39/arch/mips/ar71xx/dev-ar9xxx-wmac.h 2011-08-24 02:41:55.297981663 +0200
  648. @@ -0,0 +1,20 @@
  649. +/*
  650. + * Atheros AR9XXX SoCs built-in WMAC device support
  651. + *
  652. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  653. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  654. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  655. + *
  656. + * Parts of this file are based on Atheros 2.6.15/2.6.31 BSP
  657. + *
  658. + * This program is free software; you can redistribute it and/or modify it
  659. + * under the terms of the GNU General Public License version 2 as published
  660. + * by the Free Software Foundation.
  661. + */
  662. +
  663. +#ifndef _AR71XX_DEV_AR9XXX_WMAC_H
  664. +#define _AR71XX_DEV_AR9XXX_WMAC_H
  665. +
  666. +void ar9xxx_add_device_wmac(u8 *cal_data, u8 *mac_addr) __init;
  667. +
  668. +#endif /* _AR71XX_DEV_AR9XXX_WMAC_H */
  669. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-db120-pci.c linux-2.6.39/arch/mips/ar71xx/dev-db120-pci.c
  670. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-db120-pci.c 1970-01-01 01:00:00.000000000 +0100
  671. +++ linux-2.6.39/arch/mips/ar71xx/dev-db120-pci.c 2011-08-24 02:41:55.317990461 +0200
  672. @@ -0,0 +1,31 @@
  673. +/*
  674. + * Atheros db120 reference board PCI initialization
  675. + *
  676. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  677. + *
  678. + * Parts of this file are based on Atheros linux 2.6.31 BSP
  679. + *
  680. + * This program is free software; you can redistribute it and/or modify it
  681. + * under the terms of the GNU General Public License version 2 as published
  682. + * by the Free Software Foundation.
  683. + */
  684. +
  685. +#include <linux/pci.h>
  686. +
  687. +#include <asm/mach-ar71xx/ar71xx.h>
  688. +#include <asm/mach-ar71xx/pci.h>
  689. +
  690. +#include "dev-db120-pci.h"
  691. +
  692. +static struct ar71xx_pci_irq db120_pci_irqs[] __initdata = {
  693. + {
  694. + .slot = 0,
  695. + .pin = 1,
  696. + .irq = AR71XX_PCI_IRQ_DEV0,
  697. + }
  698. +};
  699. +
  700. +void __init db120_pci_init(void)
  701. +{
  702. + ar71xx_pci_init(ARRAY_SIZE(db120_pci_irqs), db120_pci_irqs);
  703. +}
  704. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-db120-pci.h linux-2.6.39/arch/mips/ar71xx/dev-db120-pci.h
  705. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-db120-pci.h 1970-01-01 01:00:00.000000000 +0100
  706. +++ linux-2.6.39/arch/mips/ar71xx/dev-db120-pci.h 2011-08-24 02:41:55.327990934 +0200
  707. @@ -0,0 +1,22 @@
  708. +/*
  709. + * Atheros DB120 reference board PCI initialization
  710. + *
  711. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  712. + *
  713. + * Parts of this file are based on Atheros linux 2.6.31 BSP
  714. + *
  715. + * This program is free software; you can redistribute it and/or modify it
  716. + * under the terms of the GNU General Public License version 2 as published
  717. + * by the Free Software Foundation.
  718. + */
  719. +
  720. +#ifndef _AR71XX_DEV_DB120_PCI_H
  721. +#define _AR71XX_DEV_DB120_PCI_H
  722. +
  723. +#if defined(CONFIG_AR71XX_DEV_DB120_PCI)
  724. +void db120_pci_init(void);
  725. +#else
  726. +static inline void db120_pci_init(void) { }
  727. +#endif
  728. +
  729. +#endif /* _AR71XX_DEV_DB120_PCI_H */
  730. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-dsa.c linux-2.6.39/arch/mips/ar71xx/dev-dsa.c
  731. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-dsa.c 1970-01-01 01:00:00.000000000 +0100
  732. +++ linux-2.6.39/arch/mips/ar71xx/dev-dsa.c 2011-08-24 02:41:55.337990441 +0200
  733. @@ -0,0 +1,50 @@
  734. +/*
  735. + * Atheros AR71xx DSA switch device support
  736. + *
  737. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  738. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  739. + *
  740. + * This program is free software; you can redistribute it and/or modify it
  741. + * under the terms of the GNU General Public License version 2 as published
  742. + * by the Free Software Foundation.
  743. + */
  744. +
  745. +#include <linux/init.h>
  746. +#include <linux/platform_device.h>
  747. +
  748. +#include <asm/mach-ar71xx/ar71xx.h>
  749. +
  750. +#include "devices.h"
  751. +#include "dev-dsa.h"
  752. +
  753. +static struct platform_device ar71xx_dsa_switch_device = {
  754. + .name = "dsa",
  755. + .id = 0,
  756. +};
  757. +
  758. +void __init ar71xx_add_device_dsa(unsigned int id,
  759. + struct dsa_platform_data *d)
  760. +{
  761. + int i;
  762. +
  763. + switch (id) {
  764. + case 0:
  765. + d->netdev = &ar71xx_eth0_device.dev;
  766. + break;
  767. + case 1:
  768. + d->netdev = &ar71xx_eth1_device.dev;
  769. + break;
  770. + default:
  771. + printk(KERN_ERR
  772. + "ar71xx: invalid ethernet id %d for DSA switch\n",
  773. + id);
  774. + return;
  775. + }
  776. +
  777. + for (i = 0; i < d->nr_chips; i++)
  778. + d->chip[i].mii_bus = &ar71xx_mdio_device.dev;
  779. +
  780. + ar71xx_dsa_switch_device.dev.platform_data = d;
  781. +
  782. + platform_device_register(&ar71xx_dsa_switch_device);
  783. +}
  784. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-dsa.h linux-2.6.39/arch/mips/ar71xx/dev-dsa.h
  785. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-dsa.h 1970-01-01 01:00:00.000000000 +0100
  786. +++ linux-2.6.39/arch/mips/ar71xx/dev-dsa.h 2011-08-24 02:41:55.347990727 +0200
  787. @@ -0,0 +1,20 @@
  788. +/*
  789. + * Atheros AR71xx DSA switch device support
  790. + *
  791. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  792. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  793. + *
  794. + * This program is free software; you can redistribute it and/or modify it
  795. + * under the terms of the GNU General Public License version 2 as published
  796. + * by the Free Software Foundation.
  797. + */
  798. +
  799. +#ifndef _AR71XX_DEV_DSA_H
  800. +#define _AR71XX_DEV_DSA_H
  801. +
  802. +#include <net/dsa.h>
  803. +
  804. +void ar71xx_add_device_dsa(unsigned int id,
  805. + struct dsa_platform_data *d) __init;
  806. +
  807. +#endif /* _AR71XX_DEV_DSA_H */
  808. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-gpio-buttons.c linux-2.6.39/arch/mips/ar71xx/dev-gpio-buttons.c
  809. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-gpio-buttons.c 1970-01-01 01:00:00.000000000 +0100
  810. +++ linux-2.6.39/arch/mips/ar71xx/dev-gpio-buttons.c 2011-08-24 02:41:55.347990727 +0200
  811. @@ -0,0 +1,58 @@
  812. +/*
  813. + * Atheros AR71xx GPIO button support
  814. + *
  815. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  816. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  817. + *
  818. + * This program is free software; you can redistribute it and/or modify it
  819. + * under the terms of the GNU General Public License version 2 as published
  820. + * by the Free Software Foundation.
  821. + */
  822. +
  823. +#include "linux/init.h"
  824. +#include "linux/slab.h"
  825. +#include <linux/platform_device.h>
  826. +
  827. +#include "dev-gpio-buttons.h"
  828. +
  829. +void __init ar71xx_register_gpio_keys_polled(int id,
  830. + unsigned poll_interval,
  831. + unsigned nbuttons,
  832. + struct gpio_keys_button *buttons)
  833. +{
  834. + struct platform_device *pdev;
  835. + struct gpio_keys_platform_data pdata;
  836. + struct gpio_keys_button *p;
  837. + int err;
  838. +
  839. + p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
  840. + if (!p)
  841. + return;
  842. +
  843. + memcpy(p, buttons, nbuttons * sizeof(*p));
  844. +
  845. + pdev = platform_device_alloc("gpio-keys-polled", id);
  846. + if (!pdev)
  847. + goto err_free_buttons;
  848. +
  849. + memset(&pdata, 0, sizeof(pdata));
  850. + pdata.poll_interval = poll_interval;
  851. + pdata.nbuttons = nbuttons;
  852. + pdata.buttons = p;
  853. +
  854. + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  855. + if (err)
  856. + goto err_put_pdev;
  857. +
  858. + err = platform_device_add(pdev);
  859. + if (err)
  860. + goto err_put_pdev;
  861. +
  862. + return;
  863. +
  864. +err_put_pdev:
  865. + platform_device_put(pdev);
  866. +
  867. +err_free_buttons:
  868. + kfree(p);
  869. +}
  870. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-gpio-buttons.h linux-2.6.39/arch/mips/ar71xx/dev-gpio-buttons.h
  871. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-gpio-buttons.h 1970-01-01 01:00:00.000000000 +0100
  872. +++ linux-2.6.39/arch/mips/ar71xx/dev-gpio-buttons.h 2011-08-24 02:41:55.347990727 +0200
  873. @@ -0,0 +1,23 @@
  874. +/*
  875. + * Atheros AR71xx GPIO button support
  876. + *
  877. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  878. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  879. + *
  880. + * This program is free software; you can redistribute it and/or modify it
  881. + * under the terms of the GNU General Public License version 2 as published
  882. + * by the Free Software Foundation.
  883. + */
  884. +
  885. +#ifndef _AR71XX_DEV_GPIO_BUTTONS_H
  886. +#define _AR71XX_DEV_GPIO_BUTTONS_H
  887. +
  888. +#include <linux/input.h>
  889. +#include <linux/gpio_keys.h>
  890. +
  891. +void ar71xx_register_gpio_keys_polled(int id,
  892. + unsigned poll_interval,
  893. + unsigned nbuttons,
  894. + struct gpio_keys_button *buttons);
  895. +
  896. +#endif /* _AR71XX_DEV_GPIO_BUTTONS_H */
  897. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/devices.c linux-2.6.39/arch/mips/ar71xx/devices.c
  898. --- linux-2.6.39.orig/arch/mips/ar71xx/devices.c 1970-01-01 01:00:00.000000000 +0100
  899. +++ linux-2.6.39/arch/mips/ar71xx/devices.c 2011-08-24 02:41:55.347990727 +0200
  900. @@ -0,0 +1,765 @@
  901. +/*
  902. + * Atheros AR71xx SoC platform devices
  903. + *
  904. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  905. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  906. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  907. + *
  908. + * Parts of this file are based on Atheros 2.6.15 BSP
  909. + * Parts of this file are based on Atheros 2.6.31 BSP
  910. + *
  911. + * This program is free software; you can redistribute it and/or modify it
  912. + * under the terms of the GNU General Public License version 2 as published
  913. + * by the Free Software Foundation.
  914. + */
  915. +
  916. +#include <linux/kernel.h>
  917. +#include <linux/init.h>
  918. +#include <linux/delay.h>
  919. +#include <linux/etherdevice.h>
  920. +#include <linux/platform_device.h>
  921. +#include <linux/serial_8250.h>
  922. +
  923. +#include <asm/mach-ar71xx/ar71xx.h>
  924. +#include <asm/mach-ar71xx/ar933x_uart_platform.h>
  925. +
  926. +#include "devices.h"
  927. +
  928. +unsigned char ar71xx_mac_base[ETH_ALEN] __initdata;
  929. +
  930. +static struct resource ar71xx_uart_resources[] = {
  931. + {
  932. + .start = AR71XX_UART_BASE,
  933. + .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
  934. + .flags = IORESOURCE_MEM,
  935. + },
  936. +};
  937. +
  938. +#define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
  939. +static struct plat_serial8250_port ar71xx_uart_data[] = {
  940. + {
  941. + .mapbase = AR71XX_UART_BASE,
  942. + .irq = AR71XX_MISC_IRQ_UART,
  943. + .flags = AR71XX_UART_FLAGS,
  944. + .iotype = UPIO_MEM32,
  945. + .regshift = 2,
  946. + }, {
  947. + /* terminating entry */
  948. + }
  949. +};
  950. +
  951. +static struct platform_device ar71xx_uart_device = {
  952. + .name = "serial8250",
  953. + .id = PLAT8250_DEV_PLATFORM,
  954. + .resource = ar71xx_uart_resources,
  955. + .num_resources = ARRAY_SIZE(ar71xx_uart_resources),
  956. + .dev = {
  957. + .platform_data = ar71xx_uart_data
  958. + },
  959. +};
  960. +
  961. +static struct resource ar933x_uart_resources[] = {
  962. + {
  963. + .start = AR933X_UART_BASE,
  964. + .end = AR933X_UART_BASE + AR71XX_UART_SIZE - 1,
  965. + .flags = IORESOURCE_MEM,
  966. + },
  967. + {
  968. + .start = AR71XX_MISC_IRQ_UART,
  969. + .end = AR71XX_MISC_IRQ_UART,
  970. + .flags = IORESOURCE_IRQ,
  971. + },
  972. +};
  973. +
  974. +static struct ar933x_uart_platform_data ar933x_uart_data;
  975. +static struct platform_device ar933x_uart_device = {
  976. + .name = "ar933x-uart",
  977. + .id = -1,
  978. + .resource = ar933x_uart_resources,
  979. + .num_resources = ARRAY_SIZE(ar933x_uart_resources),
  980. + .dev = {
  981. + .platform_data = &ar933x_uart_data,
  982. + },
  983. +};
  984. +
  985. +void __init ar71xx_add_device_uart(void)
  986. +{
  987. + struct platform_device *pdev;
  988. +
  989. + switch (ar71xx_soc) {
  990. + case AR71XX_SOC_AR7130:
  991. + case AR71XX_SOC_AR7141:
  992. + case AR71XX_SOC_AR7161:
  993. + case AR71XX_SOC_AR7240:
  994. + case AR71XX_SOC_AR7241:
  995. + case AR71XX_SOC_AR7242:
  996. + case AR71XX_SOC_AR9130:
  997. + case AR71XX_SOC_AR9132:
  998. + pdev = &ar71xx_uart_device;
  999. + ar71xx_uart_data[0].uartclk = ar71xx_ahb_freq;
  1000. + break;
  1001. +
  1002. + case AR71XX_SOC_AR9330:
  1003. + case AR71XX_SOC_AR9331:
  1004. + pdev = &ar933x_uart_device;
  1005. + ar933x_uart_data.uartclk = ar71xx_ref_freq;
  1006. + break;
  1007. +
  1008. + case AR71XX_SOC_AR9341:
  1009. + case AR71XX_SOC_AR9342:
  1010. + case AR71XX_SOC_AR9344:
  1011. + pdev = &ar71xx_uart_device;
  1012. + ar71xx_uart_data[0].uartclk = ar71xx_ref_freq;
  1013. + break;
  1014. +
  1015. + default:
  1016. + BUG();
  1017. + }
  1018. +
  1019. + platform_device_register(pdev);
  1020. +}
  1021. +
  1022. +static struct resource ar71xx_mdio_resources[] = {
  1023. + {
  1024. + .name = "mdio_base",
  1025. + .flags = IORESOURCE_MEM,
  1026. + .start = AR71XX_GE0_BASE,
  1027. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  1028. + }
  1029. +};
  1030. +
  1031. +static struct ag71xx_mdio_platform_data ar71xx_mdio_data;
  1032. +
  1033. +struct platform_device ar71xx_mdio_device = {
  1034. + .name = "ag71xx-mdio",
  1035. + .id = -1,
  1036. + .resource = ar71xx_mdio_resources,
  1037. + .num_resources = ARRAY_SIZE(ar71xx_mdio_resources),
  1038. + .dev = {
  1039. + .platform_data = &ar71xx_mdio_data,
  1040. + },
  1041. +};
  1042. +
  1043. +static void ar71xx_set_pll(u32 cfg_reg, u32 pll_reg, u32 pll_val, u32 shift)
  1044. +{
  1045. + void __iomem *base;
  1046. + u32 t;
  1047. +
  1048. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  1049. +
  1050. + t = __raw_readl(base + cfg_reg);
  1051. + t &= ~(3 << shift);
  1052. + t |= (2 << shift);
  1053. + __raw_writel(t, base + cfg_reg);
  1054. + udelay(100);
  1055. +
  1056. + __raw_writel(pll_val, base + pll_reg);
  1057. +
  1058. + t |= (3 << shift);
  1059. + __raw_writel(t, base + cfg_reg);
  1060. + udelay(100);
  1061. +
  1062. + t &= ~(3 << shift);
  1063. + __raw_writel(t, base + cfg_reg);
  1064. + udelay(100);
  1065. +
  1066. + printk(KERN_DEBUG "ar71xx: pll_reg %#x: %#x\n",
  1067. + (unsigned int)(base + pll_reg), __raw_readl(base + pll_reg));
  1068. +
  1069. + iounmap(base);
  1070. +}
  1071. +
  1072. +void __init ar71xx_add_device_mdio(u32 phy_mask)
  1073. +{
  1074. + switch (ar71xx_soc) {
  1075. + case AR71XX_SOC_AR7240:
  1076. + ar71xx_mdio_data.is_ar7240 = 1;
  1077. + break;
  1078. + case AR71XX_SOC_AR7241:
  1079. + ar71xx_mdio_data.is_ar7240 = 1;
  1080. + ar71xx_mdio_resources[0].start = AR71XX_GE1_BASE;
  1081. + ar71xx_mdio_resources[0].end = AR71XX_GE1_BASE + 0x200 - 1;
  1082. + break;
  1083. + case AR71XX_SOC_AR7242:
  1084. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG,
  1085. + AR7242_PLL_REG_ETH0_INT_CLOCK, 0x62000000,
  1086. + AR71XX_ETH0_PLL_SHIFT);
  1087. + break;
  1088. + case AR71XX_SOC_AR9330:
  1089. + case AR71XX_SOC_AR9331:
  1090. + ar71xx_mdio_data.is_ar7240 = 1;
  1091. + ar71xx_mdio_resources[0].start = AR71XX_GE1_BASE;
  1092. + ar71xx_mdio_resources[0].end = AR71XX_GE1_BASE + 0x200 - 1;
  1093. + break;
  1094. + default:
  1095. + break;
  1096. + }
  1097. +
  1098. + ar71xx_mdio_data.phy_mask = phy_mask;
  1099. +
  1100. + platform_device_register(&ar71xx_mdio_device);
  1101. +}
  1102. +
  1103. +struct ar71xx_eth_pll_data ar71xx_eth0_pll_data;
  1104. +struct ar71xx_eth_pll_data ar71xx_eth1_pll_data;
  1105. +
  1106. +static u32 ar71xx_get_eth_pll(unsigned int mac, int speed)
  1107. +{
  1108. + struct ar71xx_eth_pll_data *pll_data;
  1109. + u32 pll_val;
  1110. +
  1111. + switch (mac) {
  1112. + case 0:
  1113. + pll_data = &ar71xx_eth0_pll_data;
  1114. + break;
  1115. + case 1:
  1116. + pll_data = &ar71xx_eth1_pll_data;
  1117. + break;
  1118. + default:
  1119. + BUG();
  1120. + }
  1121. +
  1122. + switch (speed) {
  1123. + case SPEED_10:
  1124. + pll_val = pll_data->pll_10;
  1125. + break;
  1126. + case SPEED_100:
  1127. + pll_val = pll_data->pll_100;
  1128. + break;
  1129. + case SPEED_1000:
  1130. + pll_val = pll_data->pll_1000;
  1131. + break;
  1132. + default:
  1133. + BUG();
  1134. + }
  1135. +
  1136. + return pll_val;
  1137. +}
  1138. +
  1139. +static void ar71xx_set_pll_ge0(int speed)
  1140. +{
  1141. + u32 val = ar71xx_get_eth_pll(0, speed);
  1142. +
  1143. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH0_INT_CLOCK,
  1144. + val, AR71XX_ETH0_PLL_SHIFT);
  1145. +}
  1146. +
  1147. +static void ar71xx_set_pll_ge1(int speed)
  1148. +{
  1149. + u32 val = ar71xx_get_eth_pll(1, speed);
  1150. +
  1151. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH1_INT_CLOCK,
  1152. + val, AR71XX_ETH1_PLL_SHIFT);
  1153. +}
  1154. +
  1155. +static void ar724x_set_pll_ge0(int speed)
  1156. +{
  1157. + /* TODO */
  1158. +}
  1159. +
  1160. +static void ar724x_set_pll_ge1(int speed)
  1161. +{
  1162. + /* TODO */
  1163. +}
  1164. +
  1165. +static void ar7242_set_pll_ge0(int speed)
  1166. +{
  1167. + u32 val = ar71xx_get_eth_pll(0, speed);
  1168. +
  1169. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR7242_PLL_REG_ETH0_INT_CLOCK,
  1170. + val, AR71XX_ETH0_PLL_SHIFT);
  1171. +}
  1172. +
  1173. +static void ar91xx_set_pll_ge0(int speed)
  1174. +{
  1175. + u32 val = ar71xx_get_eth_pll(0, speed);
  1176. +
  1177. + ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG, AR91XX_PLL_REG_ETH0_INT_CLOCK,
  1178. + val, AR91XX_ETH0_PLL_SHIFT);
  1179. +}
  1180. +
  1181. +static void ar91xx_set_pll_ge1(int speed)
  1182. +{
  1183. + u32 val = ar71xx_get_eth_pll(1, speed);
  1184. +
  1185. + ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG, AR91XX_PLL_REG_ETH1_INT_CLOCK,
  1186. + val, AR91XX_ETH1_PLL_SHIFT);
  1187. +}
  1188. +
  1189. +static void ar933x_set_pll_ge0(int speed)
  1190. +{
  1191. + /* TODO */
  1192. +}
  1193. +
  1194. +static void ar933x_set_pll_ge1(int speed)
  1195. +{
  1196. + /* TODO */
  1197. +}
  1198. +
  1199. +static void ar71xx_ddr_flush_ge0(void)
  1200. +{
  1201. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE0);
  1202. +}
  1203. +
  1204. +static void ar71xx_ddr_flush_ge1(void)
  1205. +{
  1206. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE1);
  1207. +}
  1208. +
  1209. +static void ar724x_ddr_flush_ge0(void)
  1210. +{
  1211. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE0);
  1212. +}
  1213. +
  1214. +static void ar724x_ddr_flush_ge1(void)
  1215. +{
  1216. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE1);
  1217. +}
  1218. +
  1219. +static void ar91xx_ddr_flush_ge0(void)
  1220. +{
  1221. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0);
  1222. +}
  1223. +
  1224. +static void ar91xx_ddr_flush_ge1(void)
  1225. +{
  1226. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1);
  1227. +}
  1228. +
  1229. +static void ar933x_ddr_flush_ge0(void)
  1230. +{
  1231. + ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE0);
  1232. +}
  1233. +
  1234. +static void ar933x_ddr_flush_ge1(void)
  1235. +{
  1236. + ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_GE1);
  1237. +}
  1238. +
  1239. +static struct resource ar71xx_eth0_resources[] = {
  1240. + {
  1241. + .name = "mac_base",
  1242. + .flags = IORESOURCE_MEM,
  1243. + .start = AR71XX_GE0_BASE,
  1244. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  1245. + }, {
  1246. + .name = "mii_ctrl",
  1247. + .flags = IORESOURCE_MEM,
  1248. + .start = AR71XX_MII_BASE + MII_REG_MII0_CTRL,
  1249. + .end = AR71XX_MII_BASE + MII_REG_MII0_CTRL + 3,
  1250. + }, {
  1251. + .name = "mac_irq",
  1252. + .flags = IORESOURCE_IRQ,
  1253. + .start = AR71XX_CPU_IRQ_GE0,
  1254. + .end = AR71XX_CPU_IRQ_GE0,
  1255. + },
  1256. +};
  1257. +
  1258. +struct ag71xx_platform_data ar71xx_eth0_data = {
  1259. + .reset_bit = RESET_MODULE_GE0_MAC,
  1260. +};
  1261. +
  1262. +struct platform_device ar71xx_eth0_device = {
  1263. + .name = "ag71xx",
  1264. + .id = 0,
  1265. + .resource = ar71xx_eth0_resources,
  1266. + .num_resources = ARRAY_SIZE(ar71xx_eth0_resources),
  1267. + .dev = {
  1268. + .platform_data = &ar71xx_eth0_data,
  1269. + },
  1270. +};
  1271. +
  1272. +static struct resource ar71xx_eth1_resources[] = {
  1273. + {
  1274. + .name = "mac_base",
  1275. + .flags = IORESOURCE_MEM,
  1276. + .start = AR71XX_GE1_BASE,
  1277. + .end = AR71XX_GE1_BASE + 0x200 - 1,
  1278. + }, {
  1279. + .name = "mii_ctrl",
  1280. + .flags = IORESOURCE_MEM,
  1281. + .start = AR71XX_MII_BASE + MII_REG_MII1_CTRL,
  1282. + .end = AR71XX_MII_BASE + MII_REG_MII1_CTRL + 3,
  1283. + }, {
  1284. + .name = "mac_irq",
  1285. + .flags = IORESOURCE_IRQ,
  1286. + .start = AR71XX_CPU_IRQ_GE1,
  1287. + .end = AR71XX_CPU_IRQ_GE1,
  1288. + },
  1289. +};
  1290. +
  1291. +struct ag71xx_platform_data ar71xx_eth1_data = {
  1292. + .reset_bit = RESET_MODULE_GE1_MAC,
  1293. +};
  1294. +
  1295. +struct platform_device ar71xx_eth1_device = {
  1296. + .name = "ag71xx",
  1297. + .id = 1,
  1298. + .resource = ar71xx_eth1_resources,
  1299. + .num_resources = ARRAY_SIZE(ar71xx_eth1_resources),
  1300. + .dev = {
  1301. + .platform_data = &ar71xx_eth1_data,
  1302. + },
  1303. +};
  1304. +
  1305. +#define AR71XX_PLL_VAL_1000 0x00110000
  1306. +#define AR71XX_PLL_VAL_100 0x00001099
  1307. +#define AR71XX_PLL_VAL_10 0x00991099
  1308. +
  1309. +#define AR724X_PLL_VAL_1000 0x00110000
  1310. +#define AR724X_PLL_VAL_100 0x00001099
  1311. +#define AR724X_PLL_VAL_10 0x00991099
  1312. +
  1313. +#define AR7242_PLL_VAL_1000 0x1c000000
  1314. +#define AR7242_PLL_VAL_100 0x00000101
  1315. +#define AR7242_PLL_VAL_10 0x00001616
  1316. +
  1317. +#define AR91XX_PLL_VAL_1000 0x1a000000
  1318. +#define AR91XX_PLL_VAL_100 0x13000a44
  1319. +#define AR91XX_PLL_VAL_10 0x00441099
  1320. +
  1321. +#define AR933X_PLL_VAL_1000 0x00110000
  1322. +#define AR933X_PLL_VAL_100 0x00001099
  1323. +#define AR933X_PLL_VAL_10 0x00991099
  1324. +
  1325. +static void __init ar71xx_init_eth_pll_data(unsigned int id)
  1326. +{
  1327. + struct ar71xx_eth_pll_data *pll_data;
  1328. + u32 pll_10, pll_100, pll_1000;
  1329. +
  1330. + switch (id) {
  1331. + case 0:
  1332. + pll_data = &ar71xx_eth0_pll_data;
  1333. + break;
  1334. + case 1:
  1335. + pll_data = &ar71xx_eth1_pll_data;
  1336. + break;
  1337. + default:
  1338. + BUG();
  1339. + }
  1340. +
  1341. + switch (ar71xx_soc) {
  1342. + case AR71XX_SOC_AR7130:
  1343. + case AR71XX_SOC_AR7141:
  1344. + case AR71XX_SOC_AR7161:
  1345. + pll_10 = AR71XX_PLL_VAL_10;
  1346. + pll_100 = AR71XX_PLL_VAL_100;
  1347. + pll_1000 = AR71XX_PLL_VAL_1000;
  1348. + break;
  1349. +
  1350. + case AR71XX_SOC_AR7240:
  1351. + case AR71XX_SOC_AR7241:
  1352. + pll_10 = AR724X_PLL_VAL_10;
  1353. + pll_100 = AR724X_PLL_VAL_100;
  1354. + pll_1000 = AR724X_PLL_VAL_1000;
  1355. + break;
  1356. +
  1357. + case AR71XX_SOC_AR7242:
  1358. + pll_10 = AR7242_PLL_VAL_10;
  1359. + pll_100 = AR7242_PLL_VAL_100;
  1360. + pll_1000 = AR7242_PLL_VAL_1000;
  1361. + break;
  1362. +
  1363. + case AR71XX_SOC_AR9130:
  1364. + case AR71XX_SOC_AR9132:
  1365. + pll_10 = AR91XX_PLL_VAL_10;
  1366. + pll_100 = AR91XX_PLL_VAL_100;
  1367. + pll_1000 = AR91XX_PLL_VAL_1000;
  1368. + break;
  1369. +
  1370. + case AR71XX_SOC_AR9330:
  1371. + case AR71XX_SOC_AR9331:
  1372. + pll_10 = AR933X_PLL_VAL_10;
  1373. + pll_100 = AR933X_PLL_VAL_100;
  1374. + pll_1000 = AR933X_PLL_VAL_1000;
  1375. + break;
  1376. +
  1377. + default:
  1378. + BUG();
  1379. + }
  1380. +
  1381. + if (!pll_data->pll_10)
  1382. + pll_data->pll_10 = pll_10;
  1383. +
  1384. + if (!pll_data->pll_100)
  1385. + pll_data->pll_100 = pll_100;
  1386. +
  1387. + if (!pll_data->pll_1000)
  1388. + pll_data->pll_1000 = pll_1000;
  1389. +}
  1390. +
  1391. +static int ar71xx_eth_instance __initdata;
  1392. +void __init ar71xx_add_device_eth(unsigned int id)
  1393. +{
  1394. + struct platform_device *pdev;
  1395. + struct ag71xx_platform_data *pdata;
  1396. +
  1397. + ar71xx_init_eth_pll_data(id);
  1398. +
  1399. + switch (id) {
  1400. + case 0:
  1401. + switch (ar71xx_eth0_data.phy_if_mode) {
  1402. + case PHY_INTERFACE_MODE_MII:
  1403. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_MII;
  1404. + break;
  1405. + case PHY_INTERFACE_MODE_GMII:
  1406. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_GMII;
  1407. + break;
  1408. + case PHY_INTERFACE_MODE_RGMII:
  1409. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RGMII;
  1410. + break;
  1411. + case PHY_INTERFACE_MODE_RMII:
  1412. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RMII;
  1413. + break;
  1414. + default:
  1415. + printk(KERN_ERR "ar71xx: invalid PHY interface mode "
  1416. + "for eth0\n");
  1417. + return;
  1418. + }
  1419. + pdev = &ar71xx_eth0_device;
  1420. + break;
  1421. + case 1:
  1422. + switch (ar71xx_eth1_data.phy_if_mode) {
  1423. + case PHY_INTERFACE_MODE_RMII:
  1424. + ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RMII;
  1425. + break;
  1426. + case PHY_INTERFACE_MODE_RGMII:
  1427. + ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RGMII;
  1428. + break;
  1429. + default:
  1430. + printk(KERN_ERR "ar71xx: invalid PHY interface mode "
  1431. + "for eth1\n");
  1432. + return;
  1433. + }
  1434. + pdev = &ar71xx_eth1_device;
  1435. + break;
  1436. + default:
  1437. + printk(KERN_ERR "ar71xx: invalid ethernet id %d\n", id);
  1438. + return;
  1439. + }
  1440. +
  1441. + pdata = pdev->dev.platform_data;
  1442. +
  1443. + switch (ar71xx_soc) {
  1444. + case AR71XX_SOC_AR7130:
  1445. + pdata->ddr_flush = id ? ar71xx_ddr_flush_ge1
  1446. + : ar71xx_ddr_flush_ge0;
  1447. + pdata->set_pll = id ? ar71xx_set_pll_ge1
  1448. + : ar71xx_set_pll_ge0;
  1449. + break;
  1450. +
  1451. + case AR71XX_SOC_AR7141:
  1452. + case AR71XX_SOC_AR7161:
  1453. + pdata->ddr_flush = id ? ar71xx_ddr_flush_ge1
  1454. + : ar71xx_ddr_flush_ge0;
  1455. + pdata->set_pll = id ? ar71xx_set_pll_ge1
  1456. + : ar71xx_set_pll_ge0;
  1457. + pdata->has_gbit = 1;
  1458. + break;
  1459. +
  1460. + case AR71XX_SOC_AR7242:
  1461. + ar71xx_eth0_data.reset_bit |= AR724X_RESET_GE0_MDIO |
  1462. + RESET_MODULE_GE0_PHY;
  1463. + ar71xx_eth1_data.reset_bit |= AR724X_RESET_GE1_MDIO |
  1464. + RESET_MODULE_GE1_PHY;
  1465. + pdata->ddr_flush = id ? ar724x_ddr_flush_ge1
  1466. + : ar724x_ddr_flush_ge0;
  1467. + pdata->set_pll = id ? ar724x_set_pll_ge1
  1468. + : ar7242_set_pll_ge0;
  1469. + pdata->has_gbit = 1;
  1470. + pdata->is_ar724x = 1;
  1471. +
  1472. + if (!pdata->fifo_cfg1)
  1473. + pdata->fifo_cfg1 = 0x0010ffff;
  1474. + if (!pdata->fifo_cfg2)
  1475. + pdata->fifo_cfg2 = 0x015500aa;
  1476. + if (!pdata->fifo_cfg3)
  1477. + pdata->fifo_cfg3 = 0x01f00140;
  1478. + break;
  1479. +
  1480. + case AR71XX_SOC_AR7241:
  1481. + ar71xx_eth0_data.reset_bit |= AR724X_RESET_GE0_MDIO;
  1482. + ar71xx_eth1_data.reset_bit |= AR724X_RESET_GE1_MDIO;
  1483. + /* fall through */
  1484. + case AR71XX_SOC_AR7240:
  1485. + ar71xx_eth0_data.reset_bit |= RESET_MODULE_GE0_PHY;
  1486. + ar71xx_eth1_data.reset_bit |= RESET_MODULE_GE1_PHY;
  1487. + pdata->ddr_flush = id ? ar724x_ddr_flush_ge1
  1488. + : ar724x_ddr_flush_ge0;
  1489. + pdata->set_pll = id ? ar724x_set_pll_ge1
  1490. + : ar724x_set_pll_ge0;
  1491. + pdata->is_ar724x = 1;
  1492. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  1493. + pdata->is_ar7240 = 1;
  1494. +
  1495. + if (!pdata->fifo_cfg1)
  1496. + pdata->fifo_cfg1 = 0x0010ffff;
  1497. + if (!pdata->fifo_cfg2)
  1498. + pdata->fifo_cfg2 = 0x015500aa;
  1499. + if (!pdata->fifo_cfg3)
  1500. + pdata->fifo_cfg3 = 0x01f00140;
  1501. + break;
  1502. +
  1503. + case AR71XX_SOC_AR9130:
  1504. + pdata->ddr_flush = id ? ar91xx_ddr_flush_ge1
  1505. + : ar91xx_ddr_flush_ge0;
  1506. + pdata->set_pll = id ? ar91xx_set_pll_ge1
  1507. + : ar91xx_set_pll_ge0;
  1508. + pdata->is_ar91xx = 1;
  1509. + break;
  1510. +
  1511. + case AR71XX_SOC_AR9132:
  1512. + pdata->ddr_flush = id ? ar91xx_ddr_flush_ge1
  1513. + : ar91xx_ddr_flush_ge0;
  1514. + pdata->set_pll = id ? ar91xx_set_pll_ge1
  1515. + : ar91xx_set_pll_ge0;
  1516. + pdata->is_ar91xx = 1;
  1517. + pdata->has_gbit = 1;
  1518. + break;
  1519. +
  1520. + case AR71XX_SOC_AR9330:
  1521. + case AR71XX_SOC_AR9331:
  1522. + ar71xx_eth0_data.reset_bit = AR933X_RESET_GE0_MAC |
  1523. + AR933X_RESET_GE0_MDIO;
  1524. + ar71xx_eth1_data.reset_bit = AR933X_RESET_GE1_MAC |
  1525. + AR933X_RESET_GE1_MDIO;
  1526. + pdata->ddr_flush = id ? ar933x_ddr_flush_ge1
  1527. + : ar933x_ddr_flush_ge0;
  1528. + pdata->set_pll = id ? ar933x_set_pll_ge1
  1529. + : ar933x_set_pll_ge0;
  1530. + pdata->has_gbit = 1;
  1531. + pdata->is_ar724x = 1;
  1532. +
  1533. + if (!pdata->fifo_cfg1)
  1534. + pdata->fifo_cfg1 = 0x0010ffff;
  1535. + if (!pdata->fifo_cfg2)
  1536. + pdata->fifo_cfg2 = 0x015500aa;
  1537. + if (!pdata->fifo_cfg3)
  1538. + pdata->fifo_cfg3 = 0x01f00140;
  1539. + break;
  1540. +
  1541. + default:
  1542. + BUG();
  1543. + }
  1544. +
  1545. + switch (pdata->phy_if_mode) {
  1546. + case PHY_INTERFACE_MODE_GMII:
  1547. + case PHY_INTERFACE_MODE_RGMII:
  1548. + if (!pdata->has_gbit) {
  1549. + printk(KERN_ERR "ar71xx: no gbit available on eth%d\n",
  1550. + id);
  1551. + return;
  1552. + }
  1553. + /* fallthrough */
  1554. + default:
  1555. + break;
  1556. + }
  1557. +
  1558. + if (!is_valid_ether_addr(pdata->mac_addr)) {
  1559. + random_ether_addr(pdata->mac_addr);
  1560. + printk(KERN_DEBUG
  1561. + "ar71xx: using random MAC address for eth%d\n",
  1562. + ar71xx_eth_instance);
  1563. + }
  1564. +
  1565. + if (pdata->mii_bus_dev == NULL)
  1566. + pdata->mii_bus_dev = &ar71xx_mdio_device.dev;
  1567. +
  1568. + /* Reset the device */
  1569. + ar71xx_device_stop(pdata->reset_bit);
  1570. + mdelay(100);
  1571. +
  1572. + ar71xx_device_start(pdata->reset_bit);
  1573. + mdelay(100);
  1574. +
  1575. + platform_device_register(pdev);
  1576. + ar71xx_eth_instance++;
  1577. +}
  1578. +
  1579. +static struct resource ar71xx_spi_resources[] = {
  1580. + [0] = {
  1581. + .start = AR71XX_SPI_BASE,
  1582. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  1583. + .flags = IORESOURCE_MEM,
  1584. + },
  1585. +};
  1586. +
  1587. +static struct platform_device ar71xx_spi_device = {
  1588. + .name = "ar71xx-spi",
  1589. + .id = -1,
  1590. + .resource = ar71xx_spi_resources,
  1591. + .num_resources = ARRAY_SIZE(ar71xx_spi_resources),
  1592. +};
  1593. +
  1594. +void __init ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
  1595. + struct spi_board_info const *info,
  1596. + unsigned n)
  1597. +{
  1598. + spi_register_board_info(info, n);
  1599. + ar71xx_spi_device.dev.platform_data = pdata;
  1600. + platform_device_register(&ar71xx_spi_device);
  1601. +}
  1602. +
  1603. +void __init ar71xx_add_device_wdt(void)
  1604. +{
  1605. + platform_device_register_simple("ar71xx-wdt", -1, NULL, 0);
  1606. +}
  1607. +
  1608. +void __init ar71xx_set_mac_base(unsigned char *mac)
  1609. +{
  1610. + memcpy(ar71xx_mac_base, mac, ETH_ALEN);
  1611. +}
  1612. +
  1613. +void __init ar71xx_parse_mac_addr(char *mac_str)
  1614. +{
  1615. + u8 tmp[ETH_ALEN];
  1616. + int t;
  1617. +
  1618. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  1619. + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
  1620. +
  1621. + if (t != ETH_ALEN)
  1622. + t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
  1623. + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
  1624. +
  1625. + if (t == ETH_ALEN)
  1626. + ar71xx_set_mac_base(tmp);
  1627. + else
  1628. + printk(KERN_DEBUG "ar71xx: failed to parse mac address "
  1629. + "\"%s\"\n", mac_str);
  1630. +}
  1631. +
  1632. +static int __init ar71xx_ethaddr_setup(char *str)
  1633. +{
  1634. + ar71xx_parse_mac_addr(str);
  1635. + return 1;
  1636. +}
  1637. +__setup("ethaddr=", ar71xx_ethaddr_setup);
  1638. +
  1639. +static int __init ar71xx_kmac_setup(char *str)
  1640. +{
  1641. + ar71xx_parse_mac_addr(str);
  1642. + return 1;
  1643. +}
  1644. +__setup("kmac=", ar71xx_kmac_setup);
  1645. +
  1646. +void __init ar71xx_init_mac(unsigned char *dst, const unsigned char *src,
  1647. + unsigned offset)
  1648. +{
  1649. + u32 t;
  1650. +
  1651. + if (!is_valid_ether_addr(src)) {
  1652. + memset(dst, '\0', ETH_ALEN);
  1653. + return;
  1654. + }
  1655. +
  1656. + t = (((u32) src[3]) << 16) + (((u32) src[4]) << 8) + ((u32) src[5]);
  1657. + t += offset;
  1658. +
  1659. + dst[0] = src[0];
  1660. + dst[1] = src[1];
  1661. + dst[2] = src[2];
  1662. + dst[3] = (t >> 16) & 0xff;
  1663. + dst[4] = (t >> 8) & 0xff;
  1664. + dst[5] = t & 0xff;
  1665. +}
  1666. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/devices.h linux-2.6.39/arch/mips/ar71xx/devices.h
  1667. --- linux-2.6.39.orig/arch/mips/ar71xx/devices.h 1970-01-01 01:00:00.000000000 +0100
  1668. +++ linux-2.6.39/arch/mips/ar71xx/devices.h 2011-08-24 02:41:55.347990727 +0200
  1669. @@ -0,0 +1,50 @@
  1670. +/*
  1671. + * Atheros AR71xx SoC device definitions
  1672. + *
  1673. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1674. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1675. + *
  1676. + * This program is free software; you can redistribute it and/or modify it
  1677. + * under the terms of the GNU General Public License version 2 as published
  1678. + * by the Free Software Foundation.
  1679. + */
  1680. +
  1681. +#ifndef __AR71XX_DEVICES_H
  1682. +#define __AR71XX_DEVICES_H
  1683. +
  1684. +#include <asm/mach-ar71xx/platform.h>
  1685. +
  1686. +struct platform_device;
  1687. +
  1688. +void ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
  1689. + struct spi_board_info const *info,
  1690. + unsigned n) __init;
  1691. +
  1692. +extern unsigned char ar71xx_mac_base[] __initdata;
  1693. +void ar71xx_parse_mac_addr(char *mac_str) __init;
  1694. +void ar71xx_init_mac(unsigned char *dst, const unsigned char *src,
  1695. + unsigned offset) __init;
  1696. +
  1697. +struct ar71xx_eth_pll_data {
  1698. + u32 pll_10;
  1699. + u32 pll_100;
  1700. + u32 pll_1000;
  1701. +};
  1702. +
  1703. +extern struct ar71xx_eth_pll_data ar71xx_eth0_pll_data;
  1704. +extern struct ar71xx_eth_pll_data ar71xx_eth1_pll_data;
  1705. +
  1706. +extern struct ag71xx_platform_data ar71xx_eth0_data;
  1707. +extern struct ag71xx_platform_data ar71xx_eth1_data;
  1708. +extern struct platform_device ar71xx_eth0_device;
  1709. +extern struct platform_device ar71xx_eth1_device;
  1710. +void ar71xx_add_device_eth(unsigned int id) __init;
  1711. +
  1712. +extern struct platform_device ar71xx_mdio_device;
  1713. +void ar71xx_add_device_mdio(u32 phy_mask) __init;
  1714. +
  1715. +void ar71xx_add_device_uart(void) __init;
  1716. +
  1717. +void ar71xx_add_device_wdt(void) __init;
  1718. +
  1719. +#endif /* __AR71XX_DEVICES_H */
  1720. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-leds-gpio.c linux-2.6.39/arch/mips/ar71xx/dev-leds-gpio.c
  1721. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-leds-gpio.c 1970-01-01 01:00:00.000000000 +0100
  1722. +++ linux-2.6.39/arch/mips/ar71xx/dev-leds-gpio.c 2011-08-24 02:41:55.347990727 +0200
  1723. @@ -0,0 +1,57 @@
  1724. +/*
  1725. + * Atheros AR71xx GPIO LED device support
  1726. + *
  1727. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1728. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1729. + *
  1730. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1731. + *
  1732. + * This program is free software; you can redistribute it and/or modify it
  1733. + * under the terms of the GNU General Public License version 2 as published
  1734. + * by the Free Software Foundation.
  1735. + */
  1736. +
  1737. +#include <linux/init.h>
  1738. +#include <linux/slab.h>
  1739. +#include <linux/platform_device.h>
  1740. +
  1741. +#include "dev-leds-gpio.h"
  1742. +
  1743. +void __init ar71xx_add_device_leds_gpio(int id, unsigned num_leds,
  1744. + struct gpio_led *leds)
  1745. +{
  1746. + struct platform_device *pdev;
  1747. + struct gpio_led_platform_data pdata;
  1748. + struct gpio_led *p;
  1749. + int err;
  1750. +
  1751. + p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
  1752. + if (!p)
  1753. + return;
  1754. +
  1755. + memcpy(p, leds, num_leds * sizeof(*p));
  1756. +
  1757. + pdev = platform_device_alloc("leds-gpio", id);
  1758. + if (!pdev)
  1759. + goto err_free_leds;
  1760. +
  1761. + memset(&pdata, 0, sizeof(pdata));
  1762. + pdata.num_leds = num_leds;
  1763. + pdata.leds = p;
  1764. +
  1765. + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  1766. + if (err)
  1767. + goto err_put_pdev;
  1768. +
  1769. + err = platform_device_add(pdev);
  1770. + if (err)
  1771. + goto err_put_pdev;
  1772. +
  1773. + return;
  1774. +
  1775. +err_put_pdev:
  1776. + platform_device_put(pdev);
  1777. +
  1778. +err_free_leds:
  1779. + kfree(p);
  1780. +}
  1781. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-leds-gpio.h linux-2.6.39/arch/mips/ar71xx/dev-leds-gpio.h
  1782. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-leds-gpio.h 1970-01-01 01:00:00.000000000 +0100
  1783. +++ linux-2.6.39/arch/mips/ar71xx/dev-leds-gpio.h 2011-08-24 02:41:55.367990903 +0200
  1784. @@ -0,0 +1,21 @@
  1785. +/*
  1786. + * Atheros AR71xx GPIO LED device support
  1787. + *
  1788. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1789. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1790. + *
  1791. + * This program is free software; you can redistribute it and/or modify it
  1792. + * under the terms of the GNU General Public License version 2 as published
  1793. + * by the Free Software Foundation.
  1794. + */
  1795. +
  1796. +#ifndef _AR71XX_DEV_LEDS_GPIO_H
  1797. +#define _AR71XX_DEV_LEDS_GPIO_H
  1798. +
  1799. +#include <linux/leds.h>
  1800. +
  1801. +void ar71xx_add_device_leds_gpio(int id,
  1802. + unsigned num_leds,
  1803. + struct gpio_led *leds) __init;
  1804. +
  1805. +#endif /* _AR71XX_DEV_LEDS_GPIO_H */
  1806. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-m25p80.c linux-2.6.39/arch/mips/ar71xx/dev-m25p80.c
  1807. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-m25p80.c 1970-01-01 01:00:00.000000000 +0100
  1808. +++ linux-2.6.39/arch/mips/ar71xx/dev-m25p80.c 2011-08-24 02:41:55.367990903 +0200
  1809. @@ -0,0 +1,30 @@
  1810. +/*
  1811. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1812. + *
  1813. + * This program is free software; you can redistribute it and/or modify it
  1814. + * under the terms of the GNU General Public License version 2 as published
  1815. + * by the Free Software Foundation.
  1816. + */
  1817. +
  1818. +#include <linux/init.h>
  1819. +#include <linux/spi/spi.h>
  1820. +#include <linux/spi/flash.h>
  1821. +
  1822. +#include "devices.h"
  1823. +#include "dev-m25p80.h"
  1824. +
  1825. +static struct spi_board_info ar71xx_spi_info[] = {
  1826. + {
  1827. + .bus_num = 0,
  1828. + .chip_select = 0,
  1829. + .max_speed_hz = 25000000,
  1830. + .modalias = "m25p80",
  1831. + }
  1832. +};
  1833. +
  1834. +void __init ar71xx_add_device_m25p80(struct flash_platform_data *pdata)
  1835. +{
  1836. + ar71xx_spi_info[0].platform_data = pdata;
  1837. + ar71xx_add_device_spi(NULL, ar71xx_spi_info,
  1838. + ARRAY_SIZE(ar71xx_spi_info));
  1839. +}
  1840. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-m25p80.h linux-2.6.39/arch/mips/ar71xx/dev-m25p80.h
  1841. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-m25p80.h 1970-01-01 01:00:00.000000000 +0100
  1842. +++ linux-2.6.39/arch/mips/ar71xx/dev-m25p80.h 2011-08-24 02:41:55.377990515 +0200
  1843. @@ -0,0 +1,16 @@
  1844. +/*
  1845. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1846. + *
  1847. + * This program is free software; you can redistribute it and/or modify it
  1848. + * under the terms of the GNU General Public License version 2 as published
  1849. + * by the Free Software Foundation.
  1850. + */
  1851. +
  1852. +#ifndef _AR71XX_DEV_M25P80_H
  1853. +#define _AR71XX_DEV_M25P80_H
  1854. +
  1855. +#include <linux/spi/flash.h>
  1856. +
  1857. +void ar71xx_add_device_m25p80(struct flash_platform_data *pdata) __init;
  1858. +
  1859. +#endif /* _AR71XX_DEV_M25P80_H */
  1860. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-pb42-pci.c linux-2.6.39/arch/mips/ar71xx/dev-pb42-pci.c
  1861. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-pb42-pci.c 1970-01-01 01:00:00.000000000 +0100
  1862. +++ linux-2.6.39/arch/mips/ar71xx/dev-pb42-pci.c 2011-08-24 02:41:55.377990515 +0200
  1863. @@ -0,0 +1,40 @@
  1864. +/*
  1865. + * Atheros PB42 reference board PCI initialization
  1866. + *
  1867. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1868. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1869. + *
  1870. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1871. + *
  1872. + * This program is free software; you can redistribute it and/or modify it
  1873. + * under the terms of the GNU General Public License version 2 as published
  1874. + * by the Free Software Foundation.
  1875. + */
  1876. +
  1877. +#include <linux/pci.h>
  1878. +
  1879. +#include <asm/mach-ar71xx/ar71xx.h>
  1880. +#include <asm/mach-ar71xx/pci.h>
  1881. +
  1882. +#include "dev-pb42-pci.h"
  1883. +
  1884. +static struct ar71xx_pci_irq pb42_pci_irqs[] __initdata = {
  1885. + {
  1886. + .slot = 0,
  1887. + .pin = 1,
  1888. + .irq = AR71XX_PCI_IRQ_DEV0,
  1889. + }, {
  1890. + .slot = 1,
  1891. + .pin = 1,
  1892. + .irq = AR71XX_PCI_IRQ_DEV1,
  1893. + }, {
  1894. + .slot = 2,
  1895. + .pin = 1,
  1896. + .irq = AR71XX_PCI_IRQ_DEV2,
  1897. + }
  1898. +};
  1899. +
  1900. +void __init pb42_pci_init(void)
  1901. +{
  1902. + ar71xx_pci_init(ARRAY_SIZE(pb42_pci_irqs), pb42_pci_irqs);
  1903. +}
  1904. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-pb42-pci.h linux-2.6.39/arch/mips/ar71xx/dev-pb42-pci.h
  1905. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-pb42-pci.h 1970-01-01 01:00:00.000000000 +0100
  1906. +++ linux-2.6.39/arch/mips/ar71xx/dev-pb42-pci.h 2011-08-24 02:41:55.387991243 +0200
  1907. @@ -0,0 +1,21 @@
  1908. +/*
  1909. + * Atheros PB42 reference board PCI initialization
  1910. + *
  1911. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1912. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1913. + *
  1914. + * This program is free software; you can redistribute it and/or modify it
  1915. + * under the terms of the GNU General Public License version 2 as published
  1916. + * by the Free Software Foundation.
  1917. + */
  1918. +
  1919. +#ifndef _AR71XX_DEV_PB42_PCI_H
  1920. +#define _AR71XX_DEV_PB42_PCI_H
  1921. +
  1922. +#if defined(CONFIG_AR71XX_DEV_PB42_PCI)
  1923. +void pb42_pci_init(void) __init;
  1924. +#else
  1925. +static inline void pb42_pci_init(void) { }
  1926. +#endif
  1927. +
  1928. +#endif /* _AR71XX_DEV_PB42_PCI_H */
  1929. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-pb9x-pci.c linux-2.6.39/arch/mips/ar71xx/dev-pb9x-pci.c
  1930. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-pb9x-pci.c 1970-01-01 01:00:00.000000000 +0100
  1931. +++ linux-2.6.39/arch/mips/ar71xx/dev-pb9x-pci.c 2011-08-24 02:41:55.387991243 +0200
  1932. @@ -0,0 +1,33 @@
  1933. +/*
  1934. + * Atheros PB9x reference board PCI initialization
  1935. + *
  1936. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1937. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1938. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1939. + *
  1940. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1941. + *
  1942. + * This program is free software; you can redistribute it and/or modify it
  1943. + * under the terms of the GNU General Public License version 2 as published
  1944. + * by the Free Software Foundation.
  1945. + */
  1946. +
  1947. +#include <linux/pci.h>
  1948. +
  1949. +#include <asm/mach-ar71xx/ar71xx.h>
  1950. +#include <asm/mach-ar71xx/pci.h>
  1951. +
  1952. +#include "dev-pb9x-pci.h"
  1953. +
  1954. +static struct ar71xx_pci_irq pb9x_pci_irqs[] __initdata = {
  1955. + {
  1956. + .slot = 0,
  1957. + .pin = 1,
  1958. + .irq = AR71XX_PCI_IRQ_DEV0,
  1959. + }
  1960. +};
  1961. +
  1962. +void __init pb9x_pci_init(void)
  1963. +{
  1964. + ar71xx_pci_init(ARRAY_SIZE(pb9x_pci_irqs), pb9x_pci_irqs);
  1965. +}
  1966. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-pb9x-pci.h linux-2.6.39/arch/mips/ar71xx/dev-pb9x-pci.h
  1967. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-pb9x-pci.h 1970-01-01 01:00:00.000000000 +0100
  1968. +++ linux-2.6.39/arch/mips/ar71xx/dev-pb9x-pci.h 2011-08-24 02:41:55.387991243 +0200
  1969. @@ -0,0 +1,22 @@
  1970. +/*
  1971. + * Atheros PB9x reference board PCI initialization
  1972. + *
  1973. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1974. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1975. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1976. + *
  1977. + * This program is free software; you can redistribute it and/or modify it
  1978. + * under the terms of the GNU General Public License version 2 as published
  1979. + * by the Free Software Foundation.
  1980. + */
  1981. +
  1982. +#ifndef _AR71XX_DEV_PB9X_PCI_H
  1983. +#define _AR71XX_DEV_PB9X_PCI_H
  1984. +
  1985. +#if defined(CONFIG_AR71XX_DEV_PB9X_PCI)
  1986. +void pb9x_pci_init(void) __init;
  1987. +#else
  1988. +static inline void pb9x_pci_init(void) { }
  1989. +#endif
  1990. +
  1991. +#endif /* _AR71XX_DEV_PB9X_PCI_H */
  1992. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-usb.c linux-2.6.39/arch/mips/ar71xx/dev-usb.c
  1993. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-usb.c 1970-01-01 01:00:00.000000000 +0100
  1994. +++ linux-2.6.39/arch/mips/ar71xx/dev-usb.c 2011-08-24 02:41:55.417990329 +0200
  1995. @@ -0,0 +1,199 @@
  1996. +/*
  1997. + * Atheros AR71xx USB host device support
  1998. + *
  1999. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2000. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2001. + *
  2002. + * Parts of this file are based on Atheros' 2.6.15 BSP
  2003. + *
  2004. + * This program is free software; you can redistribute it and/or modify it
  2005. + * under the terms of the GNU General Public License version 2 as published
  2006. + * by the Free Software Foundation.
  2007. + */
  2008. +
  2009. +#include <linux/kernel.h>
  2010. +#include <linux/init.h>
  2011. +#include <linux/delay.h>
  2012. +#include <linux/dma-mapping.h>
  2013. +#include <linux/platform_device.h>
  2014. +
  2015. +#include <asm/mach-ar71xx/ar71xx.h>
  2016. +#include <asm/mach-ar71xx/platform.h>
  2017. +
  2018. +#include "dev-usb.h"
  2019. +
  2020. +/*
  2021. + * OHCI (USB full speed host controller)
  2022. + */
  2023. +static struct resource ar71xx_ohci_resources[] = {
  2024. + [0] = {
  2025. + .start = AR71XX_OHCI_BASE,
  2026. + .end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1,
  2027. + .flags = IORESOURCE_MEM,
  2028. + },
  2029. + [1] = {
  2030. + .start = AR71XX_MISC_IRQ_OHCI,
  2031. + .end = AR71XX_MISC_IRQ_OHCI,
  2032. + .flags = IORESOURCE_IRQ,
  2033. + },
  2034. +};
  2035. +
  2036. +static struct resource ar7240_ohci_resources[] = {
  2037. + [0] = {
  2038. + .start = AR7240_OHCI_BASE,
  2039. + .end = AR7240_OHCI_BASE + AR7240_OHCI_SIZE - 1,
  2040. + .flags = IORESOURCE_MEM,
  2041. + },
  2042. + [1] = {
  2043. + .start = AR71XX_CPU_IRQ_USB,
  2044. + .end = AR71XX_CPU_IRQ_USB,
  2045. + .flags = IORESOURCE_IRQ,
  2046. + },
  2047. +};
  2048. +
  2049. +static u64 ar71xx_ohci_dmamask = DMA_BIT_MASK(32);
  2050. +static struct platform_device ar71xx_ohci_device = {
  2051. + .name = "ar71xx-ohci",
  2052. + .id = -1,
  2053. + .resource = ar71xx_ohci_resources,
  2054. + .num_resources = ARRAY_SIZE(ar71xx_ohci_resources),
  2055. + .dev = {
  2056. + .dma_mask = &ar71xx_ohci_dmamask,
  2057. + .coherent_dma_mask = DMA_BIT_MASK(32),
  2058. + },
  2059. +};
  2060. +
  2061. +/*
  2062. + * EHCI (USB high/full speed host controller)
  2063. + */
  2064. +static struct resource ar71xx_ehci_resources[] = {
  2065. + [0] = {
  2066. + .start = AR71XX_EHCI_BASE,
  2067. + .end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1,
  2068. + .flags = IORESOURCE_MEM,
  2069. + },
  2070. + [1] = {
  2071. + .start = AR71XX_CPU_IRQ_USB,
  2072. + .end = AR71XX_CPU_IRQ_USB,
  2073. + .flags = IORESOURCE_IRQ,
  2074. + },
  2075. +};
  2076. +
  2077. +static u64 ar71xx_ehci_dmamask = DMA_BIT_MASK(32);
  2078. +static struct ar71xx_ehci_platform_data ar71xx_ehci_data;
  2079. +
  2080. +static struct platform_device ar71xx_ehci_device = {
  2081. + .name = "ar71xx-ehci",
  2082. + .id = -1,
  2083. + .resource = ar71xx_ehci_resources,
  2084. + .num_resources = ARRAY_SIZE(ar71xx_ehci_resources),
  2085. + .dev = {
  2086. + .dma_mask = &ar71xx_ehci_dmamask,
  2087. + .coherent_dma_mask = DMA_BIT_MASK(32),
  2088. + .platform_data = &ar71xx_ehci_data,
  2089. + },
  2090. +};
  2091. +
  2092. +#define AR71XX_USB_RESET_MASK \
  2093. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_PHY \
  2094. + | RESET_MODULE_USB_OHCI_DLL)
  2095. +
  2096. +#define AR7240_USB_RESET_MASK \
  2097. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_OHCI_DLL_7240)
  2098. +
  2099. +static void __init ar71xx_usb_setup(void)
  2100. +{
  2101. + ar71xx_device_stop(AR71XX_USB_RESET_MASK);
  2102. + mdelay(1000);
  2103. + ar71xx_device_start(AR71XX_USB_RESET_MASK);
  2104. +
  2105. + /* Turning on the Buff and Desc swap bits */
  2106. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_CONFIG, 0xf0000);
  2107. +
  2108. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  2109. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x20c00);
  2110. +
  2111. + mdelay(900);
  2112. +
  2113. + platform_device_register(&ar71xx_ohci_device);
  2114. + platform_device_register(&ar71xx_ehci_device);
  2115. +}
  2116. +
  2117. +static void __init ar7240_usb_setup(void)
  2118. +{
  2119. + ar71xx_device_stop(AR7240_USB_RESET_MASK);
  2120. + mdelay(1000);
  2121. + ar71xx_device_start(AR7240_USB_RESET_MASK);
  2122. +
  2123. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  2124. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x3);
  2125. +
  2126. + ar71xx_ohci_device.resource = ar7240_ohci_resources;
  2127. + ar71xx_ohci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  2128. + platform_device_register(&ar71xx_ohci_device);
  2129. +}
  2130. +
  2131. +static void __init ar7241_usb_setup(void)
  2132. +{
  2133. + ar71xx_device_start(AR724X_RESET_USBSUS_OVERRIDE);
  2134. + mdelay(10);
  2135. +
  2136. + ar71xx_device_start(AR724X_RESET_USB_HOST);
  2137. + mdelay(10);
  2138. +
  2139. + ar71xx_device_start(AR724X_RESET_USB_PHY);
  2140. + mdelay(10);
  2141. +
  2142. + ar71xx_ehci_data.is_ar91xx = 1;
  2143. + ar71xx_ehci_device.resource = ar7240_ohci_resources;
  2144. + ar71xx_ehci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  2145. + platform_device_register(&ar71xx_ehci_device);
  2146. +}
  2147. +
  2148. +static void __init ar91xx_usb_setup(void)
  2149. +{
  2150. + ar71xx_device_stop(RESET_MODULE_USBSUS_OVERRIDE);
  2151. + mdelay(10);
  2152. +
  2153. + ar71xx_device_start(RESET_MODULE_USB_HOST);
  2154. + mdelay(10);
  2155. +
  2156. + ar71xx_device_start(RESET_MODULE_USB_PHY);
  2157. + mdelay(10);
  2158. +
  2159. + ar71xx_ehci_data.is_ar91xx = 1;
  2160. + platform_device_register(&ar71xx_ehci_device);
  2161. +}
  2162. +
  2163. +void __init ar71xx_add_device_usb(void)
  2164. +{
  2165. + switch (ar71xx_soc) {
  2166. + case AR71XX_SOC_AR7240:
  2167. + ar7240_usb_setup();
  2168. + break;
  2169. +
  2170. + case AR71XX_SOC_AR7241:
  2171. + case AR71XX_SOC_AR7242:
  2172. + ar7241_usb_setup();
  2173. + break;
  2174. +
  2175. + case AR71XX_SOC_AR7130:
  2176. + case AR71XX_SOC_AR7141:
  2177. + case AR71XX_SOC_AR7161:
  2178. + ar71xx_usb_setup();
  2179. + break;
  2180. +
  2181. + case AR71XX_SOC_AR9130:
  2182. + case AR71XX_SOC_AR9132:
  2183. + case AR71XX_SOC_AR9330:
  2184. + case AR71XX_SOC_AR9331:
  2185. + case AR71XX_SOC_AR9341:
  2186. + case AR71XX_SOC_AR9342:
  2187. + case AR71XX_SOC_AR9344:
  2188. + ar91xx_usb_setup();
  2189. + break;
  2190. +
  2191. + default:
  2192. + BUG();
  2193. + }
  2194. +}
  2195. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/dev-usb.h linux-2.6.39/arch/mips/ar71xx/dev-usb.h
  2196. --- linux-2.6.39.orig/arch/mips/ar71xx/dev-usb.h 1970-01-01 01:00:00.000000000 +0100
  2197. +++ linux-2.6.39/arch/mips/ar71xx/dev-usb.h 2011-08-24 02:41:55.427989786 +0200
  2198. @@ -0,0 +1,17 @@
  2199. +/*
  2200. + * Atheros AR71xx USB host device support
  2201. + *
  2202. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2203. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2204. + *
  2205. + * This program is free software; you can redistribute it and/or modify it
  2206. + * under the terms of the GNU General Public License version 2 as published
  2207. + * by the Free Software Foundation.
  2208. + */
  2209. +
  2210. +#ifndef _AR71XX_DEV_USB_H
  2211. +#define _AR71XX_DEV_USB_H
  2212. +
  2213. +void ar71xx_add_device_usb(void) __init;
  2214. +
  2215. +#endif /* _AR71XX_DEV_USB_H */
  2216. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/early_printk.c linux-2.6.39/arch/mips/ar71xx/early_printk.c
  2217. --- linux-2.6.39.orig/arch/mips/ar71xx/early_printk.c 1970-01-01 01:00:00.000000000 +0100
  2218. +++ linux-2.6.39/arch/mips/ar71xx/early_printk.c 2011-08-24 02:41:55.427989786 +0200
  2219. @@ -0,0 +1,96 @@
  2220. +/*
  2221. + * Atheros AR7xxx/AR9xxx SoC early printk support
  2222. + *
  2223. + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  2224. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2225. + *
  2226. + * This program is free software; you can redistribute it and/or modify it
  2227. + * under the terms of the GNU General Public License version 2 as published
  2228. + * by the Free Software Foundation.
  2229. + */
  2230. +
  2231. +#include <linux/errno.h>
  2232. +#include <linux/io.h>
  2233. +#include <linux/serial_reg.h>
  2234. +#include <asm/addrspace.h>
  2235. +
  2236. +#include <asm/mach-ar71xx/ar71xx.h>
  2237. +#include <asm/mach-ar71xx/ar933x_uart.h>
  2238. +
  2239. +static void (*_prom_putchar) (unsigned char);
  2240. +
  2241. +static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
  2242. +{
  2243. + u32 t;
  2244. +
  2245. + do {
  2246. + t = __raw_readl(reg);
  2247. + if ((t & mask) == val)
  2248. + break;
  2249. + } while (1);
  2250. +}
  2251. +
  2252. +static void prom_putchar_ar71xx(unsigned char ch)
  2253. +{
  2254. + void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
  2255. +
  2256. + prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
  2257. + __raw_writel(ch, base + UART_TX * 4);
  2258. + prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
  2259. +}
  2260. +
  2261. +static void prom_putchar_ar933x(unsigned char ch)
  2262. +{
  2263. + void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
  2264. +
  2265. + prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  2266. + AR933X_UART_DATA_TX_CSR);
  2267. + __raw_writel(AR933X_UART_DATA_TX_CSR | ch, base + AR933X_UART_DATA_REG);
  2268. + prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  2269. + AR933X_UART_DATA_TX_CSR);
  2270. +}
  2271. +
  2272. +static void prom_putchar_dummy(unsigned char ch)
  2273. +{
  2274. + /* nothing to do */
  2275. +}
  2276. +
  2277. +static void prom_putchar_init(void)
  2278. +{
  2279. + void __iomem *base;
  2280. + u32 id;
  2281. +
  2282. + base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
  2283. + id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
  2284. + id &= REV_ID_MAJOR_MASK;
  2285. +
  2286. + switch (id) {
  2287. + case REV_ID_MAJOR_AR71XX:
  2288. + case REV_ID_MAJOR_AR7240:
  2289. + case REV_ID_MAJOR_AR7241:
  2290. + case REV_ID_MAJOR_AR7242:
  2291. + case REV_ID_MAJOR_AR913X:
  2292. + case REV_ID_MAJOR_AR9341:
  2293. + case REV_ID_MAJOR_AR9342:
  2294. + case REV_ID_MAJOR_AR9344:
  2295. + _prom_putchar = prom_putchar_ar71xx;
  2296. + break;
  2297. +
  2298. + case REV_ID_MAJOR_AR9330:
  2299. + case REV_ID_MAJOR_AR9331:
  2300. + _prom_putchar = prom_putchar_ar933x;
  2301. + break;
  2302. +
  2303. + default:
  2304. + _prom_putchar = prom_putchar_dummy;
  2305. + break;
  2306. + }
  2307. +}
  2308. +
  2309. +void prom_putchar(unsigned char ch)
  2310. +{
  2311. + if (!_prom_putchar)
  2312. + prom_putchar_init();
  2313. +
  2314. + _prom_putchar(ch);
  2315. +}
  2316. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/gpio.c linux-2.6.39/arch/mips/ar71xx/gpio.c
  2317. --- linux-2.6.39.orig/arch/mips/ar71xx/gpio.c 1970-01-01 01:00:00.000000000 +0100
  2318. +++ linux-2.6.39/arch/mips/ar71xx/gpio.c 2011-08-24 02:41:55.457989607 +0200
  2319. @@ -0,0 +1,193 @@
  2320. +/*
  2321. + * Atheros AR7XXX/AR9XXX SoC GPIO API support
  2322. + *
  2323. + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  2324. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2325. + *
  2326. + * This program is free software; you can redistribute it and/or modify it
  2327. + * under the terms of the GNU General Public License version 2 as published
  2328. + * by the Free Software Foundation.
  2329. + */
  2330. +
  2331. +#include <linux/kernel.h>
  2332. +#include <linux/init.h>
  2333. +#include <linux/module.h>
  2334. +#include <linux/types.h>
  2335. +#include <linux/spinlock.h>
  2336. +#include <linux/io.h>
  2337. +#include <linux/ioport.h>
  2338. +#include <linux/gpio.h>
  2339. +
  2340. +#include <asm/mach-ar71xx/ar71xx.h>
  2341. +
  2342. +static DEFINE_SPINLOCK(ar71xx_gpio_lock);
  2343. +
  2344. +unsigned long ar71xx_gpio_count;
  2345. +EXPORT_SYMBOL(ar71xx_gpio_count);
  2346. +
  2347. +void __ar71xx_gpio_set_value(unsigned gpio, int value)
  2348. +{
  2349. + void __iomem *base = ar71xx_gpio_base;
  2350. +
  2351. + if (value)
  2352. + __raw_writel(1 << gpio, base + GPIO_REG_SET);
  2353. + else
  2354. + __raw_writel(1 << gpio, base + GPIO_REG_CLEAR);
  2355. +}
  2356. +EXPORT_SYMBOL(__ar71xx_gpio_set_value);
  2357. +
  2358. +int __ar71xx_gpio_get_value(unsigned gpio)
  2359. +{
  2360. + return (__raw_readl(ar71xx_gpio_base + GPIO_REG_IN) >> gpio) & 1;
  2361. +}
  2362. +EXPORT_SYMBOL(__ar71xx_gpio_get_value);
  2363. +
  2364. +static int ar71xx_gpio_get_value(struct gpio_chip *chip, unsigned offset)
  2365. +{
  2366. + return __ar71xx_gpio_get_value(offset);
  2367. +}
  2368. +
  2369. +static void ar71xx_gpio_set_value(struct gpio_chip *chip,
  2370. + unsigned offset, int value)
  2371. +{
  2372. + __ar71xx_gpio_set_value(offset, value);
  2373. +}
  2374. +
  2375. +static int ar71xx_gpio_direction_input(struct gpio_chip *chip,
  2376. + unsigned offset)
  2377. +{
  2378. + void __iomem *base = ar71xx_gpio_base;
  2379. + unsigned long flags;
  2380. +
  2381. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2382. +
  2383. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(1 << offset),
  2384. + base + GPIO_REG_OE);
  2385. +
  2386. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2387. +
  2388. + return 0;
  2389. +}
  2390. +
  2391. +static int ar71xx_gpio_direction_output(struct gpio_chip *chip,
  2392. + unsigned offset, int value)
  2393. +{
  2394. + void __iomem *base = ar71xx_gpio_base;
  2395. + unsigned long flags;
  2396. +
  2397. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2398. +
  2399. + if (value)
  2400. + __raw_writel(1 << offset, base + GPIO_REG_SET);
  2401. + else
  2402. + __raw_writel(1 << offset, base + GPIO_REG_CLEAR);
  2403. +
  2404. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | (1 << offset),
  2405. + base + GPIO_REG_OE);
  2406. +
  2407. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2408. +
  2409. + return 0;
  2410. +}
  2411. +
  2412. +static struct gpio_chip ar71xx_gpio_chip = {
  2413. + .label = "ar71xx",
  2414. + .get = ar71xx_gpio_get_value,
  2415. + .set = ar71xx_gpio_set_value,
  2416. + .direction_input = ar71xx_gpio_direction_input,
  2417. + .direction_output = ar71xx_gpio_direction_output,
  2418. + .base = 0,
  2419. + .ngpio = AR71XX_GPIO_COUNT,
  2420. +};
  2421. +
  2422. +void ar71xx_gpio_function_enable(u32 mask)
  2423. +{
  2424. + void __iomem *base = ar71xx_gpio_base;
  2425. + unsigned long flags;
  2426. +
  2427. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2428. +
  2429. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) | mask,
  2430. + base + GPIO_REG_FUNC);
  2431. + /* flush write */
  2432. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2433. +
  2434. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2435. +}
  2436. +
  2437. +void ar71xx_gpio_function_disable(u32 mask)
  2438. +{
  2439. + void __iomem *base = ar71xx_gpio_base;
  2440. + unsigned long flags;
  2441. +
  2442. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2443. +
  2444. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) & ~mask,
  2445. + base + GPIO_REG_FUNC);
  2446. + /* flush write */
  2447. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2448. +
  2449. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2450. +}
  2451. +
  2452. +void ar71xx_gpio_function_setup(u32 set, u32 clear)
  2453. +{
  2454. + void __iomem *base = ar71xx_gpio_base;
  2455. + unsigned long flags;
  2456. +
  2457. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2458. +
  2459. + __raw_writel((__raw_readl(base + GPIO_REG_FUNC) & ~clear) | set,
  2460. + base + GPIO_REG_FUNC);
  2461. + /* flush write */
  2462. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2463. +
  2464. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2465. +}
  2466. +EXPORT_SYMBOL(ar71xx_gpio_function_setup);
  2467. +
  2468. +void __init ar71xx_gpio_init(void)
  2469. +{
  2470. + int err;
  2471. +
  2472. + if (!request_mem_region(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE,
  2473. + "AR71xx GPIO controller"))
  2474. + panic("cannot allocate AR71xx GPIO registers page");
  2475. +
  2476. + switch (ar71xx_soc) {
  2477. + case AR71XX_SOC_AR7130:
  2478. + case AR71XX_SOC_AR7141:
  2479. + case AR71XX_SOC_AR7161:
  2480. + ar71xx_gpio_chip.ngpio = AR71XX_GPIO_COUNT;
  2481. + break;
  2482. +
  2483. + case AR71XX_SOC_AR7240:
  2484. + case AR71XX_SOC_AR7241:
  2485. + case AR71XX_SOC_AR7242:
  2486. + ar71xx_gpio_chip.ngpio = AR724X_GPIO_COUNT;
  2487. + break;
  2488. +
  2489. + case AR71XX_SOC_AR9130:
  2490. + case AR71XX_SOC_AR9132:
  2491. + ar71xx_gpio_chip.ngpio = AR91XX_GPIO_COUNT;
  2492. + break;
  2493. +
  2494. + case AR71XX_SOC_AR9330:
  2495. + case AR71XX_SOC_AR9331:
  2496. + ar71xx_gpio_chip.ngpio = AR933X_GPIO_COUNT;
  2497. + break;
  2498. +
  2499. + case AR71XX_SOC_AR9341:
  2500. + case AR71XX_SOC_AR9342:
  2501. + case AR71XX_SOC_AR9344:
  2502. + ar71xx_gpio_chip.ngpio = AR934X_GPIO_COUNT;
  2503. + break;
  2504. +
  2505. + default:
  2506. + BUG();
  2507. + }
  2508. +
  2509. + err = gpiochip_add(&ar71xx_gpio_chip);
  2510. + if (err)
  2511. + panic("cannot add AR71xx GPIO chip, error=%d", err);
  2512. +}
  2513. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/irq.c linux-2.6.39/arch/mips/ar71xx/irq.c
  2514. --- linux-2.6.39.orig/arch/mips/ar71xx/irq.c 1970-01-01 01:00:00.000000000 +0100
  2515. +++ linux-2.6.39/arch/mips/ar71xx/irq.c 2011-08-24 02:41:55.457989607 +0200
  2516. @@ -0,0 +1,377 @@
  2517. +/*
  2518. + * Atheros AR71xx SoC specific interrupt handling
  2519. + *
  2520. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  2521. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  2522. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2523. + *
  2524. + * Parts of this file are based on Atheros 2.6.15 BSP
  2525. + * Parts of this file are based on Atheros 2.6.31 BSP
  2526. + *
  2527. + * This program is free software; you can redistribute it and/or modify it
  2528. + * under the terms of the GNU General Public License version 2 as published
  2529. + * by the Free Software Foundation.
  2530. + */
  2531. +
  2532. +#include <linux/kernel.h>
  2533. +#include <linux/init.h>
  2534. +#include <linux/interrupt.h>
  2535. +#include <linux/irq.h>
  2536. +
  2537. +#include <asm/irq_cpu.h>
  2538. +#include <asm/mipsregs.h>
  2539. +
  2540. +#include <asm/mach-ar71xx/ar71xx.h>
  2541. +
  2542. +static void ar71xx_gpio_irq_dispatch(void)
  2543. +{
  2544. + void __iomem *base = ar71xx_gpio_base;
  2545. + u32 pending;
  2546. +
  2547. + pending = __raw_readl(base + GPIO_REG_INT_PENDING) &
  2548. + __raw_readl(base + GPIO_REG_INT_ENABLE);
  2549. +
  2550. + if (pending)
  2551. + do_IRQ(AR71XX_GPIO_IRQ_BASE + fls(pending) - 1);
  2552. + else
  2553. + spurious_interrupt();
  2554. +}
  2555. +
  2556. +static void ar71xx_gpio_irq_unmask(struct irq_data *d)
  2557. +{
  2558. + unsigned int irq = d->irq - AR71XX_GPIO_IRQ_BASE;
  2559. + void __iomem *base = ar71xx_gpio_base;
  2560. + u32 t;
  2561. +
  2562. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2563. + __raw_writel(t | (1 << irq), base + GPIO_REG_INT_ENABLE);
  2564. +
  2565. + /* flush write */
  2566. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2567. +}
  2568. +
  2569. +static void ar71xx_gpio_irq_mask(struct irq_data *d)
  2570. +{
  2571. + unsigned int irq = d->irq - AR71XX_GPIO_IRQ_BASE;
  2572. + void __iomem *base = ar71xx_gpio_base;
  2573. + u32 t;
  2574. +
  2575. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2576. + __raw_writel(t & ~(1 << irq), base + GPIO_REG_INT_ENABLE);
  2577. +
  2578. + /* flush write */
  2579. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2580. +}
  2581. +
  2582. +static struct irq_chip ar71xx_gpio_irq_chip = {
  2583. + .name = "AR71XX GPIO",
  2584. + .irq_unmask = ar71xx_gpio_irq_unmask,
  2585. + .irq_mask = ar71xx_gpio_irq_mask,
  2586. + .irq_mask_ack = ar71xx_gpio_irq_mask,
  2587. +};
  2588. +
  2589. +static struct irqaction ar71xx_gpio_irqaction = {
  2590. + .handler = no_action,
  2591. + .name = "cascade [AR71XX GPIO]",
  2592. +};
  2593. +
  2594. +#define GPIO_INT_ALL 0xffff
  2595. +
  2596. +static void __init ar71xx_gpio_irq_init(void)
  2597. +{
  2598. + void __iomem *base = ar71xx_gpio_base;
  2599. + int i;
  2600. +
  2601. + __raw_writel(0, base + GPIO_REG_INT_ENABLE);
  2602. + __raw_writel(0, base + GPIO_REG_INT_PENDING);
  2603. +
  2604. + /* setup type of all GPIO interrupts to level sensitive */
  2605. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_TYPE);
  2606. +
  2607. + /* setup polarity of all GPIO interrupts to active high */
  2608. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_POLARITY);
  2609. +
  2610. + for (i = AR71XX_GPIO_IRQ_BASE;
  2611. + i < AR71XX_GPIO_IRQ_BASE + AR71XX_GPIO_IRQ_COUNT; i++)
  2612. + irq_set_chip_and_handler(i, &ar71xx_gpio_irq_chip,
  2613. + handle_level_irq);
  2614. +
  2615. + setup_irq(AR71XX_MISC_IRQ_GPIO, &ar71xx_gpio_irqaction);
  2616. +}
  2617. +
  2618. +static void ar71xx_misc_irq_dispatch(void)
  2619. +{
  2620. + u32 pending;
  2621. +
  2622. + pending = ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_STATUS)
  2623. + & ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE);
  2624. +
  2625. + if (pending & MISC_INT_UART)
  2626. + do_IRQ(AR71XX_MISC_IRQ_UART);
  2627. +
  2628. + else if (pending & MISC_INT_DMA)
  2629. + do_IRQ(AR71XX_MISC_IRQ_DMA);
  2630. +
  2631. + else if (pending & MISC_INT_PERFC)
  2632. + do_IRQ(AR71XX_MISC_IRQ_PERFC);
  2633. +
  2634. + else if (pending & MISC_INT_TIMER)
  2635. + do_IRQ(AR71XX_MISC_IRQ_TIMER);
  2636. +
  2637. + else if (pending & MISC_INT_OHCI)
  2638. + do_IRQ(AR71XX_MISC_IRQ_OHCI);
  2639. +
  2640. + else if (pending & MISC_INT_ERROR)
  2641. + do_IRQ(AR71XX_MISC_IRQ_ERROR);
  2642. +
  2643. + else if (pending & MISC_INT_GPIO)
  2644. + ar71xx_gpio_irq_dispatch();
  2645. +
  2646. + else if (pending & MISC_INT_WDOG)
  2647. + do_IRQ(AR71XX_MISC_IRQ_WDOG);
  2648. +
  2649. + else if (pending & MISC_INT_TIMER2)
  2650. + do_IRQ(AR71XX_MISC_IRQ_TIMER2);
  2651. +
  2652. + else if (pending & MISC_INT_TIMER3)
  2653. + do_IRQ(AR71XX_MISC_IRQ_TIMER3);
  2654. +
  2655. + else if (pending & MISC_INT_TIMER4)
  2656. + do_IRQ(AR71XX_MISC_IRQ_TIMER4);
  2657. +
  2658. + else if (pending & MISC_INT_DDR_PERF)
  2659. + do_IRQ(AR71XX_MISC_IRQ_DDR_PERF);
  2660. +
  2661. + else if (pending & MISC_INT_ENET_LINK)
  2662. + do_IRQ(AR71XX_MISC_IRQ_ENET_LINK);
  2663. +
  2664. + else
  2665. + spurious_interrupt();
  2666. +}
  2667. +
  2668. +static void ar71xx_misc_irq_unmask(struct irq_data *d)
  2669. +{
  2670. + unsigned int irq = d->irq - AR71XX_MISC_IRQ_BASE;
  2671. + void __iomem *base = ar71xx_reset_base;
  2672. + u32 t;
  2673. +
  2674. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2675. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2676. +
  2677. + /* flush write */
  2678. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2679. +}
  2680. +
  2681. +static void ar71xx_misc_irq_mask(struct irq_data *d)
  2682. +{
  2683. + unsigned int irq = d->irq - AR71XX_MISC_IRQ_BASE;
  2684. + void __iomem *base = ar71xx_reset_base;
  2685. + u32 t;
  2686. +
  2687. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2688. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2689. +
  2690. + /* flush write */
  2691. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2692. +}
  2693. +
  2694. +static void ar724x_misc_irq_ack(struct irq_data *d)
  2695. +{
  2696. + unsigned int irq = d->irq - AR71XX_MISC_IRQ_BASE;
  2697. + void __iomem *base = ar71xx_reset_base;
  2698. + u32 t;
  2699. +
  2700. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2701. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2702. +
  2703. + /* flush write */
  2704. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2705. +}
  2706. +
  2707. +static struct irq_chip ar71xx_misc_irq_chip = {
  2708. + .name = "AR71XX MISC",
  2709. + .irq_unmask = ar71xx_misc_irq_unmask,
  2710. + .irq_mask = ar71xx_misc_irq_mask,
  2711. +};
  2712. +
  2713. +static struct irqaction ar71xx_misc_irqaction = {
  2714. + .handler = no_action,
  2715. + .name = "cascade [AR71XX MISC]",
  2716. +};
  2717. +
  2718. +static void __init ar71xx_misc_irq_init(void)
  2719. +{
  2720. + void __iomem *base = ar71xx_reset_base;
  2721. + int i;
  2722. +
  2723. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2724. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2725. +
  2726. + switch (ar71xx_soc) {
  2727. + case AR71XX_SOC_AR7240:
  2728. + case AR71XX_SOC_AR7241:
  2729. + case AR71XX_SOC_AR7242:
  2730. + case AR71XX_SOC_AR9330:
  2731. + case AR71XX_SOC_AR9331:
  2732. + case AR71XX_SOC_AR9341:
  2733. + case AR71XX_SOC_AR9342:
  2734. + case AR71XX_SOC_AR9344:
  2735. + ar71xx_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
  2736. + break;
  2737. + default:
  2738. + ar71xx_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
  2739. + break;
  2740. + }
  2741. +
  2742. + for (i = AR71XX_MISC_IRQ_BASE;
  2743. + i < AR71XX_MISC_IRQ_BASE + AR71XX_MISC_IRQ_COUNT; i++)
  2744. + irq_set_chip_and_handler(i, &ar71xx_misc_irq_chip,
  2745. + handle_level_irq);
  2746. +
  2747. + setup_irq(AR71XX_CPU_IRQ_MISC, &ar71xx_misc_irqaction);
  2748. +}
  2749. +
  2750. +/*
  2751. + * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
  2752. + * these devices typically allocate coherent DMA memory, however the
  2753. + * DMA controller may still have some unsynchronized data in the FIFO.
  2754. + * Issue a flush in the handlers to ensure that the driver sees
  2755. + * the update.
  2756. + */
  2757. +static void ar71xx_ip2_handler(void)
  2758. +{
  2759. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_PCI);
  2760. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2761. +}
  2762. +
  2763. +static void ar724x_ip2_handler(void)
  2764. +{
  2765. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_PCIE);
  2766. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2767. +}
  2768. +
  2769. +static void ar913x_ip2_handler(void)
  2770. +{
  2771. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_WMAC);
  2772. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2773. +}
  2774. +
  2775. +static void ar933x_ip2_handler(void)
  2776. +{
  2777. + ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_WMAC);
  2778. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2779. +}
  2780. +
  2781. +static void ar934x_ip2_handler(void)
  2782. +{
  2783. + ar71xx_ddr_flush(AR934X_DDR_REG_FLUSH_PCIE);
  2784. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2785. +}
  2786. +
  2787. +static void ar71xx_ip3_handler(void)
  2788. +{
  2789. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_USB);
  2790. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2791. +}
  2792. +
  2793. +static void ar724x_ip3_handler(void)
  2794. +{
  2795. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_USB);
  2796. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2797. +}
  2798. +
  2799. +static void ar913x_ip3_handler(void)
  2800. +{
  2801. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_USB);
  2802. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2803. +}
  2804. +
  2805. +static void ar933x_ip3_handler(void)
  2806. +{
  2807. + ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_USB);
  2808. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2809. +}
  2810. +
  2811. +static void ar934x_ip3_handler(void)
  2812. +{
  2813. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2814. +}
  2815. +
  2816. +static void (*ip2_handler)(void);
  2817. +static void (*ip3_handler)(void);
  2818. +
  2819. +asmlinkage void plat_irq_dispatch(void)
  2820. +{
  2821. + unsigned long pending;
  2822. +
  2823. + pending = read_c0_status() & read_c0_cause() & ST0_IM;
  2824. +
  2825. + if (pending & STATUSF_IP7)
  2826. + do_IRQ(AR71XX_CPU_IRQ_TIMER);
  2827. +
  2828. + else if (pending & STATUSF_IP2)
  2829. + ip2_handler();
  2830. +
  2831. + else if (pending & STATUSF_IP4)
  2832. + do_IRQ(AR71XX_CPU_IRQ_GE0);
  2833. +
  2834. + else if (pending & STATUSF_IP5)
  2835. + do_IRQ(AR71XX_CPU_IRQ_GE1);
  2836. +
  2837. + else if (pending & STATUSF_IP3)
  2838. + ip3_handler();
  2839. +
  2840. + else if (pending & STATUSF_IP6)
  2841. + ar71xx_misc_irq_dispatch();
  2842. +
  2843. + spurious_interrupt();
  2844. +}
  2845. +
  2846. +void __init arch_init_irq(void)
  2847. +{
  2848. + switch (ar71xx_soc) {
  2849. + case AR71XX_SOC_AR7130:
  2850. + case AR71XX_SOC_AR7141:
  2851. + case AR71XX_SOC_AR7161:
  2852. + ip2_handler = ar71xx_ip2_handler;
  2853. + ip3_handler = ar71xx_ip3_handler;
  2854. + break;
  2855. +
  2856. + case AR71XX_SOC_AR7240:
  2857. + case AR71XX_SOC_AR7241:
  2858. + case AR71XX_SOC_AR7242:
  2859. + ip2_handler = ar724x_ip2_handler;
  2860. + ip3_handler = ar724x_ip3_handler;
  2861. + break;
  2862. +
  2863. + case AR71XX_SOC_AR9130:
  2864. + case AR71XX_SOC_AR9132:
  2865. + ip2_handler = ar913x_ip2_handler;
  2866. + ip3_handler = ar913x_ip3_handler;
  2867. + break;
  2868. +
  2869. + case AR71XX_SOC_AR9330:
  2870. + case AR71XX_SOC_AR9331:
  2871. + ip2_handler = ar933x_ip2_handler;
  2872. + ip3_handler = ar933x_ip3_handler;
  2873. + break;
  2874. +
  2875. + case AR71XX_SOC_AR9341:
  2876. + case AR71XX_SOC_AR9342:
  2877. + case AR71XX_SOC_AR9344:
  2878. + ip2_handler = ar934x_ip2_handler;
  2879. + ip3_handler = ar934x_ip3_handler;
  2880. + break;
  2881. +
  2882. + default:
  2883. + BUG();
  2884. + }
  2885. +
  2886. + mips_cpu_irq_init();
  2887. +
  2888. + ar71xx_misc_irq_init();
  2889. +
  2890. + cp0_perfcount_irq = AR71XX_MISC_IRQ_PERFC;
  2891. +
  2892. + ar71xx_gpio_irq_init();
  2893. +}
  2894. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/Kconfig linux-2.6.39/arch/mips/ar71xx/Kconfig
  2895. --- linux-2.6.39.orig/arch/mips/ar71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  2896. +++ linux-2.6.39/arch/mips/ar71xx/Kconfig 2011-08-24 04:20:27.209240389 +0200
  2897. @@ -0,0 +1,420 @@
  2898. +if ATHEROS_AR71XX
  2899. +
  2900. +menu "Atheros AR71xx machine selection"
  2901. +
  2902. +config AR71XX_MACH_AP81
  2903. + bool "Atheros AP81 board support"
  2904. + select SOC_AR913X
  2905. + select AR71XX_DEV_M25P80
  2906. + select AR71XX_DEV_AR9XXX_WMAC
  2907. + select AR71XX_DEV_GPIO_BUTTONS
  2908. + select AR71XX_DEV_LEDS_GPIO
  2909. + select AR71XX_DEV_USB
  2910. + default n
  2911. +
  2912. +config AR71XX_MACH_AP83
  2913. + bool "Atheros AP83 board support"
  2914. + select SOC_AR913X
  2915. + select AR71XX_DEV_AR9XXX_WMAC
  2916. + select AR71XX_DEV_GPIO_BUTTONS
  2917. + select AR71XX_DEV_LEDS_GPIO
  2918. + select AR71XX_DEV_USB
  2919. + default n
  2920. +
  2921. +config AR71XX_MACH_AP96
  2922. + bool "Atheros AP96 board support"
  2923. + select SOC_AR71XX
  2924. + select AR71XX_DEV_M25P80
  2925. + select AR71XX_DEV_AP94_PCI if PCI
  2926. + select AR71XX_DEV_GPIO_BUTTONS
  2927. + select AR71XX_DEV_LEDS_GPIO
  2928. + select AR71XX_DEV_USB
  2929. + default n
  2930. +
  2931. +config AR71XX_MACH_AP121
  2932. + bool "Atheros AP121 board support"
  2933. + select AR71XX_DEV_M25P80
  2934. + select AR71XX_DEV_GPIO_BUTTONS
  2935. + select AR71XX_DEV_LEDS_GPIO
  2936. + select AR71XX_DEV_USB
  2937. + select AR71XX_DEV_AR9XXX_WMAC
  2938. + select SOC_AR933X
  2939. + default n
  2940. +
  2941. +config AR71XX_MACH_DB120
  2942. + bool "Atheros DB120 board support"
  2943. + select SOC_AR934X
  2944. + select AR71XX_DEV_AR9XXX_WMAC
  2945. + select AR71XX_DEV_DB120_PCI if PCI
  2946. + select AR71XX_DEV_GPIO_BUTTONS
  2947. + select AR71XX_DEV_LEDS_GPIO
  2948. + select AR71XX_DEV_USB
  2949. + default n
  2950. +
  2951. +config AR71XX_MACH_DIR_600_A1
  2952. + bool "D-Link DIR-600 rev. A1 support"
  2953. + select SOC_AR724X
  2954. + select AR71XX_DEV_AP91_PCI if PCI
  2955. + select AR71XX_DEV_M25P80
  2956. + select AR71XX_DEV_GPIO_BUTTONS
  2957. + select AR71XX_DEV_LEDS_GPIO
  2958. + select AR71XX_NVRAM
  2959. + default n
  2960. +
  2961. +config AR71XX_MACH_DIR_615_C1
  2962. + bool "D-Link DIR-615 rev. C1 support"
  2963. + select SOC_AR913X
  2964. + select AR71XX_DEV_M25P80
  2965. + select AR71XX_DEV_AR9XXX_WMAC
  2966. + select AR71XX_DEV_GPIO_BUTTONS
  2967. + select AR71XX_DEV_LEDS_GPIO
  2968. + select AR71XX_NVRAM
  2969. + default n
  2970. +
  2971. +config AR71XX_MACH_DIR_825_B1
  2972. + bool "D-Link DIR-825 rev. B1 board support"
  2973. + select SOC_AR71XX
  2974. + select AR71XX_DEV_M25P80
  2975. + select AR71XX_DEV_AP94_PCI if PCI
  2976. + select AR71XX_DEV_GPIO_BUTTONS
  2977. + select AR71XX_DEV_LEDS_GPIO
  2978. + select AR71XX_DEV_USB
  2979. + default n
  2980. +
  2981. +config AR71XX_MACH_JA76PF
  2982. + bool "jjPlus JA76PF board support"
  2983. + select SOC_AR71XX
  2984. + select AR71XX_DEV_M25P80
  2985. + select AR71XX_DEV_GPIO_BUTTONS
  2986. + select AR71XX_DEV_PB42_PCI if PCI
  2987. + select AR71XX_DEV_LEDS_GPIO
  2988. + select AR71XX_DEV_USB
  2989. + default n
  2990. +
  2991. +config AR71XX_MACH_JWAP003
  2992. + bool "jjPlus JWAP003 board support"
  2993. + select SOC_AR71XX
  2994. + select AR71XX_DEV_M25P80
  2995. + select AR71XX_DEV_GPIO_BUTTONS
  2996. + select AR71XX_DEV_PB42_PCI if PCI
  2997. + select AR71XX_DEV_USB
  2998. + default n
  2999. +
  3000. +config AR71XX_MACH_PB42
  3001. + bool "Atheros PB42 board support"
  3002. + select SOC_AR71XX
  3003. + select AR71XX_DEV_M25P80
  3004. + select AR71XX_DEV_GPIO_BUTTONS
  3005. + select AR71XX_DEV_PB42_PCI if PCI
  3006. + default n
  3007. +
  3008. +config AR71XX_MACH_PB44
  3009. + bool "Atheros PB44 board support"
  3010. + select SOC_AR71XX
  3011. + select AR71XX_DEV_GPIO_BUTTONS
  3012. + select AR71XX_DEV_PB42_PCI if PCI
  3013. + select AR71XX_DEV_LEDS_GPIO
  3014. + select AR71XX_DEV_USB
  3015. + default n
  3016. +
  3017. +config AR71XX_MACH_PB92
  3018. + bool "Atheros PB92 board support"
  3019. + select SOC_AR724X
  3020. + select AR71XX_DEV_GPIO_BUTTONS
  3021. + select AR71XX_DEV_PB9X_PCI if PCI
  3022. + select AR71XX_DEV_LEDS_GPIO
  3023. + select AR71XX_DEV_USB
  3024. + default n
  3025. +
  3026. +config AR71XX_MACH_AW_NR580
  3027. + bool "AzureWave AW-NR580 board support"
  3028. + select SOC_AR71XX
  3029. + select AR71XX_DEV_M25P80
  3030. + select AR71XX_DEV_GPIO_BUTTONS
  3031. + select AR71XX_DEV_PB42_PCI if PCI
  3032. + select AR71XX_DEV_LEDS_GPIO
  3033. + default n
  3034. +
  3035. +config AR71XX_MACH_WZR_HP_AG300H
  3036. + bool "Buffalo WZR-HP-AG300H board support"
  3037. + select SOC_AR71XX
  3038. + select AR71XX_DEV_M25P80
  3039. + select AR71XX_DEV_GPIO_BUTTONS
  3040. + select AR71XX_DEV_LEDS_GPIO
  3041. + select AR71XX_DEV_USB
  3042. + default n
  3043. +
  3044. +config AR71XX_MACH_WZR_HP_G300NH
  3045. + bool "Buffalo WZR-HP-G300NH board support"
  3046. + select SOC_AR913X
  3047. + select AR71XX_DEV_AR9XXX_WMAC
  3048. + select AR71XX_DEV_GPIO_BUTTONS
  3049. + select AR71XX_DEV_LEDS_GPIO
  3050. + select AR71XX_DEV_USB
  3051. + select RTL8366_SMI
  3052. + default n
  3053. +
  3054. +config AR71XX_MACH_WP543
  3055. + bool "Compex WP543/WPJ543 board support"
  3056. + select SOC_AR71XX
  3057. + select MYLOADER
  3058. + select AR71XX_DEV_M25P80
  3059. + select AR71XX_DEV_GPIO_BUTTONS
  3060. + select AR71XX_DEV_PB42_PCI if PCI
  3061. + select AR71XX_DEV_LEDS_GPIO
  3062. + select AR71XX_DEV_USB
  3063. + default n
  3064. +
  3065. +config AR71XX_MACH_WRT160NL
  3066. + bool "Linksys WRT160NL board support"
  3067. + select SOC_AR913X
  3068. + select AR71XX_DEV_M25P80
  3069. + select AR71XX_DEV_AR9XXX_WMAC
  3070. + select AR71XX_DEV_GPIO_BUTTONS
  3071. + select AR71XX_DEV_LEDS_GPIO
  3072. + select AR71XX_DEV_USB
  3073. + select AR71XX_NVRAM
  3074. + default n
  3075. +
  3076. +config AR71XX_MACH_WRT400N
  3077. + bool "Linksys WRT400N board support"
  3078. + select SOC_AR71XX
  3079. + select AR71XX_DEV_AP94_PCI if PCI
  3080. + select AR71XX_DEV_M25P80
  3081. + select AR71XX_DEV_GPIO_BUTTONS
  3082. + select AR71XX_DEV_LEDS_GPIO
  3083. + default n
  3084. +
  3085. +config AR71XX_MACH_RB4XX
  3086. + bool "MikroTik RouterBOARD 4xx series support"
  3087. + select SOC_AR71XX
  3088. + select AR71XX_DEV_GPIO_BUTTONS
  3089. + select AR71XX_DEV_LEDS_GPIO
  3090. + select AR71XX_DEV_USB
  3091. + default n
  3092. +
  3093. +config AR71XX_MACH_RB750
  3094. + bool "MikroTik RouterBOARD 750 support"
  3095. + select SOC_AR724X
  3096. + default n
  3097. +
  3098. +config AR71XX_MACH_WNDR3700
  3099. + bool "NETGEAR WNDR3700 board support"
  3100. + select SOC_AR71XX
  3101. + select AR71XX_DEV_M25P80
  3102. + select AR71XX_DEV_AP94_PCI if PCI
  3103. + select AR71XX_DEV_GPIO_BUTTONS
  3104. + select AR71XX_DEV_LEDS_GPIO
  3105. + select AR71XX_DEV_USB
  3106. + default n
  3107. +
  3108. +config AR71XX_MACH_WNR2000
  3109. + bool "NETGEAR WNR2000 board support"
  3110. + select SOC_AR913X
  3111. + select AR71XX_DEV_M25P80
  3112. + select AR71XX_DEV_AR9XXX_WMAC
  3113. + select AR71XX_DEV_GPIO_BUTTONS
  3114. + select AR71XX_DEV_LEDS_GPIO
  3115. + default n
  3116. +
  3117. +config AR71XX_MACH_MZK_W04NU
  3118. + bool "Planex MZK-W04NU board support"
  3119. + select SOC_AR913X
  3120. + select AR71XX_DEV_M25P80
  3121. + select AR71XX_DEV_AR9XXX_WMAC
  3122. + select AR71XX_DEV_GPIO_BUTTONS
  3123. + select AR71XX_DEV_LEDS_GPIO
  3124. + select AR71XX_DEV_USB
  3125. + default n
  3126. +
  3127. +config AR71XX_MACH_MZK_W300NH
  3128. + bool "Planex MZK-W300NH board support"
  3129. + select SOC_AR913X
  3130. + select AR71XX_DEV_M25P80
  3131. + select AR71XX_DEV_AR9XXX_WMAC
  3132. + select AR71XX_DEV_GPIO_BUTTONS
  3133. + select AR71XX_DEV_LEDS_GPIO
  3134. + default n
  3135. +
  3136. +config AR71XX_MACH_NBG460N
  3137. + bool "Zyxel NBG460N/550N/550NH board support"
  3138. + select SOC_AR913X
  3139. + select AR71XX_DEV_M25P80
  3140. + select AR71XX_DEV_AR9XXX_WMAC
  3141. + select AR71XX_DEV_GPIO_BUTTONS
  3142. + select AR71XX_DEV_LEDS_GPIO
  3143. + default n
  3144. +
  3145. +config AR71XX_MACH_TL_MR3X20
  3146. + bool "TP-LINK TL-MR3220/3420 support"
  3147. + select SOC_AR724X
  3148. + select AR71XX_DEV_M25P80
  3149. + select AR71XX_DEV_AP91_PCI if PCI
  3150. + select AR71XX_DEV_GPIO_BUTTONS
  3151. + select AR71XX_DEV_LEDS_GPIO
  3152. + select AR71XX_DEV_USB
  3153. + default n
  3154. +
  3155. +config AR71XX_MACH_TL_WA901ND
  3156. + bool "TP-LINK TL-WA901ND support"
  3157. + select SOC_AR724X
  3158. + select AR71XX_DEV_M25P80
  3159. + select AR71XX_DEV_AP91_PCI if PCI
  3160. + select AR71XX_DEV_GPIO_BUTTONS
  3161. + select AR71XX_DEV_LEDS_GPIO
  3162. + default n
  3163. +
  3164. +config AR71XX_MACH_TL_WA901ND_V2
  3165. + bool "TP-LINK TL-WA901ND v2 support"
  3166. + select SOC_AR913X
  3167. + select AR71XX_DEV_M25P80
  3168. + select AR71XX_DEV_AR9XXX_WMAC
  3169. + select AR71XX_DEV_GPIO_BUTTONS
  3170. + select AR71XX_DEV_LEDS_GPIO
  3171. + default n
  3172. +
  3173. +config AR71XX_MACH_TL_WR741ND
  3174. + bool "TP-LINK TL-WR741ND support"
  3175. + select SOC_AR724X
  3176. + select AR71XX_DEV_M25P80
  3177. + select AR71XX_DEV_AP91_PCI if PCI
  3178. + select AR71XX_DEV_GPIO_BUTTONS
  3179. + select AR71XX_DEV_LEDS_GPIO
  3180. + default n
  3181. +
  3182. +config AR71XX_MACH_TL_WR841N_V1
  3183. + bool "TP-LINK TL-WR841N v1 support"
  3184. + select SOC_AR71XX
  3185. + select AR71XX_DEV_M25P80
  3186. + select AR71XX_DEV_PB42_PCI if PCI
  3187. + select AR71XX_DEV_DSA
  3188. + select AR71XX_DEV_GPIO_BUTTONS
  3189. + select AR71XX_DEV_LEDS_GPIO
  3190. + default n
  3191. +
  3192. +config AR71XX_MACH_TL_WR941ND
  3193. + bool "TP-LINK TL-WR941ND support"
  3194. + select SOC_AR913X
  3195. + select AR71XX_DEV_M25P80
  3196. + select AR71XX_DEV_AR9XXX_WMAC
  3197. + select AR71XX_DEV_DSA
  3198. + select AR71XX_DEV_GPIO_BUTTONS
  3199. + select AR71XX_DEV_LEDS_GPIO
  3200. + default n
  3201. +
  3202. +config AR71XX_MACH_TL_WR1043ND
  3203. + bool "TP-LINK TL-WR1043ND support"
  3204. + select SOC_AR913X
  3205. + select AR71XX_DEV_M25P80
  3206. + select AR71XX_DEV_AR9XXX_WMAC
  3207. + select AR71XX_DEV_GPIO_BUTTONS
  3208. + select AR71XX_DEV_LEDS_GPIO
  3209. + select AR71XX_DEV_USB
  3210. + default n
  3211. +
  3212. +config AR71XX_MACH_TEW_632BRP
  3213. + bool "TRENDnet TEW-632BRP support"
  3214. + select SOC_AR913X
  3215. + select AR71XX_DEV_M25P80
  3216. + select AR71XX_DEV_AR9XXX_WMAC
  3217. + select AR71XX_DEV_GPIO_BUTTONS
  3218. + select AR71XX_DEV_LEDS_GPIO
  3219. + select AR71XX_NVRAM
  3220. + default n
  3221. +
  3222. +config AR71XX_MACH_UBNT
  3223. + bool "Ubiquiti AR71xx based boards support"
  3224. + select SOC_AR71XX
  3225. + select SOC_AR724X
  3226. + select AR71XX_DEV_M25P80
  3227. + select AR71XX_DEV_AP91_PCI if PCI
  3228. + select AR71XX_DEV_GPIO_BUTTONS
  3229. + select AR71XX_DEV_LEDS_GPIO
  3230. + select AR71XX_DEV_PB42_PCI if PCI
  3231. + select AR71XX_DEV_USB
  3232. + default n
  3233. +
  3234. +config AR71XX_MACH_EAP7660D
  3235. + bool "Senao EAP7660D support"
  3236. + select SOC_AR71XX
  3237. + select AR71XX_DEV_M25P80
  3238. + select AR71XX_DEV_GPIO_BUTTONS
  3239. + select AR71XX_DEV_LEDS_GPIO
  3240. + default n
  3241. +
  3242. +config AR71XX_MACH_ZCN_1523H
  3243. + bool "Zcomax ZCN-1523H support"
  3244. + select SOC_AR724X
  3245. + select AR71XX_DEV_M25P80
  3246. + select AR71XX_DEV_AP91_PCI if PCI
  3247. + select AR71XX_DEV_GPIO_BUTTONS
  3248. + select AR71XX_DEV_LEDS_GPIO
  3249. + default n
  3250. +
  3251. +endmenu
  3252. +
  3253. +config SOC_AR71XX
  3254. + bool
  3255. + select USB_ARCH_HAS_EHCI
  3256. + select USB_ARCH_HAS_OHCI
  3257. +
  3258. +config SOC_AR724X
  3259. + bool
  3260. + select USB_ARCH_HAS_EHCI
  3261. + select USB_ARCH_HAS_OHCI
  3262. +
  3263. +config SOC_AR913X
  3264. + bool
  3265. + select USB_ARCH_HAS_EHCI
  3266. +
  3267. +config SOC_AR934X
  3268. + bool
  3269. + select USB_ARCH_HAS_EHCI
  3270. +
  3271. +config AR71XX_DEV_M25P80
  3272. + def_bool n
  3273. +
  3274. +config AR71XX_DEV_AP91_PCI
  3275. + select AR71XX_PCI_ATH9K_FIXUP
  3276. + def_bool n
  3277. +
  3278. +config AR71XX_DEV_AP94_PCI
  3279. + select AR71XX_PCI_ATH9K_FIXUP
  3280. + def_bool n
  3281. +
  3282. +config AR71XX_DEV_AR9XXX_WMAC
  3283. + def_bool n
  3284. +
  3285. +config AR71XX_DEV_DB120_PCI
  3286. + select AR71XX_PCI_ATH9K_FIXUP
  3287. + def_bool n
  3288. +
  3289. +config AR71XX_DEV_DSA
  3290. + def_bool n
  3291. +
  3292. +config AR71XX_DEV_GPIO_BUTTONS
  3293. + def_bool n
  3294. +
  3295. +config AR71XX_DEV_LEDS_GPIO
  3296. + def_bool n
  3297. +
  3298. +config AR71XX_DEV_PB42_PCI
  3299. + def_bool n
  3300. +
  3301. +config AR71XX_DEV_PB9X_PCI
  3302. + def_bool n
  3303. +
  3304. +config AR71XX_DEV_USB
  3305. + def_bool n
  3306. +
  3307. +config AR71XX_NVRAM
  3308. + def_bool n
  3309. +
  3310. +config AR71XX_PCI_ATH9K_FIXUP
  3311. + def_bool n
  3312. +
  3313. +config SOC_AR933X
  3314. + bool
  3315. + select USB_ARCH_HAS_EHCI
  3316. +
  3317. +endif
  3318. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ap121.c linux-2.6.39/arch/mips/ar71xx/mach-ap121.c
  3319. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ap121.c 1970-01-01 01:00:00.000000000 +0100
  3320. +++ linux-2.6.39/arch/mips/ar71xx/mach-ap121.c 2011-08-24 02:41:55.477989660 +0200
  3321. @@ -0,0 +1,245 @@
  3322. +/*
  3323. + * Atheros AP121 board support
  3324. + *
  3325. + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  3326. + *
  3327. + * This program is free software; you can redistribute it and/or modify it
  3328. + * under the terms of the GNU General Public License version 2 as published
  3329. + * by the Free Software Foundation.
  3330. + */
  3331. +
  3332. +#include <linux/mtd/mtd.h>
  3333. +#include <linux/mtd/partitions.h>
  3334. +#include <linux/spi/flash.h>
  3335. +
  3336. +#include "machtype.h"
  3337. +#include "devices.h"
  3338. +#include "dev-ar9xxx-wmac.h"
  3339. +#include "dev-gpio-buttons.h"
  3340. +#include "dev-leds-gpio.h"
  3341. +#include "dev-m25p80.h"
  3342. +#include "dev-usb.h"
  3343. +
  3344. +#define AP121_GPIO_LED_WLAN 0
  3345. +#define AP121_GPIO_LED_USB 1
  3346. +
  3347. +#define AP121_GPIO_BTN_JUMPSTART 11
  3348. +#define AP121_GPIO_BTN_RESET 12
  3349. +
  3350. +#define AP121_KEYS_POLL_INTERVAL 20 /* msecs */
  3351. +#define AP121_KEYS_DEBOUNCE_INTERVAL (3 * AP121_KEYS_POLL_INTERVAL)
  3352. +
  3353. +#define AP121_MAC0_OFFSET 0x0000
  3354. +#define AP121_MAC1_OFFSET 0x0006
  3355. +#define AP121_CALDATA_OFFSET 0x1000
  3356. +#define AP121_WMAC_MAC_OFFSET 0x1002
  3357. +
  3358. +#define AP121_MINI_GPIO_LED_WLAN 0
  3359. +#define AP121_MINI_GPIO_BTN_JUMPSTART 12
  3360. +#define AP121_MINI_GPIO_BTN_RESET 11
  3361. +
  3362. +#ifdef CONFIG_MTD_PARTITIONS
  3363. +static struct mtd_partition ap121_parts[] = {
  3364. + {
  3365. + .name = "u-boot",
  3366. + .offset = 0,
  3367. + .size = 0x010000,
  3368. + .mask_flags = MTD_WRITEABLE,
  3369. + },
  3370. + {
  3371. + .name = "rootfs",
  3372. + .offset = 0x010000,
  3373. + .size = 0x130000,
  3374. + },
  3375. + {
  3376. + .name = "uImage",
  3377. + .offset = 0x140000,
  3378. + .size = 0x0a0000,
  3379. + },
  3380. + {
  3381. + .name = "NVRAM",
  3382. + .offset = 0x1e0000,
  3383. + .size = 0x010000,
  3384. + },
  3385. + {
  3386. + .name = "ART",
  3387. + .offset = 0x1f0000,
  3388. + .size = 0x010000,
  3389. + .mask_flags = MTD_WRITEABLE,
  3390. + },
  3391. +};
  3392. +#define ap121_nr_parts ARRAY_SIZE(ap121_parts)
  3393. +
  3394. +static struct mtd_partition ap121_mini_parts[] = {
  3395. + {
  3396. + .name = "u-boot",
  3397. + .offset = 0,
  3398. + .size = 0x040000,
  3399. + .mask_flags = MTD_WRITEABLE,
  3400. + },
  3401. + {
  3402. + .name = "u-boot-env",
  3403. + .offset = 0x040000,
  3404. + .size = 0x010000,
  3405. + .mask_flags = MTD_WRITEABLE,
  3406. + },
  3407. + {
  3408. + .name = "rootfs",
  3409. + .offset = 0x050000,
  3410. + .size = 0x2b0000,
  3411. + },
  3412. + {
  3413. + .name = "uImage",
  3414. + .offset = 0x300000,
  3415. + .size = 0x0e0000,
  3416. + },
  3417. + {
  3418. + .name = "NVRAM",
  3419. + .offset = 0x3e0000,
  3420. + .size = 0x010000,
  3421. + },
  3422. + {
  3423. + .name = "ART",
  3424. + .offset = 0x3f0000,
  3425. + .size = 0x010000,
  3426. + .mask_flags = MTD_WRITEABLE,
  3427. + },
  3428. +};
  3429. +
  3430. +#define ap121_mini_nr_parts ARRAY_SIZE(ap121_parts)
  3431. +
  3432. +#else
  3433. +#define ap121_parts NULL
  3434. +#define ap121_nr_parts 0
  3435. +#define ap121_mini_parts NULL
  3436. +#define ap121_mini_nr_parts 0
  3437. +#endif /* CONFIG_MTD_PARTITIONS */
  3438. +
  3439. +static struct flash_platform_data ap121_flash_data = {
  3440. + .parts = ap121_parts,
  3441. + .nr_parts = ap121_nr_parts,
  3442. +};
  3443. +
  3444. +static struct gpio_led ap121_leds_gpio[] __initdata = {
  3445. + {
  3446. + .name = "ap121:green:usb",
  3447. + .gpio = AP121_GPIO_LED_USB,
  3448. + .active_low = 0,
  3449. + },
  3450. + {
  3451. + .name = "ap121:green:wlan",
  3452. + .gpio = AP121_GPIO_LED_WLAN,
  3453. + .active_low = 0,
  3454. + },
  3455. +};
  3456. +
  3457. +static struct gpio_keys_button ap121_gpio_keys[] __initdata = {
  3458. + {
  3459. + .desc = "jumpstart button",
  3460. + .type = EV_KEY,
  3461. + .code = KEY_WPS_BUTTON,
  3462. + .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
  3463. + .gpio = AP121_GPIO_BTN_JUMPSTART,
  3464. + .active_low = 1,
  3465. + },
  3466. + {
  3467. + .desc = "reset button",
  3468. + .type = EV_KEY,
  3469. + .code = KEY_RESTART,
  3470. + .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
  3471. + .gpio = AP121_GPIO_BTN_RESET,
  3472. + .active_low = 1,
  3473. + }
  3474. +};
  3475. +
  3476. +static struct gpio_led ap121_mini_leds_gpio[] __initdata = {
  3477. + {
  3478. + .name = "ap121:green:wlan",
  3479. + .gpio = AP121_MINI_GPIO_LED_WLAN,
  3480. + .active_low = 0,
  3481. + },
  3482. +};
  3483. +
  3484. +static struct gpio_keys_button ap121_mini_gpio_keys[] __initdata = {
  3485. + {
  3486. + .desc = "jumpstart button",
  3487. + .type = EV_KEY,
  3488. + .code = KEY_WPS_BUTTON,
  3489. + .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
  3490. + .gpio = AP121_MINI_GPIO_BTN_JUMPSTART,
  3491. + .active_low = 1,
  3492. + },
  3493. + {
  3494. + .desc = "reset button",
  3495. + .type = EV_KEY,
  3496. + .code = KEY_RESTART,
  3497. + .debounce_interval = AP121_KEYS_DEBOUNCE_INTERVAL,
  3498. + .gpio = AP121_MINI_GPIO_BTN_RESET,
  3499. + .active_low = 1,
  3500. + }
  3501. +};
  3502. +
  3503. +static void __init ap121_common_setup(void)
  3504. +{
  3505. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  3506. +
  3507. + ar71xx_add_device_m25p80(&ap121_flash_data);
  3508. +
  3509. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, art + AP121_MAC0_OFFSET, 0);
  3510. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, art + AP121_MAC1_OFFSET, 0);
  3511. +
  3512. + /* WAN port */
  3513. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3514. + ar71xx_eth0_data.speed = SPEED_100;
  3515. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3516. + ar71xx_eth0_data.phy_mask = BIT(4);
  3517. +
  3518. + /* LAN ports */
  3519. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3520. + ar71xx_eth1_data.speed = SPEED_1000;
  3521. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  3522. + ar71xx_eth1_data.has_ar7240_switch = 1;
  3523. +
  3524. + ar71xx_add_device_mdio(0x0);
  3525. + ar71xx_add_device_eth(1);
  3526. + ar71xx_add_device_eth(0);
  3527. +
  3528. + ar9xxx_add_device_wmac(art + AP121_CALDATA_OFFSET,
  3529. + art + AP121_WMAC_MAC_OFFSET);
  3530. +}
  3531. +
  3532. +static void __init ap121_setup(void)
  3533. +{
  3534. + ap121_flash_data.parts = ap121_parts;
  3535. + ap121_flash_data.nr_parts = ap121_nr_parts;
  3536. +
  3537. + ap121_common_setup();
  3538. +
  3539. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap121_leds_gpio),
  3540. + ap121_leds_gpio);
  3541. + ar71xx_register_gpio_keys_polled(-1, AP121_KEYS_POLL_INTERVAL,
  3542. + ARRAY_SIZE(ap121_gpio_keys),
  3543. + ap121_gpio_keys);
  3544. +
  3545. + ar71xx_add_device_usb();
  3546. +}
  3547. +
  3548. +static void __init ap121_mini_setup(void)
  3549. +{
  3550. + ap121_flash_data.parts = ap121_mini_parts;
  3551. + ap121_flash_data.nr_parts = ap121_mini_nr_parts;
  3552. +
  3553. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap121_mini_leds_gpio),
  3554. + ap121_mini_leds_gpio);
  3555. + ar71xx_register_gpio_keys_polled(-1, AP121_KEYS_POLL_INTERVAL,
  3556. + ARRAY_SIZE(ap121_mini_gpio_keys),
  3557. + ap121_mini_gpio_keys);
  3558. +
  3559. + ap121_common_setup();
  3560. +}
  3561. +
  3562. +MIPS_MACHINE(AR71XX_MACH_AP121, "AP121", "Atheros AP121",
  3563. + ap121_setup);
  3564. +
  3565. +MIPS_MACHINE(AR71XX_MACH_AP121_MINI, "AP121-MINI", "Atheros AP121-MINI",
  3566. + ap121_mini_setup);
  3567. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ap81.c linux-2.6.39/arch/mips/ar71xx/mach-ap81.c
  3568. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ap81.c 1970-01-01 01:00:00.000000000 +0100
  3569. +++ linux-2.6.39/arch/mips/ar71xx/mach-ap81.c 2011-08-24 02:41:55.477989660 +0200
  3570. @@ -0,0 +1,142 @@
  3571. +/*
  3572. + * Atheros AP81 board support
  3573. + *
  3574. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  3575. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  3576. + *
  3577. + * This program is free software; you can redistribute it and/or modify it
  3578. + * under the terms of the GNU General Public License version 2 as published
  3579. + * by the Free Software Foundation.
  3580. + */
  3581. +
  3582. +#include <linux/mtd/mtd.h>
  3583. +#include <linux/mtd/partitions.h>
  3584. +
  3585. +#include <asm/mach-ar71xx/ar71xx.h>
  3586. +
  3587. +#include "machtype.h"
  3588. +#include "devices.h"
  3589. +#include "dev-m25p80.h"
  3590. +#include "dev-ar9xxx-wmac.h"
  3591. +#include "dev-gpio-buttons.h"
  3592. +#include "dev-leds-gpio.h"
  3593. +#include "dev-usb.h"
  3594. +
  3595. +#define AP81_GPIO_LED_STATUS 1
  3596. +#define AP81_GPIO_LED_AOSS 3
  3597. +#define AP81_GPIO_LED_WLAN 6
  3598. +#define AP81_GPIO_LED_POWER 14
  3599. +
  3600. +#define AP81_GPIO_BTN_SW4 12
  3601. +#define AP81_GPIO_BTN_SW1 21
  3602. +
  3603. +#define AP81_KEYS_POLL_INTERVAL 20 /* msecs */
  3604. +#define AP81_KEYS_DEBOUNCE_INTERVAL (3 * AP81_KEYS_POLL_INTERVAL)
  3605. +
  3606. +#ifdef CONFIG_MTD_PARTITIONS
  3607. +static struct mtd_partition ap81_partitions[] = {
  3608. + {
  3609. + .name = "u-boot",
  3610. + .offset = 0,
  3611. + .size = 0x040000,
  3612. + .mask_flags = MTD_WRITEABLE,
  3613. + }, {
  3614. + .name = "u-boot-env",
  3615. + .offset = 0x040000,
  3616. + .size = 0x010000,
  3617. + }, {
  3618. + .name = "rootfs",
  3619. + .offset = 0x050000,
  3620. + .size = 0x500000,
  3621. + }, {
  3622. + .name = "uImage",
  3623. + .offset = 0x550000,
  3624. + .size = 0x100000,
  3625. + }, {
  3626. + .name = "ART",
  3627. + .offset = 0x650000,
  3628. + .size = 0x1b0000,
  3629. + .mask_flags = MTD_WRITEABLE,
  3630. + }
  3631. +};
  3632. +#endif /* CONFIG_MTD_PARTITIONS */
  3633. +
  3634. +static struct flash_platform_data ap81_flash_data = {
  3635. +#ifdef CONFIG_MTD_PARTITIONS
  3636. + .parts = ap81_partitions,
  3637. + .nr_parts = ARRAY_SIZE(ap81_partitions),
  3638. +#endif
  3639. +};
  3640. +
  3641. +static struct gpio_led ap81_leds_gpio[] __initdata = {
  3642. + {
  3643. + .name = "ap81:green:status",
  3644. + .gpio = AP81_GPIO_LED_STATUS,
  3645. + .active_low = 1,
  3646. + }, {
  3647. + .name = "ap81:amber:aoss",
  3648. + .gpio = AP81_GPIO_LED_AOSS,
  3649. + .active_low = 1,
  3650. + }, {
  3651. + .name = "ap81:green:wlan",
  3652. + .gpio = AP81_GPIO_LED_WLAN,
  3653. + .active_low = 1,
  3654. + }, {
  3655. + .name = "ap81:green:power",
  3656. + .gpio = AP81_GPIO_LED_POWER,
  3657. + .active_low = 1,
  3658. + }
  3659. +};
  3660. +
  3661. +static struct gpio_keys_button ap81_gpio_keys[] __initdata = {
  3662. + {
  3663. + .desc = "sw1",
  3664. + .type = EV_KEY,
  3665. + .code = BTN_0,
  3666. + .debounce_interval = AP81_KEYS_DEBOUNCE_INTERVAL,
  3667. + .gpio = AP81_GPIO_BTN_SW1,
  3668. + .active_low = 1,
  3669. + }, {
  3670. + .desc = "sw4",
  3671. + .type = EV_KEY,
  3672. + .code = BTN_1,
  3673. + .debounce_interval = AP81_KEYS_DEBOUNCE_INTERVAL,
  3674. + .gpio = AP81_GPIO_BTN_SW4,
  3675. + .active_low = 1,
  3676. + }
  3677. +};
  3678. +
  3679. +static void __init ap81_setup(void)
  3680. +{
  3681. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3682. +
  3683. + ar71xx_add_device_mdio(0x0);
  3684. +
  3685. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, eeprom, 0);
  3686. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3687. + ar71xx_eth0_data.speed = SPEED_100;
  3688. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3689. + ar71xx_eth0_data.has_ar8216 = 1;
  3690. +
  3691. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, eeprom, 1);
  3692. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3693. + ar71xx_eth1_data.phy_mask = 0x10;
  3694. +
  3695. + ar71xx_add_device_eth(0);
  3696. + ar71xx_add_device_eth(1);
  3697. +
  3698. + ar71xx_add_device_usb();
  3699. +
  3700. + ar71xx_add_device_m25p80(&ap81_flash_data);
  3701. +
  3702. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap81_leds_gpio),
  3703. + ap81_leds_gpio);
  3704. +
  3705. + ar71xx_register_gpio_keys_polled(-1, AP81_KEYS_POLL_INTERVAL,
  3706. + ARRAY_SIZE(ap81_gpio_keys),
  3707. + ap81_gpio_keys);
  3708. +
  3709. + ar9xxx_add_device_wmac(eeprom, NULL);
  3710. +}
  3711. +
  3712. +MIPS_MACHINE(AR71XX_MACH_AP81, "AP81", "Atheros AP81", ap81_setup);
  3713. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ap83.c linux-2.6.39/arch/mips/ar71xx/mach-ap83.c
  3714. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ap83.c 1970-01-01 01:00:00.000000000 +0100
  3715. +++ linux-2.6.39/arch/mips/ar71xx/mach-ap83.c 2011-08-24 02:41:55.477989660 +0200
  3716. @@ -0,0 +1,267 @@
  3717. +/*
  3718. + * Atheros AP83 board support
  3719. + *
  3720. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3721. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3722. + *
  3723. + * This program is free software; you can redistribute it and/or modify it
  3724. + * under the terms of the GNU General Public License version 2 as published
  3725. + * by the Free Software Foundation.
  3726. + */
  3727. +
  3728. +#include <linux/delay.h>
  3729. +#include <linux/platform_device.h>
  3730. +#include <linux/mtd/mtd.h>
  3731. +#include <linux/mtd/partitions.h>
  3732. +#include <linux/spi/spi.h>
  3733. +#include <linux/spi/spi_gpio.h>
  3734. +#include <linux/spi/vsc7385.h>
  3735. +
  3736. +#include <asm/mach-ar71xx/ar71xx.h>
  3737. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  3738. +
  3739. +#include "machtype.h"
  3740. +#include "devices.h"
  3741. +#include "dev-ar9xxx-wmac.h"
  3742. +#include "dev-gpio-buttons.h"
  3743. +#include "dev-leds-gpio.h"
  3744. +#include "dev-usb.h"
  3745. +
  3746. +#define AP83_GPIO_LED_WLAN 6
  3747. +#define AP83_GPIO_LED_POWER 14
  3748. +#define AP83_GPIO_LED_JUMPSTART 15
  3749. +#define AP83_GPIO_BTN_JUMPSTART 12
  3750. +#define AP83_GPIO_BTN_RESET 21
  3751. +
  3752. +#define AP83_050_GPIO_VSC7385_CS 1
  3753. +#define AP83_050_GPIO_VSC7385_MISO 3
  3754. +#define AP83_050_GPIO_VSC7385_MOSI 16
  3755. +#define AP83_050_GPIO_VSC7385_SCK 17
  3756. +
  3757. +#define AP83_KEYS_POLL_INTERVAL 20 /* msecs */
  3758. +#define AP83_KEYS_DEBOUNCE_INTERVAL (3 * AP83_KEYS_POLL_INTERVAL)
  3759. +
  3760. +#ifdef CONFIG_MTD_PARTITIONS
  3761. +static struct mtd_partition ap83_flash_partitions[] = {
  3762. + {
  3763. + .name = "u-boot",
  3764. + .offset = 0,
  3765. + .size = 0x040000,
  3766. + .mask_flags = MTD_WRITEABLE,
  3767. + }, {
  3768. + .name = "u-boot-env",
  3769. + .offset = 0x040000,
  3770. + .size = 0x020000,
  3771. + .mask_flags = MTD_WRITEABLE,
  3772. + }, {
  3773. + .name = "kernel",
  3774. + .offset = 0x060000,
  3775. + .size = 0x140000,
  3776. + }, {
  3777. + .name = "rootfs",
  3778. + .offset = 0x1a0000,
  3779. + .size = 0x650000,
  3780. + }, {
  3781. + .name = "art",
  3782. + .offset = 0x7f0000,
  3783. + .size = 0x010000,
  3784. + .mask_flags = MTD_WRITEABLE,
  3785. + }, {
  3786. + .name = "firmware",
  3787. + .offset = 0x060000,
  3788. + .size = 0x790000,
  3789. + }
  3790. +};
  3791. +#endif /* CONFIG_MTD_PARTITIONS */
  3792. +
  3793. +static struct ar91xx_flash_platform_data ap83_flash_data = {
  3794. + .width = 2,
  3795. +#ifdef CONFIG_MTD_PARTITIONS
  3796. + .parts = ap83_flash_partitions,
  3797. + .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
  3798. +#endif
  3799. +};
  3800. +
  3801. +static struct resource ap83_flash_resources[] = {
  3802. + [0] = {
  3803. + .start = AR71XX_SPI_BASE,
  3804. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3805. + .flags = IORESOURCE_MEM,
  3806. + },
  3807. +};
  3808. +
  3809. +static struct platform_device ap83_flash_device = {
  3810. + .name = "ar91xx-flash",
  3811. + .id = -1,
  3812. + .resource = ap83_flash_resources,
  3813. + .num_resources = ARRAY_SIZE(ap83_flash_resources),
  3814. + .dev = {
  3815. + .platform_data = &ap83_flash_data,
  3816. + }
  3817. +};
  3818. +
  3819. +static struct gpio_led ap83_leds_gpio[] __initdata = {
  3820. + {
  3821. + .name = "ap83:green:jumpstart",
  3822. + .gpio = AP83_GPIO_LED_JUMPSTART,
  3823. + .active_low = 0,
  3824. + }, {
  3825. + .name = "ap83:green:power",
  3826. + .gpio = AP83_GPIO_LED_POWER,
  3827. + .active_low = 0,
  3828. + }, {
  3829. + .name = "ap83:green:wlan",
  3830. + .gpio = AP83_GPIO_LED_WLAN,
  3831. + .active_low = 0,
  3832. + },
  3833. +};
  3834. +
  3835. +static struct gpio_keys_button ap83_gpio_keys[] __initdata = {
  3836. + {
  3837. + .desc = "soft_reset",
  3838. + .type = EV_KEY,
  3839. + .code = KEY_RESTART,
  3840. + .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
  3841. + .gpio = AP83_GPIO_BTN_RESET,
  3842. + .active_low = 1,
  3843. + }, {
  3844. + .desc = "jumpstart",
  3845. + .type = EV_KEY,
  3846. + .code = KEY_WPS_BUTTON,
  3847. + .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
  3848. + .gpio = AP83_GPIO_BTN_JUMPSTART,
  3849. + .active_low = 1,
  3850. + }
  3851. +};
  3852. +
  3853. +static struct resource ap83_040_spi_resources[] = {
  3854. + [0] = {
  3855. + .start = AR71XX_SPI_BASE,
  3856. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3857. + .flags = IORESOURCE_MEM,
  3858. + },
  3859. +};
  3860. +
  3861. +static struct platform_device ap83_040_spi_device = {
  3862. + .name = "ap83-spi",
  3863. + .id = 0,
  3864. + .resource = ap83_040_spi_resources,
  3865. + .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
  3866. +};
  3867. +
  3868. +static struct spi_gpio_platform_data ap83_050_spi_data = {
  3869. + .miso = AP83_050_GPIO_VSC7385_MISO,
  3870. + .mosi = AP83_050_GPIO_VSC7385_MOSI,
  3871. + .sck = AP83_050_GPIO_VSC7385_SCK,
  3872. + .num_chipselect = 1,
  3873. +};
  3874. +
  3875. +static struct platform_device ap83_050_spi_device = {
  3876. + .name = "spi_gpio",
  3877. + .id = 0,
  3878. + .dev = {
  3879. + .platform_data = &ap83_050_spi_data,
  3880. + }
  3881. +};
  3882. +
  3883. +static void ap83_vsc7385_reset(void)
  3884. +{
  3885. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  3886. + udelay(10);
  3887. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  3888. + mdelay(50);
  3889. +}
  3890. +
  3891. +static struct vsc7385_platform_data ap83_vsc7385_data = {
  3892. + .reset = ap83_vsc7385_reset,
  3893. + .ucode_name = "vsc7385_ucode_ap83.bin",
  3894. + .mac_cfg = {
  3895. + .tx_ipg = 6,
  3896. + .bit2 = 0,
  3897. + .clk_sel = 3,
  3898. + },
  3899. +};
  3900. +
  3901. +static struct spi_board_info ap83_spi_info[] = {
  3902. + {
  3903. + .bus_num = 0,
  3904. + .chip_select = 0,
  3905. + .max_speed_hz = 25000000,
  3906. + .modalias = "spi-vsc7385",
  3907. + .platform_data = &ap83_vsc7385_data,
  3908. + .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
  3909. + }
  3910. +};
  3911. +
  3912. +static void __init ap83_generic_setup(void)
  3913. +{
  3914. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3915. +
  3916. + ar71xx_add_device_mdio(0xfffffffe);
  3917. +
  3918. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, eeprom, 0);
  3919. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3920. + ar71xx_eth0_data.phy_mask = 0x1;
  3921. +
  3922. + ar71xx_add_device_eth(0);
  3923. +
  3924. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, eeprom, 1);
  3925. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3926. + ar71xx_eth1_data.speed = SPEED_1000;
  3927. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  3928. +
  3929. + ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
  3930. +
  3931. + ar71xx_add_device_eth(1);
  3932. +
  3933. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
  3934. + ap83_leds_gpio);
  3935. +
  3936. + ar71xx_register_gpio_keys_polled(-1, AP83_KEYS_POLL_INTERVAL,
  3937. + ARRAY_SIZE(ap83_gpio_keys),
  3938. + ap83_gpio_keys);
  3939. +
  3940. + ar71xx_add_device_usb();
  3941. +
  3942. + ar9xxx_add_device_wmac(eeprom, NULL);
  3943. +
  3944. + platform_device_register(&ap83_flash_device);
  3945. +
  3946. + spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
  3947. +}
  3948. +
  3949. +static void __init ap83_040_setup(void)
  3950. +{
  3951. + ap83_flash_data.is_shared = 1;
  3952. + ap83_generic_setup();
  3953. + platform_device_register(&ap83_040_spi_device);
  3954. +}
  3955. +
  3956. +static void __init ap83_050_setup(void)
  3957. +{
  3958. + ap83_generic_setup();
  3959. + platform_device_register(&ap83_050_spi_device);
  3960. +}
  3961. +
  3962. +static void __init ap83_setup(void)
  3963. +{
  3964. + u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
  3965. + unsigned int board_version;
  3966. +
  3967. + board_version = (unsigned int)(board_id[0] - '0');
  3968. + board_version += ((unsigned int)(board_id[1] - '0')) * 10;
  3969. +
  3970. + switch (board_version) {
  3971. + case 40:
  3972. + ap83_040_setup();
  3973. + break;
  3974. + case 50:
  3975. + ap83_050_setup();
  3976. + break;
  3977. + default:
  3978. + printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
  3979. + board_version);
  3980. + }
  3981. +}
  3982. +
  3983. +MIPS_MACHINE(AR71XX_MACH_AP83, "AP83", "Atheros AP83", ap83_setup);
  3984. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ap96.c linux-2.6.39/arch/mips/ar71xx/mach-ap96.c
  3985. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ap96.c 1970-01-01 01:00:00.000000000 +0100
  3986. +++ linux-2.6.39/arch/mips/ar71xx/mach-ap96.c 2011-08-24 02:41:55.477989660 +0200
  3987. @@ -0,0 +1,180 @@
  3988. +/*
  3989. + * Atheros AP96 board support
  3990. + *
  3991. + * Copyright (C) 2009 Marco Porsch
  3992. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  3993. + * Copyright (C) 2010 Atheros Communications
  3994. + *
  3995. + * This program is free software; you can redistribute it and/or modify it
  3996. + * under the terms of the GNU General Public License version 2 as published
  3997. + * by the Free Software Foundation.
  3998. + */
  3999. +
  4000. +#include <linux/platform_device.h>
  4001. +#include <linux/mtd/mtd.h>
  4002. +#include <linux/mtd/partitions.h>
  4003. +#include <linux/delay.h>
  4004. +
  4005. +#include <asm/mach-ar71xx/ar71xx.h>
  4006. +
  4007. +#include "machtype.h"
  4008. +#include "devices.h"
  4009. +#include "dev-m25p80.h"
  4010. +#include "dev-ap94-pci.h"
  4011. +#include "dev-gpio-buttons.h"
  4012. +#include "dev-leds-gpio.h"
  4013. +#include "dev-usb.h"
  4014. +
  4015. +#define AP96_GPIO_LED_12_GREEN 0
  4016. +#define AP96_GPIO_LED_3_GREEN 1
  4017. +#define AP96_GPIO_LED_2_GREEN 2
  4018. +#define AP96_GPIO_LED_WPS_GREEN 4
  4019. +#define AP96_GPIO_LED_5_GREEN 5
  4020. +#define AP96_GPIO_LED_4_ORANGE 6
  4021. +
  4022. +/* Reset button - next to the power connector */
  4023. +#define AP96_GPIO_BTN_RESET 3
  4024. +/* WPS button - next to a led on right */
  4025. +#define AP96_GPIO_BTN_WPS 8
  4026. +
  4027. +#define AP96_KEYS_POLL_INTERVAL 20 /* msecs */
  4028. +#define AP96_KEYS_DEBOUNCE_INTERVAL (3 * AP96_KEYS_POLL_INTERVAL)
  4029. +
  4030. +#define AP96_WMAC0_MAC_OFFSET 0x120c
  4031. +#define AP96_WMAC1_MAC_OFFSET 0x520c
  4032. +#define AP96_CALDATA0_OFFSET 0x1000
  4033. +#define AP96_CALDATA1_OFFSET 0x5000
  4034. +
  4035. +#ifdef CONFIG_MTD_PARTITIONS
  4036. +static struct mtd_partition ap96_partitions[] = {
  4037. + {
  4038. + .name = "uboot",
  4039. + .offset = 0,
  4040. + .size = 0x030000,
  4041. + .mask_flags = MTD_WRITEABLE,
  4042. + }, {
  4043. + .name = "env",
  4044. + .offset = 0x030000,
  4045. + .size = 0x010000,
  4046. + .mask_flags = MTD_WRITEABLE,
  4047. + }, {
  4048. + .name = "rootfs",
  4049. + .offset = 0x040000,
  4050. + .size = 0x600000,
  4051. + }, {
  4052. + .name = "uImage",
  4053. + .offset = 0x640000,
  4054. + .size = 0x1b0000,
  4055. + }, {
  4056. + .name = "caldata",
  4057. + .offset = 0x7f0000,
  4058. + .size = 0x010000,
  4059. + .mask_flags = MTD_WRITEABLE,
  4060. + }
  4061. +};
  4062. +#endif /* CONFIG_MTD_PARTITIONS */
  4063. +
  4064. +static struct flash_platform_data ap96_flash_data = {
  4065. +#ifdef CONFIG_MTD_PARTITIONS
  4066. + .parts = ap96_partitions,
  4067. + .nr_parts = ARRAY_SIZE(ap96_partitions),
  4068. +#endif
  4069. +};
  4070. +
  4071. +/*
  4072. + * AP96 has 12 unlabeled leds in the front; these are numbered from 1 to 12
  4073. + * below (from left to right on the board). Led 1 seems to be on whenever the
  4074. + * board is powered. Led 11 shows LAN link activity actity. Led 3 is orange;
  4075. + * others are green.
  4076. + *
  4077. + * In addition, there is one led next to a button on the right side for WPS.
  4078. + */
  4079. +static struct gpio_led ap96_leds_gpio[] __initdata = {
  4080. + {
  4081. + .name = "ap96:green:led2",
  4082. + .gpio = AP96_GPIO_LED_2_GREEN,
  4083. + .active_low = 1,
  4084. + }, {
  4085. + .name = "ap96:green:led3",
  4086. + .gpio = AP96_GPIO_LED_3_GREEN,
  4087. + .active_low = 1,
  4088. + }, {
  4089. + .name = "ap96:orange:led4",
  4090. + .gpio = AP96_GPIO_LED_4_ORANGE,
  4091. + .active_low = 1,
  4092. + }, {
  4093. + .name = "ap96:green:led5",
  4094. + .gpio = AP96_GPIO_LED_5_GREEN,
  4095. + .active_low = 1,
  4096. + }, {
  4097. + .name = "ap96:green:led12",
  4098. + .gpio = AP96_GPIO_LED_12_GREEN,
  4099. + .active_low = 1,
  4100. + }, { /* next to a button on right */
  4101. + .name = "ap96:green:wps",
  4102. + .gpio = AP96_GPIO_LED_WPS_GREEN,
  4103. + .active_low = 1,
  4104. + }
  4105. +};
  4106. +
  4107. +static struct gpio_keys_button ap96_gpio_keys[] __initdata = {
  4108. + {
  4109. + .desc = "reset",
  4110. + .type = EV_KEY,
  4111. + .code = KEY_RESTART,
  4112. + .debounce_interval = AP96_KEYS_DEBOUNCE_INTERVAL,
  4113. + .gpio = AP96_GPIO_BTN_RESET,
  4114. + .active_low = 1,
  4115. + }, {
  4116. + .desc = "wps",
  4117. + .type = EV_KEY,
  4118. + .code = KEY_WPS_BUTTON,
  4119. + .debounce_interval = AP96_KEYS_DEBOUNCE_INTERVAL,
  4120. + .gpio = AP96_GPIO_BTN_WPS,
  4121. + .active_low = 1,
  4122. + }
  4123. +};
  4124. +
  4125. +#define AP96_WAN_PHYMASK 0x10
  4126. +#define AP96_LAN_PHYMASK 0x0f
  4127. +
  4128. +static void __init ap96_setup(void)
  4129. +{
  4130. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  4131. +
  4132. + ar71xx_add_device_mdio(~(AP96_WAN_PHYMASK | AP96_LAN_PHYMASK));
  4133. +
  4134. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, art, 0);
  4135. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4136. + ar71xx_eth0_data.phy_mask = AP96_LAN_PHYMASK;
  4137. + ar71xx_eth0_data.speed = SPEED_1000;
  4138. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4139. +
  4140. + ar71xx_add_device_eth(0);
  4141. +
  4142. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, art, 1);
  4143. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4144. + ar71xx_eth1_data.phy_mask = AP96_WAN_PHYMASK;
  4145. +
  4146. + ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
  4147. +
  4148. + ar71xx_add_device_eth(1);
  4149. +
  4150. + ar71xx_add_device_usb();
  4151. +
  4152. + ar71xx_add_device_m25p80(&ap96_flash_data);
  4153. +
  4154. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap96_leds_gpio),
  4155. + ap96_leds_gpio);
  4156. +
  4157. + ar71xx_register_gpio_keys_polled(-1, AP96_KEYS_POLL_INTERVAL,
  4158. + ARRAY_SIZE(ap96_gpio_keys),
  4159. + ap96_gpio_keys);
  4160. +
  4161. + ap94_pci_init(art + AP96_CALDATA0_OFFSET,
  4162. + art + AP96_WMAC0_MAC_OFFSET,
  4163. + art + AP96_CALDATA1_OFFSET,
  4164. + art + AP96_WMAC1_MAC_OFFSET);
  4165. +}
  4166. +
  4167. +MIPS_MACHINE(AR71XX_MACH_AP96, "AP96", "Atheros AP96", ap96_setup);
  4168. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-aw-nr580.c linux-2.6.39/arch/mips/ar71xx/mach-aw-nr580.c
  4169. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-aw-nr580.c 1970-01-01 01:00:00.000000000 +0100
  4170. +++ linux-2.6.39/arch/mips/ar71xx/mach-aw-nr580.c 2011-08-24 02:41:55.487989871 +0200
  4171. @@ -0,0 +1,102 @@
  4172. +/*
  4173. + * AzureWave AW-NR580 board support
  4174. + *
  4175. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4176. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4177. + *
  4178. + * This program is free software; you can redistribute it and/or modify it
  4179. + * under the terms of the GNU General Public License version 2 as published
  4180. + * by the Free Software Foundation.
  4181. + */
  4182. +
  4183. +#include <linux/mtd/mtd.h>
  4184. +#include <linux/mtd/partitions.h>
  4185. +
  4186. +#include <asm/mips_machine.h>
  4187. +#include <asm/mach-ar71xx/ar71xx.h>
  4188. +
  4189. +#include "machtype.h"
  4190. +#include "devices.h"
  4191. +#include "dev-m25p80.h"
  4192. +#include "dev-gpio-buttons.h"
  4193. +#include "dev-pb42-pci.h"
  4194. +#include "dev-leds-gpio.h"
  4195. +
  4196. +#define AW_NR580_GPIO_LED_READY_RED 0
  4197. +#define AW_NR580_GPIO_LED_WLAN 1
  4198. +#define AW_NR580_GPIO_LED_READY_GREEN 2
  4199. +#define AW_NR580_GPIO_LED_WPS_GREEN 4
  4200. +#define AW_NR580_GPIO_LED_WPS_AMBER 5
  4201. +
  4202. +#define AW_NR580_GPIO_BTN_WPS 3
  4203. +#define AW_NR580_GPIO_BTN_RESET 11
  4204. +
  4205. +#define AW_NR580_KEYS_POLL_INTERVAL 20 /* msecs */
  4206. +#define AW_NR580_KEYS_DEBOUNCE_INTERVAL (3 * AW_NR580_KEYS_POLL_INTERVAL)
  4207. +
  4208. +static struct gpio_led aw_nr580_leds_gpio[] __initdata = {
  4209. + {
  4210. + .name = "aw-nr580:red:ready",
  4211. + .gpio = AW_NR580_GPIO_LED_READY_RED,
  4212. + .active_low = 0,
  4213. + }, {
  4214. + .name = "aw-nr580:green:ready",
  4215. + .gpio = AW_NR580_GPIO_LED_READY_GREEN,
  4216. + .active_low = 0,
  4217. + }, {
  4218. + .name = "aw-nr580:green:wps",
  4219. + .gpio = AW_NR580_GPIO_LED_WPS_GREEN,
  4220. + .active_low = 0,
  4221. + }, {
  4222. + .name = "aw-nr580:amber:wps",
  4223. + .gpio = AW_NR580_GPIO_LED_WPS_AMBER,
  4224. + .active_low = 0,
  4225. + }, {
  4226. + .name = "aw-nr580:green:wlan",
  4227. + .gpio = AW_NR580_GPIO_LED_WLAN,
  4228. + .active_low = 0,
  4229. + }
  4230. +};
  4231. +
  4232. +static struct gpio_keys_button aw_nr580_gpio_keys[] __initdata = {
  4233. + {
  4234. + .desc = "reset",
  4235. + .type = EV_KEY,
  4236. + .code = KEY_RESTART,
  4237. + .debounce_interval = AW_NR580_KEYS_DEBOUNCE_INTERVAL,
  4238. + .gpio = AW_NR580_GPIO_BTN_RESET,
  4239. + .active_low = 1,
  4240. + }, {
  4241. + .desc = "wps",
  4242. + .type = EV_KEY,
  4243. + .code = KEY_WPS_BUTTON,
  4244. + .debounce_interval = AW_NR580_KEYS_DEBOUNCE_INTERVAL,
  4245. + .gpio = AW_NR580_GPIO_BTN_WPS,
  4246. + .active_low = 1,
  4247. + }
  4248. +};
  4249. +
  4250. +static void __init aw_nr580_setup(void)
  4251. +{
  4252. + ar71xx_add_device_mdio(0x0);
  4253. +
  4254. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4255. + ar71xx_eth0_data.speed = SPEED_100;
  4256. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4257. +
  4258. + ar71xx_add_device_eth(0);
  4259. +
  4260. + pb42_pci_init();
  4261. +
  4262. + ar71xx_add_device_m25p80(NULL);
  4263. +
  4264. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(aw_nr580_leds_gpio),
  4265. + aw_nr580_leds_gpio);
  4266. +
  4267. + ar71xx_register_gpio_keys_polled(-1, AW_NR580_KEYS_POLL_INTERVAL,
  4268. + ARRAY_SIZE(aw_nr580_gpio_keys),
  4269. + aw_nr580_gpio_keys);
  4270. +}
  4271. +
  4272. +MIPS_MACHINE(AR71XX_MACH_AW_NR580, "AW-NR580", "AzureWave AW-NR580",
  4273. + aw_nr580_setup);
  4274. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-db120.c linux-2.6.39/arch/mips/ar71xx/mach-db120.c
  4275. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-db120.c 1970-01-01 01:00:00.000000000 +0100
  4276. +++ linux-2.6.39/arch/mips/ar71xx/mach-db120.c 2011-08-24 02:41:55.487989871 +0200
  4277. @@ -0,0 +1,134 @@
  4278. +/*
  4279. + * Atheros DB120 board (WASP SoC) support
  4280. + *
  4281. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  4282. + *
  4283. + * This program is free software; you can redistribute it and/or modify it
  4284. + * under the terms of the GNU General Public License version 2 as published
  4285. + * by the Free Software Foundation.
  4286. + */
  4287. +
  4288. +#include <linux/mtd/mtd.h>
  4289. +#include <linux/mtd/partitions.h>
  4290. +
  4291. +#include <asm/mach-ar71xx/ar71xx.h>
  4292. +
  4293. +#include "machtype.h"
  4294. +#include "devices.h"
  4295. +#include "dev-m25p80.h"
  4296. +#include "dev-gpio-buttons.h"
  4297. +#include "dev-leds-gpio.h"
  4298. +#include "dev-usb.h"
  4299. +#include "dev-ar9xxx-wmac.h"
  4300. +#include "dev-db120-pci.h"
  4301. +
  4302. +#define DB120_GPIO_LED_USB 11
  4303. +#define DB120_GPIO_LED_WLAN_5G 12
  4304. +#define DB120_GPIO_LED_WLAN_2G 13
  4305. +#define DB120_GPIO_LED_STATUS 14
  4306. +#define DB120_GPIO_LED_WPS 15
  4307. +
  4308. +#define DB120_GPIO_BTN_SW1 16
  4309. +
  4310. +#define DB120_CALDATA_OFFSET 0x1000
  4311. +#define DB120_WMAC_MAC_OFFSET 0x1002
  4312. +
  4313. +#define DB120_KEYS_POLL_INTERVAL 20 /* msecs */
  4314. +#define DB120_KEYS_DEBOUNCE_INTERVAL (3 * DB120_KEYS_POLL_INTERVAL)
  4315. +
  4316. +#ifdef CONFIG_MTD_PARTITIONS
  4317. +static struct mtd_partition db120_partitions[] = {
  4318. + {
  4319. + .name = "u-boot",
  4320. + .offset = 0,
  4321. + .size = 0x040000,
  4322. + .mask_flags = MTD_WRITEABLE,
  4323. + }, {
  4324. + .name = "u-boot-env",
  4325. + .offset = 0x040000,
  4326. + .size = 0x010000,
  4327. + }, {
  4328. + .name = "rootfs",
  4329. + .offset = 0x050000,
  4330. + .size = 0x630000,
  4331. + }, {
  4332. + .name = "uImage",
  4333. + .offset = 0x680000,
  4334. + .size = 0x160000,
  4335. + }, {
  4336. + .name = "NVRAM",
  4337. + .offset = 0x7E0000,
  4338. + .size = 0x010000,
  4339. + }, {
  4340. + .name = "ART",
  4341. + .offset = 0x7F0000,
  4342. + .size = 0x010000,
  4343. + .mask_flags = MTD_WRITEABLE,
  4344. + }
  4345. +};
  4346. +#endif /* CONFIG_MTD_PARTITIONS */
  4347. +
  4348. +static struct flash_platform_data db120_flash_data = {
  4349. +#ifdef CONFIG_MTD_PARTITIONS
  4350. + .parts = db120_partitions,
  4351. + .nr_parts = ARRAY_SIZE(db120_partitions),
  4352. +#endif
  4353. +};
  4354. +
  4355. +static struct gpio_led db120_leds_gpio[] __initdata = {
  4356. + {
  4357. + .name = "db120:green:status",
  4358. + .gpio = DB120_GPIO_LED_STATUS,
  4359. + .active_low = 1,
  4360. + }, {
  4361. + .name = "db120:green:wps",
  4362. + .gpio = DB120_GPIO_LED_WPS,
  4363. + .active_low = 1,
  4364. + }, {
  4365. + .name = "db120:green:wlan-5g",
  4366. + .gpio = DB120_GPIO_LED_WLAN_5G,
  4367. + .active_low = 1,
  4368. + }, {
  4369. + .name = "db120:green:wlan-2g",
  4370. + .gpio = DB120_GPIO_LED_WLAN_2G,
  4371. + .active_low = 1,
  4372. + }, {
  4373. + .name = "db120:green:usb",
  4374. + .gpio = DB120_GPIO_LED_USB,
  4375. + .active_low = 1,
  4376. + }
  4377. +};
  4378. +
  4379. +static struct gpio_keys_button db120_gpio_keys[] __initdata = {
  4380. + {
  4381. + .desc = "sw1",
  4382. + .type = EV_KEY,
  4383. + .code = BTN_0,
  4384. + .debounce_interval = DB120_KEYS_DEBOUNCE_INTERVAL,
  4385. + .gpio = DB120_GPIO_BTN_SW1,
  4386. + .active_low = 1,
  4387. + }
  4388. +};
  4389. +
  4390. +static void __init db120_setup(void)
  4391. +{
  4392. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  4393. +
  4394. + ar71xx_add_device_usb();
  4395. +
  4396. + ar71xx_add_device_m25p80(&db120_flash_data);
  4397. +
  4398. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(db120_leds_gpio),
  4399. + db120_leds_gpio);
  4400. +
  4401. + ar71xx_register_gpio_keys_polled(-1, DB120_KEYS_POLL_INTERVAL,
  4402. + ARRAY_SIZE(db120_gpio_keys),
  4403. + db120_gpio_keys);
  4404. +
  4405. + ar9xxx_add_device_wmac(art + DB120_CALDATA_OFFSET,
  4406. + art + DB120_WMAC_MAC_OFFSET);
  4407. +
  4408. + db120_pci_init();
  4409. +}
  4410. +
  4411. +MIPS_MACHINE(AR71XX_MACH_DB120, "DB120", "Atheros DB120", db120_setup);
  4412. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-600-a1.c linux-2.6.39/arch/mips/ar71xx/mach-dir-600-a1.c
  4413. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-600-a1.c 1970-01-01 01:00:00.000000000 +0100
  4414. +++ linux-2.6.39/arch/mips/ar71xx/mach-dir-600-a1.c 2011-08-24 02:41:55.487989871 +0200
  4415. @@ -0,0 +1,159 @@
  4416. +/*
  4417. + * D-Link DIR-600 rev. A1 board support
  4418. + *
  4419. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  4420. + *
  4421. + * This program is free software; you can redistribute it and/or modify it
  4422. + * under the terms of the GNU General Public License version 2 as published
  4423. + * by the Free Software Foundation.
  4424. + */
  4425. +
  4426. +#include <linux/mtd/mtd.h>
  4427. +#include <linux/mtd/partitions.h>
  4428. +
  4429. +#include <asm/mach-ar71xx/ar71xx.h>
  4430. +
  4431. +#include "machtype.h"
  4432. +#include "devices.h"
  4433. +#include "dev-m25p80.h"
  4434. +#include "dev-ap91-pci.h"
  4435. +#include "dev-gpio-buttons.h"
  4436. +#include "dev-leds-gpio.h"
  4437. +#include "nvram.h"
  4438. +
  4439. +#define DIR_600_A1_GPIO_LED_WPS 0
  4440. +#define DIR_600_A1_GPIO_LED_POWER_AMBER 1
  4441. +#define DIR_600_A1_GPIO_LED_POWER_GREEN 6
  4442. +
  4443. +#define DIR_600_A1_GPIO_BTN_RESET 8
  4444. +#define DIR_600_A1_GPIO_BTN_WPS 12
  4445. +
  4446. +#define DIR_600_A1_KEYS_POLL_INTERVAL 20 /* msecs */
  4447. +#define DIR_600_A1_KEYS_DEBOUNCE_INTERVAL (3 * DIR_600_A1_KEYS_POLL_INTERVAL)
  4448. +
  4449. +#define DIR_600_A1_NVRAM_ADDR 0x1f030000
  4450. +#define DIR_600_A1_NVRAM_SIZE 0x10000
  4451. +
  4452. +#ifdef CONFIG_MTD_PARTITIONS
  4453. +static struct mtd_partition dir_600_a1_partitions[] = {
  4454. + {
  4455. + .name = "u-boot",
  4456. + .offset = 0,
  4457. + .size = 0x030000,
  4458. + .mask_flags = MTD_WRITEABLE,
  4459. + }, {
  4460. + .name = "nvram",
  4461. + .offset = 0x030000,
  4462. + .size = 0x010000,
  4463. + }, {
  4464. + .name = "kernel",
  4465. + .offset = 0x040000,
  4466. + .size = 0x0e0000,
  4467. + }, {
  4468. + .name = "rootfs",
  4469. + .offset = 0x120000,
  4470. + .size = 0x2c0000,
  4471. + }, {
  4472. + .name = "mac",
  4473. + .offset = 0x3e0000,
  4474. + .size = 0x010000,
  4475. + .mask_flags = MTD_WRITEABLE,
  4476. + }, {
  4477. + .name = "art",
  4478. + .offset = 0x3f0000,
  4479. + .size = 0x010000,
  4480. + .mask_flags = MTD_WRITEABLE,
  4481. + }, {
  4482. + .name = "firmware",
  4483. + .offset = 0x040000,
  4484. + .size = 0x3a0000,
  4485. + }
  4486. +};
  4487. +#endif /* CONFIG_MTD_PARTITIONS */
  4488. +
  4489. +static struct flash_platform_data dir_600_a1_flash_data = {
  4490. +#ifdef CONFIG_MTD_PARTITIONS
  4491. + .parts = dir_600_a1_partitions,
  4492. + .nr_parts = ARRAY_SIZE(dir_600_a1_partitions),
  4493. +#endif
  4494. +};
  4495. +
  4496. +static struct gpio_led dir_600_a1_leds_gpio[] __initdata = {
  4497. + {
  4498. + .name = "dir-600-a1:green:power",
  4499. + .gpio = DIR_600_A1_GPIO_LED_POWER_GREEN,
  4500. + }, {
  4501. + .name = "dir-600-a1:amber:power",
  4502. + .gpio = DIR_600_A1_GPIO_LED_POWER_AMBER,
  4503. + }, {
  4504. + .name = "dir-600-a1:blue:wps",
  4505. + .gpio = DIR_600_A1_GPIO_LED_WPS,
  4506. + .active_low = 1,
  4507. + }
  4508. +};
  4509. +
  4510. +static struct gpio_keys_button dir_600_a1_gpio_keys[] __initdata = {
  4511. + {
  4512. + .desc = "reset",
  4513. + .type = EV_KEY,
  4514. + .code = KEY_RESTART,
  4515. + .debounce_interval = DIR_600_A1_KEYS_DEBOUNCE_INTERVAL,
  4516. + .gpio = DIR_600_A1_GPIO_BTN_RESET,
  4517. + .active_low = 1,
  4518. + }, {
  4519. + .desc = "wps",
  4520. + .type = EV_KEY,
  4521. + .code = KEY_WPS_BUTTON,
  4522. + .debounce_interval = DIR_600_A1_KEYS_DEBOUNCE_INTERVAL,
  4523. + .gpio = DIR_600_A1_GPIO_BTN_WPS,
  4524. + .active_low = 1,
  4525. + }
  4526. +};
  4527. +
  4528. +static void __init dir_600_a1_setup(void)
  4529. +{
  4530. + const char *nvram = (char *) KSEG1ADDR(DIR_600_A1_NVRAM_ADDR);
  4531. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  4532. + u8 mac_buff[6];
  4533. + u8 *mac = NULL;
  4534. +
  4535. + if (nvram_parse_mac_addr(nvram, DIR_600_A1_NVRAM_SIZE,
  4536. + "lan_mac=", mac_buff) == 0) {
  4537. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac_buff, 0);
  4538. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac_buff, 1);
  4539. + mac = mac_buff;
  4540. + }
  4541. +
  4542. + ar71xx_add_device_m25p80(&dir_600_a1_flash_data);
  4543. +
  4544. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_600_a1_leds_gpio),
  4545. + dir_600_a1_leds_gpio);
  4546. +
  4547. + ar71xx_register_gpio_keys_polled(-1, DIR_600_A1_KEYS_POLL_INTERVAL,
  4548. + ARRAY_SIZE(dir_600_a1_gpio_keys),
  4549. + dir_600_a1_gpio_keys);
  4550. +
  4551. + ar71xx_eth1_data.has_ar7240_switch = 1;
  4552. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  4553. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  4554. +
  4555. + /* WAN port */
  4556. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4557. + ar71xx_eth0_data.speed = SPEED_100;
  4558. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4559. + ar71xx_eth0_data.phy_mask = BIT(4);
  4560. +
  4561. + /* LAN ports */
  4562. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4563. + ar71xx_eth1_data.speed = SPEED_1000;
  4564. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4565. +
  4566. + ar71xx_add_device_mdio(0x0);
  4567. + ar71xx_add_device_eth(1);
  4568. + ar71xx_add_device_eth(0);
  4569. +
  4570. + ap91_pci_init(ee, mac);
  4571. +}
  4572. +
  4573. +MIPS_MACHINE(AR71XX_MACH_DIR_600_A1, "DIR-600-A1", "D-Link DIR-600 rev. A1",
  4574. + dir_600_a1_setup);
  4575. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-615-c1.c linux-2.6.39/arch/mips/ar71xx/mach-dir-615-c1.c
  4576. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-615-c1.c 1970-01-01 01:00:00.000000000 +0100
  4577. +++ linux-2.6.39/arch/mips/ar71xx/mach-dir-615-c1.c 2011-08-24 02:41:55.487989871 +0200
  4578. @@ -0,0 +1,175 @@
  4579. +/*
  4580. + * D-Link DIR-615 rev C1 board support
  4581. + *
  4582. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4583. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4584. + *
  4585. + * This program is free software; you can redistribute it and/or modify it
  4586. + * under the terms of the GNU General Public License version 2 as published
  4587. + * by the Free Software Foundation.
  4588. + */
  4589. +
  4590. +#include <linux/mtd/mtd.h>
  4591. +#include <linux/mtd/partitions.h>
  4592. +
  4593. +#include <asm/mach-ar71xx/ar71xx.h>
  4594. +
  4595. +#include "machtype.h"
  4596. +#include "devices.h"
  4597. +#include "dev-m25p80.h"
  4598. +#include "dev-ar9xxx-wmac.h"
  4599. +#include "dev-gpio-buttons.h"
  4600. +#include "dev-leds-gpio.h"
  4601. +#include "nvram.h"
  4602. +
  4603. +#define DIR_615C1_GPIO_LED_ORANGE_STATUS 1 /* ORANGE:STATUS:TRICOLOR */
  4604. +#define DIR_615C1_GPIO_LED_BLUE_WPS 3 /* BLUE:WPS */
  4605. +#define DIR_615C1_GPIO_LED_GREEN_WAN 4 /* GREEN:WAN:TRICOLOR */
  4606. +#define DIR_615C1_GPIO_LED_GREEN_WANCPU 5 /* GREEN:WAN:CPU:TRICOLOR */
  4607. +#define DIR_615C1_GPIO_LED_GREEN_WLAN 6 /* GREEN:WLAN */
  4608. +#define DIR_615C1_GPIO_LED_GREEN_STATUS 14 /* GREEN:STATUS:TRICOLOR */
  4609. +#define DIR_615C1_GPIO_LED_ORANGE_WAN 15 /* ORANGE:WAN:TRICOLOR */
  4610. +
  4611. +/* buttons may need refinement */
  4612. +
  4613. +#define DIR_615C1_GPIO_BTN_WPS 12
  4614. +#define DIR_615C1_GPIO_BTN_RESET 21
  4615. +
  4616. +#define DIR_615C1_KEYS_POLL_INTERVAL 20 /* msecs */
  4617. +#define DIR_615C1_KEYS_DEBOUNCE_INTERVAL (3 * DIR_615C1_KEYS_POLL_INTERVAL)
  4618. +
  4619. +#define DIR_615C1_CONFIG_ADDR 0x1f020000
  4620. +#define DIR_615C1_CONFIG_SIZE 0x10000
  4621. +
  4622. +#ifdef CONFIG_MTD_PARTITIONS
  4623. +static struct mtd_partition dir_615c1_partitions[] = {
  4624. + {
  4625. + .name = "u-boot",
  4626. + .offset = 0,
  4627. + .size = 0x020000,
  4628. + .mask_flags = MTD_WRITEABLE,
  4629. + }, {
  4630. + .name = "config",
  4631. + .offset = 0x020000,
  4632. + .size = 0x010000,
  4633. + }, {
  4634. + .name = "kernel",
  4635. + .offset = 0x030000,
  4636. + .size = 0x0e0000,
  4637. + }, {
  4638. + .name = "rootfs",
  4639. + .offset = 0x110000,
  4640. + .size = 0x2e0000,
  4641. + }, {
  4642. + .name = "art",
  4643. + .offset = 0x3f0000,
  4644. + .size = 0x010000,
  4645. + .mask_flags = MTD_WRITEABLE,
  4646. + }, {
  4647. + .name = "firmware",
  4648. + .offset = 0x030000,
  4649. + .size = 0x3c0000,
  4650. + }
  4651. +};
  4652. +#endif /* CONFIG_MTD_PARTITIONS */
  4653. +
  4654. +static struct flash_platform_data dir_615c1_flash_data = {
  4655. +#ifdef CONFIG_MTD_PARTITIONS
  4656. + .parts = dir_615c1_partitions,
  4657. + .nr_parts = ARRAY_SIZE(dir_615c1_partitions),
  4658. +#endif
  4659. +};
  4660. +
  4661. +static struct gpio_led dir_615c1_leds_gpio[] __initdata = {
  4662. + {
  4663. + .name = "dir-615c1:orange:status",
  4664. + .gpio = DIR_615C1_GPIO_LED_ORANGE_STATUS,
  4665. + .active_low = 1,
  4666. + }, {
  4667. + .name = "dir-615c1:blue:wps",
  4668. + .gpio = DIR_615C1_GPIO_LED_BLUE_WPS,
  4669. + .active_low = 1,
  4670. + }, {
  4671. + .name = "dir-615c1:green:wan",
  4672. + .gpio = DIR_615C1_GPIO_LED_GREEN_WAN,
  4673. + .active_low = 1,
  4674. + }, {
  4675. + .name = "dir-615c1:green:wancpu",
  4676. + .gpio = DIR_615C1_GPIO_LED_GREEN_WANCPU,
  4677. + .active_low = 1,
  4678. + }, {
  4679. + .name = "dir-615c1:green:wlan",
  4680. + .gpio = DIR_615C1_GPIO_LED_GREEN_WLAN,
  4681. + .active_low = 1,
  4682. + }, {
  4683. + .name = "dir-615c1:green:status",
  4684. + .gpio = DIR_615C1_GPIO_LED_GREEN_STATUS,
  4685. + .active_low = 1,
  4686. + }, {
  4687. + .name = "dir-615c1:orange:wan",
  4688. + .gpio = DIR_615C1_GPIO_LED_ORANGE_WAN,
  4689. + .active_low = 1,
  4690. + }
  4691. +
  4692. +};
  4693. +
  4694. +static struct gpio_keys_button dir_615c1_gpio_keys[] __initdata = {
  4695. + {
  4696. + .desc = "reset",
  4697. + .type = EV_KEY,
  4698. + .code = KEY_RESTART,
  4699. + .debounce_interval = DIR_615C1_KEYS_DEBOUNCE_INTERVAL,
  4700. + .gpio = DIR_615C1_GPIO_BTN_RESET,
  4701. + }, {
  4702. + .desc = "wps",
  4703. + .type = EV_KEY,
  4704. + .code = KEY_WPS_BUTTON,
  4705. + .debounce_interval = DIR_615C1_KEYS_DEBOUNCE_INTERVAL,
  4706. + .gpio = DIR_615C1_GPIO_BTN_WPS,
  4707. + }
  4708. +};
  4709. +
  4710. +#define DIR_615C1_LAN_PHYMASK BIT(0)
  4711. +#define DIR_615C1_WAN_PHYMASK BIT(4)
  4712. +#define DIR_615C1_MDIO_MASK (~(DIR_615C1_LAN_PHYMASK | \
  4713. + DIR_615C1_WAN_PHYMASK))
  4714. +
  4715. +static void __init dir_615c1_setup(void)
  4716. +{
  4717. + const char *config = (char *) KSEG1ADDR(DIR_615C1_CONFIG_ADDR);
  4718. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  4719. + u8 mac[6];
  4720. + u8 *wlan_mac = NULL;
  4721. +
  4722. + if (nvram_parse_mac_addr(config, DIR_615C1_CONFIG_SIZE,
  4723. + "lan_mac=", mac) == 0) {
  4724. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  4725. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  4726. + wlan_mac = mac;
  4727. + }
  4728. +
  4729. + ar71xx_add_device_mdio(DIR_615C1_MDIO_MASK);
  4730. +
  4731. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4732. + ar71xx_eth0_data.phy_mask = DIR_615C1_LAN_PHYMASK;
  4733. +
  4734. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4735. + ar71xx_eth1_data.phy_mask = DIR_615C1_WAN_PHYMASK;
  4736. +
  4737. + ar71xx_add_device_eth(0);
  4738. + ar71xx_add_device_eth(1);
  4739. +
  4740. + ar71xx_add_device_m25p80(&dir_615c1_flash_data);
  4741. +
  4742. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_615c1_leds_gpio),
  4743. + dir_615c1_leds_gpio);
  4744. +
  4745. + ar71xx_register_gpio_keys_polled(-1, DIR_615C1_KEYS_POLL_INTERVAL,
  4746. + ARRAY_SIZE(dir_615c1_gpio_keys),
  4747. + dir_615c1_gpio_keys);
  4748. +
  4749. + ar9xxx_add_device_wmac(eeprom, wlan_mac);
  4750. +}
  4751. +
  4752. +MIPS_MACHINE(AR71XX_MACH_DIR_615_C1, "DIR-615-C1", "D-Link DIR-615 rev. C1",
  4753. + dir_615c1_setup);
  4754. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-825-b1.c linux-2.6.39/arch/mips/ar71xx/mach-dir-825-b1.c
  4755. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-dir-825-b1.c 1970-01-01 01:00:00.000000000 +0100
  4756. +++ linux-2.6.39/arch/mips/ar71xx/mach-dir-825-b1.c 2011-08-24 02:41:55.487989871 +0200
  4757. @@ -0,0 +1,198 @@
  4758. +/*
  4759. + * D-Link DIR-825 rev. B1 board support
  4760. + *
  4761. + * Copyright (C) 2009 Lukas Kuna, Evkanet, s.r.o.
  4762. + *
  4763. + * based on mach-wndr3700.c
  4764. + *
  4765. + * This program is free software; you can redistribute it and/or modify it
  4766. + * under the terms of the GNU General Public License version 2 as published
  4767. + * by the Free Software Foundation.
  4768. + */
  4769. +
  4770. +#include <linux/platform_device.h>
  4771. +#include <linux/mtd/mtd.h>
  4772. +#include <linux/mtd/partitions.h>
  4773. +#include <linux/delay.h>
  4774. +#include <linux/rtl8366.h>
  4775. +
  4776. +#include <asm/mach-ar71xx/ar71xx.h>
  4777. +
  4778. +#include "machtype.h"
  4779. +#include "devices.h"
  4780. +#include "dev-m25p80.h"
  4781. +#include "dev-ap94-pci.h"
  4782. +#include "dev-gpio-buttons.h"
  4783. +#include "dev-leds-gpio.h"
  4784. +#include "dev-usb.h"
  4785. +
  4786. +#define DIR825B1_GPIO_LED_BLUE_USB 0
  4787. +#define DIR825B1_GPIO_LED_ORANGE_POWER 1
  4788. +#define DIR825B1_GPIO_LED_BLUE_POWER 2
  4789. +#define DIR825B1_GPIO_LED_BLUE_WPS 4
  4790. +#define DIR825B1_GPIO_LED_ORANGE_PLANET 6
  4791. +#define DIR825B1_GPIO_LED_BLUE_PLANET 11
  4792. +
  4793. +#define DIR825B1_GPIO_BTN_RESET 3
  4794. +#define DIR825B1_GPIO_BTN_WPS 8
  4795. +
  4796. +#define DIR825B1_GPIO_RTL8366_SDA 5
  4797. +#define DIR825B1_GPIO_RTL8366_SCK 7
  4798. +
  4799. +#define DIR825B1_KEYS_POLL_INTERVAL 20 /* msecs */
  4800. +#define DIR825B1_KEYS_DEBOUNCE_INTERVAL (3 * DIR825B1_KEYS_POLL_INTERVAL)
  4801. +
  4802. +#define DIR825B1_CAL_LOCATION_0 0x1f661000
  4803. +#define DIR825B1_CAL_LOCATION_1 0x1f665000
  4804. +
  4805. +#define DIR825B1_MAC_LOCATION_0 0x2ffa81b8
  4806. +#define DIR825B1_MAC_LOCATION_1 0x2ffa8370
  4807. +
  4808. +#ifdef CONFIG_MTD_PARTITIONS
  4809. +static struct mtd_partition dir825b1_partitions[] = {
  4810. + {
  4811. + .name = "uboot",
  4812. + .offset = 0,
  4813. + .size = 0x040000,
  4814. + .mask_flags = MTD_WRITEABLE,
  4815. + }, {
  4816. + .name = "config",
  4817. + .offset = 0x040000,
  4818. + .size = 0x010000,
  4819. + .mask_flags = MTD_WRITEABLE,
  4820. + }, {
  4821. + .name = "firmware",
  4822. + .offset = 0x050000,
  4823. + .size = 0x610000,
  4824. + }, {
  4825. + .name = "caldata",
  4826. + .offset = 0x660000,
  4827. + .size = 0x010000,
  4828. + .mask_flags = MTD_WRITEABLE,
  4829. + }, {
  4830. + .name = "unknown",
  4831. + .offset = 0x670000,
  4832. + .size = 0x190000,
  4833. + .mask_flags = MTD_WRITEABLE,
  4834. + }
  4835. +};
  4836. +#endif /* CONFIG_MTD_PARTITIONS */
  4837. +
  4838. +static struct flash_platform_data dir825b1_flash_data = {
  4839. +#ifdef CONFIG_MTD_PARTITIONS
  4840. + .parts = dir825b1_partitions,
  4841. + .nr_parts = ARRAY_SIZE(dir825b1_partitions),
  4842. +#endif
  4843. +};
  4844. +
  4845. +static struct gpio_led dir825b1_leds_gpio[] __initdata = {
  4846. + {
  4847. + .name = "dir825b1:blue:usb",
  4848. + .gpio = DIR825B1_GPIO_LED_BLUE_USB,
  4849. + .active_low = 1,
  4850. + }, {
  4851. + .name = "dir825b1:orange:power",
  4852. + .gpio = DIR825B1_GPIO_LED_ORANGE_POWER,
  4853. + .active_low = 1,
  4854. + }, {
  4855. + .name = "dir825b1:blue:power",
  4856. + .gpio = DIR825B1_GPIO_LED_BLUE_POWER,
  4857. + .active_low = 1,
  4858. + }, {
  4859. + .name = "dir825b1:blue:wps",
  4860. + .gpio = DIR825B1_GPIO_LED_BLUE_WPS,
  4861. + .active_low = 1,
  4862. + }, {
  4863. + .name = "dir825b1:orange:planet",
  4864. + .gpio = DIR825B1_GPIO_LED_ORANGE_PLANET,
  4865. + .active_low = 1,
  4866. + }, {
  4867. + .name = "dir825b1:blue:planet",
  4868. + .gpio = DIR825B1_GPIO_LED_BLUE_PLANET,
  4869. + .active_low = 1,
  4870. + }
  4871. +};
  4872. +
  4873. +static struct gpio_keys_button dir825b1_gpio_keys[] __initdata = {
  4874. + {
  4875. + .desc = "reset",
  4876. + .type = EV_KEY,
  4877. + .code = KEY_RESTART,
  4878. + .debounce_interval = DIR825B1_KEYS_DEBOUNCE_INTERVAL,
  4879. + .gpio = DIR825B1_GPIO_BTN_RESET,
  4880. + .active_low = 1,
  4881. + }, {
  4882. + .desc = "wps",
  4883. + .type = EV_KEY,
  4884. + .code = KEY_WPS_BUTTON,
  4885. + .debounce_interval = DIR825B1_KEYS_DEBOUNCE_INTERVAL,
  4886. + .gpio = DIR825B1_GPIO_BTN_WPS,
  4887. + .active_low = 1,
  4888. + }
  4889. +};
  4890. +
  4891. +static struct rtl8366_initval dir825b1_rtl8366s_initvals[] = {
  4892. + { .reg = 0x06, .val = 0x0108 },
  4893. +};
  4894. +
  4895. +static struct rtl8366_platform_data dir825b1_rtl8366s_data = {
  4896. + .gpio_sda = DIR825B1_GPIO_RTL8366_SDA,
  4897. + .gpio_sck = DIR825B1_GPIO_RTL8366_SCK,
  4898. + .num_initvals = ARRAY_SIZE(dir825b1_rtl8366s_initvals),
  4899. + .initvals = dir825b1_rtl8366s_initvals,
  4900. +};
  4901. +
  4902. +static struct platform_device dir825b1_rtl8366s_device = {
  4903. + .name = RTL8366S_DRIVER_NAME,
  4904. + .id = -1,
  4905. + .dev = {
  4906. + .platform_data = &dir825b1_rtl8366s_data,
  4907. + }
  4908. +};
  4909. +
  4910. +static void __init dir825b1_setup(void)
  4911. +{
  4912. + u8 *mac = (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_1);
  4913. +
  4914. + ar71xx_add_device_mdio(0x0);
  4915. +
  4916. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 1);
  4917. + ar71xx_eth0_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  4918. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4919. + ar71xx_eth0_data.speed = SPEED_1000;
  4920. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4921. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  4922. +
  4923. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 2);
  4924. + ar71xx_eth1_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  4925. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4926. + ar71xx_eth1_data.phy_mask = 0x10;
  4927. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  4928. +
  4929. + ar71xx_add_device_eth(0);
  4930. + ar71xx_add_device_eth(1);
  4931. +
  4932. + ar71xx_add_device_m25p80(&dir825b1_flash_data);
  4933. +
  4934. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir825b1_leds_gpio),
  4935. + dir825b1_leds_gpio);
  4936. +
  4937. + ar71xx_register_gpio_keys_polled(-1, DIR825B1_KEYS_POLL_INTERVAL,
  4938. + ARRAY_SIZE(dir825b1_gpio_keys),
  4939. + dir825b1_gpio_keys);
  4940. +
  4941. + ar71xx_add_device_usb();
  4942. +
  4943. + platform_device_register(&dir825b1_rtl8366s_device);
  4944. +
  4945. + ap94_pci_setup_wmac_led_pin(0, 5);
  4946. + ap94_pci_setup_wmac_led_pin(1, 5);
  4947. +
  4948. + ap94_pci_init((u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_0),
  4949. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_0),
  4950. + (u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_1),
  4951. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_1));
  4952. +}
  4953. +
  4954. +MIPS_MACHINE(AR71XX_MACH_DIR_825_B1, "DIR-825-B1", "D-Link DIR-825 rev. B1",
  4955. + dir825b1_setup);
  4956. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-eap7660d.c linux-2.6.39/arch/mips/ar71xx/mach-eap7660d.c
  4957. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-eap7660d.c 1970-01-01 01:00:00.000000000 +0100
  4958. +++ linux-2.6.39/arch/mips/ar71xx/mach-eap7660d.c 2011-08-24 02:41:55.497990784 +0200
  4959. @@ -0,0 +1,180 @@
  4960. +/*
  4961. + * Senao EAP7660D board support
  4962. + *
  4963. + * Copyright (C) 2010 Daniel Golle <daniel.golle@gmail.com>
  4964. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  4965. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4966. + *
  4967. + * This program is free software; you can redistribute it and/or modify it
  4968. + * under the terms of the GNU General Public License version 2 as published
  4969. + * by the Free Software Foundation.
  4970. + */
  4971. +
  4972. +#include <linux/pci.h>
  4973. +#include <linux/ath5k_platform.h>
  4974. +#include <linux/delay.h>
  4975. +#include <asm/mach-ar71xx/ar71xx.h>
  4976. +#include <asm/mach-ar71xx/pci.h>
  4977. +
  4978. +#include "machtype.h"
  4979. +#include "devices.h"
  4980. +#include "dev-gpio-buttons.h"
  4981. +#include "dev-leds-gpio.h"
  4982. +#include "dev-m25p80.h"
  4983. +
  4984. +#define EAP7660D_KEYS_POLL_INTERVAL 20 /* msecs */
  4985. +#define EAP7660D_KEYS_DEBOUNCE_INTERVAL (3 * EAP7660D_KEYS_POLL_INTERVAL)
  4986. +
  4987. +#define EAP7660D_GPIO_DS4 7
  4988. +#define EAP7660D_GPIO_DS5 2
  4989. +#define EAP7660D_GPIO_DS7 0
  4990. +#define EAP7660D_GPIO_DS8 4
  4991. +#define EAP7660D_GPIO_SW1 3
  4992. +#define EAP7660D_GPIO_SW3 8
  4993. +#define EAP7660D_PHYMASK BIT(20)
  4994. +#define EAP7660D_BOARDCONFIG 0x1F7F0000
  4995. +#define EAP7660D_GBIC_MAC_OFFSET 0x1000
  4996. +#define EAP7660D_WMAC0_MAC_OFFSET 0x1010
  4997. +#define EAP7660D_WMAC1_MAC_OFFSET 0x1016
  4998. +#define EAP7660D_WMAC0_CALDATA_OFFSET 0x2000
  4999. +#define EAP7660D_WMAC1_CALDATA_OFFSET 0x3000
  5000. +
  5001. +static struct ath5k_platform_data eap7660d_wmac0_data;
  5002. +static struct ath5k_platform_data eap7660d_wmac1_data;
  5003. +static char eap7660d_wmac0_mac[6];
  5004. +static char eap7660d_wmac1_mac[6];
  5005. +static u16 eap7660d_wmac0_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
  5006. +static u16 eap7660d_wmac1_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
  5007. +
  5008. +#ifdef CONFIG_PCI
  5009. +static struct ar71xx_pci_irq eap7660d_pci_irqs[] __initdata = {
  5010. + {
  5011. + .slot = 0,
  5012. + .pin = 1,
  5013. + .irq = AR71XX_PCI_IRQ_DEV0,
  5014. + }, {
  5015. + .slot = 1,
  5016. + .pin = 1,
  5017. + .irq = AR71XX_PCI_IRQ_DEV1,
  5018. + }
  5019. +};
  5020. +
  5021. +static int eap7660d_pci_plat_dev_init(struct pci_dev *dev)
  5022. +{
  5023. + switch (PCI_SLOT(dev->devfn)) {
  5024. + case 17:
  5025. + dev->dev.platform_data = &eap7660d_wmac0_data;
  5026. + break;
  5027. +
  5028. + case 18:
  5029. + dev->dev.platform_data = &eap7660d_wmac1_data;
  5030. + break;
  5031. + }
  5032. +
  5033. + return 0;
  5034. +}
  5035. +
  5036. +void __init eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
  5037. + u8 *cal_data1, u8 *mac_addr1)
  5038. +{
  5039. + if (cal_data0 && *cal_data0 == 0xa55a) {
  5040. + memcpy(eap7660d_wmac0_eeprom, cal_data0,
  5041. + ATH5K_PLAT_EEP_MAX_WORDS);
  5042. + eap7660d_wmac0_data.eeprom_data = eap7660d_wmac0_eeprom;
  5043. + }
  5044. +
  5045. + if (cal_data1 && *cal_data1 == 0xa55a) {
  5046. + memcpy(eap7660d_wmac1_eeprom, cal_data1,
  5047. + ATH5K_PLAT_EEP_MAX_WORDS);
  5048. + eap7660d_wmac1_data.eeprom_data = eap7660d_wmac1_eeprom;
  5049. + }
  5050. +
  5051. + if (mac_addr0) {
  5052. + memcpy(eap7660d_wmac0_mac, mac_addr0,
  5053. + sizeof(eap7660d_wmac0_mac));
  5054. + eap7660d_wmac0_data.macaddr = eap7660d_wmac0_mac;
  5055. + }
  5056. +
  5057. + if (mac_addr1) {
  5058. + memcpy(eap7660d_wmac1_mac, mac_addr1,
  5059. + sizeof(eap7660d_wmac1_mac));
  5060. + eap7660d_wmac1_data.macaddr = eap7660d_wmac1_mac;
  5061. + }
  5062. +
  5063. + ar71xx_pci_plat_dev_init = eap7660d_pci_plat_dev_init;
  5064. + ar71xx_pci_init(ARRAY_SIZE(eap7660d_pci_irqs), eap7660d_pci_irqs);
  5065. +}
  5066. +#else
  5067. +static inline void eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
  5068. + u8 *cal_data1, u8 *mac_addr1)
  5069. +{
  5070. +}
  5071. +#endif /* CONFIG_PCI */
  5072. +
  5073. +static struct gpio_led eap7660d_leds_gpio[] __initdata = {
  5074. + {
  5075. + .name = "eap7660d:green:ds8",
  5076. + .gpio = EAP7660D_GPIO_DS8,
  5077. + .active_low = 0,
  5078. + },
  5079. + {
  5080. + .name = "eap7660d:green:ds5",
  5081. + .gpio = EAP7660D_GPIO_DS5,
  5082. + .active_low = 0,
  5083. + },
  5084. + {
  5085. + .name = "eap7660d:green:ds7",
  5086. + .gpio = EAP7660D_GPIO_DS7,
  5087. + .active_low = 0,
  5088. + },
  5089. + {
  5090. + .name = "eap7660d:green:ds4",
  5091. + .gpio = EAP7660D_GPIO_DS4,
  5092. + .active_low = 0,
  5093. + }
  5094. +};
  5095. +
  5096. +static struct gpio_keys_button eap7660d_gpio_keys[] __initdata = {
  5097. + {
  5098. + .desc = "reset",
  5099. + .type = EV_KEY,
  5100. + .code = KEY_RESTART,
  5101. + .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
  5102. + .gpio = EAP7660D_GPIO_SW1,
  5103. + .active_low = 1,
  5104. + },
  5105. + {
  5106. + .desc = "wps",
  5107. + .type = EV_KEY,
  5108. + .code = KEY_WPS_BUTTON,
  5109. + .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
  5110. + .gpio = EAP7660D_GPIO_SW3,
  5111. + .active_low = 1,
  5112. + }
  5113. +};
  5114. +
  5115. +static void __init eap7660d_setup(void)
  5116. +{
  5117. + u8 *boardconfig = (u8 *) KSEG1ADDR(EAP7660D_BOARDCONFIG);
  5118. +
  5119. + ar71xx_add_device_mdio(~EAP7660D_PHYMASK);
  5120. +
  5121. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
  5122. + boardconfig + EAP7660D_GBIC_MAC_OFFSET, 0);
  5123. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5124. + ar71xx_eth0_data.phy_mask = EAP7660D_PHYMASK;
  5125. + ar71xx_add_device_eth(0);
  5126. + ar71xx_add_device_m25p80(NULL);
  5127. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(eap7660d_leds_gpio),
  5128. + eap7660d_leds_gpio);
  5129. + ar71xx_register_gpio_keys_polled(-1, EAP7660D_KEYS_POLL_INTERVAL,
  5130. + ARRAY_SIZE(eap7660d_gpio_keys),
  5131. + eap7660d_gpio_keys);
  5132. + eap7660d_pci_init(boardconfig + EAP7660D_WMAC0_CALDATA_OFFSET,
  5133. + boardconfig + EAP7660D_WMAC0_MAC_OFFSET,
  5134. + boardconfig + EAP7660D_WMAC1_CALDATA_OFFSET,
  5135. + boardconfig + EAP7660D_WMAC1_MAC_OFFSET);
  5136. +};
  5137. +
  5138. +MIPS_MACHINE(AR71XX_MACH_EAP7660D, "EAP7660D", "Senao EAP7660D",
  5139. + eap7660d_setup);
  5140. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ja76pf.c linux-2.6.39/arch/mips/ar71xx/mach-ja76pf.c
  5141. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ja76pf.c 1970-01-01 01:00:00.000000000 +0100
  5142. +++ linux-2.6.39/arch/mips/ar71xx/mach-ja76pf.c 2011-08-24 02:41:55.517989552 +0200
  5143. @@ -0,0 +1,102 @@
  5144. +/*
  5145. + * jjPlus JA76PF board support
  5146. + */
  5147. +
  5148. +#include <asm/mach-ar71xx/ar71xx.h>
  5149. +#include <linux/platform_device.h>
  5150. +#include <linux/i2c.h>
  5151. +#include <linux/i2c-gpio.h>
  5152. +
  5153. +#include "machtype.h"
  5154. +#include "devices.h"
  5155. +#include "dev-m25p80.h"
  5156. +#include "dev-gpio-buttons.h"
  5157. +#include "dev-pb42-pci.h"
  5158. +#include "dev-usb.h"
  5159. +#include "dev-leds-gpio.h"
  5160. +
  5161. +#define JA76PF_KEYS_POLL_INTERVAL 20 /* msecs */
  5162. +#define JA76PF_KEYS_DEBOUNCE_INTERVAL (3 * JA76PF_KEYS_POLL_INTERVAL)
  5163. +
  5164. +#define JA76PF_GPIO_I2C_SCL 0
  5165. +#define JA76PF_GPIO_I2C_SDA 1
  5166. +#define JA76PF_GPIO_LED_1 5
  5167. +#define JA76PF_GPIO_LED_2 4
  5168. +#define JA76PF_GPIO_LED_3 3
  5169. +#define JA76PF_GPIO_BTN_RESET 11
  5170. +
  5171. +static struct gpio_led ja76pf_leds_gpio[] __initdata = {
  5172. + {
  5173. + .name = "ja76pf:green:led1",
  5174. + .gpio = JA76PF_GPIO_LED_1,
  5175. + .active_low = 1,
  5176. + }, {
  5177. + .name = "ja76pf:green:led2",
  5178. + .gpio = JA76PF_GPIO_LED_2,
  5179. + .active_low = 1,
  5180. + }, {
  5181. + .name = "ja76pf:green:led3",
  5182. + .gpio = JA76PF_GPIO_LED_3,
  5183. + .active_low = 1,
  5184. + }
  5185. +};
  5186. +
  5187. +static struct gpio_keys_button ja76pf_gpio_keys[] __initdata = {
  5188. + {
  5189. + .desc = "reset",
  5190. + .type = EV_KEY,
  5191. + .code = KEY_RESTART,
  5192. + .debounce_interval = JA76PF_KEYS_DEBOUNCE_INTERVAL,
  5193. + .gpio = JA76PF_GPIO_BTN_RESET,
  5194. + .active_low = 1,
  5195. + }
  5196. +};
  5197. +
  5198. +static struct i2c_gpio_platform_data ja76pf_i2c_gpio_data = {
  5199. + .sda_pin = JA76PF_GPIO_I2C_SDA,
  5200. + .scl_pin = JA76PF_GPIO_I2C_SCL,
  5201. +};
  5202. +
  5203. +static struct platform_device ja76pf_i2c_gpio_device = {
  5204. + .name = "i2c-gpio",
  5205. + .id = 0,
  5206. + .dev = {
  5207. + .platform_data = &ja76pf_i2c_gpio_data,
  5208. + }
  5209. +};
  5210. +
  5211. +#define JA76PF_WAN_PHYMASK (1 << 4)
  5212. +#define JA76PF_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 < 3))
  5213. +#define JA76PF_MDIO_PHYMASK (JA76PF_LAN_PHYMASK | JA76PF_WAN_PHYMASK)
  5214. +
  5215. +static void __init ja76pf_init(void)
  5216. +{
  5217. + ar71xx_add_device_m25p80(NULL);
  5218. +
  5219. + ar71xx_add_device_mdio(~JA76PF_MDIO_PHYMASK);
  5220. +
  5221. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5222. + ar71xx_eth0_data.phy_mask = JA76PF_LAN_PHYMASK;
  5223. +
  5224. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5225. + ar71xx_eth1_data.phy_mask = JA76PF_WAN_PHYMASK;
  5226. + ar71xx_eth1_data.speed = SPEED_1000;
  5227. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  5228. +
  5229. + ar71xx_add_device_eth(0);
  5230. + ar71xx_add_device_eth(1);
  5231. +
  5232. + platform_device_register(&ja76pf_i2c_gpio_device);
  5233. +
  5234. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ja76pf_leds_gpio),
  5235. + ja76pf_leds_gpio);
  5236. +
  5237. + ar71xx_register_gpio_keys_polled(-1, JA76PF_KEYS_POLL_INTERVAL,
  5238. + ARRAY_SIZE(ja76pf_gpio_keys),
  5239. + ja76pf_gpio_keys);
  5240. +
  5241. + ar71xx_add_device_usb();
  5242. + pb42_pci_init();
  5243. +}
  5244. +
  5245. +MIPS_MACHINE(AR71XX_MACH_JA76PF, "JA76PF", "jjPlus JA76PF", ja76pf_init);
  5246. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-jwap003.c linux-2.6.39/arch/mips/ar71xx/mach-jwap003.c
  5247. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-jwap003.c 1970-01-01 01:00:00.000000000 +0100
  5248. +++ linux-2.6.39/arch/mips/ar71xx/mach-jwap003.c 2011-08-24 02:41:55.517989552 +0200
  5249. @@ -0,0 +1,83 @@
  5250. +/*
  5251. + * jjPlus JWAP003 board support
  5252. + *
  5253. + */
  5254. +
  5255. +#include <asm/mach-ar71xx/ar71xx.h>
  5256. +#include <linux/i2c.h>
  5257. +#include <linux/i2c-gpio.h>
  5258. +#include <linux/platform_device.h>
  5259. +
  5260. +#include "machtype.h"
  5261. +#include "devices.h"
  5262. +#include "dev-m25p80.h"
  5263. +#include "dev-gpio-buttons.h"
  5264. +#include "dev-pb42-pci.h"
  5265. +#include "dev-usb.h"
  5266. +
  5267. +#define JWAP003_KEYS_POLL_INTERVAL 20 /* msecs */
  5268. +#define JWAP003_KEYS_DEBOUNCE_INTERVAL (3 * JWAP003_KEYS_POLL_INTERVAL)
  5269. +
  5270. +#define JWAP003_GPIO_WPS 11
  5271. +#define JWAP003_GPIO_I2C_SCL 0
  5272. +#define JWAP003_GPIO_I2C_SDA 1
  5273. +
  5274. +static struct gpio_keys_button jwap003_gpio_keys[] __initdata = {
  5275. + {
  5276. + .desc = "wps",
  5277. + .type = EV_KEY,
  5278. + .code = KEY_WPS_BUTTON,
  5279. + .debounce_interval = JWAP003_KEYS_DEBOUNCE_INTERVAL,
  5280. + .gpio = JWAP003_GPIO_WPS,
  5281. + .active_low = 1,
  5282. + }
  5283. +};
  5284. +
  5285. +static struct i2c_gpio_platform_data jwap003_i2c_gpio_data = {
  5286. + .sda_pin = JWAP003_GPIO_I2C_SDA,
  5287. + .scl_pin = JWAP003_GPIO_I2C_SCL,
  5288. +};
  5289. +
  5290. +static struct platform_device jwap003_i2c_gpio_device = {
  5291. + .name = "i2c-gpio",
  5292. + .id = 0,
  5293. + .dev = {
  5294. + .platform_data = &jwap003_i2c_gpio_data,
  5295. + }
  5296. +};
  5297. +
  5298. +#define JWAP003_WAN_PHYMASK BIT(0)
  5299. +#define JWAP003_LAN_PHYMASK BIT(4)
  5300. +
  5301. +static void __init jwap003_init(void)
  5302. +{
  5303. + ar71xx_add_device_m25p80(NULL);
  5304. +
  5305. + ar71xx_add_device_mdio(0x0);
  5306. +
  5307. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5308. + ar71xx_eth0_data.phy_mask = JWAP003_WAN_PHYMASK;
  5309. + ar71xx_eth0_data.speed = SPEED_100;
  5310. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5311. + ar71xx_eth0_data.has_ar8216 = 1;
  5312. +
  5313. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5314. + ar71xx_eth1_data.phy_mask = JWAP003_LAN_PHYMASK;
  5315. + ar71xx_eth1_data.speed = SPEED_100;
  5316. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  5317. +
  5318. + ar71xx_add_device_eth(0);
  5319. + ar71xx_add_device_eth(1);
  5320. +
  5321. + platform_device_register(&jwap003_i2c_gpio_device);
  5322. +
  5323. + ar71xx_add_device_usb();
  5324. +
  5325. + ar71xx_register_gpio_keys_polled(-1, JWAP003_KEYS_POLL_INTERVAL,
  5326. + ARRAY_SIZE(jwap003_gpio_keys),
  5327. + jwap003_gpio_keys);
  5328. +
  5329. + pb42_pci_init();
  5330. +}
  5331. +
  5332. +MIPS_MACHINE(AR71XX_MACH_JWAP003, "JWAP003", "jjPlus JWAP003", jwap003_init);
  5333. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-mzk-w04nu.c linux-2.6.39/arch/mips/ar71xx/mach-mzk-w04nu.c
  5334. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-mzk-w04nu.c 1970-01-01 01:00:00.000000000 +0100
  5335. +++ linux-2.6.39/arch/mips/ar71xx/mach-mzk-w04nu.c 2011-08-24 02:41:55.517989552 +0200
  5336. @@ -0,0 +1,166 @@
  5337. +/*
  5338. + * Planex MZK-W04NU board support
  5339. + *
  5340. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5341. + *
  5342. + * This program is free software; you can redistribute it and/or modify it
  5343. + * under the terms of the GNU General Public License version 2 as published
  5344. + * by the Free Software Foundation.
  5345. + */
  5346. +
  5347. +#include <linux/mtd/mtd.h>
  5348. +#include <linux/mtd/partitions.h>
  5349. +
  5350. +#include <asm/mach-ar71xx/ar71xx.h>
  5351. +
  5352. +#include "machtype.h"
  5353. +#include "devices.h"
  5354. +#include "dev-ar9xxx-wmac.h"
  5355. +#include "dev-gpio-buttons.h"
  5356. +#include "dev-leds-gpio.h"
  5357. +#include "dev-m25p80.h"
  5358. +#include "dev-usb.h"
  5359. +
  5360. +#define MZK_W04NU_GPIO_LED_USB 0
  5361. +#define MZK_W04NU_GPIO_LED_STATUS 1
  5362. +#define MZK_W04NU_GPIO_LED_WPS 3
  5363. +#define MZK_W04NU_GPIO_LED_WLAN 6
  5364. +#define MZK_W04NU_GPIO_LED_AP 15
  5365. +#define MZK_W04NU_GPIO_LED_ROUTER 16
  5366. +
  5367. +#define MZK_W04NU_GPIO_BTN_APROUTER 5
  5368. +#define MZK_W04NU_GPIO_BTN_WPS 12
  5369. +#define MZK_W04NU_GPIO_BTN_RESET 21
  5370. +
  5371. +#define MZK_W04NU_KEYS_POLL_INTERVAL 20 /* msecs */
  5372. +#define MZK_W04NU_KEYS_DEBOUNCE_INTERVAL (3 * MZK_W04NU_KEYS_POLL_INTERVAL)
  5373. +
  5374. +#ifdef CONFIG_MTD_PARTITIONS
  5375. +static struct mtd_partition mzk_w04nu_partitions[] = {
  5376. + {
  5377. + .name = "u-boot",
  5378. + .offset = 0,
  5379. + .size = 0x040000,
  5380. + .mask_flags = MTD_WRITEABLE,
  5381. + }, {
  5382. + .name = "u-boot-env",
  5383. + .offset = 0x040000,
  5384. + .size = 0x010000,
  5385. + }, {
  5386. + .name = "kernel",
  5387. + .offset = 0x050000,
  5388. + .size = 0x160000,
  5389. + }, {
  5390. + .name = "rootfs",
  5391. + .offset = 0x1b0000,
  5392. + .size = 0x630000,
  5393. + }, {
  5394. + .name = "art",
  5395. + .offset = 0x7e0000,
  5396. + .size = 0x020000,
  5397. + .mask_flags = MTD_WRITEABLE,
  5398. + }, {
  5399. + .name = "firmware",
  5400. + .offset = 0x050000,
  5401. + .size = 0x790000,
  5402. + }
  5403. +};
  5404. +#endif /* CONFIG_MTD_PARTITIONS */
  5405. +
  5406. +static struct flash_platform_data mzk_w04nu_flash_data = {
  5407. +#ifdef CONFIG_MTD_PARTITIONS
  5408. + .parts = mzk_w04nu_partitions,
  5409. + .nr_parts = ARRAY_SIZE(mzk_w04nu_partitions),
  5410. +#endif
  5411. +};
  5412. +
  5413. +static struct gpio_led mzk_w04nu_leds_gpio[] __initdata = {
  5414. + {
  5415. + .name = "mzk-w04nu:green:status",
  5416. + .gpio = MZK_W04NU_GPIO_LED_STATUS,
  5417. + .active_low = 1,
  5418. + }, {
  5419. + .name = "mzk-w04nu:blue:wps",
  5420. + .gpio = MZK_W04NU_GPIO_LED_WPS,
  5421. + .active_low = 1,
  5422. + }, {
  5423. + .name = "mzk-w04nu:green:wlan",
  5424. + .gpio = MZK_W04NU_GPIO_LED_WLAN,
  5425. + .active_low = 1,
  5426. + }, {
  5427. + .name = "mzk-w04nu:green:usb",
  5428. + .gpio = MZK_W04NU_GPIO_LED_USB,
  5429. + .active_low = 1,
  5430. + }, {
  5431. + .name = "mzk-w04nu:green:ap",
  5432. + .gpio = MZK_W04NU_GPIO_LED_AP,
  5433. + .active_low = 1,
  5434. + }, {
  5435. + .name = "mzk-w04nu:green:router",
  5436. + .gpio = MZK_W04NU_GPIO_LED_ROUTER,
  5437. + .active_low = 1,
  5438. + }
  5439. +};
  5440. +
  5441. +static struct gpio_keys_button mzk_w04nu_gpio_keys[] __initdata = {
  5442. + {
  5443. + .desc = "reset",
  5444. + .type = EV_KEY,
  5445. + .code = KEY_RESTART,
  5446. + .debounce_interval = MZK_W04NU_KEYS_DEBOUNCE_INTERVAL,
  5447. + .gpio = MZK_W04NU_GPIO_BTN_RESET,
  5448. + .active_low = 1,
  5449. + }, {
  5450. + .desc = "wps",
  5451. + .type = EV_KEY,
  5452. + .code = KEY_WPS_BUTTON,
  5453. + .debounce_interval = MZK_W04NU_KEYS_DEBOUNCE_INTERVAL,
  5454. + .gpio = MZK_W04NU_GPIO_BTN_WPS,
  5455. + .active_low = 1,
  5456. + }, {
  5457. + .desc = "aprouter",
  5458. + .type = EV_KEY,
  5459. + .code = BTN_2,
  5460. + .debounce_interval = MZK_W04NU_KEYS_DEBOUNCE_INTERVAL,
  5461. + .gpio = MZK_W04NU_GPIO_BTN_APROUTER,
  5462. + .active_low = 0,
  5463. + }
  5464. +};
  5465. +
  5466. +#define MZK_W04NU_WAN_PHYMASK BIT(4)
  5467. +#define MZK_W04NU_MDIO_MASK (~MZK_W04NU_WAN_PHYMASK)
  5468. +
  5469. +static void __init mzk_w04nu_setup(void)
  5470. +{
  5471. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5472. +
  5473. + ar71xx_add_device_mdio(MZK_W04NU_MDIO_MASK);
  5474. +
  5475. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, eeprom, 0);
  5476. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5477. + ar71xx_eth0_data.speed = SPEED_100;
  5478. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5479. + ar71xx_eth0_data.has_ar8216 = 1;
  5480. +
  5481. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, eeprom, 1);
  5482. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5483. + ar71xx_eth1_data.phy_mask = MZK_W04NU_WAN_PHYMASK;
  5484. +
  5485. + ar71xx_add_device_eth(0);
  5486. + ar71xx_add_device_eth(1);
  5487. +
  5488. + ar71xx_add_device_m25p80(&mzk_w04nu_flash_data);
  5489. +
  5490. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w04nu_leds_gpio),
  5491. + mzk_w04nu_leds_gpio);
  5492. +
  5493. + ar71xx_register_gpio_keys_polled(-1, MZK_W04NU_KEYS_POLL_INTERVAL,
  5494. + ARRAY_SIZE(mzk_w04nu_gpio_keys),
  5495. + mzk_w04nu_gpio_keys);
  5496. + ar71xx_add_device_usb();
  5497. +
  5498. + ar9xxx_add_device_wmac(eeprom, NULL);
  5499. +}
  5500. +
  5501. +MIPS_MACHINE(AR71XX_MACH_MZK_W04NU, "MZK-W04NU", "Planex MZK-W04NU",
  5502. + mzk_w04nu_setup);
  5503. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-mzk-w300nh.c linux-2.6.39/arch/mips/ar71xx/mach-mzk-w300nh.c
  5504. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-mzk-w300nh.c 1970-01-01 01:00:00.000000000 +0100
  5505. +++ linux-2.6.39/arch/mips/ar71xx/mach-mzk-w300nh.c 2011-08-24 02:41:55.527982711 +0200
  5506. @@ -0,0 +1,159 @@
  5507. +/*
  5508. + * Planex MZK-W300NH board support
  5509. + *
  5510. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5511. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5512. + *
  5513. + * This program is free software; you can redistribute it and/or modify it
  5514. + * under the terms of the GNU General Public License version 2 as published
  5515. + * by the Free Software Foundation.
  5516. + */
  5517. +
  5518. +#include <linux/mtd/mtd.h>
  5519. +#include <linux/mtd/partitions.h>
  5520. +
  5521. +#include <asm/mach-ar71xx/ar71xx.h>
  5522. +
  5523. +#include "machtype.h"
  5524. +#include "devices.h"
  5525. +#include "dev-m25p80.h"
  5526. +#include "dev-ar9xxx-wmac.h"
  5527. +#include "dev-gpio-buttons.h"
  5528. +#include "dev-leds-gpio.h"
  5529. +
  5530. +#define MZK_W300NH_GPIO_LED_STATUS 1
  5531. +#define MZK_W300NH_GPIO_LED_WPS 3
  5532. +#define MZK_W300NH_GPIO_LED_WLAN 6
  5533. +#define MZK_W300NH_GPIO_LED_AP 15
  5534. +#define MZK_W300NH_GPIO_LED_ROUTER 16
  5535. +
  5536. +#define MZK_W300NH_GPIO_BTN_APROUTER 5
  5537. +#define MZK_W300NH_GPIO_BTN_WPS 12
  5538. +#define MZK_W300NH_GPIO_BTN_RESET 21
  5539. +
  5540. +#define MZK_W300NH_KEYS_POLL_INTERVAL 20 /* msecs */
  5541. +#define MZK_W300NH_KEYS_DEBOUNCE_INTERVAL (3 * MZK_W300NH_KEYS_POLL_INTERVAL)
  5542. +
  5543. +#ifdef CONFIG_MTD_PARTITIONS
  5544. +static struct mtd_partition mzk_w300nh_partitions[] = {
  5545. + {
  5546. + .name = "u-boot",
  5547. + .offset = 0,
  5548. + .size = 0x040000,
  5549. + .mask_flags = MTD_WRITEABLE,
  5550. + }, {
  5551. + .name = "u-boot-env",
  5552. + .offset = 0x040000,
  5553. + .size = 0x010000,
  5554. + }, {
  5555. + .name = "kernel",
  5556. + .offset = 0x050000,
  5557. + .size = 0x160000,
  5558. + }, {
  5559. + .name = "rootfs",
  5560. + .offset = 0x1b0000,
  5561. + .size = 0x630000,
  5562. + }, {
  5563. + .name = "art",
  5564. + .offset = 0x7e0000,
  5565. + .size = 0x020000,
  5566. + .mask_flags = MTD_WRITEABLE,
  5567. + }, {
  5568. + .name = "firmware",
  5569. + .offset = 0x050000,
  5570. + .size = 0x790000,
  5571. + }
  5572. +};
  5573. +#endif /* CONFIG_MTD_PARTITIONS */
  5574. +
  5575. +static struct flash_platform_data mzk_w300nh_flash_data = {
  5576. +#ifdef CONFIG_MTD_PARTITIONS
  5577. + .parts = mzk_w300nh_partitions,
  5578. + .nr_parts = ARRAY_SIZE(mzk_w300nh_partitions),
  5579. +#endif
  5580. +};
  5581. +
  5582. +static struct gpio_led mzk_w300nh_leds_gpio[] __initdata = {
  5583. + {
  5584. + .name = "mzk-w300nh:green:status",
  5585. + .gpio = MZK_W300NH_GPIO_LED_STATUS,
  5586. + .active_low = 1,
  5587. + }, {
  5588. + .name = "mzk-w300nh:blue:wps",
  5589. + .gpio = MZK_W300NH_GPIO_LED_WPS,
  5590. + .active_low = 1,
  5591. + }, {
  5592. + .name = "mzk-w300nh:green:wlan",
  5593. + .gpio = MZK_W300NH_GPIO_LED_WLAN,
  5594. + .active_low = 1,
  5595. + }, {
  5596. + .name = "mzk-w300nh:green:ap",
  5597. + .gpio = MZK_W300NH_GPIO_LED_AP,
  5598. + .active_low = 1,
  5599. + }, {
  5600. + .name = "mzk-w300nh:green:router",
  5601. + .gpio = MZK_W300NH_GPIO_LED_ROUTER,
  5602. + .active_low = 1,
  5603. + }
  5604. +};
  5605. +
  5606. +static struct gpio_keys_button mzk_w300nh_gpio_keys[] __initdata = {
  5607. + {
  5608. + .desc = "reset",
  5609. + .type = EV_KEY,
  5610. + .code = KEY_RESTART,
  5611. + .debounce_interval = MZK_W300NH_KEYS_DEBOUNCE_INTERVAL,
  5612. + .gpio = MZK_W300NH_GPIO_BTN_RESET,
  5613. + .active_low = 1,
  5614. + }, {
  5615. + .desc = "wps",
  5616. + .type = EV_KEY,
  5617. + .code = KEY_WPS_BUTTON,
  5618. + .debounce_interval = MZK_W300NH_KEYS_DEBOUNCE_INTERVAL,
  5619. + .gpio = MZK_W300NH_GPIO_BTN_WPS,
  5620. + .active_low = 1,
  5621. + }, {
  5622. + .desc = "aprouter",
  5623. + .type = EV_KEY,
  5624. + .code = BTN_2,
  5625. + .debounce_interval = MZK_W300NH_KEYS_DEBOUNCE_INTERVAL,
  5626. + .gpio = MZK_W300NH_GPIO_BTN_APROUTER,
  5627. + .active_low = 0,
  5628. + }
  5629. +};
  5630. +
  5631. +#define MZK_W300NH_WAN_PHYMASK BIT(4)
  5632. +#define MZK_W300NH_MDIO_MASK (~MZK_W300NH_WAN_PHYMASK)
  5633. +
  5634. +static void __init mzk_w300nh_setup(void)
  5635. +{
  5636. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5637. +
  5638. + ar71xx_add_device_mdio(MZK_W300NH_MDIO_MASK);
  5639. +
  5640. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, eeprom, 0);
  5641. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5642. + ar71xx_eth0_data.speed = SPEED_100;
  5643. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5644. + ar71xx_eth0_data.has_ar8216 = 1;
  5645. +
  5646. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, eeprom, 1);
  5647. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5648. + ar71xx_eth1_data.phy_mask = MZK_W300NH_WAN_PHYMASK;
  5649. +
  5650. + ar71xx_add_device_eth(0);
  5651. + ar71xx_add_device_eth(1);
  5652. +
  5653. + ar71xx_add_device_m25p80(&mzk_w300nh_flash_data);
  5654. +
  5655. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w300nh_leds_gpio),
  5656. + mzk_w300nh_leds_gpio);
  5657. +
  5658. + ar71xx_register_gpio_keys_polled(-1, MZK_W300NH_KEYS_POLL_INTERVAL,
  5659. + ARRAY_SIZE(mzk_w300nh_gpio_keys),
  5660. + mzk_w300nh_gpio_keys);
  5661. + ar9xxx_add_device_wmac(eeprom, NULL);
  5662. +}
  5663. +
  5664. +MIPS_MACHINE(AR71XX_MACH_MZK_W300NH, "MZK-W300NH", "Planex MZK-W300NH",
  5665. + mzk_w300nh_setup);
  5666. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-nbg460n.c linux-2.6.39/arch/mips/ar71xx/mach-nbg460n.c
  5667. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-nbg460n.c 1970-01-01 01:00:00.000000000 +0100
  5668. +++ linux-2.6.39/arch/mips/ar71xx/mach-nbg460n.c 2011-08-24 02:41:55.537990605 +0200
  5669. @@ -0,0 +1,225 @@
  5670. +/*
  5671. + * Zyxel NBG 460N/550N/550NH board support
  5672. + *
  5673. + * Copyright (C) 2010 Michael Kurz <michi.kurz@googlemail.com>
  5674. + *
  5675. + * based on mach-tl-wr1043nd.c
  5676. + *
  5677. + * This program is free software; you can redistribute it and/or modify it
  5678. + * under the terms of the GNU General Public License version 2 as published
  5679. + * by the Free Software Foundation.
  5680. + */
  5681. +
  5682. +#include <linux/platform_device.h>
  5683. +#include <linux/mtd/mtd.h>
  5684. +#include <linux/mtd/partitions.h>
  5685. +#include <linux/delay.h>
  5686. +#include <linux/rtl8366.h>
  5687. +
  5688. +#include <linux/i2c.h>
  5689. +#include <linux/i2c-algo-bit.h>
  5690. +#include <linux/i2c-gpio.h>
  5691. +
  5692. +#include <asm/mach-ar71xx/ar71xx.h>
  5693. +
  5694. +#include "machtype.h"
  5695. +#include "devices.h"
  5696. +#include "dev-m25p80.h"
  5697. +#include "dev-ar9xxx-wmac.h"
  5698. +#include "dev-gpio-buttons.h"
  5699. +#include "dev-leds-gpio.h"
  5700. +
  5701. +/* LEDs */
  5702. +#define NBG460N_GPIO_LED_WPS 3
  5703. +#define NBG460N_GPIO_LED_WAN 6
  5704. +#define NBG460N_GPIO_LED_POWER 14
  5705. +#define NBG460N_GPIO_LED_WLAN 15
  5706. +
  5707. +/* Buttons */
  5708. +#define NBG460N_GPIO_BTN_WPS 12
  5709. +#define NBG460N_GPIO_BTN_RESET 21
  5710. +
  5711. +#define NBG460N_KEYS_POLL_INTERVAL 20 /* msecs */
  5712. +#define NBG460N_KEYS_DEBOUNCE_INTERVAL (3 * NBG460N_KEYS_POLL_INTERVAL)
  5713. +
  5714. +/* RTC chip PCF8563 I2C interface */
  5715. +#define NBG460N_GPIO_PCF8563_SDA 8
  5716. +#define NBG460N_GPIO_PCF8563_SCK 7
  5717. +
  5718. +/* Switch configuration I2C interface */
  5719. +#define NBG460N_GPIO_RTL8366_SDA 16
  5720. +#define NBG460N_GPIO_RTL8366_SCK 18
  5721. +
  5722. +#ifdef CONFIG_MTD_PARTITIONS
  5723. +static struct mtd_partition nbg460n_partitions[] = {
  5724. + {
  5725. + .name = "Bootbase",
  5726. + .offset = 0,
  5727. + .size = 0x010000,
  5728. + .mask_flags = MTD_WRITEABLE,
  5729. + }, {
  5730. + .name = "U-Boot Config",
  5731. + .offset = 0x010000,
  5732. + .size = 0x030000,
  5733. + }, {
  5734. + .name = "U-Boot",
  5735. + .offset = 0x040000,
  5736. + .size = 0x030000,
  5737. + }, {
  5738. + .name = "linux",
  5739. + .offset = 0x070000,
  5740. + .size = 0x0e0000,
  5741. + }, {
  5742. + .name = "rootfs",
  5743. + .offset = 0x150000,
  5744. + .size = 0x2a0000,
  5745. + }, {
  5746. + .name = "CalibData",
  5747. + .offset = 0x3f0000,
  5748. + .size = 0x010000,
  5749. + .mask_flags = MTD_WRITEABLE,
  5750. + }, {
  5751. + .name = "firmware",
  5752. + .offset = 0x070000,
  5753. + .size = 0x380000,
  5754. + }
  5755. +};
  5756. +#endif /* CONFIG_MTD_PARTITIONS */
  5757. +
  5758. +static struct flash_platform_data nbg460n_flash_data = {
  5759. +#ifdef CONFIG_MTD_PARTITIONS
  5760. + .parts = nbg460n_partitions,
  5761. + .nr_parts = ARRAY_SIZE(nbg460n_partitions),
  5762. +#endif
  5763. +};
  5764. +
  5765. +static struct gpio_led nbg460n_leds_gpio[] __initdata = {
  5766. + {
  5767. + .name = "nbg460n:green:power",
  5768. + .gpio = NBG460N_GPIO_LED_POWER,
  5769. + .active_low = 0,
  5770. + .default_trigger = "default-on",
  5771. + }, {
  5772. + .name = "nbg460n:green:wps",
  5773. + .gpio = NBG460N_GPIO_LED_WPS,
  5774. + .active_low = 0,
  5775. + }, {
  5776. + .name = "nbg460n:green:wlan",
  5777. + .gpio = NBG460N_GPIO_LED_WLAN,
  5778. + .active_low = 0,
  5779. + }, {
  5780. + /* Not really for controlling the LED,
  5781. + when set low the LED blinks uncontrollable */
  5782. + .name = "nbg460n:green:wan",
  5783. + .gpio = NBG460N_GPIO_LED_WAN,
  5784. + .active_low = 0,
  5785. + }
  5786. +};
  5787. +
  5788. +static struct gpio_keys_button nbg460n_gpio_keys[] __initdata = {
  5789. + {
  5790. + .desc = "reset",
  5791. + .type = EV_KEY,
  5792. + .code = KEY_RESTART,
  5793. + .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
  5794. + .gpio = NBG460N_GPIO_BTN_RESET,
  5795. + .active_low = 1,
  5796. + }, {
  5797. + .desc = "wps",
  5798. + .type = EV_KEY,
  5799. + .code = KEY_WPS_BUTTON,
  5800. + .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
  5801. + .gpio = NBG460N_GPIO_BTN_WPS,
  5802. + .active_low = 1,
  5803. + }
  5804. +};
  5805. +
  5806. +static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
  5807. + .sda_pin = NBG460N_GPIO_PCF8563_SDA,
  5808. + .scl_pin = NBG460N_GPIO_PCF8563_SCK,
  5809. + .udelay = 10,
  5810. +};
  5811. +
  5812. +static struct platform_device nbg460n_i2c_device = {
  5813. + .name = "i2c-gpio",
  5814. + .id = -1,
  5815. + .num_resources = 0,
  5816. + .resource = NULL,
  5817. + .dev = {
  5818. + .platform_data = &nbg460n_i2c_device_platdata,
  5819. + },
  5820. +};
  5821. +
  5822. +static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
  5823. + {
  5824. + I2C_BOARD_INFO("pcf8563", 0x51),
  5825. + },
  5826. +};
  5827. +
  5828. +static void __devinit nbg460n_i2c_init(void)
  5829. +{
  5830. + /* The gpio interface */
  5831. + platform_device_register(&nbg460n_i2c_device);
  5832. + /* I2C devices */
  5833. + i2c_register_board_info(0, nbg460n_i2c_devs,
  5834. + ARRAY_SIZE(nbg460n_i2c_devs));
  5835. +}
  5836. +
  5837. +
  5838. +static struct rtl8366_platform_data nbg460n_rtl8366s_data = {
  5839. + .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
  5840. + .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
  5841. +};
  5842. +
  5843. +static struct platform_device nbg460n_rtl8366s_device = {
  5844. + .name = RTL8366S_DRIVER_NAME,
  5845. + .id = -1,
  5846. + .dev = {
  5847. + .platform_data = &nbg460n_rtl8366s_data,
  5848. + }
  5849. +};
  5850. +
  5851. +static void __init nbg460n_setup(void)
  5852. +{
  5853. + /* end of bootloader sector contains mac address */
  5854. + u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
  5855. + /* last sector contains wlan calib data */
  5856. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5857. +
  5858. + /* LAN Port */
  5859. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  5860. + ar71xx_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  5861. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5862. + ar71xx_eth0_data.speed = SPEED_1000;
  5863. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5864. +
  5865. + /* WAN Port */
  5866. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  5867. + ar71xx_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  5868. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5869. + ar71xx_eth1_data.phy_mask = 0x10;
  5870. +
  5871. + ar71xx_add_device_eth(0);
  5872. + ar71xx_add_device_eth(1);
  5873. +
  5874. + /* register the switch phy */
  5875. + platform_device_register(&nbg460n_rtl8366s_device);
  5876. +
  5877. + /* register flash */
  5878. + ar71xx_add_device_m25p80(&nbg460n_flash_data);
  5879. +
  5880. + ar9xxx_add_device_wmac(eeprom, mac);
  5881. +
  5882. + /* register RTC chip */
  5883. + nbg460n_i2c_init();
  5884. +
  5885. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
  5886. + nbg460n_leds_gpio);
  5887. +
  5888. + ar71xx_register_gpio_keys_polled(-1, NBG460N_KEYS_POLL_INTERVAL,
  5889. + ARRAY_SIZE(nbg460n_gpio_keys),
  5890. + nbg460n_gpio_keys);
  5891. +}
  5892. +
  5893. +MIPS_MACHINE(AR71XX_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH",
  5894. + nbg460n_setup);
  5895. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-pb42.c linux-2.6.39/arch/mips/ar71xx/mach-pb42.c
  5896. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-pb42.c 1970-01-01 01:00:00.000000000 +0100
  5897. +++ linux-2.6.39/arch/mips/ar71xx/mach-pb42.c 2011-08-24 02:41:55.537990605 +0200
  5898. @@ -0,0 +1,74 @@
  5899. +/*
  5900. + * Atheros PB42 board support
  5901. + *
  5902. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5903. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5904. + *
  5905. + * This program is free software; you can redistribute it and/or modify it
  5906. + * under the terms of the GNU General Public License version 2 as published
  5907. + * by the Free Software Foundation.
  5908. + */
  5909. +
  5910. +#include <asm/mach-ar71xx/ar71xx.h>
  5911. +
  5912. +#include "machtype.h"
  5913. +#include "devices.h"
  5914. +#include "dev-m25p80.h"
  5915. +#include "dev-gpio-buttons.h"
  5916. +#include "dev-pb42-pci.h"
  5917. +#include "dev-usb.h"
  5918. +
  5919. +#define PB42_KEYS_POLL_INTERVAL 20 /* msecs */
  5920. +#define PB42_KEYS_DEBOUNCE_INTERVAL (3 * PB42_KEYS_POLL_INTERVAL)
  5921. +
  5922. +#define PB42_GPIO_BTN_SW4 8
  5923. +#define PB42_GPIO_BTN_SW5 3
  5924. +
  5925. +static struct gpio_keys_button pb42_gpio_keys[] __initdata = {
  5926. + {
  5927. + .desc = "sw4",
  5928. + .type = EV_KEY,
  5929. + .code = BTN_0,
  5930. + .debounce_interval = PB42_KEYS_DEBOUNCE_INTERVAL,
  5931. + .gpio = PB42_GPIO_BTN_SW4,
  5932. + .active_low = 1,
  5933. + }, {
  5934. + .desc = "sw5",
  5935. + .type = EV_KEY,
  5936. + .code = BTN_1,
  5937. + .debounce_interval = PB42_KEYS_DEBOUNCE_INTERVAL,
  5938. + .gpio = PB42_GPIO_BTN_SW5,
  5939. + .active_low = 1,
  5940. + }
  5941. +};
  5942. +
  5943. +#define PB42_WAN_PHYMASK BIT(20)
  5944. +#define PB42_LAN_PHYMASK (BIT(16) | BIT(17) | BIT(18) | BIT(19))
  5945. +#define PB42_MDIO_PHYMASK (PB42_LAN_PHYMASK | PB42_WAN_PHYMASK)
  5946. +
  5947. +static void __init pb42_init(void)
  5948. +{
  5949. + ar71xx_add_device_m25p80(NULL);
  5950. +
  5951. + ar71xx_add_device_mdio(~PB42_MDIO_PHYMASK);
  5952. +
  5953. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  5954. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  5955. + ar71xx_eth0_data.phy_mask = PB42_WAN_PHYMASK;
  5956. +
  5957. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
  5958. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5959. + ar71xx_eth1_data.speed = SPEED_100;
  5960. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  5961. +
  5962. + ar71xx_add_device_eth(0);
  5963. + ar71xx_add_device_eth(1);
  5964. +
  5965. + ar71xx_register_gpio_keys_polled(-1, PB42_KEYS_POLL_INTERVAL,
  5966. + ARRAY_SIZE(pb42_gpio_keys),
  5967. + pb42_gpio_keys);
  5968. +
  5969. + pb42_pci_init();
  5970. +}
  5971. +
  5972. +MIPS_MACHINE(AR71XX_MACH_PB42, "PB42", "Atheros PB42", pb42_init);
  5973. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-pb44.c linux-2.6.39/arch/mips/ar71xx/mach-pb44.c
  5974. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-pb44.c 1970-01-01 01:00:00.000000000 +0100
  5975. +++ linux-2.6.39/arch/mips/ar71xx/mach-pb44.c 2011-08-24 02:41:55.537990605 +0200
  5976. @@ -0,0 +1,213 @@
  5977. +/*
  5978. + * Atheros PB44 board support
  5979. + *
  5980. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5981. + *
  5982. + * This program is free software; you can redistribute it and/or modify it
  5983. + * under the terms of the GNU General Public License version 2 as published
  5984. + * by the Free Software Foundation.
  5985. + */
  5986. +
  5987. +#include <linux/init.h>
  5988. +#include <linux/bitops.h>
  5989. +#include <linux/delay.h>
  5990. +#include <linux/platform_device.h>
  5991. +#include <linux/spi/spi.h>
  5992. +#include <linux/spi/flash.h>
  5993. +#include <linux/spi/vsc7385.h>
  5994. +#include <linux/i2c.h>
  5995. +#include <linux/i2c-gpio.h>
  5996. +#include <linux/i2c/pcf857x.h>
  5997. +
  5998. +#include <asm/mach-ar71xx/ar71xx.h>
  5999. +
  6000. +#include "machtype.h"
  6001. +#include "devices.h"
  6002. +#include "dev-pb42-pci.h"
  6003. +#include "dev-gpio-buttons.h"
  6004. +#include "dev-leds-gpio.h"
  6005. +#include "dev-usb.h"
  6006. +
  6007. +#define PB44_PCF8757_VSC7395_CS 0
  6008. +#define PB44_PCF8757_STEREO_CS 1
  6009. +#define PB44_PCF8757_SLIC_CS0 2
  6010. +#define PB44_PCF8757_SLIC_TEST 3
  6011. +#define PB44_PCF8757_SLIC_INT0 4
  6012. +#define PB44_PCF8757_SLIC_INT1 5
  6013. +#define PB44_PCF8757_SW_RESET 6
  6014. +#define PB44_PCF8757_SW_JUMP 8
  6015. +#define PB44_PCF8757_LED_JUMP1 9
  6016. +#define PB44_PCF8757_LED_JUMP2 10
  6017. +#define PB44_PCF8757_TP24 11
  6018. +#define PB44_PCF8757_TP25 12
  6019. +#define PB44_PCF8757_TP26 13
  6020. +#define PB44_PCF8757_TP27 14
  6021. +#define PB44_PCF8757_TP28 15
  6022. +
  6023. +#define PB44_GPIO_I2C_SCL 0
  6024. +#define PB44_GPIO_I2C_SDA 1
  6025. +
  6026. +#define PB44_GPIO_EXP_BASE 16
  6027. +#define PB44_GPIO_VSC7395_CS (PB44_GPIO_EXP_BASE + PB44_PCF8757_VSC7395_CS)
  6028. +#define PB44_GPIO_SW_RESET (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_RESET)
  6029. +#define PB44_GPIO_SW_JUMP (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_JUMP)
  6030. +#define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP1)
  6031. +#define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP2)
  6032. +
  6033. +#define PB44_KEYS_POLL_INTERVAL 20 /* msecs */
  6034. +#define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL)
  6035. +
  6036. +static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
  6037. + .sda_pin = PB44_GPIO_I2C_SDA,
  6038. + .scl_pin = PB44_GPIO_I2C_SCL,
  6039. +};
  6040. +
  6041. +static struct platform_device pb44_i2c_gpio_device = {
  6042. + .name = "i2c-gpio",
  6043. + .id = 0,
  6044. + .dev = {
  6045. + .platform_data = &pb44_i2c_gpio_data,
  6046. + }
  6047. +};
  6048. +
  6049. +static struct pcf857x_platform_data pb44_pcf857x_data = {
  6050. + .gpio_base = PB44_GPIO_EXP_BASE,
  6051. +};
  6052. +
  6053. +static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
  6054. + {
  6055. + I2C_BOARD_INFO("pcf8575", 0x20),
  6056. + .platform_data = &pb44_pcf857x_data,
  6057. + },
  6058. +};
  6059. +
  6060. +static struct gpio_led pb44_leds_gpio[] __initdata = {
  6061. + {
  6062. + .name = "pb44:amber:jump1",
  6063. + .gpio = PB44_GPIO_LED_JUMP1,
  6064. + .active_low = 1,
  6065. + }, {
  6066. + .name = "pb44:green:jump2",
  6067. + .gpio = PB44_GPIO_LED_JUMP2,
  6068. + .active_low = 1,
  6069. + },
  6070. +};
  6071. +
  6072. +static struct gpio_keys_button pb44_gpio_keys[] __initdata = {
  6073. + {
  6074. + .desc = "soft_reset",
  6075. + .type = EV_KEY,
  6076. + .code = KEY_RESTART,
  6077. + .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL,
  6078. + .gpio = PB44_GPIO_SW_RESET,
  6079. + .active_low = 1,
  6080. + }, {
  6081. + .desc = "jumpstart",
  6082. + .type = EV_KEY,
  6083. + .code = KEY_WPS_BUTTON,
  6084. + .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL,
  6085. + .gpio = PB44_GPIO_SW_JUMP,
  6086. + .active_low = 1,
  6087. + }
  6088. +};
  6089. +
  6090. +static void pb44_vsc7395_reset(void)
  6091. +{
  6092. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  6093. + udelay(10);
  6094. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  6095. + mdelay(50);
  6096. +}
  6097. +
  6098. +static struct vsc7385_platform_data pb44_vsc7395_data = {
  6099. + .reset = pb44_vsc7395_reset,
  6100. + .ucode_name = "vsc7395_ucode_pb44.bin",
  6101. + .mac_cfg = {
  6102. + .tx_ipg = 6,
  6103. + .bit2 = 1,
  6104. + .clk_sel = 0,
  6105. + },
  6106. +};
  6107. +
  6108. +static struct spi_board_info pb44_spi_info[] = {
  6109. + {
  6110. + .bus_num = 0,
  6111. + .chip_select = 0,
  6112. + .max_speed_hz = 25000000,
  6113. + .modalias = "m25p80",
  6114. + }, {
  6115. + .bus_num = 0,
  6116. + .chip_select = 1,
  6117. + .max_speed_hz = 25000000,
  6118. + .modalias = "spi-vsc7385",
  6119. + .platform_data = &pb44_vsc7395_data,
  6120. + .controller_data = (void *) PB44_GPIO_VSC7395_CS,
  6121. + },
  6122. +};
  6123. +
  6124. +static struct resource pb44_spi_resources[] = {
  6125. + [0] = {
  6126. + .start = AR71XX_SPI_BASE,
  6127. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  6128. + .flags = IORESOURCE_MEM,
  6129. + },
  6130. +};
  6131. +
  6132. +static struct ar71xx_spi_platform_data pb44_spi_data = {
  6133. + .bus_num = 0,
  6134. + .num_chipselect = 2,
  6135. +};
  6136. +
  6137. +static struct platform_device pb44_spi_device = {
  6138. + .name = "pb44-spi",
  6139. + .id = -1,
  6140. + .resource = pb44_spi_resources,
  6141. + .num_resources = ARRAY_SIZE(pb44_spi_resources),
  6142. + .dev = {
  6143. + .platform_data = &pb44_spi_data,
  6144. + },
  6145. +};
  6146. +
  6147. +#define PB44_WAN_PHYMASK BIT(0)
  6148. +#define PB44_LAN_PHYMASK 0
  6149. +#define PB44_MDIO_PHYMASK (PB44_LAN_PHYMASK | PB44_WAN_PHYMASK)
  6150. +
  6151. +static void __init pb44_init(void)
  6152. +{
  6153. + ar71xx_add_device_mdio(~PB44_MDIO_PHYMASK);
  6154. +
  6155. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  6156. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6157. + ar71xx_eth0_data.phy_mask = PB44_WAN_PHYMASK;
  6158. +
  6159. + ar71xx_add_device_eth(0);
  6160. +
  6161. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
  6162. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6163. + ar71xx_eth1_data.speed = SPEED_1000;
  6164. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6165. + ar71xx_eth1_pll_data.pll_1000 = 0x110000;
  6166. +
  6167. + ar71xx_add_device_eth(1);
  6168. +
  6169. + ar71xx_add_device_usb();
  6170. +
  6171. + pb42_pci_init();
  6172. +
  6173. + i2c_register_board_info(0, pb44_i2c_board_info,
  6174. + ARRAY_SIZE(pb44_i2c_board_info));
  6175. +
  6176. + platform_device_register(&pb44_i2c_gpio_device);
  6177. +
  6178. + spi_register_board_info(pb44_spi_info, ARRAY_SIZE(pb44_spi_info));
  6179. + platform_device_register(&pb44_spi_device);
  6180. +
  6181. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
  6182. + pb44_leds_gpio);
  6183. +
  6184. + ar71xx_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL,
  6185. + ARRAY_SIZE(pb44_gpio_keys),
  6186. + pb44_gpio_keys);
  6187. +}
  6188. +
  6189. +MIPS_MACHINE(AR71XX_MACH_PB44, "PB44", "Atheros PB44", pb44_init);
  6190. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-pb92.c linux-2.6.39/arch/mips/ar71xx/mach-pb92.c
  6191. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-pb92.c 1970-01-01 01:00:00.000000000 +0100
  6192. +++ linux-2.6.39/arch/mips/ar71xx/mach-pb92.c 2011-08-24 02:41:55.567991163 +0200
  6193. @@ -0,0 +1,105 @@
  6194. +/*
  6195. + * Atheros PB92 board support
  6196. + *
  6197. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  6198. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6199. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6200. + *
  6201. + * This program is free software; you can redistribute it and/or modify it
  6202. + * under the terms of the GNU General Public License version 2 as published
  6203. + * by the Free Software Foundation.
  6204. + */
  6205. +
  6206. +#include <linux/mtd/mtd.h>
  6207. +#include <linux/mtd/partitions.h>
  6208. +#include <asm/mach-ar71xx/ar71xx.h>
  6209. +
  6210. +#include "machtype.h"
  6211. +#include "devices.h"
  6212. +#include "dev-m25p80.h"
  6213. +#include "dev-gpio-buttons.h"
  6214. +#include "dev-pb9x-pci.h"
  6215. +#include "dev-usb.h"
  6216. +
  6217. +#ifdef CONFIG_MTD_PARTITIONS
  6218. +static struct mtd_partition pb92_partitions[] = {
  6219. + {
  6220. + .name = "u-boot",
  6221. + .offset = 0,
  6222. + .size = 0x040000,
  6223. + .mask_flags = MTD_WRITEABLE,
  6224. + }, {
  6225. + .name = "u-boot-env",
  6226. + .offset = 0x040000,
  6227. + .size = 0x010000,
  6228. + }, {
  6229. + .name = "rootfs",
  6230. + .offset = 0x050000,
  6231. + .size = 0x2b0000,
  6232. + }, {
  6233. + .name = "uImage",
  6234. + .offset = 0x300000,
  6235. + .size = 0x0e0000,
  6236. + }, {
  6237. + .name = "ART",
  6238. + .offset = 0x3e0000,
  6239. + .size = 0x020000,
  6240. + .mask_flags = MTD_WRITEABLE,
  6241. + }
  6242. +};
  6243. +#endif /* CONFIG_MTD_PARTITIONS */
  6244. +
  6245. +static struct flash_platform_data pb92_flash_data = {
  6246. +#ifdef CONFIG_MTD_PARTITIONS
  6247. + .parts = pb92_partitions,
  6248. + .nr_parts = ARRAY_SIZE(pb92_partitions),
  6249. +#endif
  6250. +};
  6251. +
  6252. +#define PB92_KEYS_POLL_INTERVAL 20 /* msecs */
  6253. +#define PB92_KEYS_DEBOUNCE_INTERVAL (3 * PB92_KEYS_POLL_INTERVAL)
  6254. +
  6255. +#define PB92_GPIO_BTN_SW4 8
  6256. +#define PB92_GPIO_BTN_SW5 3
  6257. +
  6258. +static struct gpio_keys_button pb92_gpio_keys[] __initdata = {
  6259. + {
  6260. + .desc = "sw4",
  6261. + .type = EV_KEY,
  6262. + .code = BTN_0,
  6263. + .debounce_interval = PB92_KEYS_DEBOUNCE_INTERVAL,
  6264. + .gpio = PB92_GPIO_BTN_SW4,
  6265. + .active_low = 1,
  6266. + }, {
  6267. + .desc = "sw5",
  6268. + .type = EV_KEY,
  6269. + .code = BTN_1,
  6270. + .debounce_interval = PB92_KEYS_DEBOUNCE_INTERVAL,
  6271. + .gpio = PB92_GPIO_BTN_SW5,
  6272. + .active_low = 1,
  6273. + }
  6274. +};
  6275. +
  6276. +static void __init pb92_init(void)
  6277. +{
  6278. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  6279. +
  6280. + ar71xx_add_device_m25p80(&pb92_flash_data);
  6281. +
  6282. + ar71xx_add_device_mdio(~BIT(0));
  6283. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  6284. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6285. + ar71xx_eth0_data.speed = SPEED_1000;
  6286. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6287. + ar71xx_eth0_data.phy_mask = BIT(0);
  6288. +
  6289. + ar71xx_add_device_eth(0);
  6290. +
  6291. + ar71xx_register_gpio_keys_polled(-1, PB92_KEYS_POLL_INTERVAL,
  6292. + ARRAY_SIZE(pb92_gpio_keys),
  6293. + pb92_gpio_keys);
  6294. +
  6295. + pb9x_pci_init();
  6296. +}
  6297. +
  6298. +MIPS_MACHINE(AR71XX_MACH_PB92, "PB92", "Atheros PB92", pb92_init);
  6299. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-rb4xx.c linux-2.6.39/arch/mips/ar71xx/mach-rb4xx.c
  6300. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-rb4xx.c 1970-01-01 01:00:00.000000000 +0100
  6301. +++ linux-2.6.39/arch/mips/ar71xx/mach-rb4xx.c 2011-08-24 02:41:55.567991163 +0200
  6302. @@ -0,0 +1,344 @@
  6303. +/*
  6304. + * MikroTik RouterBOARD 4xx series support
  6305. + *
  6306. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  6307. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6308. + *
  6309. + * This program is free software; you can redistribute it and/or modify it
  6310. + * under the terms of the GNU General Public License version 2 as published
  6311. + * by the Free Software Foundation.
  6312. + */
  6313. +
  6314. +#include <linux/platform_device.h>
  6315. +#include <linux/irq.h>
  6316. +#include <linux/mmc/host.h>
  6317. +#include <linux/spi/spi.h>
  6318. +#include <linux/spi/flash.h>
  6319. +#include <linux/spi/mmc_spi.h>
  6320. +#include <linux/mtd/mtd.h>
  6321. +#include <linux/mtd/partitions.h>
  6322. +
  6323. +#include <asm/mach-ar71xx/ar71xx.h>
  6324. +#include <asm/mach-ar71xx/pci.h>
  6325. +#include <asm/mach-ar71xx/rb4xx_cpld.h>
  6326. +
  6327. +#include "machtype.h"
  6328. +#include "devices.h"
  6329. +#include "dev-gpio-buttons.h"
  6330. +#include "dev-leds-gpio.h"
  6331. +#include "dev-usb.h"
  6332. +
  6333. +#define RB4XX_GPIO_USER_LED 4
  6334. +#define RB4XX_GPIO_RESET_SWITCH 7
  6335. +
  6336. +#define RB4XX_GPIO_CPLD_BASE 32
  6337. +#define RB4XX_GPIO_CPLD_LED1 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED1)
  6338. +#define RB4XX_GPIO_CPLD_LED2 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED2)
  6339. +#define RB4XX_GPIO_CPLD_LED3 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED3)
  6340. +#define RB4XX_GPIO_CPLD_LED4 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED4)
  6341. +#define RB4XX_GPIO_CPLD_LED5 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED5)
  6342. +
  6343. +#define RB4XX_KEYS_POLL_INTERVAL 20 /* msecs */
  6344. +#define RB4XX_KEYS_DEBOUNCE_INTERVAL (3 * RB4XX_KEYS_POLL_INTERVAL)
  6345. +
  6346. +static struct gpio_led rb4xx_leds_gpio[] __initdata = {
  6347. + {
  6348. + .name = "rb4xx:yellow:user",
  6349. + .gpio = RB4XX_GPIO_USER_LED,
  6350. + .active_low = 0,
  6351. + }, {
  6352. + .name = "rb4xx:green:led1",
  6353. + .gpio = RB4XX_GPIO_CPLD_LED1,
  6354. + .active_low = 1,
  6355. + }, {
  6356. + .name = "rb4xx:green:led2",
  6357. + .gpio = RB4XX_GPIO_CPLD_LED2,
  6358. + .active_low = 1,
  6359. + }, {
  6360. + .name = "rb4xx:green:led3",
  6361. + .gpio = RB4XX_GPIO_CPLD_LED3,
  6362. + .active_low = 1,
  6363. + }, {
  6364. + .name = "rb4xx:green:led4",
  6365. + .gpio = RB4XX_GPIO_CPLD_LED4,
  6366. + .active_low = 1,
  6367. + }, {
  6368. + .name = "rb4xx:green:led5",
  6369. + .gpio = RB4XX_GPIO_CPLD_LED5,
  6370. + .active_low = 0,
  6371. + },
  6372. +};
  6373. +
  6374. +static struct gpio_keys_button rb4xx_gpio_keys[] __initdata = {
  6375. + {
  6376. + .desc = "reset_switch",
  6377. + .type = EV_KEY,
  6378. + .code = KEY_RESTART,
  6379. + .debounce_interval = RB4XX_KEYS_DEBOUNCE_INTERVAL,
  6380. + .gpio = RB4XX_GPIO_RESET_SWITCH,
  6381. + .active_low = 1,
  6382. + }
  6383. +};
  6384. +
  6385. +static struct platform_device rb4xx_nand_device = {
  6386. + .name = "rb4xx-nand",
  6387. + .id = -1,
  6388. +};
  6389. +
  6390. +static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
  6391. + {
  6392. + .slot = 0,
  6393. + .pin = 1,
  6394. + .irq = AR71XX_PCI_IRQ_DEV2,
  6395. + }, {
  6396. + .slot = 1,
  6397. + .pin = 1,
  6398. + .irq = AR71XX_PCI_IRQ_DEV0,
  6399. + }, {
  6400. + .slot = 1,
  6401. + .pin = 2,
  6402. + .irq = AR71XX_PCI_IRQ_DEV1,
  6403. + }, {
  6404. + .slot = 2,
  6405. + .pin = 1,
  6406. + .irq = AR71XX_PCI_IRQ_DEV1,
  6407. + }, {
  6408. + .slot = 3,
  6409. + .pin = 1,
  6410. + .irq = AR71XX_PCI_IRQ_DEV2,
  6411. + }
  6412. +};
  6413. +
  6414. +#ifdef CONFIG_MTD_PARTITIONS
  6415. +static struct mtd_partition rb4xx_partitions[] = {
  6416. + {
  6417. + .name = "routerboot",
  6418. + .offset = 0,
  6419. + .size = 0x0b000,
  6420. + .mask_flags = MTD_WRITEABLE,
  6421. + }, {
  6422. + .name = "hard_config",
  6423. + .offset = 0x0b000,
  6424. + .size = 0x01000,
  6425. + .mask_flags = MTD_WRITEABLE,
  6426. + }, {
  6427. + .name = "bios",
  6428. + .offset = 0x0d000,
  6429. + .size = 0x02000,
  6430. + .mask_flags = MTD_WRITEABLE,
  6431. + }, {
  6432. + .name = "soft_config",
  6433. + .offset = 0x0f000,
  6434. + .size = 0x01000,
  6435. + }
  6436. +};
  6437. +#define rb4xx_num_partitions ARRAY_SIZE(rb4xx_partitions)
  6438. +#else /* CONFIG_MTD_PARTITIONS */
  6439. +#define rb4xx_partitions NULL
  6440. +#define rb4xx_num_partitions 0
  6441. +#endif /* CONFIG_MTD_PARTITIONS */
  6442. +
  6443. +static struct flash_platform_data rb4xx_flash_data = {
  6444. + .type = "pm25lv512",
  6445. + .parts = rb4xx_partitions,
  6446. + .nr_parts = rb4xx_num_partitions,
  6447. +};
  6448. +
  6449. +static struct rb4xx_cpld_platform_data rb4xx_cpld_data = {
  6450. + .gpio_base = RB4XX_GPIO_CPLD_BASE,
  6451. +};
  6452. +
  6453. +static struct mmc_spi_platform_data rb4xx_mmc_data = {
  6454. + .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  6455. +};
  6456. +
  6457. +static struct spi_board_info rb4xx_spi_info[] = {
  6458. + {
  6459. + .bus_num = 0,
  6460. + .chip_select = 0,
  6461. + .max_speed_hz = 25000000,
  6462. + .modalias = "m25p80",
  6463. + .platform_data = &rb4xx_flash_data,
  6464. + }, {
  6465. + .bus_num = 0,
  6466. + .chip_select = 1,
  6467. + .max_speed_hz = 25000000,
  6468. + .modalias = "spi-rb4xx-cpld",
  6469. + .platform_data = &rb4xx_cpld_data,
  6470. + }
  6471. +};
  6472. +
  6473. +static struct spi_board_info rb4xx_microsd_info[] = {
  6474. + {
  6475. + .bus_num = 0,
  6476. + .chip_select = 2,
  6477. + .max_speed_hz = 25000000,
  6478. + .modalias = "mmc_spi",
  6479. + .platform_data = &rb4xx_mmc_data,
  6480. + }
  6481. +};
  6482. +
  6483. +
  6484. +static struct resource rb4xx_spi_resources[] = {
  6485. + {
  6486. + .start = AR71XX_SPI_BASE,
  6487. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  6488. + .flags = IORESOURCE_MEM,
  6489. + },
  6490. +};
  6491. +
  6492. +static struct platform_device rb4xx_spi_device = {
  6493. + .name = "rb4xx-spi",
  6494. + .id = -1,
  6495. + .resource = rb4xx_spi_resources,
  6496. + .num_resources = ARRAY_SIZE(rb4xx_spi_resources),
  6497. +};
  6498. +
  6499. +static void __init rb4xx_generic_setup(void)
  6500. +{
  6501. + ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  6502. + AR71XX_GPIO_FUNC_SPI_CS2_EN);
  6503. +
  6504. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
  6505. + rb4xx_leds_gpio);
  6506. +
  6507. + ar71xx_register_gpio_keys_polled(-1, RB4XX_KEYS_POLL_INTERVAL,
  6508. + ARRAY_SIZE(rb4xx_gpio_keys),
  6509. + rb4xx_gpio_keys);
  6510. +
  6511. + spi_register_board_info(rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
  6512. + platform_device_register(&rb4xx_spi_device);
  6513. + platform_device_register(&rb4xx_nand_device);
  6514. +}
  6515. +
  6516. +static void __init rb411_setup(void)
  6517. +{
  6518. + rb4xx_generic_setup();
  6519. + spi_register_board_info(rb4xx_microsd_info,
  6520. + ARRAY_SIZE(rb4xx_microsd_info));
  6521. +
  6522. + ar71xx_add_device_mdio(0xfffffffc);
  6523. +
  6524. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  6525. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6526. + ar71xx_eth0_data.phy_mask = 0x00000003;
  6527. +
  6528. + ar71xx_add_device_eth(0);
  6529. +
  6530. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  6531. +}
  6532. +
  6533. +MIPS_MACHINE(AR71XX_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
  6534. + rb411_setup);
  6535. +
  6536. +static void __init rb411u_setup(void)
  6537. +{
  6538. + rb411_setup();
  6539. + ar71xx_add_device_usb();
  6540. +}
  6541. +
  6542. +MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
  6543. + rb411u_setup);
  6544. +
  6545. +#define RB433_LAN_PHYMASK BIT(0)
  6546. +#define RB433_WAN_PHYMASK BIT(4)
  6547. +#define RB433_MDIO_PHYMASK (RB433_LAN_PHYMASK | RB433_WAN_PHYMASK)
  6548. +
  6549. +static void __init rb433_setup(void)
  6550. +{
  6551. + rb4xx_generic_setup();
  6552. + spi_register_board_info(rb4xx_microsd_info,
  6553. + ARRAY_SIZE(rb4xx_microsd_info));
  6554. +
  6555. + ar71xx_add_device_mdio(~RB433_MDIO_PHYMASK);
  6556. +
  6557. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1);
  6558. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6559. + ar71xx_eth0_data.phy_mask = RB433_LAN_PHYMASK;
  6560. +
  6561. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0);
  6562. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6563. + ar71xx_eth1_data.phy_mask = RB433_WAN_PHYMASK;
  6564. +
  6565. + ar71xx_add_device_eth(1);
  6566. + ar71xx_add_device_eth(0);
  6567. +
  6568. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  6569. +}
  6570. +
  6571. +MIPS_MACHINE(AR71XX_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
  6572. + rb433_setup);
  6573. +
  6574. +static void __init rb433u_setup(void)
  6575. +{
  6576. + rb433_setup();
  6577. + ar71xx_add_device_usb();
  6578. +}
  6579. +
  6580. +MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
  6581. + rb433u_setup);
  6582. +
  6583. +#define RB450_LAN_PHYMASK BIT(0)
  6584. +#define RB450_WAN_PHYMASK BIT(4)
  6585. +#define RB450_MDIO_PHYMASK (RB450_LAN_PHYMASK | RB450_WAN_PHYMASK)
  6586. +
  6587. +static void __init rb450_generic_setup(int gige)
  6588. +{
  6589. + rb4xx_generic_setup();
  6590. + ar71xx_add_device_mdio(~RB450_MDIO_PHYMASK);
  6591. +
  6592. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1);
  6593. + ar71xx_eth0_data.phy_if_mode = (gige) ?
  6594. + PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
  6595. + ar71xx_eth0_data.phy_mask = RB450_LAN_PHYMASK;
  6596. +
  6597. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0);
  6598. + ar71xx_eth1_data.phy_if_mode = (gige) ?
  6599. + PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
  6600. + ar71xx_eth1_data.phy_mask = RB450_WAN_PHYMASK;
  6601. +
  6602. + ar71xx_add_device_eth(1);
  6603. + ar71xx_add_device_eth(0);
  6604. +}
  6605. +
  6606. +static void __init rb450_setup(void)
  6607. +{
  6608. + rb450_generic_setup(0);
  6609. +}
  6610. +
  6611. +MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
  6612. + rb450_setup);
  6613. +
  6614. +static void __init rb450g_setup(void)
  6615. +{
  6616. + rb450_generic_setup(1);
  6617. + spi_register_board_info(rb4xx_microsd_info,
  6618. + ARRAY_SIZE(rb4xx_microsd_info));
  6619. +}
  6620. +
  6621. +MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
  6622. + rb450g_setup);
  6623. +
  6624. +static void __init rb493_setup(void)
  6625. +{
  6626. + rb4xx_generic_setup();
  6627. +
  6628. + ar71xx_add_device_mdio(0x3fffff00);
  6629. +
  6630. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  6631. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6632. + ar71xx_eth0_data.speed = SPEED_100;
  6633. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6634. +
  6635. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
  6636. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6637. + ar71xx_eth1_data.phy_mask = 0x00000001;
  6638. +
  6639. + ar71xx_add_device_eth(0);
  6640. + ar71xx_add_device_eth(1);
  6641. +
  6642. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  6643. +}
  6644. +
  6645. +MIPS_MACHINE(AR71XX_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",
  6646. + rb493_setup);
  6647. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-rb750.c linux-2.6.39/arch/mips/ar71xx/mach-rb750.c
  6648. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-rb750.c 1970-01-01 01:00:00.000000000 +0100
  6649. +++ linux-2.6.39/arch/mips/ar71xx/mach-rb750.c 2011-08-24 02:41:55.567991163 +0200
  6650. @@ -0,0 +1,144 @@
  6651. +/*
  6652. + * MikroTik RouterBOARD 750 support
  6653. + *
  6654. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  6655. + *
  6656. + * This program is free software; you can redistribute it and/or modify it
  6657. + * under the terms of the GNU General Public License version 2 as published
  6658. + * by the Free Software Foundation.
  6659. + */
  6660. +
  6661. +#include <linux/platform_device.h>
  6662. +#include <asm/mach-ar71xx/ar71xx.h>
  6663. +#include <asm/mach-ar71xx/mach-rb750.h>
  6664. +
  6665. +#include "machtype.h"
  6666. +#include "devices.h"
  6667. +
  6668. +static struct rb750_led_data rb750_leds[] = {
  6669. + {
  6670. + .name = "rb750:green:act",
  6671. + .mask = RB750_LED_ACT,
  6672. + .active_low = 1,
  6673. + }, {
  6674. + .name = "rb750:green:port1",
  6675. + .mask = RB750_LED_PORT5,
  6676. + .active_low = 1,
  6677. + }, {
  6678. + .name = "rb750:green:port2",
  6679. + .mask = RB750_LED_PORT4,
  6680. + .active_low = 1,
  6681. + }, {
  6682. + .name = "rb750:green:port3",
  6683. + .mask = RB750_LED_PORT3,
  6684. + .active_low = 1,
  6685. + }, {
  6686. + .name = "rb750:green:port4",
  6687. + .mask = RB750_LED_PORT2,
  6688. + .active_low = 1,
  6689. + }, {
  6690. + .name = "rb750:green:port5",
  6691. + .mask = RB750_LED_PORT1,
  6692. + .active_low = 1,
  6693. + }
  6694. +};
  6695. +
  6696. +static struct rb750_led_platform_data rb750_leds_data = {
  6697. + .num_leds = ARRAY_SIZE(rb750_leds),
  6698. + .leds = rb750_leds,
  6699. +};
  6700. +
  6701. +static struct platform_device rb750_leds_device = {
  6702. + .name = "leds-rb750",
  6703. + .dev = {
  6704. + .platform_data = &rb750_leds_data,
  6705. + }
  6706. +};
  6707. +
  6708. +static struct platform_device rb750_nand_device = {
  6709. + .name = "rb750-nand",
  6710. + .id = -1,
  6711. +};
  6712. +
  6713. +int rb750_latch_change(u32 mask_clr, u32 mask_set)
  6714. +{
  6715. + static DEFINE_SPINLOCK(lock);
  6716. + static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
  6717. + static u32 latch_oe;
  6718. + static u32 latch_clr;
  6719. + unsigned long flags;
  6720. + u32 t;
  6721. + int ret = 0;
  6722. +
  6723. + spin_lock_irqsave(&lock, flags);
  6724. +
  6725. + if ((mask_clr & BIT(31)) != 0 &&
  6726. + (latch_set & RB750_LVC573_LE) == 0) {
  6727. + goto unlock;
  6728. + }
  6729. +
  6730. + latch_set = (latch_set | mask_set) & ~mask_clr;
  6731. + latch_clr = (latch_clr | mask_clr) & ~mask_set;
  6732. +
  6733. + if (latch_oe == 0)
  6734. + latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
  6735. +
  6736. + if (likely(latch_set & RB750_LVC573_LE)) {
  6737. + void __iomem *base = ar71xx_gpio_base;
  6738. +
  6739. + t = __raw_readl(base + GPIO_REG_OE);
  6740. + t |= mask_clr | latch_oe | mask_set;
  6741. +
  6742. + __raw_writel(t, base + GPIO_REG_OE);
  6743. + __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
  6744. + __raw_writel(latch_set, base + GPIO_REG_SET);
  6745. + } else if (mask_clr & RB750_LVC573_LE) {
  6746. + void __iomem *base = ar71xx_gpio_base;
  6747. +
  6748. + latch_oe = __raw_readl(base + GPIO_REG_OE);
  6749. + __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
  6750. + /* flush write */
  6751. + __raw_readl(base + GPIO_REG_CLEAR);
  6752. + }
  6753. +
  6754. + ret = 1;
  6755. +
  6756. +unlock:
  6757. + spin_unlock_irqrestore(&lock, flags);
  6758. + return ret;
  6759. +}
  6760. +EXPORT_SYMBOL_GPL(rb750_latch_change);
  6761. +
  6762. +static void __init rb750_setup(void)
  6763. +{
  6764. + ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  6765. + AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  6766. + AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  6767. + AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  6768. + AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  6769. +
  6770. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  6771. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
  6772. +
  6773. + /* WAN port */
  6774. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6775. + ar71xx_eth0_data.speed = SPEED_100;
  6776. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6777. + ar71xx_eth0_data.phy_mask = BIT(4);
  6778. +
  6779. + /* LAN ports */
  6780. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6781. + ar71xx_eth1_data.speed = SPEED_1000;
  6782. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6783. + ar71xx_eth1_data.has_ar7240_switch = 1;
  6784. +
  6785. + ar71xx_add_device_mdio(0x0);
  6786. + ar71xx_add_device_eth(1);
  6787. + ar71xx_add_device_eth(0);
  6788. +
  6789. + platform_device_register(&rb750_leds_device);
  6790. + platform_device_register(&rb750_nand_device);
  6791. +}
  6792. +
  6793. +MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
  6794. + rb750_setup);
  6795. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tew-632brp.c linux-2.6.39/arch/mips/ar71xx/mach-tew-632brp.c
  6796. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tew-632brp.c 1970-01-01 01:00:00.000000000 +0100
  6797. +++ linux-2.6.39/arch/mips/ar71xx/mach-tew-632brp.c 2011-08-24 02:41:55.577989822 +0200
  6798. @@ -0,0 +1,151 @@
  6799. +/*
  6800. + * TrendNET TEW-632BRP board support
  6801. + *
  6802. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6803. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6804. + *
  6805. + * This program is free software; you can redistribute it and/or modify it
  6806. + * under the terms of the GNU General Public License version 2 as published
  6807. + * by the Free Software Foundation.
  6808. + */
  6809. +
  6810. +#include <linux/mtd/mtd.h>
  6811. +#include <linux/mtd/partitions.h>
  6812. +
  6813. +#include <asm/mach-ar71xx/ar71xx.h>
  6814. +
  6815. +#include "machtype.h"
  6816. +#include "devices.h"
  6817. +#include "dev-m25p80.h"
  6818. +#include "dev-ar9xxx-wmac.h"
  6819. +#include "dev-gpio-buttons.h"
  6820. +#include "dev-leds-gpio.h"
  6821. +#include "nvram.h"
  6822. +
  6823. +#define TEW_632BRP_GPIO_LED_STATUS 1
  6824. +#define TEW_632BRP_GPIO_LED_WPS 3
  6825. +#define TEW_632BRP_GPIO_LED_WLAN 6
  6826. +#define TEW_632BRP_GPIO_BTN_WPS 12
  6827. +#define TEW_632BRP_GPIO_BTN_RESET 21
  6828. +
  6829. +#define TEW_632BRP_KEYS_POLL_INTERVAL 20 /* msecs */
  6830. +#define TEW_632BRP_KEYS_DEBOUNCE_INTERVAL (3 * TEW_632BRP_KEYS_POLL_INTERVAL)
  6831. +
  6832. +#define TEW_632BRP_CONFIG_ADDR 0x1f020000
  6833. +#define TEW_632BRP_CONFIG_SIZE 0x10000
  6834. +
  6835. +#ifdef CONFIG_MTD_PARTITIONS
  6836. +static struct mtd_partition tew_632brp_partitions[] = {
  6837. + {
  6838. + .name = "u-boot",
  6839. + .offset = 0,
  6840. + .size = 0x020000,
  6841. + .mask_flags = MTD_WRITEABLE,
  6842. + }, {
  6843. + .name = "config",
  6844. + .offset = 0x020000,
  6845. + .size = 0x010000,
  6846. + }, {
  6847. + .name = "kernel",
  6848. + .offset = 0x030000,
  6849. + .size = 0x0e0000,
  6850. + }, {
  6851. + .name = "rootfs",
  6852. + .offset = 0x110000,
  6853. + .size = 0x2e0000,
  6854. + }, {
  6855. + .name = "art",
  6856. + .offset = 0x3f0000,
  6857. + .size = 0x010000,
  6858. + .mask_flags = MTD_WRITEABLE,
  6859. + }, {
  6860. + .name = "firmware",
  6861. + .offset = 0x030000,
  6862. + .size = 0x3c0000,
  6863. + }
  6864. +};
  6865. +#endif /* CONFIG_MTD_PARTITIONS */
  6866. +
  6867. +static struct flash_platform_data tew_632brp_flash_data = {
  6868. +#ifdef CONFIG_MTD_PARTITIONS
  6869. + .parts = tew_632brp_partitions,
  6870. + .nr_parts = ARRAY_SIZE(tew_632brp_partitions),
  6871. +#endif
  6872. +};
  6873. +
  6874. +static struct gpio_led tew_632brp_leds_gpio[] __initdata = {
  6875. + {
  6876. + .name = "tew-632brp:green:status",
  6877. + .gpio = TEW_632BRP_GPIO_LED_STATUS,
  6878. + .active_low = 1,
  6879. + }, {
  6880. + .name = "tew-632brp:blue:wps",
  6881. + .gpio = TEW_632BRP_GPIO_LED_WPS,
  6882. + .active_low = 1,
  6883. + }, {
  6884. + .name = "tew-632brp:green:wlan",
  6885. + .gpio = TEW_632BRP_GPIO_LED_WLAN,
  6886. + .active_low = 1,
  6887. + }
  6888. +};
  6889. +
  6890. +static struct gpio_keys_button tew_632brp_gpio_keys[] __initdata = {
  6891. + {
  6892. + .desc = "reset",
  6893. + .type = EV_KEY,
  6894. + .code = KEY_RESTART,
  6895. + .debounce_interval = TEW_632BRP_KEYS_DEBOUNCE_INTERVAL,
  6896. + .gpio = TEW_632BRP_GPIO_BTN_RESET,
  6897. + }, {
  6898. + .desc = "wps",
  6899. + .type = EV_KEY,
  6900. + .code = KEY_WPS_BUTTON,
  6901. + .debounce_interval = TEW_632BRP_KEYS_DEBOUNCE_INTERVAL,
  6902. + .gpio = TEW_632BRP_GPIO_BTN_WPS,
  6903. + }
  6904. +};
  6905. +
  6906. +#define TEW_632BRP_LAN_PHYMASK BIT(0)
  6907. +#define TEW_632BRP_WAN_PHYMASK BIT(4)
  6908. +#define TEW_632BRP_MDIO_MASK (~(TEW_632BRP_LAN_PHYMASK | \
  6909. + TEW_632BRP_WAN_PHYMASK))
  6910. +
  6911. +static void __init tew_632brp_setup(void)
  6912. +{
  6913. + const char *config = (char *) KSEG1ADDR(TEW_632BRP_CONFIG_ADDR);
  6914. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  6915. + u8 mac[6];
  6916. + u8 *wlan_mac = NULL;
  6917. +
  6918. + if (nvram_parse_mac_addr(config, TEW_632BRP_CONFIG_SIZE,
  6919. + "lan_mac=", mac) == 0) {
  6920. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  6921. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  6922. + wlan_mac = mac;
  6923. + }
  6924. +
  6925. + ar71xx_add_device_mdio(TEW_632BRP_MDIO_MASK);
  6926. +
  6927. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6928. + ar71xx_eth0_data.phy_mask = TEW_632BRP_LAN_PHYMASK;
  6929. +
  6930. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6931. + ar71xx_eth1_data.phy_mask = TEW_632BRP_WAN_PHYMASK;
  6932. +
  6933. + ar71xx_add_device_eth(0);
  6934. + ar71xx_add_device_eth(1);
  6935. +
  6936. + ar71xx_add_device_m25p80(&tew_632brp_flash_data);
  6937. +
  6938. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew_632brp_leds_gpio),
  6939. + tew_632brp_leds_gpio);
  6940. +
  6941. + ar71xx_register_gpio_keys_polled(-1, TEW_632BRP_KEYS_POLL_INTERVAL,
  6942. + ARRAY_SIZE(tew_632brp_gpio_keys),
  6943. + tew_632brp_gpio_keys);
  6944. +
  6945. + ar9xxx_add_device_wmac(eeprom, wlan_mac);
  6946. +}
  6947. +
  6948. +MIPS_MACHINE(AR71XX_MACH_TEW_632BRP, "TEW-632BRP", "TRENDnet TEW-632BRP",
  6949. + tew_632brp_setup);
  6950. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-mr3x20.c linux-2.6.39/arch/mips/ar71xx/mach-tl-mr3x20.c
  6951. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-mr3x20.c 1970-01-01 01:00:00.000000000 +0100
  6952. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-mr3x20.c 2011-08-24 02:41:55.577989822 +0200
  6953. @@ -0,0 +1,166 @@
  6954. +/*
  6955. + * TP-LINK TL-MR3220/3420 board support
  6956. + *
  6957. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  6958. + *
  6959. + * This program is free software; you can redistribute it and/or modify it
  6960. + * under the terms of the GNU General Public License version 2 as published
  6961. + * by the Free Software Foundation.
  6962. + */
  6963. +
  6964. +#include <linux/gpio.h>
  6965. +#include <linux/mtd/mtd.h>
  6966. +#include <linux/mtd/partitions.h>
  6967. +
  6968. +#include <asm/mach-ar71xx/ar71xx.h>
  6969. +
  6970. +#include "machtype.h"
  6971. +#include "devices.h"
  6972. +#include "dev-m25p80.h"
  6973. +#include "dev-ap91-pci.h"
  6974. +#include "dev-gpio-buttons.h"
  6975. +#include "dev-leds-gpio.h"
  6976. +#include "dev-usb.h"
  6977. +
  6978. +#define TL_MR3X20_GPIO_LED_QSS 0
  6979. +#define TL_MR3X20_GPIO_LED_SYSTEM 1
  6980. +#define TL_MR3X20_GPIO_LED_3G 8
  6981. +
  6982. +#define TL_MR3X20_GPIO_BTN_RESET 11
  6983. +#define TL_MR3X20_GPIO_BTN_QSS 12
  6984. +
  6985. +#define TL_MR3X20_GPIO_USB_POWER 6
  6986. +
  6987. +#define TL_MR3X20_KEYS_POLL_INTERVAL 20 /* msecs */
  6988. +#define TL_MR3X20_KEYS_DEBOUNCE_INTERVAL (3 * TL_MR3X20_KEYS_POLL_INTERVAL)
  6989. +
  6990. +#ifdef CONFIG_MTD_PARTITIONS
  6991. +static struct mtd_partition tl_mr3x20_partitions[] = {
  6992. + {
  6993. + .name = "u-boot",
  6994. + .offset = 0,
  6995. + .size = 0x020000,
  6996. + .mask_flags = MTD_WRITEABLE,
  6997. + }, {
  6998. + .name = "kernel",
  6999. + .offset = 0x020000,
  7000. + .size = 0x140000,
  7001. + }, {
  7002. + .name = "rootfs",
  7003. + .offset = 0x160000,
  7004. + .size = 0x290000,
  7005. + }, {
  7006. + .name = "art",
  7007. + .offset = 0x3f0000,
  7008. + .size = 0x010000,
  7009. + .mask_flags = MTD_WRITEABLE,
  7010. + }, {
  7011. + .name = "firmware",
  7012. + .offset = 0x020000,
  7013. + .size = 0x3d0000,
  7014. + }
  7015. +};
  7016. +#define tl_mr3x20_num_partitions ARRAY_SIZE(tl_mr3x20_partitions)
  7017. +#else
  7018. +#define tl_mr3x20_partitions NULL
  7019. +#define tl_mr3x20_num_partitions 0
  7020. +#endif /* CONFIG_MTD_PARTITIONS */
  7021. +
  7022. +static struct flash_platform_data tl_mr3x20_flash_data = {
  7023. + .parts = tl_mr3x20_partitions,
  7024. + .nr_parts = tl_mr3x20_num_partitions,
  7025. +};
  7026. +
  7027. +static struct gpio_led tl_mr3x20_leds_gpio[] __initdata = {
  7028. + {
  7029. + .name = "tl-mr3x20:green:system",
  7030. + .gpio = TL_MR3X20_GPIO_LED_SYSTEM,
  7031. + .active_low = 1,
  7032. + }, {
  7033. + .name = "tl-mr3x20:green:qss",
  7034. + .gpio = TL_MR3X20_GPIO_LED_QSS,
  7035. + .active_low = 1,
  7036. + }, {
  7037. + .name = "tl-mr3x20:green:3g",
  7038. + .gpio = TL_MR3X20_GPIO_LED_3G,
  7039. + .active_low = 1,
  7040. + }
  7041. +};
  7042. +
  7043. +static struct gpio_keys_button tl_mr3x20_gpio_keys[] __initdata = {
  7044. + {
  7045. + .desc = "reset",
  7046. + .type = EV_KEY,
  7047. + .code = KEY_RESTART,
  7048. + .debounce_interval = TL_MR3X20_KEYS_DEBOUNCE_INTERVAL,
  7049. + .gpio = TL_MR3X20_GPIO_BTN_RESET,
  7050. + .active_low = 1,
  7051. + }, {
  7052. + .desc = "qss",
  7053. + .type = EV_KEY,
  7054. + .code = KEY_WPS_BUTTON,
  7055. + .debounce_interval = TL_MR3X20_KEYS_DEBOUNCE_INTERVAL,
  7056. + .gpio = TL_MR3X20_GPIO_BTN_QSS,
  7057. + .active_low = 1,
  7058. + }
  7059. +};
  7060. +
  7061. +static void __init tl_mr3x20_setup(void)
  7062. +{
  7063. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7064. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  7065. +
  7066. + /* enable power for the USB port */
  7067. + gpio_request(TL_MR3X20_GPIO_USB_POWER, "USB power");
  7068. + gpio_direction_output(TL_MR3X20_GPIO_USB_POWER, 1);
  7069. +
  7070. + ar71xx_add_device_m25p80(&tl_mr3x20_flash_data);
  7071. +
  7072. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_mr3x20_leds_gpio),
  7073. + tl_mr3x20_leds_gpio);
  7074. +
  7075. + ar71xx_register_gpio_keys_polled(-1, TL_MR3X20_KEYS_POLL_INTERVAL,
  7076. + ARRAY_SIZE(tl_mr3x20_gpio_keys),
  7077. + tl_mr3x20_gpio_keys);
  7078. +
  7079. + ar71xx_eth1_data.has_ar7240_switch = 1;
  7080. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7081. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  7082. +
  7083. + /* WAN port */
  7084. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7085. + ar71xx_eth0_data.speed = SPEED_100;
  7086. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7087. + ar71xx_eth0_data.phy_mask = BIT(4);
  7088. +
  7089. + /* LAN ports */
  7090. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7091. + ar71xx_eth1_data.speed = SPEED_1000;
  7092. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  7093. +
  7094. + ar71xx_add_device_mdio(0x0);
  7095. + ar71xx_add_device_eth(1);
  7096. + ar71xx_add_device_eth(0);
  7097. +
  7098. + ar71xx_add_device_usb();
  7099. +
  7100. + ap91_pci_init(ee, mac);
  7101. +}
  7102. +
  7103. +static void __init tl_mr3220_setup(void)
  7104. +{
  7105. + tl_mr3x20_setup();
  7106. + ap91_pci_setup_wmac_led_pin(1);
  7107. +}
  7108. +
  7109. +MIPS_MACHINE(AR71XX_MACH_TL_MR3220, "TL-MR3220", "TP-LINK TL-MR3220",
  7110. + tl_mr3220_setup);
  7111. +
  7112. +static void __init tl_mr3420_setup(void)
  7113. +{
  7114. + tl_mr3x20_setup();
  7115. + ap91_pci_setup_wmac_led_pin(0);
  7116. +}
  7117. +
  7118. +MIPS_MACHINE(AR71XX_MACH_TL_MR3420, "TL-MR3420", "TP-LINK TL-MR3420",
  7119. + tl_mr3420_setup);
  7120. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wa901nd.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wa901nd.c
  7121. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wa901nd.c 1970-01-01 01:00:00.000000000 +0100
  7122. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wa901nd.c 2011-08-24 02:41:55.587990766 +0200
  7123. @@ -0,0 +1,130 @@
  7124. +/*
  7125. + * TP-LINK TL-WA901ND board support
  7126. + *
  7127. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  7128. + * Copyright (C) 2010 Pieter Hollants <pieter@hollants.com>
  7129. + *
  7130. + * This program is free software; you can redistribute it and/or modify it
  7131. + * under the terms of the GNU General Public License version 2 as published
  7132. + * by the Free Software Foundation.
  7133. + */
  7134. +
  7135. +#include <linux/mtd/mtd.h>
  7136. +#include <linux/mtd/partitions.h>
  7137. +
  7138. +#include <asm/mach-ar71xx/ar71xx.h>
  7139. +
  7140. +#include "machtype.h"
  7141. +#include "devices.h"
  7142. +#include "dev-m25p80.h"
  7143. +#include "dev-ap91-pci.h"
  7144. +#include "dev-gpio-buttons.h"
  7145. +#include "dev-leds-gpio.h"
  7146. +
  7147. +#define TL_WA901ND_GPIO_LED_QSS 0
  7148. +#define TL_WA901ND_GPIO_LED_SYSTEM 1
  7149. +
  7150. +#define TL_WA901ND_GPIO_BTN_RESET 11
  7151. +#define TL_WA901ND_GPIO_BTN_QSS 12
  7152. +
  7153. +#define TL_WA901ND_KEYS_POLL_INTERVAL 20 /* msecs */
  7154. +#define TL_WA901ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WA901ND_KEYS_POLL_INTERVAL)
  7155. +
  7156. +#ifdef CONFIG_MTD_PARTITIONS
  7157. +static struct mtd_partition tl_wa901nd_partitions[] = {
  7158. + {
  7159. + .name = "u-boot",
  7160. + .offset = 0,
  7161. + .size = 0x020000,
  7162. + .mask_flags = MTD_WRITEABLE,
  7163. + }, {
  7164. + .name = "kernel",
  7165. + .offset = 0x020000,
  7166. + .size = 0x140000,
  7167. + }, {
  7168. + .name = "rootfs",
  7169. + .offset = 0x160000,
  7170. + .size = 0x290000,
  7171. + }, {
  7172. + .name = "art",
  7173. + .offset = 0x3f0000,
  7174. + .size = 0x010000,
  7175. + .mask_flags = MTD_WRITEABLE,
  7176. + }, {
  7177. + .name = "firmware",
  7178. + .offset = 0x020000,
  7179. + .size = 0x3d0000,
  7180. + }
  7181. +};
  7182. +#endif /* CONFIG_MTD_PARTITIONS */
  7183. +
  7184. +static struct flash_platform_data tl_wa901nd_flash_data = {
  7185. +#ifdef CONFIG_MTD_PARTITIONS
  7186. + .parts = tl_wa901nd_partitions,
  7187. + .nr_parts = ARRAY_SIZE(tl_wa901nd_partitions),
  7188. +#endif
  7189. +};
  7190. +
  7191. +static struct gpio_led tl_wa901nd_leds_gpio[] __initdata = {
  7192. + {
  7193. + .name = "tl-wa901nd:green:system",
  7194. + .gpio = TL_WA901ND_GPIO_LED_SYSTEM,
  7195. + .active_low = 1,
  7196. + }, {
  7197. + .name = "tl-wa901nd:green:qss",
  7198. + .gpio = TL_WA901ND_GPIO_LED_QSS,
  7199. + .active_low = 1,
  7200. + }
  7201. +};
  7202. +
  7203. +static struct gpio_keys_button tl_wa901nd_gpio_keys[] __initdata = {
  7204. + {
  7205. + .desc = "reset",
  7206. + .type = EV_KEY,
  7207. + .code = BTN_0,
  7208. + .debounce_interval = TL_WA901ND_KEYS_DEBOUNCE_INTERVAL,
  7209. + .gpio = TL_WA901ND_GPIO_BTN_RESET,
  7210. + .active_low = 1,
  7211. + }, {
  7212. + .desc = "qss",
  7213. + .type = EV_KEY,
  7214. + .code = BTN_1,
  7215. + .debounce_interval = TL_WA901ND_KEYS_DEBOUNCE_INTERVAL,
  7216. + .gpio = TL_WA901ND_GPIO_BTN_QSS,
  7217. + .active_low = 1,
  7218. + }
  7219. +};
  7220. +
  7221. +static void __init tl_wa901nd_setup(void)
  7222. +{
  7223. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7224. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  7225. +
  7226. + /*
  7227. + * ar71xx_eth0 would be the WAN port, but is not connected on
  7228. + * the TL-WA901ND. ar71xx_eth1 connects to the internal switch chip,
  7229. + * however we have a single LAN port only.
  7230. + */
  7231. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 0);
  7232. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7233. + ar71xx_eth1_data.speed = SPEED_1000;
  7234. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  7235. + ar71xx_eth1_data.has_ar7240_switch = 1;
  7236. +
  7237. + ar71xx_add_device_mdio(0x0);
  7238. + ar71xx_add_device_eth(1);
  7239. +
  7240. + ar71xx_add_device_m25p80(&tl_wa901nd_flash_data);
  7241. +
  7242. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wa901nd_leds_gpio),
  7243. + tl_wa901nd_leds_gpio);
  7244. +
  7245. + ar71xx_register_gpio_keys_polled(-1, TL_WA901ND_KEYS_POLL_INTERVAL,
  7246. + ARRAY_SIZE(tl_wa901nd_gpio_keys),
  7247. + tl_wa901nd_gpio_keys);
  7248. +
  7249. + ap91_pci_init(ee, mac);
  7250. +}
  7251. +
  7252. +MIPS_MACHINE(AR71XX_MACH_TL_WA901ND, "TL-WA901ND", "TP-LINK TL-WA901ND",
  7253. + tl_wa901nd_setup);
  7254. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wa901nd-v2.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wa901nd-v2.c
  7255. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wa901nd-v2.c 1970-01-01 01:00:00.000000000 +0100
  7256. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wa901nd-v2.c 2011-08-24 02:41:55.587990766 +0200
  7257. @@ -0,0 +1,132 @@
  7258. +/*
  7259. + * TP-LINK TL-WA901ND v2 board support
  7260. + *
  7261. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  7262. + * Copyright (C) 2010 Pieter Hollants <pieter@hollants.com>
  7263. + * Copyright (C) 2011 Jonathan Bennett <jbscience87@gmail.com>
  7264. + *
  7265. + * This program is free software; you can redistribute it and/or modify it
  7266. + * under the terms of the GNU General Public License version 2 as published
  7267. + * by the Free Software Foundation.
  7268. + */
  7269. +
  7270. +#include <linux/mtd/mtd.h>
  7271. +#include <linux/mtd/partitions.h>
  7272. +
  7273. +#include <asm/mach-ar71xx/ar71xx.h>
  7274. +
  7275. +#include "machtype.h"
  7276. +#include "devices.h"
  7277. +#include "dev-m25p80.h"
  7278. +#include "dev-gpio-buttons.h"
  7279. +#include "dev-leds-gpio.h"
  7280. +#include "dev-ar9xxx-wmac.h"
  7281. +
  7282. +#define TL_WA901ND_V2_GPIO_LED_QSS 4
  7283. +#define TL_WA901ND_V2_GPIO_LED_SYSTEM 2
  7284. +#define TL_WA901ND_V2_GPIO_LED_WLAN 9
  7285. +
  7286. +
  7287. +#define TL_WA901ND_V2_GPIO_BTN_RESET 3
  7288. +#define TL_WA901ND_V2_GPIO_BTN_QSS 7
  7289. +
  7290. +#define TL_WA901ND_V2_KEYS_POLL_INTERVAL 20 /* msecs */
  7291. +#define TL_WA901ND_V2_KEYS_DEBOUNCE_INTERVAL \
  7292. + (3 * TL_WA901ND_V2_KEYS_POLL_INTERVAL)
  7293. +#ifdef CONFIG_MTD_PARTITIONS
  7294. +static struct mtd_partition tl_wa901nd_v2_partitions[] = {
  7295. + {
  7296. + .name = "u-boot",
  7297. + .offset = 0,
  7298. + .size = 0x020000,
  7299. + .mask_flags = MTD_WRITEABLE,
  7300. + }, {
  7301. + .name = "kernel",
  7302. + .offset = 0x020000,
  7303. + .size = 0x140000,
  7304. + }, {
  7305. + .name = "rootfs",
  7306. + .offset = 0x160000,
  7307. + .size = 0x290000,
  7308. + }, {
  7309. + .name = "art",
  7310. + .offset = 0x3f0000,
  7311. + .size = 0x010000,
  7312. + .mask_flags = MTD_WRITEABLE,
  7313. + }, {
  7314. + .name = "firmware",
  7315. + .offset = 0x020000,
  7316. + .size = 0x3d0000,
  7317. + }
  7318. +};
  7319. +#endif /* CONFIG_MTD_PARTITIONS */
  7320. +
  7321. +static struct flash_platform_data tl_wa901nd_v2_flash_data = {
  7322. +#ifdef CONFIG_MTD_PARTITIONS
  7323. + .parts = tl_wa901nd_v2_partitions,
  7324. + .nr_parts = ARRAY_SIZE(tl_wa901nd_v2_partitions),
  7325. +#endif
  7326. +};
  7327. +
  7328. +static struct gpio_led tl_wa901nd_v2_leds_gpio[] __initdata = {
  7329. + {
  7330. + .name = "tl-wa901nd-v2:green:system",
  7331. + .gpio = TL_WA901ND_V2_GPIO_LED_SYSTEM,
  7332. + .active_low = 1,
  7333. + }, {
  7334. + .name = "tl-wa901nd-v2:green:qss",
  7335. + .gpio = TL_WA901ND_V2_GPIO_LED_QSS,
  7336. + }, {
  7337. + .name = "tl-wa901nd-v2:green:wlan",
  7338. + .gpio = TL_WA901ND_V2_GPIO_LED_WLAN,
  7339. + .active_low = 1,
  7340. + }
  7341. +};
  7342. +
  7343. +static struct gpio_keys_button tl_wa901nd_v2_gpio_keys[] __initdata = {
  7344. + {
  7345. + .desc = "reset",
  7346. + .type = EV_KEY,
  7347. + .code = KEY_RESTART,
  7348. + .debounce_interval = TL_WA901ND_V2_KEYS_DEBOUNCE_INTERVAL,
  7349. + .gpio = TL_WA901ND_V2_GPIO_BTN_RESET,
  7350. + .active_low = 1,
  7351. + }, {
  7352. + .desc = "qss",
  7353. + .type = EV_KEY,
  7354. + .code = KEY_WPS_BUTTON,
  7355. + .debounce_interval = TL_WA901ND_V2_KEYS_DEBOUNCE_INTERVAL,
  7356. + .gpio = TL_WA901ND_V2_GPIO_BTN_QSS,
  7357. + .active_low = 1,
  7358. + }
  7359. +};
  7360. +
  7361. +static void __init tl_wa901nd_v2_setup(void)
  7362. +{
  7363. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7364. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  7365. +
  7366. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7367. +
  7368. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  7369. + ar71xx_eth0_data.phy_mask = 0x00001000;
  7370. + ar71xx_add_device_mdio(0x0);
  7371. +
  7372. + ar71xx_eth0_data.reset_bit = RESET_MODULE_GE0_MAC |
  7373. + RESET_MODULE_GE0_PHY;
  7374. + ar71xx_add_device_eth(0);
  7375. +
  7376. + ar71xx_add_device_m25p80(&tl_wa901nd_v2_flash_data);
  7377. +
  7378. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wa901nd_v2_leds_gpio),
  7379. + tl_wa901nd_v2_leds_gpio);
  7380. +
  7381. + ar71xx_register_gpio_keys_polled(-1, TL_WA901ND_V2_KEYS_POLL_INTERVAL,
  7382. + ARRAY_SIZE(tl_wa901nd_v2_gpio_keys),
  7383. + tl_wa901nd_v2_gpio_keys);
  7384. +
  7385. + ar9xxx_add_device_wmac(eeprom, mac);
  7386. +}
  7387. +
  7388. +MIPS_MACHINE(AR71XX_MACH_TL_WA901ND_V2, "TL-WA901ND-v2",
  7389. + "TP-LINK TL-WA901ND v2", tl_wa901nd_v2_setup);
  7390. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wr1043nd.c
  7391. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c 1970-01-01 01:00:00.000000000 +0100
  7392. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wr1043nd.c 2011-08-24 02:41:55.587990766 +0200
  7393. @@ -0,0 +1,156 @@
  7394. +/*
  7395. + * TP-LINK TL-WR1043ND board support
  7396. + *
  7397. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7398. + *
  7399. + * This program is free software; you can redistribute it and/or modify it
  7400. + * under the terms of the GNU General Public License version 2 as published
  7401. + * by the Free Software Foundation.
  7402. + */
  7403. +
  7404. +#include <linux/mtd/mtd.h>
  7405. +#include <linux/mtd/partitions.h>
  7406. +#include <linux/platform_device.h>
  7407. +#include <linux/rtl8366.h>
  7408. +#include <asm/mach-ar71xx/ar71xx.h>
  7409. +
  7410. +#include "machtype.h"
  7411. +#include "devices.h"
  7412. +#include "dev-m25p80.h"
  7413. +#include "dev-ar9xxx-wmac.h"
  7414. +#include "dev-gpio-buttons.h"
  7415. +#include "dev-leds-gpio.h"
  7416. +#include "dev-usb.h"
  7417. +
  7418. +#define TL_WR1043ND_GPIO_LED_USB 1
  7419. +#define TL_WR1043ND_GPIO_LED_SYSTEM 2
  7420. +#define TL_WR1043ND_GPIO_LED_QSS 5
  7421. +#define TL_WR1043ND_GPIO_LED_WLAN 9
  7422. +
  7423. +#define TL_WR1043ND_GPIO_BTN_RESET 3
  7424. +#define TL_WR1043ND_GPIO_BTN_QSS 7
  7425. +
  7426. +#define TL_WR1043ND_GPIO_RTL8366_SDA 18
  7427. +#define TL_WR1043ND_GPIO_RTL8366_SCK 19
  7428. +
  7429. +#define TL_WR1043ND_KEYS_POLL_INTERVAL 20 /* msecs */
  7430. +#define TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043ND_KEYS_POLL_INTERVAL)
  7431. +
  7432. +#ifdef CONFIG_MTD_PARTITIONS
  7433. +static struct mtd_partition tl_wr1043nd_partitions[] = {
  7434. + {
  7435. + .name = "u-boot",
  7436. + .offset = 0,
  7437. + .size = 0x020000,
  7438. + .mask_flags = MTD_WRITEABLE,
  7439. + }, {
  7440. + .name = "kernel",
  7441. + .offset = 0x020000,
  7442. + .size = 0x140000,
  7443. + }, {
  7444. + .name = "rootfs",
  7445. + .offset = 0x160000,
  7446. + .size = 0x690000,
  7447. + }, {
  7448. + .name = "art",
  7449. + .offset = 0x7f0000,
  7450. + .size = 0x010000,
  7451. + .mask_flags = MTD_WRITEABLE,
  7452. + }, {
  7453. + .name = "firmware",
  7454. + .offset = 0x020000,
  7455. + .size = 0x7d0000,
  7456. + }
  7457. +};
  7458. +#endif /* CONFIG_MTD_PARTITIONS */
  7459. +
  7460. +static struct flash_platform_data tl_wr1043nd_flash_data = {
  7461. +#ifdef CONFIG_MTD_PARTITIONS
  7462. + .parts = tl_wr1043nd_partitions,
  7463. + .nr_parts = ARRAY_SIZE(tl_wr1043nd_partitions),
  7464. +#endif
  7465. +};
  7466. +
  7467. +static struct gpio_led tl_wr1043nd_leds_gpio[] __initdata = {
  7468. + {
  7469. + .name = "tl-wr1043nd:green:usb",
  7470. + .gpio = TL_WR1043ND_GPIO_LED_USB,
  7471. + .active_low = 1,
  7472. + }, {
  7473. + .name = "tl-wr1043nd:green:system",
  7474. + .gpio = TL_WR1043ND_GPIO_LED_SYSTEM,
  7475. + .active_low = 1,
  7476. + }, {
  7477. + .name = "tl-wr1043nd:green:qss",
  7478. + .gpio = TL_WR1043ND_GPIO_LED_QSS,
  7479. + .active_low = 0,
  7480. + }, {
  7481. + .name = "tl-wr1043nd:green:wlan",
  7482. + .gpio = TL_WR1043ND_GPIO_LED_WLAN,
  7483. + .active_low = 1,
  7484. + }
  7485. +};
  7486. +
  7487. +static struct gpio_keys_button tl_wr1043nd_gpio_keys[] __initdata = {
  7488. + {
  7489. + .desc = "reset",
  7490. + .type = EV_KEY,
  7491. + .code = KEY_RESTART,
  7492. + .debounce_interval = TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL,
  7493. + .gpio = TL_WR1043ND_GPIO_BTN_RESET,
  7494. + .active_low = 1,
  7495. + }, {
  7496. + .desc = "qss",
  7497. + .type = EV_KEY,
  7498. + .code = KEY_WPS_BUTTON,
  7499. + .debounce_interval = TL_WR1043ND_KEYS_DEBOUNCE_INTERVAL,
  7500. + .gpio = TL_WR1043ND_GPIO_BTN_QSS,
  7501. + .active_low = 1,
  7502. + }
  7503. +};
  7504. +
  7505. +static struct rtl8366_platform_data tl_wr1043nd_rtl8366rb_data = {
  7506. + .gpio_sda = TL_WR1043ND_GPIO_RTL8366_SDA,
  7507. + .gpio_sck = TL_WR1043ND_GPIO_RTL8366_SCK,
  7508. +};
  7509. +
  7510. +static struct platform_device tl_wr1043nd_rtl8366rb_device = {
  7511. + .name = RTL8366RB_DRIVER_NAME,
  7512. + .id = -1,
  7513. + .dev = {
  7514. + .platform_data = &tl_wr1043nd_rtl8366rb_data,
  7515. + }
  7516. +};
  7517. +
  7518. +static void __init tl_wr1043nd_setup(void)
  7519. +{
  7520. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7521. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  7522. +
  7523. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7524. + ar71xx_eth0_data.mii_bus_dev = &tl_wr1043nd_rtl8366rb_device.dev;
  7525. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  7526. + ar71xx_eth0_data.speed = SPEED_1000;
  7527. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7528. + ar71xx_eth0_pll_data.pll_1000 = 0x1a000000;
  7529. +
  7530. + ar71xx_add_device_eth(0);
  7531. +
  7532. + ar71xx_add_device_usb();
  7533. +
  7534. + ar71xx_add_device_m25p80(&tl_wr1043nd_flash_data);
  7535. +
  7536. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_leds_gpio),
  7537. + tl_wr1043nd_leds_gpio);
  7538. +
  7539. + platform_device_register(&tl_wr1043nd_rtl8366rb_device);
  7540. +
  7541. + ar71xx_register_gpio_keys_polled(-1, TL_WR1043ND_KEYS_POLL_INTERVAL,
  7542. + ARRAY_SIZE(tl_wr1043nd_gpio_keys),
  7543. + tl_wr1043nd_gpio_keys);
  7544. +
  7545. + ar9xxx_add_device_wmac(eeprom, mac);
  7546. +}
  7547. +
  7548. +MIPS_MACHINE(AR71XX_MACH_TL_WR1043ND, "TL-WR1043ND", "TP-LINK TL-WR1043ND",
  7549. + tl_wr1043nd_setup);
  7550. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr741nd.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wr741nd.c
  7551. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr741nd.c 1970-01-01 01:00:00.000000000 +0100
  7552. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wr741nd.c 2011-08-24 02:41:55.587990766 +0200
  7553. @@ -0,0 +1,135 @@
  7554. +/*
  7555. + * TP-LINK TL-WR741ND board support
  7556. + *
  7557. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  7558. + *
  7559. + * This program is free software; you can redistribute it and/or modify it
  7560. + * under the terms of the GNU General Public License version 2 as published
  7561. + * by the Free Software Foundation.
  7562. + */
  7563. +
  7564. +#include <linux/mtd/mtd.h>
  7565. +#include <linux/mtd/partitions.h>
  7566. +
  7567. +#include <asm/mach-ar71xx/ar71xx.h>
  7568. +
  7569. +#include "machtype.h"
  7570. +#include "devices.h"
  7571. +#include "dev-m25p80.h"
  7572. +#include "dev-ap91-pci.h"
  7573. +#include "dev-gpio-buttons.h"
  7574. +#include "dev-leds-gpio.h"
  7575. +
  7576. +#define TL_WR741ND_GPIO_LED_QSS 0
  7577. +#define TL_WR741ND_GPIO_LED_SYSTEM 1
  7578. +
  7579. +#define TL_WR741ND_GPIO_BTN_RESET 11
  7580. +#define TL_WR741ND_GPIO_BTN_QSS 12
  7581. +
  7582. +#define TL_WR741ND_KEYS_POLL_INTERVAL 20 /* msecs */
  7583. +#define TL_WR741ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741ND_KEYS_POLL_INTERVAL)
  7584. +
  7585. +#ifdef CONFIG_MTD_PARTITIONS
  7586. +static struct mtd_partition tl_wr741nd_partitions[] = {
  7587. + {
  7588. + .name = "u-boot",
  7589. + .offset = 0,
  7590. + .size = 0x020000,
  7591. + .mask_flags = MTD_WRITEABLE,
  7592. + }, {
  7593. + .name = "kernel",
  7594. + .offset = 0x020000,
  7595. + .size = 0x140000,
  7596. + }, {
  7597. + .name = "rootfs",
  7598. + .offset = 0x160000,
  7599. + .size = 0x290000,
  7600. + }, {
  7601. + .name = "art",
  7602. + .offset = 0x3f0000,
  7603. + .size = 0x010000,
  7604. + .mask_flags = MTD_WRITEABLE,
  7605. + }, {
  7606. + .name = "firmware",
  7607. + .offset = 0x020000,
  7608. + .size = 0x3d0000,
  7609. + }
  7610. +};
  7611. +#endif /* CONFIG_MTD_PARTITIONS */
  7612. +
  7613. +static struct flash_platform_data tl_wr741nd_flash_data = {
  7614. +#ifdef CONFIG_MTD_PARTITIONS
  7615. + .parts = tl_wr741nd_partitions,
  7616. + .nr_parts = ARRAY_SIZE(tl_wr741nd_partitions),
  7617. +#endif
  7618. +};
  7619. +
  7620. +static struct gpio_led tl_wr741nd_leds_gpio[] __initdata = {
  7621. + {
  7622. + .name = "tl-wr741nd:green:system",
  7623. + .gpio = TL_WR741ND_GPIO_LED_SYSTEM,
  7624. + .active_low = 1,
  7625. + }, {
  7626. + .name = "tl-wr741nd:green:qss",
  7627. + .gpio = TL_WR741ND_GPIO_LED_QSS,
  7628. + .active_low = 1,
  7629. + }
  7630. +};
  7631. +
  7632. +static struct gpio_keys_button tl_wr741nd_gpio_keys[] __initdata = {
  7633. + {
  7634. + .desc = "reset",
  7635. + .type = EV_KEY,
  7636. + .code = KEY_RESTART,
  7637. + .debounce_interval = TL_WR741ND_KEYS_DEBOUNCE_INTERVAL,
  7638. + .gpio = TL_WR741ND_GPIO_BTN_RESET,
  7639. + .active_low = 1,
  7640. + }, {
  7641. + .desc = "qss",
  7642. + .type = EV_KEY,
  7643. + .code = KEY_WPS_BUTTON,
  7644. + .debounce_interval = TL_WR741ND_KEYS_DEBOUNCE_INTERVAL,
  7645. + .gpio = TL_WR741ND_GPIO_BTN_QSS,
  7646. + .active_low = 1,
  7647. + }
  7648. +};
  7649. +
  7650. +static void __init tl_wr741nd_setup(void)
  7651. +{
  7652. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7653. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  7654. +
  7655. + ar71xx_add_device_m25p80(&tl_wr741nd_flash_data);
  7656. +
  7657. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr741nd_leds_gpio),
  7658. + tl_wr741nd_leds_gpio);
  7659. +
  7660. + ar71xx_register_gpio_keys_polled(-1, TL_WR741ND_KEYS_POLL_INTERVAL,
  7661. + ARRAY_SIZE(tl_wr741nd_gpio_keys),
  7662. + tl_wr741nd_gpio_keys);
  7663. +
  7664. + ar71xx_eth1_data.has_ar7240_switch = 1;
  7665. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7666. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  7667. +
  7668. + /* WAN port */
  7669. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7670. + ar71xx_eth0_data.speed = SPEED_100;
  7671. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7672. + ar71xx_eth0_data.phy_mask = BIT(4);
  7673. +
  7674. + /* LAN ports */
  7675. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7676. + ar71xx_eth1_data.speed = SPEED_1000;
  7677. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  7678. +
  7679. + ar71xx_add_device_mdio(0x0);
  7680. + ar71xx_add_device_eth(1);
  7681. + ar71xx_add_device_eth(0);
  7682. +
  7683. + ap91_pci_setup_wmac_led_pin(1);
  7684. +
  7685. + ap91_pci_init(ee, mac);
  7686. +}
  7687. +MIPS_MACHINE(AR71XX_MACH_TL_WR741ND, "TL-WR741ND", "TP-LINK TL-WR741ND",
  7688. + tl_wr741nd_setup);
  7689. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr841n.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wr841n.c
  7690. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr841n.c 1970-01-01 01:00:00.000000000 +0100
  7691. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wr841n.c 2011-08-24 02:41:55.597982750 +0200
  7692. @@ -0,0 +1,144 @@
  7693. +/*
  7694. + * TP-LINK TL-WR841N board support
  7695. + *
  7696. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7697. + *
  7698. + * This program is free software; you can redistribute it and/or modify it
  7699. + * under the terms of the GNU General Public License version 2 as published
  7700. + * by the Free Software Foundation.
  7701. + */
  7702. +
  7703. +#include <linux/mtd/mtd.h>
  7704. +#include <linux/mtd/partitions.h>
  7705. +
  7706. +#include <asm/mach-ar71xx/ar71xx.h>
  7707. +
  7708. +#include "machtype.h"
  7709. +#include "devices.h"
  7710. +#include "dev-dsa.h"
  7711. +#include "dev-m25p80.h"
  7712. +#include "dev-gpio-buttons.h"
  7713. +#include "dev-pb42-pci.h"
  7714. +#include "dev-leds-gpio.h"
  7715. +
  7716. +#define TL_WR841ND_V1_GPIO_LED_SYSTEM 2
  7717. +#define TL_WR841ND_V1_GPIO_LED_QSS_GREEN 4
  7718. +#define TL_WR841ND_V1_GPIO_LED_QSS_RED 5
  7719. +
  7720. +#define TL_WR841ND_V1_GPIO_BTN_RESET 3
  7721. +#define TL_WR841ND_V1_GPIO_BTN_QSS 7
  7722. +
  7723. +#define TL_WR841ND_V1_KEYS_POLL_INTERVAL 20 /* msecs */
  7724. +#define TL_WR841ND_V1_KEYS_DEBOUNCE_INTERVAL \
  7725. + (3 * TL_WR841ND_V1_KEYS_POLL_INTERVAL)
  7726. +
  7727. +#ifdef CONFIG_MTD_PARTITIONS
  7728. +static struct mtd_partition tl_wr841n_v1_partitions[] = {
  7729. + {
  7730. + .name = "redboot",
  7731. + .offset = 0,
  7732. + .size = 0x020000,
  7733. + .mask_flags = MTD_WRITEABLE,
  7734. + }, {
  7735. + .name = "kernel",
  7736. + .offset = 0x020000,
  7737. + .size = 0x140000,
  7738. + }, {
  7739. + .name = "rootfs",
  7740. + .offset = 0x160000,
  7741. + .size = 0x280000,
  7742. + }, {
  7743. + .name = "config",
  7744. + .offset = 0x3e0000,
  7745. + .size = 0x020000,
  7746. + .mask_flags = MTD_WRITEABLE,
  7747. + }, {
  7748. + .name = "firmware",
  7749. + .offset = 0x020000,
  7750. + .size = 0x3c0000,
  7751. + }
  7752. +};
  7753. +#endif /* CONFIG_MTD_PARTITIONS */
  7754. +
  7755. +static struct flash_platform_data tl_wr841n_v1_flash_data = {
  7756. +#ifdef CONFIG_MTD_PARTITIONS
  7757. + .parts = tl_wr841n_v1_partitions,
  7758. + .nr_parts = ARRAY_SIZE(tl_wr841n_v1_partitions),
  7759. +#endif
  7760. +};
  7761. +
  7762. +static struct gpio_led tl_wr841n_v1_leds_gpio[] __initdata = {
  7763. + {
  7764. + .name = "tl-wr841n:green:system",
  7765. + .gpio = TL_WR841ND_V1_GPIO_LED_SYSTEM,
  7766. + .active_low = 1,
  7767. + }, {
  7768. + .name = "tl-wr841n:red:qss",
  7769. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_RED,
  7770. + }, {
  7771. + .name = "tl-wr841n:green:qss",
  7772. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_GREEN,
  7773. + }
  7774. +};
  7775. +
  7776. +static struct gpio_keys_button tl_wr841n_v1_gpio_keys[] __initdata = {
  7777. + {
  7778. + .desc = "reset",
  7779. + .type = EV_KEY,
  7780. + .code = KEY_RESTART,
  7781. + .debounce_interval = TL_WR841ND_V1_KEYS_DEBOUNCE_INTERVAL,
  7782. + .gpio = TL_WR841ND_V1_GPIO_BTN_RESET,
  7783. + .active_low = 1,
  7784. + }, {
  7785. + .desc = "qss",
  7786. + .type = EV_KEY,
  7787. + .code = KEY_WPS_BUTTON,
  7788. + .debounce_interval = TL_WR841ND_V1_KEYS_DEBOUNCE_INTERVAL,
  7789. + .gpio = TL_WR841ND_V1_GPIO_BTN_QSS,
  7790. + .active_low = 1,
  7791. + }
  7792. +};
  7793. +
  7794. +static struct dsa_chip_data tl_wr841n_v1_dsa_chip = {
  7795. + .port_names[0] = "wan",
  7796. + .port_names[1] = "lan1",
  7797. + .port_names[2] = "lan2",
  7798. + .port_names[3] = "lan3",
  7799. + .port_names[4] = "lan4",
  7800. + .port_names[5] = "cpu",
  7801. +};
  7802. +
  7803. +static struct dsa_platform_data tl_wr841n_v1_dsa_data = {
  7804. + .nr_chips = 1,
  7805. + .chip = &tl_wr841n_v1_dsa_chip,
  7806. +};
  7807. +
  7808. +static void __init tl_wr841n_v1_setup(void)
  7809. +{
  7810. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7811. +
  7812. + ar71xx_add_device_mdio(0x0);
  7813. +
  7814. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7815. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7816. + ar71xx_eth0_data.speed = SPEED_100;
  7817. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7818. +
  7819. + ar71xx_add_device_eth(0);
  7820. +
  7821. + ar71xx_add_device_dsa(0, &tl_wr841n_v1_dsa_data);
  7822. +
  7823. + ar71xx_add_device_m25p80(&tl_wr841n_v1_flash_data);
  7824. +
  7825. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v1_leds_gpio),
  7826. + tl_wr841n_v1_leds_gpio);
  7827. +
  7828. + ar71xx_register_gpio_keys_polled(-1, TL_WR841ND_V1_KEYS_POLL_INTERVAL,
  7829. + ARRAY_SIZE(tl_wr841n_v1_gpio_keys),
  7830. + tl_wr841n_v1_gpio_keys);
  7831. +
  7832. + pb42_pci_init();
  7833. +}
  7834. +
  7835. +MIPS_MACHINE(AR71XX_MACH_TL_WR841N_V1, "TL-WR841N-v1.5", "TP-LINK TL-WR841N v1",
  7836. + tl_wr841n_v1_setup);
  7837. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr941nd.c linux-2.6.39/arch/mips/ar71xx/mach-tl-wr941nd.c
  7838. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-tl-wr941nd.c 1970-01-01 01:00:00.000000000 +0100
  7839. +++ linux-2.6.39/arch/mips/ar71xx/mach-tl-wr941nd.c 2011-08-24 02:41:55.597982750 +0200
  7840. @@ -0,0 +1,147 @@
  7841. +/*
  7842. + * TP-LINK TL-WR941ND board support
  7843. + *
  7844. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  7845. + *
  7846. + * This program is free software; you can redistribute it and/or modify it
  7847. + * under the terms of the GNU General Public License version 2 as published
  7848. + * by the Free Software Foundation.
  7849. + */
  7850. +
  7851. +#include <linux/mtd/mtd.h>
  7852. +#include <linux/mtd/partitions.h>
  7853. +
  7854. +#include <asm/mach-ar71xx/ar71xx.h>
  7855. +
  7856. +#include "machtype.h"
  7857. +#include "devices.h"
  7858. +#include "dev-dsa.h"
  7859. +#include "dev-m25p80.h"
  7860. +#include "dev-ar9xxx-wmac.h"
  7861. +#include "dev-gpio-buttons.h"
  7862. +#include "dev-leds-gpio.h"
  7863. +
  7864. +#define TL_WR941ND_GPIO_LED_SYSTEM 2
  7865. +#define TL_WR941ND_GPIO_LED_QSS_RED 4
  7866. +#define TL_WR941ND_GPIO_LED_QSS_GREEN 5
  7867. +#define TL_WR941ND_GPIO_LED_WLAN 9
  7868. +
  7869. +#define TL_WR941ND_GPIO_BTN_RESET 3
  7870. +#define TL_WR941ND_GPIO_BTN_QSS 7
  7871. +
  7872. +#define TL_WR941ND_KEYS_POLL_INTERVAL 20 /* msecs */
  7873. +#define TL_WR941ND_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR941ND_KEYS_POLL_INTERVAL)
  7874. +
  7875. +#ifdef CONFIG_MTD_PARTITIONS
  7876. +static struct mtd_partition tl_wr941nd_partitions[] = {
  7877. + {
  7878. + .name = "u-boot",
  7879. + .offset = 0,
  7880. + .size = 0x020000,
  7881. + .mask_flags = MTD_WRITEABLE,
  7882. + }, {
  7883. + .name = "kernel",
  7884. + .offset = 0x020000,
  7885. + .size = 0x140000,
  7886. + }, {
  7887. + .name = "rootfs",
  7888. + .offset = 0x160000,
  7889. + .size = 0x290000,
  7890. + }, {
  7891. + .name = "art",
  7892. + .offset = 0x3f0000,
  7893. + .size = 0x010000,
  7894. + .mask_flags = MTD_WRITEABLE,
  7895. + }, {
  7896. + .name = "firmware",
  7897. + .offset = 0x020000,
  7898. + .size = 0x3d0000,
  7899. + }
  7900. +};
  7901. +#endif /* CONFIG_MTD_PARTITIONS */
  7902. +
  7903. +static struct flash_platform_data tl_wr941nd_flash_data = {
  7904. +#ifdef CONFIG_MTD_PARTITIONS
  7905. + .parts = tl_wr941nd_partitions,
  7906. + .nr_parts = ARRAY_SIZE(tl_wr941nd_partitions),
  7907. +#endif
  7908. +};
  7909. +
  7910. +static struct gpio_led tl_wr941nd_leds_gpio[] __initdata = {
  7911. + {
  7912. + .name = "tl-wr941nd:green:system",
  7913. + .gpio = TL_WR941ND_GPIO_LED_SYSTEM,
  7914. + .active_low = 1,
  7915. + }, {
  7916. + .name = "tl-wr941nd:red:qss",
  7917. + .gpio = TL_WR941ND_GPIO_LED_QSS_RED,
  7918. + }, {
  7919. + .name = "tl-wr941nd:green:qss",
  7920. + .gpio = TL_WR941ND_GPIO_LED_QSS_GREEN,
  7921. + }, {
  7922. + .name = "tl-wr941nd:green:wlan",
  7923. + .gpio = TL_WR941ND_GPIO_LED_WLAN,
  7924. + .active_low = 1,
  7925. + }
  7926. +};
  7927. +
  7928. +static struct gpio_keys_button tl_wr941nd_gpio_keys[] __initdata = {
  7929. + {
  7930. + .desc = "reset",
  7931. + .type = EV_KEY,
  7932. + .code = KEY_RESTART,
  7933. + .debounce_interval = TL_WR941ND_KEYS_DEBOUNCE_INTERVAL,
  7934. + .gpio = TL_WR941ND_GPIO_BTN_RESET,
  7935. + .active_low = 1,
  7936. + }, {
  7937. + .desc = "qss",
  7938. + .type = EV_KEY,
  7939. + .code = KEY_WPS_BUTTON,
  7940. + .debounce_interval = TL_WR941ND_KEYS_DEBOUNCE_INTERVAL,
  7941. + .gpio = TL_WR941ND_GPIO_BTN_QSS,
  7942. + .active_low = 1,
  7943. + }
  7944. +};
  7945. +
  7946. +static struct dsa_chip_data tl_wr941nd_dsa_chip = {
  7947. + .port_names[0] = "wan",
  7948. + .port_names[1] = "lan1",
  7949. + .port_names[2] = "lan2",
  7950. + .port_names[3] = "lan3",
  7951. + .port_names[4] = "lan4",
  7952. + .port_names[5] = "cpu",
  7953. +};
  7954. +
  7955. +static struct dsa_platform_data tl_wr941nd_dsa_data = {
  7956. + .nr_chips = 1,
  7957. + .chip = &tl_wr941nd_dsa_chip,
  7958. +};
  7959. +
  7960. +static void __init tl_wr941nd_setup(void)
  7961. +{
  7962. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  7963. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  7964. +
  7965. + ar71xx_add_device_mdio(0x0);
  7966. +
  7967. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  7968. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7969. + ar71xx_eth0_data.speed = SPEED_100;
  7970. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7971. +
  7972. + ar71xx_add_device_eth(0);
  7973. + ar71xx_add_device_dsa(0, &tl_wr941nd_dsa_data);
  7974. +
  7975. + ar71xx_add_device_m25p80(&tl_wr941nd_flash_data);
  7976. +
  7977. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr941nd_leds_gpio),
  7978. + tl_wr941nd_leds_gpio);
  7979. +
  7980. + ar71xx_register_gpio_keys_polled(-1, TL_WR941ND_KEYS_POLL_INTERVAL,
  7981. + ARRAY_SIZE(tl_wr941nd_gpio_keys),
  7982. + tl_wr941nd_gpio_keys);
  7983. + ar9xxx_add_device_wmac(eeprom, mac);
  7984. +}
  7985. +
  7986. +MIPS_MACHINE(AR71XX_MACH_TL_WR941ND, "TL-WR941ND", "TP-LINK TL-WR941ND",
  7987. + tl_wr941nd_setup);
  7988. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/machtype.h linux-2.6.39/arch/mips/ar71xx/machtype.h
  7989. --- linux-2.6.39.orig/arch/mips/ar71xx/machtype.h 1970-01-01 01:00:00.000000000 +0100
  7990. +++ linux-2.6.39/arch/mips/ar71xx/machtype.h 2011-08-24 02:41:55.597982750 +0200
  7991. @@ -0,0 +1,75 @@
  7992. +/*
  7993. + * Atheros AR71xx machine type definitions
  7994. + *
  7995. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  7996. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7997. + *
  7998. + * This program is free software; you can redistribute it and/or modify it
  7999. + * under the terms of the GNU General Public License version 2 as published
  8000. + * by the Free Software Foundation.
  8001. + */
  8002. +
  8003. +#ifndef _AR71XX_MACHTYPE_H
  8004. +#define _AR71XX_MACHTYPE_H
  8005. +
  8006. +#include <asm/mips_machine.h>
  8007. +
  8008. +enum ar71xx_mach_type {
  8009. + AR71XX_MACH_GENERIC = 0,
  8010. + AR71XX_MACH_AP121, /* Atheros AP121 */
  8011. + AR71XX_MACH_AP121_MINI, /* Atheros AP121-MINI */
  8012. + AR71XX_MACH_AP81, /* Atheros AP81 */
  8013. + AR71XX_MACH_AP83, /* Atheros AP83 */
  8014. + AR71XX_MACH_AW_NR580, /* AzureWave AW-NR580 */
  8015. + AR71XX_MACH_DIR_600_A1, /* D-Link DIR-600 rev. A1 */
  8016. + AR71XX_MACH_DIR_615_C1, /* D-Link DIR-615 rev. C1 */
  8017. + AR71XX_MACH_DIR_825_B1, /* D-Link DIR-825 rev. B1 */
  8018. + AR71XX_MACH_JA76PF, /* jjPlus JA76PF */
  8019. + AR71XX_MACH_JWAP003, /* jjPlus JWAP003 */
  8020. + AR71XX_MACH_RB_411, /* MikroTik RouterBOARD 411/411A/411AH */
  8021. + AR71XX_MACH_RB_411U, /* MikroTik RouterBOARD 411U */
  8022. + AR71XX_MACH_RB_433, /* MikroTik RouterBOARD 433/433AH */
  8023. + AR71XX_MACH_RB_433U, /* MikroTik RouterBOARD 433UAH */
  8024. + AR71XX_MACH_RB_450, /* MikroTik RouterBOARD 450 */
  8025. + AR71XX_MACH_RB_450G, /* MikroTik RouterBOARD 450G */
  8026. + AR71XX_MACH_RB_493, /* Mikrotik RouterBOARD 493/493AH */
  8027. + AR71XX_MACH_RB_750, /* MikroTik RouterBOARD 750 */
  8028. + AR71XX_MACH_PB42, /* Atheros PB42 */
  8029. + AR71XX_MACH_PB44, /* Atheros PB44 */
  8030. + AR71XX_MACH_PB92, /* Atheros PB92 */
  8031. + AR71XX_MACH_MZK_W04NU, /* Planex MZK-W04NU */
  8032. + AR71XX_MACH_MZK_W300NH, /* Planex MZK-W300NH */
  8033. + AR71XX_MACH_NBG460N, /* Zyxel NBG460N/550N/550NH */
  8034. + AR71XX_MACH_TEW_632BRP, /* TRENDnet TEW-632BRP */
  8035. + AR71XX_MACH_TL_MR3220, /* TP-LINK TL-MR3220 */
  8036. + AR71XX_MACH_TL_MR3420, /* TP-LINK TL-MR3420 */
  8037. + AR71XX_MACH_TL_WA901ND, /* TP-LINK TL-WA901ND */
  8038. + AR71XX_MACH_TL_WA901ND_V2, /* TP-LINK TL-WA901ND v2 */
  8039. + AR71XX_MACH_TL_WR741ND, /* TP-LINK TL-WR741ND */
  8040. + AR71XX_MACH_TL_WR841N_V1, /* TP-LINK TL-WR841N v1 */
  8041. + AR71XX_MACH_TL_WR941ND, /* TP-LINK TL-WR941ND */
  8042. + AR71XX_MACH_TL_WR1043ND, /* TP-LINK TL-WR1041ND */
  8043. + AR71XX_MACH_UBNT_LSSR71, /* Ubiquiti LS-SR71 */
  8044. + AR71XX_MACH_UBNT_LSX, /* Ubiquiti LSX */
  8045. + AR71XX_MACH_UBNT_RS, /* Ubiquiti RouterStation */
  8046. + AR71XX_MACH_UBNT_RSPRO, /* Ubiquiti RouterStation Pro */
  8047. + AR71XX_MACH_UBNT_BULLET_M, /* Ubiquiti Bullet M */
  8048. + AR71XX_MACH_UBNT_ROCKET_M, /* Ubiquiti Rocket M */
  8049. + AR71XX_MACH_UBNT_NANO_M, /* Ubiquiti NanoStation M */
  8050. + AR71XX_MACH_WNDR3700, /* NETGEAR WNDR3700 */
  8051. + AR71XX_MACH_WNDR3700V2, /* NETGEAR WNDR3700v2 */
  8052. + AR71XX_MACH_WNR2000, /* NETGEAR WNR2000 */
  8053. + AR71XX_MACH_WP543, /* Compex WP543 */
  8054. + AR71XX_MACH_WRT160NL, /* Linksys WRT160NL */
  8055. + AR71XX_MACH_WRT400N, /* Linksys WRT400N */
  8056. + AR71XX_MACH_WZR_HP_AG300H, /* Buffalo WZR-HP-AG300H */
  8057. + AR71XX_MACH_WZR_HP_G300NH, /* Buffalo WZR-HP-G300NH */
  8058. + AR71XX_MACH_EAP7660D, /* Senao EAP7660D */
  8059. + AR71XX_MACH_ZCN_1523H_2, /* Zcomax ZCN-1523H-2-xx */
  8060. + AR71XX_MACH_ZCN_1523H_5, /* Zcomax ZCN-1523H-5-xx */
  8061. + AR71XX_MACH_AP96, /* Atheros AP96 */
  8062. + AR71XX_MACH_UBNT_UNIFI, /* Unifi */
  8063. + AR71XX_MACH_DB120, /* Atheros DB120 (AR934x based) */
  8064. +};
  8065. +
  8066. +#endif /* _AR71XX_MACHTYPE_H */
  8067. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-ubnt.c linux-2.6.39/arch/mips/ar71xx/mach-ubnt.c
  8068. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-ubnt.c 1970-01-01 01:00:00.000000000 +0100
  8069. +++ linux-2.6.39/arch/mips/ar71xx/mach-ubnt.c 2011-08-24 02:41:55.597982750 +0200
  8070. @@ -0,0 +1,333 @@
  8071. +/*
  8072. + * Ubiquiti RouterStation support
  8073. + *
  8074. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8075. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8076. + * Copyright (C) 2008 Ubiquiti <support@ubnt.com>
  8077. + *
  8078. + * This program is free software; you can redistribute it and/or modify it
  8079. + * under the terms of the GNU General Public License version 2 as published
  8080. + * by the Free Software Foundation.
  8081. + */
  8082. +
  8083. +#include <asm/mach-ar71xx/ar71xx.h>
  8084. +
  8085. +#include "machtype.h"
  8086. +#include "devices.h"
  8087. +#include "dev-m25p80.h"
  8088. +#include "dev-ap91-pci.h"
  8089. +#include "dev-gpio-buttons.h"
  8090. +#include "dev-pb42-pci.h"
  8091. +#include "dev-leds-gpio.h"
  8092. +#include "dev-usb.h"
  8093. +
  8094. +#define UBNT_RS_GPIO_LED_RF 2
  8095. +#define UBNT_RS_GPIO_SW4 8
  8096. +
  8097. +#define UBNT_LS_SR71_GPIO_LED_D25 0
  8098. +#define UBNT_LS_SR71_GPIO_LED_D26 1
  8099. +#define UBNT_LS_SR71_GPIO_LED_D24 2
  8100. +#define UBNT_LS_SR71_GPIO_LED_D23 4
  8101. +#define UBNT_LS_SR71_GPIO_LED_D22 5
  8102. +#define UBNT_LS_SR71_GPIO_LED_D27 6
  8103. +#define UBNT_LS_SR71_GPIO_LED_D28 7
  8104. +
  8105. +#define UBNT_M_GPIO_LED_L1 0
  8106. +#define UBNT_M_GPIO_LED_L2 1
  8107. +#define UBNT_M_GPIO_LED_L3 11
  8108. +#define UBNT_M_GPIO_LED_L4 7
  8109. +#define UBNT_M_GPIO_BTN_RESET 12
  8110. +
  8111. +#define UBNT_KEYS_POLL_INTERVAL 20 /* msecs */
  8112. +#define UBNT_KEYS_DEBOUNCE_INTERVAL (3 * UBNT_KEYS_POLL_INTERVAL)
  8113. +
  8114. +static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
  8115. + {
  8116. + .name = "ubnt:green:rf",
  8117. + .gpio = UBNT_RS_GPIO_LED_RF,
  8118. + .active_low = 0,
  8119. + }
  8120. +};
  8121. +
  8122. +static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
  8123. + {
  8124. + .name = "ubnt:green:d22",
  8125. + .gpio = UBNT_LS_SR71_GPIO_LED_D22,
  8126. + .active_low = 0,
  8127. + }, {
  8128. + .name = "ubnt:green:d23",
  8129. + .gpio = UBNT_LS_SR71_GPIO_LED_D23,
  8130. + .active_low = 0,
  8131. + }, {
  8132. + .name = "ubnt:green:d24",
  8133. + .gpio = UBNT_LS_SR71_GPIO_LED_D24,
  8134. + .active_low = 0,
  8135. + }, {
  8136. + .name = "ubnt:red:d25",
  8137. + .gpio = UBNT_LS_SR71_GPIO_LED_D25,
  8138. + .active_low = 0,
  8139. + }, {
  8140. + .name = "ubnt:red:d26",
  8141. + .gpio = UBNT_LS_SR71_GPIO_LED_D26,
  8142. + .active_low = 0,
  8143. + }, {
  8144. + .name = "ubnt:green:d27",
  8145. + .gpio = UBNT_LS_SR71_GPIO_LED_D27,
  8146. + .active_low = 0,
  8147. + }, {
  8148. + .name = "ubnt:green:d28",
  8149. + .gpio = UBNT_LS_SR71_GPIO_LED_D28,
  8150. + .active_low = 0,
  8151. + }
  8152. +};
  8153. +
  8154. +static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
  8155. + {
  8156. + .name = "ubnt:red:link1",
  8157. + .gpio = UBNT_M_GPIO_LED_L1,
  8158. + .active_low = 0,
  8159. + }, {
  8160. + .name = "ubnt:orange:link2",
  8161. + .gpio = UBNT_M_GPIO_LED_L2,
  8162. + .active_low = 0,
  8163. + }, {
  8164. + .name = "ubnt:green:link3",
  8165. + .gpio = UBNT_M_GPIO_LED_L3,
  8166. + .active_low = 0,
  8167. + }, {
  8168. + .name = "ubnt:green:link4",
  8169. + .gpio = UBNT_M_GPIO_LED_L4,
  8170. + .active_low = 0,
  8171. + }
  8172. +};
  8173. +
  8174. +static struct gpio_keys_button ubnt_gpio_keys[] __initdata = {
  8175. + {
  8176. + .desc = "sw4",
  8177. + .type = EV_KEY,
  8178. + .code = KEY_RESTART,
  8179. + .debounce_interval = UBNT_KEYS_DEBOUNCE_INTERVAL,
  8180. + .gpio = UBNT_RS_GPIO_SW4,
  8181. + .active_low = 1,
  8182. + }
  8183. +};
  8184. +
  8185. +static struct gpio_keys_button ubnt_m_gpio_keys[] __initdata = {
  8186. + {
  8187. + .desc = "reset",
  8188. + .type = EV_KEY,
  8189. + .code = KEY_RESTART,
  8190. + .debounce_interval = UBNT_KEYS_DEBOUNCE_INTERVAL,
  8191. + .gpio = UBNT_M_GPIO_BTN_RESET,
  8192. + .active_low = 1,
  8193. + }
  8194. +};
  8195. +
  8196. +static void __init ubnt_generic_setup(void)
  8197. +{
  8198. + ar71xx_add_device_m25p80(NULL);
  8199. +
  8200. + ar71xx_register_gpio_keys_polled(-1, UBNT_KEYS_POLL_INTERVAL,
  8201. + ARRAY_SIZE(ubnt_gpio_keys),
  8202. + ubnt_gpio_keys);
  8203. +
  8204. + pb42_pci_init();
  8205. +}
  8206. +
  8207. +/*
  8208. + * There is Secondary MAC address duplicate problem with some UBNT HW batches.
  8209. + * Do not increase Secondary MAC address by 1 but do workaround
  8210. + * with 'Locally Administrated' bit.
  8211. + */
  8212. +static void __init ubnt_init_secondary_mac(unsigned char *mac_base)
  8213. +{
  8214. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac_base, 0);
  8215. + ar71xx_eth1_data.mac_addr[0] |= 0x02;
  8216. +}
  8217. +
  8218. +#define UBNT_RS_WAN_PHYMASK BIT(20)
  8219. +#define UBNT_RS_LAN_PHYMASK (BIT(16) | BIT(17) | BIT(18) | BIT(19))
  8220. +
  8221. +static void __init ubnt_rs_setup(void)
  8222. +{
  8223. + ubnt_generic_setup();
  8224. +
  8225. + ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
  8226. +
  8227. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  8228. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  8229. + ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
  8230. +
  8231. + ubnt_init_secondary_mac(ar71xx_mac_base);
  8232. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8233. + ar71xx_eth1_data.speed = SPEED_100;
  8234. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  8235. +
  8236. + ar71xx_add_device_eth(0);
  8237. + ar71xx_add_device_eth(1);
  8238. +
  8239. + ar71xx_add_device_usb();
  8240. +
  8241. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  8242. + ubnt_rs_leds_gpio);
  8243. +}
  8244. +
  8245. +MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
  8246. + ubnt_rs_setup);
  8247. +
  8248. +#define UBNT_RSPRO_WAN_PHYMASK BIT(4)
  8249. +#define UBNT_RSPRO_LAN_PHYMASK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
  8250. +
  8251. +static void __init ubnt_rspro_setup(void)
  8252. +{
  8253. + ubnt_generic_setup();
  8254. +
  8255. + ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK |
  8256. + UBNT_RSPRO_LAN_PHYMASK));
  8257. +
  8258. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  8259. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  8260. + ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
  8261. +
  8262. + ubnt_init_secondary_mac(ar71xx_mac_base);
  8263. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  8264. + ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
  8265. + ar71xx_eth1_data.speed = SPEED_1000;
  8266. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  8267. +
  8268. + ar71xx_add_device_eth(0);
  8269. + ar71xx_add_device_eth(1);
  8270. +
  8271. + ar71xx_add_device_usb();
  8272. +
  8273. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  8274. + ubnt_rs_leds_gpio);
  8275. +}
  8276. +
  8277. +MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
  8278. + ubnt_rspro_setup);
  8279. +
  8280. +static void __init ubnt_lsx_setup(void)
  8281. +{
  8282. + ubnt_generic_setup();
  8283. +}
  8284. +
  8285. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
  8286. +
  8287. +#define UBNT_LSSR71_PHY_MASK BIT(1)
  8288. +
  8289. +static void __init ubnt_lssr71_setup(void)
  8290. +{
  8291. + ubnt_generic_setup();
  8292. +
  8293. + ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
  8294. +
  8295. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  8296. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  8297. + ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
  8298. +
  8299. + ar71xx_add_device_eth(0);
  8300. +
  8301. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
  8302. + ubnt_ls_sr71_leds_gpio);
  8303. +}
  8304. +
  8305. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
  8306. + ubnt_lssr71_setup);
  8307. +
  8308. +#define UBNT_M_WAN_PHYMASK BIT(4)
  8309. +
  8310. +static void __init ubnt_m_setup(void)
  8311. +{
  8312. + u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
  8313. + u8 *mac2 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
  8314. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  8315. +
  8316. + ar71xx_add_device_m25p80(NULL);
  8317. +
  8318. + ar71xx_add_device_mdio(~UBNT_M_WAN_PHYMASK);
  8319. +
  8320. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac1, 0);
  8321. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac2, 0);
  8322. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8323. + ar71xx_eth0_data.speed = SPEED_100;
  8324. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  8325. + ar71xx_eth0_data.phy_mask = UBNT_M_WAN_PHYMASK;
  8326. +
  8327. + ar71xx_add_device_eth(0);
  8328. +
  8329. + ap91_pci_init(ee, NULL);
  8330. +
  8331. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
  8332. + ubnt_m_leds_gpio);
  8333. +
  8334. + ar71xx_register_gpio_keys_polled(-1, UBNT_KEYS_POLL_INTERVAL,
  8335. + ARRAY_SIZE(ubnt_m_gpio_keys),
  8336. + ubnt_m_gpio_keys);
  8337. +}
  8338. +
  8339. +static void __init ubnt_rocket_m_setup(void)
  8340. +{
  8341. + ubnt_m_setup();
  8342. + ar71xx_add_device_usb();
  8343. +}
  8344. +
  8345. +MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
  8346. + ubnt_m_setup);
  8347. +MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
  8348. + ubnt_rocket_m_setup);
  8349. +
  8350. +/* TODO detect the second ethernet port and use one
  8351. + init function for all Ubiquiti MIMO series products */
  8352. +static void __init ubnt_nano_m_setup(void)
  8353. +{
  8354. + ubnt_m_setup();
  8355. +
  8356. + ar71xx_eth1_data.has_ar7240_switch = 1;
  8357. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8358. + ar71xx_eth1_data.speed = SPEED_1000;
  8359. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  8360. +
  8361. + ar71xx_add_device_eth(1);
  8362. +}
  8363. +
  8364. +MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
  8365. + ubnt_nano_m_setup);
  8366. +
  8367. +static struct gpio_led ubnt_unifi_leds_gpio[] __initdata = {
  8368. + {
  8369. + .name = "ubnt:orange:dome",
  8370. + .gpio = 1,
  8371. + .active_low = 0,
  8372. + }, {
  8373. + .name = "ubnt:green:dome",
  8374. + .gpio = 0,
  8375. + .active_low = 0,
  8376. + }
  8377. +};
  8378. +
  8379. +static void __init ubnt_unifi_setup(void)
  8380. +{
  8381. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  8382. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  8383. +
  8384. + ar71xx_add_device_m25p80(NULL);
  8385. +
  8386. + ar71xx_add_device_mdio(~UBNT_M_WAN_PHYMASK);
  8387. +
  8388. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  8389. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8390. + ar71xx_eth0_data.speed = SPEED_100;
  8391. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  8392. + ar71xx_eth0_data.phy_mask = UBNT_M_WAN_PHYMASK;
  8393. +
  8394. + ar71xx_add_device_eth(0);
  8395. +
  8396. + ap91_pci_init(ee, NULL);
  8397. +
  8398. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_leds_gpio),
  8399. + ubnt_unifi_leds_gpio);
  8400. +}
  8401. +
  8402. +MIPS_MACHINE(AR71XX_MACH_UBNT_UNIFI, "UBNT-XM", "Ubiquiti UniFi",
  8403. + ubnt_unifi_setup);
  8404. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wndr3700.c linux-2.6.39/arch/mips/ar71xx/mach-wndr3700.c
  8405. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wndr3700.c 1970-01-01 01:00:00.000000000 +0100
  8406. +++ linux-2.6.39/arch/mips/ar71xx/mach-wndr3700.c 2011-08-24 02:41:55.607980283 +0200
  8407. @@ -0,0 +1,290 @@
  8408. +/*
  8409. + * Netgear WNDR3700 board support
  8410. + *
  8411. + * Copyright (C) 2009 Marco Porsch
  8412. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  8413. + *
  8414. + * This program is free software; you can redistribute it and/or modify it
  8415. + * under the terms of the GNU General Public License version 2 as published
  8416. + * by the Free Software Foundation.
  8417. + */
  8418. +
  8419. +#include <linux/platform_device.h>
  8420. +#include <linux/mtd/mtd.h>
  8421. +#include <linux/mtd/partitions.h>
  8422. +#include <linux/delay.h>
  8423. +#include <linux/rtl8366.h>
  8424. +
  8425. +#include <asm/mach-ar71xx/ar71xx.h>
  8426. +
  8427. +#include "machtype.h"
  8428. +#include "devices.h"
  8429. +#include "dev-m25p80.h"
  8430. +#include "dev-ap94-pci.h"
  8431. +#include "dev-gpio-buttons.h"
  8432. +#include "dev-leds-gpio.h"
  8433. +#include "dev-usb.h"
  8434. +
  8435. +#define WNDR3700_GPIO_LED_WPS_ORANGE 0
  8436. +#define WNDR3700_GPIO_LED_POWER_ORANGE 1
  8437. +#define WNDR3700_GPIO_LED_POWER_GREEN 2
  8438. +#define WNDR3700_GPIO_LED_WPS_GREEN 4
  8439. +#define WNDR3700_GPIO_LED_WAN_GREEN 6
  8440. +
  8441. +#define WNDR3700_GPIO_BTN_WPS 3
  8442. +#define WNDR3700_GPIO_BTN_RESET 8
  8443. +#define WNDR3700_GPIO_BTN_WIFI 11
  8444. +
  8445. +#define WNDR3700_GPIO_RTL8366_SDA 5
  8446. +#define WNDR3700_GPIO_RTL8366_SCK 7
  8447. +
  8448. +#define WNDR3700_KEYS_POLL_INTERVAL 20 /* msecs */
  8449. +#define WNDR3700_KEYS_DEBOUNCE_INTERVAL (3 * WNDR3700_KEYS_POLL_INTERVAL)
  8450. +
  8451. +#define WNDR3700_ETH0_MAC_OFFSET 0
  8452. +#define WNDR3700_ETH1_MAC_OFFSET 0x6
  8453. +
  8454. +#define WNDR3700_WMAC0_MAC_OFFSET 0
  8455. +#define WNDR3700_WMAC1_MAC_OFFSET 0xc
  8456. +#define WNDR3700_CALDATA0_OFFSET 0x1000
  8457. +#define WNDR3700_CALDATA1_OFFSET 0x5000
  8458. +
  8459. +#ifdef CONFIG_MTD_PARTITIONS
  8460. +static struct mtd_partition wndr3700_partitions[] = {
  8461. + {
  8462. + .name = "uboot",
  8463. + .offset = 0,
  8464. + .size = 0x050000,
  8465. + .mask_flags = MTD_WRITEABLE,
  8466. + }, {
  8467. + .name = "env",
  8468. + .offset = 0x050000,
  8469. + .size = 0x020000,
  8470. + .mask_flags = MTD_WRITEABLE,
  8471. + }, {
  8472. + .name = "rootfs",
  8473. + .offset = 0x070000,
  8474. + .size = 0x720000,
  8475. + }, {
  8476. + .name = "config",
  8477. + .offset = 0x790000,
  8478. + .size = 0x010000,
  8479. + .mask_flags = MTD_WRITEABLE,
  8480. + }, {
  8481. + .name = "config_bak",
  8482. + .offset = 0x7a0000,
  8483. + .size = 0x010000,
  8484. + .mask_flags = MTD_WRITEABLE,
  8485. + }, {
  8486. + .name = "pot",
  8487. + .offset = 0x7b0000,
  8488. + .size = 0x010000,
  8489. + .mask_flags = MTD_WRITEABLE,
  8490. + }, {
  8491. + .name = "traffic_meter",
  8492. + .offset = 0x7c0000,
  8493. + .size = 0x010000,
  8494. + .mask_flags = MTD_WRITEABLE,
  8495. + }, {
  8496. + .name = "language",
  8497. + .offset = 0x7d0000,
  8498. + .size = 0x020000,
  8499. + .mask_flags = MTD_WRITEABLE,
  8500. + }, {
  8501. + .name = "caldata",
  8502. + .offset = 0x7f0000,
  8503. + .size = 0x010000,
  8504. + .mask_flags = MTD_WRITEABLE,
  8505. + }
  8506. +};
  8507. +
  8508. +static struct mtd_partition wndr3700v2_partitions[] = {
  8509. + {
  8510. + .name = "uboot",
  8511. + .offset = 0,
  8512. + .size = 0x050000,
  8513. + .mask_flags = MTD_WRITEABLE,
  8514. + }, {
  8515. + .name = "env",
  8516. + .offset = 0x050000,
  8517. + .size = 0x020000,
  8518. + .mask_flags = MTD_WRITEABLE,
  8519. + }, {
  8520. + .name = "rootfs",
  8521. + .offset = 0x070000,
  8522. + .size = 0xe40000,
  8523. + }, {
  8524. + .name = "config",
  8525. + .offset = 0xeb0000,
  8526. + .size = 0x010000,
  8527. + .mask_flags = MTD_WRITEABLE,
  8528. + }, {
  8529. + .name = "config_bak",
  8530. + .offset = 0xec0000,
  8531. + .size = 0x010000,
  8532. + .mask_flags = MTD_WRITEABLE,
  8533. + }, {
  8534. + .name = "pot",
  8535. + .offset = 0xed0000,
  8536. + .size = 0x010000,
  8537. + .mask_flags = MTD_WRITEABLE,
  8538. + }, {
  8539. + .name = "traffic_meter",
  8540. + .offset = 0xee0000,
  8541. + .size = 0x010000,
  8542. + .mask_flags = MTD_WRITEABLE,
  8543. + }, {
  8544. + .name = "language",
  8545. + .offset = 0xef0000,
  8546. + .size = 0x100000,
  8547. + .mask_flags = MTD_WRITEABLE,
  8548. + }, {
  8549. + .name = "caldata",
  8550. + .offset = 0xff0000,
  8551. + .size = 0x010000,
  8552. + .mask_flags = MTD_WRITEABLE,
  8553. + }
  8554. +};
  8555. +#define wndr3700_num_partitions ARRAY_SIZE(wndr3700_partitions)
  8556. +#define wndr3700v2_num_partitions ARRAY_SIZE(wndr3700v2_partitions)
  8557. +#else
  8558. +#define wndr3700_partitions NULL
  8559. +#define wndr3700_num_partitions 0
  8560. +#define wndr3700v2_partitions NULL
  8561. +#define wndr3700v2_num_partitions 0
  8562. +#endif /* CONFIG_MTD_PARTITIONS */
  8563. +
  8564. +static struct flash_platform_data wndr3700_flash_data;
  8565. +
  8566. +static struct gpio_led wndr3700_leds_gpio[] __initdata = {
  8567. + {
  8568. + .name = "wndr3700:green:power",
  8569. + .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
  8570. + .active_low = 1,
  8571. + }, {
  8572. + .name = "wndr3700:orange:power",
  8573. + .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
  8574. + .active_low = 1,
  8575. + }, {
  8576. + .name = "wndr3700:green:wps",
  8577. + .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
  8578. + .active_low = 1,
  8579. + }, {
  8580. + .name = "wndr3700:orange:wps",
  8581. + .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
  8582. + .active_low = 1,
  8583. + }, {
  8584. + .name = "wndr3700:green:wan",
  8585. + .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
  8586. + .active_low = 1,
  8587. + }
  8588. +};
  8589. +
  8590. +static struct gpio_keys_button wndr3700_gpio_keys[] __initdata = {
  8591. + {
  8592. + .desc = "reset",
  8593. + .type = EV_KEY,
  8594. + .code = KEY_RESTART,
  8595. + .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
  8596. + .gpio = WNDR3700_GPIO_BTN_RESET,
  8597. + .active_low = 1,
  8598. + }, {
  8599. + .desc = "wps",
  8600. + .type = EV_KEY,
  8601. + .code = KEY_WPS_BUTTON,
  8602. + .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
  8603. + .gpio = WNDR3700_GPIO_BTN_WPS,
  8604. + .active_low = 1,
  8605. + }, {
  8606. + .desc = "wifi",
  8607. + .type = EV_KEY,
  8608. + .code = BTN_2,
  8609. + .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
  8610. + .gpio = WNDR3700_GPIO_BTN_WIFI,
  8611. + .active_low = 1,
  8612. + }
  8613. +};
  8614. +
  8615. +static struct rtl8366_platform_data wndr3700_rtl8366s_data = {
  8616. + .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
  8617. + .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
  8618. +};
  8619. +
  8620. +static struct platform_device wndr3700_rtl8366s_device = {
  8621. + .name = RTL8366S_DRIVER_NAME,
  8622. + .id = -1,
  8623. + .dev = {
  8624. + .platform_data = &wndr3700_rtl8366s_data,
  8625. + }
  8626. +};
  8627. +
  8628. +static void __init wndr3700_common_setup(void)
  8629. +{
  8630. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  8631. +
  8632. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
  8633. + art + WNDR3700_ETH0_MAC_OFFSET, 0);
  8634. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  8635. + ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  8636. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  8637. + ar71xx_eth0_data.speed = SPEED_1000;
  8638. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  8639. +
  8640. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr,
  8641. + art + WNDR3700_ETH1_MAC_OFFSET, 0);
  8642. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  8643. + ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  8644. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  8645. + ar71xx_eth1_data.phy_mask = 0x10;
  8646. +
  8647. + ar71xx_add_device_eth(0);
  8648. + ar71xx_add_device_eth(1);
  8649. +
  8650. + ar71xx_add_device_usb();
  8651. +
  8652. + ar71xx_add_device_m25p80(&wndr3700_flash_data);
  8653. +
  8654. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
  8655. + wndr3700_leds_gpio);
  8656. +
  8657. + ar71xx_register_gpio_keys_polled(-1, WNDR3700_KEYS_POLL_INTERVAL,
  8658. + ARRAY_SIZE(wndr3700_gpio_keys),
  8659. + wndr3700_gpio_keys);
  8660. +
  8661. + platform_device_register(&wndr3700_rtl8366s_device);
  8662. + platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
  8663. +
  8664. + ap94_pci_setup_wmac_led_pin(0, 5);
  8665. + ap94_pci_setup_wmac_led_pin(1, 5);
  8666. +
  8667. + /* 2.4 GHz uses the first fixed antenna group (1, 0, 1, 0) */
  8668. + ap94_pci_setup_wmac_gpio(0, (0xf << 6), (0xa << 6));
  8669. +
  8670. + /* 5 GHz uses the second fixed antenna group (0, 1, 1, 0) */
  8671. + ap94_pci_setup_wmac_gpio(1, (0xf << 6), (0x6 << 6));
  8672. +
  8673. + ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
  8674. + art + WNDR3700_WMAC0_MAC_OFFSET,
  8675. + art + WNDR3700_CALDATA1_OFFSET,
  8676. + art + WNDR3700_WMAC1_MAC_OFFSET);
  8677. +}
  8678. +
  8679. +static void __init wndr3700_setup(void)
  8680. +{
  8681. + wndr3700_flash_data.parts = wndr3700_partitions,
  8682. + wndr3700_flash_data.nr_parts = wndr3700_num_partitions,
  8683. + wndr3700_common_setup();
  8684. +}
  8685. +
  8686. +MIPS_MACHINE(AR71XX_MACH_WNDR3700, "WNDR3700", "NETGEAR WNDR3700",
  8687. + wndr3700_setup);
  8688. +
  8689. +static void __init wndr3700v2_setup(void)
  8690. +{
  8691. + wndr3700_flash_data.parts = wndr3700v2_partitions,
  8692. + wndr3700_flash_data.nr_parts = wndr3700v2_num_partitions,
  8693. + wndr3700_common_setup();
  8694. +}
  8695. +
  8696. +MIPS_MACHINE(AR71XX_MACH_WNDR3700V2, "WNDR3700v2", "NETGEAR WNDR3700v2",
  8697. + wndr3700v2_setup);
  8698. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wnr2000.c linux-2.6.39/arch/mips/ar71xx/mach-wnr2000.c
  8699. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wnr2000.c 1970-01-01 01:00:00.000000000 +0100
  8700. +++ linux-2.6.39/arch/mips/ar71xx/mach-wnr2000.c 2011-08-24 02:41:55.617990333 +0200
  8701. @@ -0,0 +1,150 @@
  8702. +/*
  8703. + * NETGEAR WNR2000 board support
  8704. + *
  8705. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8706. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8707. + * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
  8708. + *
  8709. + * This program is free software; you can redistribute it and/or modify it
  8710. + * under the terms of the GNU General Public License version 2 as published
  8711. + * by the Free Software Foundation.
  8712. + */
  8713. +
  8714. +#include <linux/mtd/mtd.h>
  8715. +#include <linux/mtd/partitions.h>
  8716. +
  8717. +#include <asm/mach-ar71xx/ar71xx.h>
  8718. +
  8719. +#include "machtype.h"
  8720. +#include "devices.h"
  8721. +#include "dev-m25p80.h"
  8722. +#include "dev-ar9xxx-wmac.h"
  8723. +#include "dev-gpio-buttons.h"
  8724. +#include "dev-leds-gpio.h"
  8725. +
  8726. +#define WNR2000_GPIO_LED_PWR_GREEN 14
  8727. +#define WNR2000_GPIO_LED_PWR_AMBER 7
  8728. +#define WNR2000_GPIO_LED_WPS 4
  8729. +#define WNR2000_GPIO_LED_WLAN 6
  8730. +#define WNR2000_GPIO_BTN_RESET 21
  8731. +#define WNR2000_GPIO_BTN_WPS 8
  8732. +
  8733. +#define WNR2000_KEYS_POLL_INTERVAL 20 /* msecs */
  8734. +#define WNR2000_KEYS_DEBOUNCE_INTERVAL (3 * WNR2000_KEYS_POLL_INTERVAL)
  8735. +
  8736. +#ifdef CONFIG_MTD_PARTITIONS
  8737. +static struct mtd_partition wnr2000_partitions[] = {
  8738. + {
  8739. + .name = "u-boot",
  8740. + .offset = 0,
  8741. + .size = 0x040000,
  8742. + .mask_flags = MTD_WRITEABLE,
  8743. + }, {
  8744. + .name = "u-boot-env",
  8745. + .offset = 0x040000,
  8746. + .size = 0x010000,
  8747. + }, {
  8748. + .name = "rootfs",
  8749. + .offset = 0x050000,
  8750. + .size = 0x240000,
  8751. + }, {
  8752. + .name = "user-config",
  8753. + .offset = 0x290000,
  8754. + .size = 0x010000,
  8755. + }, {
  8756. + .name = "uImage",
  8757. + .offset = 0x2a0000,
  8758. + .size = 0x120000,
  8759. + }, {
  8760. + .name = "language_table",
  8761. + .offset = 0x3c0000,
  8762. + .size = 0x020000,
  8763. + }, {
  8764. + .name = "rootfs_checksum",
  8765. + .offset = 0x3e0000,
  8766. + .size = 0x010000,
  8767. + }, {
  8768. + .name = "art",
  8769. + .offset = 0x3f0000,
  8770. + .size = 0x010000,
  8771. + .mask_flags = MTD_WRITEABLE,
  8772. + }
  8773. +};
  8774. +#endif /* CONFIG_MTD_PARTITIONS */
  8775. +
  8776. +static struct flash_platform_data wnr2000_flash_data = {
  8777. +#ifdef CONFIG_MTD_PARTITIONS
  8778. + .parts = wnr2000_partitions,
  8779. + .nr_parts = ARRAY_SIZE(wnr2000_partitions),
  8780. +#endif
  8781. +};
  8782. +
  8783. +static struct gpio_led wnr2000_leds_gpio[] __initdata = {
  8784. + {
  8785. + .name = "wnr2000:green:power",
  8786. + .gpio = WNR2000_GPIO_LED_PWR_GREEN,
  8787. + .active_low = 1,
  8788. + }, {
  8789. + .name = "wnr2000:amber:power",
  8790. + .gpio = WNR2000_GPIO_LED_PWR_AMBER,
  8791. + .active_low = 1,
  8792. + }, {
  8793. + .name = "wnr2000:green:wps",
  8794. + .gpio = WNR2000_GPIO_LED_WPS,
  8795. + .active_low = 1,
  8796. + }, {
  8797. + .name = "wnr2000:blue:wlan",
  8798. + .gpio = WNR2000_GPIO_LED_WLAN,
  8799. + .active_low = 1,
  8800. + }
  8801. +};
  8802. +
  8803. +static struct gpio_keys_button wnr2000_gpio_keys[] __initdata = {
  8804. + {
  8805. + .desc = "reset",
  8806. + .type = EV_KEY,
  8807. + .code = KEY_RESTART,
  8808. + .debounce_interval = WNR2000_KEYS_DEBOUNCE_INTERVAL,
  8809. + .gpio = WNR2000_GPIO_BTN_RESET,
  8810. + }, {
  8811. + .desc = "wps",
  8812. + .type = EV_KEY,
  8813. + .code = KEY_WPS_BUTTON,
  8814. + .debounce_interval = WNR2000_KEYS_DEBOUNCE_INTERVAL,
  8815. + .gpio = WNR2000_GPIO_BTN_WPS,
  8816. + }
  8817. +};
  8818. +
  8819. +static void __init wnr2000_setup(void)
  8820. +{
  8821. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  8822. +
  8823. + ar71xx_add_device_mdio(0x0);
  8824. +
  8825. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, eeprom, 0);
  8826. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8827. + ar71xx_eth0_data.speed = SPEED_100;
  8828. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  8829. + ar71xx_eth0_data.has_ar8216 = 1;
  8830. +
  8831. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, eeprom, 1);
  8832. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  8833. + ar71xx_eth1_data.phy_mask = 0x10;
  8834. +
  8835. + ar71xx_add_device_eth(0);
  8836. + ar71xx_add_device_eth(1);
  8837. +
  8838. + ar71xx_add_device_m25p80(&wnr2000_flash_data);
  8839. +
  8840. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wnr2000_leds_gpio),
  8841. + wnr2000_leds_gpio);
  8842. +
  8843. + ar71xx_register_gpio_keys_polled(-1, WNR2000_KEYS_POLL_INTERVAL,
  8844. + ARRAY_SIZE(wnr2000_gpio_keys),
  8845. + wnr2000_gpio_keys);
  8846. +
  8847. +
  8848. + ar9xxx_add_device_wmac(eeprom, NULL);
  8849. +}
  8850. +
  8851. +MIPS_MACHINE(AR71XX_MACH_WNR2000, "WNR2000", "NETGEAR WNR2000", wnr2000_setup);
  8852. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wp543.c linux-2.6.39/arch/mips/ar71xx/mach-wp543.c
  8853. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wp543.c 1970-01-01 01:00:00.000000000 +0100
  8854. +++ linux-2.6.39/arch/mips/ar71xx/mach-wp543.c 2011-08-24 02:41:55.617990333 +0200
  8855. @@ -0,0 +1,101 @@
  8856. +/*
  8857. + * Compex WP543/WPJ543 board support
  8858. + *
  8859. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8860. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8861. + *
  8862. + * This program is free software; you can redistribute it and/or modify it
  8863. + * under the terms of the GNU General Public License version 2 as published
  8864. + * by the Free Software Foundation.
  8865. + */
  8866. +
  8867. +#include <linux/mtd/mtd.h>
  8868. +#include <linux/mtd/partitions.h>
  8869. +
  8870. +#include <asm/mach-ar71xx/ar71xx.h>
  8871. +
  8872. +#include "machtype.h"
  8873. +#include "devices.h"
  8874. +#include "dev-m25p80.h"
  8875. +#include "dev-pb42-pci.h"
  8876. +#include "dev-gpio-buttons.h"
  8877. +#include "dev-leds-gpio.h"
  8878. +#include "dev-usb.h"
  8879. +
  8880. +#define WP543_GPIO_SW6 2
  8881. +#define WP543_GPIO_LED_1 3
  8882. +#define WP543_GPIO_LED_2 4
  8883. +#define WP543_GPIO_LED_WLAN 5
  8884. +#define WP543_GPIO_LED_CONN 6
  8885. +#define WP543_GPIO_LED_DIAG 7
  8886. +#define WP543_GPIO_SW4 8
  8887. +
  8888. +#define WP543_KEYS_POLL_INTERVAL 20 /* msecs */
  8889. +#define WP543_KEYS_DEBOUNCE_INTERVAL (3 * WP543_KEYS_POLL_INTERVAL)
  8890. +
  8891. +static struct gpio_led wp543_leds_gpio[] __initdata = {
  8892. + {
  8893. + .name = "wp543:green:led1",
  8894. + .gpio = WP543_GPIO_LED_1,
  8895. + .active_low = 1,
  8896. + }, {
  8897. + .name = "wp543:green:led2",
  8898. + .gpio = WP543_GPIO_LED_2,
  8899. + .active_low = 1,
  8900. + }, {
  8901. + .name = "wp543:green:wlan",
  8902. + .gpio = WP543_GPIO_LED_WLAN,
  8903. + .active_low = 1,
  8904. + }, {
  8905. + .name = "wp543:green:conn",
  8906. + .gpio = WP543_GPIO_LED_CONN,
  8907. + .active_low = 1,
  8908. + }, {
  8909. + .name = "wp543:green:diag",
  8910. + .gpio = WP543_GPIO_LED_DIAG,
  8911. + .active_low = 1,
  8912. + }
  8913. +};
  8914. +
  8915. +static struct gpio_keys_button wp543_gpio_keys[] __initdata = {
  8916. + {
  8917. + .desc = "sw6",
  8918. + .type = EV_KEY,
  8919. + .code = BTN_0,
  8920. + .debounce_interval = WP543_KEYS_DEBOUNCE_INTERVAL,
  8921. + .gpio = WP543_GPIO_SW6,
  8922. + }, {
  8923. + .desc = "sw4",
  8924. + .type = EV_KEY,
  8925. + .code = BTN_1,
  8926. + .debounce_interval = WP543_KEYS_DEBOUNCE_INTERVAL,
  8927. + .gpio = WP543_GPIO_SW4,
  8928. + }
  8929. +};
  8930. +
  8931. +static void __init wp543_setup(void)
  8932. +{
  8933. + ar71xx_add_device_m25p80(NULL);
  8934. +
  8935. + ar71xx_add_device_mdio(0xfffffff7);
  8936. +
  8937. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
  8938. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  8939. + ar71xx_eth0_data.phy_mask = 0x08;
  8940. + ar71xx_eth0_data.reset_bit = RESET_MODULE_GE0_MAC |
  8941. + RESET_MODULE_GE0_PHY;
  8942. + ar71xx_add_device_eth(0);
  8943. +
  8944. + ar71xx_add_device_usb();
  8945. +
  8946. + pb42_pci_init();
  8947. +
  8948. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wp543_leds_gpio),
  8949. + wp543_leds_gpio);
  8950. +
  8951. + ar71xx_register_gpio_keys_polled(-1, WP543_KEYS_POLL_INTERVAL,
  8952. + ARRAY_SIZE(wp543_gpio_keys),
  8953. + wp543_gpio_keys);
  8954. +}
  8955. +
  8956. +MIPS_MACHINE(AR71XX_MACH_WP543, "WP543", "Compex WP543", wp543_setup);
  8957. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wrt160nl.c linux-2.6.39/arch/mips/ar71xx/mach-wrt160nl.c
  8958. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wrt160nl.c 1970-01-01 01:00:00.000000000 +0100
  8959. +++ linux-2.6.39/arch/mips/ar71xx/mach-wrt160nl.c 2011-08-24 02:41:55.617990333 +0200
  8960. @@ -0,0 +1,161 @@
  8961. +/*
  8962. + * Linksys WRT160NL board support
  8963. + *
  8964. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  8965. + *
  8966. + * This program is free software; you can redistribute it and/or modify it
  8967. + * under the terms of the GNU General Public License version 2 as published
  8968. + * by the Free Software Foundation.
  8969. + */
  8970. +
  8971. +#include <linux/mtd/mtd.h>
  8972. +#include <linux/mtd/partitions.h>
  8973. +
  8974. +#include <asm/mach-ar71xx/ar71xx.h>
  8975. +
  8976. +#include "machtype.h"
  8977. +#include "devices.h"
  8978. +#include "dev-m25p80.h"
  8979. +#include "dev-ar9xxx-wmac.h"
  8980. +#include "dev-gpio-buttons.h"
  8981. +#include "dev-leds-gpio.h"
  8982. +#include "dev-usb.h"
  8983. +#include "nvram.h"
  8984. +
  8985. +#define WRT160NL_GPIO_LED_POWER 14
  8986. +#define WRT160NL_GPIO_LED_WPS_AMBER 9
  8987. +#define WRT160NL_GPIO_LED_WPS_BLUE 8
  8988. +#define WRT160NL_GPIO_LED_WLAN 6
  8989. +
  8990. +#define WRT160NL_GPIO_BTN_WPS 7
  8991. +#define WRT160NL_GPIO_BTN_RESET 21
  8992. +
  8993. +#define WRT160NL_KEYS_POLL_INTERVAL 20 /* msecs */
  8994. +#define WRT160NL_KEYS_DEBOUNCE_INTERVAL (3 * WRT160NL_KEYS_POLL_INTERVAL)
  8995. +
  8996. +#define WRT160NL_NVRAM_ADDR 0x1f7e0000
  8997. +#define WRT160NL_NVRAM_SIZE 0x10000
  8998. +
  8999. +#ifdef CONFIG_MTD_PARTITIONS
  9000. +static struct mtd_partition wrt160nl_partitions[] = {
  9001. + {
  9002. + .name = "u-boot",
  9003. + .offset = 0,
  9004. + .size = 0x040000,
  9005. + .mask_flags = MTD_WRITEABLE,
  9006. + }, {
  9007. + .name = "kernel",
  9008. + .offset = 0x040000,
  9009. + .size = 0x0e0000,
  9010. + }, {
  9011. + .name = "filesytem",
  9012. + .offset = 0x120000,
  9013. + .size = 0x6c0000,
  9014. + }, {
  9015. + .name = "nvram",
  9016. + .offset = 0x7e0000,
  9017. + .size = 0x010000,
  9018. + .mask_flags = MTD_WRITEABLE,
  9019. + }, {
  9020. + .name = "ART",
  9021. + .offset = 0x7f0000,
  9022. + .size = 0x010000,
  9023. + .mask_flags = MTD_WRITEABLE,
  9024. + }, {
  9025. + .name = "firmware",
  9026. + .offset = 0x040000,
  9027. + .size = 0x7a0000,
  9028. + }
  9029. +};
  9030. +#endif /* CONFIG_MTD_PARTITIONS */
  9031. +
  9032. +static struct flash_platform_data wrt160nl_flash_data = {
  9033. +#ifdef CONFIG_MTD_PARTITIONS
  9034. + .parts = wrt160nl_partitions,
  9035. + .nr_parts = ARRAY_SIZE(wrt160nl_partitions),
  9036. +#endif
  9037. +};
  9038. +
  9039. +static struct gpio_led wrt160nl_leds_gpio[] __initdata = {
  9040. + {
  9041. + .name = "wrt160nl:blue:power",
  9042. + .gpio = WRT160NL_GPIO_LED_POWER,
  9043. + .active_low = 1,
  9044. + .default_trigger = "default-on",
  9045. + }, {
  9046. + .name = "wrt160nl:amber:wps",
  9047. + .gpio = WRT160NL_GPIO_LED_WPS_AMBER,
  9048. + .active_low = 1,
  9049. + }, {
  9050. + .name = "wrt160nl:blue:wps",
  9051. + .gpio = WRT160NL_GPIO_LED_WPS_BLUE,
  9052. + .active_low = 1,
  9053. + }, {
  9054. + .name = "wrt160nl:blue:wlan",
  9055. + .gpio = WRT160NL_GPIO_LED_WLAN,
  9056. + .active_low = 1,
  9057. + }
  9058. +};
  9059. +
  9060. +static struct gpio_keys_button wrt160nl_gpio_keys[] __initdata = {
  9061. + {
  9062. + .desc = "reset",
  9063. + .type = EV_KEY,
  9064. + .code = KEY_RESTART,
  9065. + .debounce_interval = WRT160NL_KEYS_DEBOUNCE_INTERVAL,
  9066. + .gpio = WRT160NL_GPIO_BTN_RESET,
  9067. + .active_low = 1,
  9068. + }, {
  9069. + .desc = "wps",
  9070. + .type = EV_KEY,
  9071. + .code = KEY_WPS_BUTTON,
  9072. + .debounce_interval = WRT160NL_KEYS_DEBOUNCE_INTERVAL,
  9073. + .gpio = WRT160NL_GPIO_BTN_WPS,
  9074. + .active_low = 1,
  9075. + }
  9076. +};
  9077. +
  9078. +static void __init wrt160nl_setup(void)
  9079. +{
  9080. + const char *nvram = (char *) KSEG1ADDR(WRT160NL_NVRAM_ADDR);
  9081. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  9082. + u8 mac[6];
  9083. +
  9084. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  9085. + "lan_hwaddr=", mac) == 0) {
  9086. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  9087. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  9088. + }
  9089. +
  9090. + ar71xx_add_device_mdio(0x0);
  9091. +
  9092. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  9093. + ar71xx_eth0_data.phy_mask = 0x01;
  9094. +
  9095. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  9096. + ar71xx_eth1_data.phy_mask = 0x10;
  9097. +
  9098. + ar71xx_add_device_eth(0);
  9099. + ar71xx_add_device_eth(1);
  9100. +
  9101. + ar71xx_add_device_m25p80(&wrt160nl_flash_data);
  9102. +
  9103. + ar71xx_add_device_usb();
  9104. +
  9105. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  9106. + "wl0_hwaddr=", mac) == 0)
  9107. + ar9xxx_add_device_wmac(eeprom, mac);
  9108. + else
  9109. + ar9xxx_add_device_wmac(eeprom, NULL);
  9110. +
  9111. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt160nl_leds_gpio),
  9112. + wrt160nl_leds_gpio);
  9113. +
  9114. + ar71xx_register_gpio_keys_polled(-1, WRT160NL_KEYS_POLL_INTERVAL,
  9115. + ARRAY_SIZE(wrt160nl_gpio_keys),
  9116. + wrt160nl_gpio_keys);
  9117. +
  9118. +}
  9119. +
  9120. +MIPS_MACHINE(AR71XX_MACH_WRT160NL, "WRT160NL", "Linksys WRT160NL",
  9121. + wrt160nl_setup);
  9122. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wrt400n.c linux-2.6.39/arch/mips/ar71xx/mach-wrt400n.c
  9123. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wrt400n.c 1970-01-01 01:00:00.000000000 +0100
  9124. +++ linux-2.6.39/arch/mips/ar71xx/mach-wrt400n.c 2011-08-24 02:41:55.617990333 +0200
  9125. @@ -0,0 +1,164 @@
  9126. +/*
  9127. + * Linksys WRT400N board support
  9128. + *
  9129. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  9130. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  9131. + *
  9132. + * This program is free software; you can redistribute it and/or modify it
  9133. + * under the terms of the GNU General Public License version 2 as published
  9134. + * by the Free Software Foundation.
  9135. + */
  9136. +
  9137. +#include <linux/mtd/mtd.h>
  9138. +#include <linux/mtd/partitions.h>
  9139. +
  9140. +#include <asm/mach-ar71xx/ar71xx.h>
  9141. +
  9142. +#include "machtype.h"
  9143. +#include "devices.h"
  9144. +#include "dev-ap94-pci.h"
  9145. +#include "dev-m25p80.h"
  9146. +#include "dev-gpio-buttons.h"
  9147. +#include "dev-leds-gpio.h"
  9148. +
  9149. +#define WRT400N_GPIO_LED_ORANGE 5
  9150. +#define WRT400N_GPIO_LED_GREEN 4
  9151. +#define WRT400N_GPIO_LED_POWER 1
  9152. +#define WRT400N_GPIO_LED_WLAN 0
  9153. +
  9154. +#define WRT400N_GPIO_BTN_RESET 8
  9155. +#define WRT400N_GPIO_BTN_WLSEC 3
  9156. +
  9157. +#define WRT400N_KEYS_POLL_INTERVAL 20 /* msecs */
  9158. +#define WRT400N_KEYS_DEBOUNE_INTERVAL (3 * WRT400N_KEYS_POLL_INTERVAL)
  9159. +
  9160. +#define WRT400N_MAC_ADDR_OFFSET 0x120c
  9161. +#define WRT400N_CALDATA0_OFFSET 0x1000
  9162. +#define WRT400N_CALDATA1_OFFSET 0x5000
  9163. +
  9164. +#ifdef CONFIG_MTD_PARTITIONS
  9165. +static struct mtd_partition wrt400n_partitions[] = {
  9166. + {
  9167. + .name = "uboot",
  9168. + .offset = 0,
  9169. + .size = 0x030000,
  9170. + .mask_flags = MTD_WRITEABLE,
  9171. + }, {
  9172. + .name = "env",
  9173. + .offset = 0x030000,
  9174. + .size = 0x010000,
  9175. + .mask_flags = MTD_WRITEABLE,
  9176. + }, {
  9177. + .name = "linux",
  9178. + .offset = 0x040000,
  9179. + .size = 0x140000,
  9180. + }, {
  9181. + .name = "rootfs",
  9182. + .offset = 0x180000,
  9183. + .size = 0x630000,
  9184. + }, {
  9185. + .name = "nvram",
  9186. + .offset = 0x7b0000,
  9187. + .size = 0x010000,
  9188. + .mask_flags = MTD_WRITEABLE,
  9189. + }, {
  9190. + .name = "factory",
  9191. + .offset = 0x7c0000,
  9192. + .size = 0x010000,
  9193. + .mask_flags = MTD_WRITEABLE,
  9194. + }, {
  9195. + .name = "language",
  9196. + .offset = 0x7d0000,
  9197. + .size = 0x020000,
  9198. + .mask_flags = MTD_WRITEABLE,
  9199. + }, {
  9200. + .name = "caldata",
  9201. + .offset = 0x7f0000,
  9202. + .size = 0x010000,
  9203. + .mask_flags = MTD_WRITEABLE,
  9204. + }, {
  9205. + .name = "firmware",
  9206. + .offset = 0x040000,
  9207. + .size = 0x770000,
  9208. + }
  9209. +};
  9210. +#endif /* CONFIG_MTD_PARTITIONS */
  9211. +
  9212. +static struct flash_platform_data wrt400n_flash_data = {
  9213. +#ifdef CONFIG_MTD_PARTITIONS
  9214. + .parts = wrt400n_partitions,
  9215. + .nr_parts = ARRAY_SIZE(wrt400n_partitions),
  9216. +#endif
  9217. +};
  9218. +
  9219. +static struct gpio_led wrt400n_leds_gpio[] __initdata = {
  9220. + {
  9221. + .name = "wrt400n:green:status",
  9222. + .gpio = WRT400N_GPIO_LED_GREEN,
  9223. + .active_low = 1,
  9224. + }, {
  9225. + .name = "wrt400n:amber:aoss",
  9226. + .gpio = WRT400N_GPIO_LED_ORANGE,
  9227. + .active_low = 1,
  9228. + }, {
  9229. + .name = "wrt400n:green:wlan",
  9230. + .gpio = WRT400N_GPIO_LED_WLAN,
  9231. + .active_low = 1,
  9232. + }, {
  9233. + .name = "wrt400n:green:power",
  9234. + .gpio = WRT400N_GPIO_LED_POWER,
  9235. + .active_low = 1,
  9236. + }
  9237. +};
  9238. +
  9239. +static struct gpio_keys_button wrt400n_gpio_keys[] __initdata = {
  9240. + {
  9241. + .desc = "reset",
  9242. + .type = EV_KEY,
  9243. + .code = KEY_RESTART,
  9244. + .debounce_interval = WRT400N_KEYS_DEBOUNE_INTERVAL,
  9245. + .gpio = WRT400N_GPIO_BTN_RESET,
  9246. + .active_low = 1,
  9247. + }, {
  9248. + .desc = "wlsec",
  9249. + .type = EV_KEY,
  9250. + .code = KEY_WPS_BUTTON,
  9251. + .debounce_interval = WRT400N_KEYS_DEBOUNE_INTERVAL,
  9252. + .gpio = WRT400N_GPIO_BTN_WLSEC,
  9253. + .active_low = 1,
  9254. + }
  9255. +};
  9256. +
  9257. +static void __init wrt400n_setup(void)
  9258. +{
  9259. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  9260. + u8 *mac = art + WRT400N_MAC_ADDR_OFFSET;
  9261. +
  9262. + ar71xx_add_device_mdio(0x0);
  9263. +
  9264. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 1);
  9265. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  9266. + ar71xx_eth0_data.speed = SPEED_100;
  9267. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  9268. +
  9269. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 2);
  9270. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  9271. + ar71xx_eth1_data.phy_mask = 0x10;
  9272. +
  9273. + ar71xx_add_device_eth(0);
  9274. + ar71xx_add_device_eth(1);
  9275. +
  9276. + ar71xx_add_device_m25p80(&wrt400n_flash_data);
  9277. +
  9278. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt400n_leds_gpio),
  9279. + wrt400n_leds_gpio);
  9280. +
  9281. + ar71xx_register_gpio_keys_polled(-1, WRT400N_KEYS_POLL_INTERVAL,
  9282. + ARRAY_SIZE(wrt400n_gpio_keys),
  9283. + wrt400n_gpio_keys);
  9284. +
  9285. + ap94_pci_init(art + WRT400N_CALDATA0_OFFSET, NULL,
  9286. + art + WRT400N_CALDATA1_OFFSET, NULL);
  9287. +}
  9288. +
  9289. +MIPS_MACHINE(AR71XX_MACH_WRT400N, "WRT400N", "Linksys WRT400N", wrt400n_setup);
  9290. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wzr-hp-ag300h.c linux-2.6.39/arch/mips/ar71xx/mach-wzr-hp-ag300h.c
  9291. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wzr-hp-ag300h.c 1970-01-01 01:00:00.000000000 +0100
  9292. +++ linux-2.6.39/arch/mips/ar71xx/mach-wzr-hp-ag300h.c 2011-08-24 02:41:55.628193451 +0200
  9293. @@ -0,0 +1,231 @@
  9294. +/*
  9295. + * Buffalo WZR-HP-AG300H board support
  9296. + *
  9297. + * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
  9298. + *
  9299. + * This program is free software; you can redistribute it and/or modify it
  9300. + * under the terms of the GNU General Public License version 2 as published
  9301. + * by the Free Software Foundation.
  9302. + */
  9303. +
  9304. +#include <linux/platform_device.h>
  9305. +#include <linux/mtd/mtd.h>
  9306. +#include <linux/mtd/partitions.h>
  9307. +#include <linux/mtd/concat.h>
  9308. +
  9309. +#include <asm/mips_machine.h>
  9310. +#include <asm/mach-ar71xx/ar71xx.h>
  9311. +#include <asm/mach-ar71xx/gpio.h>
  9312. +
  9313. +#include "machtype.h"
  9314. +#include "devices.h"
  9315. +#include "dev-ap94-pci.h"
  9316. +#include "dev-gpio-buttons.h"
  9317. +#include "dev-leds-gpio.h"
  9318. +#include "dev-m25p80.h"
  9319. +#include "dev-usb.h"
  9320. +
  9321. +#define WZRHPAG300H_MAC_OFFSET 0x20c
  9322. +#define WZRHPAG300H_KEYS_POLL_INTERVAL 20 /* msecs */
  9323. +#define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
  9324. +
  9325. +#ifdef CONFIG_MTD_PARTITIONS
  9326. +static struct mtd_partition wzrhpag300h_flash_partitions[] = {
  9327. + {
  9328. + .name = "u-boot",
  9329. + .offset = 0,
  9330. + .size = 0x0040000,
  9331. + .mask_flags = MTD_WRITEABLE,
  9332. + }, {
  9333. + .name = "u-boot-env",
  9334. + .offset = 0x0040000,
  9335. + .size = 0x0010000,
  9336. + .mask_flags = MTD_WRITEABLE,
  9337. + }, {
  9338. + .name = "art",
  9339. + .offset = 0x0050000,
  9340. + .size = 0x0010000,
  9341. + .mask_flags = MTD_WRITEABLE,
  9342. + }, {
  9343. + .name = "kernel",
  9344. + .offset = 0x0060000,
  9345. + .size = 0x0100000,
  9346. + }, {
  9347. + .name = "rootfs",
  9348. + .offset = 0x0160000,
  9349. + .size = 0x1e90000,
  9350. + }, {
  9351. + .name = "user_property",
  9352. + .offset = 0x1ff0000,
  9353. + .size = 0x0010000,
  9354. + .mask_flags = MTD_WRITEABLE,
  9355. + }, {
  9356. + .name = "firmware",
  9357. + .offset = 0x0060000,
  9358. + .size = 0x1f90000,
  9359. + }
  9360. +};
  9361. +
  9362. +#endif /* CONFIG_MTD_PARTITIONS */
  9363. +
  9364. +static struct mtd_info *concat_devs[2] = { NULL, NULL };
  9365. +static struct work_struct mtd_concat_work;
  9366. +
  9367. +static void mtd_concat_add_work(struct work_struct *work)
  9368. +{
  9369. + struct mtd_info *mtd;
  9370. +
  9371. + mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
  9372. +
  9373. +#ifdef CONFIG_MTD_PARTITIONS
  9374. + add_mtd_partitions(mtd, wzrhpag300h_flash_partitions,
  9375. + ARRAY_SIZE(wzrhpag300h_flash_partitions));
  9376. +#else
  9377. + add_mtd_device(mtd);
  9378. +#endif
  9379. +}
  9380. +
  9381. +static void mtd_concat_add(struct mtd_info *mtd)
  9382. +{
  9383. + static bool registered = false;
  9384. +
  9385. + if (registered)
  9386. + return;
  9387. +
  9388. + if (!strcmp(mtd->name, "spi0.0"))
  9389. + concat_devs[0] = mtd;
  9390. + else if (!strcmp(mtd->name, "spi0.1"))
  9391. + concat_devs[1] = mtd;
  9392. + else
  9393. + return;
  9394. +
  9395. + if (!concat_devs[0] || !concat_devs[1])
  9396. + return;
  9397. +
  9398. + registered = true;
  9399. + INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
  9400. + schedule_work(&mtd_concat_work);
  9401. +}
  9402. +
  9403. +static void mtd_concat_remove(struct mtd_info *mtd)
  9404. +{
  9405. +}
  9406. +
  9407. +static void add_mtd_concat_notifier(void)
  9408. +{
  9409. + static struct mtd_notifier not = {
  9410. + .add = mtd_concat_add,
  9411. + .remove = mtd_concat_remove,
  9412. + };
  9413. +
  9414. + register_mtd_user(&not);
  9415. +}
  9416. +
  9417. +static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
  9418. + {
  9419. + .name = "wzr-hp-ag300h:red:diag",
  9420. + .gpio = 1,
  9421. + .active_low = 1,
  9422. + },
  9423. +};
  9424. +
  9425. +
  9426. +static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
  9427. + {
  9428. + .desc = "reset",
  9429. + .type = EV_KEY,
  9430. + .code = KEY_RESTART,
  9431. + .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  9432. + .gpio = 11,
  9433. + .active_low = 1,
  9434. + }, {
  9435. + .desc = "usb",
  9436. + .type = EV_KEY,
  9437. + .code = BTN_2,
  9438. + .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  9439. + .gpio = 3,
  9440. + .active_low = 1,
  9441. + }, {
  9442. + .desc = "aoss",
  9443. + .type = EV_KEY,
  9444. + .code = KEY_WPS_BUTTON,
  9445. + .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  9446. + .gpio = 5,
  9447. + .active_low = 1,
  9448. + }, {
  9449. + .desc = "router_auto",
  9450. + .type = EV_KEY,
  9451. + .code = BTN_6,
  9452. + .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  9453. + .gpio = 6,
  9454. + .active_low = 1,
  9455. + }, {
  9456. + .desc = "router_off",
  9457. + .type = EV_KEY,
  9458. + .code = BTN_5,
  9459. + .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  9460. + .gpio = 7,
  9461. + .active_low = 1,
  9462. + }
  9463. +};
  9464. +
  9465. +static struct spi_board_info ar71xx_spi_info[] = {
  9466. + {
  9467. + .bus_num = 0,
  9468. + .chip_select = 0,
  9469. + .max_speed_hz = 25000000,
  9470. + .modalias = "m25p80",
  9471. + },
  9472. + {
  9473. + .bus_num = 0,
  9474. + .chip_select = 1,
  9475. + .max_speed_hz = 25000000,
  9476. + .modalias = "m25p80",
  9477. + }
  9478. +};
  9479. +
  9480. +static void __init wzrhpag300h_setup(void)
  9481. +{
  9482. + u8 *eeprom1 = (u8 *) KSEG1ADDR(0x1f051000);
  9483. + u8 *eeprom2 = (u8 *) KSEG1ADDR(0x1f055000);
  9484. + u8 *mac1 = eeprom1 + WZRHPAG300H_MAC_OFFSET;
  9485. + u8 *mac2 = eeprom2 + WZRHPAG300H_MAC_OFFSET;
  9486. +
  9487. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac1, 0);
  9488. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac2, 1);
  9489. +
  9490. + ar71xx_add_device_mdio(~(BIT(0) | BIT(4)));
  9491. +
  9492. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  9493. + ar71xx_eth0_data.speed = SPEED_1000;
  9494. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  9495. + ar71xx_eth0_data.phy_mask = BIT(0);
  9496. +
  9497. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  9498. + ar71xx_eth1_data.phy_mask = BIT(4);
  9499. +
  9500. + ar71xx_add_device_eth(0);
  9501. + ar71xx_add_device_eth(1);
  9502. +
  9503. + ar71xx_add_device_usb();
  9504. + gpio_request(2, "usb");
  9505. + gpio_direction_output(2, 1);
  9506. +
  9507. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
  9508. + wzrhpag300h_leds_gpio);
  9509. +
  9510. + ar71xx_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
  9511. + ARRAY_SIZE(wzrhpag300h_gpio_keys),
  9512. + wzrhpag300h_gpio_keys);
  9513. +
  9514. + ar71xx_add_device_spi(NULL, ar71xx_spi_info,
  9515. + ARRAY_SIZE(ar71xx_spi_info));
  9516. +
  9517. + add_mtd_concat_notifier();
  9518. +
  9519. + ap94_pci_init(eeprom1, mac1, eeprom2, mac2);
  9520. +}
  9521. +
  9522. +MIPS_MACHINE(AR71XX_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
  9523. + "Buffalo WZR-HP-AG300H", wzrhpag300h_setup);
  9524. +
  9525. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c linux-2.6.39/arch/mips/ar71xx/mach-wzr-hp-g300nh.c
  9526. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 1970-01-01 01:00:00.000000000 +0100
  9527. +++ linux-2.6.39/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 2011-08-24 02:41:55.649418561 +0200
  9528. @@ -0,0 +1,292 @@
  9529. +/*
  9530. + * Buffalo WZR-HP-G300NH board support
  9531. + *
  9532. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  9533. + *
  9534. + * This program is free software; you can redistribute it and/or modify it
  9535. + * under the terms of the GNU General Public License version 2 as published
  9536. + * by the Free Software Foundation.
  9537. + */
  9538. +
  9539. +#include <linux/platform_device.h>
  9540. +#include <linux/mtd/mtd.h>
  9541. +#include <linux/mtd/partitions.h>
  9542. +#include <linux/nxp_74hc153.h>
  9543. +#include <linux/rtl8366.h>
  9544. +
  9545. +#include <asm/mips_machine.h>
  9546. +#include <asm/mach-ar71xx/ar71xx.h>
  9547. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  9548. +
  9549. +#include "machtype.h"
  9550. +#include "devices.h"
  9551. +#include "dev-ar9xxx-wmac.h"
  9552. +#include "dev-gpio-buttons.h"
  9553. +#include "dev-leds-gpio.h"
  9554. +#include "dev-usb.h"
  9555. +
  9556. +#define WZRHPG300NH_GPIO_LED_USB 0
  9557. +#define WZRHPG300NH_GPIO_LED_DIAG 1
  9558. +#define WZRHPG300NH_GPIO_LED_WIRELESS 6
  9559. +#define WZRHPG300NH_GPIO_LED_SECURITY 17
  9560. +#define WZRHPG300NH_GPIO_LED_ROUTER 18
  9561. +
  9562. +#define WZRHPG300NH_GPIO_RTL8366_SDA 19
  9563. +#define WZRHPG300NH_GPIO_RTL8366_SCK 20
  9564. +
  9565. +#define WZRHPG300NH_GPIO_74HC153_S0 9
  9566. +#define WZRHPG300NH_GPIO_74HC153_S1 11
  9567. +#define WZRHPG300NH_GPIO_74HC153_1Y 12
  9568. +#define WZRHPG300NH_GPIO_74HC153_2Y 14
  9569. +
  9570. +#define WZRHPG300NH_GPIO_EXP_BASE 32
  9571. +#define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
  9572. +#define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
  9573. +#define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
  9574. +#define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
  9575. +#define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
  9576. +#define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
  9577. +#define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
  9578. +
  9579. +#define WZRHPG300NH_KEYS_POLL_INTERVAL 20 /* msecs */
  9580. +#define WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH_KEYS_POLL_INTERVAL)
  9581. +
  9582. +#define WZRHPG300NH_MAC_OFFSET 0x20c
  9583. +
  9584. +#ifdef CONFIG_MTD_PARTITIONS
  9585. +static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
  9586. + {
  9587. + .name = "u-boot",
  9588. + .offset = 0,
  9589. + .size = 0x0040000,
  9590. + .mask_flags = MTD_WRITEABLE,
  9591. + }, {
  9592. + .name = "u-boot-env",
  9593. + .offset = 0x0040000,
  9594. + .size = 0x0020000,
  9595. + .mask_flags = MTD_WRITEABLE,
  9596. + }, {
  9597. + .name = "kernel",
  9598. + .offset = 0x0060000,
  9599. + .size = 0x0100000,
  9600. + }, {
  9601. + .name = "rootfs",
  9602. + .offset = 0x0160000,
  9603. + .size = 0x1e60000,
  9604. + }, {
  9605. + .name = "user_property",
  9606. + .offset = 0x1fc0000,
  9607. + .size = 0x0020000,
  9608. + .mask_flags = MTD_WRITEABLE,
  9609. + }, {
  9610. + .name = "art",
  9611. + .offset = 0x1fe0000,
  9612. + .size = 0x0020000,
  9613. + .mask_flags = MTD_WRITEABLE,
  9614. + }, {
  9615. + .name = "firmware",
  9616. + .offset = 0x0060000,
  9617. + .size = 0x1f60000,
  9618. + }
  9619. +};
  9620. +#endif /* CONFIG_MTD_PARTITIONS */
  9621. +
  9622. +static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
  9623. + .width = 2,
  9624. +#ifdef CONFIG_MTD_PARTITIONS
  9625. + .parts = wzrhpg300nh_flash_partitions,
  9626. + .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
  9627. +#endif
  9628. +};
  9629. +
  9630. +#define WZRHPG300NH_FLASH_BASE 0x1e000000
  9631. +#define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
  9632. +
  9633. +static struct resource wzrhpg300nh_flash_resources[] = {
  9634. + [0] = {
  9635. + .start = WZRHPG300NH_FLASH_BASE,
  9636. + .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
  9637. + .flags = IORESOURCE_MEM,
  9638. + },
  9639. +};
  9640. +
  9641. +static struct platform_device wzrhpg300nh_flash_device = {
  9642. + .name = "ar91xx-flash",
  9643. + .id = -1,
  9644. + .resource = wzrhpg300nh_flash_resources,
  9645. + .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
  9646. + .dev = {
  9647. + .platform_data = &wzrhpg300nh_flash_data,
  9648. + }
  9649. +};
  9650. +
  9651. +static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
  9652. + {
  9653. + .name = "wzr-hp-g300nh:orange:security",
  9654. + .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
  9655. + .active_low = 1,
  9656. + }, {
  9657. + .name = "wzr-hp-g300nh:green:wireless",
  9658. + .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
  9659. + .active_low = 1,
  9660. + }, {
  9661. + .name = "wzr-hp-g300nh:green:router",
  9662. + .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
  9663. + .active_low = 1,
  9664. + }, {
  9665. + .name = "wzr-hp-g300nh:red:diag",
  9666. + .gpio = WZRHPG300NH_GPIO_LED_DIAG,
  9667. + .active_low = 1,
  9668. + }, {
  9669. + .name = "wzr-hp-g300nh:blue:usb",
  9670. + .gpio = WZRHPG300NH_GPIO_LED_USB,
  9671. + .active_low = 1,
  9672. + }
  9673. +};
  9674. +
  9675. +static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = {
  9676. + {
  9677. + .desc = "reset",
  9678. + .type = EV_KEY,
  9679. + .code = KEY_RESTART,
  9680. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9681. + .gpio = WZRHPG300NH_GPIO_BTN_RESET,
  9682. + .active_low = 1,
  9683. + }, {
  9684. + .desc = "aoss",
  9685. + .type = EV_KEY,
  9686. + .code = KEY_WPS_BUTTON,
  9687. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9688. + .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
  9689. + .active_low = 1,
  9690. + }, {
  9691. + .desc = "usb",
  9692. + .type = EV_KEY,
  9693. + .code = BTN_2,
  9694. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9695. + .gpio = WZRHPG300NH_GPIO_BTN_USB,
  9696. + .active_low = 1,
  9697. + }, {
  9698. + .desc = "qos_on",
  9699. + .type = EV_KEY,
  9700. + .code = BTN_3,
  9701. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9702. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
  9703. + .active_low = 0,
  9704. + }, {
  9705. + .desc = "qos_off",
  9706. + .type = EV_KEY,
  9707. + .code = BTN_4,
  9708. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9709. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
  9710. + .active_low = 0,
  9711. + }, {
  9712. + .desc = "router_on",
  9713. + .type = EV_KEY,
  9714. + .code = BTN_5,
  9715. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9716. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
  9717. + .active_low = 0,
  9718. + }, {
  9719. + .desc = "router_auto",
  9720. + .type = EV_KEY,
  9721. + .code = BTN_6,
  9722. + .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  9723. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
  9724. + .active_low = 0,
  9725. + }
  9726. +};
  9727. +
  9728. +static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
  9729. + .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
  9730. + .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
  9731. + .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
  9732. + .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
  9733. + .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
  9734. +};
  9735. +
  9736. +static struct platform_device wzrhpg300nh_74hc153_device = {
  9737. + .name = NXP_74HC153_DRIVER_NAME,
  9738. + .id = -1,
  9739. + .dev = {
  9740. + .platform_data = &wzrhpg300nh_74hc153_data,
  9741. + }
  9742. +};
  9743. +
  9744. +static struct rtl8366_platform_data wzrhpg300nh_rtl8366_data = {
  9745. + .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
  9746. + .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
  9747. +};
  9748. +
  9749. +static struct platform_device wzrhpg300nh_rtl8366s_device = {
  9750. + .name = RTL8366S_DRIVER_NAME,
  9751. + .id = -1,
  9752. + .dev = {
  9753. + .platform_data = &wzrhpg300nh_rtl8366_data,
  9754. + }
  9755. +};
  9756. +
  9757. +static struct platform_device wzrhpg300nh_rtl8366rb_device = {
  9758. + .name = RTL8366RB_DRIVER_NAME,
  9759. + .id = -1,
  9760. + .dev = {
  9761. + .platform_data = &wzrhpg300nh_rtl8366_data,
  9762. + }
  9763. +};
  9764. +
  9765. +static void __init wzrhpg300nh_setup(void)
  9766. +{
  9767. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  9768. + u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET;
  9769. + bool hasrtl8366rb = false;
  9770. +
  9771. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  9772. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  9773. +
  9774. + if (rtl8366_smi_detect(&wzrhpg300nh_rtl8366_data) == RTL8366_TYPE_RB)
  9775. + hasrtl8366rb = true;
  9776. +
  9777. + if (hasrtl8366rb) {
  9778. + ar71xx_eth0_pll_data.pll_1000 = 0x1f000000;
  9779. + ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
  9780. + ar71xx_eth1_pll_data.pll_1000 = 0x100;
  9781. + ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
  9782. + } else {
  9783. + ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
  9784. + ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  9785. + ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
  9786. + ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  9787. + }
  9788. +
  9789. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  9790. + ar71xx_eth0_data.speed = SPEED_1000;
  9791. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  9792. +
  9793. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  9794. + ar71xx_eth1_data.phy_mask = 0x10;
  9795. +
  9796. + ar71xx_add_device_eth(0);
  9797. + ar71xx_add_device_eth(1);
  9798. +
  9799. + ar71xx_add_device_usb();
  9800. + ar9xxx_add_device_wmac(eeprom, NULL);
  9801. +
  9802. + platform_device_register(&wzrhpg300nh_74hc153_device);
  9803. + platform_device_register(&wzrhpg300nh_flash_device);
  9804. +
  9805. + if (hasrtl8366rb)
  9806. + platform_device_register(&wzrhpg300nh_rtl8366rb_device);
  9807. + else
  9808. + platform_device_register(&wzrhpg300nh_rtl8366s_device);
  9809. +
  9810. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
  9811. + wzrhpg300nh_leds_gpio);
  9812. +
  9813. + ar71xx_register_gpio_keys_polled(-1, WZRHPG300NH_KEYS_POLL_INTERVAL,
  9814. + ARRAY_SIZE(wzrhpg300nh_gpio_keys),
  9815. + wzrhpg300nh_gpio_keys);
  9816. +
  9817. +}
  9818. +
  9819. +MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
  9820. + "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);
  9821. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/mach-zcn-1523h.c linux-2.6.39/arch/mips/ar71xx/mach-zcn-1523h.c
  9822. --- linux-2.6.39.orig/arch/mips/ar71xx/mach-zcn-1523h.c 1970-01-01 01:00:00.000000000 +0100
  9823. +++ linux-2.6.39/arch/mips/ar71xx/mach-zcn-1523h.c 2011-08-24 02:41:55.649418561 +0200
  9824. @@ -0,0 +1,214 @@
  9825. +/*
  9826. + * Zcomax ZCN-1523H-2-8/5-16 board support
  9827. + *
  9828. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  9829. + *
  9830. + * This program is free software; you can redistribute it and/or modify it
  9831. + * under the terms of the GNU General Public License version 2 as published
  9832. + * by the Free Software Foundation.
  9833. + */
  9834. +
  9835. +#include <linux/mtd/mtd.h>
  9836. +#include <linux/mtd/partitions.h>
  9837. +
  9838. +#include <asm/mach-ar71xx/ar71xx.h>
  9839. +
  9840. +#include "machtype.h"
  9841. +#include "devices.h"
  9842. +#include "dev-m25p80.h"
  9843. +#include "dev-ap91-pci.h"
  9844. +#include "dev-gpio-buttons.h"
  9845. +#include "dev-leds-gpio.h"
  9846. +
  9847. +#define ZCN_1523H_GPIO_BTN_RESET 0
  9848. +#define ZCN_1523H_GPIO_LED_INIT 11
  9849. +#define ZCN_1523H_GPIO_LED_LAN1 17
  9850. +
  9851. +#define ZCN_1523H_2_GPIO_LED_WEAK 13
  9852. +#define ZCN_1523H_2_GPIO_LED_MEDIUM 14
  9853. +#define ZCN_1523H_2_GPIO_LED_STRONG 15
  9854. +
  9855. +#define ZCN_1523H_5_GPIO_LED_UNKNOWN 1
  9856. +#define ZCN_1523H_5_GPIO_LED_LAN2 13
  9857. +#define ZCN_1523H_5_GPIO_LED_WEAK 14
  9858. +#define ZCN_1523H_5_GPIO_LED_MEDIUM 15
  9859. +#define ZCN_1523H_5_GPIO_LED_STRONG 16
  9860. +
  9861. +#define ZCN_1523H_KEYS_POLL_INTERVAL 20 /* msecs */
  9862. +#define ZCN_1523H_KEYS_DEBOUNCE_INTERVAL (3 * ZCN_1523H_KEYS_POLL_INTERVAL)
  9863. +
  9864. +#ifdef CONFIG_MTD_PARTITIONS
  9865. +static struct mtd_partition zcn_1523h_partitions[] = {
  9866. + {
  9867. + .name = "u-boot",
  9868. + .offset = 0,
  9869. + .size = 0x040000,
  9870. + .mask_flags = MTD_WRITEABLE,
  9871. + }, {
  9872. + .name = "u-boot-env",
  9873. + .offset = 0x040000,
  9874. + .size = 0x010000,
  9875. + .mask_flags = MTD_WRITEABLE,
  9876. + }, {
  9877. + .name = "rootfs",
  9878. + .offset = 0x050000,
  9879. + .size = 0x610000,
  9880. + }, {
  9881. + .name = "kernel",
  9882. + .offset = 0x660000,
  9883. + .size = 0x170000,
  9884. + }, {
  9885. + .name = "configure",
  9886. + .offset = 0x7d0000,
  9887. + .size = 0x010000,
  9888. + .mask_flags = MTD_WRITEABLE,
  9889. + }, {
  9890. + .name = "mfg",
  9891. + .offset = 0x7e0000,
  9892. + .size = 0x010000,
  9893. + .mask_flags = MTD_WRITEABLE,
  9894. + }, {
  9895. + .name = "eeprom",
  9896. + .offset = 0x7f0000,
  9897. + .size = 0x010000,
  9898. + .mask_flags = MTD_WRITEABLE,
  9899. + }, {
  9900. + .name = "firmware",
  9901. + .offset = 0x050000,
  9902. + .size = 0x780000,
  9903. + }
  9904. +};
  9905. +#endif /* CONFIG_MTD_PARTITIONS */
  9906. +
  9907. +static struct flash_platform_data zcn_1523h_flash_data = {
  9908. +#ifdef CONFIG_MTD_PARTITIONS
  9909. + .parts = zcn_1523h_partitions,
  9910. + .nr_parts = ARRAY_SIZE(zcn_1523h_partitions),
  9911. +#endif
  9912. +};
  9913. +
  9914. +static struct gpio_keys_button zcn_1523h_gpio_keys[] __initdata = {
  9915. + {
  9916. + .desc = "reset",
  9917. + .type = EV_KEY,
  9918. + .code = KEY_RESTART,
  9919. + .debounce_interval = ZCN_1523H_KEYS_DEBOUNCE_INTERVAL,
  9920. + .gpio = ZCN_1523H_GPIO_BTN_RESET,
  9921. + .active_low = 1,
  9922. + }
  9923. +};
  9924. +
  9925. +static struct gpio_led zcn_1523h_leds_gpio[] __initdata = {
  9926. + {
  9927. + .name = "zcn-1523h:amber:init",
  9928. + .gpio = ZCN_1523H_GPIO_LED_INIT,
  9929. + .active_low = 1,
  9930. + }, {
  9931. + .name = "zcn-1523h:green:lan1",
  9932. + .gpio = ZCN_1523H_GPIO_LED_LAN1,
  9933. + .active_low = 1,
  9934. + }
  9935. +};
  9936. +
  9937. +static struct gpio_led zcn_1523h_2_leds_gpio[] __initdata = {
  9938. + {
  9939. + .name = "zcn-1523h:red:weak",
  9940. + .gpio = ZCN_1523H_2_GPIO_LED_WEAK,
  9941. + .active_low = 1,
  9942. + }, {
  9943. + .name = "zcn-1523h:amber:medium",
  9944. + .gpio = ZCN_1523H_2_GPIO_LED_MEDIUM,
  9945. + .active_low = 1,
  9946. + }, {
  9947. + .name = "zcn-1523h:green:strong",
  9948. + .gpio = ZCN_1523H_2_GPIO_LED_STRONG,
  9949. + .active_low = 1,
  9950. + }
  9951. +};
  9952. +
  9953. +static struct gpio_led zcn_1523h_5_leds_gpio[] __initdata = {
  9954. + {
  9955. + .name = "zcn-1523h:red:weak",
  9956. + .gpio = ZCN_1523H_5_GPIO_LED_WEAK,
  9957. + .active_low = 1,
  9958. + }, {
  9959. + .name = "zcn-1523h:amber:medium",
  9960. + .gpio = ZCN_1523H_5_GPIO_LED_MEDIUM,
  9961. + .active_low = 1,
  9962. + }, {
  9963. + .name = "zcn-1523h:green:strong",
  9964. + .gpio = ZCN_1523H_5_GPIO_LED_STRONG,
  9965. + .active_low = 1,
  9966. + }, {
  9967. + .name = "zcn-1523h:green:lan2",
  9968. + .gpio = ZCN_1523H_5_GPIO_LED_LAN2,
  9969. + .active_low = 1,
  9970. + }, {
  9971. + .name = "zcn-1523h:amber:unknown",
  9972. + .gpio = ZCN_1523H_5_GPIO_LED_UNKNOWN,
  9973. + }
  9974. +};
  9975. +
  9976. +static void __init zcn_1523h_generic_setup(void)
  9977. +{
  9978. + u8 *mac = (u8 *) KSEG1ADDR(0x1f7e0004);
  9979. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  9980. +
  9981. + ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  9982. + AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  9983. + AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  9984. + AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  9985. + AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  9986. +
  9987. + ar71xx_add_device_m25p80(&zcn_1523h_flash_data);
  9988. +
  9989. + ar71xx_add_device_leds_gpio(0, ARRAY_SIZE(zcn_1523h_leds_gpio),
  9990. + zcn_1523h_leds_gpio);
  9991. +
  9992. + ar71xx_register_gpio_keys_polled(-1, ZCN_1523H_KEYS_POLL_INTERVAL,
  9993. + ARRAY_SIZE(zcn_1523h_gpio_keys),
  9994. + zcn_1523h_gpio_keys);
  9995. +
  9996. + ap91_pci_init(ee, mac);
  9997. +
  9998. + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
  9999. + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
  10000. +
  10001. + /* LAN1 port */
  10002. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  10003. + ar71xx_eth0_data.speed = SPEED_100;
  10004. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  10005. +
  10006. + /* LAN2 port */
  10007. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  10008. + ar71xx_eth1_data.speed = SPEED_1000;
  10009. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  10010. +
  10011. + ar71xx_add_device_mdio(0x0);
  10012. + ar71xx_add_device_eth(0);
  10013. +}
  10014. +
  10015. +static void __init zcn_1523h_2_setup(void)
  10016. +{
  10017. + zcn_1523h_generic_setup();
  10018. + ap91_pci_setup_wmac_gpio(BIT(9), 0);
  10019. +
  10020. + ar71xx_add_device_leds_gpio(1, ARRAY_SIZE(zcn_1523h_2_leds_gpio),
  10021. + zcn_1523h_2_leds_gpio);
  10022. +}
  10023. +
  10024. +MIPS_MACHINE(AR71XX_MACH_ZCN_1523H_2, "ZCN-1523H-2", "Zcomax ZCN-1523H-2",
  10025. + zcn_1523h_2_setup);
  10026. +
  10027. +static void __init zcn_1523h_5_setup(void)
  10028. +{
  10029. + zcn_1523h_generic_setup();
  10030. + ap91_pci_setup_wmac_gpio(BIT(8), 0);
  10031. +
  10032. + ar71xx_add_device_leds_gpio(1, ARRAY_SIZE(zcn_1523h_5_leds_gpio),
  10033. + zcn_1523h_5_leds_gpio);
  10034. + ar71xx_add_device_eth(1);
  10035. +}
  10036. +
  10037. +MIPS_MACHINE(AR71XX_MACH_ZCN_1523H_5, "ZCN-1523H-5", "Zcomax ZCN-1523H-5",
  10038. + zcn_1523h_5_setup);
  10039. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/Makefile linux-2.6.39/arch/mips/ar71xx/Makefile
  10040. --- linux-2.6.39.orig/arch/mips/ar71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  10041. +++ linux-2.6.39/arch/mips/ar71xx/Makefile 2011-08-24 02:41:55.677990354 +0200
  10042. @@ -0,0 +1,67 @@
  10043. +#
  10044. +# Makefile for the Atheros AR71xx SoC specific parts of the kernel
  10045. +#
  10046. +# Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  10047. +# Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10048. +#
  10049. +# This program is free software; you can redistribute it and/or modify it
  10050. +# under the terms of the GNU General Public License version 2 as published
  10051. +# by the Free Software Foundation.
  10052. +
  10053. +obj-y := prom.o irq.o setup.o devices.o gpio.o ar71xx.o
  10054. +
  10055. +obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  10056. +obj-$(CONFIG_PCI) += pci.o
  10057. +
  10058. +obj-$(CONFIG_AR71XX_DEV_AP91_PCI) += dev-ap91-pci.o
  10059. +obj-$(CONFIG_AR71XX_DEV_AP94_PCI) += dev-ap94-pci.o
  10060. +obj-$(CONFIG_AR71XX_DEV_AR9XXX_WMAC) += dev-ar9xxx-wmac.o
  10061. +obj-$(CONFIG_AR71XX_DEV_DB120_PCI) += dev-db120-pci.o
  10062. +obj-$(CONFIG_AR71XX_DEV_DSA) += dev-dsa.o
  10063. +obj-$(CONFIG_AR71XX_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o
  10064. +obj-$(CONFIG_AR71XX_DEV_LEDS_GPIO) += dev-leds-gpio.o
  10065. +obj-$(CONFIG_AR71XX_DEV_M25P80) += dev-m25p80.o
  10066. +obj-$(CONFIG_AR71XX_DEV_PB42_PCI) += dev-pb42-pci.o
  10067. +obj-$(CONFIG_AR71XX_DEV_PB9X_PCI) += dev-pb9x-pci.o
  10068. +obj-$(CONFIG_AR71XX_DEV_USB) += dev-usb.o
  10069. +
  10070. +obj-$(CONFIG_AR71XX_NVRAM) += nvram.o
  10071. +obj-$(CONFIG_AR71XX_PCI_ATH9K_FIXUP) += pci-ath9k-fixup.o
  10072. +
  10073. +obj-$(CONFIG_AR71XX_MACH_AP121) += mach-ap121.o
  10074. +obj-$(CONFIG_AR71XX_MACH_AP81) += mach-ap81.o
  10075. +obj-$(CONFIG_AR71XX_MACH_AP83) += mach-ap83.o
  10076. +obj-$(CONFIG_AR71XX_MACH_AP96) += mach-ap96.o
  10077. +obj-$(CONFIG_AR71XX_MACH_AW_NR580) += mach-aw-nr580.o
  10078. +obj-$(CONFIG_AR71XX_MACH_DB120) += mach-db120.o
  10079. +obj-$(CONFIG_AR71XX_MACH_DIR_600_A1) += mach-dir-600-a1.o
  10080. +obj-$(CONFIG_AR71XX_MACH_DIR_615_C1) += mach-dir-615-c1.o
  10081. +obj-$(CONFIG_AR71XX_MACH_DIR_825_B1) += mach-dir-825-b1.o
  10082. +obj-$(CONFIG_AR71XX_MACH_EAP7660D) += mach-eap7660d.o
  10083. +obj-$(CONFIG_AR71XX_MACH_JA76PF) += mach-ja76pf.o
  10084. +obj-$(CONFIG_AR71XX_MACH_JWAP003) += mach-jwap003.o
  10085. +obj-$(CONFIG_AR71XX_MACH_MZK_W04NU) += mach-mzk-w04nu.o
  10086. +obj-$(CONFIG_AR71XX_MACH_MZK_W300NH) += mach-mzk-w300nh.o
  10087. +obj-$(CONFIG_AR71XX_MACH_NBG460N) += mach-nbg460n.o
  10088. +obj-$(CONFIG_AR71XX_MACH_PB42) += mach-pb42.o
  10089. +obj-$(CONFIG_AR71XX_MACH_PB44) += mach-pb44.o
  10090. +obj-$(CONFIG_AR71XX_MACH_PB92) += mach-pb92.o
  10091. +obj-$(CONFIG_AR71XX_MACH_RB4XX) += mach-rb4xx.o
  10092. +obj-$(CONFIG_AR71XX_MACH_RB750) += mach-rb750.o
  10093. +obj-$(CONFIG_AR71XX_MACH_TEW_632BRP) += mach-tew-632brp.o
  10094. +obj-$(CONFIG_AR71XX_MACH_TL_MR3X20) += mach-tl-mr3x20.o
  10095. +obj-$(CONFIG_AR71XX_MACH_TL_WA901ND) += mach-tl-wa901nd.o
  10096. +obj-$(CONFIG_AR71XX_MACH_TL_WA901ND_V2) += mach-tl-wa901nd-v2.o
  10097. +obj-$(CONFIG_AR71XX_MACH_TL_WR741ND) += mach-tl-wr741nd.o
  10098. +obj-$(CONFIG_AR71XX_MACH_TL_WR841N_V1) += mach-tl-wr841n.o
  10099. +obj-$(CONFIG_AR71XX_MACH_TL_WR941ND) += mach-tl-wr941nd.o
  10100. +obj-$(CONFIG_AR71XX_MACH_TL_WR1043ND) += mach-tl-wr1043nd.o
  10101. +obj-$(CONFIG_AR71XX_MACH_UBNT) += mach-ubnt.o
  10102. +obj-$(CONFIG_AR71XX_MACH_WNDR3700) += mach-wndr3700.o
  10103. +obj-$(CONFIG_AR71XX_MACH_WNR2000) += mach-wnr2000.o
  10104. +obj-$(CONFIG_AR71XX_MACH_WP543) += mach-wp543.o
  10105. +obj-$(CONFIG_AR71XX_MACH_WRT160NL) += mach-wrt160nl.o
  10106. +obj-$(CONFIG_AR71XX_MACH_WRT400N) += mach-wrt400n.o
  10107. +obj-$(CONFIG_AR71XX_MACH_WZR_HP_G300NH) += mach-wzr-hp-g300nh.o
  10108. +obj-$(CONFIG_AR71XX_MACH_WZR_HP_AG300H) += mach-wzr-hp-ag300h.o
  10109. +obj-$(CONFIG_AR71XX_MACH_ZCN_1523H) += mach-zcn-1523h.o
  10110. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/nvram.c linux-2.6.39/arch/mips/ar71xx/nvram.c
  10111. --- linux-2.6.39.orig/arch/mips/ar71xx/nvram.c 1970-01-01 01:00:00.000000000 +0100
  10112. +++ linux-2.6.39/arch/mips/ar71xx/nvram.c 2011-08-24 02:41:55.677990354 +0200
  10113. @@ -0,0 +1,75 @@
  10114. +/*
  10115. + * Atheros AR71xx minimal nvram support
  10116. + *
  10117. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10118. + *
  10119. + * This program is free software; you can redistribute it and/or modify it
  10120. + * under the terms of the GNU General Public License version 2 as published
  10121. + * by the Free Software Foundation.
  10122. + */
  10123. +
  10124. +#include <linux/kernel.h>
  10125. +#include <linux/vmalloc.h>
  10126. +#include <linux/errno.h>
  10127. +#include <linux/init.h>
  10128. +#include <linux/string.h>
  10129. +
  10130. +#include "nvram.h"
  10131. +
  10132. +char *nvram_find_var(const char *name, const char *buf, unsigned buf_len)
  10133. +{
  10134. + unsigned len = strlen(name);
  10135. + char *cur, *last;
  10136. +
  10137. + if (buf_len == 0 || len == 0)
  10138. + return NULL;
  10139. +
  10140. + if (buf_len < len)
  10141. + return NULL;
  10142. +
  10143. + if (len == 1)
  10144. + return memchr(buf, (int) *name, buf_len);
  10145. +
  10146. + last = (char *) buf + buf_len - len;
  10147. + for (cur = (char *) buf; cur <= last; cur++)
  10148. + if (cur[0] == name[0] && memcmp(cur, name, len) == 0)
  10149. + return cur + len;
  10150. +
  10151. + return NULL;
  10152. +}
  10153. +
  10154. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  10155. + const char *name, char *mac)
  10156. +{
  10157. + char *buf;
  10158. + char *mac_str;
  10159. + int ret;
  10160. + int t;
  10161. +
  10162. + buf = vmalloc(nvram_len);
  10163. + if (!buf)
  10164. + return -ENOMEM;
  10165. +
  10166. + memcpy(buf, nvram, nvram_len);
  10167. + buf[nvram_len - 1] = '\0';
  10168. +
  10169. + mac_str = nvram_find_var(name, buf, nvram_len);
  10170. + if (!mac_str) {
  10171. + ret = -EINVAL;
  10172. + goto free;
  10173. + }
  10174. +
  10175. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  10176. + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  10177. +
  10178. + if (t != 6) {
  10179. + ret = -EINVAL;
  10180. + goto free;
  10181. + }
  10182. +
  10183. + ret = 0;
  10184. +
  10185. +free:
  10186. + vfree(buf);
  10187. + return ret;
  10188. +}
  10189. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/nvram.h linux-2.6.39/arch/mips/ar71xx/nvram.h
  10190. --- linux-2.6.39.orig/arch/mips/ar71xx/nvram.h 1970-01-01 01:00:00.000000000 +0100
  10191. +++ linux-2.6.39/arch/mips/ar71xx/nvram.h 2011-08-24 02:41:55.687991145 +0200
  10192. @@ -0,0 +1,19 @@
  10193. +/*
  10194. + * Atheros AR71xx minimal nvram support
  10195. + *
  10196. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10197. + *
  10198. + * This program is free software; you can redistribute it and/or modify it
  10199. + * under the terms of the GNU General Public License version 2 as published
  10200. + * by the Free Software Foundation.
  10201. + */
  10202. +
  10203. +#ifndef _AR71XX_NVRAM_H
  10204. +#define _AR71XX_NVRAM_H
  10205. +
  10206. +char *nvram_find_var(const char *name, const char *buf,
  10207. + unsigned buf_len) __init;
  10208. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  10209. + const char *name, char *mac) __init;
  10210. +
  10211. +#endif /* _AR71XX_NVRAM_H */
  10212. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/pci-ath9k-fixup.c linux-2.6.39/arch/mips/ar71xx/pci-ath9k-fixup.c
  10213. --- linux-2.6.39.orig/arch/mips/ar71xx/pci-ath9k-fixup.c 1970-01-01 01:00:00.000000000 +0100
  10214. +++ linux-2.6.39/arch/mips/ar71xx/pci-ath9k-fixup.c 2011-08-24 02:41:55.697990606 +0200
  10215. @@ -0,0 +1,123 @@
  10216. +/*
  10217. + * Atheros AP94 reference board PCI initialization
  10218. + *
  10219. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  10220. + *
  10221. + * This program is free software; you can redistribute it and/or modify it
  10222. + * under the terms of the GNU General Public License version 2 as published
  10223. + * by the Free Software Foundation.
  10224. + */
  10225. +
  10226. +#include <linux/pci.h>
  10227. +#include <linux/delay.h>
  10228. +
  10229. +#include <asm/mach-ar71xx/ar71xx.h>
  10230. +#include <asm/mach-ar71xx/pci.h>
  10231. +
  10232. +struct ath9k_fixup {
  10233. + u16 *cal_data;
  10234. + unsigned slot;
  10235. +};
  10236. +
  10237. +static int ath9k_num_fixups;
  10238. +static struct ath9k_fixup ath9k_fixups[2];
  10239. +
  10240. +static void ath9k_pci_fixup(struct pci_dev *dev)
  10241. +{
  10242. + void __iomem *mem;
  10243. + u16 *cal_data = NULL;
  10244. + u16 cmd;
  10245. + u32 bar0;
  10246. + u32 val;
  10247. + unsigned i;
  10248. +
  10249. + for (i = 0; i < ath9k_num_fixups; i++) {
  10250. + if (ath9k_fixups[i].cal_data == NULL)
  10251. + continue;
  10252. +
  10253. + if (ath9k_fixups[i].slot != PCI_SLOT(dev->devfn))
  10254. + continue;
  10255. +
  10256. + cal_data = ath9k_fixups[i].cal_data;
  10257. + break;
  10258. + }
  10259. +
  10260. + if (cal_data == NULL)
  10261. + return;
  10262. +
  10263. + if (*cal_data != 0xa55a) {
  10264. + pr_err("pci %s: invalid calibration data\n", pci_name(dev));
  10265. + return;
  10266. + }
  10267. +
  10268. + pr_info("pci %s: fixup device configuration\n", pci_name(dev));
  10269. +
  10270. + mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
  10271. + if (!mem) {
  10272. + pr_err("pci %s: ioremap error\n", pci_name(dev));
  10273. + return;
  10274. + }
  10275. +
  10276. + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
  10277. +
  10278. + switch (ar71xx_soc) {
  10279. + case AR71XX_SOC_AR7161:
  10280. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
  10281. + AR71XX_PCI_MEM_BASE);
  10282. + break;
  10283. + case AR71XX_SOC_AR7240:
  10284. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0xffff);
  10285. + break;
  10286. +
  10287. + case AR71XX_SOC_AR7241:
  10288. + case AR71XX_SOC_AR7242:
  10289. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0x1000ffff);
  10290. + break;
  10291. +
  10292. + default:
  10293. + BUG();
  10294. + }
  10295. +
  10296. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  10297. + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  10298. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  10299. +
  10300. + /* set pointer to first reg address */
  10301. + cal_data += 3;
  10302. + while (*cal_data != 0xffff) {
  10303. + u32 reg;
  10304. + reg = *cal_data++;
  10305. + val = *cal_data++;
  10306. + val |= (*cal_data++) << 16;
  10307. +
  10308. + __raw_writel(val, mem + reg);
  10309. + udelay(100);
  10310. + }
  10311. +
  10312. + pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  10313. + dev->vendor = val & 0xffff;
  10314. + dev->device = (val >> 16) & 0xffff;
  10315. +
  10316. + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  10317. + dev->revision = val & 0xff;
  10318. + dev->class = val >> 8; /* upper 3 bytes */
  10319. +
  10320. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  10321. + cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  10322. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  10323. +
  10324. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  10325. +
  10326. + iounmap(mem);
  10327. +}
  10328. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath9k_pci_fixup);
  10329. +
  10330. +void __init pci_enable_ath9k_fixup(unsigned slot, u16 *cal_data)
  10331. +{
  10332. + if (ath9k_num_fixups >= ARRAY_SIZE(ath9k_fixups))
  10333. + return;
  10334. +
  10335. + ath9k_fixups[ath9k_num_fixups].slot = slot;
  10336. + ath9k_fixups[ath9k_num_fixups].cal_data = cal_data;
  10337. + ath9k_num_fixups++;
  10338. +}
  10339. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/pci-ath9k-fixup.h linux-2.6.39/arch/mips/ar71xx/pci-ath9k-fixup.h
  10340. --- linux-2.6.39.orig/arch/mips/ar71xx/pci-ath9k-fixup.h 1970-01-01 01:00:00.000000000 +0100
  10341. +++ linux-2.6.39/arch/mips/ar71xx/pci-ath9k-fixup.h 2011-08-24 02:41:55.697990606 +0200
  10342. @@ -0,0 +1,6 @@
  10343. +#ifndef _PCI_ATH9K_FIXUP
  10344. +#define _PCI_ATH9K_FIXUP
  10345. +
  10346. +void pci_enable_ath9k_fixup(unsigned slot, u16 *cal_data) __init;
  10347. +
  10348. +#endif /* _PCI_ATH9K_FIXUP */
  10349. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/pci.c linux-2.6.39/arch/mips/ar71xx/pci.c
  10350. --- linux-2.6.39.orig/arch/mips/ar71xx/pci.c 1970-01-01 01:00:00.000000000 +0100
  10351. +++ linux-2.6.39/arch/mips/ar71xx/pci.c 2011-08-24 02:41:55.697990606 +0200
  10352. @@ -0,0 +1,97 @@
  10353. +/*
  10354. + * Atheros AR71xx PCI setup code
  10355. + *
  10356. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  10357. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10358. + *
  10359. + * Parts of this file are based on Atheros' 2.6.15 BSP
  10360. + *
  10361. + * This program is free software; you can redistribute it and/or modify it
  10362. + * under the terms of the GNU General Public License version 2 as published
  10363. + * by the Free Software Foundation.
  10364. + */
  10365. +
  10366. +#include <linux/kernel.h>
  10367. +
  10368. +#include <asm/traps.h>
  10369. +
  10370. +#include <asm/mach-ar71xx/ar71xx.h>
  10371. +#include <asm/mach-ar71xx/pci.h>
  10372. +
  10373. +unsigned ar71xx_pci_nr_irqs __initdata;
  10374. +struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  10375. +
  10376. +int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  10377. +
  10378. +static int ar71xx_be_handler(struct pt_regs *regs, int is_fixup)
  10379. +{
  10380. + int err = 0;
  10381. +
  10382. + err = ar71xx_pci_be_handler(is_fixup);
  10383. +
  10384. + return (is_fixup && !err) ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
  10385. +}
  10386. +
  10387. +int pcibios_plat_dev_init(struct pci_dev *dev)
  10388. +{
  10389. + if (ar71xx_pci_plat_dev_init)
  10390. + return ar71xx_pci_plat_dev_init(dev);
  10391. +
  10392. + return 0;
  10393. +}
  10394. +
  10395. +int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  10396. +{
  10397. + int ret = 0;
  10398. +
  10399. + switch (ar71xx_soc) {
  10400. + case AR71XX_SOC_AR7130:
  10401. + case AR71XX_SOC_AR7141:
  10402. + case AR71XX_SOC_AR7161:
  10403. + ret = ar71xx_pcibios_map_irq(dev, slot, pin);
  10404. + break;
  10405. +
  10406. + case AR71XX_SOC_AR7240:
  10407. + case AR71XX_SOC_AR7241:
  10408. + case AR71XX_SOC_AR7242:
  10409. + case AR71XX_SOC_AR9342:
  10410. + case AR71XX_SOC_AR9344:
  10411. + ret = ar724x_pcibios_map_irq(dev, slot, pin);
  10412. + break;
  10413. +
  10414. + default:
  10415. + break;
  10416. + }
  10417. +
  10418. + return ret;
  10419. +}
  10420. +
  10421. +int __init ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map)
  10422. +{
  10423. + int ret = 0;
  10424. +
  10425. + switch (ar71xx_soc) {
  10426. + case AR71XX_SOC_AR7130:
  10427. + case AR71XX_SOC_AR7141:
  10428. + case AR71XX_SOC_AR7161:
  10429. + board_be_handler = ar71xx_be_handler;
  10430. + ret = ar71xx_pcibios_init();
  10431. + break;
  10432. +
  10433. + case AR71XX_SOC_AR7240:
  10434. + case AR71XX_SOC_AR7241:
  10435. + case AR71XX_SOC_AR7242:
  10436. + case AR71XX_SOC_AR9342:
  10437. + case AR71XX_SOC_AR9344:
  10438. + ret = ar724x_pcibios_init();
  10439. + break;
  10440. +
  10441. + default:
  10442. + return 0;
  10443. + }
  10444. +
  10445. + ar71xx_pci_nr_irqs = nr_irqs;
  10446. + ar71xx_pci_irq_map = map;
  10447. +
  10448. + return ret;
  10449. +}
  10450. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/prom.c linux-2.6.39/arch/mips/ar71xx/prom.c
  10451. --- linux-2.6.39.orig/arch/mips/ar71xx/prom.c 1970-01-01 01:00:00.000000000 +0100
  10452. +++ linux-2.6.39/arch/mips/ar71xx/prom.c 2011-08-24 02:41:55.737990425 +0200
  10453. @@ -0,0 +1,189 @@
  10454. +/*
  10455. + * Atheros AR71xx SoC specific prom routines
  10456. + *
  10457. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  10458. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10459. + *
  10460. + * This program is free software; you can redistribute it and/or modify it
  10461. + * under the terms of the GNU General Public License version 2 as published
  10462. + * by the Free Software Foundation.
  10463. + */
  10464. +
  10465. +#include <linux/kernel.h>
  10466. +#include <linux/init.h>
  10467. +#include <linux/io.h>
  10468. +#include <linux/string.h>
  10469. +
  10470. +#include <asm/bootinfo.h>
  10471. +#include <asm/addrspace.h>
  10472. +#include <asm/fw/myloader/myloader.h>
  10473. +
  10474. +#include <asm/mach-ar71xx/ar71xx.h>
  10475. +
  10476. +static inline int is_valid_ram_addr(void *addr)
  10477. +{
  10478. + if (((u32) addr > KSEG0) &&
  10479. + ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
  10480. + return 1;
  10481. +
  10482. + if (((u32) addr > KSEG1) &&
  10483. + ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
  10484. + return 1;
  10485. +
  10486. + return 0;
  10487. +}
  10488. +
  10489. +static void __init ar71xx_prom_append_cmdline(const char *name,
  10490. + const char *value)
  10491. +{
  10492. + char buf[COMMAND_LINE_SIZE];
  10493. +
  10494. + snprintf(buf, sizeof(buf), " %s=%s", name, value);
  10495. + strlcat(arcs_cmdline, buf, sizeof(arcs_cmdline));
  10496. +}
  10497. +
  10498. +static const char * __init ar71xx_prom_find_env(char **envp, const char *name)
  10499. +{
  10500. + const char *ret = NULL;
  10501. + int len;
  10502. + char **p;
  10503. +
  10504. + if (!is_valid_ram_addr(envp))
  10505. + return NULL;
  10506. +
  10507. + len = strlen(name);
  10508. + for (p = envp; is_valid_ram_addr(*p); p++) {
  10509. + if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') {
  10510. + ret = *p + len + 1;
  10511. + break;
  10512. + }
  10513. +
  10514. + /* RedBoot env comes in pointer pairs - key, value */
  10515. + if (strncmp(name, *p, len) == 0 && (*p)[len] == 0)
  10516. + if (is_valid_ram_addr(*(++p))) {
  10517. + ret = *p;
  10518. + break;
  10519. + }
  10520. + }
  10521. +
  10522. + return ret;
  10523. +}
  10524. +
  10525. +static int __init ar71xx_prom_init_myloader(void)
  10526. +{
  10527. + struct myloader_info *mylo;
  10528. + char mac_buf[32];
  10529. + char *mac;
  10530. +
  10531. + mylo = myloader_get_info();
  10532. + if (!mylo)
  10533. + return 0;
  10534. +
  10535. + switch (mylo->did) {
  10536. + case DEVID_COMPEX_WP543:
  10537. + ar71xx_prom_append_cmdline("board", "WP543");
  10538. + break;
  10539. + default:
  10540. + printk(KERN_WARNING "prom: unknown device id: %x\n",
  10541. + mylo->did);
  10542. + return 0;
  10543. + }
  10544. +
  10545. + mac = mylo->macs[0];
  10546. + snprintf(mac_buf, sizeof(mac_buf), "%02x:%02x:%02x:%02x:%02x:%02x",
  10547. + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  10548. +
  10549. + ar71xx_prom_append_cmdline("ethaddr", mac_buf);
  10550. +
  10551. + return 1;
  10552. +}
  10553. +
  10554. +#ifdef CONFIG_IMAGE_CMDLINE_HACK
  10555. +extern char __image_cmdline[];
  10556. +
  10557. +static int __init ar71xx_use__image_cmdline(void)
  10558. +{
  10559. + char *p = __image_cmdline;
  10560. + int replace = 0;
  10561. +
  10562. + if (*p == '-') {
  10563. + replace = 1;
  10564. + p++;
  10565. + }
  10566. +
  10567. + if (*p == '\0')
  10568. + return 0;
  10569. +
  10570. + if (replace) {
  10571. + strlcpy(arcs_cmdline, p, sizeof(arcs_cmdline));
  10572. + } else {
  10573. + strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
  10574. + strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
  10575. + }
  10576. +
  10577. + return 1;
  10578. +}
  10579. +#else
  10580. +static inline int ar71xx_use__image_cmdline(void) { return 0; }
  10581. +#endif
  10582. +
  10583. +static __init void ar71xx_prom_init_cmdline(int argc, char **argv)
  10584. +{
  10585. + int i;
  10586. +
  10587. + if (ar71xx_use__image_cmdline())
  10588. + return;
  10589. +
  10590. + if (!is_valid_ram_addr(argv))
  10591. + return;
  10592. +
  10593. + for (i = 0; i < argc; i++)
  10594. + if (is_valid_ram_addr(argv[i])) {
  10595. + strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
  10596. + strlcat(arcs_cmdline, argv[i], sizeof(arcs_cmdline));
  10597. + }
  10598. +}
  10599. +
  10600. +void __init prom_init(void)
  10601. +{
  10602. + const char *env;
  10603. + char **envp;
  10604. +
  10605. + printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
  10606. + "fw_arg2=%08x, fw_arg3=%08x\n",
  10607. + (unsigned int)fw_arg0, (unsigned int)fw_arg1,
  10608. + (unsigned int)fw_arg2, (unsigned int)fw_arg3);
  10609. +
  10610. +
  10611. + if (ar71xx_prom_init_myloader())
  10612. + return;
  10613. +
  10614. + ar71xx_prom_init_cmdline(fw_arg0, (char **)fw_arg1);
  10615. +
  10616. + envp = (char **)fw_arg2;
  10617. + if (!strstr(arcs_cmdline, "ethaddr=")) {
  10618. + env = ar71xx_prom_find_env(envp, "ethaddr");
  10619. + if (env)
  10620. + ar71xx_prom_append_cmdline("ethaddr", env);
  10621. + }
  10622. +
  10623. + if (!strstr(arcs_cmdline, "board=")) {
  10624. + env = ar71xx_prom_find_env(envp, "board");
  10625. + if (env) {
  10626. + /* Workaround for buggy bootloaders */
  10627. + if (strcmp(env, "RouterStation") == 0 ||
  10628. + strcmp(env, "Ubiquiti AR71xx-based board") == 0)
  10629. + env = "UBNT-RS";
  10630. +
  10631. + if (strcmp(env, "RouterStation PRO") == 0)
  10632. + env = "UBNT-RSPRO";
  10633. +
  10634. + ar71xx_prom_append_cmdline("board", env);
  10635. + }
  10636. + }
  10637. +}
  10638. +
  10639. +void __init prom_free_prom_memory(void)
  10640. +{
  10641. + /* We do not have to prom memory to free */
  10642. +}
  10643. diff -Nur linux-2.6.39.orig/arch/mips/ar71xx/setup.c linux-2.6.39/arch/mips/ar71xx/setup.c
  10644. --- linux-2.6.39.orig/arch/mips/ar71xx/setup.c 1970-01-01 01:00:00.000000000 +0100
  10645. +++ linux-2.6.39/arch/mips/ar71xx/setup.c 2011-08-24 02:41:55.737990425 +0200
  10646. @@ -0,0 +1,446 @@
  10647. +/*
  10648. + * Atheros AR71xx SoC specific setup
  10649. + *
  10650. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  10651. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  10652. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10653. + *
  10654. + * Parts of this file are based on Atheros 2.6.15 BSP
  10655. + * Parts of this file are based on Atheros 2.6.31 BSP
  10656. + *
  10657. + * This program is free software; you can redistribute it and/or modify it
  10658. + * under the terms of the GNU General Public License version 2 as published
  10659. + * by the Free Software Foundation.
  10660. + */
  10661. +
  10662. +#include <linux/kernel.h>
  10663. +#include <linux/init.h>
  10664. +#include <linux/bootmem.h>
  10665. +
  10666. +#include <asm/bootinfo.h>
  10667. +#include <asm/time.h> /* for mips_hpt_frequency */
  10668. +#include <asm/reboot.h> /* for _machine_{restart,halt} */
  10669. +#include <asm/mips_machine.h>
  10670. +
  10671. +#include <asm/mach-ar71xx/ar71xx.h>
  10672. +
  10673. +#include "machtype.h"
  10674. +#include "devices.h"
  10675. +
  10676. +#define AR71XX_SYS_TYPE_LEN 64
  10677. +
  10678. +u32 ar71xx_cpu_freq;
  10679. +EXPORT_SYMBOL_GPL(ar71xx_cpu_freq);
  10680. +
  10681. +u32 ar71xx_ahb_freq;
  10682. +EXPORT_SYMBOL_GPL(ar71xx_ahb_freq);
  10683. +
  10684. +u32 ar71xx_ddr_freq;
  10685. +EXPORT_SYMBOL_GPL(ar71xx_ddr_freq);
  10686. +
  10687. +u32 ar71xx_ref_freq;
  10688. +EXPORT_SYMBOL_GPL(ar71xx_ref_freq);
  10689. +
  10690. +enum ar71xx_soc_type ar71xx_soc;
  10691. +EXPORT_SYMBOL_GPL(ar71xx_soc);
  10692. +
  10693. +u32 ar71xx_soc_rev;
  10694. +EXPORT_SYMBOL_GPL(ar71xx_soc_rev);
  10695. +
  10696. +static char ar71xx_sys_type[AR71XX_SYS_TYPE_LEN];
  10697. +
  10698. +static void ar71xx_restart(char *command)
  10699. +{
  10700. + ar71xx_device_stop(RESET_MODULE_FULL_CHIP);
  10701. + for (;;)
  10702. + if (cpu_wait)
  10703. + cpu_wait();
  10704. +}
  10705. +
  10706. +static void ar71xx_halt(void)
  10707. +{
  10708. + while (1)
  10709. + cpu_wait();
  10710. +}
  10711. +
  10712. +static void __init ar71xx_detect_mem_size(void)
  10713. +{
  10714. + unsigned long size;
  10715. +
  10716. + for (size = AR71XX_MEM_SIZE_MIN; size < AR71XX_MEM_SIZE_MAX;
  10717. + size <<= 1) {
  10718. + if (!memcmp(ar71xx_detect_mem_size,
  10719. + ar71xx_detect_mem_size + size, 1024))
  10720. + break;
  10721. + }
  10722. +
  10723. + add_memory_region(0, size, BOOT_MEM_RAM);
  10724. +}
  10725. +
  10726. +static void __init ar71xx_detect_sys_type(void)
  10727. +{
  10728. + char *chip = "????";
  10729. + u32 id;
  10730. + u32 major;
  10731. + u32 minor;
  10732. + u32 rev = 0;
  10733. +
  10734. + id = ar71xx_reset_rr(AR71XX_RESET_REG_REV_ID);
  10735. + major = id & REV_ID_MAJOR_MASK;
  10736. +
  10737. + switch (major) {
  10738. + case REV_ID_MAJOR_AR71XX:
  10739. + minor = id & AR71XX_REV_ID_MINOR_MASK;
  10740. + rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  10741. + rev &= AR71XX_REV_ID_REVISION_MASK;
  10742. + switch (minor) {
  10743. + case AR71XX_REV_ID_MINOR_AR7130:
  10744. + ar71xx_soc = AR71XX_SOC_AR7130;
  10745. + chip = "7130";
  10746. + break;
  10747. +
  10748. + case AR71XX_REV_ID_MINOR_AR7141:
  10749. + ar71xx_soc = AR71XX_SOC_AR7141;
  10750. + chip = "7141";
  10751. + break;
  10752. +
  10753. + case AR71XX_REV_ID_MINOR_AR7161:
  10754. + ar71xx_soc = AR71XX_SOC_AR7161;
  10755. + chip = "7161";
  10756. + break;
  10757. + }
  10758. + break;
  10759. +
  10760. + case REV_ID_MAJOR_AR7240:
  10761. + ar71xx_soc = AR71XX_SOC_AR7240;
  10762. + chip = "7240";
  10763. + rev = id & AR724X_REV_ID_REVISION_MASK;
  10764. + break;
  10765. +
  10766. + case REV_ID_MAJOR_AR7241:
  10767. + ar71xx_soc = AR71XX_SOC_AR7241;
  10768. + chip = "7241";
  10769. + rev = id & AR724X_REV_ID_REVISION_MASK;
  10770. + break;
  10771. +
  10772. + case REV_ID_MAJOR_AR7242:
  10773. + ar71xx_soc = AR71XX_SOC_AR7242;
  10774. + chip = "7242";
  10775. + rev = id & AR724X_REV_ID_REVISION_MASK;
  10776. + break;
  10777. +
  10778. + case REV_ID_MAJOR_AR913X:
  10779. + minor = id & AR91XX_REV_ID_MINOR_MASK;
  10780. + rev = id >> AR91XX_REV_ID_REVISION_SHIFT;
  10781. + rev &= AR91XX_REV_ID_REVISION_MASK;
  10782. + switch (minor) {
  10783. + case AR91XX_REV_ID_MINOR_AR9130:
  10784. + ar71xx_soc = AR71XX_SOC_AR9130;
  10785. + chip = "9130";
  10786. + break;
  10787. +
  10788. + case AR91XX_REV_ID_MINOR_AR9132:
  10789. + ar71xx_soc = AR71XX_SOC_AR9132;
  10790. + chip = "9132";
  10791. + break;
  10792. + }
  10793. + break;
  10794. +
  10795. + case REV_ID_MAJOR_AR9330:
  10796. + ar71xx_soc = AR71XX_SOC_AR9330;
  10797. + chip = "9330";
  10798. + rev = id & AR933X_REV_ID_REVISION_MASK;
  10799. + break;
  10800. +
  10801. + case REV_ID_MAJOR_AR9331:
  10802. + ar71xx_soc = AR71XX_SOC_AR9331;
  10803. + chip = "9331";
  10804. + rev = id & AR933X_REV_ID_REVISION_MASK;
  10805. + break;
  10806. +
  10807. + case REV_ID_MAJOR_AR9342:
  10808. + ar71xx_soc = AR71XX_SOC_AR9342;
  10809. + chip = "9342";
  10810. + rev = id & AR934X_REV_ID_REVISION_MASK;
  10811. + break;
  10812. +
  10813. + case REV_ID_MAJOR_AR9344:
  10814. + ar71xx_soc = AR71XX_SOC_AR9344;
  10815. + chip = "9344";
  10816. + rev = id & AR934X_REV_ID_REVISION_MASK;
  10817. + break;
  10818. +
  10819. + default:
  10820. + panic("ar71xx: unknown chip id:0x%08x\n", id);
  10821. + }
  10822. +
  10823. + ar71xx_soc_rev = rev;
  10824. +
  10825. + sprintf(ar71xx_sys_type, "Atheros AR%s rev %u", chip, rev);
  10826. + pr_info("SoC: %s\n", ar71xx_sys_type);
  10827. +}
  10828. +
  10829. +static void __init ar934x_detect_sys_frequency(void)
  10830. +{
  10831. + u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv;
  10832. +
  10833. + if (ar71xx_reset_rr(AR934X_RESET_REG_BOOTSTRAP) & AR934X_REF_CLK_40)
  10834. + ar71xx_ref_freq = 40 * 1000 * 1000;
  10835. + else
  10836. + ar71xx_ref_freq = 25 * 1000 * 1000;
  10837. +
  10838. + clk_ctrl = ar71xx_pll_rr(AR934X_PLL_REG_DDR_CTRL_CLOCK);
  10839. +
  10840. + pll = ar71xx_pll_rr(AR934X_PLL_REG_CPU_CONFIG);
  10841. + out_div = AR934X_CPU_PLL_CFG_OUTDIV_GET(pll);
  10842. + ref_div = AR934X_CPU_PLL_CFG_REFDIV_GET(pll);
  10843. + nint = AR934X_CPU_PLL_CFG_NINT_GET(pll);
  10844. + frac = AR934X_CPU_PLL_CFG_NFRAC_GET(pll);
  10845. + postdiv = AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_GET(clk_ctrl);
  10846. + ar71xx_cpu_freq = ((nint * ar71xx_ref_freq / ref_div) >> out_div) /
  10847. + (postdiv + 1);
  10848. +
  10849. + out_div = AR934X_DDR_PLL_CFG_OUTDIV_GET(pll);
  10850. + ref_div = AR934X_DDR_PLL_CFG_REFDIV_GET(pll);
  10851. + nint = AR934X_DDR_PLL_CFG_NINT_GET(pll);
  10852. + frac = AR934X_DDR_PLL_CFG_NFRAC_GET(pll);
  10853. + postdiv = AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_GET(clk_ctrl);
  10854. + ar71xx_ddr_freq = ((nint * ar71xx_ref_freq / ref_div) >> out_div) /
  10855. + (postdiv + 1);
  10856. +
  10857. + postdiv = AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_GET(clk_ctrl);
  10858. +
  10859. + if (AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_GET(clk_ctrl)) {
  10860. + ar71xx_ahb_freq = ar71xx_ddr_freq / (postdiv + 1);
  10861. + } else {
  10862. + ar71xx_ahb_freq = ar71xx_cpu_freq / (postdiv + 1);
  10863. + }
  10864. +
  10865. +}
  10866. +
  10867. +static void __init ar91xx_detect_sys_frequency(void)
  10868. +{
  10869. + u32 pll;
  10870. + u32 freq;
  10871. + u32 div;
  10872. +
  10873. + ar71xx_ref_freq = 5 * 1000 * 1000;
  10874. +
  10875. + pll = ar71xx_pll_rr(AR91XX_PLL_REG_CPU_CONFIG);
  10876. +
  10877. + div = ((pll >> AR91XX_PLL_DIV_SHIFT) & AR91XX_PLL_DIV_MASK);
  10878. + freq = div * ar71xx_ref_freq;
  10879. +
  10880. + ar71xx_cpu_freq = freq;
  10881. +
  10882. + div = ((pll >> AR91XX_DDR_DIV_SHIFT) & AR91XX_DDR_DIV_MASK) + 1;
  10883. + ar71xx_ddr_freq = freq / div;
  10884. +
  10885. + div = (((pll >> AR91XX_AHB_DIV_SHIFT) & AR91XX_AHB_DIV_MASK) + 1) * 2;
  10886. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  10887. +}
  10888. +
  10889. +static void __init ar71xx_detect_sys_frequency(void)
  10890. +{
  10891. + u32 pll;
  10892. + u32 freq;
  10893. + u32 div;
  10894. +
  10895. + ar71xx_ref_freq = 40 * 1000 * 1000;
  10896. +
  10897. + pll = ar71xx_pll_rr(AR71XX_PLL_REG_CPU_CONFIG);
  10898. +
  10899. + div = ((pll >> AR71XX_PLL_DIV_SHIFT) & AR71XX_PLL_DIV_MASK) + 1;
  10900. + freq = div * ar71xx_ref_freq;
  10901. +
  10902. + div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1;
  10903. + ar71xx_cpu_freq = freq / div;
  10904. +
  10905. + div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1;
  10906. + ar71xx_ddr_freq = freq / div;
  10907. +
  10908. + div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  10909. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  10910. +}
  10911. +
  10912. +static void __init ar724x_detect_sys_frequency(void)
  10913. +{
  10914. + u32 pll;
  10915. + u32 freq;
  10916. + u32 div;
  10917. +
  10918. + ar71xx_ref_freq = 5 * 1000 * 1000;
  10919. +
  10920. + pll = ar71xx_pll_rr(AR724X_PLL_REG_CPU_CONFIG);
  10921. +
  10922. + div = ((pll >> AR724X_PLL_DIV_SHIFT) & AR724X_PLL_DIV_MASK);
  10923. + freq = div * ar71xx_ref_freq;
  10924. +
  10925. + div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK);
  10926. + freq *= div;
  10927. +
  10928. + ar71xx_cpu_freq = freq;
  10929. +
  10930. + div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  10931. + ar71xx_ddr_freq = freq / div;
  10932. +
  10933. + div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  10934. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  10935. +}
  10936. +
  10937. +static void __init ar933x_detect_sys_frequency(void)
  10938. +{
  10939. + u32 clock_ctrl;
  10940. + u32 cpu_config;
  10941. + u32 freq;
  10942. + u32 t;
  10943. +
  10944. + t = ar71xx_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  10945. + if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  10946. + ar71xx_ref_freq = (40 * 1000 * 1000);
  10947. + else
  10948. + ar71xx_ref_freq = (25 * 1000 * 1000);
  10949. +
  10950. + clock_ctrl = ar71xx_pll_rr(AR933X_PLL_CLOCK_CTRL_REG);
  10951. + if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
  10952. + ar71xx_cpu_freq = ar71xx_ref_freq;
  10953. + ar71xx_ahb_freq = ar71xx_ref_freq;
  10954. + ar71xx_ddr_freq = ar71xx_ref_freq;
  10955. + } else {
  10956. + cpu_config = ar71xx_pll_rr(AR933X_PLL_CPU_CONFIG_REG);
  10957. +
  10958. + t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  10959. + AR933X_PLL_CPU_CONFIG_REFDIV_MASK;
  10960. + freq = ar71xx_ref_freq / t;
  10961. +
  10962. + t = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) &
  10963. + AR933X_PLL_CPU_CONFIG_NINT_MASK;
  10964. + freq *= t;
  10965. +
  10966. + t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  10967. + AR933X_PLL_CPU_CONFIG_OUTDIV_MASK;
  10968. + if (t == 0)
  10969. + t = 1;
  10970. +
  10971. + freq >>= t;
  10972. +
  10973. + t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) &
  10974. + AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1;
  10975. + ar71xx_cpu_freq = freq / t;
  10976. +
  10977. + t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) &
  10978. + AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1;
  10979. + ar71xx_ddr_freq = freq / t;
  10980. +
  10981. + t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) &
  10982. + AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
  10983. + ar71xx_ahb_freq = freq / t;
  10984. + }
  10985. +}
  10986. +
  10987. +static void __init detect_sys_frequency(void)
  10988. +{
  10989. + switch (ar71xx_soc) {
  10990. + case AR71XX_SOC_AR7130:
  10991. + case AR71XX_SOC_AR7141:
  10992. + case AR71XX_SOC_AR7161:
  10993. + ar71xx_detect_sys_frequency();
  10994. + break;
  10995. +
  10996. + case AR71XX_SOC_AR7240:
  10997. + case AR71XX_SOC_AR7241:
  10998. + case AR71XX_SOC_AR7242:
  10999. + ar724x_detect_sys_frequency();
  11000. + break;
  11001. +
  11002. + case AR71XX_SOC_AR9130:
  11003. + case AR71XX_SOC_AR9132:
  11004. + ar91xx_detect_sys_frequency();
  11005. + break;
  11006. +
  11007. + case AR71XX_SOC_AR9330:
  11008. + case AR71XX_SOC_AR9331:
  11009. + ar933x_detect_sys_frequency();
  11010. + break;
  11011. +
  11012. + case AR71XX_SOC_AR9341:
  11013. + case AR71XX_SOC_AR9342:
  11014. + case AR71XX_SOC_AR9344:
  11015. + ar934x_detect_sys_frequency();
  11016. + break;
  11017. + default:
  11018. + BUG();
  11019. + }
  11020. +}
  11021. +
  11022. +const char *get_system_type(void)
  11023. +{
  11024. + return ar71xx_sys_type;
  11025. +}
  11026. +
  11027. +unsigned int __cpuinit get_c0_compare_irq(void)
  11028. +{
  11029. + return CP0_LEGACY_COMPARE_IRQ;
  11030. +}
  11031. +
  11032. +void __init plat_mem_setup(void)
  11033. +{
  11034. + set_io_port_base(KSEG1);
  11035. +
  11036. + ar71xx_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  11037. + AR71XX_DDR_CTRL_SIZE);
  11038. +
  11039. + ar71xx_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  11040. + AR71XX_PLL_SIZE);
  11041. +
  11042. + ar71xx_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  11043. + AR71XX_RESET_SIZE);
  11044. +
  11045. + ar71xx_gpio_base = ioremap_nocache(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
  11046. +
  11047. + ar71xx_usb_ctrl_base = ioremap_nocache(AR71XX_USB_CTRL_BASE,
  11048. + AR71XX_USB_CTRL_SIZE);
  11049. +
  11050. + ar71xx_detect_mem_size();
  11051. + ar71xx_detect_sys_type();
  11052. + detect_sys_frequency();
  11053. +
  11054. + pr_info("Clocks: CPU:%u.%03uMHz, DDR:%u.%03uMHz, AHB:%u.%03uMHz, "
  11055. + "Ref:%u.%03uMHz",
  11056. + ar71xx_cpu_freq / 1000000, (ar71xx_cpu_freq / 1000) % 1000,
  11057. + ar71xx_ddr_freq / 1000000, (ar71xx_ddr_freq / 1000) % 1000,
  11058. + ar71xx_ahb_freq / 1000000, (ar71xx_ahb_freq / 1000) % 1000,
  11059. + ar71xx_ref_freq / 1000000, (ar71xx_ref_freq / 1000) % 1000);
  11060. +
  11061. + _machine_restart = ar71xx_restart;
  11062. + _machine_halt = ar71xx_halt;
  11063. + pm_power_off = ar71xx_halt;
  11064. +}
  11065. +
  11066. +void __init plat_time_init(void)
  11067. +{
  11068. + mips_hpt_frequency = ar71xx_cpu_freq / 2;
  11069. +}
  11070. +
  11071. +__setup("board=", mips_machtype_setup);
  11072. +
  11073. +static int __init ar71xx_machine_setup(void)
  11074. +{
  11075. + ar71xx_gpio_init();
  11076. +
  11077. + ar71xx_add_device_uart();
  11078. + ar71xx_add_device_wdt();
  11079. +
  11080. + mips_machine_setup();
  11081. + return 0;
  11082. +}
  11083. +
  11084. +arch_initcall(ar71xx_machine_setup);
  11085. +
  11086. +static void __init ar71xx_generic_init(void)
  11087. +{
  11088. + /* Nothing to do */
  11089. +}
  11090. +
  11091. +MIPS_MACHINE(AR71XX_MACH_GENERIC, "Generic", "Generic AR71xx board",
  11092. + ar71xx_generic_init);
  11093. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/checksum.h linux-2.6.39/arch/mips/include/asm/checksum.h
  11094. --- linux-2.6.39.orig/arch/mips/include/asm/checksum.h 2011-05-19 06:06:34.000000000 +0200
  11095. +++ linux-2.6.39/arch/mips/include/asm/checksum.h 2011-08-24 05:53:21.109231561 +0200
  11096. @@ -12,6 +12,7 @@
  11097. #define _ASM_CHECKSUM_H
  11098. #include <linux/in6.h>
  11099. +#include <linux/unaligned/packed_struct.h>
  11100. #include <asm/uaccess.h>
  11101. @@ -104,26 +105,30 @@
  11102. const unsigned int *stop = word + ihl;
  11103. unsigned int csum;
  11104. int carry;
  11105. + unsigned int w;
  11106. - csum = word[0];
  11107. - csum += word[1];
  11108. - carry = (csum < word[1]);
  11109. + csum = __get_unaligned_cpu32(word++);
  11110. +
  11111. + w = __get_unaligned_cpu32(word++);
  11112. + csum += w;
  11113. + carry = (csum < w);
  11114. csum += carry;
  11115. - csum += word[2];
  11116. - carry = (csum < word[2]);
  11117. + w = __get_unaligned_cpu32(word++);
  11118. + csum += w;
  11119. + carry = (csum < w);
  11120. csum += carry;
  11121. - csum += word[3];
  11122. - carry = (csum < word[3]);
  11123. + w = __get_unaligned_cpu32(word++);
  11124. + csum += w;
  11125. + carry = (csum < w);
  11126. csum += carry;
  11127. - word += 4;
  11128. do {
  11129. - csum += *word;
  11130. - carry = (csum < *word);
  11131. + w = __get_unaligned_cpu32(word++);
  11132. + csum += w;
  11133. + carry = (csum < w);
  11134. csum += carry;
  11135. - word++;
  11136. } while (word != stop);
  11137. return csum_fold(csum);
  11138. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/fw/myloader/myloader.h linux-2.6.39/arch/mips/include/asm/fw/myloader/myloader.h
  11139. --- linux-2.6.39.orig/arch/mips/include/asm/fw/myloader/myloader.h 1970-01-01 01:00:00.000000000 +0100
  11140. +++ linux-2.6.39/arch/mips/include/asm/fw/myloader/myloader.h 2011-04-27 12:19:21.887662064 +0200
  11141. @@ -0,0 +1,34 @@
  11142. +/*
  11143. + * Compex's MyLoader specific definitions
  11144. + *
  11145. + * Copyright (C) 2006-2008 Gabor Juhos <juhosg@openwrt.org>
  11146. + *
  11147. + * This program is free software; you can redistribute it and/or modify it
  11148. + * under the terms of the GNU General Public License version 2 as published
  11149. + * by the Free Software Foundation.
  11150. + *
  11151. + */
  11152. +
  11153. +#ifndef _ASM_MIPS_FW_MYLOADER_H
  11154. +#define _ASM_MIPS_FW_MYLOADER_H
  11155. +
  11156. +#include <linux/myloader.h>
  11157. +
  11158. +struct myloader_info {
  11159. + uint32_t vid;
  11160. + uint32_t did;
  11161. + uint32_t svid;
  11162. + uint32_t sdid;
  11163. + uint8_t macs[MYLO_ETHADDR_COUNT][6];
  11164. +};
  11165. +
  11166. +#ifdef CONFIG_MYLOADER
  11167. +extern struct myloader_info *myloader_get_info(void) __init;
  11168. +#else
  11169. +static inline struct myloader_info *myloader_get_info(void)
  11170. +{
  11171. + return NULL;
  11172. +}
  11173. +#endif /* CONFIG_MYLOADER */
  11174. +
  11175. +#endif /* _ASM_MIPS_FW_MYLOADER_H */
  11176. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar71xx.h
  11177. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h 1970-01-01 01:00:00.000000000 +0100
  11178. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar71xx.h 2011-08-06 09:32:36.758018150 +0200
  11179. @@ -0,0 +1,769 @@
  11180. +/*
  11181. + * Atheros AR71xx SoC specific definitions
  11182. + *
  11183. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  11184. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  11185. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  11186. + *
  11187. + * Parts of this file are based on Atheros 2.6.15 BSP
  11188. + * Parts of this file are based on Atheros 2.6.31 BSP
  11189. + *
  11190. + * This program is free software; you can redistribute it and/or modify it
  11191. + * under the terms of the GNU General Public License version 2 as published
  11192. + * by the Free Software Foundation.
  11193. + */
  11194. +
  11195. +#ifndef __ASM_MACH_AR71XX_H
  11196. +#define __ASM_MACH_AR71XX_H
  11197. +
  11198. +#include <linux/types.h>
  11199. +#include <linux/init.h>
  11200. +#include <linux/io.h>
  11201. +#include <linux/bitops.h>
  11202. +
  11203. +#ifndef __ASSEMBLER__
  11204. +
  11205. +#define AR71XX_PCI_MEM_BASE 0x10000000
  11206. +#define AR71XX_PCI_MEM_SIZE 0x08000000
  11207. +#define AR71XX_APB_BASE 0x18000000
  11208. +#define AR71XX_GE0_BASE 0x19000000
  11209. +#define AR71XX_GE0_SIZE 0x01000000
  11210. +#define AR71XX_GE1_BASE 0x1a000000
  11211. +#define AR71XX_GE1_SIZE 0x01000000
  11212. +#define AR71XX_EHCI_BASE 0x1b000000
  11213. +#define AR71XX_EHCI_SIZE 0x01000000
  11214. +#define AR71XX_OHCI_BASE 0x1c000000
  11215. +#define AR71XX_OHCI_SIZE 0x01000000
  11216. +#define AR7240_OHCI_BASE 0x1b000000
  11217. +#define AR7240_OHCI_SIZE 0x01000000
  11218. +#define AR71XX_SPI_BASE 0x1f000000
  11219. +#define AR71XX_SPI_SIZE 0x01000000
  11220. +
  11221. +#define AR71XX_DDR_CTRL_BASE (AR71XX_APB_BASE + 0x00000000)
  11222. +#define AR71XX_DDR_CTRL_SIZE 0x10000
  11223. +#define AR71XX_CPU_BASE (AR71XX_APB_BASE + 0x00010000)
  11224. +#define AR71XX_UART_BASE (AR71XX_APB_BASE + 0x00020000)
  11225. +#define AR71XX_UART_SIZE 0x10000
  11226. +#define AR71XX_USB_CTRL_BASE (AR71XX_APB_BASE + 0x00030000)
  11227. +#define AR71XX_USB_CTRL_SIZE 0x10000
  11228. +#define AR71XX_GPIO_BASE (AR71XX_APB_BASE + 0x00040000)
  11229. +#define AR71XX_GPIO_SIZE 0x10000
  11230. +#define AR71XX_PLL_BASE (AR71XX_APB_BASE + 0x00050000)
  11231. +#define AR71XX_PLL_SIZE 0x10000
  11232. +#define AR71XX_RESET_BASE (AR71XX_APB_BASE + 0x00060000)
  11233. +#define AR71XX_RESET_SIZE 0x10000
  11234. +#define AR71XX_MII_BASE (AR71XX_APB_BASE + 0x00070000)
  11235. +#define AR71XX_MII_SIZE 0x10000
  11236. +#define AR71XX_SLIC_BASE (AR71XX_APB_BASE + 0x00090000)
  11237. +#define AR71XX_SLIC_SIZE 0x10000
  11238. +#define AR71XX_DMA_BASE (AR71XX_APB_BASE + 0x000A0000)
  11239. +#define AR71XX_DMA_SIZE 0x10000
  11240. +#define AR71XX_STEREO_BASE (AR71XX_APB_BASE + 0x000B0000)
  11241. +#define AR71XX_STEREO_SIZE 0x10000
  11242. +
  11243. +#define AR724X_PCI_CRP_BASE (AR71XX_APB_BASE + 0x000C0000)
  11244. +#define AR724X_PCI_CRP_SIZE 0x100
  11245. +
  11246. +#define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000F0000)
  11247. +#define AR724X_PCI_CTRL_SIZE 0x100
  11248. +
  11249. +#define AR91XX_WMAC_BASE (AR71XX_APB_BASE + 0x000C0000)
  11250. +#define AR91XX_WMAC_SIZE 0x30000
  11251. +
  11252. +#define AR933X_UART_BASE (AR71XX_APB_BASE + 0x00020000)
  11253. +#define AR933X_UART_SIZE 0x14
  11254. +#define AR933X_WMAC_BASE (AR71XX_APB_BASE + 0x00100000)
  11255. +#define AR933X_WMAC_SIZE 0x20000
  11256. +
  11257. +#define AR934X_WMAC_BASE (AR71XX_APB_BASE + 0x00100000)
  11258. +#define AR934X_WMAC_SIZE 0x20000
  11259. +
  11260. +#define AR71XX_MEM_SIZE_MIN 0x0200000
  11261. +#define AR71XX_MEM_SIZE_MAX 0x10000000
  11262. +
  11263. +#define AR71XX_CPU_IRQ_BASE 0
  11264. +#define AR71XX_MISC_IRQ_BASE 8
  11265. +#define AR71XX_MISC_IRQ_COUNT 32
  11266. +#define AR71XX_GPIO_IRQ_BASE 40
  11267. +#define AR71XX_GPIO_IRQ_COUNT 32
  11268. +#define AR71XX_PCI_IRQ_BASE 72
  11269. +#define AR71XX_PCI_IRQ_COUNT 8
  11270. +
  11271. +#define AR71XX_CPU_IRQ_IP2 (AR71XX_CPU_IRQ_BASE + 2)
  11272. +#define AR71XX_CPU_IRQ_USB (AR71XX_CPU_IRQ_BASE + 3)
  11273. +#define AR71XX_CPU_IRQ_GE0 (AR71XX_CPU_IRQ_BASE + 4)
  11274. +#define AR71XX_CPU_IRQ_GE1 (AR71XX_CPU_IRQ_BASE + 5)
  11275. +#define AR71XX_CPU_IRQ_MISC (AR71XX_CPU_IRQ_BASE + 6)
  11276. +#define AR71XX_CPU_IRQ_TIMER (AR71XX_CPU_IRQ_BASE + 7)
  11277. +
  11278. +#define AR71XX_MISC_IRQ_TIMER (AR71XX_MISC_IRQ_BASE + 0)
  11279. +#define AR71XX_MISC_IRQ_ERROR (AR71XX_MISC_IRQ_BASE + 1)
  11280. +#define AR71XX_MISC_IRQ_GPIO (AR71XX_MISC_IRQ_BASE + 2)
  11281. +#define AR71XX_MISC_IRQ_UART (AR71XX_MISC_IRQ_BASE + 3)
  11282. +#define AR71XX_MISC_IRQ_WDOG (AR71XX_MISC_IRQ_BASE + 4)
  11283. +#define AR71XX_MISC_IRQ_PERFC (AR71XX_MISC_IRQ_BASE + 5)
  11284. +#define AR71XX_MISC_IRQ_OHCI (AR71XX_MISC_IRQ_BASE + 6)
  11285. +#define AR71XX_MISC_IRQ_DMA (AR71XX_MISC_IRQ_BASE + 7)
  11286. +#define AR71XX_MISC_IRQ_TIMER2 (AR71XX_MISC_IRQ_BASE + 8)
  11287. +#define AR71XX_MISC_IRQ_TIMER3 (AR71XX_MISC_IRQ_BASE + 9)
  11288. +#define AR71XX_MISC_IRQ_TIMER4 (AR71XX_MISC_IRQ_BASE + 10)
  11289. +#define AR71XX_MISC_IRQ_DDR_PERF (AR71XX_MISC_IRQ_BASE + 11)
  11290. +#define AR71XX_MISC_IRQ_ENET_LINK (AR71XX_MISC_IRQ_BASE + 12)
  11291. +
  11292. +#define AR71XX_GPIO_IRQ(_x) (AR71XX_GPIO_IRQ_BASE + (_x))
  11293. +
  11294. +#define AR71XX_PCI_IRQ_DEV0 (AR71XX_PCI_IRQ_BASE + 0)
  11295. +#define AR71XX_PCI_IRQ_DEV1 (AR71XX_PCI_IRQ_BASE + 1)
  11296. +#define AR71XX_PCI_IRQ_DEV2 (AR71XX_PCI_IRQ_BASE + 2)
  11297. +#define AR71XX_PCI_IRQ_CORE (AR71XX_PCI_IRQ_BASE + 4)
  11298. +
  11299. +extern u32 ar71xx_ahb_freq;
  11300. +extern u32 ar71xx_cpu_freq;
  11301. +extern u32 ar71xx_ddr_freq;
  11302. +extern u32 ar71xx_ref_freq;
  11303. +
  11304. +enum ar71xx_soc_type {
  11305. + AR71XX_SOC_UNKNOWN,
  11306. + AR71XX_SOC_AR7130,
  11307. + AR71XX_SOC_AR7141,
  11308. + AR71XX_SOC_AR7161,
  11309. + AR71XX_SOC_AR7240,
  11310. + AR71XX_SOC_AR7241,
  11311. + AR71XX_SOC_AR7242,
  11312. + AR71XX_SOC_AR9130,
  11313. + AR71XX_SOC_AR9132,
  11314. + AR71XX_SOC_AR9330,
  11315. + AR71XX_SOC_AR9331,
  11316. + AR71XX_SOC_AR9341,
  11317. + AR71XX_SOC_AR9342,
  11318. + AR71XX_SOC_AR9344,
  11319. +};
  11320. +extern u32 ar71xx_soc_rev;
  11321. +
  11322. +extern enum ar71xx_soc_type ar71xx_soc;
  11323. +
  11324. +/*
  11325. + * PLL block
  11326. + */
  11327. +#define AR71XX_PLL_REG_CPU_CONFIG 0x00
  11328. +#define AR71XX_PLL_REG_SEC_CONFIG 0x04
  11329. +#define AR71XX_PLL_REG_ETH0_INT_CLOCK 0x10
  11330. +#define AR71XX_PLL_REG_ETH1_INT_CLOCK 0x14
  11331. +
  11332. +#define AR71XX_PLL_DIV_SHIFT 3
  11333. +#define AR71XX_PLL_DIV_MASK 0x1f
  11334. +#define AR71XX_CPU_DIV_SHIFT 16
  11335. +#define AR71XX_CPU_DIV_MASK 0x3
  11336. +#define AR71XX_DDR_DIV_SHIFT 18
  11337. +#define AR71XX_DDR_DIV_MASK 0x3
  11338. +#define AR71XX_AHB_DIV_SHIFT 20
  11339. +#define AR71XX_AHB_DIV_MASK 0x7
  11340. +
  11341. +#define AR71XX_ETH0_PLL_SHIFT 17
  11342. +#define AR71XX_ETH1_PLL_SHIFT 19
  11343. +
  11344. +#define AR724X_PLL_REG_CPU_CONFIG 0x00
  11345. +#define AR724X_PLL_REG_PCIE_CONFIG 0x18
  11346. +
  11347. +#define AR724X_PLL_DIV_SHIFT 0
  11348. +#define AR724X_PLL_DIV_MASK 0x3ff
  11349. +#define AR724X_PLL_REF_DIV_SHIFT 10
  11350. +#define AR724X_PLL_REF_DIV_MASK 0xf
  11351. +#define AR724X_AHB_DIV_SHIFT 19
  11352. +#define AR724X_AHB_DIV_MASK 0x1
  11353. +#define AR724X_DDR_DIV_SHIFT 22
  11354. +#define AR724X_DDR_DIV_MASK 0x3
  11355. +
  11356. +#define AR7242_PLL_REG_ETH0_INT_CLOCK 0x2c
  11357. +
  11358. +#define AR91XX_PLL_REG_CPU_CONFIG 0x00
  11359. +#define AR91XX_PLL_REG_ETH_CONFIG 0x04
  11360. +#define AR91XX_PLL_REG_ETH0_INT_CLOCK 0x14
  11361. +#define AR91XX_PLL_REG_ETH1_INT_CLOCK 0x18
  11362. +
  11363. +#define AR91XX_PLL_DIV_SHIFT 0
  11364. +#define AR91XX_PLL_DIV_MASK 0x3ff
  11365. +#define AR91XX_DDR_DIV_SHIFT 22
  11366. +#define AR91XX_DDR_DIV_MASK 0x3
  11367. +#define AR91XX_AHB_DIV_SHIFT 19
  11368. +#define AR91XX_AHB_DIV_MASK 0x1
  11369. +
  11370. +#define AR91XX_ETH0_PLL_SHIFT 20
  11371. +#define AR91XX_ETH1_PLL_SHIFT 22
  11372. +
  11373. +#define AR933X_PLL_CPU_CONFIG_REG 0x00
  11374. +#define AR933X_PLL_CLOCK_CTRL_REG 0x08
  11375. +
  11376. +#define AR933X_PLL_CPU_CONFIG_NINT_SHIFT 10
  11377. +#define AR933X_PLL_CPU_CONFIG_NINT_MASK 0x3f
  11378. +#define AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT 16
  11379. +#define AR933X_PLL_CPU_CONFIG_REFDIV_MASK 0x1f
  11380. +#define AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT 23
  11381. +#define AR933X_PLL_CPU_CONFIG_OUTDIV_MASK 0x7
  11382. +
  11383. +#define AR933X_PLL_CLOCK_CTRL_BYPASS BIT(2)
  11384. +#define AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT 5
  11385. +#define AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK 0x3
  11386. +#define AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT 10
  11387. +#define AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK 0x3
  11388. +#define AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT 15
  11389. +#define AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK 0x7
  11390. +
  11391. +#define AR934X_PLL_REG_CPU_CONFIG 0x00
  11392. +#define AR934X_PLL_REG_DDR_CTRL_CLOCK 0x8
  11393. +
  11394. +#define AR934X_CPU_PLL_CFG_OUTDIV_MSB 21
  11395. +#define AR934X_CPU_PLL_CFG_OUTDIV_LSB 19
  11396. +#define AR934X_CPU_PLL_CFG_OUTDIV_MASK 0x00380000
  11397. +
  11398. +#define AR934X_CPU_PLL_CFG_OUTDIV_GET(x) \
  11399. + (((x) & AR934X_CPU_PLL_CFG_OUTDIV_MASK) >> \
  11400. + AR934X_CPU_PLL_CFG_OUTDIV_LSB)
  11401. +
  11402. +#define AR934X_DDR_PLL_CFG_OUTDIV_MSB 25
  11403. +#define AR934X_DDR_PLL_CFG_OUTDIV_LSB 23
  11404. +#define AR934X_DDR_PLL_CFG_OUTDIV_MASK 0x03800000
  11405. +
  11406. +#define AR934X_DDR_PLL_CFG_OUTDIV_GET(x) \
  11407. + (((x) & AR934X_DDR_PLL_CFG_OUTDIV_MASK) >> \
  11408. + AR934X_DDR_PLL_CFG_OUTDIV_LSB)
  11409. +
  11410. +#define AR934X_DDR_PLL_CFG_OUTDIV_SET(x) \
  11411. + (((x) << AR934X_DDR_PLL_CFG_OUTDIV_LSB) & \
  11412. + AR934X_DDR_PLL_CFG_OUTDIV_MASK)
  11413. +
  11414. +#define AR934X_CPU_PLL_CFG_REFDIV_MSB 16
  11415. +#define AR934X_CPU_PLL_CFG_REFDIV_LSB 12
  11416. +#define AR934X_CPU_PLL_CFG_REFDIV_MASK 0x0001f000
  11417. +
  11418. +#define AR934X_CPU_PLL_CFG_REFDIV_GET(x) \
  11419. + (((x) & AR934X_CPU_PLL_CFG_REFDIV_MASK) >> \
  11420. + AR934X_CPU_PLL_CFG_REFDIV_LSB)
  11421. +
  11422. +#define AR934X_CPU_PLL_CFG_REFDIV_SET(x) \
  11423. + (((x) << AR934X_CPU_PLL_CFG_REFDIV_LSB) & \
  11424. + AR934X_CPU_PLL_CFG_REFDIV_MASK)
  11425. +
  11426. +#define AR934X_CPU_PLL_CFG_REFDIV_RESET 2
  11427. +
  11428. +#define AR934X_CPU_PLL_CFG_NINT_MSB 11
  11429. +#define AR934X_CPU_PLL_CFG_NINT_LSB 6
  11430. +#define AR934X_CPU_PLL_CFG_NINT_MASK 0x00000fc0
  11431. +
  11432. +#define AR934X_CPU_PLL_CFG_NINT_GET(x) \
  11433. + (((x) & AR934X_CPU_PLL_CFG_NINT_MASK) >> \
  11434. + AR934X_CPU_PLL_CFG_NINT_LSB)
  11435. +
  11436. +#define AR934X_CPU_PLL_CFG_NINT_SET(x) \
  11437. + (((x) << AR934X_CPU_PLL_CFG_NINT_LSB) & \
  11438. + AR934X_CPU_PLL_CFG_NINT_MASK)
  11439. +
  11440. +#define AR934X_CPU_PLL_CFG_NINT_RESET 20
  11441. +
  11442. +#define AR934X_CPU_PLL_CFG_NFRAC_MSB 5
  11443. +#define AR934X_CPU_PLL_CFG_NFRAC_LSB 0
  11444. +#define AR934X_CPU_PLL_CFG_NFRAC_MASK 0x0000003f
  11445. +
  11446. +#define AR934X_CPU_PLL_CFG_NFRAC_GET(x) \
  11447. + (((x) & AR934X_CPU_PLL_CFG_NFRAC_MASK) >> \
  11448. + AR934X_CPU_PLL_CFG_NFRAC_LSB)
  11449. +
  11450. +#define AR934X_CPU_PLL_CFG_NFRAC_SET(x) \
  11451. + (((x) << AR934X_CPU_PLL_CFG_NFRAC_LSB) & \
  11452. + AR934X_CPU_PLL_CFG_NFRAC_MASK)
  11453. +
  11454. +#define AR934X_DDR_PLL_CFG_REFDIV_MSB 20
  11455. +#define AR934X_DDR_PLL_CFG_REFDIV_LSB 16
  11456. +#define AR934X_DDR_PLL_CFG_REFDIV_MASK 0x001f0000
  11457. +
  11458. +#define AR934X_DDR_PLL_CFG_REFDIV_GET(x) \
  11459. + (((x) & AR934X_DDR_PLL_CFG_REFDIV_MASK) >> \
  11460. + AR934X_DDR_PLL_CFG_REFDIV_LSB)
  11461. +
  11462. +#define AR934X_DDR_PLL_CFG_REFDIV_SET(x) \
  11463. + (((x) << AR934X_DDR_PLL_CFG_REFDIV_LSB) & \
  11464. + AR934X_DDR_PLL_CFG_REFDIV_MASK)
  11465. +
  11466. +#define AR934X_DDR_PLL_CFG_REFDIV_RESET 2
  11467. +
  11468. +#define AR934X_DDR_PLL_CFG_NINT_MSB 15
  11469. +#define AR934X_DDR_PLL_CFG_NINT_LSB 10
  11470. +#define AR934X_DDR_PLL_CFG_NINT_MASK 0x0000fc00
  11471. +
  11472. +#define AR934X_DDR_PLL_CFG_NINT_GET(x) \
  11473. + (((x) & AR934X_DDR_PLL_CFG_NINT_MASK) >> \
  11474. + AR934X_DDR_PLL_CFG_NINT_LSB)
  11475. +
  11476. +#define AR934X_DDR_PLL_CFG_NINT_SET(x) \
  11477. + (((x) << AR934X_DDR_PLL_CFG_NINT_LSB) & \
  11478. + AR934X_DDR_PLL_CFG_NINT_MASK)
  11479. +
  11480. +#define AR934X_DDR_PLL_CFG_NINT_RESET 20
  11481. +
  11482. +#define AR934X_DDR_PLL_CFG_NFRAC_MSB 9
  11483. +#define AR934X_DDR_PLL_CFG_NFRAC_LSB 0
  11484. +#define AR934X_DDR_PLL_CFG_NFRAC_MASK 0x000003ff
  11485. +
  11486. +#define AR934X_DDR_PLL_CFG_NFRAC_GET(x) \
  11487. + (((x) & AR934X_DDR_PLL_CFG_NFRAC_MASK) >> \
  11488. + AR934X_DDR_PLL_CFG_NFRAC_LSB)
  11489. +
  11490. +#define AR934X_DDR_PLL_CFG_NFRAC_SET(x) \
  11491. + (((x) << AR934X_DDR_PLL_CFG_NFRAC_LSB) & \
  11492. + AR934X_DDR_PLL_CFG_NFRAC_MASK)
  11493. +
  11494. +#define AR934X_DDR_PLL_CFG_NFRAC_RESET 512
  11495. +
  11496. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MSB 19
  11497. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_LSB 15
  11498. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK 0x000f8000
  11499. +
  11500. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_GET(x) \
  11501. + (((x) & AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK) >> \
  11502. + AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_LSB)
  11503. +
  11504. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_SET(x) \
  11505. + (((x) << AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_LSB) & \
  11506. + AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK)
  11507. +
  11508. +#define AR934X_CPU_DDR_CLK_CTRL_AHB_POST_DIV_RESET 0
  11509. +
  11510. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MSB 14
  11511. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_LSB 10
  11512. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK 0x00007c00
  11513. +
  11514. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_GET(x) \
  11515. + (((x) & AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK) >> \
  11516. + AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_LSB)
  11517. +
  11518. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_SET(x) \
  11519. + (((x) << AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_LSB) & \
  11520. + AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK)
  11521. +
  11522. +#define AR934X_CPU_DDR_CLK_CTRL_DDR_POST_DIV_RESET 0
  11523. +
  11524. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MSB 9
  11525. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_LSB 5
  11526. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK 0x000003e0
  11527. +
  11528. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_GET(x) \
  11529. + (((x) & AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK) >> \
  11530. + AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_LSB)
  11531. +
  11532. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_SET(x) \
  11533. + (((x) << AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_LSB) & \
  11534. + AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK)
  11535. +
  11536. +#define AR934X_CPU_DDR_CLK_CTRL_CPU_POST_DIV_RESET 0
  11537. +
  11538. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_MSB 24
  11539. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_LSB 24
  11540. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_MASK 0x01000000
  11541. +
  11542. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_GET(x) \
  11543. + (((x) & AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_MASK) >> \
  11544. + AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_LSB)
  11545. +
  11546. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_SET(x) \
  11547. + (((x) << AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_LSB) & \
  11548. + AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_MASK)
  11549. +
  11550. +#define AR934X_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL_RESET 1
  11551. +
  11552. +extern void __iomem *ar71xx_pll_base;
  11553. +
  11554. +static inline void ar71xx_pll_wr(unsigned reg, u32 val)
  11555. +{
  11556. + __raw_writel(val, ar71xx_pll_base + reg);
  11557. +}
  11558. +
  11559. +static inline u32 ar71xx_pll_rr(unsigned reg)
  11560. +{
  11561. + return __raw_readl(ar71xx_pll_base + reg);
  11562. +}
  11563. +
  11564. +/*
  11565. + * USB_CONFIG block
  11566. + */
  11567. +#define USB_CTRL_REG_FLADJ 0x00
  11568. +#define USB_CTRL_REG_CONFIG 0x04
  11569. +
  11570. +extern void __iomem *ar71xx_usb_ctrl_base;
  11571. +
  11572. +static inline void ar71xx_usb_ctrl_wr(unsigned reg, u32 val)
  11573. +{
  11574. + __raw_writel(val, ar71xx_usb_ctrl_base + reg);
  11575. +}
  11576. +
  11577. +static inline u32 ar71xx_usb_ctrl_rr(unsigned reg)
  11578. +{
  11579. + return __raw_readl(ar71xx_usb_ctrl_base + reg);
  11580. +}
  11581. +
  11582. +/*
  11583. + * GPIO block
  11584. + */
  11585. +#define GPIO_REG_OE 0x00
  11586. +#define GPIO_REG_IN 0x04
  11587. +#define GPIO_REG_OUT 0x08
  11588. +#define GPIO_REG_SET 0x0c
  11589. +#define GPIO_REG_CLEAR 0x10
  11590. +#define GPIO_REG_INT_MODE 0x14
  11591. +#define GPIO_REG_INT_TYPE 0x18
  11592. +#define GPIO_REG_INT_POLARITY 0x1c
  11593. +#define GPIO_REG_INT_PENDING 0x20
  11594. +#define GPIO_REG_INT_ENABLE 0x24
  11595. +#define GPIO_REG_FUNC 0x28
  11596. +
  11597. +#define AR71XX_GPIO_FUNC_STEREO_EN BIT(17)
  11598. +#define AR71XX_GPIO_FUNC_SLIC_EN BIT(16)
  11599. +#define AR71XX_GPIO_FUNC_SPI_CS2_EN BIT(13)
  11600. +#define AR71XX_GPIO_FUNC_SPI_CS1_EN BIT(12)
  11601. +#define AR71XX_GPIO_FUNC_UART_EN BIT(8)
  11602. +#define AR71XX_GPIO_FUNC_USB_OC_EN BIT(4)
  11603. +#define AR71XX_GPIO_FUNC_USB_CLK_EN BIT(0)
  11604. +
  11605. +#define AR71XX_GPIO_COUNT 16
  11606. +
  11607. +#define AR724X_GPIO_FUNC_GE0_MII_CLK_EN BIT(19)
  11608. +#define AR724X_GPIO_FUNC_SPI_EN BIT(18)
  11609. +#define AR724X_GPIO_FUNC_SPI_CS_EN2 BIT(14)
  11610. +#define AR724X_GPIO_FUNC_SPI_CS_EN1 BIT(13)
  11611. +#define AR724X_GPIO_FUNC_CLK_OBS5_EN BIT(12)
  11612. +#define AR724X_GPIO_FUNC_CLK_OBS4_EN BIT(11)
  11613. +#define AR724X_GPIO_FUNC_CLK_OBS3_EN BIT(10)
  11614. +#define AR724X_GPIO_FUNC_CLK_OBS2_EN BIT(9)
  11615. +#define AR724X_GPIO_FUNC_CLK_OBS1_EN BIT(8)
  11616. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN BIT(7)
  11617. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN BIT(6)
  11618. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN BIT(5)
  11619. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN BIT(4)
  11620. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN BIT(3)
  11621. +#define AR724X_GPIO_FUNC_UART_RTS_CTS_EN BIT(2)
  11622. +#define AR724X_GPIO_FUNC_UART_EN BIT(1)
  11623. +#define AR724X_GPIO_FUNC_JTAG_DISABLE BIT(0)
  11624. +
  11625. +#define AR724X_GPIO_COUNT 18
  11626. +
  11627. +#define AR91XX_GPIO_FUNC_WMAC_LED_EN BIT(22)
  11628. +#define AR91XX_GPIO_FUNC_EXP_PORT_CS_EN BIT(21)
  11629. +#define AR91XX_GPIO_FUNC_I2S_REFCLKEN BIT(20)
  11630. +#define AR91XX_GPIO_FUNC_I2S_MCKEN BIT(19)
  11631. +#define AR91XX_GPIO_FUNC_I2S1_EN BIT(18)
  11632. +#define AR91XX_GPIO_FUNC_I2S0_EN BIT(17)
  11633. +#define AR91XX_GPIO_FUNC_SLIC_EN BIT(16)
  11634. +#define AR91XX_GPIO_FUNC_UART_RTSCTS_EN BIT(9)
  11635. +#define AR91XX_GPIO_FUNC_UART_EN BIT(8)
  11636. +#define AR91XX_GPIO_FUNC_USB_CLK_EN BIT(4)
  11637. +
  11638. +#define AR91XX_GPIO_COUNT 22
  11639. +
  11640. +#define AR933X_GPIO_COUNT 30
  11641. +
  11642. +#define AR934X_GPIO_FUNC_SPI_CS_1_EN BIT(14)
  11643. +#define AR934X_GPIO_FUNC_SPI_CS_0_EN BIT(13)
  11644. +
  11645. +#define AR934X_GPIO_COUNT 32
  11646. +#define AR934X_GPIO_FUNC_DDR_DQOE_EN BIT(17)
  11647. +
  11648. +extern void __iomem *ar71xx_gpio_base;
  11649. +
  11650. +static inline void ar71xx_gpio_wr(unsigned reg, u32 value)
  11651. +{
  11652. + __raw_writel(value, ar71xx_gpio_base + reg);
  11653. +}
  11654. +
  11655. +static inline u32 ar71xx_gpio_rr(unsigned reg)
  11656. +{
  11657. + return __raw_readl(ar71xx_gpio_base + reg);
  11658. +}
  11659. +
  11660. +void ar71xx_gpio_init(void) __init;
  11661. +void ar71xx_gpio_function_enable(u32 mask);
  11662. +void ar71xx_gpio_function_disable(u32 mask);
  11663. +void ar71xx_gpio_function_setup(u32 set, u32 clear);
  11664. +
  11665. +/*
  11666. + * DDR_CTRL block
  11667. + */
  11668. +#define AR71XX_DDR_REG_PCI_WIN0 0x7c
  11669. +#define AR71XX_DDR_REG_PCI_WIN1 0x80
  11670. +#define AR71XX_DDR_REG_PCI_WIN2 0x84
  11671. +#define AR71XX_DDR_REG_PCI_WIN3 0x88
  11672. +#define AR71XX_DDR_REG_PCI_WIN4 0x8c
  11673. +#define AR71XX_DDR_REG_PCI_WIN5 0x90
  11674. +#define AR71XX_DDR_REG_PCI_WIN6 0x94
  11675. +#define AR71XX_DDR_REG_PCI_WIN7 0x98
  11676. +#define AR71XX_DDR_REG_FLUSH_GE0 0x9c
  11677. +#define AR71XX_DDR_REG_FLUSH_GE1 0xa0
  11678. +#define AR71XX_DDR_REG_FLUSH_USB 0xa4
  11679. +#define AR71XX_DDR_REG_FLUSH_PCI 0xa8
  11680. +
  11681. +#define AR724X_DDR_REG_FLUSH_GE0 0x7c
  11682. +#define AR724X_DDR_REG_FLUSH_GE1 0x80
  11683. +#define AR724X_DDR_REG_FLUSH_USB 0x84
  11684. +#define AR724X_DDR_REG_FLUSH_PCIE 0x88
  11685. +
  11686. +#define AR91XX_DDR_REG_FLUSH_GE0 0x7c
  11687. +#define AR91XX_DDR_REG_FLUSH_GE1 0x80
  11688. +#define AR91XX_DDR_REG_FLUSH_USB 0x84
  11689. +#define AR91XX_DDR_REG_FLUSH_WMAC 0x88
  11690. +
  11691. +#define AR933X_DDR_REG_FLUSH_GE0 0x7c
  11692. +#define AR933X_DDR_REG_FLUSH_GE1 0x80
  11693. +#define AR933X_DDR_REG_FLUSH_USB 0x84
  11694. +#define AR933X_DDR_REG_FLUSH_WMAC 0x88
  11695. +
  11696. +#define AR934X_DDR_REG_FLUSH_GE0 0x9c
  11697. +#define AR934X_DDR_REG_FLUSH_GE1 0xa0
  11698. +#define AR934X_DDR_REG_FLUSH_USB 0xa4
  11699. +#define AR934X_DDR_REG_FLUSH_PCIE 0xa8
  11700. +
  11701. +
  11702. +#define PCI_WIN0_OFFS 0x10000000
  11703. +#define PCI_WIN1_OFFS 0x11000000
  11704. +#define PCI_WIN2_OFFS 0x12000000
  11705. +#define PCI_WIN3_OFFS 0x13000000
  11706. +#define PCI_WIN4_OFFS 0x14000000
  11707. +#define PCI_WIN5_OFFS 0x15000000
  11708. +#define PCI_WIN6_OFFS 0x16000000
  11709. +#define PCI_WIN7_OFFS 0x07000000
  11710. +
  11711. +extern void __iomem *ar71xx_ddr_base;
  11712. +
  11713. +static inline void ar71xx_ddr_wr(unsigned reg, u32 val)
  11714. +{
  11715. + __raw_writel(val, ar71xx_ddr_base + reg);
  11716. +}
  11717. +
  11718. +static inline u32 ar71xx_ddr_rr(unsigned reg)
  11719. +{
  11720. + return __raw_readl(ar71xx_ddr_base + reg);
  11721. +}
  11722. +
  11723. +void ar71xx_ddr_flush(u32 reg);
  11724. +
  11725. +/*
  11726. + * PCI block
  11727. + */
  11728. +#define AR71XX_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + PCI_WIN7_OFFS + 0x10000)
  11729. +#define AR71XX_PCI_CFG_SIZE 0x100
  11730. +
  11731. +#define PCI_REG_CRP_AD_CBE 0x00
  11732. +#define PCI_REG_CRP_WRDATA 0x04
  11733. +#define PCI_REG_CRP_RDDATA 0x08
  11734. +#define PCI_REG_CFG_AD 0x0c
  11735. +#define PCI_REG_CFG_CBE 0x10
  11736. +#define PCI_REG_CFG_WRDATA 0x14
  11737. +#define PCI_REG_CFG_RDDATA 0x18
  11738. +#define PCI_REG_PCI_ERR 0x1c
  11739. +#define PCI_REG_PCI_ERR_ADDR 0x20
  11740. +#define PCI_REG_AHB_ERR 0x24
  11741. +#define PCI_REG_AHB_ERR_ADDR 0x28
  11742. +
  11743. +#define PCI_CRP_CMD_WRITE 0x00010000
  11744. +#define PCI_CRP_CMD_READ 0x00000000
  11745. +#define PCI_CFG_CMD_READ 0x0000000a
  11746. +#define PCI_CFG_CMD_WRITE 0x0000000b
  11747. +
  11748. +#define PCI_IDSEL_ADL_START 17
  11749. +
  11750. +#define AR724X_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + 0x4000000)
  11751. +#define AR724X_PCI_CFG_SIZE 0x1000
  11752. +
  11753. +#define AR724X_PCI_REG_APP 0x00
  11754. +#define AR724X_PCI_REG_RESET 0x18
  11755. +#define AR724X_PCI_REG_INT_STATUS 0x4c
  11756. +#define AR724X_PCI_REG_INT_MASK 0x50
  11757. +
  11758. +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
  11759. +#define AR724X_PCI_RESET_LINK_UP BIT(0)
  11760. +
  11761. +#define AR724X_PCI_INT_DEV0 BIT(14)
  11762. +
  11763. +/*
  11764. + * RESET block
  11765. + */
  11766. +#define AR71XX_RESET_REG_TIMER 0x00
  11767. +#define AR71XX_RESET_REG_TIMER_RELOAD 0x04
  11768. +#define AR71XX_RESET_REG_WDOG_CTRL 0x08
  11769. +#define AR71XX_RESET_REG_WDOG 0x0c
  11770. +#define AR71XX_RESET_REG_MISC_INT_STATUS 0x10
  11771. +#define AR71XX_RESET_REG_MISC_INT_ENABLE 0x14
  11772. +#define AR71XX_RESET_REG_PCI_INT_STATUS 0x18
  11773. +#define AR71XX_RESET_REG_PCI_INT_ENABLE 0x1c
  11774. +#define AR71XX_RESET_REG_GLOBAL_INT_STATUS 0x20
  11775. +#define AR71XX_RESET_REG_RESET_MODULE 0x24
  11776. +#define AR71XX_RESET_REG_PERFC_CTRL 0x2c
  11777. +#define AR71XX_RESET_REG_PERFC0 0x30
  11778. +#define AR71XX_RESET_REG_PERFC1 0x34
  11779. +#define AR71XX_RESET_REG_REV_ID 0x90
  11780. +
  11781. +#define AR91XX_RESET_REG_GLOBAL_INT_STATUS 0x18
  11782. +#define AR91XX_RESET_REG_RESET_MODULE 0x1c
  11783. +#define AR91XX_RESET_REG_PERF_CTRL 0x20
  11784. +#define AR91XX_RESET_REG_PERFC0 0x24
  11785. +#define AR91XX_RESET_REG_PERFC1 0x28
  11786. +
  11787. +#define AR724X_RESET_REG_RESET_MODULE 0x1c
  11788. +
  11789. +#define AR933X_RESET_REG_RESET_MODULE 0x1c
  11790. +#define AR933X_RESET_REG_BOOTSTRAP 0xac
  11791. +#define AR933X_BOOTSTRAP_EEPBUSY BIT(4)
  11792. +#define AR933X_BOOTSTRAP_REF_CLK_40 BIT(0)
  11793. +
  11794. +#define AR934X_RESET_REG_RESET_MODULE 0x1c
  11795. +#define AR934X_RESET_REG_BOOTSTRAP 0xb0
  11796. +/* 0 - 25MHz 1 - 40 MHz */
  11797. +#define AR934X_REF_CLK_40 (1 << 4)
  11798. +
  11799. +#define WDOG_CTRL_LAST_RESET BIT(31)
  11800. +#define WDOG_CTRL_ACTION_MASK 3
  11801. +#define WDOG_CTRL_ACTION_NONE 0 /* no action */
  11802. +#define WDOG_CTRL_ACTION_GPI 1 /* general purpose interrupt */
  11803. +#define WDOG_CTRL_ACTION_NMI 2 /* NMI */
  11804. +#define WDOG_CTRL_ACTION_FCR 3 /* full chip reset */
  11805. +
  11806. +#define MISC_INT_ENET_LINK BIT(12)
  11807. +#define MISC_INT_DDR_PERF BIT(11)
  11808. +#define MISC_INT_TIMER4 BIT(10)
  11809. +#define MISC_INT_TIMER3 BIT(9)
  11810. +#define MISC_INT_TIMER2 BIT(8)
  11811. +#define MISC_INT_DMA BIT(7)
  11812. +#define MISC_INT_OHCI BIT(6)
  11813. +#define MISC_INT_PERFC BIT(5)
  11814. +#define MISC_INT_WDOG BIT(4)
  11815. +#define MISC_INT_UART BIT(3)
  11816. +#define MISC_INT_GPIO BIT(2)
  11817. +#define MISC_INT_ERROR BIT(1)
  11818. +#define MISC_INT_TIMER BIT(0)
  11819. +
  11820. +#define PCI_INT_CORE BIT(4)
  11821. +#define PCI_INT_DEV2 BIT(2)
  11822. +#define PCI_INT_DEV1 BIT(1)
  11823. +#define PCI_INT_DEV0 BIT(0)
  11824. +
  11825. +#define RESET_MODULE_EXTERNAL BIT(28)
  11826. +#define RESET_MODULE_FULL_CHIP BIT(24)
  11827. +#define RESET_MODULE_AMBA2WMAC BIT(22)
  11828. +#define RESET_MODULE_CPU_NMI BIT(21)
  11829. +#define RESET_MODULE_CPU_COLD BIT(20)
  11830. +#define RESET_MODULE_DMA BIT(19)
  11831. +#define RESET_MODULE_SLIC BIT(18)
  11832. +#define RESET_MODULE_STEREO BIT(17)
  11833. +#define RESET_MODULE_DDR BIT(16)
  11834. +#define RESET_MODULE_GE1_MAC BIT(13)
  11835. +#define RESET_MODULE_GE1_PHY BIT(12)
  11836. +#define RESET_MODULE_USBSUS_OVERRIDE BIT(10)
  11837. +#define RESET_MODULE_GE0_MAC BIT(9)
  11838. +#define RESET_MODULE_GE0_PHY BIT(8)
  11839. +#define RESET_MODULE_USB_OHCI_DLL BIT(6)
  11840. +#define RESET_MODULE_USB_HOST BIT(5)
  11841. +#define RESET_MODULE_USB_PHY BIT(4)
  11842. +#define RESET_MODULE_USB_OHCI_DLL_7240 BIT(3)
  11843. +#define RESET_MODULE_PCI_BUS BIT(1)
  11844. +#define RESET_MODULE_PCI_CORE BIT(0)
  11845. +
  11846. +#define AR724X_RESET_GE1_MDIO BIT(23)
  11847. +#define AR724X_RESET_GE0_MDIO BIT(22)
  11848. +#define AR724X_RESET_PCIE_PHY_SERIAL BIT(10)
  11849. +#define AR724X_RESET_PCIE_PHY BIT(7)
  11850. +#define AR724X_RESET_PCIE BIT(6)
  11851. +#define AR724X_RESET_USB_HOST BIT(5)
  11852. +#define AR724X_RESET_USB_PHY BIT(4)
  11853. +#define AR724X_RESET_USBSUS_OVERRIDE BIT(3)
  11854. +
  11855. +#define AR933X_RESET_WMAC BIT(11)
  11856. +#define AR933X_RESET_GE1_MDIO BIT(23)
  11857. +#define AR933X_RESET_GE0_MDIO BIT(22)
  11858. +#define AR933X_RESET_GE1_MAC BIT(13)
  11859. +#define AR933X_RESET_GE0_MAC BIT(9)
  11860. +
  11861. +#define REV_ID_MAJOR_MASK 0xfff0
  11862. +#define REV_ID_MAJOR_AR71XX 0x00a0
  11863. +#define REV_ID_MAJOR_AR913X 0x00b0
  11864. +#define REV_ID_MAJOR_AR7240 0x00c0
  11865. +#define REV_ID_MAJOR_AR7241 0x0100
  11866. +#define REV_ID_MAJOR_AR7242 0x1100
  11867. +#define REV_ID_MAJOR_AR9330 0x0110
  11868. +#define REV_ID_MAJOR_AR9331 0x1110
  11869. +#define REV_ID_MAJOR_AR9341 0x0120
  11870. +#define REV_ID_MAJOR_AR9342 0x1120
  11871. +#define REV_ID_MAJOR_AR9344 0x2120
  11872. +
  11873. +#define AR71XX_REV_ID_MINOR_MASK 0x3
  11874. +#define AR71XX_REV_ID_MINOR_AR7130 0x0
  11875. +#define AR71XX_REV_ID_MINOR_AR7141 0x1
  11876. +#define AR71XX_REV_ID_MINOR_AR7161 0x2
  11877. +#define AR71XX_REV_ID_REVISION_MASK 0x3
  11878. +#define AR71XX_REV_ID_REVISION_SHIFT 2
  11879. +
  11880. +#define AR91XX_REV_ID_MINOR_MASK 0x3
  11881. +#define AR91XX_REV_ID_MINOR_AR9130 0x0
  11882. +#define AR91XX_REV_ID_MINOR_AR9132 0x1
  11883. +#define AR91XX_REV_ID_REVISION_MASK 0x3
  11884. +#define AR91XX_REV_ID_REVISION_SHIFT 2
  11885. +
  11886. +#define AR724X_REV_ID_REVISION_MASK 0x3
  11887. +
  11888. +#define AR933X_REV_ID_REVISION_MASK 0xf
  11889. +
  11890. +#define AR934X_REV_ID_REVISION_MASK 0xf
  11891. +
  11892. +extern void __iomem *ar71xx_reset_base;
  11893. +
  11894. +static inline void ar71xx_reset_wr(unsigned reg, u32 val)
  11895. +{
  11896. + __raw_writel(val, ar71xx_reset_base + reg);
  11897. +}
  11898. +
  11899. +static inline u32 ar71xx_reset_rr(unsigned reg)
  11900. +{
  11901. + return __raw_readl(ar71xx_reset_base + reg);
  11902. +}
  11903. +
  11904. +void ar71xx_device_stop(u32 mask);
  11905. +void ar71xx_device_start(u32 mask);
  11906. +int ar71xx_device_stopped(u32 mask);
  11907. +
  11908. +/*
  11909. + * SPI block
  11910. + */
  11911. +#define SPI_REG_FS 0x00 /* Function Select */
  11912. +#define SPI_REG_CTRL 0x04 /* SPI Control */
  11913. +#define SPI_REG_IOC 0x08 /* SPI I/O Control */
  11914. +#define SPI_REG_RDS 0x0c /* Read Data Shift */
  11915. +
  11916. +#define SPI_FS_GPIO BIT(0) /* Enable GPIO mode */
  11917. +
  11918. +#define SPI_CTRL_RD BIT(6) /* Remap Disable */
  11919. +#define SPI_CTRL_DIV_MASK 0x3f
  11920. +
  11921. +#define SPI_IOC_DO BIT(0) /* Data Out pin */
  11922. +#define SPI_IOC_CLK BIT(8) /* CLK pin */
  11923. +#define SPI_IOC_CS(n) BIT(16 + (n))
  11924. +#define SPI_IOC_CS0 SPI_IOC_CS(0)
  11925. +#define SPI_IOC_CS1 SPI_IOC_CS(1)
  11926. +#define SPI_IOC_CS2 SPI_IOC_CS(2)
  11927. +#define SPI_IOC_CS_ALL (SPI_IOC_CS0 | SPI_IOC_CS1 | SPI_IOC_CS2)
  11928. +
  11929. +void ar71xx_flash_acquire(void);
  11930. +void ar71xx_flash_release(void);
  11931. +
  11932. +/*
  11933. + * MII_CTRL block
  11934. + */
  11935. +#define MII_REG_MII0_CTRL 0x00
  11936. +#define MII_REG_MII1_CTRL 0x04
  11937. +
  11938. +#define MII0_CTRL_IF_GMII 0
  11939. +#define MII0_CTRL_IF_MII 1
  11940. +#define MII0_CTRL_IF_RGMII 2
  11941. +#define MII0_CTRL_IF_RMII 3
  11942. +
  11943. +#define MII1_CTRL_IF_RGMII 0
  11944. +#define MII1_CTRL_IF_RMII 1
  11945. +
  11946. +#endif /* __ASSEMBLER__ */
  11947. +
  11948. +#endif /* __ASM_MACH_AR71XX_H */
  11949. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h
  11950. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 1970-01-01 01:00:00.000000000 +0100
  11951. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 2011-04-27 12:19:21.867661560 +0200
  11952. @@ -0,0 +1,26 @@
  11953. +/*
  11954. + * AR91xx parallel flash driver platform data definitions
  11955. + *
  11956. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  11957. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  11958. + *
  11959. + * This program is free software; you can redistribute it and/or modify it
  11960. + * under the terms of the GNU General Public License version 2 as published
  11961. + * by the Free Software Foundation.
  11962. + */
  11963. +
  11964. +#ifndef __AR91XX_FLASH_H
  11965. +#define __AR91XX_FLASH_H
  11966. +
  11967. +struct mtd_partition;
  11968. +
  11969. +struct ar91xx_flash_platform_data {
  11970. + unsigned int width;
  11971. + u8 is_shared:1;
  11972. +#ifdef CONFIG_MTD_PARTITIONS
  11973. + unsigned int nr_parts;
  11974. + struct mtd_partition *parts;
  11975. +#endif
  11976. +};
  11977. +
  11978. +#endif /* __AR91XX_FLASH_H */
  11979. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar933x_uart.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar933x_uart.h
  11980. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar933x_uart.h 1970-01-01 01:00:00.000000000 +0100
  11981. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar933x_uart.h 2011-08-06 09:32:36.758018150 +0200
  11982. @@ -0,0 +1,67 @@
  11983. +/*
  11984. + * Atheros AR933X UART defines
  11985. + *
  11986. + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  11987. + *
  11988. + * This program is free software; you can redistribute it and/or modify it
  11989. + * under the terms of the GNU General Public License version 2 as published
  11990. + * by the Free Software Foundation.
  11991. + */
  11992. +
  11993. +#ifndef __AR933X_UART_H
  11994. +#define __AR933X_UART_H
  11995. +
  11996. +#define AR933X_UART_REGS_SIZE 20
  11997. +#define AR933X_UART_FIFO_SIZE 16
  11998. +
  11999. +#define AR933X_UART_DATA_REG 0x00
  12000. +#define AR933X_UART_CS_REG 0x04
  12001. +#define AR933X_UART_CLOCK_REG 0x08
  12002. +#define AR933X_UART_INT_REG 0x0c
  12003. +#define AR933X_UART_INT_EN_REG 0x10
  12004. +
  12005. +#define AR933X_UART_DATA_TX_RX_MASK 0xff
  12006. +#define AR933X_UART_DATA_RX_CSR BIT(8)
  12007. +#define AR933X_UART_DATA_TX_CSR BIT(9)
  12008. +
  12009. +#define AR933X_UART_CS_PARITY_S 0
  12010. +#define AR933X_UART_CS_PARITY_M 0x3
  12011. +#define AR933X_UART_CS_PARITY_NONE 0
  12012. +#define AR933X_UART_CS_PARITY_ODD 1
  12013. +#define AR933X_UART_CS_PARITY_EVEN 2
  12014. +#define AR933X_UART_CS_IF_MODE_S 2
  12015. +#define AR933X_UART_CS_IF_MODE_M 0x3
  12016. +#define AR933X_UART_CS_IF_MODE_NONE 0
  12017. +#define AR933X_UART_CS_IF_MODE_DTE 1
  12018. +#define AR933X_UART_CS_IF_MODE_DCE 2
  12019. +#define AR933X_UART_CS_FLOW_CTRL_S 4
  12020. +#define AR933X_UART_CS_FLOW_CTRL_M 0x3
  12021. +#define AR933X_UART_CS_DMA_EN BIT(6)
  12022. +#define AR933X_UART_CS_TX_READY_ORIDE BIT(7)
  12023. +#define AR933X_UART_CS_RX_READY_ORIDE BIT(8)
  12024. +#define AR933X_UART_CS_TX_READY BIT(9)
  12025. +#define AR933X_UART_CS_RX_BREAK BIT(10)
  12026. +#define AR933X_UART_CS_TX_BREAK BIT(11)
  12027. +#define AR933X_UART_CS_HOST_INT BIT(12)
  12028. +#define AR933X_UART_CS_HOST_INT_EN BIT(13)
  12029. +#define AR933X_UART_CS_TX_BUSY BIT(14)
  12030. +#define AR933X_UART_CS_RX_BUSY BIT(15)
  12031. +
  12032. +#define AR933X_UART_CLOCK_STEP_M 0xffff
  12033. +#define AR933X_UART_CLOCK_SCALE_M 0xfff
  12034. +#define AR933X_UART_CLOCK_SCALE_S 16
  12035. +#define AR933X_UART_CLOCK_STEP_M 0xffff
  12036. +
  12037. +#define AR933X_UART_INT_RX_VALID BIT(0)
  12038. +#define AR933X_UART_INT_TX_READY BIT(1)
  12039. +#define AR933X_UART_INT_RX_FRAMING_ERR BIT(2)
  12040. +#define AR933X_UART_INT_RX_OFLOW_ERR BIT(3)
  12041. +#define AR933X_UART_INT_TX_OFLOW_ERR BIT(4)
  12042. +#define AR933X_UART_INT_RX_PARITY_ERR BIT(5)
  12043. +#define AR933X_UART_INT_RX_BREAK_ON BIT(6)
  12044. +#define AR933X_UART_INT_RX_BREAK_OFF BIT(7)
  12045. +#define AR933X_UART_INT_RX_FULL BIT(8)
  12046. +#define AR933X_UART_INT_TX_EMPTY BIT(9)
  12047. +#define AR933X_UART_INT_ALLINTS 0x3ff
  12048. +
  12049. +#endif /* __AR933X_UART_H */
  12050. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar933x_uart_platform.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar933x_uart_platform.h
  12051. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/ar933x_uart_platform.h 1970-01-01 01:00:00.000000000 +0100
  12052. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/ar933x_uart_platform.h 2011-08-06 09:32:36.758018150 +0200
  12053. @@ -0,0 +1,18 @@
  12054. +/*
  12055. + * Platform data definition for Atheros AR933X UART
  12056. + *
  12057. + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  12058. + *
  12059. + * This program is free software; you can redistribute it and/or modify it
  12060. + * under the terms of the GNU General Public License version 2 as published
  12061. + * by the Free Software Foundation.
  12062. + */
  12063. +
  12064. +#ifndef _AR933X_UART_PLATFORM_H
  12065. +#define _AR933X_UART_PLATFORM_H
  12066. +
  12067. +struct ar933x_uart_platform_data {
  12068. + unsigned uartclk;
  12069. +};
  12070. +
  12071. +#endif /* _AR933X_UART_PLATFORM_H */
  12072. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h
  12073. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 1970-01-01 01:00:00.000000000 +0100
  12074. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 2011-04-27 12:19:21.877661867 +0200
  12075. @@ -0,0 +1,56 @@
  12076. +/*
  12077. + * Atheros AR71xx specific CPU feature overrides
  12078. + *
  12079. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  12080. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12081. + *
  12082. + * This file was derived from: include/asm-mips/cpu-features.h
  12083. + * Copyright (C) 2003, 2004 Ralf Baechle
  12084. + * Copyright (C) 2004 Maciej W. Rozycki
  12085. + *
  12086. + * This program is free software; you can redistribute it and/or modify it
  12087. + * under the terms of the GNU General Public License version 2 as published
  12088. + * by the Free Software Foundation.
  12089. + *
  12090. + */
  12091. +#ifndef __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  12092. +#define __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  12093. +
  12094. +#define cpu_has_tlb 1
  12095. +#define cpu_has_4kex 1
  12096. +#define cpu_has_3k_cache 0
  12097. +#define cpu_has_4k_cache 1
  12098. +#define cpu_has_tx39_cache 0
  12099. +#define cpu_has_sb1_cache 0
  12100. +#define cpu_has_fpu 0
  12101. +#define cpu_has_32fpr 0
  12102. +#define cpu_has_counter 1
  12103. +#define cpu_has_watch 1
  12104. +#define cpu_has_divec 1
  12105. +
  12106. +#define cpu_has_prefetch 1
  12107. +#define cpu_has_ejtag 1
  12108. +#define cpu_has_llsc 1
  12109. +
  12110. +#define cpu_has_mips16 1
  12111. +#define cpu_has_mdmx 0
  12112. +#define cpu_has_mips3d 0
  12113. +#define cpu_has_smartmips 0
  12114. +
  12115. +#define cpu_has_mips32r1 1
  12116. +#define cpu_has_mips32r2 1
  12117. +#define cpu_has_mips64r1 0
  12118. +#define cpu_has_mips64r2 0
  12119. +
  12120. +#define cpu_has_dsp 0
  12121. +#define cpu_has_mipsmt 0
  12122. +
  12123. +#define cpu_has_64bits 0
  12124. +#define cpu_has_64bit_zero_reg 0
  12125. +#define cpu_has_64bit_gp_regs 0
  12126. +#define cpu_has_64bit_addresses 0
  12127. +
  12128. +#define cpu_dcache_line_size() 32
  12129. +#define cpu_icache_line_size() 32
  12130. +
  12131. +#endif /* __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H */
  12132. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/gpio.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/gpio.h
  12133. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/gpio.h 1970-01-01 01:00:00.000000000 +0100
  12134. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/gpio.h 2011-04-27 12:19:21.877661867 +0200
  12135. @@ -0,0 +1,53 @@
  12136. +/*
  12137. + * Atheros AR71xx GPIO API definitions
  12138. + *
  12139. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  12140. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12141. + *
  12142. + * This program is free software; you can redistribute it and/or modify it
  12143. + * under the terms of the GNU General Public License version 2 as published
  12144. + * by the Free Software Foundation.
  12145. + *
  12146. + */
  12147. +
  12148. +#ifndef __ASM_MACH_AR71XX_GPIO_H
  12149. +#define __ASM_MACH_AR71XX_GPIO_H
  12150. +
  12151. +#define ARCH_NR_GPIOS 64
  12152. +#include <asm-generic/gpio.h>
  12153. +
  12154. +#include <asm/mach-ar71xx/ar71xx.h>
  12155. +
  12156. +extern unsigned long ar71xx_gpio_count;
  12157. +extern void __ar71xx_gpio_set_value(unsigned gpio, int value);
  12158. +extern int __ar71xx_gpio_get_value(unsigned gpio);
  12159. +
  12160. +static inline int gpio_to_irq(unsigned gpio)
  12161. +{
  12162. + return AR71XX_GPIO_IRQ(gpio);
  12163. +}
  12164. +
  12165. +static inline int irq_to_gpio(unsigned irq)
  12166. +{
  12167. + return irq - AR71XX_GPIO_IRQ_BASE;
  12168. +}
  12169. +
  12170. +static inline int gpio_get_value(unsigned gpio)
  12171. +{
  12172. + if (gpio < ar71xx_gpio_count)
  12173. + return __ar71xx_gpio_get_value(gpio);
  12174. +
  12175. + return __gpio_get_value(gpio);
  12176. +}
  12177. +
  12178. +static inline void gpio_set_value(unsigned gpio, int value)
  12179. +{
  12180. + if (gpio < ar71xx_gpio_count)
  12181. + __ar71xx_gpio_set_value(gpio, value);
  12182. + else
  12183. + __gpio_set_value(gpio, value);
  12184. +}
  12185. +
  12186. +#define gpio_cansleep __gpio_cansleep
  12187. +
  12188. +#endif /* __ASM_MACH_AR71XX_GPIO_H */
  12189. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/irq.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/irq.h
  12190. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/irq.h 1970-01-01 01:00:00.000000000 +0100
  12191. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/irq.h 2011-04-27 12:19:21.877661867 +0200
  12192. @@ -0,0 +1,17 @@
  12193. +/*
  12194. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  12195. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12196. + *
  12197. + * This program is free software; you can redistribute it and/or modify it
  12198. + * under the terms of the GNU General Public License version 2 as published
  12199. + * by the Free Software Foundation.
  12200. + */
  12201. +#ifndef __ASM_MACH_AR71XX_IRQ_H
  12202. +#define __ASM_MACH_AR71XX_IRQ_H
  12203. +
  12204. +#define MIPS_CPU_IRQ_BASE 0
  12205. +#define NR_IRQS 80
  12206. +
  12207. +#include_next <irq.h>
  12208. +
  12209. +#endif /* __ASM_MACH_AR71XX_IRQ_H */
  12210. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h
  12211. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 1970-01-01 01:00:00.000000000 +0100
  12212. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 2011-04-27 12:19:21.877661867 +0200
  12213. @@ -0,0 +1,32 @@
  12214. +/*
  12215. + * Atheros AR71xx specific kernel entry setup
  12216. + *
  12217. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  12218. + *
  12219. + * This program is free software; you can redistribute it and/or modify it
  12220. + * under the terms of the GNU General Public License version 2 as published
  12221. + * by the Free Software Foundation.
  12222. + *
  12223. + */
  12224. +#ifndef __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  12225. +#define __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  12226. +
  12227. + /*
  12228. + * Some bootloaders set the 'Kseg0 coherency algorithm' to
  12229. + * 'Cacheable, noncoherent, write-through, no write allocate'
  12230. + * and this cause performance issues. Let's go and change it to
  12231. + * 'Cacheable, noncoherent, write-back, write allocate'
  12232. + */
  12233. + .macro kernel_entry_setup
  12234. + mfc0 t0, CP0_CONFIG
  12235. + li t1, ~CONF_CM_CMASK
  12236. + and t0, t1
  12237. + ori t0, CONF_CM_CACHABLE_NONCOHERENT
  12238. + mtc0 t0, CP0_CONFIG
  12239. + nop
  12240. + .endm
  12241. +
  12242. + .macro smp_slave_setup
  12243. + .endm
  12244. +
  12245. +#endif /* __ASM_MACH_AR71XX_KERNEL_ENTRY_H */
  12246. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/mach-rb750.h
  12247. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 1970-01-01 01:00:00.000000000 +0100
  12248. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 2011-04-27 12:19:21.877661867 +0200
  12249. @@ -0,0 +1,66 @@
  12250. +/*
  12251. + * MikroTik RouterBOARD 750 definitions
  12252. + *
  12253. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  12254. + *
  12255. + * This program is free software; you can redistribute it and/or modify it
  12256. + * under the terms of the GNU General Public License version 2 as published
  12257. + * by the Free Software Foundation.
  12258. + */
  12259. +#ifndef _MACH_RB750_H
  12260. +#define _MACH_RB750_H
  12261. +
  12262. +#include <linux/bitops.h>
  12263. +
  12264. +#define RB750_GPIO_LVC573_LE 0 /* Latch enable on LVC573 */
  12265. +#define RB750_GPIO_NAND_IO0 1 /* NAND I/O 0 */
  12266. +#define RB750_GPIO_NAND_IO1 2 /* NAND I/O 1 */
  12267. +#define RB750_GPIO_NAND_IO2 3 /* NAND I/O 2 */
  12268. +#define RB750_GPIO_NAND_IO3 4 /* NAND I/O 3 */
  12269. +#define RB750_GPIO_NAND_IO4 5 /* NAND I/O 4 */
  12270. +#define RB750_GPIO_NAND_IO5 6 /* NAND I/O 5 */
  12271. +#define RB750_GPIO_NAND_IO6 7 /* NAND I/O 6 */
  12272. +#define RB750_GPIO_NAND_IO7 8 /* NAND I/O 7 */
  12273. +#define RB750_GPIO_NAND_NCE 11 /* NAND Chip Enable (active low) */
  12274. +#define RB750_GPIO_NAND_RDY 12 /* NAND Ready */
  12275. +#define RB750_GPIO_NAND_CLE 14 /* NAND Command Latch Enable */
  12276. +#define RB750_GPIO_NAND_ALE 15 /* NAND Address Latch Enable */
  12277. +#define RB750_GPIO_NAND_NRE 16 /* NAND Read Enable (active low) */
  12278. +#define RB750_GPIO_NAND_NWE 17 /* NAND Write Enable (active low) */
  12279. +
  12280. +#define RB750_GPIO_BTN_RESET 1
  12281. +#define RB750_GPIO_SPI_CS0 2
  12282. +#define RB750_GPIO_LED_ACT 12
  12283. +#define RB750_GPIO_LED_PORT1 13
  12284. +#define RB750_GPIO_LED_PORT2 14
  12285. +#define RB750_GPIO_LED_PORT3 15
  12286. +#define RB750_GPIO_LED_PORT4 16
  12287. +#define RB750_GPIO_LED_PORT5 17
  12288. +
  12289. +#define RB750_LED_ACT BIT(RB750_GPIO_LED_ACT)
  12290. +#define RB750_LED_PORT1 BIT(RB750_GPIO_LED_PORT1)
  12291. +#define RB750_LED_PORT2 BIT(RB750_GPIO_LED_PORT2)
  12292. +#define RB750_LED_PORT3 BIT(RB750_GPIO_LED_PORT3)
  12293. +#define RB750_LED_PORT4 BIT(RB750_GPIO_LED_PORT4)
  12294. +#define RB750_LED_PORT5 BIT(RB750_GPIO_LED_PORT5)
  12295. +
  12296. +#define RB750_LVC573_LE BIT(RB750_GPIO_LVC573_LE)
  12297. +
  12298. +#define RB750_LED_BITS (RB750_LED_PORT1 | RB750_LED_PORT2 | RB750_LED_PORT3 | \
  12299. + RB750_LED_PORT4 | RB750_LED_PORT5 | RB750_LED_ACT)
  12300. +
  12301. +struct rb750_led_data {
  12302. + char *name;
  12303. + char *default_trigger;
  12304. + u32 mask;
  12305. + int active_low;
  12306. +};
  12307. +
  12308. +struct rb750_led_platform_data {
  12309. + int num_leds;
  12310. + struct rb750_led_data *leds;
  12311. +};
  12312. +
  12313. +int rb750_latch_change(u32 mask_clr, u32 mask_set);
  12314. +
  12315. +#endif /* _MACH_RB750_H */
  12316. \ No newline at end of file
  12317. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/mangle-port.h
  12318. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h 1970-01-01 01:00:00.000000000 +0100
  12319. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/mangle-port.h 2011-04-27 12:19:21.877661867 +0200
  12320. @@ -0,0 +1,45 @@
  12321. +/*
  12322. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  12323. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12324. + *
  12325. + * This file was derived from: inlude/asm-mips/mach-generic/mangle-port.h
  12326. + * Copyright (C) 2003, 2004 Ralf Baechle
  12327. + *
  12328. + * This program is free software; you can redistribute it and/or modify it
  12329. + * under the terms of the GNU General Public License version 2 as published
  12330. + * by the Free Software Foundation.
  12331. + */
  12332. +
  12333. +#ifndef __ASM_MACH_AR71XX_MANGLE_PORT_H
  12334. +#define __ASM_MACH_AR71XX_MANGLE_PORT_H
  12335. +
  12336. +#define __swizzle_addr_b(port) ((port) ^ 3)
  12337. +#define __swizzle_addr_w(port) ((port) ^ 2)
  12338. +#define __swizzle_addr_l(port) (port)
  12339. +#define __swizzle_addr_q(port) (port)
  12340. +
  12341. +#if defined(CONFIG_SWAP_IO_SPACE)
  12342. +
  12343. +# define ioswabb(a, x) (x)
  12344. +# define __mem_ioswabb(a, x) (x)
  12345. +# define ioswabw(a, x) le16_to_cpu(x)
  12346. +# define __mem_ioswabw(a, x) (x)
  12347. +# define ioswabl(a, x) le32_to_cpu(x)
  12348. +# define __mem_ioswabl(a, x) (x)
  12349. +# define ioswabq(a, x) le64_to_cpu(x)
  12350. +# define __mem_ioswabq(a, x) (x)
  12351. +
  12352. +#else
  12353. +
  12354. +# define ioswabb(a, x) (x)
  12355. +# define __mem_ioswabb(a, x) (x)
  12356. +# define ioswabw(a, x) (x)
  12357. +# define __mem_ioswabw(a, x) cpu_to_le16(x)
  12358. +# define ioswabl(a, x) (x)
  12359. +# define __mem_ioswabl(a, x) cpu_to_le32(x)
  12360. +# define ioswabq(a, x) (x)
  12361. +# define __mem_ioswabq(a, x) cpu_to_le64(x)
  12362. +
  12363. +#endif
  12364. +
  12365. +#endif /* __ASM_MACH_AR71XX_MANGLE_PORT_H */
  12366. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/pci.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/pci.h
  12367. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/pci.h 1970-01-01 01:00:00.000000000 +0100
  12368. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/pci.h 2011-04-27 12:19:21.877661867 +0200
  12369. @@ -0,0 +1,46 @@
  12370. +/*
  12371. + * Atheros AR71xx SoC specific PCI definitions
  12372. + *
  12373. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  12374. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12375. + *
  12376. + * This program is free software; you can redistribute it and/or modify it
  12377. + * under the terms of the GNU General Public License version 2 as published
  12378. + * by the Free Software Foundation.
  12379. + */
  12380. +
  12381. +#ifndef __ASM_MACH_AR71XX_PCI_H
  12382. +#define __ASM_MACH_AR71XX_PCI_H
  12383. +
  12384. +struct pci_dev;
  12385. +
  12386. +struct ar71xx_pci_irq {
  12387. + int irq;
  12388. + u8 slot;
  12389. + u8 pin;
  12390. +};
  12391. +
  12392. +#ifdef CONFIG_PCI
  12393. +extern int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  12394. +extern unsigned ar71xx_pci_nr_irqs __initdata;
  12395. +extern struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  12396. +
  12397. +int ar71xx_pcibios_map_irq(const struct pci_dev *dev,
  12398. + uint8_t slot, uint8_t pin) __init;
  12399. +int ar71xx_pcibios_init(void) __init;
  12400. +
  12401. +int ar71xx_pci_be_handler(int is_fixup);
  12402. +
  12403. +int ar724x_pcibios_map_irq(const struct pci_dev *dev,
  12404. + uint8_t slot, uint8_t pin) __init;
  12405. +int ar724x_pcibios_init(void) __init;
  12406. +
  12407. +int ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map) __init;
  12408. +#else
  12409. +static inline int ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map)
  12410. +{
  12411. + return 0;
  12412. +}
  12413. +#endif
  12414. +
  12415. +#endif /* __ASM_MACH_AR71XX_PCI_H */
  12416. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/platform.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/platform.h
  12417. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/platform.h 1970-01-01 01:00:00.000000000 +0100
  12418. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/platform.h 2011-08-22 07:40:11.890481646 +0200
  12419. @@ -0,0 +1,63 @@
  12420. +/*
  12421. + * Atheros AR71xx SoC specific platform data definitions
  12422. + *
  12423. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  12424. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12425. + *
  12426. + * This program is free software; you can redistribute it and/or modify it
  12427. + * under the terms of the GNU General Public License version 2 as published
  12428. + * by the Free Software Foundation.
  12429. + */
  12430. +
  12431. +#ifndef __ASM_MACH_AR71XX_PLATFORM_H
  12432. +#define __ASM_MACH_AR71XX_PLATFORM_H
  12433. +
  12434. +#include <linux/if_ether.h>
  12435. +#include <linux/skbuff.h>
  12436. +#include <linux/phy.h>
  12437. +#include <linux/spi/spi.h>
  12438. +
  12439. +struct ag71xx_platform_data {
  12440. + phy_interface_t phy_if_mode;
  12441. + u32 phy_mask;
  12442. + int speed;
  12443. + int duplex;
  12444. + u32 reset_bit;
  12445. + u32 mii_if;
  12446. + u8 mac_addr[ETH_ALEN];
  12447. + struct device *mii_bus_dev;
  12448. +
  12449. + u8 has_gbit:1;
  12450. + u8 is_ar91xx:1;
  12451. + u8 is_ar7240:1;
  12452. + u8 is_ar724x:1;
  12453. + u8 has_ar8216:1;
  12454. + u8 has_ar7240_switch:1;
  12455. +
  12456. + void (*ddr_flush)(void);
  12457. + void (*set_pll)(int speed);
  12458. +
  12459. + u32 fifo_cfg1;
  12460. + u32 fifo_cfg2;
  12461. + u32 fifo_cfg3;
  12462. +};
  12463. +
  12464. +struct ag71xx_mdio_platform_data {
  12465. + u32 phy_mask;
  12466. + int is_ar7240;
  12467. +};
  12468. +
  12469. +struct ar71xx_ehci_platform_data {
  12470. + u8 is_ar91xx;
  12471. +};
  12472. +
  12473. +struct ar71xx_spi_platform_data {
  12474. + unsigned bus_num;
  12475. + unsigned num_chipselect;
  12476. + u32 (*get_ioc_base)(u8 chip_select, int cs_high, int is_on);
  12477. +};
  12478. +
  12479. +#define AR71XX_SPI_CS_INACTIVE 0
  12480. +#define AR71XX_SPI_CS_ACTIVE 1
  12481. +
  12482. +#endif /* __ASM_MACH_AR71XX_PLATFORM_H */
  12483. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/rb4xx_cpld.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/rb4xx_cpld.h
  12484. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/rb4xx_cpld.h 1970-01-01 01:00:00.000000000 +0100
  12485. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/rb4xx_cpld.h 2011-04-27 12:19:21.867661560 +0200
  12486. @@ -0,0 +1,48 @@
  12487. +/*
  12488. + * SPI driver definitions for the CPLD chip on the Mikrotik RB4xx boards
  12489. + *
  12490. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  12491. + *
  12492. + * This file was based on the patches for Linux 2.6.27.39 published by
  12493. + * MikroTik for their RouterBoard 4xx series devices.
  12494. + *
  12495. + * This program is free software; you can redistribute it and/or modify it
  12496. + * under the terms of the GNU General Public License version 2 as published
  12497. + * by the Free Software Foundation.
  12498. + */
  12499. +
  12500. +#define CPLD_GPIO_nLED1 0
  12501. +#define CPLD_GPIO_nLED2 1
  12502. +#define CPLD_GPIO_nLED3 2
  12503. +#define CPLD_GPIO_nLED4 3
  12504. +#define CPLD_GPIO_FAN 4
  12505. +#define CPLD_GPIO_ALE 5
  12506. +#define CPLD_GPIO_CLE 6
  12507. +#define CPLD_GPIO_nCE 7
  12508. +#define CPLD_GPIO_nLED5 8
  12509. +
  12510. +#define CPLD_NUM_GPIOS 9
  12511. +
  12512. +#define CPLD_CFG_nLED1 BIT(CPLD_GPIO_nLED1)
  12513. +#define CPLD_CFG_nLED2 BIT(CPLD_GPIO_nLED2)
  12514. +#define CPLD_CFG_nLED3 BIT(CPLD_GPIO_nLED3)
  12515. +#define CPLD_CFG_nLED4 BIT(CPLD_GPIO_nLED4)
  12516. +#define CPLD_CFG_FAN BIT(CPLD_GPIO_FAN)
  12517. +#define CPLD_CFG_ALE BIT(CPLD_GPIO_ALE)
  12518. +#define CPLD_CFG_CLE BIT(CPLD_GPIO_CLE)
  12519. +#define CPLD_CFG_nCE BIT(CPLD_GPIO_nCE)
  12520. +#define CPLD_CFG_nLED5 BIT(CPLD_GPIO_nLED5)
  12521. +
  12522. +struct rb4xx_cpld_platform_data {
  12523. + unsigned gpio_base;
  12524. +};
  12525. +
  12526. +extern int rb4xx_cpld_change_cfg(unsigned mask, unsigned value);
  12527. +extern int rb4xx_cpld_read(unsigned char *rx_buf,
  12528. + const unsigned char *verify_buf,
  12529. + unsigned cnt);
  12530. +extern int rb4xx_cpld_read_from(unsigned addr,
  12531. + unsigned char *rx_buf,
  12532. + const unsigned char *verify_buf,
  12533. + unsigned cnt);
  12534. +extern int rb4xx_cpld_write(const unsigned char *buf, unsigned count);
  12535. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/war.h linux-2.6.39/arch/mips/include/asm/mach-ar71xx/war.h
  12536. --- linux-2.6.39.orig/arch/mips/include/asm/mach-ar71xx/war.h 1970-01-01 01:00:00.000000000 +0100
  12537. +++ linux-2.6.39/arch/mips/include/asm/mach-ar71xx/war.h 2011-04-27 12:19:21.867661560 +0200
  12538. @@ -0,0 +1,25 @@
  12539. +/*
  12540. + * This file is subject to the terms and conditions of the GNU General Public
  12541. + * License. See the file "COPYING" in the main directory of this archive
  12542. + * for more details.
  12543. + *
  12544. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  12545. + */
  12546. +#ifndef __ASM_MACH_AR71XX_WAR_H
  12547. +#define __ASM_MACH_AR71XX_WAR_H
  12548. +
  12549. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  12550. +#define R4600_V1_HIT_CACHEOP_WAR 0
  12551. +#define R4600_V2_HIT_CACHEOP_WAR 0
  12552. +#define R5432_CP0_INTERRUPT_WAR 0
  12553. +#define BCM1250_M3_WAR 0
  12554. +#define SIBYTE_1956_WAR 0
  12555. +#define MIPS4K_ICACHE_REFILL_WAR 0
  12556. +#define MIPS_CACHE_SYNC_WAR 0
  12557. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  12558. +#define RM9000_CDEX_SMP_WAR 0
  12559. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  12560. +#define R10000_LLSC_WAR 0
  12561. +#define MIPS34K_MISSED_ITLB_WAR 0
  12562. +
  12563. +#endif /* __ASM_MACH_AR71XX_WAR_H */
  12564. diff -Nur linux-2.6.39.orig/arch/mips/include/asm/time.h linux-2.6.39/arch/mips/include/asm/time.h
  12565. --- linux-2.6.39.orig/arch/mips/include/asm/time.h 2011-05-19 06:06:34.000000000 +0200
  12566. +++ linux-2.6.39/arch/mips/include/asm/time.h 2011-08-24 05:53:05.239228886 +0200
  12567. @@ -52,6 +52,7 @@
  12568. */
  12569. #ifdef CONFIG_CEVT_R4K_LIB
  12570. extern unsigned int __weak get_c0_compare_int(void);
  12571. +extern unsigned int __weak get_c0_compare_irq(void);
  12572. extern int r4k_clockevent_init(void);
  12573. #endif
  12574. diff -Nur linux-2.6.39.orig/arch/mips/Kconfig linux-2.6.39/arch/mips/Kconfig
  12575. --- linux-2.6.39.orig/arch/mips/Kconfig 2011-05-19 06:06:34.000000000 +0200
  12576. +++ linux-2.6.39/arch/mips/Kconfig 2011-08-24 02:42:39.969240338 +0200
  12577. @@ -84,6 +84,23 @@
  12578. help
  12579. Support for the Atheros AR71XX/AR724X/AR913X SoCs.
  12580. +config ATHEROS_AR71XX
  12581. + bool "Atheros AR71xx based boards"
  12582. + select CEVT_R4K
  12583. + select CSRC_R4K
  12584. + select DMA_NONCOHERENT
  12585. + select HW_HAS_PCI
  12586. + select IRQ_CPU
  12587. + select ARCH_REQUIRE_GPIOLIB
  12588. + select SYS_HAS_CPU_MIPS32_R1
  12589. + select SYS_HAS_CPU_MIPS32_R2
  12590. + select SYS_SUPPORTS_32BIT_KERNEL
  12591. + select SYS_SUPPORTS_BIG_ENDIAN
  12592. + select SYS_HAS_EARLY_PRINTK
  12593. + select MIPS_MACHINE
  12594. + help
  12595. + Support for Atheros AR71xx based boards.
  12596. +
  12597. config BCM47XX
  12598. bool "Broadcom BCM47XX based boards"
  12599. select CEVT_R4K
  12600. @@ -739,6 +756,7 @@
  12601. endchoice
  12602. source "arch/mips/alchemy/Kconfig"
  12603. +source "arch/mips/ar71xx/Kconfig"
  12604. source "arch/mips/ath79/Kconfig"
  12605. source "arch/mips/bcm63xx/Kconfig"
  12606. source "arch/mips/jazz/Kconfig"
  12607. @@ -907,6 +925,9 @@
  12608. config MIPS_DISABLE_OBSOLETE_IDE
  12609. bool
  12610. +config MYLOADER
  12611. + bool
  12612. +
  12613. config SYNC_R4K
  12614. bool
  12615. diff -Nur linux-2.6.39.orig/arch/mips/Kconfig.orig linux-2.6.39/arch/mips/Kconfig.orig
  12616. --- linux-2.6.39.orig/arch/mips/Kconfig.orig 1970-01-01 01:00:00.000000000 +0100
  12617. +++ linux-2.6.39/arch/mips/Kconfig.orig 2011-08-22 16:21:32.077979816 +0200
  12618. @@ -0,0 +1,2472 @@
  12619. +config MIPS
  12620. + bool
  12621. + default y
  12622. + select HAVE_GENERIC_DMA_COHERENT
  12623. + select HAVE_IDE
  12624. + select HAVE_OPROFILE
  12625. + select HAVE_IRQ_WORK
  12626. + select HAVE_PERF_EVENTS
  12627. + select PERF_USE_VMALLOC
  12628. + select HAVE_ARCH_KGDB
  12629. + select HAVE_FUNCTION_TRACER
  12630. + select HAVE_FUNCTION_TRACE_MCOUNT_TEST
  12631. + select HAVE_DYNAMIC_FTRACE
  12632. + select HAVE_FTRACE_MCOUNT_RECORD
  12633. + select HAVE_C_RECORDMCOUNT
  12634. + select HAVE_FUNCTION_GRAPH_TRACER
  12635. + select HAVE_KPROBES
  12636. + select HAVE_KRETPROBES
  12637. + select RTC_LIB if !MACH_LOONGSON
  12638. + select GENERIC_ATOMIC64 if !64BIT
  12639. + select HAVE_DMA_ATTRS
  12640. + select HAVE_DMA_API_DEBUG
  12641. + select HAVE_GENERIC_HARDIRQS
  12642. + select GENERIC_IRQ_PROBE
  12643. + select GENERIC_IRQ_SHOW
  12644. + select HAVE_ARCH_JUMP_LABEL
  12645. +
  12646. +menu "Machine selection"
  12647. +
  12648. +config ZONE_DMA
  12649. + bool
  12650. +
  12651. +choice
  12652. + prompt "System type"
  12653. + default SGI_IP22
  12654. +
  12655. +config MIPS_ALCHEMY
  12656. + bool "Alchemy processor based machines"
  12657. + select 64BIT_PHYS_ADDR
  12658. + select CEVT_R4K_LIB
  12659. + select CSRC_R4K_LIB
  12660. + select IRQ_CPU
  12661. + select SYS_HAS_CPU_MIPS32_R1
  12662. + select SYS_SUPPORTS_32BIT_KERNEL
  12663. + select SYS_SUPPORTS_APM_EMULATION
  12664. + select GENERIC_GPIO
  12665. + select ARCH_WANT_OPTIONAL_GPIOLIB
  12666. + select SYS_SUPPORTS_ZBOOT
  12667. +
  12668. +config AR7
  12669. + bool "Texas Instruments AR7"
  12670. + select BOOT_ELF32
  12671. + select DMA_NONCOHERENT
  12672. + select CEVT_R4K
  12673. + select CSRC_R4K
  12674. + select IRQ_CPU
  12675. + select NO_EXCEPT_FILL
  12676. + select SWAP_IO_SPACE
  12677. + select SYS_HAS_CPU_MIPS32_R1
  12678. + select SYS_HAS_EARLY_PRINTK
  12679. + select SYS_SUPPORTS_32BIT_KERNEL
  12680. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12681. + select SYS_SUPPORTS_ZBOOT_UART16550
  12682. + select ARCH_REQUIRE_GPIOLIB
  12683. + select GCD
  12684. + select VLYNQ
  12685. + help
  12686. + Support for the Texas Instruments AR7 System-on-a-Chip
  12687. + family: TNETD7100, 7200 and 7300.
  12688. +
  12689. +config ATH79
  12690. + bool "Atheros AR71XX/AR724X/AR913X based boards"
  12691. + select ARCH_REQUIRE_GPIOLIB
  12692. + select BOOT_RAW
  12693. + select CEVT_R4K
  12694. + select CSRC_R4K
  12695. + select DMA_NONCOHERENT
  12696. + select IRQ_CPU
  12697. + select MIPS_MACHINE
  12698. + select SYS_HAS_CPU_MIPS32_R2
  12699. + select SYS_HAS_EARLY_PRINTK
  12700. + select SYS_SUPPORTS_32BIT_KERNEL
  12701. + select SYS_SUPPORTS_BIG_ENDIAN
  12702. + help
  12703. + Support for the Atheros AR71XX/AR724X/AR913X SoCs.
  12704. +
  12705. +config ATHEROS_AR71XX
  12706. + bool "Atheros AR71xx based boards"
  12707. + select CEVT_R4K
  12708. + select CSRC_R4K
  12709. + select DMA_NONCOHERENT
  12710. + select HW_HAS_PCI
  12711. + select IRQ_CPU
  12712. + select ARCH_REQUIRE_GPIOLIB
  12713. + select SYS_HAS_CPU_MIPS32_R1
  12714. + select SYS_HAS_CPU_MIPS32_R2
  12715. + select SYS_SUPPORTS_32BIT_KERNEL
  12716. + select SYS_SUPPORTS_BIG_ENDIAN
  12717. + select SYS_HAS_EARLY_PRINTK
  12718. + select MIPS_MACHINE
  12719. + help
  12720. + Support for Atheros AR71xx based boards.
  12721. +
  12722. +config BCM47XX
  12723. + bool "Broadcom BCM47XX based boards"
  12724. + select CEVT_R4K
  12725. + select CSRC_R4K
  12726. + select DMA_NONCOHERENT
  12727. + select HW_HAS_PCI
  12728. + select IRQ_CPU
  12729. + select SYS_HAS_CPU_MIPS32_R1
  12730. + select SYS_SUPPORTS_32BIT_KERNEL
  12731. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12732. + select SSB
  12733. + select SSB_DRIVER_MIPS
  12734. + select SSB_DRIVER_EXTIF
  12735. + select SSB_EMBEDDED
  12736. + select SSB_B43_PCI_BRIDGE if PCI
  12737. + select SSB_PCICORE_HOSTMODE if PCI
  12738. + select GENERIC_GPIO
  12739. + select SYS_HAS_EARLY_PRINTK
  12740. + select CFE
  12741. + help
  12742. + Support for BCM47XX based boards
  12743. +
  12744. +config BCM63XX
  12745. + bool "Broadcom BCM63XX based boards"
  12746. + select CEVT_R4K
  12747. + select CSRC_R4K
  12748. + select DMA_NONCOHERENT
  12749. + select IRQ_CPU
  12750. + select SYS_HAS_CPU_MIPS32_R1
  12751. + select SYS_SUPPORTS_32BIT_KERNEL
  12752. + select SYS_SUPPORTS_BIG_ENDIAN
  12753. + select SYS_HAS_EARLY_PRINTK
  12754. + select SWAP_IO_SPACE
  12755. + select ARCH_REQUIRE_GPIOLIB
  12756. + help
  12757. + Support for BCM63XX based boards
  12758. +
  12759. +config MIPS_COBALT
  12760. + bool "Cobalt Server"
  12761. + select CEVT_R4K
  12762. + select CSRC_R4K
  12763. + select CEVT_GT641XX
  12764. + select DMA_NONCOHERENT
  12765. + select HW_HAS_PCI
  12766. + select I8253
  12767. + select I8259
  12768. + select IRQ_CPU
  12769. + select IRQ_GT641XX
  12770. + select PCI_GT64XXX_PCI0
  12771. + select PCI
  12772. + select SYS_HAS_CPU_NEVADA
  12773. + select SYS_HAS_EARLY_PRINTK
  12774. + select SYS_SUPPORTS_32BIT_KERNEL
  12775. + select SYS_SUPPORTS_64BIT_KERNEL
  12776. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12777. +
  12778. +config MACH_DECSTATION
  12779. + bool "DECstations"
  12780. + select BOOT_ELF32
  12781. + select CEVT_DS1287
  12782. + select CEVT_R4K
  12783. + select CSRC_IOASIC
  12784. + select CSRC_R4K
  12785. + select CPU_DADDI_WORKAROUNDS if 64BIT
  12786. + select CPU_R4000_WORKAROUNDS if 64BIT
  12787. + select CPU_R4400_WORKAROUNDS if 64BIT
  12788. + select DMA_NONCOHERENT
  12789. + select NO_IOPORT
  12790. + select IRQ_CPU
  12791. + select SYS_HAS_CPU_R3000
  12792. + select SYS_HAS_CPU_R4X00
  12793. + select SYS_SUPPORTS_32BIT_KERNEL
  12794. + select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
  12795. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12796. + select SYS_SUPPORTS_128HZ
  12797. + select SYS_SUPPORTS_256HZ
  12798. + select SYS_SUPPORTS_1024HZ
  12799. + help
  12800. + This enables support for DEC's MIPS based workstations. For details
  12801. + see the Linux/MIPS FAQ on <http://www.linux-mips.org/> and the
  12802. + DECstation porting pages on <http://decstation.unix-ag.org/>.
  12803. +
  12804. + If you have one of the following DECstation Models you definitely
  12805. + want to choose R4xx0 for the CPU Type:
  12806. +
  12807. + DECstation 5000/50
  12808. + DECstation 5000/150
  12809. + DECstation 5000/260
  12810. + DECsystem 5900/260
  12811. +
  12812. + otherwise choose R3000.
  12813. +
  12814. +config MACH_JAZZ
  12815. + bool "Jazz family of machines"
  12816. + select ARC
  12817. + select ARC32
  12818. + select ARCH_MAY_HAVE_PC_FDC
  12819. + select CEVT_R4K
  12820. + select CSRC_R4K
  12821. + select DEFAULT_SGI_PARTITION if CPU_BIG_ENDIAN
  12822. + select GENERIC_ISA_DMA
  12823. + select IRQ_CPU
  12824. + select I8253
  12825. + select I8259
  12826. + select ISA
  12827. + select SYS_HAS_CPU_R4X00
  12828. + select SYS_SUPPORTS_32BIT_KERNEL
  12829. + select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
  12830. + select SYS_SUPPORTS_100HZ
  12831. + help
  12832. + This a family of machines based on the MIPS R4030 chipset which was
  12833. + used by several vendors to build RISC/os and Windows NT workstations.
  12834. + Members include the Acer PICA, MIPS Magnum 4000, MIPS Millennium and
  12835. + Olivetti M700-10 workstations.
  12836. +
  12837. +config MACH_JZ4740
  12838. + bool "Ingenic JZ4740 based machines"
  12839. + select SYS_HAS_CPU_MIPS32_R1
  12840. + select SYS_SUPPORTS_32BIT_KERNEL
  12841. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12842. + select DMA_NONCOHERENT
  12843. + select IRQ_CPU
  12844. + select GENERIC_GPIO
  12845. + select ARCH_REQUIRE_GPIOLIB
  12846. + select SYS_HAS_EARLY_PRINTK
  12847. + select HAVE_PWM
  12848. + select HAVE_CLK
  12849. +
  12850. +config LASAT
  12851. + bool "LASAT Networks platforms"
  12852. + select CEVT_R4K
  12853. + select CSRC_R4K
  12854. + select DMA_NONCOHERENT
  12855. + select SYS_HAS_EARLY_PRINTK
  12856. + select HW_HAS_PCI
  12857. + select IRQ_CPU
  12858. + select PCI_GT64XXX_PCI0
  12859. + select MIPS_NILE4
  12860. + select R5000_CPU_SCACHE
  12861. + select SYS_HAS_CPU_R5000
  12862. + select SYS_SUPPORTS_32BIT_KERNEL
  12863. + select SYS_SUPPORTS_64BIT_KERNEL if BROKEN
  12864. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12865. +
  12866. +config MACH_LOONGSON
  12867. + bool "Loongson family of machines"
  12868. + select SYS_SUPPORTS_ZBOOT
  12869. + help
  12870. + This enables the support of Loongson family of machines.
  12871. +
  12872. + Loongson is a family of general-purpose MIPS-compatible CPUs.
  12873. + developed at Institute of Computing Technology (ICT),
  12874. + Chinese Academy of Sciences (CAS) in the People's Republic
  12875. + of China. The chief architect is Professor Weiwu Hu.
  12876. +
  12877. +config MIPS_MALTA
  12878. + bool "MIPS Malta board"
  12879. + select ARCH_MAY_HAVE_PC_FDC
  12880. + select BOOT_ELF32
  12881. + select BOOT_RAW
  12882. + select CEVT_R4K
  12883. + select CSRC_R4K
  12884. + select DMA_NONCOHERENT
  12885. + select GENERIC_ISA_DMA
  12886. + select IRQ_CPU
  12887. + select IRQ_GIC
  12888. + select HW_HAS_PCI
  12889. + select I8253
  12890. + select I8259
  12891. + select MIPS_BOARDS_GEN
  12892. + select MIPS_BONITO64
  12893. + select MIPS_CPU_SCACHE
  12894. + select PCI_GT64XXX_PCI0
  12895. + select MIPS_MSC
  12896. + select SWAP_IO_SPACE
  12897. + select SYS_HAS_CPU_MIPS32_R1
  12898. + select SYS_HAS_CPU_MIPS32_R2
  12899. + select SYS_HAS_CPU_MIPS64_R1
  12900. + select SYS_HAS_CPU_NEVADA
  12901. + select SYS_HAS_CPU_RM7000
  12902. + select SYS_HAS_EARLY_PRINTK
  12903. + select SYS_SUPPORTS_32BIT_KERNEL
  12904. + select SYS_SUPPORTS_64BIT_KERNEL
  12905. + select SYS_SUPPORTS_BIG_ENDIAN
  12906. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12907. + select SYS_SUPPORTS_MIPS_CMP
  12908. + select SYS_SUPPORTS_MULTITHREADING
  12909. + select SYS_SUPPORTS_SMARTMIPS
  12910. + select SYS_SUPPORTS_ZBOOT
  12911. + help
  12912. + This enables support for the MIPS Technologies Malta evaluation
  12913. + board.
  12914. +
  12915. +config MIPS_SIM
  12916. + bool 'MIPS simulator (MIPSsim)'
  12917. + select CEVT_R4K
  12918. + select CSRC_R4K
  12919. + select DMA_NONCOHERENT
  12920. + select SYS_HAS_EARLY_PRINTK
  12921. + select IRQ_CPU
  12922. + select BOOT_RAW
  12923. + select SYS_HAS_CPU_MIPS32_R1
  12924. + select SYS_HAS_CPU_MIPS32_R2
  12925. + select SYS_HAS_EARLY_PRINTK
  12926. + select SYS_SUPPORTS_32BIT_KERNEL
  12927. + select SYS_SUPPORTS_BIG_ENDIAN
  12928. + select SYS_SUPPORTS_MULTITHREADING
  12929. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12930. + help
  12931. + This option enables support for MIPS Technologies MIPSsim software
  12932. + emulator.
  12933. +
  12934. +config NEC_MARKEINS
  12935. + bool "NEC EMMA2RH Mark-eins board"
  12936. + select SOC_EMMA2RH
  12937. + select HW_HAS_PCI
  12938. + help
  12939. + This enables support for the NEC Electronics Mark-eins boards.
  12940. +
  12941. +config MACH_VR41XX
  12942. + bool "NEC VR4100 series based machines"
  12943. + select CEVT_R4K
  12944. + select CSRC_R4K
  12945. + select SYS_HAS_CPU_VR41XX
  12946. + select ARCH_REQUIRE_GPIOLIB
  12947. +
  12948. +config NXP_STB220
  12949. + bool "NXP STB220 board"
  12950. + select SOC_PNX833X
  12951. + help
  12952. + Support for NXP Semiconductors STB220 Development Board.
  12953. +
  12954. +config NXP_STB225
  12955. + bool "NXP 225 board"
  12956. + select SOC_PNX833X
  12957. + select SOC_PNX8335
  12958. + help
  12959. + Support for NXP Semiconductors STB225 Development Board.
  12960. +
  12961. +config PNX8550_JBS
  12962. + bool "NXP PNX8550 based JBS board"
  12963. + select PNX8550
  12964. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12965. +
  12966. +config PNX8550_STB810
  12967. + bool "NXP PNX8550 based STB810 board"
  12968. + select PNX8550
  12969. + select SYS_SUPPORTS_LITTLE_ENDIAN
  12970. +
  12971. +config PMC_MSP
  12972. + bool "PMC-Sierra MSP chipsets"
  12973. + depends on EXPERIMENTAL
  12974. + select CEVT_R4K
  12975. + select CSRC_R4K
  12976. + select DMA_NONCOHERENT
  12977. + select SWAP_IO_SPACE
  12978. + select NO_EXCEPT_FILL
  12979. + select BOOT_RAW
  12980. + select SYS_HAS_CPU_MIPS32_R1
  12981. + select SYS_HAS_CPU_MIPS32_R2
  12982. + select SYS_SUPPORTS_32BIT_KERNEL
  12983. + select SYS_SUPPORTS_BIG_ENDIAN
  12984. + select IRQ_CPU
  12985. + select SERIAL_8250
  12986. + select SERIAL_8250_CONSOLE
  12987. + help
  12988. + This adds support for the PMC-Sierra family of Multi-Service
  12989. + Processor System-On-A-Chips. These parts include a number
  12990. + of integrated peripherals, interfaces and DSPs in addition to
  12991. + a variety of MIPS cores.
  12992. +
  12993. +config PMC_YOSEMITE
  12994. + bool "PMC-Sierra Yosemite eval board"
  12995. + select CEVT_R4K
  12996. + select CSRC_R4K
  12997. + select DMA_COHERENT
  12998. + select HW_HAS_PCI
  12999. + select IRQ_CPU
  13000. + select IRQ_CPU_RM7K
  13001. + select IRQ_CPU_RM9K
  13002. + select SWAP_IO_SPACE
  13003. + select SYS_HAS_CPU_RM9000
  13004. + select SYS_HAS_EARLY_PRINTK
  13005. + select SYS_SUPPORTS_32BIT_KERNEL
  13006. + select SYS_SUPPORTS_64BIT_KERNEL
  13007. + select SYS_SUPPORTS_BIG_ENDIAN
  13008. + select SYS_SUPPORTS_HIGHMEM
  13009. + select SYS_SUPPORTS_SMP
  13010. + help
  13011. + Yosemite is an evaluation board for the RM9000x2 processor
  13012. + manufactured by PMC-Sierra.
  13013. +
  13014. +config POWERTV
  13015. + bool "Cisco PowerTV"
  13016. + select BOOT_ELF32
  13017. + select CEVT_R4K
  13018. + select CPU_MIPSR2_IRQ_VI
  13019. + select CPU_MIPSR2_IRQ_EI
  13020. + select CSRC_POWERTV
  13021. + select DMA_NONCOHERENT
  13022. + select HW_HAS_PCI
  13023. + select SYS_HAS_EARLY_PRINTK
  13024. + select SYS_HAS_CPU_MIPS32_R2
  13025. + select SYS_SUPPORTS_32BIT_KERNEL
  13026. + select SYS_SUPPORTS_BIG_ENDIAN
  13027. + select SYS_SUPPORTS_HIGHMEM
  13028. + select USB_OHCI_LITTLE_ENDIAN
  13029. + help
  13030. + This enables support for the Cisco PowerTV Platform.
  13031. +
  13032. +config SGI_IP22
  13033. + bool "SGI IP22 (Indy/Indigo2)"
  13034. + select ARC
  13035. + select ARC32
  13036. + select BOOT_ELF32
  13037. + select CEVT_R4K
  13038. + select CSRC_R4K
  13039. + select DEFAULT_SGI_PARTITION
  13040. + select DMA_NONCOHERENT
  13041. + select HW_HAS_EISA
  13042. + select I8253
  13043. + select I8259
  13044. + select IP22_CPU_SCACHE
  13045. + select IRQ_CPU
  13046. + select GENERIC_ISA_DMA_SUPPORT_BROKEN
  13047. + select SGI_HAS_I8042
  13048. + select SGI_HAS_INDYDOG
  13049. + select SGI_HAS_HAL2
  13050. + select SGI_HAS_SEEQ
  13051. + select SGI_HAS_WD93
  13052. + select SGI_HAS_ZILOG
  13053. + select SWAP_IO_SPACE
  13054. + select SYS_HAS_CPU_R4X00
  13055. + select SYS_HAS_CPU_R5000
  13056. + #
  13057. + # Disable EARLY_PRINTK for now since it leads to overwritten prom
  13058. + # memory during early boot on some machines.
  13059. + #
  13060. + # See http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=20091119164009.GA15038%40deprecation.cyrius.com
  13061. + # for a more details discussion
  13062. + #
  13063. + # select SYS_HAS_EARLY_PRINTK
  13064. + select SYS_SUPPORTS_32BIT_KERNEL
  13065. + select SYS_SUPPORTS_64BIT_KERNEL
  13066. + select SYS_SUPPORTS_BIG_ENDIAN
  13067. + help
  13068. + This are the SGI Indy, Challenge S and Indigo2, as well as certain
  13069. + OEM variants like the Tandem CMN B006S. To compile a Linux kernel
  13070. + that runs on these, say Y here.
  13071. +
  13072. +config SGI_IP27
  13073. + bool "SGI IP27 (Origin200/2000)"
  13074. + select ARC
  13075. + select ARC64
  13076. + select BOOT_ELF64
  13077. + select DEFAULT_SGI_PARTITION
  13078. + select DMA_COHERENT
  13079. + select SYS_HAS_EARLY_PRINTK
  13080. + select HW_HAS_PCI
  13081. + select NR_CPUS_DEFAULT_64
  13082. + select SYS_HAS_CPU_R10000
  13083. + select SYS_SUPPORTS_64BIT_KERNEL
  13084. + select SYS_SUPPORTS_BIG_ENDIAN
  13085. + select SYS_SUPPORTS_NUMA
  13086. + select SYS_SUPPORTS_SMP
  13087. + help
  13088. + This are the SGI Origin 200, Origin 2000 and Onyx 2 Graphics
  13089. + workstations. To compile a Linux kernel that runs on these, say Y
  13090. + here.
  13091. +
  13092. +config SGI_IP28
  13093. + bool "SGI IP28 (Indigo2 R10k) (EXPERIMENTAL)"
  13094. + depends on EXPERIMENTAL
  13095. + select ARC
  13096. + select ARC64
  13097. + select BOOT_ELF64
  13098. + select CEVT_R4K
  13099. + select CSRC_R4K
  13100. + select DEFAULT_SGI_PARTITION
  13101. + select DMA_NONCOHERENT
  13102. + select GENERIC_ISA_DMA_SUPPORT_BROKEN
  13103. + select IRQ_CPU
  13104. + select HW_HAS_EISA
  13105. + select I8253
  13106. + select I8259
  13107. + select SGI_HAS_I8042
  13108. + select SGI_HAS_INDYDOG
  13109. + select SGI_HAS_HAL2
  13110. + select SGI_HAS_SEEQ
  13111. + select SGI_HAS_WD93
  13112. + select SGI_HAS_ZILOG
  13113. + select SWAP_IO_SPACE
  13114. + select SYS_HAS_CPU_R10000
  13115. + #
  13116. + # Disable EARLY_PRINTK for now since it leads to overwritten prom
  13117. + # memory during early boot on some machines.
  13118. + #
  13119. + # See http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=20091119164009.GA15038%40deprecation.cyrius.com
  13120. + # for a more details discussion
  13121. + #
  13122. + # select SYS_HAS_EARLY_PRINTK
  13123. + select SYS_SUPPORTS_64BIT_KERNEL
  13124. + select SYS_SUPPORTS_BIG_ENDIAN
  13125. + help
  13126. + This is the SGI Indigo2 with R10000 processor. To compile a Linux
  13127. + kernel that runs on these, say Y here.
  13128. +
  13129. +config SGI_IP32
  13130. + bool "SGI IP32 (O2)"
  13131. + select ARC
  13132. + select ARC32
  13133. + select BOOT_ELF32
  13134. + select CEVT_R4K
  13135. + select CSRC_R4K
  13136. + select DMA_NONCOHERENT
  13137. + select HW_HAS_PCI
  13138. + select IRQ_CPU
  13139. + select R5000_CPU_SCACHE
  13140. + select RM7000_CPU_SCACHE
  13141. + select SYS_HAS_CPU_R5000
  13142. + select SYS_HAS_CPU_R10000 if BROKEN
  13143. + select SYS_HAS_CPU_RM7000
  13144. + select SYS_HAS_CPU_NEVADA
  13145. + select SYS_SUPPORTS_64BIT_KERNEL
  13146. + select SYS_SUPPORTS_BIG_ENDIAN
  13147. + help
  13148. + If you want this kernel to run on SGI O2 workstation, say Y here.
  13149. +
  13150. +config SIBYTE_CRHINE
  13151. + bool "Sibyte BCM91120C-CRhine"
  13152. + depends on EXPERIMENTAL
  13153. + select BOOT_ELF32
  13154. + select DMA_COHERENT
  13155. + select SIBYTE_BCM1120
  13156. + select SWAP_IO_SPACE
  13157. + select SYS_HAS_CPU_SB1
  13158. + select SYS_SUPPORTS_BIG_ENDIAN
  13159. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13160. +
  13161. +config SIBYTE_CARMEL
  13162. + bool "Sibyte BCM91120x-Carmel"
  13163. + depends on EXPERIMENTAL
  13164. + select BOOT_ELF32
  13165. + select DMA_COHERENT
  13166. + select SIBYTE_BCM1120
  13167. + select SWAP_IO_SPACE
  13168. + select SYS_HAS_CPU_SB1
  13169. + select SYS_SUPPORTS_BIG_ENDIAN
  13170. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13171. +
  13172. +config SIBYTE_CRHONE
  13173. + bool "Sibyte BCM91125C-CRhone"
  13174. + depends on EXPERIMENTAL
  13175. + select BOOT_ELF32
  13176. + select DMA_COHERENT
  13177. + select SIBYTE_BCM1125
  13178. + select SWAP_IO_SPACE
  13179. + select SYS_HAS_CPU_SB1
  13180. + select SYS_SUPPORTS_BIG_ENDIAN
  13181. + select SYS_SUPPORTS_HIGHMEM
  13182. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13183. +
  13184. +config SIBYTE_RHONE
  13185. + bool "Sibyte BCM91125E-Rhone"
  13186. + depends on EXPERIMENTAL
  13187. + select BOOT_ELF32
  13188. + select DMA_COHERENT
  13189. + select SIBYTE_BCM1125H
  13190. + select SWAP_IO_SPACE
  13191. + select SYS_HAS_CPU_SB1
  13192. + select SYS_SUPPORTS_BIG_ENDIAN
  13193. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13194. +
  13195. +config SIBYTE_SWARM
  13196. + bool "Sibyte BCM91250A-SWARM"
  13197. + select BOOT_ELF32
  13198. + select DMA_COHERENT
  13199. + select HAVE_PATA_PLATFORM
  13200. + select NR_CPUS_DEFAULT_2
  13201. + select SIBYTE_SB1250
  13202. + select SWAP_IO_SPACE
  13203. + select SYS_HAS_CPU_SB1
  13204. + select SYS_SUPPORTS_BIG_ENDIAN
  13205. + select SYS_SUPPORTS_HIGHMEM
  13206. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13207. + select ZONE_DMA32 if 64BIT
  13208. +
  13209. +config SIBYTE_LITTLESUR
  13210. + bool "Sibyte BCM91250C2-LittleSur"
  13211. + depends on EXPERIMENTAL
  13212. + select BOOT_ELF32
  13213. + select DMA_COHERENT
  13214. + select HAVE_PATA_PLATFORM
  13215. + select NR_CPUS_DEFAULT_2
  13216. + select SIBYTE_SB1250
  13217. + select SWAP_IO_SPACE
  13218. + select SYS_HAS_CPU_SB1
  13219. + select SYS_SUPPORTS_BIG_ENDIAN
  13220. + select SYS_SUPPORTS_HIGHMEM
  13221. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13222. +
  13223. +config SIBYTE_SENTOSA
  13224. + bool "Sibyte BCM91250E-Sentosa"
  13225. + depends on EXPERIMENTAL
  13226. + select BOOT_ELF32
  13227. + select DMA_COHERENT
  13228. + select NR_CPUS_DEFAULT_2
  13229. + select SIBYTE_SB1250
  13230. + select SWAP_IO_SPACE
  13231. + select SYS_HAS_CPU_SB1
  13232. + select SYS_SUPPORTS_BIG_ENDIAN
  13233. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13234. +
  13235. +config SIBYTE_BIGSUR
  13236. + bool "Sibyte BCM91480B-BigSur"
  13237. + select BOOT_ELF32
  13238. + select DMA_COHERENT
  13239. + select NR_CPUS_DEFAULT_4
  13240. + select SIBYTE_BCM1x80
  13241. + select SWAP_IO_SPACE
  13242. + select SYS_HAS_CPU_SB1
  13243. + select SYS_SUPPORTS_BIG_ENDIAN
  13244. + select SYS_SUPPORTS_HIGHMEM
  13245. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13246. + select ZONE_DMA32 if 64BIT
  13247. +
  13248. +config SNI_RM
  13249. + bool "SNI RM200/300/400"
  13250. + select ARC if CPU_LITTLE_ENDIAN
  13251. + select ARC32 if CPU_LITTLE_ENDIAN
  13252. + select SNIPROM if CPU_BIG_ENDIAN
  13253. + select ARCH_MAY_HAVE_PC_FDC
  13254. + select BOOT_ELF32
  13255. + select CEVT_R4K
  13256. + select CSRC_R4K
  13257. + select DEFAULT_SGI_PARTITION if CPU_BIG_ENDIAN
  13258. + select DMA_NONCOHERENT
  13259. + select GENERIC_ISA_DMA
  13260. + select HW_HAS_EISA
  13261. + select HW_HAS_PCI
  13262. + select IRQ_CPU
  13263. + select I8253
  13264. + select I8259
  13265. + select ISA
  13266. + select SWAP_IO_SPACE if CPU_BIG_ENDIAN
  13267. + select SYS_HAS_CPU_R4X00
  13268. + select SYS_HAS_CPU_R5000
  13269. + select SYS_HAS_CPU_R10000
  13270. + select R5000_CPU_SCACHE
  13271. + select SYS_HAS_EARLY_PRINTK
  13272. + select SYS_SUPPORTS_32BIT_KERNEL
  13273. + select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
  13274. + select SYS_SUPPORTS_BIG_ENDIAN
  13275. + select SYS_SUPPORTS_HIGHMEM
  13276. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13277. + help
  13278. + The SNI RM200/300/400 are MIPS-based machines manufactured by
  13279. + Siemens Nixdorf Informationssysteme (SNI), parent company of Pyramid
  13280. + Technology and now in turn merged with Fujitsu. Say Y here to
  13281. + support this machine type.
  13282. +
  13283. +config MACH_TX39XX
  13284. + bool "Toshiba TX39 series based machines"
  13285. +
  13286. +config MACH_TX49XX
  13287. + bool "Toshiba TX49 series based machines"
  13288. +
  13289. +config MIKROTIK_RB532
  13290. + bool "Mikrotik RB532 boards"
  13291. + select CEVT_R4K
  13292. + select CSRC_R4K
  13293. + select DMA_NONCOHERENT
  13294. + select HW_HAS_PCI
  13295. + select IRQ_CPU
  13296. + select SYS_HAS_CPU_MIPS32_R1
  13297. + select SYS_SUPPORTS_32BIT_KERNEL
  13298. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13299. + select SWAP_IO_SPACE
  13300. + select BOOT_RAW
  13301. + select ARCH_REQUIRE_GPIOLIB
  13302. + help
  13303. + Support the Mikrotik(tm) RouterBoard 532 series,
  13304. + based on the IDT RC32434 SoC.
  13305. +
  13306. +config WR_PPMC
  13307. + bool "Wind River PPMC board"
  13308. + select CEVT_R4K
  13309. + select CSRC_R4K
  13310. + select IRQ_CPU
  13311. + select BOOT_ELF32
  13312. + select DMA_NONCOHERENT
  13313. + select HW_HAS_PCI
  13314. + select PCI_GT64XXX_PCI0
  13315. + select SWAP_IO_SPACE
  13316. + select SYS_HAS_CPU_MIPS32_R1
  13317. + select SYS_HAS_CPU_MIPS32_R2
  13318. + select SYS_HAS_CPU_MIPS64_R1
  13319. + select SYS_HAS_CPU_NEVADA
  13320. + select SYS_HAS_CPU_RM7000
  13321. + select SYS_SUPPORTS_32BIT_KERNEL
  13322. + select SYS_SUPPORTS_64BIT_KERNEL
  13323. + select SYS_SUPPORTS_BIG_ENDIAN
  13324. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13325. + help
  13326. + This enables support for the Wind River MIPS32 4KC PPMC evaluation
  13327. + board, which is based on GT64120 bridge chip.
  13328. +
  13329. +config CAVIUM_OCTEON_SIMULATOR
  13330. + bool "Cavium Networks Octeon Simulator"
  13331. + select CEVT_R4K
  13332. + select 64BIT_PHYS_ADDR
  13333. + select DMA_COHERENT
  13334. + select SYS_SUPPORTS_64BIT_KERNEL
  13335. + select SYS_SUPPORTS_BIG_ENDIAN
  13336. + select SYS_SUPPORTS_HIGHMEM
  13337. + select SYS_SUPPORTS_HOTPLUG_CPU
  13338. + select SYS_HAS_CPU_CAVIUM_OCTEON
  13339. + help
  13340. + The Octeon simulator is software performance model of the Cavium
  13341. + Octeon Processor. It supports simulating Octeon processors on x86
  13342. + hardware.
  13343. +
  13344. +config CAVIUM_OCTEON_REFERENCE_BOARD
  13345. + bool "Cavium Networks Octeon reference board"
  13346. + select CEVT_R4K
  13347. + select 64BIT_PHYS_ADDR
  13348. + select DMA_COHERENT
  13349. + select SYS_SUPPORTS_64BIT_KERNEL
  13350. + select SYS_SUPPORTS_BIG_ENDIAN
  13351. + select SYS_SUPPORTS_HIGHMEM
  13352. + select SYS_SUPPORTS_HOTPLUG_CPU
  13353. + select SYS_HAS_EARLY_PRINTK
  13354. + select SYS_HAS_CPU_CAVIUM_OCTEON
  13355. + select SWAP_IO_SPACE
  13356. + select HW_HAS_PCI
  13357. + select ARCH_SUPPORTS_MSI
  13358. + select ZONE_DMA32
  13359. + select USB_ARCH_HAS_OHCI
  13360. + select USB_ARCH_HAS_EHCI
  13361. + help
  13362. + This option supports all of the Octeon reference boards from Cavium
  13363. + Networks. It builds a kernel that dynamically determines the Octeon
  13364. + CPU type and supports all known board reference implementations.
  13365. + Some of the supported boards are:
  13366. + EBT3000
  13367. + EBH3000
  13368. + EBH3100
  13369. + Thunder
  13370. + Kodama
  13371. + Hikari
  13372. + Say Y here for most Octeon reference boards.
  13373. +
  13374. +endchoice
  13375. +
  13376. +source "arch/mips/alchemy/Kconfig"
  13377. +source "arch/mips/ar71xx/Kconfig"
  13378. +source "arch/mips/ath79/Kconfig"
  13379. +source "arch/mips/bcm63xx/Kconfig"
  13380. +source "arch/mips/jazz/Kconfig"
  13381. +source "arch/mips/jz4740/Kconfig"
  13382. +source "arch/mips/lasat/Kconfig"
  13383. +source "arch/mips/pmc-sierra/Kconfig"
  13384. +source "arch/mips/powertv/Kconfig"
  13385. +source "arch/mips/sgi-ip27/Kconfig"
  13386. +source "arch/mips/sibyte/Kconfig"
  13387. +source "arch/mips/txx9/Kconfig"
  13388. +source "arch/mips/vr41xx/Kconfig"
  13389. +source "arch/mips/cavium-octeon/Kconfig"
  13390. +source "arch/mips/loongson/Kconfig"
  13391. +
  13392. +endmenu
  13393. +
  13394. +config RWSEM_GENERIC_SPINLOCK
  13395. + bool
  13396. + default y
  13397. +
  13398. +config RWSEM_XCHGADD_ALGORITHM
  13399. + bool
  13400. +
  13401. +config ARCH_HAS_ILOG2_U32
  13402. + bool
  13403. + default n
  13404. +
  13405. +config ARCH_HAS_ILOG2_U64
  13406. + bool
  13407. + default n
  13408. +
  13409. +config ARCH_SUPPORTS_OPROFILE
  13410. + bool
  13411. + default y if !MIPS_MT_SMTC
  13412. +
  13413. +config GENERIC_FIND_NEXT_BIT
  13414. + bool
  13415. + default y
  13416. +
  13417. +config GENERIC_FIND_BIT_LE
  13418. + bool
  13419. + default y
  13420. +
  13421. +config GENERIC_HWEIGHT
  13422. + bool
  13423. + default y
  13424. +
  13425. +config GENERIC_CALIBRATE_DELAY
  13426. + bool
  13427. + default y
  13428. +
  13429. +config GENERIC_CLOCKEVENTS
  13430. + bool
  13431. + default y
  13432. +
  13433. +config GENERIC_CMOS_UPDATE
  13434. + bool
  13435. + default y
  13436. +
  13437. +config SCHED_OMIT_FRAME_POINTER
  13438. + bool
  13439. + default y
  13440. +
  13441. +#
  13442. +# Select some configuration options automatically based on user selections.
  13443. +#
  13444. +config ARC
  13445. + bool
  13446. +
  13447. +config ARCH_MAY_HAVE_PC_FDC
  13448. + bool
  13449. +
  13450. +config BOOT_RAW
  13451. + bool
  13452. +
  13453. +config CEVT_BCM1480
  13454. + bool
  13455. +
  13456. +config CEVT_DS1287
  13457. + bool
  13458. +
  13459. +config CEVT_GT641XX
  13460. + bool
  13461. +
  13462. +config CEVT_R4K_LIB
  13463. + bool
  13464. +
  13465. +config CEVT_R4K
  13466. + select CEVT_R4K_LIB
  13467. + bool
  13468. +
  13469. +config CEVT_SB1250
  13470. + bool
  13471. +
  13472. +config CEVT_TXX9
  13473. + bool
  13474. +
  13475. +config CSRC_BCM1480
  13476. + bool
  13477. +
  13478. +config CSRC_IOASIC
  13479. + bool
  13480. +
  13481. +config CSRC_POWERTV
  13482. + bool
  13483. +
  13484. +config CSRC_R4K_LIB
  13485. + bool
  13486. +
  13487. +config CSRC_R4K
  13488. + select CSRC_R4K_LIB
  13489. + bool
  13490. +
  13491. +config CSRC_SB1250
  13492. + bool
  13493. +
  13494. +config GPIO_TXX9
  13495. + select GENERIC_GPIO
  13496. + select ARCH_REQUIRE_GPIOLIB
  13497. + bool
  13498. +
  13499. +config CFE
  13500. + bool
  13501. +
  13502. +config ARCH_DMA_ADDR_T_64BIT
  13503. + def_bool (HIGHMEM && 64BIT_PHYS_ADDR) || 64BIT
  13504. +
  13505. +config DMA_COHERENT
  13506. + bool
  13507. +
  13508. +config DMA_NONCOHERENT
  13509. + bool
  13510. + select NEED_DMA_MAP_STATE
  13511. +
  13512. +config NEED_DMA_MAP_STATE
  13513. + bool
  13514. +
  13515. +config SYS_HAS_EARLY_PRINTK
  13516. + bool
  13517. +
  13518. +config HOTPLUG_CPU
  13519. + bool "Support for hot-pluggable CPUs"
  13520. + depends on SMP && HOTPLUG && SYS_SUPPORTS_HOTPLUG_CPU
  13521. + help
  13522. + Say Y here to allow turning CPUs off and on. CPUs can be
  13523. + controlled through /sys/devices/system/cpu.
  13524. + (Note: power management support will enable this option
  13525. + automatically on SMP systems. )
  13526. + Say N if you want to disable CPU hotplug.
  13527. +
  13528. +config SYS_SUPPORTS_HOTPLUG_CPU
  13529. + bool
  13530. +
  13531. +config I8259
  13532. + bool
  13533. +
  13534. +config MIPS_BONITO64
  13535. + bool
  13536. +
  13537. +config MIPS_MSC
  13538. + bool
  13539. +
  13540. +config MIPS_NILE4
  13541. + bool
  13542. +
  13543. +config MIPS_DISABLE_OBSOLETE_IDE
  13544. + bool
  13545. +
  13546. +config SYNC_R4K
  13547. + bool
  13548. +
  13549. +config MIPS_MACHINE
  13550. + def_bool n
  13551. +
  13552. +config NO_IOPORT
  13553. + def_bool n
  13554. +
  13555. +config GENERIC_ISA_DMA
  13556. + bool
  13557. + select ZONE_DMA if GENERIC_ISA_DMA_SUPPORT_BROKEN=n
  13558. + select ISA_DMA_API
  13559. +
  13560. +config GENERIC_ISA_DMA_SUPPORT_BROKEN
  13561. + bool
  13562. + select GENERIC_ISA_DMA
  13563. +
  13564. +config ISA_DMA_API
  13565. + bool
  13566. +
  13567. +config GENERIC_GPIO
  13568. + bool
  13569. +
  13570. +#
  13571. +# Endianess selection. Sufficiently obscure so many users don't know what to
  13572. +# answer,so we try hard to limit the available choices. Also the use of a
  13573. +# choice statement should be more obvious to the user.
  13574. +#
  13575. +choice
  13576. + prompt "Endianess selection"
  13577. + help
  13578. + Some MIPS machines can be configured for either little or big endian
  13579. + byte order. These modes require different kernels and a different
  13580. + Linux distribution. In general there is one preferred byteorder for a
  13581. + particular system but some systems are just as commonly used in the
  13582. + one or the other endianness.
  13583. +
  13584. +config CPU_BIG_ENDIAN
  13585. + bool "Big endian"
  13586. + depends on SYS_SUPPORTS_BIG_ENDIAN
  13587. +
  13588. +config CPU_LITTLE_ENDIAN
  13589. + bool "Little endian"
  13590. + depends on SYS_SUPPORTS_LITTLE_ENDIAN
  13591. + help
  13592. +
  13593. +endchoice
  13594. +
  13595. +config EXPORT_UASM
  13596. + bool
  13597. +
  13598. +config SYS_SUPPORTS_APM_EMULATION
  13599. + bool
  13600. +
  13601. +config SYS_SUPPORTS_BIG_ENDIAN
  13602. + bool
  13603. +
  13604. +config SYS_SUPPORTS_LITTLE_ENDIAN
  13605. + bool
  13606. +
  13607. +config SYS_SUPPORTS_HUGETLBFS
  13608. + bool
  13609. + depends on CPU_SUPPORTS_HUGEPAGES && 64BIT
  13610. + default y
  13611. +
  13612. +config IRQ_CPU
  13613. + bool
  13614. +
  13615. +config IRQ_CPU_RM7K
  13616. + bool
  13617. +
  13618. +config IRQ_CPU_RM9K
  13619. + bool
  13620. +
  13621. +config IRQ_MSP_SLP
  13622. + bool
  13623. +
  13624. +config IRQ_MSP_CIC
  13625. + bool
  13626. +
  13627. +config IRQ_TXX9
  13628. + bool
  13629. +
  13630. +config IRQ_GT641XX
  13631. + bool
  13632. +
  13633. +config IRQ_GIC
  13634. + bool
  13635. +
  13636. +config MIPS_BOARDS_GEN
  13637. + bool
  13638. +
  13639. +config PCI_GT64XXX_PCI0
  13640. + bool
  13641. +
  13642. +config NO_EXCEPT_FILL
  13643. + bool
  13644. +
  13645. +config MIPS_RM9122
  13646. + bool
  13647. + select SERIAL_RM9000
  13648. +
  13649. +config SOC_EMMA2RH
  13650. + bool
  13651. + select CEVT_R4K
  13652. + select CSRC_R4K
  13653. + select DMA_NONCOHERENT
  13654. + select IRQ_CPU
  13655. + select SWAP_IO_SPACE
  13656. + select SYS_HAS_CPU_R5500
  13657. + select SYS_SUPPORTS_32BIT_KERNEL
  13658. + select SYS_SUPPORTS_64BIT_KERNEL
  13659. + select SYS_SUPPORTS_BIG_ENDIAN
  13660. +
  13661. +config SOC_PNX833X
  13662. + bool
  13663. + select CEVT_R4K
  13664. + select CSRC_R4K
  13665. + select IRQ_CPU
  13666. + select DMA_NONCOHERENT
  13667. + select SYS_HAS_CPU_MIPS32_R2
  13668. + select SYS_SUPPORTS_32BIT_KERNEL
  13669. + select SYS_SUPPORTS_LITTLE_ENDIAN
  13670. + select SYS_SUPPORTS_BIG_ENDIAN
  13671. + select GENERIC_GPIO
  13672. + select CPU_MIPSR2_IRQ_VI
  13673. +
  13674. +config SOC_PNX8335
  13675. + bool
  13676. + select SOC_PNX833X
  13677. +
  13678. +config PNX8550
  13679. + bool
  13680. + select SOC_PNX8550
  13681. +
  13682. +config SOC_PNX8550
  13683. + bool
  13684. + select DMA_NONCOHERENT
  13685. + select HW_HAS_PCI
  13686. + select SYS_HAS_CPU_MIPS32_R1
  13687. + select SYS_HAS_EARLY_PRINTK
  13688. + select SYS_SUPPORTS_32BIT_KERNEL
  13689. + select GENERIC_GPIO
  13690. +
  13691. +config SWAP_IO_SPACE
  13692. + bool
  13693. +
  13694. +config SERIAL_RM9000
  13695. + bool
  13696. +
  13697. +config SGI_HAS_INDYDOG
  13698. + bool
  13699. +
  13700. +config SGI_HAS_HAL2
  13701. + bool
  13702. +
  13703. +config SGI_HAS_SEEQ
  13704. + bool
  13705. +
  13706. +config SGI_HAS_WD93
  13707. + bool
  13708. +
  13709. +config SGI_HAS_ZILOG
  13710. + bool
  13711. +
  13712. +config SGI_HAS_I8042
  13713. + bool
  13714. +
  13715. +config DEFAULT_SGI_PARTITION
  13716. + bool
  13717. +
  13718. +config ARC32
  13719. + bool
  13720. +
  13721. +config SNIPROM
  13722. + bool
  13723. +
  13724. +config BOOT_ELF32
  13725. + bool
  13726. +
  13727. +config MIPS_L1_CACHE_SHIFT
  13728. + int
  13729. + default "4" if MACH_DECSTATION || MIKROTIK_RB532 || PMC_MSP4200_EVAL
  13730. + default "6" if MIPS_CPU_SCACHE
  13731. + default "7" if SGI_IP22 || SGI_IP27 || SGI_IP28 || SNI_RM || CPU_CAVIUM_OCTEON
  13732. + default "5"
  13733. +
  13734. +config HAVE_STD_PC_SERIAL_PORT
  13735. + bool
  13736. +
  13737. +config ARC_CONSOLE
  13738. + bool "ARC console support"
  13739. + depends on SGI_IP22 || SGI_IP28 || (SNI_RM && CPU_LITTLE_ENDIAN)
  13740. +
  13741. +config ARC_MEMORY
  13742. + bool
  13743. + depends on MACH_JAZZ || SNI_RM || SGI_IP32
  13744. + default y
  13745. +
  13746. +config ARC_PROMLIB
  13747. + bool
  13748. + depends on MACH_JAZZ || SNI_RM || SGI_IP22 || SGI_IP28 || SGI_IP32
  13749. + default y
  13750. +
  13751. +config ARC64
  13752. + bool
  13753. +
  13754. +config BOOT_ELF64
  13755. + bool
  13756. +
  13757. +menu "CPU selection"
  13758. +
  13759. +choice
  13760. + prompt "CPU type"
  13761. + default CPU_R4X00
  13762. +
  13763. +config CPU_LOONGSON2E
  13764. + bool "Loongson 2E"
  13765. + depends on SYS_HAS_CPU_LOONGSON2E
  13766. + select CPU_LOONGSON2
  13767. + help
  13768. + The Loongson 2E processor implements the MIPS III instruction set
  13769. + with many extensions.
  13770. +
  13771. + It has an internal FPGA northbridge, which is compatible to
  13772. + bonito64.
  13773. +
  13774. +config CPU_LOONGSON2F
  13775. + bool "Loongson 2F"
  13776. + depends on SYS_HAS_CPU_LOONGSON2F
  13777. + select CPU_LOONGSON2
  13778. + select GENERIC_GPIO
  13779. + select ARCH_REQUIRE_GPIOLIB
  13780. + help
  13781. + The Loongson 2F processor implements the MIPS III instruction set
  13782. + with many extensions.
  13783. +
  13784. + Loongson2F have built-in DDR2 and PCIX controller. The PCIX controller
  13785. + have a similar programming interface with FPGA northbridge used in
  13786. + Loongson2E.
  13787. +
  13788. +config CPU_MIPS32_R1
  13789. + bool "MIPS32 Release 1"
  13790. + depends on SYS_HAS_CPU_MIPS32_R1
  13791. + select CPU_HAS_PREFETCH
  13792. + select CPU_SUPPORTS_32BIT_KERNEL
  13793. + select CPU_SUPPORTS_HIGHMEM
  13794. + help
  13795. + Choose this option to build a kernel for release 1 or later of the
  13796. + MIPS32 architecture. Most modern embedded systems with a 32-bit
  13797. + MIPS processor are based on a MIPS32 processor. If you know the
  13798. + specific type of processor in your system, choose those that one
  13799. + otherwise CPU_MIPS32_R1 is a safe bet for any MIPS32 system.
  13800. + Release 2 of the MIPS32 architecture is available since several
  13801. + years so chances are you even have a MIPS32 Release 2 processor
  13802. + in which case you should choose CPU_MIPS32_R2 instead for better
  13803. + performance.
  13804. +
  13805. +config CPU_MIPS32_R2
  13806. + bool "MIPS32 Release 2"
  13807. + depends on SYS_HAS_CPU_MIPS32_R2
  13808. + select CPU_HAS_PREFETCH
  13809. + select CPU_SUPPORTS_32BIT_KERNEL
  13810. + select CPU_SUPPORTS_HIGHMEM
  13811. + help
  13812. + Choose this option to build a kernel for release 2 or later of the
  13813. + MIPS32 architecture. Most modern embedded systems with a 32-bit
  13814. + MIPS processor are based on a MIPS32 processor. If you know the
  13815. + specific type of processor in your system, choose those that one
  13816. + otherwise CPU_MIPS32_R1 is a safe bet for any MIPS32 system.
  13817. +
  13818. +config CPU_MIPS64_R1
  13819. + bool "MIPS64 Release 1"
  13820. + depends on SYS_HAS_CPU_MIPS64_R1
  13821. + select CPU_HAS_PREFETCH
  13822. + select CPU_SUPPORTS_32BIT_KERNEL
  13823. + select CPU_SUPPORTS_64BIT_KERNEL
  13824. + select CPU_SUPPORTS_HIGHMEM
  13825. + select CPU_SUPPORTS_HUGEPAGES
  13826. + help
  13827. + Choose this option to build a kernel for release 1 or later of the
  13828. + MIPS64 architecture. Many modern embedded systems with a 64-bit
  13829. + MIPS processor are based on a MIPS64 processor. If you know the
  13830. + specific type of processor in your system, choose those that one
  13831. + otherwise CPU_MIPS64_R1 is a safe bet for any MIPS64 system.
  13832. + Release 2 of the MIPS64 architecture is available since several
  13833. + years so chances are you even have a MIPS64 Release 2 processor
  13834. + in which case you should choose CPU_MIPS64_R2 instead for better
  13835. + performance.
  13836. +
  13837. +config CPU_MIPS64_R2
  13838. + bool "MIPS64 Release 2"
  13839. + depends on SYS_HAS_CPU_MIPS64_R2
  13840. + select CPU_HAS_PREFETCH
  13841. + select CPU_SUPPORTS_32BIT_KERNEL
  13842. + select CPU_SUPPORTS_64BIT_KERNEL
  13843. + select CPU_SUPPORTS_HIGHMEM
  13844. + select CPU_SUPPORTS_HUGEPAGES
  13845. + help
  13846. + Choose this option to build a kernel for release 2 or later of the
  13847. + MIPS64 architecture. Many modern embedded systems with a 64-bit
  13848. + MIPS processor are based on a MIPS64 processor. If you know the
  13849. + specific type of processor in your system, choose those that one
  13850. + otherwise CPU_MIPS64_R1 is a safe bet for any MIPS64 system.
  13851. +
  13852. +config CPU_R3000
  13853. + bool "R3000"
  13854. + depends on SYS_HAS_CPU_R3000
  13855. + select CPU_HAS_WB
  13856. + select CPU_SUPPORTS_32BIT_KERNEL
  13857. + select CPU_SUPPORTS_HIGHMEM
  13858. + help
  13859. + Please make sure to pick the right CPU type. Linux/MIPS is not
  13860. + designed to be generic, i.e. Kernels compiled for R3000 CPUs will
  13861. + *not* work on R4000 machines and vice versa. However, since most
  13862. + of the supported machines have an R4000 (or similar) CPU, R4x00
  13863. + might be a safe bet. If the resulting kernel does not work,
  13864. + try to recompile with R3000.
  13865. +
  13866. +config CPU_TX39XX
  13867. + bool "R39XX"
  13868. + depends on SYS_HAS_CPU_TX39XX
  13869. + select CPU_SUPPORTS_32BIT_KERNEL
  13870. +
  13871. +config CPU_VR41XX
  13872. + bool "R41xx"
  13873. + depends on SYS_HAS_CPU_VR41XX
  13874. + select CPU_SUPPORTS_32BIT_KERNEL
  13875. + select CPU_SUPPORTS_64BIT_KERNEL
  13876. + help
  13877. + The options selects support for the NEC VR4100 series of processors.
  13878. + Only choose this option if you have one of these processors as a
  13879. + kernel built with this option will not run on any other type of
  13880. + processor or vice versa.
  13881. +
  13882. +config CPU_R4300
  13883. + bool "R4300"
  13884. + depends on SYS_HAS_CPU_R4300
  13885. + select CPU_SUPPORTS_32BIT_KERNEL
  13886. + select CPU_SUPPORTS_64BIT_KERNEL
  13887. + help
  13888. + MIPS Technologies R4300-series processors.
  13889. +
  13890. +config CPU_R4X00
  13891. + bool "R4x00"
  13892. + depends on SYS_HAS_CPU_R4X00
  13893. + select CPU_SUPPORTS_32BIT_KERNEL
  13894. + select CPU_SUPPORTS_64BIT_KERNEL
  13895. + help
  13896. + MIPS Technologies R4000-series processors other than 4300, including
  13897. + the R4000, R4400, R4600, and 4700.
  13898. +
  13899. +config CPU_TX49XX
  13900. + bool "R49XX"
  13901. + depends on SYS_HAS_CPU_TX49XX
  13902. + select CPU_HAS_PREFETCH
  13903. + select CPU_SUPPORTS_32BIT_KERNEL
  13904. + select CPU_SUPPORTS_64BIT_KERNEL
  13905. +
  13906. +config CPU_R5000
  13907. + bool "R5000"
  13908. + depends on SYS_HAS_CPU_R5000
  13909. + select CPU_SUPPORTS_32BIT_KERNEL
  13910. + select CPU_SUPPORTS_64BIT_KERNEL
  13911. + help
  13912. + MIPS Technologies R5000-series processors other than the Nevada.
  13913. +
  13914. +config CPU_R5432
  13915. + bool "R5432"
  13916. + depends on SYS_HAS_CPU_R5432
  13917. + select CPU_SUPPORTS_32BIT_KERNEL
  13918. + select CPU_SUPPORTS_64BIT_KERNEL
  13919. +
  13920. +config CPU_R5500
  13921. + bool "R5500"
  13922. + depends on SYS_HAS_CPU_R5500
  13923. + select CPU_SUPPORTS_32BIT_KERNEL
  13924. + select CPU_SUPPORTS_64BIT_KERNEL
  13925. + select CPU_SUPPORTS_HUGEPAGES
  13926. + help
  13927. + NEC VR5500 and VR5500A series processors implement 64-bit MIPS IV
  13928. + instruction set.
  13929. +
  13930. +config CPU_R6000
  13931. + bool "R6000"
  13932. + depends on EXPERIMENTAL
  13933. + depends on SYS_HAS_CPU_R6000
  13934. + select CPU_SUPPORTS_32BIT_KERNEL
  13935. + help
  13936. + MIPS Technologies R6000 and R6000A series processors. Note these
  13937. + processors are extremely rare and the support for them is incomplete.
  13938. +
  13939. +config CPU_NEVADA
  13940. + bool "RM52xx"
  13941. + depends on SYS_HAS_CPU_NEVADA
  13942. + select CPU_SUPPORTS_32BIT_KERNEL
  13943. + select CPU_SUPPORTS_64BIT_KERNEL
  13944. + help
  13945. + QED / PMC-Sierra RM52xx-series ("Nevada") processors.
  13946. +
  13947. +config CPU_R8000
  13948. + bool "R8000"
  13949. + depends on EXPERIMENTAL
  13950. + depends on SYS_HAS_CPU_R8000
  13951. + select CPU_HAS_PREFETCH
  13952. + select CPU_SUPPORTS_64BIT_KERNEL
  13953. + help
  13954. + MIPS Technologies R8000 processors. Note these processors are
  13955. + uncommon and the support for them is incomplete.
  13956. +
  13957. +config CPU_R10000
  13958. + bool "R10000"
  13959. + depends on SYS_HAS_CPU_R10000
  13960. + select CPU_HAS_PREFETCH
  13961. + select CPU_SUPPORTS_32BIT_KERNEL
  13962. + select CPU_SUPPORTS_64BIT_KERNEL
  13963. + select CPU_SUPPORTS_HIGHMEM
  13964. + help
  13965. + MIPS Technologies R10000-series processors.
  13966. +
  13967. +config CPU_RM7000
  13968. + bool "RM7000"
  13969. + depends on SYS_HAS_CPU_RM7000
  13970. + select CPU_HAS_PREFETCH
  13971. + select CPU_SUPPORTS_32BIT_KERNEL
  13972. + select CPU_SUPPORTS_64BIT_KERNEL
  13973. + select CPU_SUPPORTS_HIGHMEM
  13974. +
  13975. +config CPU_RM9000
  13976. + bool "RM9000"
  13977. + depends on SYS_HAS_CPU_RM9000
  13978. + select CPU_HAS_PREFETCH
  13979. + select CPU_SUPPORTS_32BIT_KERNEL
  13980. + select CPU_SUPPORTS_64BIT_KERNEL
  13981. + select CPU_SUPPORTS_HIGHMEM
  13982. + select WEAK_ORDERING
  13983. +
  13984. +config CPU_SB1
  13985. + bool "SB1"
  13986. + depends on SYS_HAS_CPU_SB1
  13987. + select CPU_SUPPORTS_32BIT_KERNEL
  13988. + select CPU_SUPPORTS_64BIT_KERNEL
  13989. + select CPU_SUPPORTS_HIGHMEM
  13990. + select WEAK_ORDERING
  13991. +
  13992. +config CPU_CAVIUM_OCTEON
  13993. + bool "Cavium Octeon processor"
  13994. + depends on SYS_HAS_CPU_CAVIUM_OCTEON
  13995. + select CPU_HAS_PREFETCH
  13996. + select CPU_SUPPORTS_64BIT_KERNEL
  13997. + select SYS_SUPPORTS_SMP
  13998. + select NR_CPUS_DEFAULT_16
  13999. + select WEAK_ORDERING
  14000. + select CPU_SUPPORTS_HIGHMEM
  14001. + select CPU_SUPPORTS_HUGEPAGES
  14002. + help
  14003. + The Cavium Octeon processor is a highly integrated chip containing
  14004. + many ethernet hardware widgets for networking tasks. The processor
  14005. + can have up to 16 Mips64v2 cores and 8 integrated gigabit ethernets.
  14006. + Full details can be found at http://www.caviumnetworks.com.
  14007. +
  14008. +config CPU_BMIPS3300
  14009. + bool "BMIPS3300"
  14010. + depends on SYS_HAS_CPU_BMIPS3300
  14011. + select DMA_NONCOHERENT
  14012. + select IRQ_CPU
  14013. + select SWAP_IO_SPACE
  14014. + select SYS_SUPPORTS_32BIT_KERNEL
  14015. + select WEAK_ORDERING
  14016. + help
  14017. + Broadcom BMIPS3300 processors.
  14018. +
  14019. +config CPU_BMIPS4350
  14020. + bool "BMIPS4350"
  14021. + depends on SYS_HAS_CPU_BMIPS4350
  14022. + select CPU_SUPPORTS_32BIT_KERNEL
  14023. + select DMA_NONCOHERENT
  14024. + select IRQ_CPU
  14025. + select SWAP_IO_SPACE
  14026. + select SYS_SUPPORTS_SMP
  14027. + select SYS_SUPPORTS_HOTPLUG_CPU
  14028. + select WEAK_ORDERING
  14029. + help
  14030. + Broadcom BMIPS4350 ("VIPER") processors.
  14031. +
  14032. +config CPU_BMIPS4380
  14033. + bool "BMIPS4380"
  14034. + depends on SYS_HAS_CPU_BMIPS4380
  14035. + select CPU_SUPPORTS_32BIT_KERNEL
  14036. + select DMA_NONCOHERENT
  14037. + select IRQ_CPU
  14038. + select SWAP_IO_SPACE
  14039. + select SYS_SUPPORTS_SMP
  14040. + select SYS_SUPPORTS_HOTPLUG_CPU
  14041. + select WEAK_ORDERING
  14042. + help
  14043. + Broadcom BMIPS4380 processors.
  14044. +
  14045. +config CPU_BMIPS5000
  14046. + bool "BMIPS5000"
  14047. + depends on SYS_HAS_CPU_BMIPS5000
  14048. + select CPU_SUPPORTS_32BIT_KERNEL
  14049. + select CPU_SUPPORTS_HIGHMEM
  14050. + select DMA_NONCOHERENT
  14051. + select IRQ_CPU
  14052. + select SWAP_IO_SPACE
  14053. + select SYS_SUPPORTS_SMP
  14054. + select SYS_SUPPORTS_HOTPLUG_CPU
  14055. + select WEAK_ORDERING
  14056. + help
  14057. + Broadcom BMIPS5000 processors.
  14058. +
  14059. +endchoice
  14060. +
  14061. +if CPU_LOONGSON2F
  14062. +config CPU_NOP_WORKAROUNDS
  14063. + bool
  14064. +
  14065. +config CPU_JUMP_WORKAROUNDS
  14066. + bool
  14067. +
  14068. +config CPU_LOONGSON2F_WORKAROUNDS
  14069. + bool "Loongson 2F Workarounds"
  14070. + default y
  14071. + select CPU_NOP_WORKAROUNDS
  14072. + select CPU_JUMP_WORKAROUNDS
  14073. + help
  14074. + Loongson 2F01 / 2F02 processors have the NOP & JUMP issues which
  14075. + require workarounds. Without workarounds the system may hang
  14076. + unexpectedly. For more information please refer to the gas
  14077. + -mfix-loongson2f-nop and -mfix-loongson2f-jump options.
  14078. +
  14079. + Loongson 2F03 and later have fixed these issues and no workarounds
  14080. + are needed. The workarounds have no significant side effect on them
  14081. + but may decrease the performance of the system so this option should
  14082. + be disabled unless the kernel is intended to be run on 2F01 or 2F02
  14083. + systems.
  14084. +
  14085. + If unsure, please say Y.
  14086. +endif # CPU_LOONGSON2F
  14087. +
  14088. +config SYS_SUPPORTS_ZBOOT
  14089. + bool
  14090. + select HAVE_KERNEL_GZIP
  14091. + select HAVE_KERNEL_BZIP2
  14092. + select HAVE_KERNEL_LZMA
  14093. + select HAVE_KERNEL_LZO
  14094. +
  14095. +config SYS_SUPPORTS_ZBOOT_UART16550
  14096. + bool
  14097. + select SYS_SUPPORTS_ZBOOT
  14098. +
  14099. +config CPU_LOONGSON2
  14100. + bool
  14101. + select CPU_SUPPORTS_32BIT_KERNEL
  14102. + select CPU_SUPPORTS_64BIT_KERNEL
  14103. + select CPU_SUPPORTS_HIGHMEM
  14104. +
  14105. +config SYS_HAS_CPU_LOONGSON2E
  14106. + bool
  14107. +
  14108. +config SYS_HAS_CPU_LOONGSON2F
  14109. + bool
  14110. + select CPU_SUPPORTS_CPUFREQ
  14111. + select CPU_SUPPORTS_ADDRWINCFG if 64BIT
  14112. + select CPU_SUPPORTS_UNCACHED_ACCELERATED
  14113. +
  14114. +config SYS_HAS_CPU_MIPS32_R1
  14115. + bool
  14116. +
  14117. +config SYS_HAS_CPU_MIPS32_R2
  14118. + bool
  14119. +
  14120. +config SYS_HAS_CPU_MIPS64_R1
  14121. + bool
  14122. +
  14123. +config SYS_HAS_CPU_MIPS64_R2
  14124. + bool
  14125. +
  14126. +config SYS_HAS_CPU_R3000
  14127. + bool
  14128. +
  14129. +config SYS_HAS_CPU_TX39XX
  14130. + bool
  14131. +
  14132. +config SYS_HAS_CPU_VR41XX
  14133. + bool
  14134. +
  14135. +config SYS_HAS_CPU_R4300
  14136. + bool
  14137. +
  14138. +config SYS_HAS_CPU_R4X00
  14139. + bool
  14140. +
  14141. +config SYS_HAS_CPU_TX49XX
  14142. + bool
  14143. +
  14144. +config SYS_HAS_CPU_R5000
  14145. + bool
  14146. +
  14147. +config SYS_HAS_CPU_R5432
  14148. + bool
  14149. +
  14150. +config SYS_HAS_CPU_R5500
  14151. + bool
  14152. +
  14153. +config SYS_HAS_CPU_R6000
  14154. + bool
  14155. +
  14156. +config SYS_HAS_CPU_NEVADA
  14157. + bool
  14158. +
  14159. +config SYS_HAS_CPU_R8000
  14160. + bool
  14161. +
  14162. +config SYS_HAS_CPU_R10000
  14163. + bool
  14164. +
  14165. +config SYS_HAS_CPU_RM7000
  14166. + bool
  14167. +
  14168. +config SYS_HAS_CPU_RM9000
  14169. + bool
  14170. +
  14171. +config SYS_HAS_CPU_SB1
  14172. + bool
  14173. +
  14174. +config SYS_HAS_CPU_CAVIUM_OCTEON
  14175. + bool
  14176. +
  14177. +config SYS_HAS_CPU_BMIPS3300
  14178. + bool
  14179. +
  14180. +config SYS_HAS_CPU_BMIPS4350
  14181. + bool
  14182. +
  14183. +config SYS_HAS_CPU_BMIPS4380
  14184. + bool
  14185. +
  14186. +config SYS_HAS_CPU_BMIPS5000
  14187. + bool
  14188. +
  14189. +#
  14190. +# CPU may reorder R->R, R->W, W->R, W->W
  14191. +# Reordering beyond LL and SC is handled in WEAK_REORDERING_BEYOND_LLSC
  14192. +#
  14193. +config WEAK_ORDERING
  14194. + bool
  14195. +
  14196. +#
  14197. +# CPU may reorder reads and writes beyond LL/SC
  14198. +# CPU may reorder R->LL, R->LL, W->LL, W->LL, R->SC, R->SC, W->SC, W->SC
  14199. +#
  14200. +config WEAK_REORDERING_BEYOND_LLSC
  14201. + bool
  14202. +endmenu
  14203. +
  14204. +#
  14205. +# These two indicate any level of the MIPS32 and MIPS64 architecture
  14206. +#
  14207. +config CPU_MIPS32
  14208. + bool
  14209. + default y if CPU_MIPS32_R1 || CPU_MIPS32_R2
  14210. +
  14211. +config CPU_MIPS64
  14212. + bool
  14213. + default y if CPU_MIPS64_R1 || CPU_MIPS64_R2
  14214. +
  14215. +#
  14216. +# These two indicate the revision of the architecture, either Release 1 or Release 2
  14217. +#
  14218. +config CPU_MIPSR1
  14219. + bool
  14220. + default y if CPU_MIPS32_R1 || CPU_MIPS64_R1
  14221. +
  14222. +config CPU_MIPSR2
  14223. + bool
  14224. + default y if CPU_MIPS32_R2 || CPU_MIPS64_R2 || CPU_CAVIUM_OCTEON
  14225. +
  14226. +config SYS_SUPPORTS_32BIT_KERNEL
  14227. + bool
  14228. +config SYS_SUPPORTS_64BIT_KERNEL
  14229. + bool
  14230. +config CPU_SUPPORTS_32BIT_KERNEL
  14231. + bool
  14232. +config CPU_SUPPORTS_64BIT_KERNEL
  14233. + bool
  14234. +config CPU_SUPPORTS_CPUFREQ
  14235. + bool
  14236. +config CPU_SUPPORTS_ADDRWINCFG
  14237. + bool
  14238. +config CPU_SUPPORTS_HUGEPAGES
  14239. + bool
  14240. +config CPU_SUPPORTS_UNCACHED_ACCELERATED
  14241. + bool
  14242. +config MIPS_PGD_C0_CONTEXT
  14243. + bool
  14244. + default y if 64BIT && CPU_MIPSR2
  14245. +
  14246. +#
  14247. +# Set to y for ptrace access to watch registers.
  14248. +#
  14249. +config HARDWARE_WATCHPOINTS
  14250. + bool
  14251. + default y if CPU_MIPSR1 || CPU_MIPSR2
  14252. +
  14253. +menu "Kernel type"
  14254. +
  14255. +choice
  14256. +
  14257. + prompt "Kernel code model"
  14258. + help
  14259. + You should only select this option if you have a workload that
  14260. + actually benefits from 64-bit processing or if your machine has
  14261. + large memory. You will only be presented a single option in this
  14262. + menu if your system does not support both 32-bit and 64-bit kernels.
  14263. +
  14264. +config 32BIT
  14265. + bool "32-bit kernel"
  14266. + depends on CPU_SUPPORTS_32BIT_KERNEL && SYS_SUPPORTS_32BIT_KERNEL
  14267. + select TRAD_SIGNALS
  14268. + help
  14269. + Select this option if you want to build a 32-bit kernel.
  14270. +config 64BIT
  14271. + bool "64-bit kernel"
  14272. + depends on CPU_SUPPORTS_64BIT_KERNEL && SYS_SUPPORTS_64BIT_KERNEL
  14273. + select HAVE_SYSCALL_WRAPPERS
  14274. + help
  14275. + Select this option if you want to build a 64-bit kernel.
  14276. +
  14277. +endchoice
  14278. +
  14279. +choice
  14280. + prompt "Kernel page size"
  14281. + default PAGE_SIZE_4KB
  14282. +
  14283. +config PAGE_SIZE_4KB
  14284. + bool "4kB"
  14285. + depends on !CPU_LOONGSON2
  14286. + help
  14287. + This option select the standard 4kB Linux page size. On some
  14288. + R3000-family processors this is the only available page size. Using
  14289. + 4kB page size will minimize memory consumption and is therefore
  14290. + recommended for low memory systems.
  14291. +
  14292. +config PAGE_SIZE_8KB
  14293. + bool "8kB"
  14294. + depends on (EXPERIMENTAL && CPU_R8000) || CPU_CAVIUM_OCTEON
  14295. + help
  14296. + Using 8kB page size will result in higher performance kernel at
  14297. + the price of higher memory consumption. This option is available
  14298. + only on R8000 and cnMIPS processors. Note that you will need a
  14299. + suitable Linux distribution to support this.
  14300. +
  14301. +config PAGE_SIZE_16KB
  14302. + bool "16kB"
  14303. + depends on !CPU_R3000 && !CPU_TX39XX
  14304. + help
  14305. + Using 16kB page size will result in higher performance kernel at
  14306. + the price of higher memory consumption. This option is available on
  14307. + all non-R3000 family processors. Note that you will need a suitable
  14308. + Linux distribution to support this.
  14309. +
  14310. +config PAGE_SIZE_32KB
  14311. + bool "32kB"
  14312. + depends on CPU_CAVIUM_OCTEON
  14313. + help
  14314. + Using 32kB page size will result in higher performance kernel at
  14315. + the price of higher memory consumption. This option is available
  14316. + only on cnMIPS cores. Note that you will need a suitable Linux
  14317. + distribution to support this.
  14318. +
  14319. +config PAGE_SIZE_64KB
  14320. + bool "64kB"
  14321. + depends on EXPERIMENTAL && !CPU_R3000 && !CPU_TX39XX
  14322. + help
  14323. + Using 64kB page size will result in higher performance kernel at
  14324. + the price of higher memory consumption. This option is available on
  14325. + all non-R3000 family processor. Not that at the time of this
  14326. + writing this option is still high experimental.
  14327. +
  14328. +endchoice
  14329. +
  14330. +config FORCE_MAX_ZONEORDER
  14331. + int "Maximum zone order"
  14332. + range 13 64 if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_32KB
  14333. + default "13" if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_32KB
  14334. + range 12 64 if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_16KB
  14335. + default "12" if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_16KB
  14336. + range 11 64
  14337. + default "11"
  14338. + help
  14339. + The kernel memory allocator divides physically contiguous memory
  14340. + blocks into "zones", where each zone is a power of two number of
  14341. + pages. This option selects the largest power of two that the kernel
  14342. + keeps in the memory allocator. If you need to allocate very large
  14343. + blocks of physically contiguous memory, then you may need to
  14344. + increase this value.
  14345. +
  14346. + This config option is actually maximum order plus one. For example,
  14347. + a value of 11 means that the largest free memory block is 2^10 pages.
  14348. +
  14349. + The page size is not necessarily 4KB. Keep this in mind
  14350. + when choosing a value for this option.
  14351. +
  14352. +config BOARD_SCACHE
  14353. + bool
  14354. +
  14355. +config IP22_CPU_SCACHE
  14356. + bool
  14357. + select BOARD_SCACHE
  14358. +
  14359. +#
  14360. +# Support for a MIPS32 / MIPS64 style S-caches
  14361. +#
  14362. +config MIPS_CPU_SCACHE
  14363. + bool
  14364. + select BOARD_SCACHE
  14365. +
  14366. +config R5000_CPU_SCACHE
  14367. + bool
  14368. + select BOARD_SCACHE
  14369. +
  14370. +config RM7000_CPU_SCACHE
  14371. + bool
  14372. + select BOARD_SCACHE
  14373. +
  14374. +config SIBYTE_DMA_PAGEOPS
  14375. + bool "Use DMA to clear/copy pages"
  14376. + depends on CPU_SB1
  14377. + help
  14378. + Instead of using the CPU to zero and copy pages, use a Data Mover
  14379. + channel. These DMA channels are otherwise unused by the standard
  14380. + SiByte Linux port. Seems to give a small performance benefit.
  14381. +
  14382. +config CPU_HAS_PREFETCH
  14383. + bool
  14384. +
  14385. +choice
  14386. + prompt "MIPS MT options"
  14387. +
  14388. +config MIPS_MT_DISABLED
  14389. + bool "Disable multithreading support."
  14390. + help
  14391. + Use this option if your workload can't take advantage of
  14392. + MIPS hardware multithreading support. On systems that don't have
  14393. + the option of an MT-enabled processor this option will be the only
  14394. + option in this menu.
  14395. +
  14396. +config MIPS_MT_SMP
  14397. + bool "Use 1 TC on each available VPE for SMP"
  14398. + depends on SYS_SUPPORTS_MULTITHREADING
  14399. + select CPU_MIPSR2_IRQ_VI
  14400. + select CPU_MIPSR2_IRQ_EI
  14401. + select MIPS_MT
  14402. + select NR_CPUS_DEFAULT_2
  14403. + select SMP
  14404. + select SYS_SUPPORTS_SCHED_SMT if SMP
  14405. + select SYS_SUPPORTS_SMP
  14406. + select SMP_UP
  14407. + help
  14408. + This is a kernel model which is known a VSMP but lately has been
  14409. + marketesed into SMVP.
  14410. + Virtual SMP uses the processor's VPEs to implement virtual
  14411. + processors. In currently available configuration of the 34K processor
  14412. + this allows for a dual processor. Both processors will share the same
  14413. + primary caches; each will obtain the half of the TLB for it's own
  14414. + exclusive use. For a layman this model can be described as similar to
  14415. + what Intel calls Hyperthreading.
  14416. +
  14417. + For further information see http://www.linux-mips.org/wiki/34K#VSMP
  14418. +
  14419. +config MIPS_MT_SMTC
  14420. + bool "SMTC: Use all TCs on all VPEs for SMP"
  14421. + depends on CPU_MIPS32_R2
  14422. + #depends on CPU_MIPS64_R2 # once there is hardware ...
  14423. + depends on SYS_SUPPORTS_MULTITHREADING
  14424. + select CPU_MIPSR2_IRQ_VI
  14425. + select CPU_MIPSR2_IRQ_EI
  14426. + select MIPS_MT
  14427. + select NR_CPUS_DEFAULT_8
  14428. + select SMP
  14429. + select SYS_SUPPORTS_SMP
  14430. + select SMP_UP
  14431. + help
  14432. + This is a kernel model which is known a SMTC or lately has been
  14433. + marketesed into SMVP.
  14434. + is presenting the available TC's of the core as processors to Linux.
  14435. + On currently available 34K processors this means a Linux system will
  14436. + see up to 5 processors. The implementation of the SMTC kernel differs
  14437. + significantly from VSMP and cannot efficiently coexist in the same
  14438. + kernel binary so the choice between VSMP and SMTC is a compile time
  14439. + decision.
  14440. +
  14441. + For further information see http://www.linux-mips.org/wiki/34K#SMTC
  14442. +
  14443. +endchoice
  14444. +
  14445. +config MIPS_MT
  14446. + bool
  14447. +
  14448. +config SCHED_SMT
  14449. + bool "SMT (multithreading) scheduler support"
  14450. + depends on SYS_SUPPORTS_SCHED_SMT
  14451. + default n
  14452. + help
  14453. + SMT scheduler support improves the CPU scheduler's decision making
  14454. + when dealing with MIPS MT enabled cores at a cost of slightly
  14455. + increased overhead in some places. If unsure say N here.
  14456. +
  14457. +config SYS_SUPPORTS_SCHED_SMT
  14458. + bool
  14459. +
  14460. +
  14461. +config SYS_SUPPORTS_MULTITHREADING
  14462. + bool
  14463. +
  14464. +config MIPS_MT_FPAFF
  14465. + bool "Dynamic FPU affinity for FP-intensive threads"
  14466. + default y
  14467. + depends on MIPS_MT_SMP || MIPS_MT_SMTC
  14468. +
  14469. +config MIPS_VPE_LOADER
  14470. + bool "VPE loader support."
  14471. + depends on SYS_SUPPORTS_MULTITHREADING
  14472. + select CPU_MIPSR2_IRQ_VI
  14473. + select CPU_MIPSR2_IRQ_EI
  14474. + select MIPS_MT
  14475. + help
  14476. + Includes a loader for loading an elf relocatable object
  14477. + onto another VPE and running it.
  14478. +
  14479. +config MIPS_MT_SMTC_IM_BACKSTOP
  14480. + bool "Use per-TC register bits as backstop for inhibited IM bits"
  14481. + depends on MIPS_MT_SMTC
  14482. + default n
  14483. + help
  14484. + To support multiple TC microthreads acting as "CPUs" within
  14485. + a VPE, VPE-wide interrupt mask bits must be specially manipulated
  14486. + during interrupt handling. To support legacy drivers and interrupt
  14487. + controller management code, SMTC has a "backstop" to track and
  14488. + if necessary restore the interrupt mask. This has some performance
  14489. + impact on interrupt service overhead.
  14490. +
  14491. +config MIPS_MT_SMTC_IRQAFF
  14492. + bool "Support IRQ affinity API"
  14493. + depends on MIPS_MT_SMTC
  14494. + default n
  14495. + help
  14496. + Enables SMP IRQ affinity API (/proc/irq/*/smp_affinity, etc.)
  14497. + for SMTC Linux kernel. Requires platform support, of which
  14498. + an example can be found in the MIPS kernel i8259 and Malta
  14499. + platform code. Adds some overhead to interrupt dispatch, and
  14500. + should be used only if you know what you are doing.
  14501. +
  14502. +config MIPS_VPE_LOADER_TOM
  14503. + bool "Load VPE program into memory hidden from linux"
  14504. + depends on MIPS_VPE_LOADER
  14505. + default y
  14506. + help
  14507. + The loader can use memory that is present but has been hidden from
  14508. + Linux using the kernel command line option "mem=xxMB". It's up to
  14509. + you to ensure the amount you put in the option and the space your
  14510. + program requires is less or equal to the amount physically present.
  14511. +
  14512. +# this should possibly be in drivers/char, but it is rather cpu related. Hmmm
  14513. +config MIPS_VPE_APSP_API
  14514. + bool "Enable support for AP/SP API (RTLX)"
  14515. + depends on MIPS_VPE_LOADER
  14516. + help
  14517. +
  14518. +config MIPS_APSP_KSPD
  14519. + bool "Enable KSPD"
  14520. + depends on MIPS_VPE_APSP_API
  14521. + default y
  14522. + help
  14523. + KSPD is a kernel daemon that accepts syscall requests from the SP
  14524. + side, actions them and returns the results. It also handles the
  14525. + "exit" syscall notifying other kernel modules the SP program is
  14526. + exiting. You probably want to say yes here.
  14527. +
  14528. +config MIPS_CMP
  14529. + bool "MIPS CMP framework support"
  14530. + depends on SYS_SUPPORTS_MIPS_CMP
  14531. + select SYNC_R4K
  14532. + select SYS_SUPPORTS_SMP
  14533. + select SYS_SUPPORTS_SCHED_SMT if SMP
  14534. + select WEAK_ORDERING
  14535. + default n
  14536. + help
  14537. + This is a placeholder option for the GCMP work. It will need to
  14538. + be handled differently...
  14539. +
  14540. +config SB1_PASS_1_WORKAROUNDS
  14541. + bool
  14542. + depends on CPU_SB1_PASS_1
  14543. + default y
  14544. +
  14545. +config SB1_PASS_2_WORKAROUNDS
  14546. + bool
  14547. + depends on CPU_SB1 && (CPU_SB1_PASS_2_2 || CPU_SB1_PASS_2)
  14548. + default y
  14549. +
  14550. +config SB1_PASS_2_1_WORKAROUNDS
  14551. + bool
  14552. + depends on CPU_SB1 && CPU_SB1_PASS_2
  14553. + default y
  14554. +
  14555. +config 64BIT_PHYS_ADDR
  14556. + bool
  14557. +
  14558. +config ARCH_PHYS_ADDR_T_64BIT
  14559. + def_bool 64BIT_PHYS_ADDR
  14560. +
  14561. +config CPU_HAS_SMARTMIPS
  14562. + depends on SYS_SUPPORTS_SMARTMIPS
  14563. + bool "Support for the SmartMIPS ASE"
  14564. + help
  14565. + SmartMIPS is a extension of the MIPS32 architecture aimed at
  14566. + increased security at both hardware and software level for
  14567. + smartcards. Enabling this option will allow proper use of the
  14568. + SmartMIPS instructions by Linux applications. However a kernel with
  14569. + this option will not work on a MIPS core without SmartMIPS core. If
  14570. + you don't know you probably don't have SmartMIPS and should say N
  14571. + here.
  14572. +
  14573. +config CPU_HAS_WB
  14574. + bool
  14575. +
  14576. +#
  14577. +# Vectored interrupt mode is an R2 feature
  14578. +#
  14579. +config CPU_MIPSR2_IRQ_VI
  14580. + bool
  14581. +
  14582. +#
  14583. +# Extended interrupt mode is an R2 feature
  14584. +#
  14585. +config CPU_MIPSR2_IRQ_EI
  14586. + bool
  14587. +
  14588. +config CPU_HAS_SYNC
  14589. + bool
  14590. + depends on !CPU_R3000
  14591. + default y
  14592. +
  14593. +config GENERIC_CLOCKEVENTS_BROADCAST
  14594. + bool
  14595. +
  14596. +#
  14597. +# CPU non-features
  14598. +#
  14599. +config CPU_DADDI_WORKAROUNDS
  14600. + bool
  14601. +
  14602. +config CPU_R4000_WORKAROUNDS
  14603. + bool
  14604. + select CPU_R4400_WORKAROUNDS
  14605. +
  14606. +config CPU_R4400_WORKAROUNDS
  14607. + bool
  14608. +
  14609. +#
  14610. +# - Highmem only makes sense for the 32-bit kernel.
  14611. +# - The current highmem code will only work properly on physically indexed
  14612. +# caches such as R3000, SB1, R7000 or those that look like they're virtually
  14613. +# indexed such as R4000/R4400 SC and MC versions or R10000. So for the
  14614. +# moment we protect the user and offer the highmem option only on machines
  14615. +# where it's known to be safe. This will not offer highmem on a few systems
  14616. +# such as MIPS32 and MIPS64 CPUs which may have virtual and physically
  14617. +# indexed CPUs but we're playing safe.
  14618. +# - We use SYS_SUPPORTS_HIGHMEM to offer highmem only for systems where we
  14619. +# know they might have memory configurations that could make use of highmem
  14620. +# support.
  14621. +#
  14622. +config HIGHMEM
  14623. + bool "High Memory Support"
  14624. + depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM
  14625. +
  14626. +config CPU_SUPPORTS_HIGHMEM
  14627. + bool
  14628. +
  14629. +config SYS_SUPPORTS_HIGHMEM
  14630. + bool
  14631. +
  14632. +config SYS_SUPPORTS_SMARTMIPS
  14633. + bool
  14634. +
  14635. +config ARCH_FLATMEM_ENABLE
  14636. + def_bool y
  14637. + depends on !NUMA && !CPU_LOONGSON2
  14638. +
  14639. +config ARCH_DISCONTIGMEM_ENABLE
  14640. + bool
  14641. + default y if SGI_IP27
  14642. + help
  14643. + Say Y to support efficient handling of discontiguous physical memory,
  14644. + for architectures which are either NUMA (Non-Uniform Memory Access)
  14645. + or have huge holes in the physical address space for other reasons.
  14646. + See <file:Documentation/vm/numa> for more.
  14647. +
  14648. +config ARCH_POPULATES_NODE_MAP
  14649. + def_bool y
  14650. +
  14651. +config ARCH_SPARSEMEM_ENABLE
  14652. + bool
  14653. + select SPARSEMEM_STATIC
  14654. +
  14655. +config NUMA
  14656. + bool "NUMA Support"
  14657. + depends on SYS_SUPPORTS_NUMA
  14658. + help
  14659. + Say Y to compile the kernel to support NUMA (Non-Uniform Memory
  14660. + Access). This option improves performance on systems with more
  14661. + than two nodes; on two node systems it is generally better to
  14662. + leave it disabled; on single node systems disable this option
  14663. + disabled.
  14664. +
  14665. +config SYS_SUPPORTS_NUMA
  14666. + bool
  14667. +
  14668. +config NODES_SHIFT
  14669. + int
  14670. + default "6"
  14671. + depends on NEED_MULTIPLE_NODES
  14672. +
  14673. +config HW_PERF_EVENTS
  14674. + bool "Enable hardware performance counter support for perf events"
  14675. + depends on PERF_EVENTS && !MIPS_MT_SMTC && OPROFILE=n && CPU_MIPS32
  14676. + default y
  14677. + help
  14678. + Enable hardware performance counter support for perf events. If
  14679. + disabled, perf events will use software events only.
  14680. +
  14681. +source "mm/Kconfig"
  14682. +
  14683. +config SMP
  14684. + bool "Multi-Processing support"
  14685. + depends on SYS_SUPPORTS_SMP
  14686. + select IRQ_PER_CPU
  14687. + select USE_GENERIC_SMP_HELPERS
  14688. + help
  14689. + This enables support for systems with more than one CPU. If you have
  14690. + a system with only one CPU, like most personal computers, say N. If
  14691. + you have a system with more than one CPU, say Y.
  14692. +
  14693. + If you say N here, the kernel will run on single and multiprocessor
  14694. + machines, but will use only one CPU of a multiprocessor machine. If
  14695. + you say Y here, the kernel will run on many, but not all,
  14696. + singleprocessor machines. On a singleprocessor machine, the kernel
  14697. + will run faster if you say N here.
  14698. +
  14699. + People using multiprocessor machines who say Y here should also say
  14700. + Y to "Enhanced Real Time Clock Support", below.
  14701. +
  14702. + See also the SMP-HOWTO available at
  14703. + <http://www.tldp.org/docs.html#howto>.
  14704. +
  14705. + If you don't know what to do here, say N.
  14706. +
  14707. +config SMP_UP
  14708. + bool
  14709. +
  14710. +config SYS_SUPPORTS_MIPS_CMP
  14711. + bool
  14712. +
  14713. +config SYS_SUPPORTS_SMP
  14714. + bool
  14715. +
  14716. +config NR_CPUS_DEFAULT_1
  14717. + bool
  14718. +
  14719. +config NR_CPUS_DEFAULT_2
  14720. + bool
  14721. +
  14722. +config NR_CPUS_DEFAULT_4
  14723. + bool
  14724. +
  14725. +config NR_CPUS_DEFAULT_8
  14726. + bool
  14727. +
  14728. +config NR_CPUS_DEFAULT_16
  14729. + bool
  14730. +
  14731. +config NR_CPUS_DEFAULT_32
  14732. + bool
  14733. +
  14734. +config NR_CPUS_DEFAULT_64
  14735. + bool
  14736. +
  14737. +config NR_CPUS
  14738. + int "Maximum number of CPUs (2-64)"
  14739. + range 1 64 if NR_CPUS_DEFAULT_1
  14740. + depends on SMP
  14741. + default "1" if NR_CPUS_DEFAULT_1
  14742. + default "2" if NR_CPUS_DEFAULT_2
  14743. + default "4" if NR_CPUS_DEFAULT_4
  14744. + default "8" if NR_CPUS_DEFAULT_8
  14745. + default "16" if NR_CPUS_DEFAULT_16
  14746. + default "32" if NR_CPUS_DEFAULT_32
  14747. + default "64" if NR_CPUS_DEFAULT_64
  14748. + help
  14749. + This allows you to specify the maximum number of CPUs which this
  14750. + kernel will support. The maximum supported value is 32 for 32-bit
  14751. + kernel and 64 for 64-bit kernels; the minimum value which makes
  14752. + sense is 1 for Qemu (useful only for kernel debugging purposes)
  14753. + and 2 for all others.
  14754. +
  14755. + This is purely to save memory - each supported CPU adds
  14756. + approximately eight kilobytes to the kernel image. For best
  14757. + performance should round up your number of processors to the next
  14758. + power of two.
  14759. +
  14760. +source "kernel/time/Kconfig"
  14761. +
  14762. +#
  14763. +# Timer Interrupt Frequency Configuration
  14764. +#
  14765. +
  14766. +choice
  14767. + prompt "Timer frequency"
  14768. + default HZ_250
  14769. + help
  14770. + Allows the configuration of the timer frequency.
  14771. +
  14772. + config HZ_48
  14773. + bool "48 HZ" if SYS_SUPPORTS_48HZ || SYS_SUPPORTS_ARBIT_HZ
  14774. +
  14775. + config HZ_100
  14776. + bool "100 HZ" if SYS_SUPPORTS_100HZ || SYS_SUPPORTS_ARBIT_HZ
  14777. +
  14778. + config HZ_128
  14779. + bool "128 HZ" if SYS_SUPPORTS_128HZ || SYS_SUPPORTS_ARBIT_HZ
  14780. +
  14781. + config HZ_250
  14782. + bool "250 HZ" if SYS_SUPPORTS_250HZ || SYS_SUPPORTS_ARBIT_HZ
  14783. +
  14784. + config HZ_256
  14785. + bool "256 HZ" if SYS_SUPPORTS_256HZ || SYS_SUPPORTS_ARBIT_HZ
  14786. +
  14787. + config HZ_1000
  14788. + bool "1000 HZ" if SYS_SUPPORTS_1000HZ || SYS_SUPPORTS_ARBIT_HZ
  14789. +
  14790. + config HZ_1024
  14791. + bool "1024 HZ" if SYS_SUPPORTS_1024HZ || SYS_SUPPORTS_ARBIT_HZ
  14792. +
  14793. +endchoice
  14794. +
  14795. +config SYS_SUPPORTS_48HZ
  14796. + bool
  14797. +
  14798. +config SYS_SUPPORTS_100HZ
  14799. + bool
  14800. +
  14801. +config SYS_SUPPORTS_128HZ
  14802. + bool
  14803. +
  14804. +config SYS_SUPPORTS_250HZ
  14805. + bool
  14806. +
  14807. +config SYS_SUPPORTS_256HZ
  14808. + bool
  14809. +
  14810. +config SYS_SUPPORTS_1000HZ
  14811. + bool
  14812. +
  14813. +config SYS_SUPPORTS_1024HZ
  14814. + bool
  14815. +
  14816. +config SYS_SUPPORTS_ARBIT_HZ
  14817. + bool
  14818. + default y if !SYS_SUPPORTS_48HZ && !SYS_SUPPORTS_100HZ && \
  14819. + !SYS_SUPPORTS_128HZ && !SYS_SUPPORTS_250HZ && \
  14820. + !SYS_SUPPORTS_256HZ && !SYS_SUPPORTS_1000HZ && \
  14821. + !SYS_SUPPORTS_1024HZ
  14822. +
  14823. +config HZ
  14824. + int
  14825. + default 48 if HZ_48
  14826. + default 100 if HZ_100
  14827. + default 128 if HZ_128
  14828. + default 250 if HZ_250
  14829. + default 256 if HZ_256
  14830. + default 1000 if HZ_1000
  14831. + default 1024 if HZ_1024
  14832. +
  14833. +source "kernel/Kconfig.preempt"
  14834. +
  14835. +config MIPS_INSANE_LARGE
  14836. + bool "Support for large 64-bit configurations"
  14837. + depends on CPU_R10000 && 64BIT
  14838. + help
  14839. + MIPS R10000 does support a 44 bit / 16TB address space as opposed to
  14840. + previous 64-bit processors which only supported 40 bit / 1TB. If you
  14841. + need processes of more than 1TB virtual address space, say Y here.
  14842. + This will result in additional memory usage, so it is not
  14843. + recommended for normal users.
  14844. +
  14845. +config KEXEC
  14846. + bool "Kexec system call (EXPERIMENTAL)"
  14847. + depends on EXPERIMENTAL
  14848. + help
  14849. + kexec is a system call that implements the ability to shutdown your
  14850. + current kernel, and to start another kernel. It is like a reboot
  14851. + but it is independent of the system firmware. And like a reboot
  14852. + you can start any kernel with it, not just Linux.
  14853. +
  14854. + The name comes from the similarity to the exec system call.
  14855. +
  14856. + It is an ongoing process to be certain the hardware in a machine
  14857. + is properly shutdown, so do not be surprised if this code does not
  14858. + initially work for you. It may help to enable device hotplugging
  14859. + support. As of this writing the exact hardware interface is
  14860. + strongly in flux, so no good recommendation can be made.
  14861. +
  14862. +config SECCOMP
  14863. + bool "Enable seccomp to safely compute untrusted bytecode"
  14864. + depends on PROC_FS
  14865. + default y
  14866. + help
  14867. + This kernel feature is useful for number crunching applications
  14868. + that may need to compute untrusted bytecode during their
  14869. + execution. By using pipes or other transports made available to
  14870. + the process as file descriptors supporting the read/write
  14871. + syscalls, it's possible to isolate those applications in
  14872. + their own address space using seccomp. Once seccomp is
  14873. + enabled via /proc/<pid>/seccomp, it cannot be disabled
  14874. + and the task is only allowed to execute a few safe syscalls
  14875. + defined by each seccomp mode.
  14876. +
  14877. + If unsure, say Y. Only embedded should say N here.
  14878. +
  14879. +config USE_OF
  14880. + bool "Flattened Device Tree support"
  14881. + select OF
  14882. + select OF_EARLY_FLATTREE
  14883. + help
  14884. + Include support for flattened device tree machine descriptions.
  14885. +
  14886. +endmenu
  14887. +
  14888. +config LOCKDEP_SUPPORT
  14889. + bool
  14890. + default y
  14891. +
  14892. +config STACKTRACE_SUPPORT
  14893. + bool
  14894. + default y
  14895. +
  14896. +source "init/Kconfig"
  14897. +
  14898. +source "kernel/Kconfig.freezer"
  14899. +
  14900. +menu "Bus options (PCI, PCMCIA, EISA, ISA, TC)"
  14901. +
  14902. +config HW_HAS_EISA
  14903. + bool
  14904. +config HW_HAS_PCI
  14905. + bool
  14906. +
  14907. +config PCI
  14908. + bool "Support for PCI controller"
  14909. + depends on HW_HAS_PCI
  14910. + select PCI_DOMAINS
  14911. + help
  14912. + Find out whether you have a PCI motherboard. PCI is the name of a
  14913. + bus system, i.e. the way the CPU talks to the other stuff inside
  14914. + your box. Other bus systems are ISA, EISA, or VESA. If you have PCI,
  14915. + say Y, otherwise N.
  14916. +
  14917. +config PCI_DOMAINS
  14918. + bool
  14919. +
  14920. +source "drivers/pci/Kconfig"
  14921. +
  14922. +#
  14923. +# ISA support is now enabled via select. Too many systems still have the one
  14924. +# or other ISA chip on the board that users don't know about so don't expect
  14925. +# users to choose the right thing ...
  14926. +#
  14927. +config ISA
  14928. + bool
  14929. +
  14930. +config EISA
  14931. + bool "EISA support"
  14932. + depends on HW_HAS_EISA
  14933. + select ISA
  14934. + select GENERIC_ISA_DMA
  14935. + ---help---
  14936. + The Extended Industry Standard Architecture (EISA) bus was
  14937. + developed as an open alternative to the IBM MicroChannel bus.
  14938. +
  14939. + The EISA bus provided some of the features of the IBM MicroChannel
  14940. + bus while maintaining backward compatibility with cards made for
  14941. + the older ISA bus. The EISA bus saw limited use between 1988 and
  14942. + 1995 when it was made obsolete by the PCI bus.
  14943. +
  14944. + Say Y here if you are building a kernel for an EISA-based machine.
  14945. +
  14946. + Otherwise, say N.
  14947. +
  14948. +source "drivers/eisa/Kconfig"
  14949. +
  14950. +config TC
  14951. + bool "TURBOchannel support"
  14952. + depends on MACH_DECSTATION
  14953. + help
  14954. + TURBOchannel is a DEC (now Compaq (now HP)) bus for Alpha and MIPS
  14955. + processors. TURBOchannel programming specifications are available
  14956. + at:
  14957. + <ftp://ftp.hp.com/pub/alphaserver/archive/triadd/>
  14958. + and:
  14959. + <http://www.computer-refuge.org/classiccmp/ftp.digital.com/pub/DEC/TriAdd/>
  14960. + Linux driver support status is documented at:
  14961. + <http://www.linux-mips.org/wiki/DECstation>
  14962. +
  14963. +#config ACCESSBUS
  14964. +# bool "Access.Bus support"
  14965. +# depends on TC
  14966. +
  14967. +config MMU
  14968. + bool
  14969. + default y
  14970. +
  14971. +config I8253
  14972. + bool
  14973. + select MIPS_EXTERNAL_TIMER
  14974. +
  14975. +config ZONE_DMA32
  14976. + bool
  14977. +
  14978. +source "drivers/pcmcia/Kconfig"
  14979. +
  14980. +source "drivers/pci/hotplug/Kconfig"
  14981. +
  14982. +config RAPIDIO
  14983. + bool "RapidIO support"
  14984. + depends on PCI
  14985. + default n
  14986. + help
  14987. + If you say Y here, the kernel will include drivers and
  14988. + infrastructure code to support RapidIO interconnect devices.
  14989. +
  14990. +source "drivers/rapidio/Kconfig"
  14991. +
  14992. +endmenu
  14993. +
  14994. +menu "Executable file formats"
  14995. +
  14996. +source "fs/Kconfig.binfmt"
  14997. +
  14998. +config TRAD_SIGNALS
  14999. + bool
  15000. +
  15001. +config MIPS32_COMPAT
  15002. + bool "Kernel support for Linux/MIPS 32-bit binary compatibility"
  15003. + depends on 64BIT
  15004. + help
  15005. + Select this option if you want Linux/MIPS 32-bit binary
  15006. + compatibility. Since all software available for Linux/MIPS is
  15007. + currently 32-bit you should say Y here.
  15008. +
  15009. +config COMPAT
  15010. + bool
  15011. + depends on MIPS32_COMPAT
  15012. + default y
  15013. +
  15014. +config SYSVIPC_COMPAT
  15015. + bool
  15016. + depends on COMPAT && SYSVIPC
  15017. + default y
  15018. +
  15019. +config MIPS32_O32
  15020. + bool "Kernel support for o32 binaries"
  15021. + depends on MIPS32_COMPAT
  15022. + help
  15023. + Select this option if you want to run o32 binaries. These are pure
  15024. + 32-bit binaries as used by the 32-bit Linux/MIPS port. Most of
  15025. + existing binaries are in this format.
  15026. +
  15027. + If unsure, say Y.
  15028. +
  15029. +config MIPS32_N32
  15030. + bool "Kernel support for n32 binaries"
  15031. + depends on MIPS32_COMPAT
  15032. + help
  15033. + Select this option if you want to run n32 binaries. These are
  15034. + 64-bit binaries using 32-bit quantities for addressing and certain
  15035. + data that would normally be 64-bit. They are used in special
  15036. + cases.
  15037. +
  15038. + If unsure, say N.
  15039. +
  15040. +config BINFMT_ELF32
  15041. + bool
  15042. + default y if MIPS32_O32 || MIPS32_N32
  15043. +
  15044. +endmenu
  15045. +
  15046. +menu "Power management options"
  15047. +
  15048. +config ARCH_HIBERNATION_POSSIBLE
  15049. + def_bool y
  15050. + depends on SYS_SUPPORTS_HOTPLUG_CPU || !SMP
  15051. +
  15052. +config ARCH_SUSPEND_POSSIBLE
  15053. + def_bool y
  15054. + depends on SYS_SUPPORTS_HOTPLUG_CPU || !SMP
  15055. +
  15056. +source "kernel/power/Kconfig"
  15057. +
  15058. +endmenu
  15059. +
  15060. +source "arch/mips/kernel/cpufreq/Kconfig"
  15061. +
  15062. +source "net/Kconfig"
  15063. +
  15064. +source "drivers/Kconfig"
  15065. +
  15066. +source "fs/Kconfig"
  15067. +
  15068. +source "arch/mips/Kconfig.debug"
  15069. +
  15070. +source "security/Kconfig"
  15071. +
  15072. +source "crypto/Kconfig"
  15073. +
  15074. +menuconfig VIRTUALIZATION
  15075. + bool "Virtualization"
  15076. + default n
  15077. + ---help---
  15078. + Say Y here to get to see options for using your Linux host to run other
  15079. + operating systems inside virtual machines (guests).
  15080. + This option alone does not add any kernel code.
  15081. +
  15082. + If you say N, all options in this submenu will be skipped and disabled.
  15083. +
  15084. +if VIRTUALIZATION
  15085. +
  15086. +source drivers/virtio/Kconfig
  15087. +
  15088. +endif # VIRTUALIZATION
  15089. +
  15090. +source "lib/Kconfig"
  15091. diff -Nur linux-2.6.39.orig/arch/mips/kernel/traps.c linux-2.6.39/arch/mips/kernel/traps.c
  15092. --- linux-2.6.39.orig/arch/mips/kernel/traps.c 2011-05-19 06:06:34.000000000 +0200
  15093. +++ linux-2.6.39/arch/mips/kernel/traps.c 2011-08-24 05:53:05.179230891 +0200
  15094. @@ -54,6 +54,7 @@
  15095. #include <asm/types.h>
  15096. #include <asm/stacktrace.h>
  15097. #include <asm/uasm.h>
  15098. +#include <asm/time.h>
  15099. extern void check_wait(void);
  15100. extern asmlinkage void r4k_wait(void);
  15101. @@ -1576,6 +1577,8 @@
  15102. if (cpu_has_mips_r2) {
  15103. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  15104. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  15105. + if (get_c0_compare_irq)
  15106. + cp0_compare_irq = get_c0_compare_irq();
  15107. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  15108. if (cp0_perfcount_irq == cp0_compare_irq)
  15109. cp0_perfcount_irq = -1;
  15110. diff -Nur linux-2.6.39.orig/arch/mips/Makefile linux-2.6.39/arch/mips/Makefile
  15111. --- linux-2.6.39.orig/arch/mips/Makefile 2011-05-19 06:06:34.000000000 +0200
  15112. +++ linux-2.6.39/arch/mips/Makefile 2011-08-24 02:42:39.917989402 +0200
  15113. @@ -158,6 +158,13 @@
  15114. endif
  15115. cflags-$(CONFIG_CAVIUM_CN63XXP1) += -Wa,-mfix-cn63xxp1
  15116. +#
  15117. +# Atheros AR71xx
  15118. +#
  15119. +core-$(CONFIG_ATHEROS_AR71XX) += arch/mips/ar71xx/
  15120. +cflags-$(CONFIG_ATHEROS_AR71XX) += -I$(srctree)/arch/mips/include/asm/mach-ar71xx
  15121. +load-$(CONFIG_ATHEROS_AR71XX) += 0xffffffff80060000
  15122. +
  15123. cflags-$(CONFIG_CPU_R4000_WORKAROUNDS) += $(call cc-option,-mfix-r4000,)
  15124. cflags-$(CONFIG_CPU_R4400_WORKAROUNDS) += $(call cc-option,-mfix-r4400,)
  15125. cflags-$(CONFIG_CPU_DADDI_WORKAROUNDS) += $(call cc-option,-mno-daddi,)
  15126. @@ -174,6 +181,7 @@
  15127. #
  15128. libs-$(CONFIG_ARC) += arch/mips/fw/arc/
  15129. libs-$(CONFIG_CFE) += arch/mips/fw/cfe/
  15130. +libs-$(CONFIG_MYLOADER) += arch/mips/fw/myloader/
  15131. libs-$(CONFIG_SNIPROM) += arch/mips/fw/sni/
  15132. libs-y += arch/mips/fw/lib/
  15133. diff -Nur linux-2.6.39.orig/arch/mips/pci/Makefile linux-2.6.39/arch/mips/pci/Makefile
  15134. --- linux-2.6.39.orig/arch/mips/pci/Makefile 2011-05-19 06:06:34.000000000 +0200
  15135. +++ linux-2.6.39/arch/mips/pci/Makefile 2011-08-22 16:21:37.437981205 +0200
  15136. @@ -18,6 +18,7 @@
  15137. obj-$(CONFIG_BCM47XX) += pci-bcm47xx.o
  15138. obj-$(CONFIG_BCM63XX) += pci-bcm63xx.o fixup-bcm63xx.o \
  15139. ops-bcm63xx.o
  15140. +obj-$(CONFIG_ATHEROS_AR71XX) += pci-ar71xx.o pci-ar724x.o
  15141. #
  15142. # These are still pretty much in the old state, watch, go blind.
  15143. diff -Nur linux-2.6.39.orig/arch/mips/pci/pci-ar71xx.c linux-2.6.39/arch/mips/pci/pci-ar71xx.c
  15144. --- linux-2.6.39.orig/arch/mips/pci/pci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  15145. +++ linux-2.6.39/arch/mips/pci/pci-ar71xx.c 2011-08-06 09:32:37.098016752 +0200
  15146. @@ -0,0 +1,415 @@
  15147. +/*
  15148. + * Atheros AR71xx PCI host controller driver
  15149. + *
  15150. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  15151. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  15152. + *
  15153. + * Parts of this file are based on Atheros' 2.6.15 BSP
  15154. + *
  15155. + * This program is free software; you can redistribute it and/or modify it
  15156. + * under the terms of the GNU General Public License version 2 as published
  15157. + * by the Free Software Foundation.
  15158. + */
  15159. +
  15160. +#include <linux/resource.h>
  15161. +#include <linux/types.h>
  15162. +#include <linux/delay.h>
  15163. +#include <linux/bitops.h>
  15164. +#include <linux/pci.h>
  15165. +#include <linux/pci_regs.h>
  15166. +#include <linux/interrupt.h>
  15167. +
  15168. +#include <asm/mach-ar71xx/ar71xx.h>
  15169. +#include <asm/mach-ar71xx/pci.h>
  15170. +
  15171. +#undef DEBUG
  15172. +#ifdef DEBUG
  15173. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  15174. +#else
  15175. +#define DBG(fmt, args...)
  15176. +#endif
  15177. +
  15178. +#define AR71XX_PCI_DELAY 100 /* msecs */
  15179. +
  15180. +#if 0
  15181. +#define PCI_IDSEL_BASE PCI_IDSEL_ADL_START
  15182. +#else
  15183. +#define PCI_IDSEL_BASE 0
  15184. +#endif
  15185. +
  15186. +static void __iomem *ar71xx_pcicfg_base;
  15187. +static DEFINE_SPINLOCK(ar71xx_pci_lock);
  15188. +static int ar71xx_pci_fixup_enable;
  15189. +
  15190. +static inline void ar71xx_pci_delay(void)
  15191. +{
  15192. + mdelay(AR71XX_PCI_DELAY);
  15193. +}
  15194. +
  15195. +/* Byte lane enable bits */
  15196. +static u8 ble_table[4][4] = {
  15197. + {0x0, 0xf, 0xf, 0xf},
  15198. + {0xe, 0xd, 0xb, 0x7},
  15199. + {0xc, 0xf, 0x3, 0xf},
  15200. + {0xf, 0xf, 0xf, 0xf},
  15201. +};
  15202. +
  15203. +static inline u32 ar71xx_pci_get_ble(int where, int size, int local)
  15204. +{
  15205. + u32 t;
  15206. +
  15207. + t = ble_table[size & 3][where & 3];
  15208. + BUG_ON(t == 0xf);
  15209. + t <<= (local) ? 20 : 4;
  15210. + return t;
  15211. +}
  15212. +
  15213. +static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
  15214. + int where)
  15215. +{
  15216. + u32 ret;
  15217. +
  15218. + if (!bus->number) {
  15219. + /* type 0 */
  15220. + ret = (1 << (PCI_IDSEL_BASE + PCI_SLOT(devfn)))
  15221. + | (PCI_FUNC(devfn) << 8) | (where & ~3);
  15222. + } else {
  15223. + /* type 1 */
  15224. + ret = (bus->number << 16) | (PCI_SLOT(devfn) << 11)
  15225. + | (PCI_FUNC(devfn) << 8) | (where & ~3) | 1;
  15226. + }
  15227. +
  15228. + return ret;
  15229. +}
  15230. +
  15231. +int ar71xx_pci_be_handler(int is_fixup)
  15232. +{
  15233. + void __iomem *base = ar71xx_pcicfg_base;
  15234. + u32 pci_err;
  15235. + u32 ahb_err;
  15236. +
  15237. + pci_err = __raw_readl(base + PCI_REG_PCI_ERR) & 3;
  15238. + if (pci_err) {
  15239. + if (!is_fixup)
  15240. + printk(KERN_ALERT "PCI error %d at PCI addr 0x%x\n",
  15241. + pci_err,
  15242. + __raw_readl(base + PCI_REG_PCI_ERR_ADDR));
  15243. +
  15244. + __raw_writel(pci_err, base + PCI_REG_PCI_ERR);
  15245. + }
  15246. +
  15247. + ahb_err = __raw_readl(base + PCI_REG_AHB_ERR) & 1;
  15248. + if (ahb_err) {
  15249. + if (!is_fixup)
  15250. + printk(KERN_ALERT "AHB error at AHB address 0x%x\n",
  15251. + __raw_readl(base + PCI_REG_AHB_ERR_ADDR));
  15252. +
  15253. + __raw_writel(ahb_err, base + PCI_REG_AHB_ERR);
  15254. + }
  15255. +
  15256. + return (ahb_err | pci_err) ? 1 : 0;
  15257. +}
  15258. +
  15259. +static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
  15260. + unsigned int devfn, int where, int size, u32 cmd)
  15261. +{
  15262. + void __iomem *base = ar71xx_pcicfg_base;
  15263. + u32 addr;
  15264. +
  15265. + addr = ar71xx_pci_bus_addr(bus, devfn, where);
  15266. +
  15267. + DBG("PCI: set cfgaddr: %02x:%02x.%01x/%02x:%01d, addr=%08x\n",
  15268. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  15269. + where, size, addr);
  15270. +
  15271. + __raw_writel(addr, base + PCI_REG_CFG_AD);
  15272. + __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0),
  15273. + base + PCI_REG_CFG_CBE);
  15274. +
  15275. + return ar71xx_pci_be_handler(1);
  15276. +}
  15277. +
  15278. +static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  15279. + int where, int size, u32 *value)
  15280. +{
  15281. + void __iomem *base = ar71xx_pcicfg_base;
  15282. + static u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
  15283. + unsigned long flags;
  15284. + u32 data;
  15285. + int retry = 0;
  15286. + int ret;
  15287. +
  15288. + ret = PCIBIOS_SUCCESSFUL;
  15289. +
  15290. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d\n", bus->number,
  15291. + PCI_SLOT(devfn), PCI_FUNC(devfn), where, size);
  15292. +
  15293. +retry:
  15294. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  15295. +
  15296. + if (bus->number == 0 && devfn == 0) {
  15297. + u32 t;
  15298. +
  15299. + t = PCI_CRP_CMD_READ | (where & ~3);
  15300. +
  15301. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  15302. + data = __raw_readl(base + PCI_REG_CRP_RDDATA);
  15303. +
  15304. + DBG("PCI: rd local cfg, ad_cbe:%08x, data:%08x\n", t, data);
  15305. +
  15306. + } else {
  15307. + int err;
  15308. +
  15309. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  15310. + PCI_CFG_CMD_READ);
  15311. +
  15312. + if (err == 0) {
  15313. + data = __raw_readl(base + PCI_REG_CFG_RDDATA);
  15314. + } else {
  15315. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  15316. + data = ~0;
  15317. + }
  15318. + }
  15319. +
  15320. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  15321. +
  15322. + DBG("PCI: read config: data=%08x raw=%08x\n",
  15323. + (data >> (8 * (where & 3))) & mask[size & 7], data);
  15324. +
  15325. + *value = (data >> (8 * (where & 3))) & mask[size & 7];
  15326. +
  15327. + /*
  15328. + * PCI controller bug: sometimes reads to the PCI_COMMAND register
  15329. + * return 0xffff, even though the PCI trace shows the correct value.
  15330. + * Work around this by retrying reads to this register
  15331. + */
  15332. + if (where == PCI_COMMAND && (*value & 0xffff) == 0xffff && retry++ < 2)
  15333. + goto retry;
  15334. +
  15335. + return ret;
  15336. +}
  15337. +
  15338. +static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  15339. + int where, int size, u32 value)
  15340. +{
  15341. + void __iomem *base = ar71xx_pcicfg_base;
  15342. + unsigned long flags;
  15343. + int ret;
  15344. +
  15345. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d value=%08x\n",
  15346. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  15347. + where, size, value);
  15348. +
  15349. + value = value << (8 * (where & 3));
  15350. + ret = PCIBIOS_SUCCESSFUL;
  15351. +
  15352. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  15353. + if (bus->number == 0 && devfn == 0) {
  15354. + u32 t;
  15355. +
  15356. + t = PCI_CRP_CMD_WRITE | (where & ~3);
  15357. + t |= ar71xx_pci_get_ble(where, size, 1);
  15358. +
  15359. + DBG("PCI: wr local cfg, ad_cbe:%08x, value:%08x\n", t, value);
  15360. +
  15361. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  15362. + __raw_writel(value, base + PCI_REG_CRP_WRDATA);
  15363. + } else {
  15364. + int err;
  15365. +
  15366. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  15367. + PCI_CFG_CMD_WRITE);
  15368. +
  15369. + if (err == 0)
  15370. + __raw_writel(value, base + PCI_REG_CFG_WRDATA);
  15371. + else
  15372. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  15373. + }
  15374. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  15375. +
  15376. + return ret;
  15377. +}
  15378. +
  15379. +static void ar71xx_pci_fixup(struct pci_dev *dev)
  15380. +{
  15381. + u32 t;
  15382. +
  15383. + if (!ar71xx_pci_fixup_enable)
  15384. + return;
  15385. +
  15386. + if (dev->bus->number != 0 || dev->devfn != 0)
  15387. + return;
  15388. +
  15389. + DBG("PCI: fixup host controller %s (%04x:%04x)\n", pci_name(dev),
  15390. + dev->vendor, dev->device);
  15391. +
  15392. + /* setup COMMAND register */
  15393. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
  15394. + | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
  15395. +
  15396. + pci_write_config_word(dev, PCI_COMMAND, t);
  15397. +}
  15398. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar71xx_pci_fixup);
  15399. +
  15400. +int __init ar71xx_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  15401. + uint8_t pin)
  15402. +{
  15403. + int irq = -1;
  15404. + int i;
  15405. +
  15406. + slot -= PCI_IDSEL_ADL_START - PCI_IDSEL_BASE;
  15407. +
  15408. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  15409. + struct ar71xx_pci_irq *entry;
  15410. +
  15411. + entry = &ar71xx_pci_irq_map[i];
  15412. + if (entry->slot == slot && entry->pin == pin) {
  15413. + irq = entry->irq;
  15414. + break;
  15415. + }
  15416. + }
  15417. +
  15418. + if (irq < 0) {
  15419. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  15420. + pin, pci_name((struct pci_dev *)dev));
  15421. + } else {
  15422. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  15423. + irq, pin, pci_name((struct pci_dev *)dev));
  15424. + }
  15425. +
  15426. + return irq;
  15427. +}
  15428. +
  15429. +static struct pci_ops ar71xx_pci_ops = {
  15430. + .read = ar71xx_pci_read_config,
  15431. + .write = ar71xx_pci_write_config,
  15432. +};
  15433. +
  15434. +static struct resource ar71xx_pci_io_resource = {
  15435. + .name = "PCI IO space",
  15436. + .start = 0,
  15437. + .end = 0,
  15438. + .flags = IORESOURCE_IO,
  15439. +};
  15440. +
  15441. +static struct resource ar71xx_pci_mem_resource = {
  15442. + .name = "PCI memory space",
  15443. + .start = AR71XX_PCI_MEM_BASE,
  15444. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  15445. + .flags = IORESOURCE_MEM
  15446. +};
  15447. +
  15448. +static struct pci_controller ar71xx_pci_controller = {
  15449. + .pci_ops = &ar71xx_pci_ops,
  15450. + .mem_resource = &ar71xx_pci_mem_resource,
  15451. + .io_resource = &ar71xx_pci_io_resource,
  15452. +};
  15453. +
  15454. +static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  15455. +{
  15456. + void __iomem *base = ar71xx_reset_base;
  15457. + u32 pending;
  15458. +
  15459. + pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
  15460. + __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15461. +
  15462. + if (pending & PCI_INT_DEV0)
  15463. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  15464. +
  15465. + else if (pending & PCI_INT_DEV1)
  15466. + generic_handle_irq(AR71XX_PCI_IRQ_DEV1);
  15467. +
  15468. + else if (pending & PCI_INT_DEV2)
  15469. + generic_handle_irq(AR71XX_PCI_IRQ_DEV2);
  15470. +
  15471. + else if (pending & PCI_INT_CORE)
  15472. + generic_handle_irq(AR71XX_PCI_IRQ_CORE);
  15473. +
  15474. + else
  15475. + spurious_interrupt();
  15476. +}
  15477. +
  15478. +static void ar71xx_pci_irq_unmask(struct irq_data *d)
  15479. +{
  15480. + unsigned int irq = d->irq - AR71XX_PCI_IRQ_BASE;
  15481. + void __iomem *base = ar71xx_reset_base;
  15482. + u32 t;
  15483. +
  15484. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15485. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15486. +
  15487. + /* flush write */
  15488. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15489. +}
  15490. +
  15491. +static void ar71xx_pci_irq_mask(struct irq_data *d)
  15492. +{
  15493. + unsigned int irq = d->irq - AR71XX_PCI_IRQ_BASE;
  15494. + void __iomem *base = ar71xx_reset_base;
  15495. + u32 t;
  15496. +
  15497. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15498. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15499. +
  15500. + /* flush write */
  15501. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15502. +}
  15503. +
  15504. +static struct irq_chip ar71xx_pci_irq_chip = {
  15505. + .name = "AR71XX PCI ",
  15506. + .irq_mask = ar71xx_pci_irq_mask,
  15507. + .irq_unmask = ar71xx_pci_irq_unmask,
  15508. + .irq_mask_ack = ar71xx_pci_irq_mask,
  15509. +};
  15510. +
  15511. +static void __init ar71xx_pci_irq_init(void)
  15512. +{
  15513. + void __iomem *base = ar71xx_reset_base;
  15514. + int i;
  15515. +
  15516. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  15517. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_STATUS);
  15518. +
  15519. + for (i = AR71XX_PCI_IRQ_BASE;
  15520. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++)
  15521. + irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
  15522. + handle_level_irq);
  15523. +
  15524. + irq_set_chained_handler(AR71XX_CPU_IRQ_IP2, ar71xx_pci_irq_handler);
  15525. +}
  15526. +
  15527. +int __init ar71xx_pcibios_init(void)
  15528. +{
  15529. + void __iomem *ddr_base = ar71xx_ddr_base;
  15530. +
  15531. + ar71xx_device_stop(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  15532. + ar71xx_pci_delay();
  15533. +
  15534. + ar71xx_device_start(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  15535. + ar71xx_pci_delay();
  15536. +
  15537. + ar71xx_pcicfg_base = ioremap_nocache(AR71XX_PCI_CFG_BASE,
  15538. + AR71XX_PCI_CFG_SIZE);
  15539. + if (ar71xx_pcicfg_base == NULL)
  15540. + return -ENOMEM;
  15541. +
  15542. + __raw_writel(PCI_WIN0_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN0);
  15543. + __raw_writel(PCI_WIN1_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN1);
  15544. + __raw_writel(PCI_WIN2_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN2);
  15545. + __raw_writel(PCI_WIN3_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN3);
  15546. + __raw_writel(PCI_WIN4_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN4);
  15547. + __raw_writel(PCI_WIN5_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN5);
  15548. + __raw_writel(PCI_WIN6_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN6);
  15549. + __raw_writel(PCI_WIN7_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN7);
  15550. +
  15551. + ar71xx_pci_delay();
  15552. +
  15553. + /* clear bus errors */
  15554. + (void)ar71xx_pci_be_handler(1);
  15555. +
  15556. + ar71xx_pci_fixup_enable = 1;
  15557. + ar71xx_pci_irq_init();
  15558. + register_pci_controller(&ar71xx_pci_controller);
  15559. +
  15560. + return 0;
  15561. +}
  15562. diff -Nur linux-2.6.39.orig/arch/mips/pci/pci-ar724x.c linux-2.6.39/arch/mips/pci/pci-ar724x.c
  15563. --- linux-2.6.39.orig/arch/mips/pci/pci-ar724x.c 1970-01-01 01:00:00.000000000 +0100
  15564. +++ linux-2.6.39/arch/mips/pci/pci-ar724x.c 2011-08-06 09:32:37.088017079 +0200
  15565. @@ -0,0 +1,389 @@
  15566. +/*
  15567. + * Atheros AR724x PCI host controller driver
  15568. + *
  15569. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  15570. + *
  15571. + * Parts of this file are based on Atheros' 2.6.15 BSP
  15572. + *
  15573. + * This program is free software; you can redistribute it and/or modify it
  15574. + * under the terms of the GNU General Public License version 2 as published
  15575. + * by the Free Software Foundation.
  15576. + */
  15577. +
  15578. +#include <linux/resource.h>
  15579. +#include <linux/types.h>
  15580. +#include <linux/delay.h>
  15581. +#include <linux/bitops.h>
  15582. +#include <linux/pci.h>
  15583. +#include <linux/pci_regs.h>
  15584. +#include <linux/interrupt.h>
  15585. +
  15586. +#include <asm/mach-ar71xx/ar71xx.h>
  15587. +#include <asm/mach-ar71xx/pci.h>
  15588. +
  15589. +#undef DEBUG
  15590. +#ifdef DEBUG
  15591. +#define DBG(fmt, args...) printk(KERN_INFO fmt, ## args)
  15592. +#else
  15593. +#define DBG(fmt, args...)
  15594. +#endif
  15595. +
  15596. +static void __iomem *ar724x_pci_localcfg_base;
  15597. +static void __iomem *ar724x_pci_devcfg_base;
  15598. +static void __iomem *ar724x_pci_ctrl_base;
  15599. +static int ar724x_pci_fixup_enable;
  15600. +
  15601. +static DEFINE_SPINLOCK(ar724x_pci_lock);
  15602. +
  15603. +static void ar724x_pci_read(void __iomem *base, int where, int size, u32 *value)
  15604. +{
  15605. + unsigned long flags;
  15606. + u32 data;
  15607. +
  15608. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  15609. + data = __raw_readl(base + (where & ~3));
  15610. +
  15611. + switch (size) {
  15612. + case 1:
  15613. + if (where & 1)
  15614. + data >>= 8;
  15615. + if (where & 2)
  15616. + data >>= 16;
  15617. + data &= 0xFF;
  15618. + break;
  15619. + case 2:
  15620. + if (where & 2)
  15621. + data >>= 16;
  15622. + data &= 0xFFFF;
  15623. + break;
  15624. + }
  15625. +
  15626. + *value = data;
  15627. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  15628. +}
  15629. +
  15630. +static void ar724x_pci_write(void __iomem *base, int where, int size, u32 value)
  15631. +{
  15632. + unsigned long flags;
  15633. + u32 data;
  15634. + int s;
  15635. +
  15636. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  15637. + data = __raw_readl(base + (where & ~3));
  15638. +
  15639. + switch (size) {
  15640. + case 1:
  15641. + s = ((where & 3) << 3);
  15642. + data &= ~(0xFF << s);
  15643. + data |= ((value & 0xFF) << s);
  15644. + break;
  15645. + case 2:
  15646. + s = ((where & 2) << 3);
  15647. + data &= ~(0xFFFF << s);
  15648. + data |= ((value & 0xFFFF) << s);
  15649. + break;
  15650. + case 4:
  15651. + data = value;
  15652. + break;
  15653. + }
  15654. +
  15655. + __raw_writel(data, base + (where & ~3));
  15656. + /* flush write */
  15657. + (void)__raw_readl(base + (where & ~3));
  15658. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  15659. +}
  15660. +
  15661. +static int ar724x_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  15662. + int where, int size, u32 *value)
  15663. +{
  15664. +
  15665. + if (bus->number != 0 || devfn != 0)
  15666. + return PCIBIOS_DEVICE_NOT_FOUND;
  15667. +
  15668. + ar724x_pci_read(ar724x_pci_devcfg_base, where, size, value);
  15669. +
  15670. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  15671. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  15672. + where, size, *value);
  15673. +
  15674. + /*
  15675. + * WAR for BAR issue - We are unable to access the PCI device space
  15676. + * if we set the BAR with proper base address
  15677. + */
  15678. + if ((where == 0x10) && (size == 4)) {
  15679. + u32 val;
  15680. + val = (ar71xx_soc == AR71XX_SOC_AR7240) ? 0xffff : 0x1000ffff;
  15681. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, val);
  15682. + }
  15683. +
  15684. + return PCIBIOS_SUCCESSFUL;
  15685. +}
  15686. +
  15687. +static int ar724x_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  15688. + int where, int size, u32 value)
  15689. +{
  15690. + if (bus->number != 0 || devfn != 0)
  15691. + return PCIBIOS_DEVICE_NOT_FOUND;
  15692. +
  15693. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  15694. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  15695. + where, size, value);
  15696. +
  15697. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, value);
  15698. +
  15699. + return PCIBIOS_SUCCESSFUL;
  15700. +}
  15701. +
  15702. +static void ar724x_pci_fixup(struct pci_dev *dev)
  15703. +{
  15704. + u16 cmd;
  15705. +
  15706. + if (!ar724x_pci_fixup_enable)
  15707. + return;
  15708. +
  15709. + if (dev->bus->number != 0 || dev->devfn != 0)
  15710. + return;
  15711. +
  15712. + /* setup COMMAND register */
  15713. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  15714. + cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  15715. + PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY | PCI_COMMAND_SERR |
  15716. + PCI_COMMAND_FAST_BACK;
  15717. +
  15718. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  15719. +}
  15720. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar724x_pci_fixup);
  15721. +
  15722. +int __init ar724x_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  15723. + uint8_t pin)
  15724. +{
  15725. + int irq = -1;
  15726. + int i;
  15727. +
  15728. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  15729. + struct ar71xx_pci_irq *entry;
  15730. + entry = &ar71xx_pci_irq_map[i];
  15731. +
  15732. + if (entry->slot == slot && entry->pin == pin) {
  15733. + irq = entry->irq;
  15734. + break;
  15735. + }
  15736. + }
  15737. +
  15738. + if (irq < 0)
  15739. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  15740. + pin, pci_name((struct pci_dev *)dev));
  15741. + else
  15742. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  15743. + irq, pin, pci_name((struct pci_dev *)dev));
  15744. +
  15745. + return irq;
  15746. +}
  15747. +
  15748. +static struct pci_ops ar724x_pci_ops = {
  15749. + .read = ar724x_pci_read_config,
  15750. + .write = ar724x_pci_write_config,
  15751. +};
  15752. +
  15753. +static struct resource ar724x_pci_io_resource = {
  15754. + .name = "PCI IO space",
  15755. + .start = 0,
  15756. + .end = 0,
  15757. + .flags = IORESOURCE_IO,
  15758. +};
  15759. +
  15760. +static struct resource ar724x_pci_mem_resource = {
  15761. + .name = "PCI memory space",
  15762. + .start = AR71XX_PCI_MEM_BASE,
  15763. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  15764. + .flags = IORESOURCE_MEM
  15765. +};
  15766. +
  15767. +static struct pci_controller ar724x_pci_controller = {
  15768. + .pci_ops = &ar724x_pci_ops,
  15769. + .mem_resource = &ar724x_pci_mem_resource,
  15770. + .io_resource = &ar724x_pci_io_resource,
  15771. +};
  15772. +
  15773. +static void __init ar724x_pci_reset(void)
  15774. +{
  15775. + ar71xx_device_stop(AR724X_RESET_PCIE);
  15776. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY);
  15777. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY_SERIAL);
  15778. + udelay(100);
  15779. +
  15780. + ar71xx_device_start(AR724X_RESET_PCIE_PHY_SERIAL);
  15781. + udelay(100);
  15782. + ar71xx_device_start(AR724X_RESET_PCIE_PHY);
  15783. + ar71xx_device_start(AR724X_RESET_PCIE);
  15784. +}
  15785. +
  15786. +static int __init ar724x_pci_setup(void)
  15787. +{
  15788. + void __iomem *base = ar724x_pci_ctrl_base;
  15789. + u32 t;
  15790. +
  15791. + /* setup COMMAND register */
  15792. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE |
  15793. + PCI_COMMAND_PARITY|PCI_COMMAND_SERR|PCI_COMMAND_FAST_BACK;
  15794. +
  15795. + ar724x_pci_write(ar724x_pci_localcfg_base, PCI_COMMAND, 4, t);
  15796. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x20, 4, 0x1ff01000);
  15797. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x24, 4, 0x1ff01000);
  15798. +
  15799. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  15800. + if (t != 0x7) {
  15801. + udelay(100000);
  15802. + __raw_writel(0, base + AR724X_PCI_REG_RESET);
  15803. + udelay(100);
  15804. + __raw_writel(4, base + AR724X_PCI_REG_RESET);
  15805. + udelay(100000);
  15806. + }
  15807. +
  15808. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  15809. + t = AR724X_PCI_APP_LTSSM_ENABLE;
  15810. + else
  15811. + t = 0x1ffc1;
  15812. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  15813. + /* flush write */
  15814. + (void) __raw_readl(base + AR724X_PCI_REG_APP);
  15815. + udelay(1000);
  15816. +
  15817. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  15818. + if ((t & AR724X_PCI_RESET_LINK_UP) == 0x0) {
  15819. + printk(KERN_WARNING "PCI: no PCIe module found\n");
  15820. + return -ENODEV;
  15821. + }
  15822. +
  15823. + if (ar71xx_soc == AR71XX_SOC_AR7241 ||
  15824. + ar71xx_soc == AR71XX_SOC_AR7242) {
  15825. + t = __raw_readl(base + AR724X_PCI_REG_APP);
  15826. + t |= BIT(16);
  15827. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  15828. + }
  15829. +
  15830. + return 0;
  15831. +}
  15832. +
  15833. +static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  15834. +{
  15835. + void __iomem *base = ar724x_pci_ctrl_base;
  15836. + u32 pending;
  15837. +
  15838. + pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
  15839. + __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  15840. +
  15841. + if (pending & AR724X_PCI_INT_DEV0)
  15842. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  15843. +
  15844. + else
  15845. + spurious_interrupt();
  15846. +}
  15847. +
  15848. +static void ar724x_pci_irq_unmask(struct irq_data *d)
  15849. +{
  15850. + void __iomem *base = ar724x_pci_ctrl_base;
  15851. + u32 t;
  15852. +
  15853. + switch (d->irq) {
  15854. + case AR71XX_PCI_IRQ_DEV0:
  15855. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  15856. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  15857. + base + AR724X_PCI_REG_INT_MASK);
  15858. + /* flush write */
  15859. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  15860. + }
  15861. +}
  15862. +
  15863. +static void ar724x_pci_irq_mask(struct irq_data *d)
  15864. +{
  15865. + void __iomem *base = ar724x_pci_ctrl_base;
  15866. + u32 t;
  15867. +
  15868. + switch (d->irq) {
  15869. + case AR71XX_PCI_IRQ_DEV0:
  15870. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  15871. + __raw_writel(t & ~AR724X_PCI_INT_DEV0,
  15872. + base + AR724X_PCI_REG_INT_MASK);
  15873. +
  15874. + /* flush write */
  15875. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  15876. +
  15877. + t = __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  15878. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  15879. + base + AR724X_PCI_REG_INT_STATUS);
  15880. +
  15881. + /* flush write */
  15882. + (void) __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  15883. + }
  15884. +}
  15885. +
  15886. +static struct irq_chip ar724x_pci_irq_chip = {
  15887. + .name = "AR724X PCI ",
  15888. + .irq_mask = ar724x_pci_irq_mask,
  15889. + .irq_unmask = ar724x_pci_irq_unmask,
  15890. + .irq_mask_ack = ar724x_pci_irq_mask,
  15891. +};
  15892. +
  15893. +static void __init ar724x_pci_irq_init(void)
  15894. +{
  15895. + void __iomem *base = ar724x_pci_ctrl_base;
  15896. + u32 t;
  15897. + int i;
  15898. +
  15899. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  15900. + if (t & (AR724X_RESET_PCIE | AR724X_RESET_PCIE_PHY |
  15901. + AR724X_RESET_PCIE_PHY_SERIAL)) {
  15902. + return;
  15903. + }
  15904. +
  15905. + __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
  15906. + __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
  15907. +
  15908. + for (i = AR71XX_PCI_IRQ_BASE;
  15909. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++)
  15910. + irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
  15911. + handle_level_irq);
  15912. +
  15913. + irq_set_chained_handler(AR71XX_CPU_IRQ_IP2, ar724x_pci_irq_handler);
  15914. +}
  15915. +
  15916. +int __init ar724x_pcibios_init(void)
  15917. +{
  15918. + int ret = -ENOMEM;
  15919. +
  15920. + ar724x_pci_localcfg_base = ioremap_nocache(AR724X_PCI_CRP_BASE,
  15921. + AR724X_PCI_CRP_SIZE);
  15922. + if (ar724x_pci_localcfg_base == NULL)
  15923. + goto err;
  15924. +
  15925. + ar724x_pci_devcfg_base = ioremap_nocache(AR724X_PCI_CFG_BASE,
  15926. + AR724X_PCI_CFG_SIZE);
  15927. + if (ar724x_pci_devcfg_base == NULL)
  15928. + goto err_unmap_localcfg;
  15929. +
  15930. + ar724x_pci_ctrl_base = ioremap_nocache(AR724X_PCI_CTRL_BASE,
  15931. + AR724X_PCI_CTRL_SIZE);
  15932. + if (ar724x_pci_ctrl_base == NULL)
  15933. + goto err_unmap_devcfg;
  15934. +
  15935. + ar724x_pci_reset();
  15936. + ret = ar724x_pci_setup();
  15937. + if (ret)
  15938. + goto err_unmap_ctrl;
  15939. +
  15940. + ar724x_pci_fixup_enable = 1;
  15941. + ar724x_pci_irq_init();
  15942. + register_pci_controller(&ar724x_pci_controller);
  15943. +
  15944. + return 0;
  15945. +
  15946. +err_unmap_ctrl:
  15947. + iounmap(ar724x_pci_ctrl_base);
  15948. +err_unmap_devcfg:
  15949. + iounmap(ar724x_pci_devcfg_base);
  15950. +err_unmap_localcfg:
  15951. + iounmap(ar724x_pci_localcfg_base);
  15952. +err:
  15953. + return ret;
  15954. +}
  15955. diff -Nur linux-2.6.39.orig/drivers/gpio/nxp_74hc153.c linux-2.6.39/drivers/gpio/nxp_74hc153.c
  15956. --- linux-2.6.39.orig/drivers/gpio/nxp_74hc153.c 1970-01-01 01:00:00.000000000 +0100
  15957. +++ linux-2.6.39/drivers/gpio/nxp_74hc153.c 2011-04-27 12:19:22.327664626 +0200
  15958. @@ -0,0 +1,247 @@
  15959. +/*
  15960. + * NXP 74HC153 - Dual 4-input multiplexer GPIO driver
  15961. + *
  15962. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  15963. + *
  15964. + * This program is free software; you can redistribute it and/or modify
  15965. + * it under the terms of the GNU General Public License version 2 as
  15966. + * published by the Free Software Foundation.
  15967. + */
  15968. +
  15969. +#include <linux/module.h>
  15970. +#include <linux/init.h>
  15971. +#include <linux/gpio.h>
  15972. +#include <linux/slab.h>
  15973. +#include <linux/platform_device.h>
  15974. +#include <linux/nxp_74hc153.h>
  15975. +
  15976. +#define NXP_74HC153_NUM_GPIOS 8
  15977. +#define NXP_74HC153_S0_MASK 0x1
  15978. +#define NXP_74HC153_S1_MASK 0x2
  15979. +#define NXP_74HC153_BANK_MASK 0x4
  15980. +
  15981. +struct nxp_74hc153_chip {
  15982. + struct device *parent;
  15983. + struct gpio_chip gpio_chip;
  15984. + struct mutex lock;
  15985. +};
  15986. +
  15987. +static struct nxp_74hc153_chip *gpio_to_nxp(struct gpio_chip *gc)
  15988. +{
  15989. + return container_of(gc, struct nxp_74hc153_chip, gpio_chip);
  15990. +}
  15991. +
  15992. +static int nxp_74hc153_direction_input(struct gpio_chip *gc, unsigned offset)
  15993. +{
  15994. + return 0;
  15995. +}
  15996. +
  15997. +static int nxp_74hc153_direction_output(struct gpio_chip *gc,
  15998. + unsigned offset, int val)
  15999. +{
  16000. + return -EINVAL;
  16001. +}
  16002. +
  16003. +static int nxp_74hc153_get_value(struct gpio_chip *gc, unsigned offset)
  16004. +{
  16005. + struct nxp_74hc153_chip *nxp;
  16006. + struct nxp_74hc153_platform_data *pdata;
  16007. + unsigned s0;
  16008. + unsigned s1;
  16009. + unsigned pin;
  16010. + int ret;
  16011. +
  16012. + nxp = gpio_to_nxp(gc);
  16013. + pdata = nxp->parent->platform_data;
  16014. +
  16015. + s0 = !!(offset & NXP_74HC153_S0_MASK);
  16016. + s1 = !!(offset & NXP_74HC153_S1_MASK);
  16017. + pin = (offset & NXP_74HC153_BANK_MASK) ? pdata->gpio_pin_2y
  16018. + : pdata->gpio_pin_1y;
  16019. +
  16020. + mutex_lock(&nxp->lock);
  16021. + gpio_set_value(pdata->gpio_pin_s0, s0);
  16022. + gpio_set_value(pdata->gpio_pin_s1, s1);
  16023. + ret = gpio_get_value(pin);
  16024. + mutex_unlock(&nxp->lock);
  16025. +
  16026. + return ret;
  16027. +}
  16028. +
  16029. +static void nxp_74hc153_set_value(struct gpio_chip *gc,
  16030. + unsigned offset, int val)
  16031. +{
  16032. + /* not supported */
  16033. +}
  16034. +
  16035. +static int __devinit nxp_74hc153_probe(struct platform_device *pdev)
  16036. +{
  16037. + struct nxp_74hc153_platform_data *pdata;
  16038. + struct nxp_74hc153_chip *nxp;
  16039. + struct gpio_chip *gc;
  16040. + int err;
  16041. +
  16042. + pdata = pdev->dev.platform_data;
  16043. + if (pdata == NULL) {
  16044. + dev_dbg(&pdev->dev, "no platform data specified\n");
  16045. + return -EINVAL;
  16046. + }
  16047. +
  16048. + nxp = kzalloc(sizeof(struct nxp_74hc153_chip), GFP_KERNEL);
  16049. + if (nxp == NULL) {
  16050. + dev_err(&pdev->dev, "no memory for private data\n");
  16051. + return -ENOMEM;
  16052. + }
  16053. +
  16054. + err = gpio_request(pdata->gpio_pin_s0, dev_name(&pdev->dev));
  16055. + if (err) {
  16056. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  16057. + pdata->gpio_pin_s0, err);
  16058. + goto err_free_nxp;
  16059. + }
  16060. +
  16061. + err = gpio_request(pdata->gpio_pin_s1, dev_name(&pdev->dev));
  16062. + if (err) {
  16063. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  16064. + pdata->gpio_pin_s1, err);
  16065. + goto err_free_s0;
  16066. + }
  16067. +
  16068. + err = gpio_request(pdata->gpio_pin_1y, dev_name(&pdev->dev));
  16069. + if (err) {
  16070. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  16071. + pdata->gpio_pin_1y, err);
  16072. + goto err_free_s1;
  16073. + }
  16074. +
  16075. + err = gpio_request(pdata->gpio_pin_2y, dev_name(&pdev->dev));
  16076. + if (err) {
  16077. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  16078. + pdata->gpio_pin_2y, err);
  16079. + goto err_free_1y;
  16080. + }
  16081. +
  16082. + err = gpio_direction_output(pdata->gpio_pin_s0, 0);
  16083. + if (err) {
  16084. + dev_err(&pdev->dev,
  16085. + "unable to set direction of gpio %u, err=%d\n",
  16086. + pdata->gpio_pin_s0, err);
  16087. + goto err_free_2y;
  16088. + }
  16089. +
  16090. + err = gpio_direction_output(pdata->gpio_pin_s1, 0);
  16091. + if (err) {
  16092. + dev_err(&pdev->dev,
  16093. + "unable to set direction of gpio %u, err=%d\n",
  16094. + pdata->gpio_pin_s1, err);
  16095. + goto err_free_2y;
  16096. + }
  16097. +
  16098. + err = gpio_direction_input(pdata->gpio_pin_1y);
  16099. + if (err) {
  16100. + dev_err(&pdev->dev,
  16101. + "unable to set direction of gpio %u, err=%d\n",
  16102. + pdata->gpio_pin_1y, err);
  16103. + goto err_free_2y;
  16104. + }
  16105. +
  16106. + err = gpio_direction_input(pdata->gpio_pin_2y);
  16107. + if (err) {
  16108. + dev_err(&pdev->dev,
  16109. + "unable to set direction of gpio %u, err=%d\n",
  16110. + pdata->gpio_pin_2y, err);
  16111. + goto err_free_2y;
  16112. + }
  16113. +
  16114. + nxp->parent = &pdev->dev;
  16115. + mutex_init(&nxp->lock);
  16116. +
  16117. + gc = &nxp->gpio_chip;
  16118. +
  16119. + gc->direction_input = nxp_74hc153_direction_input;
  16120. + gc->direction_output = nxp_74hc153_direction_output;
  16121. + gc->get = nxp_74hc153_get_value;
  16122. + gc->set = nxp_74hc153_set_value;
  16123. + gc->can_sleep = 1;
  16124. +
  16125. + gc->base = pdata->gpio_base;
  16126. + gc->ngpio = NXP_74HC153_NUM_GPIOS;
  16127. + gc->label = dev_name(nxp->parent);
  16128. + gc->dev = nxp->parent;
  16129. + gc->owner = THIS_MODULE;
  16130. +
  16131. + err = gpiochip_add(&nxp->gpio_chip);
  16132. + if (err) {
  16133. + dev_err(&pdev->dev, "unable to add gpio chip, err=%d\n", err);
  16134. + goto err_free_2y;
  16135. + }
  16136. +
  16137. + platform_set_drvdata(pdev, nxp);
  16138. + return 0;
  16139. +
  16140. +err_free_2y:
  16141. + gpio_free(pdata->gpio_pin_2y);
  16142. +err_free_1y:
  16143. + gpio_free(pdata->gpio_pin_1y);
  16144. +err_free_s1:
  16145. + gpio_free(pdata->gpio_pin_s1);
  16146. +err_free_s0:
  16147. + gpio_free(pdata->gpio_pin_s0);
  16148. +err_free_nxp:
  16149. + kfree(nxp);
  16150. + return err;
  16151. +}
  16152. +
  16153. +static int nxp_74hc153_remove(struct platform_device *pdev)
  16154. +{
  16155. + struct nxp_74hc153_chip *nxp = platform_get_drvdata(pdev);
  16156. + struct nxp_74hc153_platform_data *pdata = pdev->dev.platform_data;
  16157. +
  16158. + if (nxp) {
  16159. + int err;
  16160. +
  16161. + err = gpiochip_remove(&nxp->gpio_chip);
  16162. + if (err) {
  16163. + dev_err(&pdev->dev,
  16164. + "unable to remove gpio chip, err=%d\n",
  16165. + err);
  16166. + return err;
  16167. + }
  16168. +
  16169. + gpio_free(pdata->gpio_pin_2y);
  16170. + gpio_free(pdata->gpio_pin_1y);
  16171. + gpio_free(pdata->gpio_pin_s1);
  16172. + gpio_free(pdata->gpio_pin_s0);
  16173. +
  16174. + kfree(nxp);
  16175. + platform_set_drvdata(pdev, NULL);
  16176. + }
  16177. +
  16178. + return 0;
  16179. +}
  16180. +
  16181. +static struct platform_driver nxp_74hc153_driver = {
  16182. + .probe = nxp_74hc153_probe,
  16183. + .remove = __devexit_p(nxp_74hc153_remove),
  16184. + .driver = {
  16185. + .name = NXP_74HC153_DRIVER_NAME,
  16186. + .owner = THIS_MODULE,
  16187. + },
  16188. +};
  16189. +
  16190. +static int __init nxp_74hc153_init(void)
  16191. +{
  16192. + return platform_driver_register(&nxp_74hc153_driver);
  16193. +}
  16194. +subsys_initcall(nxp_74hc153_init);
  16195. +
  16196. +static void __exit nxp_74hc153_exit(void)
  16197. +{
  16198. + platform_driver_unregister(&nxp_74hc153_driver);
  16199. +}
  16200. +module_exit(nxp_74hc153_exit);
  16201. +
  16202. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16203. +MODULE_DESCRIPTION("GPIO expander driver for NXP 74HC153");
  16204. +MODULE_LICENSE("GPL v2");
  16205. +MODULE_ALIAS("platform:" NXP_74HC153_DRIVER_NAME);
  16206. diff -Nur linux-2.6.39.orig/drivers/leds/leds-rb750.c linux-2.6.39/drivers/leds/leds-rb750.c
  16207. --- linux-2.6.39.orig/drivers/leds/leds-rb750.c 1970-01-01 01:00:00.000000000 +0100
  16208. +++ linux-2.6.39/drivers/leds/leds-rb750.c 2011-04-27 12:19:22.267661616 +0200
  16209. @@ -0,0 +1,141 @@
  16210. +/*
  16211. + * LED driver for the RouterBOARD 750
  16212. + *
  16213. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  16214. + *
  16215. + * This program is free software; you can redistribute it and/or modify
  16216. + * it under the terms of the GNU General Public License version 2 as
  16217. + * published by the Free Software Foundation.
  16218. + *
  16219. + */
  16220. +#include <linux/kernel.h>
  16221. +#include <linux/init.h>
  16222. +#include <linux/platform_device.h>
  16223. +#include <linux/leds.h>
  16224. +#include <linux/slab.h>
  16225. +
  16226. +#include <asm/mach-ar71xx/mach-rb750.h>
  16227. +
  16228. +#define DRV_NAME "leds-rb750"
  16229. +
  16230. +struct rb750_led_dev {
  16231. + struct led_classdev cdev;
  16232. + u32 mask;
  16233. + int active_low;
  16234. +};
  16235. +
  16236. +struct rb750_led_drvdata {
  16237. + struct rb750_led_dev *led_devs;
  16238. + int num_leds;
  16239. +};
  16240. +
  16241. +static inline struct rb750_led_dev *to_rbled(struct led_classdev *led_cdev)
  16242. +{
  16243. + return (struct rb750_led_dev *)container_of(led_cdev,
  16244. + struct rb750_led_dev, cdev);
  16245. +}
  16246. +
  16247. +static void rb750_led_brightness_set(struct led_classdev *led_cdev,
  16248. + enum led_brightness value)
  16249. +{
  16250. + struct rb750_led_dev *rbled = to_rbled(led_cdev);
  16251. + int level;
  16252. +
  16253. + level = (value == LED_OFF) ? 0 : 1;
  16254. + level ^= rbled->active_low;
  16255. +
  16256. + if (level)
  16257. + rb750_latch_change(0, rbled->mask);
  16258. + else
  16259. + rb750_latch_change(rbled->mask, 0);
  16260. +}
  16261. +
  16262. +static int __devinit rb750_led_probe(struct platform_device *pdev)
  16263. +{
  16264. + struct rb750_led_platform_data *pdata;
  16265. + struct rb750_led_drvdata *drvdata;
  16266. + int ret = 0;
  16267. + int i;
  16268. +
  16269. + pdata = pdev->dev.platform_data;
  16270. + if (!pdata)
  16271. + return -EINVAL;
  16272. +
  16273. + drvdata = kzalloc(sizeof(struct rb750_led_drvdata) +
  16274. + sizeof(struct rb750_led_dev) * pdata->num_leds,
  16275. + GFP_KERNEL);
  16276. + if (!drvdata)
  16277. + return -ENOMEM;
  16278. +
  16279. + drvdata->num_leds = pdata->num_leds;
  16280. + drvdata->led_devs = (struct rb750_led_dev *) &drvdata[1];
  16281. +
  16282. + for (i = 0; i < drvdata->num_leds; i++) {
  16283. + struct rb750_led_dev *rbled = &drvdata->led_devs[i];
  16284. + struct rb750_led_data *led_data = &pdata->leds[i];
  16285. +
  16286. + rbled->cdev.name = led_data->name;
  16287. + rbled->cdev.default_trigger = led_data->default_trigger;
  16288. + rbled->cdev.brightness_set = rb750_led_brightness_set;
  16289. + rbled->cdev.brightness = LED_OFF;
  16290. +
  16291. + rbled->mask = led_data->mask;
  16292. + rbled->active_low = !!led_data->active_low;
  16293. +
  16294. + ret = led_classdev_register(&pdev->dev, &rbled->cdev);
  16295. + if (ret)
  16296. + goto err;
  16297. + }
  16298. +
  16299. + platform_set_drvdata(pdev, drvdata);
  16300. + return 0;
  16301. +
  16302. +err:
  16303. + for (i = i - 1; i >= 0; i--)
  16304. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  16305. +
  16306. + kfree(drvdata);
  16307. + return ret;
  16308. +}
  16309. +
  16310. +static int __devexit rb750_led_remove(struct platform_device *pdev)
  16311. +{
  16312. + struct rb750_led_drvdata *drvdata;
  16313. + int i;
  16314. +
  16315. + drvdata = platform_get_drvdata(pdev);
  16316. + for (i = 0; i < drvdata->num_leds; i++)
  16317. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  16318. +
  16319. + kfree(drvdata);
  16320. + return 0;
  16321. +}
  16322. +
  16323. +static struct platform_driver rb750_led_driver = {
  16324. + .probe = rb750_led_probe,
  16325. + .remove = __devexit_p(rb750_led_remove),
  16326. + .driver = {
  16327. + .name = DRV_NAME,
  16328. + .owner = THIS_MODULE,
  16329. + },
  16330. +};
  16331. +
  16332. +MODULE_ALIAS("platform:leds-rb750");
  16333. +
  16334. +static int __init rb750_led_init(void)
  16335. +{
  16336. + return platform_driver_register(&rb750_led_driver);
  16337. +}
  16338. +
  16339. +static void __exit rb750_led_exit(void)
  16340. +{
  16341. + platform_driver_unregister(&rb750_led_driver);
  16342. +}
  16343. +
  16344. +module_init(rb750_led_init);
  16345. +module_exit(rb750_led_exit);
  16346. +
  16347. +MODULE_DESCRIPTION(DRV_NAME);
  16348. +MODULE_DESCRIPTION("LED driver for the RouterBOARD 750");
  16349. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16350. +MODULE_LICENSE("GPL v2");
  16351. diff -Nur linux-2.6.39.orig/drivers/leds/leds-wndr3700-usb.c linux-2.6.39/drivers/leds/leds-wndr3700-usb.c
  16352. --- linux-2.6.39.orig/drivers/leds/leds-wndr3700-usb.c 1970-01-01 01:00:00.000000000 +0100
  16353. +++ linux-2.6.39/drivers/leds/leds-wndr3700-usb.c 2011-04-27 12:19:22.267661616 +0200
  16354. @@ -0,0 +1,75 @@
  16355. +/*
  16356. + * USB LED driver for the NETGEAR WNDR3700
  16357. + *
  16358. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  16359. + *
  16360. + * This program is free software; you can redistribute it and/or modify it
  16361. + * under the terms of the GNU General Public License version 2 as published
  16362. + * by the Free Software Foundation.
  16363. + */
  16364. +
  16365. +#include <linux/leds.h>
  16366. +#include <linux/module.h>
  16367. +#include <linux/platform_device.h>
  16368. +
  16369. +#include <asm/mach-ar71xx/ar71xx.h>
  16370. +
  16371. +#define DRIVER_NAME "wndr3700-led-usb"
  16372. +
  16373. +static void wndr3700_usb_led_set(struct led_classdev *cdev,
  16374. + enum led_brightness brightness)
  16375. +{
  16376. + if (brightness)
  16377. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  16378. + else
  16379. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  16380. +}
  16381. +
  16382. +static enum led_brightness wndr3700_usb_led_get(struct led_classdev *cdev)
  16383. +{
  16384. + return ar71xx_device_stopped(RESET_MODULE_GE1_PHY) ? LED_OFF : LED_FULL;
  16385. +}
  16386. +
  16387. +static struct led_classdev wndr3700_usb_led = {
  16388. + .name = "wndr3700:green:usb",
  16389. + .brightness_set = wndr3700_usb_led_set,
  16390. + .brightness_get = wndr3700_usb_led_get,
  16391. +};
  16392. +
  16393. +static int __devinit wndr3700_usb_led_probe(struct platform_device *pdev)
  16394. +{
  16395. + return led_classdev_register(&pdev->dev, &wndr3700_usb_led);
  16396. +}
  16397. +
  16398. +static int __devexit wndr3700_usb_led_remove(struct platform_device *pdev)
  16399. +{
  16400. + led_classdev_unregister(&wndr3700_usb_led);
  16401. + return 0;
  16402. +}
  16403. +
  16404. +static struct platform_driver wndr3700_usb_led_driver = {
  16405. + .probe = wndr3700_usb_led_probe,
  16406. + .remove = __devexit_p(wndr3700_usb_led_remove),
  16407. + .driver = {
  16408. + .name = DRIVER_NAME,
  16409. + .owner = THIS_MODULE,
  16410. + },
  16411. +};
  16412. +
  16413. +static int __init wndr3700_usb_led_init(void)
  16414. +{
  16415. + return platform_driver_register(&wndr3700_usb_led_driver);
  16416. +}
  16417. +
  16418. +static void __exit wndr3700_usb_led_exit(void)
  16419. +{
  16420. + platform_driver_unregister(&wndr3700_usb_led_driver);
  16421. +}
  16422. +
  16423. +module_init(wndr3700_usb_led_init);
  16424. +module_exit(wndr3700_usb_led_exit);
  16425. +
  16426. +MODULE_DESCRIPTION("USB LED driver for the NETGEAR WNDR3700");
  16427. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16428. +MODULE_LICENSE("GPL v2");
  16429. +MODULE_ALIAS("platform:" DRIVER_NAME);
  16430. diff -Nur linux-2.6.39.orig/drivers/Makefile linux-2.6.39/drivers/Makefile
  16431. --- linux-2.6.39.orig/drivers/Makefile 2011-05-19 06:06:34.000000000 +0200
  16432. +++ linux-2.6.39/drivers/Makefile 2011-08-23 15:10:42.370478643 +0200
  16433. @@ -46,8 +46,8 @@
  16434. obj-$(CONFIG_SCSI) += scsi/
  16435. obj-$(CONFIG_ATA) += ata/
  16436. obj-$(CONFIG_TARGET_CORE) += target/
  16437. -obj-$(CONFIG_MTD) += mtd/
  16438. obj-$(CONFIG_SPI) += spi/
  16439. +obj-$(CONFIG_MTD) += mtd/
  16440. obj-y += net/
  16441. obj-$(CONFIG_ATM) += atm/
  16442. obj-$(CONFIG_FUSION) += message/
  16443. diff -Nur linux-2.6.39.orig/drivers/mtd/chips/cfi_cmdset_0002.c linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0002.c
  16444. --- linux-2.6.39.orig/drivers/mtd/chips/cfi_cmdset_0002.c 2011-05-19 06:06:34.000000000 +0200
  16445. +++ linux-2.6.39/drivers/mtd/chips/cfi_cmdset_0002.c 2011-08-22 16:22:28.477979654 +0200
  16446. @@ -39,7 +39,7 @@
  16447. #include <linux/mtd/xip.h>
  16448. #define AMD_BOOTLOC_BUG
  16449. -#define FORCE_WORD_WRITE 0
  16450. +#define FORCE_WORD_WRITE 1
  16451. #define MAX_WORD_RETRIES 3
  16452. @@ -50,7 +50,9 @@
  16453. static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  16454. static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  16455. +#if !FORCE_WORD_WRITE
  16456. static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  16457. +#endif
  16458. static int cfi_amdstd_erase_chip(struct mtd_info *, struct erase_info *);
  16459. static int cfi_amdstd_erase_varsize(struct mtd_info *, struct erase_info *);
  16460. static void cfi_amdstd_sync (struct mtd_info *);
  16461. @@ -186,6 +188,7 @@
  16462. }
  16463. #endif
  16464. +#if !FORCE_WORD_WRITE
  16465. static void fixup_use_write_buffers(struct mtd_info *mtd)
  16466. {
  16467. struct map_info *map = mtd->priv;
  16468. @@ -195,6 +198,7 @@
  16469. mtd->write = cfi_amdstd_write_buffers;
  16470. }
  16471. }
  16472. +#endif /* !FORCE_WORD_WRITE */
  16473. /* Atmel chips don't use the same PRI format as AMD chips */
  16474. static void fixup_convert_atmel_pri(struct mtd_info *mtd)
  16475. @@ -1377,6 +1381,7 @@
  16476. /*
  16477. * FIXME: interleaved mode not tested, and probably not supported!
  16478. */
  16479. +#if !FORCE_WORD_WRITE
  16480. static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
  16481. unsigned long adr, const u_char *buf,
  16482. int len)
  16483. @@ -1487,7 +1492,6 @@
  16484. return ret;
  16485. }
  16486. -
  16487. static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
  16488. size_t *retlen, const u_char *buf)
  16489. {
  16490. @@ -1566,6 +1570,7 @@
  16491. return 0;
  16492. }
  16493. +#endif /* !FORCE_WORD_WRITE */
  16494. /*
  16495. diff -Nur linux-2.6.39.orig/drivers/mtd/maps/ar91xx_flash.c linux-2.6.39/drivers/mtd/maps/ar91xx_flash.c
  16496. --- linux-2.6.39.orig/drivers/mtd/maps/ar91xx_flash.c 1970-01-01 01:00:00.000000000 +0100
  16497. +++ linux-2.6.39/drivers/mtd/maps/ar91xx_flash.c 2011-04-27 12:19:22.177661504 +0200
  16498. @@ -0,0 +1,310 @@
  16499. +/*
  16500. + * Parallel flash driver for the Atheros AR91xx SoC
  16501. + *
  16502. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  16503. + *
  16504. + * This program is free software; you can redistribute it and/or modify
  16505. + * it under the terms of the GNU General Public License version 2 as
  16506. + * published by the Free Software Foundation.
  16507. + *
  16508. + */
  16509. +
  16510. +#include <linux/module.h>
  16511. +#include <linux/types.h>
  16512. +#include <linux/kernel.h>
  16513. +#include <linux/init.h>
  16514. +#include <linux/slab.h>
  16515. +#include <linux/device.h>
  16516. +#include <linux/platform_device.h>
  16517. +#include <linux/mtd/mtd.h>
  16518. +#include <linux/mtd/map.h>
  16519. +#include <linux/mtd/partitions.h>
  16520. +#include <linux/io.h>
  16521. +
  16522. +#include <asm/mach-ar71xx/ar71xx.h>
  16523. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  16524. +
  16525. +#define DRV_NAME "ar91xx-flash"
  16526. +
  16527. +struct ar91xx_flash_info {
  16528. + struct mtd_info *mtd;
  16529. + struct map_info map;
  16530. +#ifdef CONFIG_MTD_PARTITIONS
  16531. + int nr_parts;
  16532. + struct mtd_partition *parts;
  16533. +#endif
  16534. +};
  16535. +
  16536. +static map_word ar91xx_flash_read(struct map_info *map, unsigned long ofs)
  16537. +{
  16538. + map_word val;
  16539. +
  16540. + if (map_bankwidth_is_1(map))
  16541. + val.x[0] = __raw_readb(map->virt + (ofs ^ 3));
  16542. + else if (map_bankwidth_is_2(map))
  16543. + val.x[0] = __raw_readw(map->virt + (ofs ^ 2));
  16544. + else
  16545. + val = map_word_ff(map);
  16546. +
  16547. + return val;
  16548. +}
  16549. +
  16550. +static void ar91xx_flash_write(struct map_info *map, map_word d,
  16551. + unsigned long ofs)
  16552. +{
  16553. + if (map_bankwidth_is_1(map))
  16554. + __raw_writeb(d.x[0], map->virt + (ofs ^ 3));
  16555. + else if (map_bankwidth_is_2(map))
  16556. + __raw_writew(d.x[0], map->virt + (ofs ^ 2));
  16557. +
  16558. + mb();
  16559. +}
  16560. +
  16561. +static map_word ar91xx_flash_read_lock(struct map_info *map, unsigned long ofs)
  16562. +{
  16563. + map_word ret;
  16564. +
  16565. + ar71xx_flash_acquire();
  16566. + ret = ar91xx_flash_read(map, ofs);
  16567. + ar71xx_flash_release();
  16568. +
  16569. + return ret;
  16570. +}
  16571. +
  16572. +static void ar91xx_flash_write_lock(struct map_info *map, map_word d,
  16573. + unsigned long ofs)
  16574. +{
  16575. + ar71xx_flash_acquire();
  16576. + ar91xx_flash_write(map, d, ofs);
  16577. + ar71xx_flash_release();
  16578. +}
  16579. +
  16580. +static void ar91xx_flash_copy_from_lock(struct map_info *map, void *to,
  16581. + unsigned long from, ssize_t len)
  16582. +{
  16583. + ar71xx_flash_acquire();
  16584. + inline_map_copy_from(map, to, from, len);
  16585. + ar71xx_flash_release();
  16586. +}
  16587. +
  16588. +static void ar91xx_flash_copy_to_lock(struct map_info *map, unsigned long to,
  16589. + const void *from, ssize_t len)
  16590. +{
  16591. + ar71xx_flash_acquire();
  16592. + inline_map_copy_to(map, to, from, len);
  16593. + ar71xx_flash_release();
  16594. +}
  16595. +
  16596. +static int ar91xx_flash_remove(struct platform_device *pdev)
  16597. +{
  16598. + struct ar91xx_flash_platform_data *pdata;
  16599. + struct ar91xx_flash_info *info;
  16600. +
  16601. + info = platform_get_drvdata(pdev);
  16602. + if (info == NULL)
  16603. + return 0;
  16604. +
  16605. + platform_set_drvdata(pdev, NULL);
  16606. +
  16607. + if (info->mtd == NULL)
  16608. + return 0;
  16609. +
  16610. + pdata = pdev->dev.platform_data;
  16611. +#ifdef CONFIG_MTD_PARTITIONS
  16612. + if (info->nr_parts) {
  16613. + del_mtd_partitions(info->mtd);
  16614. + kfree(info->parts);
  16615. + } else if (pdata->nr_parts) {
  16616. + del_mtd_partitions(info->mtd);
  16617. + } else {
  16618. + del_mtd_device(info->mtd);
  16619. + }
  16620. +#else
  16621. + del_mtd_device(info->mtd);
  16622. +#endif
  16623. + map_destroy(info->mtd);
  16624. +
  16625. + return 0;
  16626. +}
  16627. +
  16628. +static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
  16629. +#ifdef CONFIG_MTD_PARTITIONS
  16630. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  16631. +#endif
  16632. +
  16633. +static int ar91xx_flash_probe(struct platform_device *pdev)
  16634. +{
  16635. + struct ar91xx_flash_platform_data *pdata;
  16636. + struct ar91xx_flash_info *info;
  16637. + struct resource *res;
  16638. + struct resource *region;
  16639. + const char **probe_type;
  16640. + int err = 0;
  16641. +
  16642. + pdata = pdev->dev.platform_data;
  16643. + if (pdata == NULL)
  16644. + return -EINVAL;
  16645. +
  16646. + info = devm_kzalloc(&pdev->dev, sizeof(struct ar91xx_flash_info),
  16647. + GFP_KERNEL);
  16648. + if (info == NULL) {
  16649. + err = -ENOMEM;
  16650. + goto err_out;
  16651. + }
  16652. +
  16653. + platform_set_drvdata(pdev, info);
  16654. +
  16655. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  16656. + if (res == NULL) {
  16657. + err = -ENOENT;
  16658. + goto err_out;
  16659. + }
  16660. +
  16661. + dev_info(&pdev->dev, "%.8llx at %.8llx\n",
  16662. + (unsigned long long)(res->end - res->start + 1),
  16663. + (unsigned long long)res->start);
  16664. +
  16665. + region = devm_request_mem_region(&pdev->dev,
  16666. + res->start, res->end - res->start + 1,
  16667. + dev_name(&pdev->dev));
  16668. + if (region == NULL) {
  16669. + dev_err(&pdev->dev, "could not reserve memory region\n");
  16670. + err = -ENOMEM;
  16671. + goto err_out;
  16672. + }
  16673. +
  16674. + info->map.name = dev_name(&pdev->dev);
  16675. + info->map.phys = res->start;
  16676. + info->map.size = res->end - res->start + 1;
  16677. + info->map.bankwidth = pdata->width;
  16678. +
  16679. + info->map.virt = devm_ioremap(&pdev->dev, info->map.phys,
  16680. + info->map.size);
  16681. + if (info->map.virt == NULL) {
  16682. + dev_err(&pdev->dev, "failed to ioremap flash region\n");
  16683. + err = -EIO;
  16684. + goto err_out;
  16685. + }
  16686. +
  16687. + simple_map_init(&info->map);
  16688. + if (pdata->is_shared) {
  16689. + info->map.read = ar91xx_flash_read_lock;
  16690. + info->map.write = ar91xx_flash_write_lock;
  16691. + info->map.copy_from = ar91xx_flash_copy_from_lock;
  16692. + info->map.copy_to = ar91xx_flash_copy_to_lock;
  16693. + } else {
  16694. + info->map.read = ar91xx_flash_read;
  16695. + info->map.write = ar91xx_flash_write;
  16696. + }
  16697. +
  16698. + probe_type = rom_probe_types;
  16699. + for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
  16700. + info->mtd = do_map_probe(*probe_type, &info->map);
  16701. +
  16702. + if (info->mtd == NULL) {
  16703. + dev_err(&pdev->dev, "map_probe failed\n");
  16704. + err = -ENXIO;
  16705. + goto err_out;
  16706. + }
  16707. +
  16708. + info->mtd->owner = THIS_MODULE;
  16709. +
  16710. +#ifdef CONFIG_MTD_PARTITIONS
  16711. + if (pdata->nr_parts) {
  16712. + dev_info(&pdev->dev, "using static partition mapping\n");
  16713. + add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
  16714. + return 0;
  16715. + }
  16716. +
  16717. + err = parse_mtd_partitions(info->mtd, part_probe_types,
  16718. + &info->parts, 0);
  16719. + if (err > 0) {
  16720. + add_mtd_partitions(info->mtd, info->parts, err);
  16721. + return 0;
  16722. + }
  16723. +#endif
  16724. +
  16725. + add_mtd_device(info->mtd);
  16726. + return 0;
  16727. +
  16728. +err_out:
  16729. + ar91xx_flash_remove(pdev);
  16730. + return err;
  16731. +}
  16732. +
  16733. +#ifdef CONFIG_PM
  16734. +static int ar91xx_flash_suspend(struct platform_device *dev, pm_message_t state)
  16735. +{
  16736. + struct ar91xx_flash_info *info = platform_get_drvdata(dev);
  16737. + int ret = 0;
  16738. +
  16739. + if (info->mtd->suspend)
  16740. + ret = info->mtd->suspend(info->mtd);
  16741. +
  16742. + if (ret)
  16743. + goto fail;
  16744. +
  16745. + return 0;
  16746. +
  16747. +fail:
  16748. + if (info->mtd->suspend) {
  16749. + BUG_ON(!info->mtd->resume);
  16750. + info->mtd->resume(info->mtd);
  16751. + }
  16752. +
  16753. + return ret;
  16754. +}
  16755. +
  16756. +static int ar91xx_flash_resume(struct platform_device *pdev)
  16757. +{
  16758. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  16759. +
  16760. + if (info->mtd->resume)
  16761. + info->mtd->resume(info->mtd);
  16762. +
  16763. + return 0;
  16764. +}
  16765. +
  16766. +static void ar91xx_flash_shutdown(struct platform_device *pdev)
  16767. +{
  16768. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  16769. +
  16770. + if (info->mtd->suspend && info->mtd->resume)
  16771. + if (info->mtd->suspend(info->mtd) == 0)
  16772. + info->mtd->resume(info->mtd);
  16773. +}
  16774. +#else
  16775. +#define ar91xx_flash_suspend NULL
  16776. +#define ar91xx_flash_resume NULL
  16777. +#define ar91xx_flash_shutdown NULL
  16778. +#endif
  16779. +
  16780. +static struct platform_driver ar91xx_flash_driver = {
  16781. + .probe = ar91xx_flash_probe,
  16782. + .remove = ar91xx_flash_remove,
  16783. + .suspend = ar91xx_flash_suspend,
  16784. + .resume = ar91xx_flash_resume,
  16785. + .shutdown = ar91xx_flash_shutdown,
  16786. + .driver = {
  16787. + .name = DRV_NAME,
  16788. + .owner = THIS_MODULE,
  16789. + },
  16790. +};
  16791. +
  16792. +static int __init ar91xx_flash_init(void)
  16793. +{
  16794. + return platform_driver_register(&ar91xx_flash_driver);
  16795. +}
  16796. +
  16797. +static void __exit ar91xx_flash_exit(void)
  16798. +{
  16799. + platform_driver_unregister(&ar91xx_flash_driver);
  16800. +}
  16801. +
  16802. +module_init(ar91xx_flash_init);
  16803. +module_exit(ar91xx_flash_exit);
  16804. +
  16805. +MODULE_LICENSE("GPL v2");
  16806. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16807. +MODULE_DESCRIPTION("Parallel flash driver for the Atheros AR91xx SoC");
  16808. +MODULE_ALIAS("platform:" DRV_NAME);
  16809. diff -Nur linux-2.6.39.orig/drivers/mtd/maps/Kconfig linux-2.6.39/drivers/mtd/maps/Kconfig
  16810. --- linux-2.6.39.orig/drivers/mtd/maps/Kconfig 2011-05-19 06:06:34.000000000 +0200
  16811. +++ linux-2.6.39/drivers/mtd/maps/Kconfig 2011-08-22 16:22:06.367979538 +0200
  16812. @@ -260,6 +260,13 @@
  16813. Support for parsing CFE image tag and creating MTD partitions on
  16814. Broadcom BCM63xx boards.
  16815. +config MTD_AR91XX_FLASH
  16816. + tristate "Atheros AR91xx parallel flash support"
  16817. + depends on ATHEROS_AR71XX
  16818. + select MTD_COMPLEX_MAPPINGS
  16819. + help
  16820. + Parallel flash driver for the Atheros AR91xx based boards.
  16821. +
  16822. config MTD_DILNETPC
  16823. tristate "CFI Flash device mapped on DIL/Net PC"
  16824. depends on X86 && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
  16825. diff -Nur linux-2.6.39.orig/drivers/mtd/maps/Makefile linux-2.6.39/drivers/mtd/maps/Makefile
  16826. --- linux-2.6.39.orig/drivers/mtd/maps/Makefile 2011-05-19 06:06:34.000000000 +0200
  16827. +++ linux-2.6.39/drivers/mtd/maps/Makefile 2011-08-22 16:22:06.387979567 +0200
  16828. @@ -40,6 +40,7 @@
  16829. obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
  16830. obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
  16831. obj-$(CONFIG_MTD_PCI) += pci.o
  16832. +obj-$(CONFIG_MTD_AR91XX_FLASH) += ar91xx_flash.o
  16833. obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
  16834. obj-$(CONFIG_MTD_EDB7312) += edb7312.o
  16835. obj-$(CONFIG_MTD_IMPA7) += impa7.o
  16836. diff -Nur linux-2.6.39.orig/drivers/mtd/nand/Kconfig linux-2.6.39/drivers/mtd/nand/Kconfig
  16837. --- linux-2.6.39.orig/drivers/mtd/nand/Kconfig 2011-05-19 06:06:34.000000000 +0200
  16838. +++ linux-2.6.39/drivers/mtd/nand/Kconfig 2011-08-23 14:22:33.407989933 +0200
  16839. @@ -531,4 +531,9 @@
  16840. Enables support for NAND Flash chips on the ST Microelectronics
  16841. Flexible Static Memory Controller (FSMC)
  16842. +config MTD_NAND_RB4XX
  16843. + tristate "NAND flash driver for RouterBoard 4xx series"
  16844. + depends on MTD_NAND && AR71XX_MACH_RB4XX
  16845. + select SPI_AR71XX
  16846. +
  16847. endif # MTD_NAND
  16848. diff -Nur linux-2.6.39.orig/drivers/mtd/nand/Makefile linux-2.6.39/drivers/mtd/nand/Makefile
  16849. --- linux-2.6.39.orig/drivers/mtd/nand/Makefile 2011-05-19 06:06:34.000000000 +0200
  16850. +++ linux-2.6.39/drivers/mtd/nand/Makefile 2011-08-22 16:22:41.217981942 +0200
  16851. @@ -34,6 +34,7 @@
  16852. obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
  16853. obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o
  16854. obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
  16855. +obj-$(CONFIG_MTD_NAND_RB4XX) += rb4xx_nand.o
  16856. obj-$(CONFIG_MTD_ALAUDA) += alauda.o
  16857. obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
  16858. obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
  16859. diff -Nur linux-2.6.39.orig/drivers/mtd/nand/rb4xx_nand.c linux-2.6.39/drivers/mtd/nand/rb4xx_nand.c
  16860. --- linux-2.6.39.orig/drivers/mtd/nand/rb4xx_nand.c 1970-01-01 01:00:00.000000000 +0100
  16861. +++ linux-2.6.39/drivers/mtd/nand/rb4xx_nand.c 2011-08-23 11:36:58.637983055 +0200
  16862. @@ -0,0 +1,311 @@
  16863. +/*
  16864. + * NAND flash driver for the MikroTik RouterBoard 4xx series
  16865. + *
  16866. + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  16867. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16868. + *
  16869. + * This file was based on the driver for Linux 2.6.22 published by
  16870. + * MikroTik for their RouterBoard 4xx series devices.
  16871. + *
  16872. + * This program is free software; you can redistribute it and/or modify it
  16873. + * under the terms of the GNU General Public License version 2 as published
  16874. + * by the Free Software Foundation.
  16875. + */
  16876. +
  16877. +#include <linux/init.h>
  16878. +#include <linux/mtd/nand.h>
  16879. +#include <linux/mtd/mtd.h>
  16880. +#include <linux/mtd/partitions.h>
  16881. +#include <linux/platform_device.h>
  16882. +#include <linux/delay.h>
  16883. +#include <linux/io.h>
  16884. +#include <linux/gpio.h>
  16885. +#include <linux/slab.h>
  16886. +
  16887. +#include <asm/mach-ar71xx/ar71xx.h>
  16888. +#include <asm/mach-ar71xx/rb4xx_cpld.h>
  16889. +
  16890. +#define DRV_NAME "rb4xx-nand"
  16891. +#define DRV_VERSION "0.2.0"
  16892. +#define DRV_DESC "NAND flash driver for RouterBoard 4xx series"
  16893. +
  16894. +#define RB4XX_NAND_GPIO_READY 5
  16895. +#define RB4XX_NAND_GPIO_ALE 37
  16896. +#define RB4XX_NAND_GPIO_CLE 38
  16897. +#define RB4XX_NAND_GPIO_NCE 39
  16898. +
  16899. +struct rb4xx_nand_info {
  16900. + struct nand_chip chip;
  16901. + struct mtd_info mtd;
  16902. +};
  16903. +
  16904. +/*
  16905. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  16906. + * will not be able to find the kernel that we load.
  16907. + */
  16908. +static struct nand_ecclayout rb4xx_nand_ecclayout = {
  16909. + .eccbytes = 6,
  16910. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  16911. + .oobavail = 9,
  16912. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  16913. +};
  16914. +
  16915. +static struct mtd_partition rb4xx_nand_partitions[] = {
  16916. + {
  16917. + .name = "booter",
  16918. + .offset = 0,
  16919. + .size = (256 * 1024),
  16920. + .mask_flags = MTD_WRITEABLE,
  16921. + },
  16922. + {
  16923. + .name = "kernel",
  16924. + .offset = (256 * 1024),
  16925. + .size = (6 * 1024 * 1024) - (256 * 1024),
  16926. + },
  16927. + {
  16928. + .name = "rootfs",
  16929. + .offset = MTDPART_OFS_NXTBLK,
  16930. + .size = MTDPART_SIZ_FULL,
  16931. + },
  16932. +};
  16933. +
  16934. +static int rb4xx_nand_dev_ready(struct mtd_info *mtd)
  16935. +{
  16936. + return gpio_get_value_cansleep(RB4XX_NAND_GPIO_READY);
  16937. +}
  16938. +
  16939. +static void rb4xx_nand_write_cmd(unsigned char cmd)
  16940. +{
  16941. + unsigned char data = cmd;
  16942. + int err;
  16943. +
  16944. + err = rb4xx_cpld_write(&data, 1);
  16945. + if (err)
  16946. + pr_err("rb4xx_nand: write cmd failed, err=%d\n", err);
  16947. +}
  16948. +
  16949. +static void rb4xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  16950. + unsigned int ctrl)
  16951. +{
  16952. + if (ctrl & NAND_CTRL_CHANGE) {
  16953. + gpio_set_value_cansleep(RB4XX_NAND_GPIO_CLE,
  16954. + (ctrl & NAND_CLE) ? 1 : 0);
  16955. + gpio_set_value_cansleep(RB4XX_NAND_GPIO_ALE,
  16956. + (ctrl & NAND_ALE) ? 1 : 0);
  16957. + gpio_set_value_cansleep(RB4XX_NAND_GPIO_NCE,
  16958. + (ctrl & NAND_NCE) ? 0 : 1);
  16959. + }
  16960. +
  16961. + if (cmd != NAND_CMD_NONE)
  16962. + rb4xx_nand_write_cmd(cmd);
  16963. +}
  16964. +
  16965. +static unsigned char rb4xx_nand_read_byte(struct mtd_info *mtd)
  16966. +{
  16967. + unsigned char data = 0;
  16968. + int err;
  16969. +
  16970. + err = rb4xx_cpld_read(&data, NULL, 1);
  16971. + if (err) {
  16972. + pr_err("rb4xx_nand: read data failed, err=%d\n", err);
  16973. + data = 0xff;
  16974. + }
  16975. +
  16976. + return data;
  16977. +}
  16978. +
  16979. +static void rb4xx_nand_write_buf(struct mtd_info *mtd, const unsigned char *buf,
  16980. + int len)
  16981. +{
  16982. + int err;
  16983. +
  16984. + err = rb4xx_cpld_write(buf, len);
  16985. + if (err)
  16986. + pr_err("rb4xx_nand: write buf failed, err=%d\n", err);
  16987. +}
  16988. +
  16989. +static void rb4xx_nand_read_buf(struct mtd_info *mtd, unsigned char *buf,
  16990. + int len)
  16991. +{
  16992. + int err;
  16993. +
  16994. + err = rb4xx_cpld_read(buf, NULL, len);
  16995. + if (err)
  16996. + pr_err("rb4xx_nand: read buf failed, err=%d\n", err);
  16997. +}
  16998. +
  16999. +static int __init rb4xx_nand_probe(struct platform_device *pdev)
  17000. +{
  17001. + struct rb4xx_nand_info *info;
  17002. + int ret;
  17003. +
  17004. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  17005. +
  17006. + ret = gpio_request(RB4XX_NAND_GPIO_READY, "NAND RDY");
  17007. + if (ret) {
  17008. + dev_err(&pdev->dev, "unable to request gpio %d\n",
  17009. + RB4XX_NAND_GPIO_READY);
  17010. + goto err;
  17011. + }
  17012. +
  17013. + ret = gpio_direction_input(RB4XX_NAND_GPIO_READY);
  17014. + if (ret) {
  17015. + dev_err(&pdev->dev, "unable to set input mode on gpio %d\n",
  17016. + RB4XX_NAND_GPIO_READY);
  17017. + goto err_free_gpio_ready;
  17018. + }
  17019. +
  17020. + ret = gpio_request(RB4XX_NAND_GPIO_ALE, "NAND ALE");
  17021. + if (ret) {
  17022. + dev_err(&pdev->dev, "unable to request gpio %d\n",
  17023. + RB4XX_NAND_GPIO_ALE);
  17024. + goto err_free_gpio_ready;
  17025. + }
  17026. +
  17027. + ret = gpio_direction_output(RB4XX_NAND_GPIO_ALE, 0);
  17028. + if (ret) {
  17029. + dev_err(&pdev->dev, "unable to set output mode on gpio %d\n",
  17030. + RB4XX_NAND_GPIO_ALE);
  17031. + goto err_free_gpio_ale;
  17032. + }
  17033. +
  17034. + ret = gpio_request(RB4XX_NAND_GPIO_CLE, "NAND CLE");
  17035. + if (ret) {
  17036. + dev_err(&pdev->dev, "unable to request gpio %d\n",
  17037. + RB4XX_NAND_GPIO_CLE);
  17038. + goto err_free_gpio_ale;
  17039. + }
  17040. +
  17041. + ret = gpio_direction_output(RB4XX_NAND_GPIO_CLE, 0);
  17042. + if (ret) {
  17043. + dev_err(&pdev->dev, "unable to set output mode on gpio %d\n",
  17044. + RB4XX_NAND_GPIO_CLE);
  17045. + goto err_free_gpio_cle;
  17046. + }
  17047. +
  17048. + ret = gpio_request(RB4XX_NAND_GPIO_NCE, "NAND NCE");
  17049. + if (ret) {
  17050. + dev_err(&pdev->dev, "unable to request gpio %d\n",
  17051. + RB4XX_NAND_GPIO_NCE);
  17052. + goto err_free_gpio_cle;
  17053. + }
  17054. +
  17055. + ret = gpio_direction_output(RB4XX_NAND_GPIO_NCE, 1);
  17056. + if (ret) {
  17057. + dev_err(&pdev->dev, "unable to set output mode on gpio %d\n",
  17058. + RB4XX_NAND_GPIO_ALE);
  17059. + goto err_free_gpio_nce;
  17060. + }
  17061. +
  17062. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  17063. + if (!info) {
  17064. + dev_err(&pdev->dev, "rb4xx-nand: no memory for private data\n");
  17065. + ret = -ENOMEM;
  17066. + goto err_free_gpio_nce;
  17067. + }
  17068. +
  17069. + info->chip.priv = &info;
  17070. + info->mtd.priv = &info->chip;
  17071. + info->mtd.owner = THIS_MODULE;
  17072. +
  17073. + info->chip.cmd_ctrl = rb4xx_nand_cmd_ctrl;
  17074. + info->chip.dev_ready = rb4xx_nand_dev_ready;
  17075. + info->chip.read_byte = rb4xx_nand_read_byte;
  17076. + info->chip.write_buf = rb4xx_nand_write_buf;
  17077. + info->chip.read_buf = rb4xx_nand_read_buf;
  17078. +#if 0
  17079. + info->chip.verify_buf = rb4xx_nand_verify_buf;
  17080. +#endif
  17081. +
  17082. + info->chip.chip_delay = 25;
  17083. + info->chip.ecc.mode = NAND_ECC_SOFT;
  17084. + info->chip.options |= NAND_NO_AUTOINCR;
  17085. +
  17086. + platform_set_drvdata(pdev, info);
  17087. +
  17088. + ret = nand_scan_ident(&info->mtd, 1, NULL);
  17089. + if (ret) {
  17090. + ret = -ENXIO;
  17091. + goto err_free_info;
  17092. + }
  17093. +
  17094. + if (info->mtd.writesize == 512)
  17095. + info->chip.ecc.layout = &rb4xx_nand_ecclayout;
  17096. +
  17097. + ret = nand_scan_tail(&info->mtd);
  17098. + if (ret) {
  17099. + return -ENXIO;
  17100. + goto err_set_drvdata;
  17101. + }
  17102. +
  17103. +#ifdef CONFIG_MTD_PARTITIONS
  17104. + ret = add_mtd_partitions(&info->mtd, rb4xx_nand_partitions,
  17105. + ARRAY_SIZE(rb4xx_nand_partitions));
  17106. +#else
  17107. + ret = add_mtd_device(&info->mtd);
  17108. +#endif
  17109. + if (ret)
  17110. + goto err_release_nand;
  17111. +
  17112. + return 0;
  17113. +
  17114. +err_release_nand:
  17115. + nand_release(&info->mtd);
  17116. +err_set_drvdata:
  17117. + platform_set_drvdata(pdev, NULL);
  17118. +err_free_info:
  17119. + kfree(info);
  17120. +err_free_gpio_nce:
  17121. + gpio_free(RB4XX_NAND_GPIO_NCE);
  17122. +err_free_gpio_cle:
  17123. + gpio_free(RB4XX_NAND_GPIO_CLE);
  17124. +err_free_gpio_ale:
  17125. + gpio_free(RB4XX_NAND_GPIO_ALE);
  17126. +err_free_gpio_ready:
  17127. + gpio_free(RB4XX_NAND_GPIO_READY);
  17128. +err:
  17129. + return ret;
  17130. +}
  17131. +
  17132. +static int __devexit rb4xx_nand_remove(struct platform_device *pdev)
  17133. +{
  17134. + struct rb4xx_nand_info *info = platform_get_drvdata(pdev);
  17135. +
  17136. + nand_release(&info->mtd);
  17137. + platform_set_drvdata(pdev, NULL);
  17138. + kfree(info);
  17139. + gpio_free(RB4XX_NAND_GPIO_NCE);
  17140. + gpio_free(RB4XX_NAND_GPIO_CLE);
  17141. + gpio_free(RB4XX_NAND_GPIO_ALE);
  17142. + gpio_free(RB4XX_NAND_GPIO_READY);
  17143. +
  17144. + return 0;
  17145. +}
  17146. +
  17147. +static struct platform_driver rb4xx_nand_driver = {
  17148. + .probe = rb4xx_nand_probe,
  17149. + .remove = __devexit_p(rb4xx_nand_remove),
  17150. + .driver = {
  17151. + .name = DRV_NAME,
  17152. + .owner = THIS_MODULE,
  17153. + },
  17154. +};
  17155. +
  17156. +static int __init rb4xx_nand_init(void)
  17157. +{
  17158. + return platform_driver_register(&rb4xx_nand_driver);
  17159. +}
  17160. +
  17161. +static void __exit rb4xx_nand_exit(void)
  17162. +{
  17163. + platform_driver_unregister(&rb4xx_nand_driver);
  17164. +}
  17165. +
  17166. +module_init(rb4xx_nand_init);
  17167. +module_exit(rb4xx_nand_exit);
  17168. +
  17169. +MODULE_DESCRIPTION(DRV_DESC);
  17170. +MODULE_VERSION(DRV_VERSION);
  17171. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  17172. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  17173. +MODULE_LICENSE("GPL v2");
  17174. diff -Nur linux-2.6.39.orig/drivers/mtd/nand/rb750_nand.c linux-2.6.39/drivers/mtd/nand/rb750_nand.c
  17175. --- linux-2.6.39.orig/drivers/mtd/nand/rb750_nand.c 1970-01-01 01:00:00.000000000 +0100
  17176. +++ linux-2.6.39/drivers/mtd/nand/rb750_nand.c 2011-04-27 12:19:22.177661504 +0200
  17177. @@ -0,0 +1,361 @@
  17178. +/*
  17179. + * NAND flash driver for the MikroTik RouterBOARD 750
  17180. + *
  17181. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  17182. + *
  17183. + * This program is free software; you can redistribute it and/or modify it
  17184. + * under the terms of the GNU General Public License version 2 as published
  17185. + * by the Free Software Foundation.
  17186. + */
  17187. +
  17188. +#include <linux/init.h>
  17189. +#include <linux/mtd/nand.h>
  17190. +#include <linux/mtd/mtd.h>
  17191. +#include <linux/mtd/partitions.h>
  17192. +#include <linux/platform_device.h>
  17193. +#include <linux/io.h>
  17194. +#include <linux/slab.h>
  17195. +
  17196. +#include <asm/mach-ar71xx/ar71xx.h>
  17197. +#include <asm/mach-ar71xx/mach-rb750.h>
  17198. +
  17199. +#define DRV_NAME "rb750-nand"
  17200. +#define DRV_VERSION "0.1.0"
  17201. +#define DRV_DESC "NAND flash driver for the RouterBOARD 750"
  17202. +
  17203. +#define RB750_NAND_IO0 BIT(RB750_GPIO_NAND_IO0)
  17204. +#define RB750_NAND_ALE BIT(RB750_GPIO_NAND_ALE)
  17205. +#define RB750_NAND_CLE BIT(RB750_GPIO_NAND_CLE)
  17206. +#define RB750_NAND_NRE BIT(RB750_GPIO_NAND_NRE)
  17207. +#define RB750_NAND_NWE BIT(RB750_GPIO_NAND_NWE)
  17208. +#define RB750_NAND_RDY BIT(RB750_GPIO_NAND_RDY)
  17209. +#define RB750_NAND_NCE BIT(RB750_GPIO_NAND_NCE)
  17210. +
  17211. +#define RB750_NAND_DATA_SHIFT 1
  17212. +#define RB750_NAND_DATA_BITS (0xff << RB750_NAND_DATA_SHIFT)
  17213. +#define RB750_NAND_INPUT_BITS (RB750_NAND_DATA_BITS | RB750_NAND_RDY)
  17214. +#define RB750_NAND_OUTPUT_BITS (RB750_NAND_ALE | RB750_NAND_CLE | \
  17215. + RB750_NAND_NRE | RB750_NAND_NWE | \
  17216. + RB750_NAND_NCE)
  17217. +
  17218. +struct rb750_nand_info {
  17219. + struct nand_chip chip;
  17220. + struct mtd_info mtd;
  17221. +};
  17222. +
  17223. +/*
  17224. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  17225. + * will not be able to find the kernel that we load.
  17226. + */
  17227. +static struct nand_ecclayout rb750_nand_ecclayout = {
  17228. + .eccbytes = 6,
  17229. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  17230. + .oobavail = 9,
  17231. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  17232. +};
  17233. +
  17234. +static struct mtd_partition rb750_nand_partitions[] = {
  17235. + {
  17236. + .name = "booter",
  17237. + .offset = 0,
  17238. + .size = (256 * 1024),
  17239. + .mask_flags = MTD_WRITEABLE,
  17240. + }, {
  17241. + .name = "kernel",
  17242. + .offset = (256 * 1024),
  17243. + .size = (4 * 1024 * 1024) - (256 * 1024),
  17244. + }, {
  17245. + .name = "rootfs",
  17246. + .offset = MTDPART_OFS_NXTBLK,
  17247. + .size = MTDPART_SIZ_FULL,
  17248. + },
  17249. +};
  17250. +
  17251. +static void rb750_nand_write(const u8 *buf, unsigned len)
  17252. +{
  17253. + void __iomem *base = ar71xx_gpio_base;
  17254. + u32 out;
  17255. + unsigned i;
  17256. +
  17257. + /* set data lines to output mode */
  17258. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_DATA_BITS,
  17259. + base + GPIO_REG_OE);
  17260. +
  17261. + out = __raw_readl(base + GPIO_REG_OUT);
  17262. + out &= ~(RB750_NAND_DATA_BITS | RB750_NAND_NWE);
  17263. + for (i = 0; i != len; i++) {
  17264. + u32 data;
  17265. +
  17266. + data = buf[i];
  17267. + data <<= RB750_NAND_DATA_SHIFT;
  17268. + data |= out;
  17269. + __raw_writel(data, base + GPIO_REG_OUT);
  17270. +
  17271. + __raw_writel(data | RB750_NAND_NWE, base + GPIO_REG_OUT);
  17272. + /* flush write */
  17273. + __raw_readl(base + GPIO_REG_OUT);
  17274. + }
  17275. +
  17276. + /* set data lines to input mode */
  17277. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~RB750_NAND_DATA_BITS,
  17278. + base + GPIO_REG_OE);
  17279. + /* flush write */
  17280. + __raw_readl(base + GPIO_REG_OE);
  17281. +}
  17282. +
  17283. +static int rb750_nand_read_verify(u8 *read_buf, unsigned len,
  17284. + const u8 *verify_buf)
  17285. +{
  17286. + void __iomem *base = ar71xx_gpio_base;
  17287. + unsigned i;
  17288. +
  17289. + for (i = 0; i < len; i++) {
  17290. + u8 data;
  17291. +
  17292. + /* activate RE line */
  17293. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_CLEAR);
  17294. + /* flush write */
  17295. + __raw_readl(base + GPIO_REG_CLEAR);
  17296. +
  17297. + /* read input lines */
  17298. + data = __raw_readl(base + GPIO_REG_IN) >> RB750_NAND_DATA_SHIFT;
  17299. +
  17300. + /* deactivate RE line */
  17301. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_SET);
  17302. +
  17303. + if (read_buf)
  17304. + read_buf[i] = data;
  17305. + else if (verify_buf && verify_buf[i] != data)
  17306. + return -EFAULT;
  17307. + }
  17308. +
  17309. + return 0;
  17310. +}
  17311. +
  17312. +static void rb750_nand_select_chip(struct mtd_info *mtd, int chip)
  17313. +{
  17314. + void __iomem *base = ar71xx_gpio_base;
  17315. + u32 func;
  17316. +
  17317. + func = __raw_readl(base + GPIO_REG_FUNC);
  17318. + if (chip >= 0) {
  17319. + /* disable latch */
  17320. + rb750_latch_change(RB750_LVC573_LE, 0);
  17321. +
  17322. + /* disable alternate functions */
  17323. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  17324. + AR724X_GPIO_FUNC_SPI_EN);
  17325. +
  17326. + /* set input mode for data lines */
  17327. + __raw_writel(__raw_readl(base + GPIO_REG_OE) &
  17328. + ~RB750_NAND_INPUT_BITS,
  17329. + base + GPIO_REG_OE);
  17330. +
  17331. + /* deactivate RE and WE lines */
  17332. + __raw_writel(RB750_NAND_NRE | RB750_NAND_NWE,
  17333. + base + GPIO_REG_SET);
  17334. + /* flush write */
  17335. + (void) __raw_readl(base + GPIO_REG_SET);
  17336. +
  17337. + /* activate CE line */
  17338. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_CLEAR);
  17339. + } else {
  17340. + /* deactivate CE line */
  17341. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_SET);
  17342. + /* flush write */
  17343. + (void) __raw_readl(base + GPIO_REG_SET);
  17344. +
  17345. + __raw_writel(__raw_readl(base + GPIO_REG_OE) |
  17346. + RB750_NAND_IO0 | RB750_NAND_RDY,
  17347. + base + GPIO_REG_OE);
  17348. +
  17349. + /* restore alternate functions */
  17350. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
  17351. + AR724X_GPIO_FUNC_JTAG_DISABLE);
  17352. +
  17353. + /* enable latch */
  17354. + rb750_latch_change(0, RB750_LVC573_LE);
  17355. + }
  17356. +}
  17357. +
  17358. +static int rb750_nand_dev_ready(struct mtd_info *mtd)
  17359. +{
  17360. + void __iomem *base = ar71xx_gpio_base;
  17361. +
  17362. + return !!(__raw_readl(base + GPIO_REG_IN) & RB750_NAND_RDY);
  17363. +}
  17364. +
  17365. +static void rb750_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  17366. + unsigned int ctrl)
  17367. +{
  17368. + if (ctrl & NAND_CTRL_CHANGE) {
  17369. + void __iomem *base = ar71xx_gpio_base;
  17370. + u32 t;
  17371. +
  17372. + t = __raw_readl(base + GPIO_REG_OUT);
  17373. +
  17374. + t &= ~(RB750_NAND_CLE | RB750_NAND_ALE);
  17375. + t |= (ctrl & NAND_CLE) ? RB750_NAND_CLE : 0;
  17376. + t |= (ctrl & NAND_ALE) ? RB750_NAND_ALE : 0;
  17377. +
  17378. + __raw_writel(t, base + GPIO_REG_OUT);
  17379. + /* flush write */
  17380. + __raw_readl(base + GPIO_REG_OUT);
  17381. + }
  17382. +
  17383. + if (cmd != NAND_CMD_NONE) {
  17384. + u8 t = cmd;
  17385. + rb750_nand_write(&t, 1);
  17386. + }
  17387. +}
  17388. +
  17389. +static u8 rb750_nand_read_byte(struct mtd_info *mtd)
  17390. +{
  17391. + u8 data = 0;
  17392. + rb750_nand_read_verify(&data, 1, NULL);
  17393. + return data;
  17394. +}
  17395. +
  17396. +static void rb750_nand_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  17397. +{
  17398. + rb750_nand_read_verify(buf, len, NULL);
  17399. +}
  17400. +
  17401. +static void rb750_nand_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  17402. +{
  17403. + rb750_nand_write(buf, len);
  17404. +}
  17405. +
  17406. +static int rb750_nand_verify_buf(struct mtd_info *mtd, const u8 *buf, int len)
  17407. +{
  17408. + return rb750_nand_read_verify(NULL, len, buf);
  17409. +}
  17410. +
  17411. +static void __init rb750_nand_gpio_init(void)
  17412. +{
  17413. + void __iomem *base = ar71xx_gpio_base;
  17414. + u32 out;
  17415. +
  17416. + out = __raw_readl(base + GPIO_REG_OUT);
  17417. +
  17418. + /* setup output levels */
  17419. + __raw_writel(RB750_NAND_NCE | RB750_NAND_NRE | RB750_NAND_NWE,
  17420. + base + GPIO_REG_SET);
  17421. +
  17422. + __raw_writel(RB750_NAND_ALE | RB750_NAND_CLE,
  17423. + base + GPIO_REG_CLEAR);
  17424. +
  17425. + /* setup input lines */
  17426. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(RB750_NAND_INPUT_BITS),
  17427. + base + GPIO_REG_OE);
  17428. +
  17429. + /* setup output lines */
  17430. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_OUTPUT_BITS,
  17431. + base + GPIO_REG_OE);
  17432. +
  17433. + rb750_latch_change(~out & RB750_NAND_IO0, out & RB750_NAND_IO0);
  17434. +}
  17435. +
  17436. +static int __init rb750_nand_probe(struct platform_device *pdev)
  17437. +{
  17438. + struct rb750_nand_info *info;
  17439. + int ret;
  17440. +
  17441. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  17442. +
  17443. + rb750_nand_gpio_init();
  17444. +
  17445. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  17446. + if (!info)
  17447. + return -ENOMEM;
  17448. +
  17449. + info->chip.priv = &info;
  17450. + info->mtd.priv = &info->chip;
  17451. + info->mtd.owner = THIS_MODULE;
  17452. +
  17453. + info->chip.select_chip = rb750_nand_select_chip;
  17454. + info->chip.cmd_ctrl = rb750_nand_cmd_ctrl;
  17455. + info->chip.dev_ready = rb750_nand_dev_ready;
  17456. + info->chip.read_byte = rb750_nand_read_byte;
  17457. + info->chip.write_buf = rb750_nand_write_buf;
  17458. + info->chip.read_buf = rb750_nand_read_buf;
  17459. + info->chip.verify_buf = rb750_nand_verify_buf;
  17460. +
  17461. + info->chip.chip_delay = 25;
  17462. + info->chip.ecc.mode = NAND_ECC_SOFT;
  17463. + info->chip.options |= NAND_NO_AUTOINCR;
  17464. +
  17465. + platform_set_drvdata(pdev, info);
  17466. +
  17467. + ret = nand_scan_ident(&info->mtd, 1);
  17468. + if (ret) {
  17469. + ret = -ENXIO;
  17470. + goto err_free_info;
  17471. + }
  17472. +
  17473. + if (info->mtd.writesize == 512)
  17474. + info->chip.ecc.layout = &rb750_nand_ecclayout;
  17475. +
  17476. + ret = nand_scan_tail(&info->mtd);
  17477. + if (ret) {
  17478. + return -ENXIO;
  17479. + goto err_set_drvdata;
  17480. + }
  17481. +
  17482. +#ifdef CONFIG_MTD_PARTITIONS
  17483. + ret = add_mtd_partitions(&info->mtd, rb750_nand_partitions,
  17484. + ARRAY_SIZE(rb750_nand_partitions));
  17485. +#else
  17486. + ret = add_mtd_device(&info->mtd);
  17487. +#endif
  17488. + if (ret)
  17489. + goto err_release_nand;
  17490. +
  17491. + return 0;
  17492. +
  17493. +err_release_nand:
  17494. + nand_release(&info->mtd);
  17495. +err_set_drvdata:
  17496. + platform_set_drvdata(pdev, NULL);
  17497. +err_free_info:
  17498. + kfree(info);
  17499. + return ret;
  17500. +}
  17501. +
  17502. +static int __devexit rb750_nand_remove(struct platform_device *pdev)
  17503. +{
  17504. + struct rb750_nand_info *info = platform_get_drvdata(pdev);
  17505. +
  17506. + nand_release(&info->mtd);
  17507. + platform_set_drvdata(pdev, NULL);
  17508. + kfree(info);
  17509. +
  17510. + return 0;
  17511. +}
  17512. +
  17513. +static struct platform_driver rb750_nand_driver = {
  17514. + .probe = rb750_nand_probe,
  17515. + .remove = __devexit_p(rb750_nand_remove),
  17516. + .driver = {
  17517. + .name = DRV_NAME,
  17518. + .owner = THIS_MODULE,
  17519. + },
  17520. +};
  17521. +
  17522. +static int __init rb750_nand_init(void)
  17523. +{
  17524. + return platform_driver_register(&rb750_nand_driver);
  17525. +}
  17526. +
  17527. +static void __exit rb750_nand_exit(void)
  17528. +{
  17529. + platform_driver_unregister(&rb750_nand_driver);
  17530. +}
  17531. +
  17532. +module_init(rb750_nand_init);
  17533. +module_exit(rb750_nand_exit);
  17534. +
  17535. +MODULE_DESCRIPTION(DRV_DESC);
  17536. +MODULE_VERSION(DRV_VERSION);
  17537. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  17538. +MODULE_LICENSE("GPL v2");
  17539. diff -Nur linux-2.6.39.orig/drivers/mtd/wrt160nl_part.c linux-2.6.39/drivers/mtd/wrt160nl_part.c
  17540. --- linux-2.6.39.orig/drivers/mtd/wrt160nl_part.c 1970-01-01 01:00:00.000000000 +0100
  17541. +++ linux-2.6.39/drivers/mtd/wrt160nl_part.c 2011-08-06 09:32:37.138017083 +0200
  17542. @@ -0,0 +1,190 @@
  17543. +/*
  17544. + * Copyright (C) 2009 Christian Daniel <cd@maintech.de>
  17545. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  17546. + *
  17547. + * This program is free software; you can redistribute it and/or modify
  17548. + * it under the terms of the GNU General Public License as published by
  17549. + * the Free Software Foundation; either version 2 of the License, or
  17550. + * (at your option) any later version.
  17551. + *
  17552. + * This program is distributed in the hope that it will be useful,
  17553. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17554. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17555. + * GNU General Public License for more details.
  17556. + *
  17557. + * You should have received a copy of the GNU General Public License
  17558. + * along with this program; if not, write to the Free Software
  17559. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17560. + *
  17561. + * TRX flash partition table.
  17562. + * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
  17563. + *
  17564. + */
  17565. +
  17566. +#include <linux/kernel.h>
  17567. +#include <linux/slab.h>
  17568. +#include <linux/vmalloc.h>
  17569. +
  17570. +#include <linux/mtd/mtd.h>
  17571. +#include <linux/mtd/partitions.h>
  17572. +
  17573. +struct cybertan_header {
  17574. + char magic[4];
  17575. + u8 res1[4];
  17576. + char fw_date[3];
  17577. + char fw_ver[3];
  17578. + char id[4];
  17579. + char hw_ver;
  17580. + char unused;
  17581. + u8 flags[2];
  17582. + u8 res2[10];
  17583. +};
  17584. +
  17585. +#define TRX_PARTS 6
  17586. +#define TRX_MAGIC 0x30524448
  17587. +#define TRX_MAX_OFFSET 3
  17588. +
  17589. +struct trx_header {
  17590. + uint32_t magic; /* "HDR0" */
  17591. + uint32_t len; /* Length of file including header */
  17592. + uint32_t crc32; /* 32-bit CRC from flag_version to end of file */
  17593. + uint32_t flag_version; /* 0:15 flags, 16:31 version */
  17594. + uint32_t offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */
  17595. +};
  17596. +
  17597. +#define IH_MAGIC 0x27051956 /* Image Magic Number */
  17598. +#define IH_NMLEN 32 /* Image Name Length */
  17599. +
  17600. +struct uimage_header {
  17601. + uint32_t ih_magic; /* Image Header Magic Number */
  17602. + uint32_t ih_hcrc; /* Image Header CRC Checksum */
  17603. + uint32_t ih_time; /* Image Creation Timestamp */
  17604. + uint32_t ih_size; /* Image Data Size */
  17605. + uint32_t ih_load; /* Data» Load Address */
  17606. + uint32_t ih_ep; /* Entry Point Address */
  17607. + uint32_t ih_dcrc; /* Image Data CRC Checksum */
  17608. + uint8_t ih_os; /* Operating System */
  17609. + uint8_t ih_arch; /* CPU architecture */
  17610. + uint8_t ih_type; /* Image Type */
  17611. + uint8_t ih_comp; /* Compression Type */
  17612. + uint8_t ih_name[IH_NMLEN]; /* Image Name */
  17613. +};
  17614. +
  17615. +struct wrt160nl_header {
  17616. + struct cybertan_header cybertan;
  17617. + struct trx_header trx;
  17618. + struct uimage_header uimage;
  17619. +} __attribute__ ((packed));
  17620. +
  17621. +static struct mtd_partition trx_parts[TRX_PARTS];
  17622. +
  17623. +#define WRT160NL_UBOOT_LEN 0x40000
  17624. +#define WRT160NL_ART_LEN 0x10000
  17625. +#define WRT160NL_NVRAM_LEN 0x10000
  17626. +
  17627. +static int wrt160nl_parse_partitions(struct mtd_info *master,
  17628. + struct mtd_partition **pparts,
  17629. + unsigned long origin)
  17630. +{
  17631. + struct wrt160nl_header *header;
  17632. + struct trx_header *theader;
  17633. + struct uimage_header *uheader;
  17634. + size_t retlen;
  17635. + unsigned int kernel_len;
  17636. + unsigned int uboot_len = max(master->erasesize, WRT160NL_UBOOT_LEN);
  17637. + unsigned int nvram_len = max(master->erasesize, WRT160NL_NVRAM_LEN);
  17638. + unsigned int art_len = max(master->erasesize, WRT160NL_ART_LEN);
  17639. + int ret;
  17640. +
  17641. + header = vmalloc(sizeof(*header));
  17642. + if (!header) {
  17643. + return -ENOMEM;
  17644. + goto out;
  17645. + }
  17646. +
  17647. + ret = master->read(master, uboot_len, sizeof(*header),
  17648. + &retlen, (void *) header);
  17649. + if (ret)
  17650. + goto free_hdr;
  17651. +
  17652. + if (retlen != sizeof(*header)) {
  17653. + ret = -EIO;
  17654. + goto free_hdr;
  17655. + }
  17656. +
  17657. + if (strncmp(header->cybertan.magic, "NL16", 4) != 0) {
  17658. + printk(KERN_NOTICE "%s: no WRT160NL signature found\n",
  17659. + master->name);
  17660. + goto free_hdr;
  17661. + }
  17662. +
  17663. + theader = &header->trx;
  17664. + if (le32_to_cpu(theader->magic) != TRX_MAGIC) {
  17665. + printk(KERN_NOTICE "%s: no TRX header found\n", master->name);
  17666. + goto free_hdr;
  17667. + }
  17668. +
  17669. + uheader = &header->uimage;
  17670. + if (uheader->ih_magic != IH_MAGIC) {
  17671. + printk(KERN_NOTICE "%s: no uImage found\n", master->name);
  17672. + goto free_hdr;
  17673. + }
  17674. +
  17675. + kernel_len = le32_to_cpu(theader->offsets[1]) +
  17676. + sizeof(struct cybertan_header);
  17677. +
  17678. + trx_parts[0].name = "u-boot";
  17679. + trx_parts[0].offset = 0;
  17680. + trx_parts[0].size = uboot_len;
  17681. + trx_parts[0].mask_flags = MTD_WRITEABLE;
  17682. +
  17683. + trx_parts[1].name = "kernel";
  17684. + trx_parts[1].offset = trx_parts[0].offset + trx_parts[0].size;
  17685. + trx_parts[1].size = kernel_len;
  17686. + trx_parts[1].mask_flags = 0;
  17687. +
  17688. + trx_parts[2].name = "rootfs";
  17689. + trx_parts[2].offset = trx_parts[1].offset + trx_parts[1].size;
  17690. + trx_parts[2].size = master->size - uboot_len - nvram_len - art_len -
  17691. + trx_parts[1].size;
  17692. + trx_parts[2].mask_flags = 0;
  17693. +
  17694. + trx_parts[3].name = "nvram";
  17695. + trx_parts[3].offset = master->size - nvram_len - art_len;
  17696. + trx_parts[3].size = nvram_len;
  17697. + trx_parts[3].mask_flags = MTD_WRITEABLE;
  17698. +
  17699. + trx_parts[4].name = "art";
  17700. + trx_parts[4].offset = master->size - art_len;
  17701. + trx_parts[4].size = art_len;
  17702. + trx_parts[4].mask_flags = MTD_WRITEABLE;
  17703. +
  17704. + trx_parts[5].name = "firmware";
  17705. + trx_parts[5].offset = uboot_len;
  17706. + trx_parts[5].size = master->size - uboot_len - nvram_len - art_len;
  17707. + trx_parts[5].mask_flags = 0;
  17708. +
  17709. + *pparts = trx_parts;
  17710. + ret = TRX_PARTS;
  17711. +
  17712. +free_hdr:
  17713. + vfree(header);
  17714. +out:
  17715. + return ret;
  17716. +}
  17717. +
  17718. +static struct mtd_part_parser wrt160nl_parser = {
  17719. + .owner = THIS_MODULE,
  17720. + .parse_fn = wrt160nl_parse_partitions,
  17721. + .name = "wrt160nl",
  17722. +};
  17723. +
  17724. +static int __init wrt160nl_parser_init(void)
  17725. +{
  17726. + return register_mtd_parser(&wrt160nl_parser);
  17727. +}
  17728. +
  17729. +module_init(wrt160nl_parser_init);
  17730. +
  17731. +MODULE_LICENSE("GPL");
  17732. +MODULE_AUTHOR("Christian Daniel <cd@maintech.de>");
  17733. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ar7240.c linux-2.6.39/drivers/net/ag71xx/ag71xx_ar7240.c
  17734. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ar7240.c 1970-01-01 01:00:00.000000000 +0100
  17735. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_ar7240.c 2011-08-06 09:32:37.298018216 +0200
  17736. @@ -0,0 +1,913 @@
  17737. +/*
  17738. + * Driver for the built-in ethernet switch of the Atheros AR7240 SoC
  17739. + * Copyright (c) 2010 Gabor Juhos <juhosg@openwrt.org>
  17740. + * Copyright (c) 2010 Felix Fietkau <nbd@openwrt.org>
  17741. + *
  17742. + * This program is free software; you can redistribute it and/or modify it
  17743. + * under the terms of the GNU General Public License version 2 as published
  17744. + * by the Free Software Foundation.
  17745. + *
  17746. + */
  17747. +
  17748. +#include <linux/etherdevice.h>
  17749. +#include <linux/list.h>
  17750. +#include <linux/netdevice.h>
  17751. +#include <linux/phy.h>
  17752. +#include <linux/mii.h>
  17753. +#include <linux/bitops.h>
  17754. +#include <linux/switch.h>
  17755. +#include "ag71xx.h"
  17756. +
  17757. +#define BITM(_count) (BIT(_count) - 1)
  17758. +#define BITS(_shift, _count) (BITM(_count) << _shift)
  17759. +
  17760. +#define AR7240_REG_MASK_CTRL 0x00
  17761. +#define AR7240_MASK_CTRL_REVISION_M BITM(8)
  17762. +#define AR7240_MASK_CTRL_VERSION_M BITM(8)
  17763. +#define AR7240_MASK_CTRL_VERSION_S 8
  17764. +#define AR7240_MASK_CTRL_SOFT_RESET BIT(31)
  17765. +
  17766. +#define AR7240_REG_MAC_ADDR0 0x20
  17767. +#define AR7240_REG_MAC_ADDR1 0x24
  17768. +
  17769. +#define AR7240_REG_FLOOD_MASK 0x2c
  17770. +#define AR7240_FLOOD_MASK_BROAD_TO_CPU BIT(26)
  17771. +
  17772. +#define AR7240_REG_GLOBAL_CTRL 0x30
  17773. +#define AR7240_GLOBAL_CTRL_MTU_M BITM(12)
  17774. +
  17775. +#define AR7240_REG_VTU 0x0040
  17776. +#define AR7240_VTU_OP BITM(3)
  17777. +#define AR7240_VTU_OP_NOOP 0x0
  17778. +#define AR7240_VTU_OP_FLUSH 0x1
  17779. +#define AR7240_VTU_OP_LOAD 0x2
  17780. +#define AR7240_VTU_OP_PURGE 0x3
  17781. +#define AR7240_VTU_OP_REMOVE_PORT 0x4
  17782. +#define AR7240_VTU_ACTIVE BIT(3)
  17783. +#define AR7240_VTU_FULL BIT(4)
  17784. +#define AR7240_VTU_PORT BITS(8, 4)
  17785. +#define AR7240_VTU_PORT_S 8
  17786. +#define AR7240_VTU_VID BITS(16, 12)
  17787. +#define AR7240_VTU_VID_S 16
  17788. +#define AR7240_VTU_PRIO BITS(28, 3)
  17789. +#define AR7240_VTU_PRIO_S 28
  17790. +#define AR7240_VTU_PRIO_EN BIT(31)
  17791. +
  17792. +#define AR7240_REG_VTU_DATA 0x0044
  17793. +#define AR7240_VTUDATA_MEMBER BITS(0, 10)
  17794. +#define AR7240_VTUDATA_VALID BIT(11)
  17795. +
  17796. +#define AR7240_REG_ATU 0x50
  17797. +#define AR7240_ATU_FLUSH_ALL 0x1
  17798. +
  17799. +#define AR7240_REG_AT_CTRL 0x5c
  17800. +#define AR7240_AT_CTRL_AGE_TIME BITS(0, 15)
  17801. +#define AR7240_AT_CTRL_AGE_EN BIT(17)
  17802. +#define AR7240_AT_CTRL_LEARN_CHANGE BIT(18)
  17803. +#define AR7240_AT_CTRL_ARP_EN BIT(20)
  17804. +
  17805. +#define AR7240_REG_TAG_PRIORITY 0x70
  17806. +
  17807. +#define AR7240_REG_SERVICE_TAG 0x74
  17808. +#define AR7240_SERVICE_TAG_M BITM(16)
  17809. +
  17810. +#define AR7240_REG_CPU_PORT 0x78
  17811. +#define AR7240_MIRROR_PORT_S 4
  17812. +#define AR7240_CPU_PORT_EN BIT(8)
  17813. +
  17814. +#define AR7240_REG_MIB_FUNCTION0 0x80
  17815. +#define AR7240_MIB_TIMER_M BITM(16)
  17816. +#define AR7240_MIB_AT_HALF_EN BIT(16)
  17817. +#define AR7240_MIB_BUSY BIT(17)
  17818. +#define AR7240_MIB_FUNC_S 24
  17819. +#define AR7240_MIB_FUNC_NO_OP 0x0
  17820. +#define AR7240_MIB_FUNC_FLUSH 0x1
  17821. +#define AR7240_MIB_FUNC_CAPTURE 0x3
  17822. +
  17823. +#define AR7240_REG_MDIO_CTRL 0x98
  17824. +#define AR7240_MDIO_CTRL_DATA_M BITM(16)
  17825. +#define AR7240_MDIO_CTRL_REG_ADDR_S 16
  17826. +#define AR7240_MDIO_CTRL_PHY_ADDR_S 21
  17827. +#define AR7240_MDIO_CTRL_CMD_WRITE 0
  17828. +#define AR7240_MDIO_CTRL_CMD_READ BIT(27)
  17829. +#define AR7240_MDIO_CTRL_MASTER_EN BIT(30)
  17830. +#define AR7240_MDIO_CTRL_BUSY BIT(31)
  17831. +
  17832. +#define AR7240_REG_PORT_BASE(_port) (0x100 + (_port) * 0x100)
  17833. +
  17834. +#define AR7240_REG_PORT_STATUS(_port) (AR7240_REG_PORT_BASE((_port)) + 0x00)
  17835. +#define AR7240_PORT_STATUS_SPEED_M BITM(2)
  17836. +#define AR7240_PORT_STATUS_SPEED_10 0
  17837. +#define AR7240_PORT_STATUS_SPEED_100 1
  17838. +#define AR7240_PORT_STATUS_SPEED_1000 2
  17839. +#define AR7240_PORT_STATUS_TXMAC BIT(2)
  17840. +#define AR7240_PORT_STATUS_RXMAC BIT(3)
  17841. +#define AR7240_PORT_STATUS_TXFLOW BIT(4)
  17842. +#define AR7240_PORT_STATUS_RXFLOW BIT(5)
  17843. +#define AR7240_PORT_STATUS_DUPLEX BIT(6)
  17844. +#define AR7240_PORT_STATUS_LINK_UP BIT(8)
  17845. +#define AR7240_PORT_STATUS_LINK_AUTO BIT(9)
  17846. +#define AR7240_PORT_STATUS_LINK_PAUSE BIT(10)
  17847. +
  17848. +#define AR7240_REG_PORT_CTRL(_port) (AR7240_REG_PORT_BASE((_port)) + 0x04)
  17849. +#define AR7240_PORT_CTRL_STATE_M BITM(3)
  17850. +#define AR7240_PORT_CTRL_STATE_DISABLED 0
  17851. +#define AR7240_PORT_CTRL_STATE_BLOCK 1
  17852. +#define AR7240_PORT_CTRL_STATE_LISTEN 2
  17853. +#define AR7240_PORT_CTRL_STATE_LEARN 3
  17854. +#define AR7240_PORT_CTRL_STATE_FORWARD 4
  17855. +#define AR7240_PORT_CTRL_LEARN_LOCK BIT(7)
  17856. +#define AR7240_PORT_CTRL_VLAN_MODE_S 8
  17857. +#define AR7240_PORT_CTRL_VLAN_MODE_KEEP 0
  17858. +#define AR7240_PORT_CTRL_VLAN_MODE_STRIP 1
  17859. +#define AR7240_PORT_CTRL_VLAN_MODE_ADD 2
  17860. +#define AR7240_PORT_CTRL_VLAN_MODE_DOUBLE_TAG 3
  17861. +#define AR7240_PORT_CTRL_IGMP_SNOOP BIT(10)
  17862. +#define AR7240_PORT_CTRL_HEADER BIT(11)
  17863. +#define AR7240_PORT_CTRL_MAC_LOOP BIT(12)
  17864. +#define AR7240_PORT_CTRL_SINGLE_VLAN BIT(13)
  17865. +#define AR7240_PORT_CTRL_LEARN BIT(14)
  17866. +#define AR7240_PORT_CTRL_DOUBLE_TAG BIT(15)
  17867. +#define AR7240_PORT_CTRL_MIRROR_TX BIT(16)
  17868. +#define AR7240_PORT_CTRL_MIRROR_RX BIT(17)
  17869. +
  17870. +#define AR7240_REG_PORT_VLAN(_port) (AR7240_REG_PORT_BASE((_port)) + 0x08)
  17871. +
  17872. +#define AR7240_PORT_VLAN_DEFAULT_ID_S 0
  17873. +#define AR7240_PORT_VLAN_DEST_PORTS_S 16
  17874. +#define AR7240_PORT_VLAN_MODE_S 30
  17875. +#define AR7240_PORT_VLAN_MODE_PORT_ONLY 0
  17876. +#define AR7240_PORT_VLAN_MODE_PORT_FALLBACK 1
  17877. +#define AR7240_PORT_VLAN_MODE_VLAN_ONLY 2
  17878. +#define AR7240_PORT_VLAN_MODE_SECURE 3
  17879. +
  17880. +
  17881. +#define AR7240_REG_STATS_BASE(_port) (0x20000 + (_port) * 0x100)
  17882. +
  17883. +#define AR7240_STATS_RXBROAD 0x00
  17884. +#define AR7240_STATS_RXPAUSE 0x04
  17885. +#define AR7240_STATS_RXMULTI 0x08
  17886. +#define AR7240_STATS_RXFCSERR 0x0c
  17887. +#define AR7240_STATS_RXALIGNERR 0x10
  17888. +#define AR7240_STATS_RXRUNT 0x14
  17889. +#define AR7240_STATS_RXFRAGMENT 0x18
  17890. +#define AR7240_STATS_RX64BYTE 0x1c
  17891. +#define AR7240_STATS_RX128BYTE 0x20
  17892. +#define AR7240_STATS_RX256BYTE 0x24
  17893. +#define AR7240_STATS_RX512BYTE 0x28
  17894. +#define AR7240_STATS_RX1024BYTE 0x2c
  17895. +#define AR7240_STATS_RX1518BYTE 0x30
  17896. +#define AR7240_STATS_RXMAXBYTE 0x34
  17897. +#define AR7240_STATS_RXTOOLONG 0x38
  17898. +#define AR7240_STATS_RXGOODBYTE 0x3c
  17899. +#define AR7240_STATS_RXBADBYTE 0x44
  17900. +#define AR7240_STATS_RXOVERFLOW 0x4c
  17901. +#define AR7240_STATS_FILTERED 0x50
  17902. +#define AR7240_STATS_TXBROAD 0x54
  17903. +#define AR7240_STATS_TXPAUSE 0x58
  17904. +#define AR7240_STATS_TXMULTI 0x5c
  17905. +#define AR7240_STATS_TXUNDERRUN 0x60
  17906. +#define AR7240_STATS_TX64BYTE 0x64
  17907. +#define AR7240_STATS_TX128BYTE 0x68
  17908. +#define AR7240_STATS_TX256BYTE 0x6c
  17909. +#define AR7240_STATS_TX512BYTE 0x70
  17910. +#define AR7240_STATS_TX1024BYTE 0x74
  17911. +#define AR7240_STATS_TX1518BYTE 0x78
  17912. +#define AR7240_STATS_TXMAXBYTE 0x7c
  17913. +#define AR7240_STATS_TXOVERSIZE 0x80
  17914. +#define AR7240_STATS_TXBYTE 0x84
  17915. +#define AR7240_STATS_TXCOLLISION 0x8c
  17916. +#define AR7240_STATS_TXABORTCOL 0x90
  17917. +#define AR7240_STATS_TXMULTICOL 0x94
  17918. +#define AR7240_STATS_TXSINGLECOL 0x98
  17919. +#define AR7240_STATS_TXEXCDEFER 0x9c
  17920. +#define AR7240_STATS_TXDEFER 0xa0
  17921. +#define AR7240_STATS_TXLATECOL 0xa4
  17922. +
  17923. +#define AR7240_PORT_CPU 0
  17924. +#define AR7240_NUM_PORTS 6
  17925. +#define AR7240_NUM_PHYS 5
  17926. +
  17927. +#define AR7240_PHY_ID1 0x004d
  17928. +#define AR7240_PHY_ID2 0xd041
  17929. +
  17930. +#define AR7240_PORT_MASK(_port) BIT((_port))
  17931. +#define AR7240_PORT_MASK_ALL BITM(AR7240_NUM_PORTS)
  17932. +#define AR7240_PORT_MASK_BUT(_port) (AR7240_PORT_MASK_ALL & ~BIT((_port)))
  17933. +
  17934. +#define AR7240_MAX_VLANS 16
  17935. +
  17936. +#define sw_to_ar7240(_dev) container_of(_dev, struct ar7240sw, swdev)
  17937. +
  17938. +struct ar7240sw {
  17939. + struct mii_bus *mii_bus;
  17940. + struct switch_dev swdev;
  17941. + bool vlan;
  17942. + u16 vlan_id[AR7240_MAX_VLANS];
  17943. + u8 vlan_table[AR7240_MAX_VLANS];
  17944. + u8 vlan_tagged;
  17945. + u16 pvid[AR7240_NUM_PORTS];
  17946. +};
  17947. +
  17948. +struct ar7240sw_hw_stat {
  17949. + char string[ETH_GSTRING_LEN];
  17950. + int sizeof_stat;
  17951. + int reg;
  17952. +};
  17953. +
  17954. +static DEFINE_MUTEX(reg_mutex);
  17955. +
  17956. +static inline void ar7240sw_init(struct ar7240sw *as, struct mii_bus *mii)
  17957. +{
  17958. + as->mii_bus = mii;
  17959. +}
  17960. +
  17961. +static inline u16 mk_phy_addr(u32 reg)
  17962. +{
  17963. + return 0x17 & ((reg >> 4) | 0x10);
  17964. +}
  17965. +
  17966. +static inline u16 mk_phy_reg(u32 reg)
  17967. +{
  17968. + return (reg << 1) & 0x1e;
  17969. +}
  17970. +
  17971. +static inline u16 mk_high_addr(u32 reg)
  17972. +{
  17973. + return (reg >> 7) & 0x1ff;
  17974. +}
  17975. +
  17976. +static u32 __ar7240sw_reg_read(struct mii_bus *mii, u32 reg)
  17977. +{
  17978. + unsigned long flags;
  17979. + u16 phy_addr;
  17980. + u16 phy_reg;
  17981. + u32 hi, lo;
  17982. +
  17983. + reg = (reg & 0xfffffffc) >> 2;
  17984. + phy_addr = mk_phy_addr(reg);
  17985. + phy_reg = mk_phy_reg(reg);
  17986. +
  17987. + local_irq_save(flags);
  17988. + ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
  17989. + lo = (u32) ag71xx_mdio_mii_read(mii->priv, phy_addr, phy_reg);
  17990. + hi = (u32) ag71xx_mdio_mii_read(mii->priv, phy_addr, phy_reg + 1);
  17991. + local_irq_restore(flags);
  17992. +
  17993. + return (hi << 16) | lo;
  17994. +}
  17995. +
  17996. +static void __ar7240sw_reg_write(struct mii_bus *mii, u32 reg, u32 val)
  17997. +{
  17998. + unsigned long flags;
  17999. + u16 phy_addr;
  18000. + u16 phy_reg;
  18001. +
  18002. + reg = (reg & 0xfffffffc) >> 2;
  18003. + phy_addr = mk_phy_addr(reg);
  18004. + phy_reg = mk_phy_reg(reg);
  18005. +
  18006. + local_irq_save(flags);
  18007. + ag71xx_mdio_mii_write(mii->priv, 0x1f, 0x10, mk_high_addr(reg));
  18008. + ag71xx_mdio_mii_write(mii->priv, phy_addr, phy_reg + 1, (val >> 16));
  18009. + ag71xx_mdio_mii_write(mii->priv, phy_addr, phy_reg, (val & 0xffff));
  18010. + local_irq_restore(flags);
  18011. +}
  18012. +
  18013. +static u32 ar7240sw_reg_read(struct mii_bus *mii, u32 reg_addr)
  18014. +{
  18015. + u32 ret;
  18016. +
  18017. + mutex_lock(&reg_mutex);
  18018. + ret = __ar7240sw_reg_read(mii, reg_addr);
  18019. + mutex_unlock(&reg_mutex);
  18020. +
  18021. + return ret;
  18022. +}
  18023. +
  18024. +static void ar7240sw_reg_write(struct mii_bus *mii, u32 reg_addr, u32 reg_val)
  18025. +{
  18026. + mutex_lock(&reg_mutex);
  18027. + __ar7240sw_reg_write(mii, reg_addr, reg_val);
  18028. + mutex_unlock(&reg_mutex);
  18029. +}
  18030. +
  18031. +static u32 ar7240sw_reg_rmw(struct mii_bus *mii, u32 reg, u32 mask, u32 val)
  18032. +{
  18033. + u32 t;
  18034. +
  18035. + mutex_lock(&reg_mutex);
  18036. + t = __ar7240sw_reg_read(mii, reg);
  18037. + t &= ~mask;
  18038. + t |= val;
  18039. + __ar7240sw_reg_write(mii, reg, t);
  18040. + mutex_unlock(&reg_mutex);
  18041. +
  18042. + return t;
  18043. +}
  18044. +
  18045. +static void ar7240sw_reg_set(struct mii_bus *mii, u32 reg, u32 val)
  18046. +{
  18047. + u32 t;
  18048. +
  18049. + mutex_lock(&reg_mutex);
  18050. + t = __ar7240sw_reg_read(mii, reg);
  18051. + t |= val;
  18052. + __ar7240sw_reg_write(mii, reg, t);
  18053. + mutex_unlock(&reg_mutex);
  18054. +}
  18055. +
  18056. +static int __ar7240sw_reg_wait(struct mii_bus *mii, u32 reg, u32 mask, u32 val,
  18057. + unsigned timeout)
  18058. +{
  18059. + int i;
  18060. +
  18061. + for (i = 0; i < timeout; i++) {
  18062. + u32 t;
  18063. +
  18064. + t = __ar7240sw_reg_read(mii, reg);
  18065. + if ((t & mask) == val)
  18066. + return 0;
  18067. +
  18068. + msleep(1);
  18069. + }
  18070. +
  18071. + return -ETIMEDOUT;
  18072. +}
  18073. +
  18074. +static int ar7240sw_reg_wait(struct mii_bus *mii, u32 reg, u32 mask, u32 val,
  18075. + unsigned timeout)
  18076. +{
  18077. + int ret;
  18078. +
  18079. + mutex_lock(&reg_mutex);
  18080. + ret = __ar7240sw_reg_wait(mii, reg, mask, val, timeout);
  18081. + mutex_unlock(&reg_mutex);
  18082. + return ret;
  18083. +}
  18084. +
  18085. +u16 ar7240sw_phy_read(struct mii_bus *mii, unsigned phy_addr,
  18086. + unsigned reg_addr)
  18087. +{
  18088. + u32 t, val = 0xffff;
  18089. + int err;
  18090. +
  18091. + if (phy_addr >= AR7240_NUM_PHYS)
  18092. + return 0xffff;
  18093. +
  18094. + mutex_lock(&reg_mutex);
  18095. + t = (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  18096. + (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  18097. + AR7240_MDIO_CTRL_MASTER_EN |
  18098. + AR7240_MDIO_CTRL_BUSY |
  18099. + AR7240_MDIO_CTRL_CMD_READ;
  18100. +
  18101. + __ar7240sw_reg_write(mii, AR7240_REG_MDIO_CTRL, t);
  18102. + err = __ar7240sw_reg_wait(mii, AR7240_REG_MDIO_CTRL,
  18103. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  18104. + if (!err)
  18105. + val = __ar7240sw_reg_read(mii, AR7240_REG_MDIO_CTRL);
  18106. + mutex_unlock(&reg_mutex);
  18107. +
  18108. + return val & AR7240_MDIO_CTRL_DATA_M;
  18109. +}
  18110. +
  18111. +int ar7240sw_phy_write(struct mii_bus *mii, unsigned phy_addr,
  18112. + unsigned reg_addr, u16 reg_val)
  18113. +{
  18114. + u32 t;
  18115. + int ret;
  18116. +
  18117. + if (phy_addr >= AR7240_NUM_PHYS)
  18118. + return -EINVAL;
  18119. +
  18120. + mutex_lock(&reg_mutex);
  18121. + t = (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  18122. + (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  18123. + AR7240_MDIO_CTRL_MASTER_EN |
  18124. + AR7240_MDIO_CTRL_BUSY |
  18125. + AR7240_MDIO_CTRL_CMD_WRITE |
  18126. + reg_val;
  18127. +
  18128. + __ar7240sw_reg_write(mii, AR7240_REG_MDIO_CTRL, t);
  18129. + ret = __ar7240sw_reg_wait(mii, AR7240_REG_MDIO_CTRL,
  18130. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  18131. + mutex_unlock(&reg_mutex);
  18132. +
  18133. + return ret;
  18134. +}
  18135. +
  18136. +static int ar7240sw_capture_stats(struct ar7240sw *as)
  18137. +{
  18138. + struct mii_bus *mii = as->mii_bus;
  18139. + int ret;
  18140. +
  18141. + /* Capture the hardware statistics for all ports */
  18142. + ar7240sw_reg_write(mii, AR7240_REG_MIB_FUNCTION0,
  18143. + (AR7240_MIB_FUNC_CAPTURE << AR7240_MIB_FUNC_S));
  18144. +
  18145. + /* Wait for the capturing to complete. */
  18146. + ret = ar7240sw_reg_wait(mii, AR7240_REG_MIB_FUNCTION0,
  18147. + AR7240_MIB_BUSY, 0, 10);
  18148. + return ret;
  18149. +}
  18150. +
  18151. +static void ar7240sw_disable_port(struct ar7240sw *as, unsigned port)
  18152. +{
  18153. + ar7240sw_reg_write(as->mii_bus, AR7240_REG_PORT_CTRL(port),
  18154. + AR7240_PORT_CTRL_STATE_DISABLED);
  18155. +}
  18156. +
  18157. +static void ar7240sw_setup(struct ar7240sw *as)
  18158. +{
  18159. + struct mii_bus *mii = as->mii_bus;
  18160. +
  18161. + /* Enable CPU port, and disable mirror port */
  18162. + ar7240sw_reg_write(mii, AR7240_REG_CPU_PORT,
  18163. + AR7240_CPU_PORT_EN |
  18164. + (15 << AR7240_MIRROR_PORT_S));
  18165. +
  18166. + /* Setup TAG priority mapping */
  18167. + ar7240sw_reg_write(mii, AR7240_REG_TAG_PRIORITY, 0xfa50);
  18168. +
  18169. + /* Enable ARP frame acknowledge, aging, MAC replacing */
  18170. + ar7240sw_reg_write(mii, AR7240_REG_AT_CTRL,
  18171. + 0x2b /* 5 min age time */ |
  18172. + AR7240_AT_CTRL_AGE_EN |
  18173. + AR7240_AT_CTRL_ARP_EN |
  18174. + AR7240_AT_CTRL_LEARN_CHANGE);
  18175. +
  18176. + /* Enable Broadcast frames transmitted to the CPU */
  18177. + ar7240sw_reg_set(mii, AR7240_REG_FLOOD_MASK,
  18178. + AR7240_FLOOD_MASK_BROAD_TO_CPU);
  18179. +
  18180. + /* setup MTU */
  18181. + ar7240sw_reg_rmw(mii, AR7240_REG_GLOBAL_CTRL, AR7240_GLOBAL_CTRL_MTU_M,
  18182. + 1536);
  18183. +
  18184. + /* setup Service TAG */
  18185. + ar7240sw_reg_rmw(mii, AR7240_REG_SERVICE_TAG, AR7240_SERVICE_TAG_M, 0);
  18186. +}
  18187. +
  18188. +static int ar7240sw_reset(struct ar7240sw *as)
  18189. +{
  18190. + struct mii_bus *mii = as->mii_bus;
  18191. + int ret;
  18192. + int i;
  18193. +
  18194. + /* Set all ports to disabled state. */
  18195. + for (i = 0; i < AR7240_NUM_PORTS; i++)
  18196. + ar7240sw_disable_port(as, i);
  18197. +
  18198. + /* Wait for transmit queues to drain. */
  18199. + msleep(2);
  18200. +
  18201. + /* Reset the switch. */
  18202. + ar7240sw_reg_write(mii, AR7240_REG_MASK_CTRL,
  18203. + AR7240_MASK_CTRL_SOFT_RESET);
  18204. +
  18205. + ret = ar7240sw_reg_wait(mii, AR7240_REG_MASK_CTRL,
  18206. + AR7240_MASK_CTRL_SOFT_RESET, 0, 1000);
  18207. +
  18208. + ar7240sw_setup(as);
  18209. + return ret;
  18210. +}
  18211. +
  18212. +static void ar7240sw_setup_port(struct ar7240sw *as, unsigned port, u8 portmask)
  18213. +{
  18214. + struct mii_bus *mii = as->mii_bus;
  18215. + u32 ctrl;
  18216. + u32 dest_ports;
  18217. + u32 vlan;
  18218. +
  18219. + ctrl = AR7240_PORT_CTRL_STATE_FORWARD | AR7240_PORT_CTRL_LEARN |
  18220. + AR7240_PORT_CTRL_SINGLE_VLAN;
  18221. +
  18222. + if (port == AR7240_PORT_CPU) {
  18223. + ar7240sw_reg_write(mii, AR7240_REG_PORT_STATUS(port),
  18224. + AR7240_PORT_STATUS_SPEED_1000 |
  18225. + AR7240_PORT_STATUS_TXFLOW |
  18226. + AR7240_PORT_STATUS_RXFLOW |
  18227. + AR7240_PORT_STATUS_TXMAC |
  18228. + AR7240_PORT_STATUS_RXMAC |
  18229. + AR7240_PORT_STATUS_DUPLEX);
  18230. + } else {
  18231. + ar7240sw_reg_write(mii, AR7240_REG_PORT_STATUS(port),
  18232. + AR7240_PORT_STATUS_LINK_AUTO);
  18233. + }
  18234. +
  18235. + /* Set the default VID for this port */
  18236. + if (as->vlan) {
  18237. + vlan = as->vlan_id[as->pvid[port]];
  18238. + vlan |= AR7240_PORT_VLAN_MODE_SECURE <<
  18239. + AR7240_PORT_VLAN_MODE_S;
  18240. + } else {
  18241. + vlan = port;
  18242. + vlan |= AR7240_PORT_VLAN_MODE_PORT_ONLY <<
  18243. + AR7240_PORT_VLAN_MODE_S;
  18244. + }
  18245. +
  18246. + if (as->vlan && (as->vlan_tagged & BIT(port))) {
  18247. + ctrl |= AR7240_PORT_CTRL_VLAN_MODE_ADD <<
  18248. + AR7240_PORT_CTRL_VLAN_MODE_S;
  18249. + } else {
  18250. + ctrl |= AR7240_PORT_CTRL_VLAN_MODE_STRIP <<
  18251. + AR7240_PORT_CTRL_VLAN_MODE_S;
  18252. + }
  18253. +
  18254. + if (!portmask) {
  18255. + if (port == AR7240_PORT_CPU)
  18256. + portmask = AR7240_PORT_MASK_BUT(AR7240_PORT_CPU);
  18257. + else
  18258. + portmask = AR7240_PORT_MASK(AR7240_PORT_CPU);
  18259. + }
  18260. +
  18261. + /* allow the port to talk to all other ports, but exclude its
  18262. + * own ID to prevent frames from being reflected back to the
  18263. + * port that they came from */
  18264. + dest_ports = AR7240_PORT_MASK_BUT(port);
  18265. +
  18266. + /* set default VID and and destination ports for this VLAN */
  18267. + vlan |= (portmask << AR7240_PORT_VLAN_DEST_PORTS_S);
  18268. +
  18269. + ar7240sw_reg_write(mii, AR7240_REG_PORT_CTRL(port), ctrl);
  18270. + ar7240sw_reg_write(mii, AR7240_REG_PORT_VLAN(port), vlan);
  18271. +}
  18272. +
  18273. +static int ar7240_set_addr(struct ar7240sw *as, u8 *addr)
  18274. +{
  18275. + struct mii_bus *mii = as->mii_bus;
  18276. + u32 t;
  18277. +
  18278. + t = (addr[4] << 8) | addr[5];
  18279. + ar7240sw_reg_write(mii, AR7240_REG_MAC_ADDR0, t);
  18280. +
  18281. + t = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
  18282. + ar7240sw_reg_write(mii, AR7240_REG_MAC_ADDR1, t);
  18283. +
  18284. + return 0;
  18285. +}
  18286. +
  18287. +static int
  18288. +ar7240_set_vid(struct switch_dev *dev, const struct switch_attr *attr,
  18289. + struct switch_val *val)
  18290. +{
  18291. + struct ar7240sw *as = sw_to_ar7240(dev);
  18292. + as->vlan_id[val->port_vlan] = val->value.i;
  18293. + return 0;
  18294. +}
  18295. +
  18296. +static int
  18297. +ar7240_get_vid(struct switch_dev *dev, const struct switch_attr *attr,
  18298. + struct switch_val *val)
  18299. +{
  18300. + struct ar7240sw *as = sw_to_ar7240(dev);
  18301. + val->value.i = as->vlan_id[val->port_vlan];
  18302. + return 0;
  18303. +}
  18304. +
  18305. +static int
  18306. +ar7240_set_pvid(struct switch_dev *dev, int port, int vlan)
  18307. +{
  18308. + struct ar7240sw *as = sw_to_ar7240(dev);
  18309. +
  18310. + /* make sure no invalid PVIDs get set */
  18311. +
  18312. + if (vlan >= dev->vlans)
  18313. + return -EINVAL;
  18314. +
  18315. + as->pvid[port] = vlan;
  18316. + return 0;
  18317. +}
  18318. +
  18319. +static int
  18320. +ar7240_get_pvid(struct switch_dev *dev, int port, int *vlan)
  18321. +{
  18322. + struct ar7240sw *as = sw_to_ar7240(dev);
  18323. + *vlan = as->pvid[port];
  18324. + return 0;
  18325. +}
  18326. +
  18327. +static int
  18328. +ar7240_get_ports(struct switch_dev *dev, struct switch_val *val)
  18329. +{
  18330. + struct ar7240sw *as = sw_to_ar7240(dev);
  18331. + u8 ports = as->vlan_table[val->port_vlan];
  18332. + int i;
  18333. +
  18334. + val->len = 0;
  18335. + for (i = 0; i < AR7240_NUM_PORTS; i++) {
  18336. + struct switch_port *p;
  18337. +
  18338. + if (!(ports & (1 << i)))
  18339. + continue;
  18340. +
  18341. + p = &val->value.ports[val->len++];
  18342. + p->id = i;
  18343. + if (as->vlan_tagged & (1 << i))
  18344. + p->flags = (1 << SWITCH_PORT_FLAG_TAGGED);
  18345. + else
  18346. + p->flags = 0;
  18347. + }
  18348. + return 0;
  18349. +}
  18350. +
  18351. +static int
  18352. +ar7240_set_ports(struct switch_dev *dev, struct switch_val *val)
  18353. +{
  18354. + struct ar7240sw *as = sw_to_ar7240(dev);
  18355. + u8 *vt = &as->vlan_table[val->port_vlan];
  18356. + int i, j;
  18357. +
  18358. + *vt = 0;
  18359. + for (i = 0; i < val->len; i++) {
  18360. + struct switch_port *p = &val->value.ports[i];
  18361. +
  18362. + if (p->flags & (1 << SWITCH_PORT_FLAG_TAGGED))
  18363. + as->vlan_tagged |= (1 << p->id);
  18364. + else {
  18365. + as->vlan_tagged &= ~(1 << p->id);
  18366. + as->pvid[p->id] = val->port_vlan;
  18367. +
  18368. + /* make sure that an untagged port does not
  18369. + * appear in other vlans */
  18370. + for (j = 0; j < AR7240_MAX_VLANS; j++) {
  18371. + if (j == val->port_vlan)
  18372. + continue;
  18373. + as->vlan_table[j] &= ~(1 << p->id);
  18374. + }
  18375. + }
  18376. +
  18377. + *vt |= 1 << p->id;
  18378. + }
  18379. + return 0;
  18380. +}
  18381. +
  18382. +static int
  18383. +ar7240_set_vlan(struct switch_dev *dev, const struct switch_attr *attr,
  18384. + struct switch_val *val)
  18385. +{
  18386. + struct ar7240sw *as = sw_to_ar7240(dev);
  18387. + as->vlan = !!val->value.i;
  18388. + return 0;
  18389. +}
  18390. +
  18391. +static int
  18392. +ar7240_get_vlan(struct switch_dev *dev, const struct switch_attr *attr,
  18393. + struct switch_val *val)
  18394. +{
  18395. + struct ar7240sw *as = sw_to_ar7240(dev);
  18396. + val->value.i = as->vlan;
  18397. + return 0;
  18398. +}
  18399. +
  18400. +
  18401. +static void
  18402. +ar7240_vtu_op(struct ar7240sw *as, u32 op, u32 val)
  18403. +{
  18404. + struct mii_bus *mii = as->mii_bus;
  18405. +
  18406. + if (ar7240sw_reg_wait(mii, AR7240_REG_VTU, AR7240_VTU_ACTIVE, 0, 5))
  18407. + return;
  18408. +
  18409. + if ((op & AR7240_VTU_OP) == AR7240_VTU_OP_LOAD) {
  18410. + val &= AR7240_VTUDATA_MEMBER;
  18411. + val |= AR7240_VTUDATA_VALID;
  18412. + ar7240sw_reg_write(mii, AR7240_REG_VTU_DATA, val);
  18413. + }
  18414. + op |= AR7240_VTU_ACTIVE;
  18415. + ar7240sw_reg_write(mii, AR7240_REG_VTU, op);
  18416. +}
  18417. +
  18418. +static int
  18419. +ar7240_hw_apply(struct switch_dev *dev)
  18420. +{
  18421. + struct ar7240sw *as = sw_to_ar7240(dev);
  18422. + u8 portmask[AR7240_NUM_PORTS];
  18423. + int i, j;
  18424. +
  18425. + /* flush all vlan translation unit entries */
  18426. + ar7240_vtu_op(as, AR7240_VTU_OP_FLUSH, 0);
  18427. +
  18428. + memset(portmask, 0, sizeof(portmask));
  18429. + if (as->vlan) {
  18430. + /* calculate the port destination masks and load vlans
  18431. + * into the vlan translation unit */
  18432. + for (j = 0; j < AR7240_MAX_VLANS; j++) {
  18433. + u8 vp = as->vlan_table[j];
  18434. +
  18435. + if (!vp)
  18436. + continue;
  18437. +
  18438. + for (i = 0; i < AR7240_NUM_PORTS; i++) {
  18439. + u8 mask = (1 << i);
  18440. + if (vp & mask)
  18441. + portmask[i] |= vp & ~mask;
  18442. + }
  18443. +
  18444. + ar7240_vtu_op(as,
  18445. + AR7240_VTU_OP_LOAD |
  18446. + (as->vlan_id[j] << AR7240_VTU_VID_S),
  18447. + as->vlan_table[j]);
  18448. + }
  18449. + } else {
  18450. + /* vlan disabled:
  18451. + * isolate all ports, but connect them to the cpu port */
  18452. + for (i = 0; i < AR7240_NUM_PORTS; i++) {
  18453. + if (i == AR7240_PORT_CPU)
  18454. + continue;
  18455. +
  18456. + portmask[i] = 1 << AR7240_PORT_CPU;
  18457. + portmask[AR7240_PORT_CPU] |= (1 << i);
  18458. + }
  18459. + }
  18460. +
  18461. + /* update the port destination mask registers and tag settings */
  18462. + for (i = 0; i < AR7240_NUM_PORTS; i++)
  18463. + ar7240sw_setup_port(as, i, portmask[i]);
  18464. +
  18465. + return 0;
  18466. +}
  18467. +
  18468. +static int
  18469. +ar7240_reset_switch(struct switch_dev *dev)
  18470. +{
  18471. + struct ar7240sw *as = sw_to_ar7240(dev);
  18472. + ar7240sw_reset(as);
  18473. + return 0;
  18474. +}
  18475. +
  18476. +static struct switch_attr ar7240_globals[] = {
  18477. + {
  18478. + .type = SWITCH_TYPE_INT,
  18479. + .name = "enable_vlan",
  18480. + .description = "Enable VLAN mode",
  18481. + .set = ar7240_set_vlan,
  18482. + .get = ar7240_get_vlan,
  18483. + .max = 1
  18484. + },
  18485. +};
  18486. +
  18487. +static struct switch_attr ar7240_port[] = {
  18488. +};
  18489. +
  18490. +static struct switch_attr ar7240_vlan[] = {
  18491. + {
  18492. + .type = SWITCH_TYPE_INT,
  18493. + .name = "vid",
  18494. + .description = "VLAN ID",
  18495. + .set = ar7240_set_vid,
  18496. + .get = ar7240_get_vid,
  18497. + .max = 4094,
  18498. + },
  18499. +};
  18500. +
  18501. +static const struct switch_dev_ops ar7240_ops = {
  18502. + .attr_global = {
  18503. + .attr = ar7240_globals,
  18504. + .n_attr = ARRAY_SIZE(ar7240_globals),
  18505. + },
  18506. + .attr_port = {
  18507. + .attr = ar7240_port,
  18508. + .n_attr = ARRAY_SIZE(ar7240_port),
  18509. + },
  18510. + .attr_vlan = {
  18511. + .attr = ar7240_vlan,
  18512. + .n_attr = ARRAY_SIZE(ar7240_vlan),
  18513. + },
  18514. + .get_port_pvid = ar7240_get_pvid,
  18515. + .set_port_pvid = ar7240_set_pvid,
  18516. + .get_vlan_ports = ar7240_get_ports,
  18517. + .set_vlan_ports = ar7240_set_ports,
  18518. + .apply_config = ar7240_hw_apply,
  18519. + .reset_switch = ar7240_reset_switch,
  18520. +};
  18521. +
  18522. +static struct ar7240sw *ar7240_probe(struct ag71xx *ag)
  18523. +{
  18524. + struct mii_bus *mii = ag->mii_bus;
  18525. + struct ar7240sw *as;
  18526. + struct switch_dev *swdev;
  18527. + u32 ctrl;
  18528. + u16 phy_id1;
  18529. + u16 phy_id2;
  18530. + u8 ver;
  18531. + int i;
  18532. +
  18533. + as = kzalloc(sizeof(*as), GFP_KERNEL);
  18534. + if (!as)
  18535. + return NULL;
  18536. +
  18537. + ar7240sw_init(as, mii);
  18538. +
  18539. + ctrl = ar7240sw_reg_read(mii, AR7240_REG_MASK_CTRL);
  18540. +
  18541. + ver = (ctrl >> AR7240_MASK_CTRL_VERSION_S) & AR7240_MASK_CTRL_VERSION_M;
  18542. + if (ver != 1) {
  18543. + pr_err("%s: unsupported chip, ctrl=%08x\n",
  18544. + ag->dev->name, ctrl);
  18545. + return NULL;
  18546. + }
  18547. +
  18548. + phy_id1 = ar7240sw_phy_read(mii, 0, MII_PHYSID1);
  18549. + phy_id2 = ar7240sw_phy_read(mii, 0, MII_PHYSID2);
  18550. + if (phy_id1 != AR7240_PHY_ID1 || phy_id2 != AR7240_PHY_ID2) {
  18551. + pr_err("%s: unknown phy id '%04x:%04x'\n",
  18552. + ag->dev->name, phy_id1, phy_id2);
  18553. + return NULL;
  18554. + }
  18555. +
  18556. + swdev = &as->swdev;
  18557. + swdev->name = "AR7240 built-in switch";
  18558. + swdev->ports = AR7240_NUM_PORTS;
  18559. + swdev->cpu_port = AR7240_PORT_CPU;
  18560. + swdev->vlans = AR7240_MAX_VLANS;
  18561. + swdev->ops = &ar7240_ops;
  18562. +
  18563. + if (register_switch(&as->swdev, ag->dev) < 0) {
  18564. + kfree(as);
  18565. + return NULL;
  18566. + }
  18567. +
  18568. + pr_info("%s: Found an AR7240 built-in switch\n", ag->dev->name);
  18569. +
  18570. + /* initialize defaults */
  18571. + for (i = 0; i < AR7240_MAX_VLANS; i++)
  18572. + as->vlan_id[i] = i;
  18573. +
  18574. + as->vlan_table[0] = AR7240_PORT_MASK_ALL;
  18575. +
  18576. + return as;
  18577. +}
  18578. +
  18579. +static void link_function(struct work_struct *work) {
  18580. + struct ag71xx *ag = container_of(work, struct ag71xx, link_work.work);
  18581. + unsigned long flags;
  18582. + int i;
  18583. + int status = 0;
  18584. +
  18585. + for (i = 0; i < 4; i++) {
  18586. + int link = ar7240sw_phy_read(ag->mii_bus, i, MII_BMSR);
  18587. + if(link & BMSR_LSTATUS) {
  18588. + status = 1;
  18589. + break;
  18590. + }
  18591. + }
  18592. +
  18593. + spin_lock_irqsave(&ag->lock, flags);
  18594. + if(status != ag->link) {
  18595. + ag->link = status;
  18596. + ag71xx_link_adjust(ag);
  18597. + }
  18598. + spin_unlock_irqrestore(&ag->lock, flags);
  18599. +
  18600. + schedule_delayed_work(&ag->link_work, HZ / 2);
  18601. +}
  18602. +
  18603. +void ag71xx_ar7240_start(struct ag71xx *ag)
  18604. +{
  18605. + struct ar7240sw *as = ag->phy_priv;
  18606. +
  18607. + ar7240sw_reset(as);
  18608. +
  18609. + ag->speed = SPEED_1000;
  18610. + ag->duplex = 1;
  18611. +
  18612. + ar7240_set_addr(as, ag->dev->dev_addr);
  18613. + ar7240_hw_apply(&as->swdev);
  18614. +
  18615. + schedule_delayed_work(&ag->link_work, HZ / 10);
  18616. +}
  18617. +
  18618. +void ag71xx_ar7240_stop(struct ag71xx *ag)
  18619. +{
  18620. + cancel_delayed_work_sync(&ag->link_work);
  18621. +}
  18622. +
  18623. +int __devinit ag71xx_ar7240_init(struct ag71xx *ag)
  18624. +{
  18625. + struct ar7240sw *as;
  18626. +
  18627. + as = ar7240_probe(ag);
  18628. + if (!as)
  18629. + return -ENODEV;
  18630. +
  18631. + ag->phy_priv = as;
  18632. + ar7240sw_reset(as);
  18633. +
  18634. + INIT_DELAYED_WORK(&ag->link_work, link_function);
  18635. +
  18636. + return 0;
  18637. +}
  18638. +
  18639. +void ag71xx_ar7240_cleanup(struct ag71xx *ag)
  18640. +{
  18641. + struct ar7240sw *as = ag->phy_priv;
  18642. +
  18643. + if (!as)
  18644. + return;
  18645. +
  18646. + unregister_switch(&as->swdev);
  18647. + kfree(as);
  18648. + ag->phy_priv = NULL;
  18649. +}
  18650. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ar8216.c linux-2.6.39/drivers/net/ag71xx/ag71xx_ar8216.c
  18651. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ar8216.c 1970-01-01 01:00:00.000000000 +0100
  18652. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_ar8216.c 2011-04-27 12:19:22.257663952 +0200
  18653. @@ -0,0 +1,44 @@
  18654. +/*
  18655. + * Atheros AR71xx built-in ethernet mac driver
  18656. + * Special support for the Atheros ar8216 switch chip
  18657. + *
  18658. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  18659. + *
  18660. + * Based on Atheros' AG7100 driver
  18661. + *
  18662. + * This program is free software; you can redistribute it and/or modify it
  18663. + * under the terms of the GNU General Public License version 2 as published
  18664. + * by the Free Software Foundation.
  18665. + */
  18666. +
  18667. +#include "ag71xx.h"
  18668. +
  18669. +#define AR8216_PACKET_TYPE_MASK 0xf
  18670. +#define AR8216_PACKET_TYPE_NORMAL 0
  18671. +
  18672. +#define AR8216_HEADER_LEN 2
  18673. +
  18674. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb)
  18675. +{
  18676. + skb_push(skb, AR8216_HEADER_LEN);
  18677. + skb->data[0] = 0x10;
  18678. + skb->data[1] = 0x80;
  18679. +}
  18680. +
  18681. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  18682. + int pktlen)
  18683. +{
  18684. + u8 type;
  18685. +
  18686. + type = skb->data[1] & AR8216_PACKET_TYPE_MASK;
  18687. + switch (type) {
  18688. + case AR8216_PACKET_TYPE_NORMAL:
  18689. + break;
  18690. +
  18691. + default:
  18692. + return -EINVAL;
  18693. + }
  18694. +
  18695. + skb_pull(skb, AR8216_HEADER_LEN);
  18696. + return 0;
  18697. +}
  18698. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_debugfs.c linux-2.6.39/drivers/net/ag71xx/ag71xx_debugfs.c
  18699. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  18700. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_debugfs.c 2011-08-06 09:32:37.298018216 +0200
  18701. @@ -0,0 +1,280 @@
  18702. +/*
  18703. + * Atheros AR71xx built-in ethernet mac driver
  18704. + *
  18705. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  18706. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  18707. + *
  18708. + * Based on Atheros' AG7100 driver
  18709. + *
  18710. + * This program is free software; you can redistribute it and/or modify it
  18711. + * under the terms of the GNU General Public License version 2 as published
  18712. + * by the Free Software Foundation.
  18713. + */
  18714. +
  18715. +#include <linux/debugfs.h>
  18716. +
  18717. +#include "ag71xx.h"
  18718. +
  18719. +static struct dentry *ag71xx_debugfs_root;
  18720. +
  18721. +static int ag71xx_debugfs_generic_open(struct inode *inode, struct file *file)
  18722. +{
  18723. + file->private_data = inode->i_private;
  18724. + return 0;
  18725. +}
  18726. +
  18727. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status)
  18728. +{
  18729. + if (status)
  18730. + ag->debug.int_stats.total++;
  18731. + if (status & AG71XX_INT_TX_PS)
  18732. + ag->debug.int_stats.tx_ps++;
  18733. + if (status & AG71XX_INT_TX_UR)
  18734. + ag->debug.int_stats.tx_ur++;
  18735. + if (status & AG71XX_INT_TX_BE)
  18736. + ag->debug.int_stats.tx_be++;
  18737. + if (status & AG71XX_INT_RX_PR)
  18738. + ag->debug.int_stats.rx_pr++;
  18739. + if (status & AG71XX_INT_RX_OF)
  18740. + ag->debug.int_stats.rx_of++;
  18741. + if (status & AG71XX_INT_RX_BE)
  18742. + ag->debug.int_stats.rx_be++;
  18743. +}
  18744. +
  18745. +static ssize_t read_file_int_stats(struct file *file, char __user *user_buf,
  18746. + size_t count, loff_t *ppos)
  18747. +{
  18748. +#define PR_INT_STAT(_label, _field) \
  18749. + len += snprintf(buf + len, sizeof(buf) - len, \
  18750. + "%20s: %10lu\n", _label, ag->debug.int_stats._field);
  18751. +
  18752. + struct ag71xx *ag = file->private_data;
  18753. + char buf[256];
  18754. + unsigned int len = 0;
  18755. +
  18756. + PR_INT_STAT("TX Packet Sent", tx_ps);
  18757. + PR_INT_STAT("TX Underrun", tx_ur);
  18758. + PR_INT_STAT("TX Bus Error", tx_be);
  18759. + PR_INT_STAT("RX Packet Received", rx_pr);
  18760. + PR_INT_STAT("RX Overflow", rx_of);
  18761. + PR_INT_STAT("RX Bus Error", rx_be);
  18762. + len += snprintf(buf + len, sizeof(buf) - len, "\n");
  18763. + PR_INT_STAT("Total", total);
  18764. +
  18765. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  18766. +#undef PR_INT_STAT
  18767. +}
  18768. +
  18769. +static const struct file_operations ag71xx_fops_int_stats = {
  18770. + .open = ag71xx_debugfs_generic_open,
  18771. + .read = read_file_int_stats,
  18772. + .owner = THIS_MODULE
  18773. +};
  18774. +
  18775. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx)
  18776. +{
  18777. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  18778. +
  18779. + if (rx) {
  18780. + stats->rx_count++;
  18781. + stats->rx_packets += rx;
  18782. + if (rx <= AG71XX_NAPI_WEIGHT)
  18783. + stats->rx[rx]++;
  18784. + if (rx > stats->rx_packets_max)
  18785. + stats->rx_packets_max = rx;
  18786. + }
  18787. +
  18788. + if (tx) {
  18789. + stats->tx_count++;
  18790. + stats->tx_packets += tx;
  18791. + if (tx <= AG71XX_NAPI_WEIGHT)
  18792. + stats->tx[tx]++;
  18793. + if (tx > stats->tx_packets_max)
  18794. + stats->tx_packets_max = tx;
  18795. + }
  18796. +}
  18797. +
  18798. +static ssize_t read_file_napi_stats(struct file *file, char __user *user_buf,
  18799. + size_t count, loff_t *ppos)
  18800. +{
  18801. + struct ag71xx *ag = file->private_data;
  18802. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  18803. + char *buf;
  18804. + unsigned int buflen;
  18805. + unsigned int len = 0;
  18806. + unsigned long rx_avg = 0;
  18807. + unsigned long tx_avg = 0;
  18808. + int ret;
  18809. + int i;
  18810. +
  18811. + buflen = 2048;
  18812. + buf = kmalloc(buflen, GFP_KERNEL);
  18813. + if (!buf)
  18814. + return -ENOMEM;
  18815. +
  18816. + if (stats->rx_count)
  18817. + rx_avg = stats->rx_packets / stats->rx_count;
  18818. +
  18819. + if (stats->tx_count)
  18820. + tx_avg = stats->tx_packets / stats->tx_count;
  18821. +
  18822. + len += snprintf(buf + len, buflen - len, "%3s %10s %10s\n",
  18823. + "len", "rx", "tx");
  18824. +
  18825. + for (i = 1; i <= AG71XX_NAPI_WEIGHT; i++)
  18826. + len += snprintf(buf + len, buflen - len,
  18827. + "%3d: %10lu %10lu\n",
  18828. + i, stats->rx[i], stats->tx[i]);
  18829. +
  18830. + len += snprintf(buf + len, buflen - len, "\n");
  18831. +
  18832. + len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
  18833. + "sum", stats->rx_count, stats->tx_count);
  18834. + len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
  18835. + "avg", rx_avg, tx_avg);
  18836. + len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
  18837. + "max", stats->rx_packets_max, stats->tx_packets_max);
  18838. + len += snprintf(buf + len, buflen - len, "%3s: %10lu %10lu\n",
  18839. + "pkt", stats->rx_packets, stats->tx_packets);
  18840. +
  18841. + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  18842. + kfree(buf);
  18843. +
  18844. + return ret;
  18845. +}
  18846. +
  18847. +static const struct file_operations ag71xx_fops_napi_stats = {
  18848. + .open = ag71xx_debugfs_generic_open,
  18849. + .read = read_file_napi_stats,
  18850. + .owner = THIS_MODULE
  18851. +};
  18852. +
  18853. +#define DESC_PRINT_LEN 64
  18854. +
  18855. +static ssize_t read_file_ring(struct file *file, char __user *user_buf,
  18856. + size_t count, loff_t *ppos,
  18857. + struct ag71xx *ag,
  18858. + struct ag71xx_ring *ring,
  18859. + unsigned desc_reg)
  18860. +{
  18861. + char *buf;
  18862. + unsigned int buflen;
  18863. + unsigned int len = 0;
  18864. + unsigned long flags;
  18865. + ssize_t ret;
  18866. + int curr;
  18867. + int dirty;
  18868. + u32 desc_hw;
  18869. + int i;
  18870. +
  18871. + buflen = (ring->size * DESC_PRINT_LEN);
  18872. + buf = kmalloc(buflen, GFP_KERNEL);
  18873. + if (!buf)
  18874. + return -ENOMEM;
  18875. +
  18876. + len += snprintf(buf + len, buflen - len,
  18877. + "Idx ... %-8s %-8s %-8s %-8s . %-10s\n",
  18878. + "desc", "next", "data", "ctrl", "timestamp");
  18879. +
  18880. + spin_lock_irqsave(&ag->lock, flags);
  18881. +
  18882. + curr = (ring->curr % ring->size);
  18883. + dirty = (ring->dirty % ring->size);
  18884. + desc_hw = ag71xx_rr(ag, desc_reg);
  18885. + for (i = 0; i < ring->size; i++) {
  18886. + struct ag71xx_buf *ab = &ring->buf[i];
  18887. + u32 desc_dma = ((u32) ring->descs_dma) + i * ring->desc_size;
  18888. +
  18889. + len += snprintf(buf + len, buflen - len,
  18890. + "%3d %c%c%c %08x %08x %08x %08x %c %10lu\n",
  18891. + i,
  18892. + (i == curr) ? 'C' : ' ',
  18893. + (i == dirty) ? 'D' : ' ',
  18894. + (desc_hw == desc_dma) ? 'H' : ' ',
  18895. + desc_dma,
  18896. + ab->desc->next,
  18897. + ab->desc->data,
  18898. + ab->desc->ctrl,
  18899. + (ab->desc->ctrl & DESC_EMPTY) ? 'E' : '*',
  18900. + ab->timestamp);
  18901. + }
  18902. +
  18903. + spin_unlock_irqrestore(&ag->lock, flags);
  18904. +
  18905. + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  18906. + kfree(buf);
  18907. +
  18908. + return ret;
  18909. +}
  18910. +
  18911. +static ssize_t read_file_tx_ring(struct file *file, char __user *user_buf,
  18912. + size_t count, loff_t *ppos)
  18913. +{
  18914. + struct ag71xx *ag = file->private_data;
  18915. +
  18916. + return read_file_ring(file, user_buf, count, ppos, ag, &ag->tx_ring,
  18917. + AG71XX_REG_TX_DESC);
  18918. +}
  18919. +
  18920. +static const struct file_operations ag71xx_fops_tx_ring = {
  18921. + .open = ag71xx_debugfs_generic_open,
  18922. + .read = read_file_tx_ring,
  18923. + .owner = THIS_MODULE
  18924. +};
  18925. +
  18926. +static ssize_t read_file_rx_ring(struct file *file, char __user *user_buf,
  18927. + size_t count, loff_t *ppos)
  18928. +{
  18929. + struct ag71xx *ag = file->private_data;
  18930. +
  18931. + return read_file_ring(file, user_buf, count, ppos, ag, &ag->rx_ring,
  18932. + AG71XX_REG_RX_DESC);
  18933. +}
  18934. +
  18935. +static const struct file_operations ag71xx_fops_rx_ring = {
  18936. + .open = ag71xx_debugfs_generic_open,
  18937. + .read = read_file_rx_ring,
  18938. + .owner = THIS_MODULE
  18939. +};
  18940. +
  18941. +void ag71xx_debugfs_exit(struct ag71xx *ag)
  18942. +{
  18943. + debugfs_remove_recursive(ag->debug.debugfs_dir);
  18944. +}
  18945. +
  18946. +int ag71xx_debugfs_init(struct ag71xx *ag)
  18947. +{
  18948. + ag->debug.debugfs_dir = debugfs_create_dir(ag->dev->name,
  18949. + ag71xx_debugfs_root);
  18950. + if (!ag->debug.debugfs_dir)
  18951. + return -ENOMEM;
  18952. +
  18953. + debugfs_create_file("int_stats", S_IRUGO, ag->debug.debugfs_dir,
  18954. + ag, &ag71xx_fops_int_stats);
  18955. + debugfs_create_file("napi_stats", S_IRUGO, ag->debug.debugfs_dir,
  18956. + ag, &ag71xx_fops_napi_stats);
  18957. + debugfs_create_file("tx_ring", S_IRUGO, ag->debug.debugfs_dir,
  18958. + ag, &ag71xx_fops_tx_ring);
  18959. + debugfs_create_file("rx_ring", S_IRUGO, ag->debug.debugfs_dir,
  18960. + ag, &ag71xx_fops_rx_ring);
  18961. +
  18962. + return 0;
  18963. +}
  18964. +
  18965. +int ag71xx_debugfs_root_init(void)
  18966. +{
  18967. + if (ag71xx_debugfs_root)
  18968. + return -EBUSY;
  18969. +
  18970. + ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  18971. + if (!ag71xx_debugfs_root)
  18972. + return -ENOENT;
  18973. +
  18974. + return 0;
  18975. +}
  18976. +
  18977. +void ag71xx_debugfs_root_exit(void)
  18978. +{
  18979. + debugfs_remove(ag71xx_debugfs_root);
  18980. + ag71xx_debugfs_root = NULL;
  18981. +}
  18982. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ethtool.c linux-2.6.39/drivers/net/ag71xx/ag71xx_ethtool.c
  18983. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_ethtool.c 1970-01-01 01:00:00.000000000 +0100
  18984. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_ethtool.c 2011-08-06 09:32:37.308017908 +0200
  18985. @@ -0,0 +1,124 @@
  18986. +/*
  18987. + * Atheros AR71xx built-in ethernet mac driver
  18988. + *
  18989. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  18990. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  18991. + *
  18992. + * Based on Atheros' AG7100 driver
  18993. + *
  18994. + * This program is free software; you can redistribute it and/or modify it
  18995. + * under the terms of the GNU General Public License version 2 as published
  18996. + * by the Free Software Foundation.
  18997. + */
  18998. +
  18999. +#include "ag71xx.h"
  19000. +
  19001. +static int ag71xx_ethtool_get_settings(struct net_device *dev,
  19002. + struct ethtool_cmd *cmd)
  19003. +{
  19004. + struct ag71xx *ag = netdev_priv(dev);
  19005. + struct phy_device *phydev = ag->phy_dev;
  19006. +
  19007. + if (!phydev)
  19008. + return -ENODEV;
  19009. +
  19010. + return phy_ethtool_gset(phydev, cmd);
  19011. +}
  19012. +
  19013. +static int ag71xx_ethtool_set_settings(struct net_device *dev,
  19014. + struct ethtool_cmd *cmd)
  19015. +{
  19016. + struct ag71xx *ag = netdev_priv(dev);
  19017. + struct phy_device *phydev = ag->phy_dev;
  19018. +
  19019. + if (!phydev)
  19020. + return -ENODEV;
  19021. +
  19022. + return phy_ethtool_sset(phydev, cmd);
  19023. +}
  19024. +
  19025. +static void ag71xx_ethtool_get_drvinfo(struct net_device *dev,
  19026. + struct ethtool_drvinfo *info)
  19027. +{
  19028. + struct ag71xx *ag = netdev_priv(dev);
  19029. +
  19030. + strcpy(info->driver, ag->pdev->dev.driver->name);
  19031. + strcpy(info->version, AG71XX_DRV_VERSION);
  19032. + strcpy(info->bus_info, dev_name(&ag->pdev->dev));
  19033. +}
  19034. +
  19035. +static u32 ag71xx_ethtool_get_msglevel(struct net_device *dev)
  19036. +{
  19037. + struct ag71xx *ag = netdev_priv(dev);
  19038. +
  19039. + return ag->msg_enable;
  19040. +}
  19041. +
  19042. +static void ag71xx_ethtool_set_msglevel(struct net_device *dev, u32 msg_level)
  19043. +{
  19044. + struct ag71xx *ag = netdev_priv(dev);
  19045. +
  19046. + ag->msg_enable = msg_level;
  19047. +}
  19048. +
  19049. +static void ag71xx_ethtool_get_ringparam(struct net_device *dev,
  19050. + struct ethtool_ringparam *er)
  19051. +{
  19052. + struct ag71xx *ag = netdev_priv(dev);
  19053. +
  19054. + er->tx_max_pending = AG71XX_TX_RING_SIZE_MAX;
  19055. + er->rx_max_pending = AG71XX_RX_RING_SIZE_MAX;
  19056. + er->rx_mini_max_pending = 0;
  19057. + er->rx_jumbo_max_pending = 0;
  19058. +
  19059. + er->tx_pending = ag->tx_ring.size;
  19060. + er->rx_pending = ag->rx_ring.size;
  19061. + er->rx_mini_pending = 0;
  19062. + er->rx_jumbo_pending = 0;
  19063. +}
  19064. +
  19065. +static int ag71xx_ethtool_set_ringparam(struct net_device *dev,
  19066. + struct ethtool_ringparam *er)
  19067. +{
  19068. + struct ag71xx *ag = netdev_priv(dev);
  19069. + unsigned tx_size;
  19070. + unsigned rx_size;
  19071. + int err;
  19072. +
  19073. + if (er->rx_mini_pending != 0||
  19074. + er->rx_jumbo_pending != 0 ||
  19075. + er->rx_pending == 0 ||
  19076. + er->tx_pending == 0)
  19077. + return -EINVAL;
  19078. +
  19079. + tx_size = er->tx_pending < AG71XX_TX_RING_SIZE_MAX ?
  19080. + er->tx_pending : AG71XX_TX_RING_SIZE_MAX;
  19081. +
  19082. + rx_size = er->rx_pending < AG71XX_RX_RING_SIZE_MAX ?
  19083. + er->rx_pending : AG71XX_RX_RING_SIZE_MAX;
  19084. +
  19085. + if (netif_running(dev)) {
  19086. + err = dev->netdev_ops->ndo_stop(dev);
  19087. + if (err)
  19088. + return err;
  19089. + }
  19090. +
  19091. + ag->tx_ring.size = tx_size;
  19092. + ag->rx_ring.size = rx_size;
  19093. +
  19094. + if (netif_running(dev))
  19095. + err = dev->netdev_ops->ndo_open(dev);
  19096. +
  19097. + return err;
  19098. +}
  19099. +
  19100. +struct ethtool_ops ag71xx_ethtool_ops = {
  19101. + .set_settings = ag71xx_ethtool_set_settings,
  19102. + .get_settings = ag71xx_ethtool_get_settings,
  19103. + .get_drvinfo = ag71xx_ethtool_get_drvinfo,
  19104. + .get_msglevel = ag71xx_ethtool_get_msglevel,
  19105. + .set_msglevel = ag71xx_ethtool_set_msglevel,
  19106. + .get_ringparam = ag71xx_ethtool_get_ringparam,
  19107. + .set_ringparam = ag71xx_ethtool_set_ringparam,
  19108. + .get_link = ethtool_op_get_link,
  19109. +};
  19110. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx.h linux-2.6.39/drivers/net/ag71xx/ag71xx.h
  19111. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx.h 1970-01-01 01:00:00.000000000 +0100
  19112. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx.h 2011-08-22 07:40:12.160480642 +0200
  19113. @@ -0,0 +1,518 @@
  19114. +/*
  19115. + * Atheros AR71xx built-in ethernet mac driver
  19116. + *
  19117. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  19118. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  19119. + *
  19120. + * Based on Atheros' AG7100 driver
  19121. + *
  19122. + * This program is free software; you can redistribute it and/or modify it
  19123. + * under the terms of the GNU General Public License version 2 as published
  19124. + * by the Free Software Foundation.
  19125. + */
  19126. +
  19127. +#ifndef __AG71XX_H
  19128. +#define __AG71XX_H
  19129. +
  19130. +#include <linux/kernel.h>
  19131. +#include <linux/version.h>
  19132. +#include <linux/module.h>
  19133. +#include <linux/init.h>
  19134. +#include <linux/types.h>
  19135. +#include <linux/random.h>
  19136. +#include <linux/spinlock.h>
  19137. +#include <linux/interrupt.h>
  19138. +#include <linux/platform_device.h>
  19139. +#include <linux/ethtool.h>
  19140. +#include <linux/etherdevice.h>
  19141. +#include <linux/if_vlan.h>
  19142. +#include <linux/phy.h>
  19143. +#include <linux/skbuff.h>
  19144. +#include <linux/dma-mapping.h>
  19145. +#include <linux/workqueue.h>
  19146. +
  19147. +#include <linux/bitops.h>
  19148. +
  19149. +#include <asm/mach-ar71xx/ar71xx.h>
  19150. +#include <asm/mach-ar71xx/platform.h>
  19151. +
  19152. +#define AG71XX_DRV_NAME "ag71xx"
  19153. +#define AG71XX_DRV_VERSION "0.5.35"
  19154. +
  19155. +#define AG71XX_NAPI_WEIGHT 64
  19156. +#define AG71XX_OOM_REFILL (1 + HZ/10)
  19157. +
  19158. +#define AG71XX_INT_ERR (AG71XX_INT_RX_BE | AG71XX_INT_TX_BE)
  19159. +#define AG71XX_INT_TX (AG71XX_INT_TX_PS)
  19160. +#define AG71XX_INT_RX (AG71XX_INT_RX_PR | AG71XX_INT_RX_OF)
  19161. +
  19162. +#define AG71XX_INT_POLL (AG71XX_INT_RX | AG71XX_INT_TX)
  19163. +#define AG71XX_INT_INIT (AG71XX_INT_ERR | AG71XX_INT_POLL)
  19164. +
  19165. +#define AG71XX_TX_MTU_LEN 1540
  19166. +#define AG71XX_RX_PKT_RESERVE 64
  19167. +#define AG71XX_RX_PKT_SIZE \
  19168. + (AG71XX_RX_PKT_RESERVE + ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  19169. +
  19170. +#define AG71XX_TX_RING_SIZE_DEFAULT 64
  19171. +#define AG71XX_RX_RING_SIZE_DEFAULT 128
  19172. +
  19173. +#define AG71XX_TX_RING_SIZE_MAX 256
  19174. +#define AG71XX_RX_RING_SIZE_MAX 256
  19175. +
  19176. +#ifdef CONFIG_AG71XX_DEBUG
  19177. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  19178. +#else
  19179. +#define DBG(fmt, args...) do {} while (0)
  19180. +#endif
  19181. +
  19182. +#define ag71xx_assert(_cond) \
  19183. +do { \
  19184. + if (_cond) \
  19185. + break; \
  19186. + printk("%s,%d: assertion failed\n", __FILE__, __LINE__); \
  19187. + BUG(); \
  19188. +} while (0)
  19189. +
  19190. +struct ag71xx_desc {
  19191. + u32 data;
  19192. + u32 ctrl;
  19193. +#define DESC_EMPTY BIT(31)
  19194. +#define DESC_MORE BIT(24)
  19195. +#define DESC_PKTLEN_M 0xfff
  19196. + u32 next;
  19197. + u32 pad;
  19198. +} __attribute__((aligned(4)));
  19199. +
  19200. +struct ag71xx_buf {
  19201. + struct sk_buff *skb;
  19202. + struct ag71xx_desc *desc;
  19203. + dma_addr_t dma_addr;
  19204. + unsigned long timestamp;
  19205. +};
  19206. +
  19207. +struct ag71xx_ring {
  19208. + struct ag71xx_buf *buf;
  19209. + u8 *descs_cpu;
  19210. + dma_addr_t descs_dma;
  19211. + unsigned int desc_size;
  19212. + unsigned int curr;
  19213. + unsigned int dirty;
  19214. + unsigned int size;
  19215. +};
  19216. +
  19217. +struct ag71xx_mdio {
  19218. + struct mii_bus *mii_bus;
  19219. + int mii_irq[PHY_MAX_ADDR];
  19220. + void __iomem *mdio_base;
  19221. + struct ag71xx_mdio_platform_data *pdata;
  19222. +};
  19223. +
  19224. +struct ag71xx_int_stats {
  19225. + unsigned long rx_pr;
  19226. + unsigned long rx_be;
  19227. + unsigned long rx_of;
  19228. + unsigned long tx_ps;
  19229. + unsigned long tx_be;
  19230. + unsigned long tx_ur;
  19231. + unsigned long total;
  19232. +};
  19233. +
  19234. +struct ag71xx_napi_stats {
  19235. + unsigned long napi_calls;
  19236. + unsigned long rx_count;
  19237. + unsigned long rx_packets;
  19238. + unsigned long rx_packets_max;
  19239. + unsigned long tx_count;
  19240. + unsigned long tx_packets;
  19241. + unsigned long tx_packets_max;
  19242. +
  19243. + unsigned long rx[AG71XX_NAPI_WEIGHT + 1];
  19244. + unsigned long tx[AG71XX_NAPI_WEIGHT + 1];
  19245. +};
  19246. +
  19247. +struct ag71xx_debug {
  19248. + struct dentry *debugfs_dir;
  19249. +
  19250. + struct ag71xx_int_stats int_stats;
  19251. + struct ag71xx_napi_stats napi_stats;
  19252. +};
  19253. +
  19254. +struct ag71xx {
  19255. + void __iomem *mac_base;
  19256. + void __iomem *mii_ctrl;
  19257. +
  19258. + spinlock_t lock;
  19259. + struct platform_device *pdev;
  19260. + struct net_device *dev;
  19261. + struct napi_struct napi;
  19262. + u32 msg_enable;
  19263. +
  19264. + struct ag71xx_desc *stop_desc;
  19265. + dma_addr_t stop_desc_dma;
  19266. +
  19267. + struct ag71xx_ring rx_ring;
  19268. + struct ag71xx_ring tx_ring;
  19269. +
  19270. + struct mii_bus *mii_bus;
  19271. + struct phy_device *phy_dev;
  19272. + void *phy_priv;
  19273. +
  19274. + unsigned int link;
  19275. + unsigned int speed;
  19276. + int duplex;
  19277. +
  19278. + struct work_struct restart_work;
  19279. + struct delayed_work link_work;
  19280. + struct timer_list oom_timer;
  19281. +
  19282. +#ifdef CONFIG_AG71XX_DEBUG_FS
  19283. + struct ag71xx_debug debug;
  19284. +#endif
  19285. +};
  19286. +
  19287. +extern struct ethtool_ops ag71xx_ethtool_ops;
  19288. +void ag71xx_link_adjust(struct ag71xx *ag);
  19289. +
  19290. +int ag71xx_mdio_driver_init(void) __init;
  19291. +void ag71xx_mdio_driver_exit(void);
  19292. +
  19293. +int ag71xx_phy_connect(struct ag71xx *ag);
  19294. +void ag71xx_phy_disconnect(struct ag71xx *ag);
  19295. +void ag71xx_phy_start(struct ag71xx *ag);
  19296. +void ag71xx_phy_stop(struct ag71xx *ag);
  19297. +
  19298. +static inline struct ag71xx_platform_data *ag71xx_get_pdata(struct ag71xx *ag)
  19299. +{
  19300. + return ag->pdev->dev.platform_data;
  19301. +}
  19302. +
  19303. +static inline int ag71xx_desc_empty(struct ag71xx_desc *desc)
  19304. +{
  19305. + return (desc->ctrl & DESC_EMPTY) != 0;
  19306. +}
  19307. +
  19308. +static inline int ag71xx_desc_pktlen(struct ag71xx_desc *desc)
  19309. +{
  19310. + return desc->ctrl & DESC_PKTLEN_M;
  19311. +}
  19312. +
  19313. +/* Register offsets */
  19314. +#define AG71XX_REG_MAC_CFG1 0x0000
  19315. +#define AG71XX_REG_MAC_CFG2 0x0004
  19316. +#define AG71XX_REG_MAC_IPG 0x0008
  19317. +#define AG71XX_REG_MAC_HDX 0x000c
  19318. +#define AG71XX_REG_MAC_MFL 0x0010
  19319. +#define AG71XX_REG_MII_CFG 0x0020
  19320. +#define AG71XX_REG_MII_CMD 0x0024
  19321. +#define AG71XX_REG_MII_ADDR 0x0028
  19322. +#define AG71XX_REG_MII_CTRL 0x002c
  19323. +#define AG71XX_REG_MII_STATUS 0x0030
  19324. +#define AG71XX_REG_MII_IND 0x0034
  19325. +#define AG71XX_REG_MAC_IFCTL 0x0038
  19326. +#define AG71XX_REG_MAC_ADDR1 0x0040
  19327. +#define AG71XX_REG_MAC_ADDR2 0x0044
  19328. +#define AG71XX_REG_FIFO_CFG0 0x0048
  19329. +#define AG71XX_REG_FIFO_CFG1 0x004c
  19330. +#define AG71XX_REG_FIFO_CFG2 0x0050
  19331. +#define AG71XX_REG_FIFO_CFG3 0x0054
  19332. +#define AG71XX_REG_FIFO_CFG4 0x0058
  19333. +#define AG71XX_REG_FIFO_CFG5 0x005c
  19334. +#define AG71XX_REG_FIFO_RAM0 0x0060
  19335. +#define AG71XX_REG_FIFO_RAM1 0x0064
  19336. +#define AG71XX_REG_FIFO_RAM2 0x0068
  19337. +#define AG71XX_REG_FIFO_RAM3 0x006c
  19338. +#define AG71XX_REG_FIFO_RAM4 0x0070
  19339. +#define AG71XX_REG_FIFO_RAM5 0x0074
  19340. +#define AG71XX_REG_FIFO_RAM6 0x0078
  19341. +#define AG71XX_REG_FIFO_RAM7 0x007c
  19342. +
  19343. +#define AG71XX_REG_TX_CTRL 0x0180
  19344. +#define AG71XX_REG_TX_DESC 0x0184
  19345. +#define AG71XX_REG_TX_STATUS 0x0188
  19346. +#define AG71XX_REG_RX_CTRL 0x018c
  19347. +#define AG71XX_REG_RX_DESC 0x0190
  19348. +#define AG71XX_REG_RX_STATUS 0x0194
  19349. +#define AG71XX_REG_INT_ENABLE 0x0198
  19350. +#define AG71XX_REG_INT_STATUS 0x019c
  19351. +
  19352. +#define AG71XX_REG_FIFO_DEPTH 0x01a8
  19353. +#define AG71XX_REG_RX_SM 0x01b0
  19354. +#define AG71XX_REG_TX_SM 0x01b4
  19355. +
  19356. +#define MAC_CFG1_TXE BIT(0) /* Tx Enable */
  19357. +#define MAC_CFG1_STX BIT(1) /* Synchronize Tx Enable */
  19358. +#define MAC_CFG1_RXE BIT(2) /* Rx Enable */
  19359. +#define MAC_CFG1_SRX BIT(3) /* Synchronize Rx Enable */
  19360. +#define MAC_CFG1_TFC BIT(4) /* Tx Flow Control Enable */
  19361. +#define MAC_CFG1_RFC BIT(5) /* Rx Flow Control Enable */
  19362. +#define MAC_CFG1_LB BIT(8) /* Loopback mode */
  19363. +#define MAC_CFG1_SR BIT(31) /* Soft Reset */
  19364. +
  19365. +#define MAC_CFG2_FDX BIT(0)
  19366. +#define MAC_CFG2_CRC_EN BIT(1)
  19367. +#define MAC_CFG2_PAD_CRC_EN BIT(2)
  19368. +#define MAC_CFG2_LEN_CHECK BIT(4)
  19369. +#define MAC_CFG2_HUGE_FRAME_EN BIT(5)
  19370. +#define MAC_CFG2_IF_1000 BIT(9)
  19371. +#define MAC_CFG2_IF_10_100 BIT(8)
  19372. +
  19373. +#define FIFO_CFG0_WTM BIT(0) /* Watermark Module */
  19374. +#define FIFO_CFG0_RXS BIT(1) /* Rx System Module */
  19375. +#define FIFO_CFG0_RXF BIT(2) /* Rx Fabric Module */
  19376. +#define FIFO_CFG0_TXS BIT(3) /* Tx System Module */
  19377. +#define FIFO_CFG0_TXF BIT(4) /* Tx Fabric Module */
  19378. +#define FIFO_CFG0_ALL (FIFO_CFG0_WTM | FIFO_CFG0_RXS | FIFO_CFG0_RXF \
  19379. + | FIFO_CFG0_TXS | FIFO_CFG0_TXF)
  19380. +
  19381. +#define FIFO_CFG0_ENABLE_SHIFT 8
  19382. +
  19383. +#define FIFO_CFG4_DE BIT(0) /* Drop Event */
  19384. +#define FIFO_CFG4_DV BIT(1) /* RX_DV Event */
  19385. +#define FIFO_CFG4_FC BIT(2) /* False Carrier */
  19386. +#define FIFO_CFG4_CE BIT(3) /* Code Error */
  19387. +#define FIFO_CFG4_CR BIT(4) /* CRC error */
  19388. +#define FIFO_CFG4_LM BIT(5) /* Length Mismatch */
  19389. +#define FIFO_CFG4_LO BIT(6) /* Length out of range */
  19390. +#define FIFO_CFG4_OK BIT(7) /* Packet is OK */
  19391. +#define FIFO_CFG4_MC BIT(8) /* Multicast Packet */
  19392. +#define FIFO_CFG4_BC BIT(9) /* Broadcast Packet */
  19393. +#define FIFO_CFG4_DR BIT(10) /* Dribble */
  19394. +#define FIFO_CFG4_LE BIT(11) /* Long Event */
  19395. +#define FIFO_CFG4_CF BIT(12) /* Control Frame */
  19396. +#define FIFO_CFG4_PF BIT(13) /* Pause Frame */
  19397. +#define FIFO_CFG4_UO BIT(14) /* Unsupported Opcode */
  19398. +#define FIFO_CFG4_VT BIT(15) /* VLAN tag detected */
  19399. +#define FIFO_CFG4_FT BIT(16) /* Frame Truncated */
  19400. +#define FIFO_CFG4_UC BIT(17) /* Unicast Packet */
  19401. +
  19402. +#define FIFO_CFG5_DE BIT(0) /* Drop Event */
  19403. +#define FIFO_CFG5_DV BIT(1) /* RX_DV Event */
  19404. +#define FIFO_CFG5_FC BIT(2) /* False Carrier */
  19405. +#define FIFO_CFG5_CE BIT(3) /* Code Error */
  19406. +#define FIFO_CFG5_LM BIT(4) /* Length Mismatch */
  19407. +#define FIFO_CFG5_LO BIT(5) /* Length Out of Range */
  19408. +#define FIFO_CFG5_OK BIT(6) /* Packet is OK */
  19409. +#define FIFO_CFG5_MC BIT(7) /* Multicast Packet */
  19410. +#define FIFO_CFG5_BC BIT(8) /* Broadcast Packet */
  19411. +#define FIFO_CFG5_DR BIT(9) /* Dribble */
  19412. +#define FIFO_CFG5_CF BIT(10) /* Control Frame */
  19413. +#define FIFO_CFG5_PF BIT(11) /* Pause Frame */
  19414. +#define FIFO_CFG5_UO BIT(12) /* Unsupported Opcode */
  19415. +#define FIFO_CFG5_VT BIT(13) /* VLAN tag detected */
  19416. +#define FIFO_CFG5_LE BIT(14) /* Long Event */
  19417. +#define FIFO_CFG5_FT BIT(15) /* Frame Truncated */
  19418. +#define FIFO_CFG5_16 BIT(16) /* unknown */
  19419. +#define FIFO_CFG5_17 BIT(17) /* unknown */
  19420. +#define FIFO_CFG5_SF BIT(18) /* Short Frame */
  19421. +#define FIFO_CFG5_BM BIT(19) /* Byte Mode */
  19422. +
  19423. +#define AG71XX_INT_TX_PS BIT(0)
  19424. +#define AG71XX_INT_TX_UR BIT(1)
  19425. +#define AG71XX_INT_TX_BE BIT(3)
  19426. +#define AG71XX_INT_RX_PR BIT(4)
  19427. +#define AG71XX_INT_RX_OF BIT(6)
  19428. +#define AG71XX_INT_RX_BE BIT(7)
  19429. +
  19430. +#define MAC_IFCTL_SPEED BIT(16)
  19431. +
  19432. +#define MII_CFG_CLK_DIV_4 0
  19433. +#define MII_CFG_CLK_DIV_6 2
  19434. +#define MII_CFG_CLK_DIV_8 3
  19435. +#define MII_CFG_CLK_DIV_10 4
  19436. +#define MII_CFG_CLK_DIV_14 5
  19437. +#define MII_CFG_CLK_DIV_20 6
  19438. +#define MII_CFG_CLK_DIV_28 7
  19439. +#define MII_CFG_RESET BIT(31)
  19440. +
  19441. +#define MII_CMD_WRITE 0x0
  19442. +#define MII_CMD_READ 0x1
  19443. +#define MII_ADDR_SHIFT 8
  19444. +#define MII_IND_BUSY BIT(0)
  19445. +#define MII_IND_INVALID BIT(2)
  19446. +
  19447. +#define TX_CTRL_TXE BIT(0) /* Tx Enable */
  19448. +
  19449. +#define TX_STATUS_PS BIT(0) /* Packet Sent */
  19450. +#define TX_STATUS_UR BIT(1) /* Tx Underrun */
  19451. +#define TX_STATUS_BE BIT(3) /* Bus Error */
  19452. +
  19453. +#define RX_CTRL_RXE BIT(0) /* Rx Enable */
  19454. +
  19455. +#define RX_STATUS_PR BIT(0) /* Packet Received */
  19456. +#define RX_STATUS_OF BIT(2) /* Rx Overflow */
  19457. +#define RX_STATUS_BE BIT(3) /* Bus Error */
  19458. +
  19459. +#define MII_CTRL_IF_MASK 3
  19460. +#define MII_CTRL_SPEED_SHIFT 4
  19461. +#define MII_CTRL_SPEED_MASK 3
  19462. +#define MII_CTRL_SPEED_10 0
  19463. +#define MII_CTRL_SPEED_100 1
  19464. +#define MII_CTRL_SPEED_1000 2
  19465. +
  19466. +static inline void ag71xx_check_reg_offset(struct ag71xx *ag, unsigned reg)
  19467. +{
  19468. + switch (reg) {
  19469. + case AG71XX_REG_MAC_CFG1 ... AG71XX_REG_MAC_MFL:
  19470. + case AG71XX_REG_MAC_IFCTL ... AG71XX_REG_INT_STATUS:
  19471. + case AG71XX_REG_MII_CFG:
  19472. + break;
  19473. +
  19474. + default:
  19475. + BUG();
  19476. + }
  19477. +}
  19478. +
  19479. +static inline void ag71xx_wr(struct ag71xx *ag, unsigned reg, u32 value)
  19480. +{
  19481. + ag71xx_check_reg_offset(ag, reg);
  19482. +
  19483. + __raw_writel(value, ag->mac_base + reg);
  19484. + /* flush write */
  19485. + (void) __raw_readl(ag->mac_base + reg);
  19486. +}
  19487. +
  19488. +static inline u32 ag71xx_rr(struct ag71xx *ag, unsigned reg)
  19489. +{
  19490. + ag71xx_check_reg_offset(ag, reg);
  19491. +
  19492. + return __raw_readl(ag->mac_base + reg);
  19493. +}
  19494. +
  19495. +static inline void ag71xx_sb(struct ag71xx *ag, unsigned reg, u32 mask)
  19496. +{
  19497. + void __iomem *r;
  19498. +
  19499. + ag71xx_check_reg_offset(ag, reg);
  19500. +
  19501. + r = ag->mac_base + reg;
  19502. + __raw_writel(__raw_readl(r) | mask, r);
  19503. + /* flush write */
  19504. + (void)__raw_readl(r);
  19505. +}
  19506. +
  19507. +static inline void ag71xx_cb(struct ag71xx *ag, unsigned reg, u32 mask)
  19508. +{
  19509. + void __iomem *r;
  19510. +
  19511. + ag71xx_check_reg_offset(ag, reg);
  19512. +
  19513. + r = ag->mac_base + reg;
  19514. + __raw_writel(__raw_readl(r) & ~mask, r);
  19515. + /* flush write */
  19516. + (void) __raw_readl(r);
  19517. +}
  19518. +
  19519. +static inline void ag71xx_int_enable(struct ag71xx *ag, u32 ints)
  19520. +{
  19521. + ag71xx_sb(ag, AG71XX_REG_INT_ENABLE, ints);
  19522. +}
  19523. +
  19524. +static inline void ag71xx_int_disable(struct ag71xx *ag, u32 ints)
  19525. +{
  19526. + ag71xx_cb(ag, AG71XX_REG_INT_ENABLE, ints);
  19527. +}
  19528. +
  19529. +static inline void ag71xx_mii_ctrl_wr(struct ag71xx *ag, u32 value)
  19530. +{
  19531. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  19532. +
  19533. + if (pdata->is_ar724x)
  19534. + return;
  19535. +
  19536. + __raw_writel(value, ag->mii_ctrl);
  19537. +
  19538. + /* flush write */
  19539. + __raw_readl(ag->mii_ctrl);
  19540. +}
  19541. +
  19542. +static inline u32 ag71xx_mii_ctrl_rr(struct ag71xx *ag)
  19543. +{
  19544. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  19545. +
  19546. + if (pdata->is_ar724x)
  19547. + return 0xffffffff;
  19548. +
  19549. + return __raw_readl(ag->mii_ctrl);
  19550. +}
  19551. +
  19552. +static inline void ag71xx_mii_ctrl_set_if(struct ag71xx *ag,
  19553. + unsigned int mii_if)
  19554. +{
  19555. + u32 t;
  19556. +
  19557. + t = ag71xx_mii_ctrl_rr(ag);
  19558. + t &= ~(MII_CTRL_IF_MASK);
  19559. + t |= (mii_if & MII_CTRL_IF_MASK);
  19560. + ag71xx_mii_ctrl_wr(ag, t);
  19561. +}
  19562. +
  19563. +static inline void ag71xx_mii_ctrl_set_speed(struct ag71xx *ag,
  19564. + unsigned int speed)
  19565. +{
  19566. + u32 t;
  19567. +
  19568. + t = ag71xx_mii_ctrl_rr(ag);
  19569. + t &= ~(MII_CTRL_SPEED_MASK << MII_CTRL_SPEED_SHIFT);
  19570. + t |= (speed & MII_CTRL_SPEED_MASK) << MII_CTRL_SPEED_SHIFT;
  19571. + ag71xx_mii_ctrl_wr(ag, t);
  19572. +}
  19573. +
  19574. +#ifdef CONFIG_AG71XX_AR8216_SUPPORT
  19575. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb);
  19576. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  19577. + int pktlen);
  19578. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  19579. +{
  19580. + return ag71xx_get_pdata(ag)->has_ar8216;
  19581. +}
  19582. +#else
  19583. +static inline void ag71xx_add_ar8216_header(struct ag71xx *ag,
  19584. + struct sk_buff *skb)
  19585. +{
  19586. +}
  19587. +
  19588. +static inline int ag71xx_remove_ar8216_header(struct ag71xx *ag,
  19589. + struct sk_buff *skb,
  19590. + int pktlen)
  19591. +{
  19592. + return 0;
  19593. +}
  19594. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  19595. +{
  19596. + return 0;
  19597. +}
  19598. +#endif
  19599. +
  19600. +#ifdef CONFIG_AG71XX_DEBUG_FS
  19601. +int ag71xx_debugfs_root_init(void);
  19602. +void ag71xx_debugfs_root_exit(void);
  19603. +int ag71xx_debugfs_init(struct ag71xx *ag);
  19604. +void ag71xx_debugfs_exit(struct ag71xx *ag);
  19605. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status);
  19606. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx);
  19607. +#else
  19608. +static inline int ag71xx_debugfs_root_init(void) { return 0; }
  19609. +static inline void ag71xx_debugfs_root_exit(void) {}
  19610. +static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; }
  19611. +static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {}
  19612. +static inline void ag71xx_debugfs_update_int_stats(struct ag71xx *ag,
  19613. + u32 status) {}
  19614. +static inline void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag,
  19615. + int rx, int tx) {}
  19616. +#endif /* CONFIG_AG71XX_DEBUG_FS */
  19617. +
  19618. +void ag71xx_ar7240_start(struct ag71xx *ag);
  19619. +void ag71xx_ar7240_stop(struct ag71xx *ag);
  19620. +int ag71xx_ar7240_init(struct ag71xx *ag);
  19621. +void ag71xx_ar7240_cleanup(struct ag71xx *ag);
  19622. +
  19623. +int ag71xx_mdio_mii_read(struct ag71xx_mdio *am, int addr, int reg);
  19624. +void ag71xx_mdio_mii_write(struct ag71xx_mdio *am, int addr, int reg, u16 val);
  19625. +
  19626. +u16 ar7240sw_phy_read(struct mii_bus *mii, unsigned phy_addr,
  19627. + unsigned reg_addr);
  19628. +int ar7240sw_phy_write(struct mii_bus *mii, unsigned phy_addr,
  19629. + unsigned reg_addr, u16 reg_val);
  19630. +
  19631. +#endif /* _AG71XX_H */
  19632. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_main.c linux-2.6.39/drivers/net/ag71xx/ag71xx_main.c
  19633. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_main.c 1970-01-01 01:00:00.000000000 +0100
  19634. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_main.c 2011-08-22 07:40:12.160480642 +0200
  19635. @@ -0,0 +1,1291 @@
  19636. +/*
  19637. + * Atheros AR71xx built-in ethernet mac driver
  19638. + *
  19639. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  19640. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  19641. + *
  19642. + * Based on Atheros' AG7100 driver
  19643. + *
  19644. + * This program is free software; you can redistribute it and/or modify it
  19645. + * under the terms of the GNU General Public License version 2 as published
  19646. + * by the Free Software Foundation.
  19647. + */
  19648. +
  19649. +#include "ag71xx.h"
  19650. +
  19651. +#define AG71XX_DEFAULT_MSG_ENABLE \
  19652. + (NETIF_MSG_DRV \
  19653. + | NETIF_MSG_PROBE \
  19654. + | NETIF_MSG_LINK \
  19655. + | NETIF_MSG_TIMER \
  19656. + | NETIF_MSG_IFDOWN \
  19657. + | NETIF_MSG_IFUP \
  19658. + | NETIF_MSG_RX_ERR \
  19659. + | NETIF_MSG_TX_ERR)
  19660. +
  19661. +static int ag71xx_msg_level = -1;
  19662. +
  19663. +module_param_named(msg_level, ag71xx_msg_level, int, 0);
  19664. +MODULE_PARM_DESC(msg_level, "Message level (-1=defaults,0=none,...,16=all)");
  19665. +
  19666. +static void ag71xx_dump_dma_regs(struct ag71xx *ag)
  19667. +{
  19668. + DBG("%s: dma_tx_ctrl=%08x, dma_tx_desc=%08x, dma_tx_status=%08x\n",
  19669. + ag->dev->name,
  19670. + ag71xx_rr(ag, AG71XX_REG_TX_CTRL),
  19671. + ag71xx_rr(ag, AG71XX_REG_TX_DESC),
  19672. + ag71xx_rr(ag, AG71XX_REG_TX_STATUS));
  19673. +
  19674. + DBG("%s: dma_rx_ctrl=%08x, dma_rx_desc=%08x, dma_rx_status=%08x\n",
  19675. + ag->dev->name,
  19676. + ag71xx_rr(ag, AG71XX_REG_RX_CTRL),
  19677. + ag71xx_rr(ag, AG71XX_REG_RX_DESC),
  19678. + ag71xx_rr(ag, AG71XX_REG_RX_STATUS));
  19679. +}
  19680. +
  19681. +static void ag71xx_dump_regs(struct ag71xx *ag)
  19682. +{
  19683. + DBG("%s: mac_cfg1=%08x, mac_cfg2=%08x, ipg=%08x, hdx=%08x, mfl=%08x\n",
  19684. + ag->dev->name,
  19685. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG1),
  19686. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  19687. + ag71xx_rr(ag, AG71XX_REG_MAC_IPG),
  19688. + ag71xx_rr(ag, AG71XX_REG_MAC_HDX),
  19689. + ag71xx_rr(ag, AG71XX_REG_MAC_MFL));
  19690. + DBG("%s: mac_ifctl=%08x, mac_addr1=%08x, mac_addr2=%08x\n",
  19691. + ag->dev->name,
  19692. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  19693. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR1),
  19694. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR2));
  19695. + DBG("%s: fifo_cfg0=%08x, fifo_cfg1=%08x, fifo_cfg2=%08x\n",
  19696. + ag->dev->name,
  19697. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  19698. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  19699. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  19700. + DBG("%s: fifo_cfg3=%08x, fifo_cfg4=%08x, fifo_cfg5=%08x\n",
  19701. + ag->dev->name,
  19702. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  19703. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  19704. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  19705. +}
  19706. +
  19707. +static inline void ag71xx_dump_intr(struct ag71xx *ag, char *label, u32 intr)
  19708. +{
  19709. + DBG("%s: %s intr=%08x %s%s%s%s%s%s\n",
  19710. + ag->dev->name, label, intr,
  19711. + (intr & AG71XX_INT_TX_PS) ? "TXPS " : "",
  19712. + (intr & AG71XX_INT_TX_UR) ? "TXUR " : "",
  19713. + (intr & AG71XX_INT_TX_BE) ? "TXBE " : "",
  19714. + (intr & AG71XX_INT_RX_PR) ? "RXPR " : "",
  19715. + (intr & AG71XX_INT_RX_OF) ? "RXOF " : "",
  19716. + (intr & AG71XX_INT_RX_BE) ? "RXBE " : "");
  19717. +}
  19718. +
  19719. +static void ag71xx_ring_free(struct ag71xx_ring *ring)
  19720. +{
  19721. + kfree(ring->buf);
  19722. +
  19723. + if (ring->descs_cpu)
  19724. + dma_free_coherent(NULL, ring->size * ring->desc_size,
  19725. + ring->descs_cpu, ring->descs_dma);
  19726. +}
  19727. +
  19728. +static int ag71xx_ring_alloc(struct ag71xx_ring *ring)
  19729. +{
  19730. + int err;
  19731. + int i;
  19732. +
  19733. + ring->desc_size = sizeof(struct ag71xx_desc);
  19734. + if (ring->desc_size % cache_line_size()) {
  19735. + DBG("ag71xx: ring %p, desc size %u rounded to %u\n",
  19736. + ring, ring->desc_size,
  19737. + roundup(ring->desc_size, cache_line_size()));
  19738. + ring->desc_size = roundup(ring->desc_size, cache_line_size());
  19739. + }
  19740. +
  19741. + ring->descs_cpu = dma_alloc_coherent(NULL, ring->size * ring->desc_size,
  19742. + &ring->descs_dma, GFP_ATOMIC);
  19743. + if (!ring->descs_cpu) {
  19744. + err = -ENOMEM;
  19745. + goto err;
  19746. + }
  19747. +
  19748. +
  19749. + ring->buf = kzalloc(ring->size * sizeof(*ring->buf), GFP_KERNEL);
  19750. + if (!ring->buf) {
  19751. + err = -ENOMEM;
  19752. + goto err;
  19753. + }
  19754. +
  19755. + for (i = 0; i < ring->size; i++) {
  19756. + int idx = i * ring->desc_size;
  19757. + ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[idx];
  19758. + DBG("ag71xx: ring %p, desc %d at %p\n",
  19759. + ring, i, ring->buf[i].desc);
  19760. + }
  19761. +
  19762. + return 0;
  19763. +
  19764. +err:
  19765. + return err;
  19766. +}
  19767. +
  19768. +static void ag71xx_ring_tx_clean(struct ag71xx *ag)
  19769. +{
  19770. + struct ag71xx_ring *ring = &ag->tx_ring;
  19771. + struct net_device *dev = ag->dev;
  19772. +
  19773. + while (ring->curr != ring->dirty) {
  19774. + u32 i = ring->dirty % ring->size;
  19775. +
  19776. + if (!ag71xx_desc_empty(ring->buf[i].desc)) {
  19777. + ring->buf[i].desc->ctrl = 0;
  19778. + dev->stats.tx_errors++;
  19779. + }
  19780. +
  19781. + if (ring->buf[i].skb)
  19782. + dev_kfree_skb_any(ring->buf[i].skb);
  19783. +
  19784. + ring->buf[i].skb = NULL;
  19785. +
  19786. + ring->dirty++;
  19787. + }
  19788. +
  19789. + /* flush descriptors */
  19790. + wmb();
  19791. +
  19792. +}
  19793. +
  19794. +static void ag71xx_ring_tx_init(struct ag71xx *ag)
  19795. +{
  19796. + struct ag71xx_ring *ring = &ag->tx_ring;
  19797. + int i;
  19798. +
  19799. + for (i = 0; i < ring->size; i++) {
  19800. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  19801. + ring->desc_size * ((i + 1) % ring->size));
  19802. +
  19803. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  19804. + ring->buf[i].skb = NULL;
  19805. + }
  19806. +
  19807. + /* flush descriptors */
  19808. + wmb();
  19809. +
  19810. + ring->curr = 0;
  19811. + ring->dirty = 0;
  19812. +}
  19813. +
  19814. +static void ag71xx_ring_rx_clean(struct ag71xx *ag)
  19815. +{
  19816. + struct ag71xx_ring *ring = &ag->rx_ring;
  19817. + int i;
  19818. +
  19819. + if (!ring->buf)
  19820. + return;
  19821. +
  19822. + for (i = 0; i < ring->size; i++)
  19823. + if (ring->buf[i].skb) {
  19824. + dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
  19825. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  19826. + kfree_skb(ring->buf[i].skb);
  19827. + }
  19828. +}
  19829. +
  19830. +static int ag71xx_rx_reserve(struct ag71xx *ag)
  19831. +{
  19832. + int reserve = 0;
  19833. +
  19834. + if (ag71xx_get_pdata(ag)->is_ar724x) {
  19835. + if (!ag71xx_has_ar8216(ag))
  19836. + reserve = 2;
  19837. +
  19838. + if (ag->phy_dev)
  19839. + reserve += 4 - (ag->phy_dev->pkt_align % 4);
  19840. +
  19841. + reserve %= 4;
  19842. + }
  19843. +
  19844. + return reserve + AG71XX_RX_PKT_RESERVE;
  19845. +}
  19846. +
  19847. +
  19848. +static int ag71xx_ring_rx_init(struct ag71xx *ag)
  19849. +{
  19850. + struct ag71xx_ring *ring = &ag->rx_ring;
  19851. + unsigned int reserve = ag71xx_rx_reserve(ag);
  19852. + unsigned int i;
  19853. + int ret;
  19854. +
  19855. + ret = 0;
  19856. + for (i = 0; i < ring->size; i++) {
  19857. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  19858. + ring->desc_size * ((i + 1) % ring->size));
  19859. +
  19860. + DBG("ag71xx: RX desc at %p, next is %08x\n",
  19861. + ring->buf[i].desc,
  19862. + ring->buf[i].desc->next);
  19863. + }
  19864. +
  19865. + for (i = 0; i < ring->size; i++) {
  19866. + struct sk_buff *skb;
  19867. + dma_addr_t dma_addr;
  19868. +
  19869. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  19870. + if (!skb) {
  19871. + ret = -ENOMEM;
  19872. + break;
  19873. + }
  19874. +
  19875. + skb->dev = ag->dev;
  19876. + skb_reserve(skb, reserve);
  19877. +
  19878. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  19879. + AG71XX_RX_PKT_SIZE,
  19880. + DMA_FROM_DEVICE);
  19881. + ring->buf[i].skb = skb;
  19882. + ring->buf[i].dma_addr = dma_addr;
  19883. + ring->buf[i].desc->data = (u32) dma_addr;
  19884. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  19885. + }
  19886. +
  19887. + /* flush descriptors */
  19888. + wmb();
  19889. +
  19890. + ring->curr = 0;
  19891. + ring->dirty = 0;
  19892. +
  19893. + return ret;
  19894. +}
  19895. +
  19896. +static int ag71xx_ring_rx_refill(struct ag71xx *ag)
  19897. +{
  19898. + struct ag71xx_ring *ring = &ag->rx_ring;
  19899. + unsigned int reserve = ag71xx_rx_reserve(ag);
  19900. + unsigned int count;
  19901. +
  19902. + count = 0;
  19903. + for (; ring->curr - ring->dirty > 0; ring->dirty++) {
  19904. + unsigned int i;
  19905. +
  19906. + i = ring->dirty % ring->size;
  19907. +
  19908. + if (ring->buf[i].skb == NULL) {
  19909. + dma_addr_t dma_addr;
  19910. + struct sk_buff *skb;
  19911. +
  19912. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  19913. + if (skb == NULL)
  19914. + break;
  19915. +
  19916. + skb_reserve(skb, reserve);
  19917. + skb->dev = ag->dev;
  19918. +
  19919. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  19920. + AG71XX_RX_PKT_SIZE,
  19921. + DMA_FROM_DEVICE);
  19922. +
  19923. + ring->buf[i].skb = skb;
  19924. + ring->buf[i].dma_addr = dma_addr;
  19925. + ring->buf[i].desc->data = (u32) dma_addr;
  19926. + }
  19927. +
  19928. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  19929. + count++;
  19930. + }
  19931. +
  19932. + /* flush descriptors */
  19933. + wmb();
  19934. +
  19935. + DBG("%s: %u rx descriptors refilled\n", ag->dev->name, count);
  19936. +
  19937. + return count;
  19938. +}
  19939. +
  19940. +static int ag71xx_rings_init(struct ag71xx *ag)
  19941. +{
  19942. + int ret;
  19943. +
  19944. + ret = ag71xx_ring_alloc(&ag->tx_ring);
  19945. + if (ret)
  19946. + return ret;
  19947. +
  19948. + ag71xx_ring_tx_init(ag);
  19949. +
  19950. + ret = ag71xx_ring_alloc(&ag->rx_ring);
  19951. + if (ret)
  19952. + return ret;
  19953. +
  19954. + ret = ag71xx_ring_rx_init(ag);
  19955. + return ret;
  19956. +}
  19957. +
  19958. +static void ag71xx_rings_cleanup(struct ag71xx *ag)
  19959. +{
  19960. + ag71xx_ring_rx_clean(ag);
  19961. + ag71xx_ring_free(&ag->rx_ring);
  19962. +
  19963. + ag71xx_ring_tx_clean(ag);
  19964. + ag71xx_ring_free(&ag->tx_ring);
  19965. +}
  19966. +
  19967. +static unsigned char *ag71xx_speed_str(struct ag71xx *ag)
  19968. +{
  19969. + switch (ag->speed) {
  19970. + case SPEED_1000:
  19971. + return "1000";
  19972. + case SPEED_100:
  19973. + return "100";
  19974. + case SPEED_10:
  19975. + return "10";
  19976. + }
  19977. +
  19978. + return "?";
  19979. +}
  19980. +
  19981. +static void ag71xx_hw_set_macaddr(struct ag71xx *ag, unsigned char *mac)
  19982. +{
  19983. + u32 t;
  19984. +
  19985. + t = (((u32) mac[5]) << 24) | (((u32) mac[4]) << 16)
  19986. + | (((u32) mac[3]) << 8) | ((u32) mac[2]);
  19987. +
  19988. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR1, t);
  19989. +
  19990. + t = (((u32) mac[1]) << 24) | (((u32) mac[0]) << 16);
  19991. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR2, t);
  19992. +}
  19993. +
  19994. +static void ag71xx_dma_reset(struct ag71xx *ag)
  19995. +{
  19996. + u32 val;
  19997. + int i;
  19998. +
  19999. + ag71xx_dump_dma_regs(ag);
  20000. +
  20001. + /* stop RX and TX */
  20002. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, 0);
  20003. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, 0);
  20004. +
  20005. + /*
  20006. + * give the hardware some time to really stop all rx/tx activity
  20007. + * clearing the descriptors too early causes random memory corruption
  20008. + */
  20009. + mdelay(1);
  20010. +
  20011. + /* clear descriptor addresses */
  20012. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, ag->stop_desc_dma);
  20013. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, ag->stop_desc_dma);
  20014. +
  20015. + /* clear pending RX/TX interrupts */
  20016. + for (i = 0; i < 256; i++) {
  20017. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  20018. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  20019. + }
  20020. +
  20021. + /* clear pending errors */
  20022. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE | RX_STATUS_OF);
  20023. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE | TX_STATUS_UR);
  20024. +
  20025. + val = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  20026. + if (val)
  20027. + printk(KERN_ALERT "%s: unable to clear DMA Rx status: %08x\n",
  20028. + ag->dev->name, val);
  20029. +
  20030. + val = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  20031. +
  20032. + /* mask out reserved bits */
  20033. + val &= ~0xff000000;
  20034. +
  20035. + if (val)
  20036. + printk(KERN_ALERT "%s: unable to clear DMA Tx status: %08x\n",
  20037. + ag->dev->name, val);
  20038. +
  20039. + ag71xx_dump_dma_regs(ag);
  20040. +}
  20041. +
  20042. +#define MAC_CFG1_INIT (MAC_CFG1_RXE | MAC_CFG1_TXE | \
  20043. + MAC_CFG1_SRX | MAC_CFG1_STX)
  20044. +
  20045. +#define FIFO_CFG0_INIT (FIFO_CFG0_ALL << FIFO_CFG0_ENABLE_SHIFT)
  20046. +
  20047. +#define FIFO_CFG4_INIT (FIFO_CFG4_DE | FIFO_CFG4_DV | FIFO_CFG4_FC | \
  20048. + FIFO_CFG4_CE | FIFO_CFG4_CR | FIFO_CFG4_LM | \
  20049. + FIFO_CFG4_LO | FIFO_CFG4_OK | FIFO_CFG4_MC | \
  20050. + FIFO_CFG4_BC | FIFO_CFG4_DR | FIFO_CFG4_LE | \
  20051. + FIFO_CFG4_CF | FIFO_CFG4_PF | FIFO_CFG4_UO | \
  20052. + FIFO_CFG4_VT)
  20053. +
  20054. +#define FIFO_CFG5_INIT (FIFO_CFG5_DE | FIFO_CFG5_DV | FIFO_CFG5_FC | \
  20055. + FIFO_CFG5_CE | FIFO_CFG5_LO | FIFO_CFG5_OK | \
  20056. + FIFO_CFG5_MC | FIFO_CFG5_BC | FIFO_CFG5_DR | \
  20057. + FIFO_CFG5_CF | FIFO_CFG5_PF | FIFO_CFG5_VT | \
  20058. + FIFO_CFG5_LE | FIFO_CFG5_FT | FIFO_CFG5_16 | \
  20059. + FIFO_CFG5_17 | FIFO_CFG5_SF)
  20060. +
  20061. +static void ag71xx_hw_stop(struct ag71xx *ag)
  20062. +{
  20063. + /* disable all interrupts and stop the rx/tx engine */
  20064. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, 0);
  20065. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, 0);
  20066. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, 0);
  20067. +}
  20068. +
  20069. +static void ag71xx_hw_setup(struct ag71xx *ag)
  20070. +{
  20071. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20072. +
  20073. + /* setup MAC configuration registers */
  20074. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_INIT);
  20075. +
  20076. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG2,
  20077. + MAC_CFG2_PAD_CRC_EN | MAC_CFG2_LEN_CHECK);
  20078. +
  20079. + /* setup max frame length */
  20080. + ag71xx_wr(ag, AG71XX_REG_MAC_MFL, AG71XX_TX_MTU_LEN);
  20081. +
  20082. + /* setup MII interface type */
  20083. + ag71xx_mii_ctrl_set_if(ag, pdata->mii_if);
  20084. +
  20085. + /* setup FIFO configuration registers */
  20086. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG0, FIFO_CFG0_INIT);
  20087. + if (pdata->is_ar724x) {
  20088. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, pdata->fifo_cfg1);
  20089. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, pdata->fifo_cfg2);
  20090. + } else {
  20091. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, 0x0fff0000);
  20092. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, 0x00001fff);
  20093. + }
  20094. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG4, FIFO_CFG4_INIT);
  20095. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, FIFO_CFG5_INIT);
  20096. +}
  20097. +
  20098. +static void ag71xx_hw_init(struct ag71xx *ag)
  20099. +{
  20100. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20101. + u32 reset_mask = pdata->reset_bit;
  20102. +
  20103. + ag71xx_hw_stop(ag);
  20104. +
  20105. + if (pdata->is_ar724x) {
  20106. + u32 reset_phy = reset_mask;
  20107. +
  20108. + reset_phy &= RESET_MODULE_GE0_PHY | RESET_MODULE_GE1_PHY;
  20109. + reset_mask &= ~(RESET_MODULE_GE0_PHY | RESET_MODULE_GE1_PHY);
  20110. +
  20111. + ar71xx_device_stop(reset_phy);
  20112. + mdelay(50);
  20113. + ar71xx_device_start(reset_phy);
  20114. + mdelay(200);
  20115. + }
  20116. +
  20117. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_SR);
  20118. + udelay(20);
  20119. +
  20120. + ar71xx_device_stop(reset_mask);
  20121. + mdelay(100);
  20122. + ar71xx_device_start(reset_mask);
  20123. + mdelay(200);
  20124. +
  20125. + ag71xx_hw_setup(ag);
  20126. +
  20127. + ag71xx_dma_reset(ag);
  20128. +}
  20129. +
  20130. +static void ag71xx_fast_reset(struct ag71xx *ag)
  20131. +{
  20132. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20133. + struct net_device *dev = ag->dev;
  20134. + u32 reset_mask = pdata->reset_bit;
  20135. + u32 rx_ds, tx_ds;
  20136. + u32 mii_reg;
  20137. +
  20138. + reset_mask &= RESET_MODULE_GE0_MAC | RESET_MODULE_GE1_MAC;
  20139. +
  20140. + mii_reg = ag71xx_rr(ag, AG71XX_REG_MII_CFG);
  20141. + rx_ds = ag71xx_rr(ag, AG71XX_REG_RX_DESC);
  20142. + tx_ds = ag71xx_rr(ag, AG71XX_REG_TX_DESC);
  20143. +
  20144. + ar71xx_device_stop(reset_mask);
  20145. + udelay(10);
  20146. + ar71xx_device_start(reset_mask);
  20147. + udelay(10);
  20148. +
  20149. + ag71xx_dma_reset(ag);
  20150. + ag71xx_hw_setup(ag);
  20151. +
  20152. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, rx_ds);
  20153. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, tx_ds);
  20154. + ag71xx_wr(ag, AG71XX_REG_MII_CFG, mii_reg);
  20155. +
  20156. + ag71xx_hw_set_macaddr(ag, dev->dev_addr);
  20157. +}
  20158. +
  20159. +static void ag71xx_hw_start(struct ag71xx *ag)
  20160. +{
  20161. + /* start RX engine */
  20162. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  20163. +
  20164. + /* enable interrupts */
  20165. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, AG71XX_INT_INIT);
  20166. +}
  20167. +
  20168. +void ag71xx_link_adjust(struct ag71xx *ag)
  20169. +{
  20170. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20171. + u32 cfg2;
  20172. + u32 ifctl;
  20173. + u32 fifo5;
  20174. + u32 mii_speed;
  20175. +
  20176. + if (!ag->link) {
  20177. + ag71xx_hw_stop(ag);
  20178. + netif_carrier_off(ag->dev);
  20179. + if (netif_msg_link(ag))
  20180. + printk(KERN_INFO "%s: link down\n", ag->dev->name);
  20181. + return;
  20182. + }
  20183. +
  20184. + if (pdata->is_ar724x)
  20185. + ag71xx_fast_reset(ag);
  20186. +
  20187. + cfg2 = ag71xx_rr(ag, AG71XX_REG_MAC_CFG2);
  20188. + cfg2 &= ~(MAC_CFG2_IF_1000 | MAC_CFG2_IF_10_100 | MAC_CFG2_FDX);
  20189. + cfg2 |= (ag->duplex) ? MAC_CFG2_FDX : 0;
  20190. +
  20191. + ifctl = ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL);
  20192. + ifctl &= ~(MAC_IFCTL_SPEED);
  20193. +
  20194. + fifo5 = ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5);
  20195. + fifo5 &= ~FIFO_CFG5_BM;
  20196. +
  20197. + switch (ag->speed) {
  20198. + case SPEED_1000:
  20199. + mii_speed = MII_CTRL_SPEED_1000;
  20200. + cfg2 |= MAC_CFG2_IF_1000;
  20201. + fifo5 |= FIFO_CFG5_BM;
  20202. + break;
  20203. + case SPEED_100:
  20204. + mii_speed = MII_CTRL_SPEED_100;
  20205. + cfg2 |= MAC_CFG2_IF_10_100;
  20206. + ifctl |= MAC_IFCTL_SPEED;
  20207. + break;
  20208. + case SPEED_10:
  20209. + mii_speed = MII_CTRL_SPEED_10;
  20210. + cfg2 |= MAC_CFG2_IF_10_100;
  20211. + break;
  20212. + default:
  20213. + BUG();
  20214. + return;
  20215. + }
  20216. +
  20217. + if (pdata->is_ar91xx)
  20218. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x00780fff);
  20219. + else if (pdata->is_ar724x)
  20220. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, pdata->fifo_cfg3);
  20221. + else
  20222. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x008001ff);
  20223. +
  20224. + if (pdata->set_pll)
  20225. + pdata->set_pll(ag->speed);
  20226. +
  20227. + ag71xx_mii_ctrl_set_speed(ag, mii_speed);
  20228. +
  20229. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG2, cfg2);
  20230. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, fifo5);
  20231. + ag71xx_wr(ag, AG71XX_REG_MAC_IFCTL, ifctl);
  20232. + ag71xx_hw_start(ag);
  20233. +
  20234. + netif_carrier_on(ag->dev);
  20235. + if (netif_msg_link(ag))
  20236. + printk(KERN_INFO "%s: link up (%sMbps/%s duplex)\n",
  20237. + ag->dev->name,
  20238. + ag71xx_speed_str(ag),
  20239. + (DUPLEX_FULL == ag->duplex) ? "Full" : "Half");
  20240. +
  20241. + DBG("%s: fifo_cfg0=%#x, fifo_cfg1=%#x, fifo_cfg2=%#x\n",
  20242. + ag->dev->name,
  20243. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  20244. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  20245. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  20246. +
  20247. + DBG("%s: fifo_cfg3=%#x, fifo_cfg4=%#x, fifo_cfg5=%#x\n",
  20248. + ag->dev->name,
  20249. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  20250. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  20251. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  20252. +
  20253. + DBG("%s: mac_cfg2=%#x, mac_ifctl=%#x, mii_ctrl=%#x\n",
  20254. + ag->dev->name,
  20255. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  20256. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  20257. + ag71xx_mii_ctrl_rr(ag));
  20258. +}
  20259. +
  20260. +static int ag71xx_open(struct net_device *dev)
  20261. +{
  20262. + struct ag71xx *ag = netdev_priv(dev);
  20263. + int ret;
  20264. +
  20265. + ret = ag71xx_rings_init(ag);
  20266. + if (ret)
  20267. + goto err;
  20268. +
  20269. + napi_enable(&ag->napi);
  20270. +
  20271. + netif_carrier_off(dev);
  20272. + ag71xx_phy_start(ag);
  20273. +
  20274. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, ag->tx_ring.descs_dma);
  20275. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, ag->rx_ring.descs_dma);
  20276. +
  20277. + ag71xx_hw_set_macaddr(ag, dev->dev_addr);
  20278. +
  20279. + netif_start_queue(dev);
  20280. +
  20281. + return 0;
  20282. +
  20283. +err:
  20284. + ag71xx_rings_cleanup(ag);
  20285. + return ret;
  20286. +}
  20287. +
  20288. +static int ag71xx_stop(struct net_device *dev)
  20289. +{
  20290. + struct ag71xx *ag = netdev_priv(dev);
  20291. + unsigned long flags;
  20292. +
  20293. + netif_carrier_off(dev);
  20294. + ag71xx_phy_stop(ag);
  20295. +
  20296. + spin_lock_irqsave(&ag->lock, flags);
  20297. +
  20298. + netif_stop_queue(dev);
  20299. +
  20300. + ag71xx_hw_stop(ag);
  20301. + ag71xx_dma_reset(ag);
  20302. +
  20303. + napi_disable(&ag->napi);
  20304. + del_timer_sync(&ag->oom_timer);
  20305. +
  20306. + spin_unlock_irqrestore(&ag->lock, flags);
  20307. +
  20308. + ag71xx_rings_cleanup(ag);
  20309. +
  20310. + return 0;
  20311. +}
  20312. +
  20313. +static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
  20314. + struct net_device *dev)
  20315. +{
  20316. + struct ag71xx *ag = netdev_priv(dev);
  20317. + struct ag71xx_ring *ring = &ag->tx_ring;
  20318. + struct ag71xx_desc *desc;
  20319. + dma_addr_t dma_addr;
  20320. + int i;
  20321. +
  20322. + i = ring->curr % ring->size;
  20323. + desc = ring->buf[i].desc;
  20324. +
  20325. + if (!ag71xx_desc_empty(desc))
  20326. + goto err_drop;
  20327. +
  20328. + if (ag71xx_has_ar8216(ag))
  20329. + ag71xx_add_ar8216_header(ag, skb);
  20330. +
  20331. + if (skb->len <= 0) {
  20332. + DBG("%s: packet len is too small\n", ag->dev->name);
  20333. + goto err_drop;
  20334. + }
  20335. +
  20336. + dma_addr = dma_map_single(&dev->dev, skb->data, skb->len,
  20337. + DMA_TO_DEVICE);
  20338. +
  20339. + ring->buf[i].skb = skb;
  20340. + ring->buf[i].timestamp = jiffies;
  20341. +
  20342. + /* setup descriptor fields */
  20343. + desc->data = (u32) dma_addr;
  20344. + desc->ctrl = (skb->len & DESC_PKTLEN_M);
  20345. +
  20346. + /* flush descriptor */
  20347. + wmb();
  20348. +
  20349. + ring->curr++;
  20350. + if (ring->curr == (ring->dirty + ring->size)) {
  20351. + DBG("%s: tx queue full\n", ag->dev->name);
  20352. + netif_stop_queue(dev);
  20353. + }
  20354. +
  20355. + DBG("%s: packet injected into TX queue\n", ag->dev->name);
  20356. +
  20357. + /* enable TX engine */
  20358. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, TX_CTRL_TXE);
  20359. +
  20360. + return NETDEV_TX_OK;
  20361. +
  20362. +err_drop:
  20363. + dev->stats.tx_dropped++;
  20364. +
  20365. + dev_kfree_skb(skb);
  20366. + return NETDEV_TX_OK;
  20367. +}
  20368. +
  20369. +static int ag71xx_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  20370. +{
  20371. + struct ag71xx *ag = netdev_priv(dev);
  20372. + int ret;
  20373. +
  20374. + switch (cmd) {
  20375. + case SIOCETHTOOL:
  20376. + if (ag->phy_dev == NULL)
  20377. + break;
  20378. +
  20379. + spin_lock_irq(&ag->lock);
  20380. + ret = phy_ethtool_ioctl(ag->phy_dev, (void *) ifr->ifr_data);
  20381. + spin_unlock_irq(&ag->lock);
  20382. + return ret;
  20383. +
  20384. + case SIOCSIFHWADDR:
  20385. + if (copy_from_user
  20386. + (dev->dev_addr, ifr->ifr_data, sizeof(dev->dev_addr)))
  20387. + return -EFAULT;
  20388. + return 0;
  20389. +
  20390. + case SIOCGIFHWADDR:
  20391. + if (copy_to_user
  20392. + (ifr->ifr_data, dev->dev_addr, sizeof(dev->dev_addr)))
  20393. + return -EFAULT;
  20394. + return 0;
  20395. +
  20396. + case SIOCGMIIPHY:
  20397. + case SIOCGMIIREG:
  20398. + case SIOCSMIIREG:
  20399. + if (ag->phy_dev == NULL)
  20400. + break;
  20401. +
  20402. + return phy_mii_ioctl(ag->phy_dev, ifr, cmd);
  20403. +
  20404. + default:
  20405. + break;
  20406. + }
  20407. +
  20408. + return -EOPNOTSUPP;
  20409. +}
  20410. +
  20411. +static void ag71xx_oom_timer_handler(unsigned long data)
  20412. +{
  20413. + struct net_device *dev = (struct net_device *) data;
  20414. + struct ag71xx *ag = netdev_priv(dev);
  20415. +
  20416. + napi_schedule(&ag->napi);
  20417. +}
  20418. +
  20419. +static void ag71xx_tx_timeout(struct net_device *dev)
  20420. +{
  20421. + struct ag71xx *ag = netdev_priv(dev);
  20422. +
  20423. + if (netif_msg_tx_err(ag))
  20424. + printk(KERN_DEBUG "%s: tx timeout\n", ag->dev->name);
  20425. +
  20426. + schedule_work(&ag->restart_work);
  20427. +}
  20428. +
  20429. +static void ag71xx_restart_work_func(struct work_struct *work)
  20430. +{
  20431. + struct ag71xx *ag = container_of(work, struct ag71xx, restart_work);
  20432. +
  20433. + if (ag71xx_get_pdata(ag)->is_ar724x) {
  20434. + ag->link = 0;
  20435. + ag71xx_link_adjust(ag);
  20436. + return;
  20437. + }
  20438. +
  20439. + ag71xx_stop(ag->dev);
  20440. + ag71xx_open(ag->dev);
  20441. +}
  20442. +
  20443. +static bool ag71xx_check_dma_stuck(struct ag71xx *ag, unsigned long timestamp)
  20444. +{
  20445. + u32 rx_sm, tx_sm, rx_fd;
  20446. +
  20447. + if (likely(time_before(jiffies, timestamp + HZ/10)))
  20448. + return false;
  20449. +
  20450. + if (!netif_carrier_ok(ag->dev))
  20451. + return false;
  20452. +
  20453. + rx_sm = ag71xx_rr(ag, AG71XX_REG_RX_SM);
  20454. + if ((rx_sm & 0x7) == 0x3 && ((rx_sm >> 4) & 0x7) == 0x6)
  20455. + return true;
  20456. +
  20457. + tx_sm = ag71xx_rr(ag, AG71XX_REG_TX_SM);
  20458. + rx_fd = ag71xx_rr(ag, AG71XX_REG_FIFO_DEPTH);
  20459. + if (((tx_sm >> 4) & 0x7) == 0 && ((rx_sm & 0x7) == 0) &&
  20460. + ((rx_sm >> 4) & 0x7) == 0 && rx_fd == 0)
  20461. + return true;
  20462. +
  20463. + return false;
  20464. +}
  20465. +
  20466. +static int ag71xx_tx_packets(struct ag71xx *ag)
  20467. +{
  20468. + struct ag71xx_ring *ring = &ag->tx_ring;
  20469. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20470. + int sent;
  20471. +
  20472. + DBG("%s: processing TX ring\n", ag->dev->name);
  20473. +
  20474. + sent = 0;
  20475. + while (ring->dirty != ring->curr) {
  20476. + unsigned int i = ring->dirty % ring->size;
  20477. + struct ag71xx_desc *desc = ring->buf[i].desc;
  20478. + struct sk_buff *skb = ring->buf[i].skb;
  20479. +
  20480. + if (!ag71xx_desc_empty(desc)) {
  20481. + if (pdata->is_ar7240 &&
  20482. + ag71xx_check_dma_stuck(ag, ring->buf[i].timestamp))
  20483. + schedule_work(&ag->restart_work);
  20484. + break;
  20485. + }
  20486. +
  20487. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  20488. +
  20489. + ag->dev->stats.tx_bytes += skb->len;
  20490. + ag->dev->stats.tx_packets++;
  20491. +
  20492. + dev_kfree_skb_any(skb);
  20493. + ring->buf[i].skb = NULL;
  20494. +
  20495. + ring->dirty++;
  20496. + sent++;
  20497. + }
  20498. +
  20499. + DBG("%s: %d packets sent out\n", ag->dev->name, sent);
  20500. +
  20501. + if ((ring->curr - ring->dirty) < (ring->size * 3) / 4)
  20502. + netif_wake_queue(ag->dev);
  20503. +
  20504. + return sent;
  20505. +}
  20506. +
  20507. +static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
  20508. +{
  20509. + struct net_device *dev = ag->dev;
  20510. + struct ag71xx_ring *ring = &ag->rx_ring;
  20511. + int done = 0;
  20512. +
  20513. + DBG("%s: rx packets, limit=%d, curr=%u, dirty=%u\n",
  20514. + dev->name, limit, ring->curr, ring->dirty);
  20515. +
  20516. + while (done < limit) {
  20517. + unsigned int i = ring->curr % ring->size;
  20518. + struct ag71xx_desc *desc = ring->buf[i].desc;
  20519. + struct sk_buff *skb;
  20520. + int pktlen;
  20521. + int err = 0;
  20522. +
  20523. + if (ag71xx_desc_empty(desc))
  20524. + break;
  20525. +
  20526. + if ((ring->dirty + ring->size) == ring->curr) {
  20527. + ag71xx_assert(0);
  20528. + break;
  20529. + }
  20530. +
  20531. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  20532. +
  20533. + skb = ring->buf[i].skb;
  20534. + pktlen = ag71xx_desc_pktlen(desc);
  20535. + pktlen -= ETH_FCS_LEN;
  20536. +
  20537. + dma_unmap_single(&dev->dev, ring->buf[i].dma_addr,
  20538. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  20539. +
  20540. + dev->last_rx = jiffies;
  20541. + dev->stats.rx_packets++;
  20542. + dev->stats.rx_bytes += pktlen;
  20543. +
  20544. + skb_put(skb, pktlen);
  20545. + if (ag71xx_has_ar8216(ag))
  20546. + err = ag71xx_remove_ar8216_header(ag, skb, pktlen);
  20547. +
  20548. + if (err) {
  20549. + dev->stats.rx_dropped++;
  20550. + kfree_skb(skb);
  20551. + } else {
  20552. + skb->dev = dev;
  20553. + skb->ip_summed = CHECKSUM_NONE;
  20554. + if (ag->phy_dev) {
  20555. + ag->phy_dev->netif_receive_skb(skb);
  20556. + } else {
  20557. + skb->protocol = eth_type_trans(skb, dev);
  20558. + netif_receive_skb(skb);
  20559. + }
  20560. + }
  20561. +
  20562. + ring->buf[i].skb = NULL;
  20563. + done++;
  20564. +
  20565. + ring->curr++;
  20566. + }
  20567. +
  20568. + ag71xx_ring_rx_refill(ag);
  20569. +
  20570. + DBG("%s: rx finish, curr=%u, dirty=%u, done=%d\n",
  20571. + dev->name, ring->curr, ring->dirty, done);
  20572. +
  20573. + return done;
  20574. +}
  20575. +
  20576. +static int ag71xx_poll(struct napi_struct *napi, int limit)
  20577. +{
  20578. + struct ag71xx *ag = container_of(napi, struct ag71xx, napi);
  20579. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  20580. + struct net_device *dev = ag->dev;
  20581. + struct ag71xx_ring *rx_ring;
  20582. + unsigned long flags;
  20583. + u32 status;
  20584. + int tx_done;
  20585. + int rx_done;
  20586. +
  20587. + pdata->ddr_flush();
  20588. + tx_done = ag71xx_tx_packets(ag);
  20589. +
  20590. + DBG("%s: processing RX ring\n", dev->name);
  20591. + rx_done = ag71xx_rx_packets(ag, limit);
  20592. +
  20593. + ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done);
  20594. +
  20595. + rx_ring = &ag->rx_ring;
  20596. + if (rx_ring->buf[rx_ring->dirty % rx_ring->size].skb == NULL)
  20597. + goto oom;
  20598. +
  20599. + status = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  20600. + if (unlikely(status & RX_STATUS_OF)) {
  20601. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_OF);
  20602. + dev->stats.rx_fifo_errors++;
  20603. +
  20604. + /* restart RX */
  20605. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  20606. + }
  20607. +
  20608. + if (rx_done < limit) {
  20609. + if (status & RX_STATUS_PR)
  20610. + goto more;
  20611. +
  20612. + status = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  20613. + if (status & TX_STATUS_PS)
  20614. + goto more;
  20615. +
  20616. + DBG("%s: disable polling mode, rx=%d, tx=%d,limit=%d\n",
  20617. + dev->name, rx_done, tx_done, limit);
  20618. +
  20619. + napi_complete(napi);
  20620. +
  20621. + /* enable interrupts */
  20622. + spin_lock_irqsave(&ag->lock, flags);
  20623. + ag71xx_int_enable(ag, AG71XX_INT_POLL);
  20624. + spin_unlock_irqrestore(&ag->lock, flags);
  20625. + return rx_done;
  20626. + }
  20627. +
  20628. +more:
  20629. + DBG("%s: stay in polling mode, rx=%d, tx=%d, limit=%d\n",
  20630. + dev->name, rx_done, tx_done, limit);
  20631. + return rx_done;
  20632. +
  20633. +oom:
  20634. + if (netif_msg_rx_err(ag))
  20635. + printk(KERN_DEBUG "%s: out of memory\n", dev->name);
  20636. +
  20637. + mod_timer(&ag->oom_timer, jiffies + AG71XX_OOM_REFILL);
  20638. + napi_complete(napi);
  20639. + return 0;
  20640. +}
  20641. +
  20642. +static irqreturn_t ag71xx_interrupt(int irq, void *dev_id)
  20643. +{
  20644. + struct net_device *dev = dev_id;
  20645. + struct ag71xx *ag = netdev_priv(dev);
  20646. + u32 status;
  20647. +
  20648. + status = ag71xx_rr(ag, AG71XX_REG_INT_STATUS);
  20649. + ag71xx_dump_intr(ag, "raw", status);
  20650. +
  20651. + if (unlikely(!status))
  20652. + return IRQ_NONE;
  20653. +
  20654. + if (unlikely(status & AG71XX_INT_ERR)) {
  20655. + if (status & AG71XX_INT_TX_BE) {
  20656. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE);
  20657. + dev_err(&dev->dev, "TX BUS error\n");
  20658. + }
  20659. + if (status & AG71XX_INT_RX_BE) {
  20660. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE);
  20661. + dev_err(&dev->dev, "RX BUS error\n");
  20662. + }
  20663. + }
  20664. +
  20665. + if (likely(status & AG71XX_INT_POLL)) {
  20666. + ag71xx_int_disable(ag, AG71XX_INT_POLL);
  20667. + DBG("%s: enable polling mode\n", dev->name);
  20668. + napi_schedule(&ag->napi);
  20669. + }
  20670. +
  20671. + ag71xx_debugfs_update_int_stats(ag, status);
  20672. +
  20673. + return IRQ_HANDLED;
  20674. +}
  20675. +
  20676. +static void ag71xx_set_multicast_list(struct net_device *dev)
  20677. +{
  20678. + /* TODO */
  20679. +}
  20680. +
  20681. +#ifdef CONFIG_NET_POLL_CONTROLLER
  20682. +/*
  20683. + * Polling 'interrupt' - used by things like netconsole to send skbs
  20684. + * without having to re-enable interrupts. It's not called while
  20685. + * the interrupt routine is executing.
  20686. + */
  20687. +static void ag71xx_netpoll(struct net_device *dev)
  20688. +{
  20689. + disable_irq(dev->irq);
  20690. + ag71xx_interrupt(dev->irq, dev);
  20691. + enable_irq(dev->irq);
  20692. +}
  20693. +#endif
  20694. +
  20695. +static const struct net_device_ops ag71xx_netdev_ops = {
  20696. + .ndo_open = ag71xx_open,
  20697. + .ndo_stop = ag71xx_stop,
  20698. + .ndo_start_xmit = ag71xx_hard_start_xmit,
  20699. + .ndo_set_multicast_list = ag71xx_set_multicast_list,
  20700. + .ndo_do_ioctl = ag71xx_do_ioctl,
  20701. + .ndo_tx_timeout = ag71xx_tx_timeout,
  20702. + .ndo_change_mtu = eth_change_mtu,
  20703. + .ndo_set_mac_address = eth_mac_addr,
  20704. + .ndo_validate_addr = eth_validate_addr,
  20705. +#ifdef CONFIG_NET_POLL_CONTROLLER
  20706. + .ndo_poll_controller = ag71xx_netpoll,
  20707. +#endif
  20708. +};
  20709. +
  20710. +static int __devinit ag71xx_probe(struct platform_device *pdev)
  20711. +{
  20712. + struct net_device *dev;
  20713. + struct resource *res;
  20714. + struct ag71xx *ag;
  20715. + struct ag71xx_platform_data *pdata;
  20716. + int err;
  20717. +
  20718. + pdata = pdev->dev.platform_data;
  20719. + if (!pdata) {
  20720. + dev_err(&pdev->dev, "no platform data specified\n");
  20721. + err = -ENXIO;
  20722. + goto err_out;
  20723. + }
  20724. +
  20725. + if (pdata->mii_bus_dev == NULL) {
  20726. + dev_err(&pdev->dev, "no MII bus device specified\n");
  20727. + err = -EINVAL;
  20728. + goto err_out;
  20729. + }
  20730. +
  20731. + dev = alloc_etherdev(sizeof(*ag));
  20732. + if (!dev) {
  20733. + dev_err(&pdev->dev, "alloc_etherdev failed\n");
  20734. + err = -ENOMEM;
  20735. + goto err_out;
  20736. + }
  20737. +
  20738. + SET_NETDEV_DEV(dev, &pdev->dev);
  20739. +
  20740. + ag = netdev_priv(dev);
  20741. + ag->pdev = pdev;
  20742. + ag->dev = dev;
  20743. + ag->msg_enable = netif_msg_init(ag71xx_msg_level,
  20744. + AG71XX_DEFAULT_MSG_ENABLE);
  20745. + spin_lock_init(&ag->lock);
  20746. +
  20747. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mac_base");
  20748. + if (!res) {
  20749. + dev_err(&pdev->dev, "no mac_base resource found\n");
  20750. + err = -ENXIO;
  20751. + goto err_out;
  20752. + }
  20753. +
  20754. + ag->mac_base = ioremap_nocache(res->start, res->end - res->start + 1);
  20755. + if (!ag->mac_base) {
  20756. + dev_err(&pdev->dev, "unable to ioremap mac_base\n");
  20757. + err = -ENOMEM;
  20758. + goto err_free_dev;
  20759. + }
  20760. +
  20761. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mii_ctrl");
  20762. + if (!res) {
  20763. + dev_err(&pdev->dev, "no mii_ctrl resource found\n");
  20764. + err = -ENXIO;
  20765. + goto err_unmap_base;
  20766. + }
  20767. +
  20768. + ag->mii_ctrl = ioremap_nocache(res->start, res->end - res->start + 1);
  20769. + if (!ag->mii_ctrl) {
  20770. + dev_err(&pdev->dev, "unable to ioremap mii_ctrl\n");
  20771. + err = -ENOMEM;
  20772. + goto err_unmap_base;
  20773. + }
  20774. +
  20775. + dev->irq = platform_get_irq(pdev, 0);
  20776. + err = request_irq(dev->irq, ag71xx_interrupt,
  20777. + IRQF_DISABLED,
  20778. + dev->name, dev);
  20779. + if (err) {
  20780. + dev_err(&pdev->dev, "unable to request IRQ %d\n", dev->irq);
  20781. + goto err_unmap_mii_ctrl;
  20782. + }
  20783. +
  20784. + dev->base_addr = (unsigned long)ag->mac_base;
  20785. + dev->netdev_ops = &ag71xx_netdev_ops;
  20786. + dev->ethtool_ops = &ag71xx_ethtool_ops;
  20787. +
  20788. + INIT_WORK(&ag->restart_work, ag71xx_restart_work_func);
  20789. +
  20790. + init_timer(&ag->oom_timer);
  20791. + ag->oom_timer.data = (unsigned long) dev;
  20792. + ag->oom_timer.function = ag71xx_oom_timer_handler;
  20793. +
  20794. + ag->tx_ring.size = AG71XX_TX_RING_SIZE_DEFAULT;
  20795. + ag->rx_ring.size = AG71XX_RX_RING_SIZE_DEFAULT;
  20796. +
  20797. + ag->stop_desc = dma_alloc_coherent(NULL,
  20798. + sizeof(struct ag71xx_desc), &ag->stop_desc_dma, GFP_KERNEL);
  20799. +
  20800. + if (!ag->stop_desc)
  20801. + goto err_free_irq;
  20802. +
  20803. + ag->stop_desc->data = 0;
  20804. + ag->stop_desc->ctrl = 0;
  20805. + ag->stop_desc->next = (u32) ag->stop_desc_dma;
  20806. +
  20807. + memcpy(dev->dev_addr, pdata->mac_addr, ETH_ALEN);
  20808. +
  20809. + netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
  20810. +
  20811. + err = register_netdev(dev);
  20812. + if (err) {
  20813. + dev_err(&pdev->dev, "unable to register net device\n");
  20814. + goto err_free_desc;
  20815. + }
  20816. +
  20817. + printk(KERN_INFO "%s: Atheros AG71xx at 0x%08lx, irq %d\n",
  20818. + dev->name, dev->base_addr, dev->irq);
  20819. +
  20820. + ag71xx_dump_regs(ag);
  20821. +
  20822. + ag71xx_hw_init(ag);
  20823. +
  20824. + ag71xx_dump_regs(ag);
  20825. +
  20826. + err = ag71xx_phy_connect(ag);
  20827. + if (err)
  20828. + goto err_unregister_netdev;
  20829. +
  20830. + err = ag71xx_debugfs_init(ag);
  20831. + if (err)
  20832. + goto err_phy_disconnect;
  20833. +
  20834. + platform_set_drvdata(pdev, dev);
  20835. +
  20836. + return 0;
  20837. +
  20838. +err_phy_disconnect:
  20839. + ag71xx_phy_disconnect(ag);
  20840. +err_unregister_netdev:
  20841. + unregister_netdev(dev);
  20842. +err_free_desc:
  20843. + dma_free_coherent(NULL, sizeof(struct ag71xx_desc), ag->stop_desc,
  20844. + ag->stop_desc_dma);
  20845. +err_free_irq:
  20846. + free_irq(dev->irq, dev);
  20847. +err_unmap_mii_ctrl:
  20848. + iounmap(ag->mii_ctrl);
  20849. +err_unmap_base:
  20850. + iounmap(ag->mac_base);
  20851. +err_free_dev:
  20852. + kfree(dev);
  20853. +err_out:
  20854. + platform_set_drvdata(pdev, NULL);
  20855. + return err;
  20856. +}
  20857. +
  20858. +static int __devexit ag71xx_remove(struct platform_device *pdev)
  20859. +{
  20860. + struct net_device *dev = platform_get_drvdata(pdev);
  20861. +
  20862. + if (dev) {
  20863. + struct ag71xx *ag = netdev_priv(dev);
  20864. +
  20865. + ag71xx_debugfs_exit(ag);
  20866. + ag71xx_phy_disconnect(ag);
  20867. + unregister_netdev(dev);
  20868. + free_irq(dev->irq, dev);
  20869. + iounmap(ag->mii_ctrl);
  20870. + iounmap(ag->mac_base);
  20871. + kfree(dev);
  20872. + platform_set_drvdata(pdev, NULL);
  20873. + }
  20874. +
  20875. + return 0;
  20876. +}
  20877. +
  20878. +static struct platform_driver ag71xx_driver = {
  20879. + .probe = ag71xx_probe,
  20880. + .remove = __exit_p(ag71xx_remove),
  20881. + .driver = {
  20882. + .name = AG71XX_DRV_NAME,
  20883. + }
  20884. +};
  20885. +
  20886. +static int __init ag71xx_module_init(void)
  20887. +{
  20888. + int ret;
  20889. +
  20890. + ret = ag71xx_debugfs_root_init();
  20891. + if (ret)
  20892. + goto err_out;
  20893. +
  20894. + ret = ag71xx_mdio_driver_init();
  20895. + if (ret)
  20896. + goto err_debugfs_exit;
  20897. +
  20898. + ret = platform_driver_register(&ag71xx_driver);
  20899. + if (ret)
  20900. + goto err_mdio_exit;
  20901. +
  20902. + return 0;
  20903. +
  20904. +err_mdio_exit:
  20905. + ag71xx_mdio_driver_exit();
  20906. +err_debugfs_exit:
  20907. + ag71xx_debugfs_root_exit();
  20908. +err_out:
  20909. + return ret;
  20910. +}
  20911. +
  20912. +static void __exit ag71xx_module_exit(void)
  20913. +{
  20914. + platform_driver_unregister(&ag71xx_driver);
  20915. + ag71xx_mdio_driver_exit();
  20916. + ag71xx_debugfs_root_exit();
  20917. +}
  20918. +
  20919. +module_init(ag71xx_module_init);
  20920. +module_exit(ag71xx_module_exit);
  20921. +
  20922. +MODULE_VERSION(AG71XX_DRV_VERSION);
  20923. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  20924. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  20925. +MODULE_LICENSE("GPL v2");
  20926. +MODULE_ALIAS("platform:" AG71XX_DRV_NAME);
  20927. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_mdio.c linux-2.6.39/drivers/net/ag71xx/ag71xx_mdio.c
  20928. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_mdio.c 1970-01-01 01:00:00.000000000 +0100
  20929. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_mdio.c 2011-04-27 12:19:22.257663952 +0200
  20930. @@ -0,0 +1,248 @@
  20931. +/*
  20932. + * Atheros AR71xx built-in ethernet mac driver
  20933. + *
  20934. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  20935. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  20936. + *
  20937. + * Based on Atheros' AG7100 driver
  20938. + *
  20939. + * This program is free software; you can redistribute it and/or modify it
  20940. + * under the terms of the GNU General Public License version 2 as published
  20941. + * by the Free Software Foundation.
  20942. + */
  20943. +
  20944. +#include "ag71xx.h"
  20945. +
  20946. +#define AG71XX_MDIO_RETRY 1000
  20947. +#define AG71XX_MDIO_DELAY 5
  20948. +
  20949. +static inline void ag71xx_mdio_wr(struct ag71xx_mdio *am, unsigned reg,
  20950. + u32 value)
  20951. +{
  20952. + void __iomem *r;
  20953. +
  20954. + r = am->mdio_base + reg;
  20955. + __raw_writel(value, r);
  20956. +
  20957. + /* flush write */
  20958. + (void) __raw_readl(r);
  20959. +}
  20960. +
  20961. +static inline u32 ag71xx_mdio_rr(struct ag71xx_mdio *am, unsigned reg)
  20962. +{
  20963. + return __raw_readl(am->mdio_base + reg);
  20964. +}
  20965. +
  20966. +static void ag71xx_mdio_dump_regs(struct ag71xx_mdio *am)
  20967. +{
  20968. + DBG("%s: mii_cfg=%08x, mii_cmd=%08x, mii_addr=%08x\n",
  20969. + am->mii_bus->name,
  20970. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CFG),
  20971. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CMD),
  20972. + ag71xx_mdio_rr(am, AG71XX_REG_MII_ADDR));
  20973. + DBG("%s: mii_ctrl=%08x, mii_status=%08x, mii_ind=%08x\n",
  20974. + am->mii_bus->name,
  20975. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CTRL),
  20976. + ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS),
  20977. + ag71xx_mdio_rr(am, AG71XX_REG_MII_IND));
  20978. +}
  20979. +
  20980. +int ag71xx_mdio_mii_read(struct ag71xx_mdio *am, int addr, int reg)
  20981. +{
  20982. + int ret;
  20983. + int i;
  20984. +
  20985. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  20986. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  20987. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  20988. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_READ);
  20989. +
  20990. + i = AG71XX_MDIO_RETRY;
  20991. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  20992. + if (i-- == 0) {
  20993. + printk(KERN_ERR "%s: mii_read timed out\n",
  20994. + am->mii_bus->name);
  20995. + ret = 0xffff;
  20996. + goto out;
  20997. + }
  20998. + udelay(AG71XX_MDIO_DELAY);
  20999. + }
  21000. +
  21001. + ret = ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS) & 0xffff;
  21002. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  21003. +
  21004. + DBG("mii_read: addr=%04x, reg=%04x, value=%04x\n", addr, reg, ret);
  21005. +
  21006. +out:
  21007. + return ret;
  21008. +}
  21009. +
  21010. +void ag71xx_mdio_mii_write(struct ag71xx_mdio *am, int addr, int reg, u16 val)
  21011. +{
  21012. + int i;
  21013. +
  21014. + DBG("mii_write: addr=%04x, reg=%04x, value=%04x\n", addr, reg, val);
  21015. +
  21016. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  21017. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  21018. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CTRL, val);
  21019. +
  21020. + i = AG71XX_MDIO_RETRY;
  21021. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  21022. + if (i-- == 0) {
  21023. + printk(KERN_ERR "%s: mii_write timed out\n",
  21024. + am->mii_bus->name);
  21025. + break;
  21026. + }
  21027. + udelay(AG71XX_MDIO_DELAY);
  21028. + }
  21029. +}
  21030. +
  21031. +static int ag71xx_mdio_reset(struct mii_bus *bus)
  21032. +{
  21033. + struct ag71xx_mdio *am = bus->priv;
  21034. + u32 t;
  21035. +
  21036. + if (am->pdata->is_ar7240)
  21037. + t = MII_CFG_CLK_DIV_6;
  21038. + else
  21039. + t = MII_CFG_CLK_DIV_28;
  21040. +
  21041. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t | MII_CFG_RESET);
  21042. + udelay(100);
  21043. +
  21044. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t);
  21045. + udelay(100);
  21046. +
  21047. + return 0;
  21048. +}
  21049. +
  21050. +static int ag71xx_mdio_read(struct mii_bus *bus, int addr, int reg)
  21051. +{
  21052. + struct ag71xx_mdio *am = bus->priv;
  21053. +
  21054. + if (am->pdata->is_ar7240)
  21055. + return ar7240sw_phy_read(bus, addr, reg);
  21056. + else
  21057. + return ag71xx_mdio_mii_read(am, addr, reg);
  21058. +}
  21059. +
  21060. +static int ag71xx_mdio_write(struct mii_bus *bus, int addr, int reg, u16 val)
  21061. +{
  21062. + struct ag71xx_mdio *am = bus->priv;
  21063. +
  21064. + if (am->pdata->is_ar7240)
  21065. + ar7240sw_phy_write(bus, addr, reg, val);
  21066. + else
  21067. + ag71xx_mdio_mii_write(am, addr, reg, val);
  21068. + return 0;
  21069. +}
  21070. +
  21071. +static int __devinit ag71xx_mdio_probe(struct platform_device *pdev)
  21072. +{
  21073. + struct ag71xx_mdio_platform_data *pdata;
  21074. + struct ag71xx_mdio *am;
  21075. + struct resource *res;
  21076. + int i;
  21077. + int err;
  21078. +
  21079. + pdata = pdev->dev.platform_data;
  21080. + if (!pdata) {
  21081. + dev_err(&pdev->dev, "no platform data specified\n");
  21082. + return -EINVAL;
  21083. + }
  21084. +
  21085. + am = kzalloc(sizeof(*am), GFP_KERNEL);
  21086. + if (!am) {
  21087. + err = -ENOMEM;
  21088. + goto err_out;
  21089. + }
  21090. +
  21091. + am->pdata = pdata;
  21092. +
  21093. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  21094. + if (!res) {
  21095. + dev_err(&pdev->dev, "no iomem resource found\n");
  21096. + err = -ENXIO;
  21097. + goto err_out;
  21098. + }
  21099. +
  21100. + am->mdio_base = ioremap_nocache(res->start, res->end - res->start + 1);
  21101. + if (!am->mdio_base) {
  21102. + dev_err(&pdev->dev, "unable to ioremap registers\n");
  21103. + err = -ENOMEM;
  21104. + goto err_free_mdio;
  21105. + }
  21106. +
  21107. + am->mii_bus = mdiobus_alloc();
  21108. + if (am->mii_bus == NULL) {
  21109. + err = -ENOMEM;
  21110. + goto err_iounmap;
  21111. + }
  21112. +
  21113. + am->mii_bus->name = "ag71xx_mdio";
  21114. + am->mii_bus->read = ag71xx_mdio_read;
  21115. + am->mii_bus->write = ag71xx_mdio_write;
  21116. + am->mii_bus->reset = ag71xx_mdio_reset;
  21117. + am->mii_bus->irq = am->mii_irq;
  21118. + am->mii_bus->priv = am;
  21119. + am->mii_bus->parent = &pdev->dev;
  21120. + snprintf(am->mii_bus->id, MII_BUS_ID_SIZE, "%s", dev_name(&pdev->dev));
  21121. + am->mii_bus->phy_mask = pdata->phy_mask;
  21122. +
  21123. + for (i = 0; i < PHY_MAX_ADDR; i++)
  21124. + am->mii_irq[i] = PHY_POLL;
  21125. +
  21126. + ag71xx_mdio_wr(am, AG71XX_REG_MAC_CFG1, 0);
  21127. +
  21128. + err = mdiobus_register(am->mii_bus);
  21129. + if (err)
  21130. + goto err_free_bus;
  21131. +
  21132. + ag71xx_mdio_dump_regs(am);
  21133. +
  21134. + platform_set_drvdata(pdev, am);
  21135. + return 0;
  21136. +
  21137. +err_free_bus:
  21138. + mdiobus_free(am->mii_bus);
  21139. +err_iounmap:
  21140. + iounmap(am->mdio_base);
  21141. +err_free_mdio:
  21142. + kfree(am);
  21143. +err_out:
  21144. + return err;
  21145. +}
  21146. +
  21147. +static int __devexit ag71xx_mdio_remove(struct platform_device *pdev)
  21148. +{
  21149. + struct ag71xx_mdio *am = platform_get_drvdata(pdev);
  21150. +
  21151. + if (am) {
  21152. + mdiobus_unregister(am->mii_bus);
  21153. + mdiobus_free(am->mii_bus);
  21154. + iounmap(am->mdio_base);
  21155. + kfree(am);
  21156. + platform_set_drvdata(pdev, NULL);
  21157. + }
  21158. +
  21159. + return 0;
  21160. +}
  21161. +
  21162. +static struct platform_driver ag71xx_mdio_driver = {
  21163. + .probe = ag71xx_mdio_probe,
  21164. + .remove = __exit_p(ag71xx_mdio_remove),
  21165. + .driver = {
  21166. + .name = "ag71xx-mdio",
  21167. + }
  21168. +};
  21169. +
  21170. +int __init ag71xx_mdio_driver_init(void)
  21171. +{
  21172. + return platform_driver_register(&ag71xx_mdio_driver);
  21173. +}
  21174. +
  21175. +void ag71xx_mdio_driver_exit(void)
  21176. +{
  21177. + platform_driver_unregister(&ag71xx_mdio_driver);
  21178. +}
  21179. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_phy.c linux-2.6.39/drivers/net/ag71xx/ag71xx_phy.c
  21180. --- linux-2.6.39.orig/drivers/net/ag71xx/ag71xx_phy.c 1970-01-01 01:00:00.000000000 +0100
  21181. +++ linux-2.6.39/drivers/net/ag71xx/ag71xx_phy.c 2011-08-06 09:32:37.298018216 +0200
  21182. @@ -0,0 +1,228 @@
  21183. +/*
  21184. + * Atheros AR71xx built-in ethernet mac driver
  21185. + *
  21186. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  21187. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  21188. + *
  21189. + * Based on Atheros' AG7100 driver
  21190. + *
  21191. + * This program is free software; you can redistribute it and/or modify it
  21192. + * under the terms of the GNU General Public License version 2 as published
  21193. + * by the Free Software Foundation.
  21194. + */
  21195. +
  21196. +#include "ag71xx.h"
  21197. +
  21198. +static void ag71xx_phy_link_adjust(struct net_device *dev)
  21199. +{
  21200. + struct ag71xx *ag = netdev_priv(dev);
  21201. + struct phy_device *phydev = ag->phy_dev;
  21202. + unsigned long flags;
  21203. + int status_change = 0;
  21204. +
  21205. + spin_lock_irqsave(&ag->lock, flags);
  21206. +
  21207. + if (phydev->link) {
  21208. + if (ag->duplex != phydev->duplex
  21209. + || ag->speed != phydev->speed) {
  21210. + status_change = 1;
  21211. + }
  21212. + }
  21213. +
  21214. + if (phydev->link != ag->link)
  21215. + status_change = 1;
  21216. +
  21217. + ag->link = phydev->link;
  21218. + ag->duplex = phydev->duplex;
  21219. + ag->speed = phydev->speed;
  21220. +
  21221. + if (status_change)
  21222. + ag71xx_link_adjust(ag);
  21223. +
  21224. + spin_unlock_irqrestore(&ag->lock, flags);
  21225. +}
  21226. +
  21227. +void ag71xx_phy_start(struct ag71xx *ag)
  21228. +{
  21229. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21230. +
  21231. + if (ag->phy_dev) {
  21232. + phy_start(ag->phy_dev);
  21233. + } else if (pdata->has_ar7240_switch) {
  21234. + ag71xx_ar7240_start(ag);
  21235. + } else {
  21236. + ag->link = 1;
  21237. + ag71xx_link_adjust(ag);
  21238. + }
  21239. +}
  21240. +
  21241. +void ag71xx_phy_stop(struct ag71xx *ag)
  21242. +{
  21243. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21244. +
  21245. + if (ag->phy_dev) {
  21246. + phy_stop(ag->phy_dev);
  21247. + } else {
  21248. + if (pdata->has_ar7240_switch)
  21249. + ag71xx_ar7240_stop(ag);
  21250. + ag->link = 0;
  21251. + ag71xx_link_adjust(ag);
  21252. + }
  21253. +}
  21254. +
  21255. +static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
  21256. +{
  21257. + struct net_device *dev = ag->dev;
  21258. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21259. + int ret = 0;
  21260. +
  21261. + /* use fixed settings */
  21262. + switch (pdata->speed) {
  21263. + case SPEED_10:
  21264. + case SPEED_100:
  21265. + case SPEED_1000:
  21266. + break;
  21267. + default:
  21268. + printk(KERN_ERR "%s: invalid speed specified\n", dev->name);
  21269. + ret = -EINVAL;
  21270. + break;
  21271. + }
  21272. +
  21273. + printk(KERN_DEBUG "%s: using fixed link parameters\n", dev->name);
  21274. +
  21275. + ag->duplex = pdata->duplex;
  21276. + ag->speed = pdata->speed;
  21277. +
  21278. + return ret;
  21279. +}
  21280. +
  21281. +static int ag71xx_phy_connect_multi(struct ag71xx *ag)
  21282. +{
  21283. + struct net_device *dev = ag->dev;
  21284. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21285. + struct phy_device *phydev = NULL;
  21286. + int phy_addr;
  21287. + int ret = 0;
  21288. +
  21289. + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
  21290. + if (!(pdata->phy_mask & (1 << phy_addr)))
  21291. + continue;
  21292. +
  21293. + if (ag->mii_bus->phy_map[phy_addr] == NULL)
  21294. + continue;
  21295. +
  21296. + DBG("%s: PHY found at %s, uid=%08x\n",
  21297. + dev->name,
  21298. + dev_name(&ag->mii_bus->phy_map[phy_addr]->dev),
  21299. + ag->mii_bus->phy_map[phy_addr]->phy_id);
  21300. +
  21301. + if (phydev == NULL)
  21302. + phydev = ag->mii_bus->phy_map[phy_addr];
  21303. + }
  21304. +
  21305. + if (!phydev) {
  21306. + printk(KERN_ERR "%s: no PHY found with phy_mask=%08x\n",
  21307. + dev->name, pdata->phy_mask);
  21308. + return -ENODEV;
  21309. + }
  21310. +
  21311. + ag->phy_dev = phy_connect(dev, dev_name(&phydev->dev),
  21312. + &ag71xx_phy_link_adjust, 0,
  21313. + pdata->phy_if_mode);
  21314. +
  21315. + if (IS_ERR(ag->phy_dev)) {
  21316. + printk(KERN_ERR "%s: could not connect to PHY at %s\n",
  21317. + dev->name, dev_name(&phydev->dev));
  21318. + return PTR_ERR(ag->phy_dev);
  21319. + }
  21320. +
  21321. + /* mask with MAC supported features */
  21322. + if (pdata->has_gbit)
  21323. + phydev->supported &= PHY_GBIT_FEATURES;
  21324. + else
  21325. + phydev->supported &= PHY_BASIC_FEATURES;
  21326. +
  21327. + phydev->advertising = phydev->supported;
  21328. +
  21329. + printk(KERN_DEBUG "%s: connected to PHY at %s [uid=%08x, driver=%s]\n",
  21330. + dev->name, dev_name(&phydev->dev),
  21331. + phydev->phy_id, phydev->drv->name);
  21332. +
  21333. + ag->link = 0;
  21334. + ag->speed = 0;
  21335. + ag->duplex = -1;
  21336. +
  21337. + return ret;
  21338. +}
  21339. +
  21340. +static int dev_is_class(struct device *dev, void *class)
  21341. +{
  21342. + if (dev->class != NULL && !strcmp(dev->class->name, class))
  21343. + return 1;
  21344. +
  21345. + return 0;
  21346. +}
  21347. +
  21348. +static struct device *dev_find_class(struct device *parent, char *class)
  21349. +{
  21350. + if (dev_is_class(parent, class)) {
  21351. + get_device(parent);
  21352. + return parent;
  21353. + }
  21354. +
  21355. + return device_find_child(parent, class, dev_is_class);
  21356. +}
  21357. +
  21358. +static struct mii_bus *dev_to_mii_bus(struct device *dev)
  21359. +{
  21360. + struct device *d;
  21361. +
  21362. + d = dev_find_class(dev, "mdio_bus");
  21363. + if (d != NULL) {
  21364. + struct mii_bus *bus;
  21365. +
  21366. + bus = to_mii_bus(d);
  21367. + put_device(d);
  21368. +
  21369. + return bus;
  21370. + }
  21371. +
  21372. + return NULL;
  21373. +}
  21374. +
  21375. +int __devinit ag71xx_phy_connect(struct ag71xx *ag)
  21376. +{
  21377. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21378. +
  21379. + ag->mii_bus = dev_to_mii_bus(pdata->mii_bus_dev);
  21380. + if (ag->mii_bus == NULL) {
  21381. + printk(KERN_ERR "%s: unable to find MII bus on device '%s'\n",
  21382. + ag->dev->name, dev_name(pdata->mii_bus_dev));
  21383. + return -ENODEV;
  21384. + }
  21385. +
  21386. + /* Reset the mdio bus explicitly */
  21387. + if (ag->mii_bus->reset) {
  21388. + mutex_lock(&ag->mii_bus->mdio_lock);
  21389. + ag->mii_bus->reset(ag->mii_bus);
  21390. + mutex_unlock(&ag->mii_bus->mdio_lock);
  21391. + }
  21392. +
  21393. + if (pdata->has_ar7240_switch)
  21394. + return ag71xx_ar7240_init(ag);
  21395. +
  21396. + if (pdata->phy_mask)
  21397. + return ag71xx_phy_connect_multi(ag);
  21398. +
  21399. + return ag71xx_phy_connect_fixed(ag);
  21400. +}
  21401. +
  21402. +void ag71xx_phy_disconnect(struct ag71xx *ag)
  21403. +{
  21404. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  21405. +
  21406. + if (pdata->has_ar7240_switch)
  21407. + ag71xx_ar7240_cleanup(ag);
  21408. + else if (ag->phy_dev)
  21409. + phy_disconnect(ag->phy_dev);
  21410. +}
  21411. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/Kconfig linux-2.6.39/drivers/net/ag71xx/Kconfig
  21412. --- linux-2.6.39.orig/drivers/net/ag71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  21413. +++ linux-2.6.39/drivers/net/ag71xx/Kconfig 2011-04-27 12:19:22.247664026 +0200
  21414. @@ -0,0 +1,33 @@
  21415. +config AG71XX
  21416. + tristate "Atheros AR71xx built-in ethernet mac support"
  21417. + depends on ATHEROS_AR71XX
  21418. + select PHYLIB
  21419. + help
  21420. + If you wish to compile a kernel for AR71xx/91xx and enable
  21421. + ethernet support, then you should always answer Y to this.
  21422. +
  21423. +if AG71XX
  21424. +
  21425. +config AG71XX_DEBUG
  21426. + bool "Atheros AR71xx built-in ethernet driver debugging"
  21427. + default n
  21428. + help
  21429. + Atheros AR71xx built-in ethernet driver debugging messages.
  21430. +
  21431. +config AG71XX_DEBUG_FS
  21432. + bool "Atheros AR71xx built-in ethernet driver debugfs support"
  21433. + depends on DEBUG_FS
  21434. + default n
  21435. + help
  21436. + Say Y, if you need access to various statistics provided by
  21437. + the ag71xx driver.
  21438. +
  21439. +config AG71XX_AR8216_SUPPORT
  21440. + bool "special support for the Atheros AR8216 switch"
  21441. + default n
  21442. + default y if AR71XX_MACH_WNR2000 || AR71XX_MACH_MZK_W04NU
  21443. + help
  21444. + Say 'y' here if you want to enable special support for the
  21445. + Atheros AR8216 switch found on some boards.
  21446. +
  21447. +endif
  21448. diff -Nur linux-2.6.39.orig/drivers/net/ag71xx/Makefile linux-2.6.39/drivers/net/ag71xx/Makefile
  21449. --- linux-2.6.39.orig/drivers/net/ag71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  21450. +++ linux-2.6.39/drivers/net/ag71xx/Makefile 2011-04-27 12:19:22.257663952 +0200
  21451. @@ -0,0 +1,15 @@
  21452. +#
  21453. +# Makefile for the Atheros AR71xx built-in ethernet macs
  21454. +#
  21455. +
  21456. +ag71xx-y += ag71xx_main.o
  21457. +ag71xx-y += ag71xx_ethtool.o
  21458. +ag71xx-y += ag71xx_phy.o
  21459. +ag71xx-y += ag71xx_mdio.o
  21460. +ag71xx-y += ag71xx_ar7240.o
  21461. +
  21462. +ag71xx-$(CONFIG_AG71XX_DEBUG_FS) += ag71xx_debugfs.o
  21463. +ag71xx-$(CONFIG_AG71XX_AR8216_SUPPORT) += ag71xx_ar8216.o
  21464. +
  21465. +obj-$(CONFIG_AG71XX) += ag71xx.o
  21466. +
  21467. diff -Nur linux-2.6.39.orig/drivers/net/Kconfig linux-2.6.39/drivers/net/Kconfig
  21468. --- linux-2.6.39.orig/drivers/net/Kconfig 2011-05-19 06:06:34.000000000 +0200
  21469. +++ linux-2.6.39/drivers/net/Kconfig 2011-08-22 16:21:54.787979739 +0200
  21470. @@ -2071,6 +2071,8 @@
  21471. The safe and default value for this is N.
  21472. +source drivers/net/ag71xx/Kconfig
  21473. +
  21474. config DL2K
  21475. tristate "DL2000/TC902x-based Gigabit Ethernet support"
  21476. depends on PCI
  21477. diff -Nur linux-2.6.39.orig/drivers/net/Makefile linux-2.6.39/drivers/net/Makefile
  21478. --- linux-2.6.39.orig/drivers/net/Makefile 2011-05-19 06:06:34.000000000 +0200
  21479. +++ linux-2.6.39/drivers/net/Makefile 2011-08-22 16:21:54.797980120 +0200
  21480. @@ -112,6 +112,7 @@
  21481. # end link order section
  21482. #
  21483. +obj-$(CONFIG_AG71XX) += ag71xx/
  21484. obj-$(CONFIG_SUNDANCE) += sundance.o
  21485. obj-$(CONFIG_HAMACHI) += hamachi.o
  21486. obj-$(CONFIG_NET) += Space.o loopback.o
  21487. diff -Nur linux-2.6.39.orig/drivers/net/phy/Kconfig linux-2.6.39/drivers/net/phy/Kconfig
  21488. --- linux-2.6.39.orig/drivers/net/phy/Kconfig 2011-05-19 06:06:34.000000000 +0200
  21489. +++ linux-2.6.39/drivers/net/phy/Kconfig 2011-08-22 22:19:34.339230055 +0200
  21490. @@ -13,6 +13,12 @@
  21491. if PHYLIB
  21492. +config SWCONFIG
  21493. + tristate "Switch configuration API"
  21494. + ---help---
  21495. + Switch configuration API using netlink. This allows
  21496. + you to configure the VLAN features of certain switches.
  21497. +
  21498. comment "MII PHY device drivers"
  21499. config MARVELL_PHY
  21500. diff -Nur linux-2.6.39.orig/drivers/net/phy/Makefile linux-2.6.39/drivers/net/phy/Makefile
  21501. --- linux-2.6.39.orig/drivers/net/phy/Makefile 2011-05-19 06:06:34.000000000 +0200
  21502. +++ linux-2.6.39/drivers/net/phy/Makefile 2011-08-22 22:19:34.339230055 +0200
  21503. @@ -3,6 +3,7 @@
  21504. libphy-objs := phy.o phy_device.o mdio_bus.o
  21505. obj-$(CONFIG_PHYLIB) += libphy.o
  21506. +obj-$(CONFIG_SWCONFIG) += swconfig.o
  21507. obj-$(CONFIG_MARVELL_PHY) += marvell.o
  21508. obj-$(CONFIG_DAVICOM_PHY) += davicom.o
  21509. obj-$(CONFIG_CICADA_PHY) += cicada.o
  21510. diff -Nur linux-2.6.39.orig/drivers/net/phy/micrel.c linux-2.6.39/drivers/net/phy/micrel.c
  21511. --- linux-2.6.39.orig/drivers/net/phy/micrel.c 2011-05-19 06:06:34.000000000 +0200
  21512. +++ linux-2.6.39/drivers/net/phy/micrel.c 2011-04-27 12:19:22.257663952 +0200
  21513. @@ -1,251 +1,82 @@
  21514. /*
  21515. - * drivers/net/phy/micrel.c
  21516. + * Driver for Micrel/Kendin PHYs
  21517. *
  21518. - * Driver for Micrel PHYs
  21519. + * Copyright (c) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  21520. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  21521. *
  21522. - * Author: David J. Choi
  21523. + * This program is free software; you can redistribute it and/or modify it
  21524. + * under the terms of the GNU General Public License version 2 as published
  21525. + * by the Free Software Foundation.
  21526. *
  21527. - * Copyright (c) 2010 Micrel, Inc.
  21528. - *
  21529. - * This program is free software; you can redistribute it and/or modify it
  21530. - * under the terms of the GNU General Public License as published by the
  21531. - * Free Software Foundation; either version 2 of the License, or (at your
  21532. - * option) any later version.
  21533. - *
  21534. - * Support : ksz9021 1000/100/10 phy from Micrel
  21535. - * ks8001, ks8737, ks8721, ks8041, ks8051 100/10 phy
  21536. */
  21537. -#include <linux/kernel.h>
  21538. -#include <linux/module.h>
  21539. +#include <linux/delay.h>
  21540. +#include <linux/skbuff.h>
  21541. #include <linux/phy.h>
  21542. -#include <linux/micrel_phy.h>
  21543. -/* general Interrupt control/status reg in vendor specific block. */
  21544. -#define MII_KSZPHY_INTCS 0x1B
  21545. -#define KSZPHY_INTCS_JABBER (1 << 15)
  21546. -#define KSZPHY_INTCS_RECEIVE_ERR (1 << 14)
  21547. -#define KSZPHY_INTCS_PAGE_RECEIVE (1 << 13)
  21548. -#define KSZPHY_INTCS_PARELLEL (1 << 12)
  21549. -#define KSZPHY_INTCS_LINK_PARTNER_ACK (1 << 11)
  21550. -#define KSZPHY_INTCS_LINK_DOWN (1 << 10)
  21551. -#define KSZPHY_INTCS_REMOTE_FAULT (1 << 9)
  21552. -#define KSZPHY_INTCS_LINK_UP (1 << 8)
  21553. -#define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\
  21554. - KSZPHY_INTCS_LINK_DOWN)
  21555. -
  21556. -/* general PHY control reg in vendor specific block. */
  21557. -#define MII_KSZPHY_CTRL 0x1F
  21558. -/* bitmap of PHY register to set interrupt mode */
  21559. -#define KSZPHY_CTRL_INT_ACTIVE_HIGH (1 << 9)
  21560. -#define KSZ9021_CTRL_INT_ACTIVE_HIGH (1 << 14)
  21561. -#define KS8737_CTRL_INT_ACTIVE_HIGH (1 << 14)
  21562. -#define KSZ8051_RMII_50MHZ_CLK (1 << 7)
  21563. +#define KSZ_REG_INT_CTRL 0x1b
  21564. -static int kszphy_ack_interrupt(struct phy_device *phydev)
  21565. -{
  21566. - /* bit[7..0] int status, which is a read and clear register. */
  21567. - int rc;
  21568. +#define KSZ_INT_LU_EN (1 << 8) /* enable Link Up interrupt */
  21569. +#define KSZ_INT_RF_EN (1 << 9) /* enable Remote Fault interrupt */
  21570. +#define KSZ_INT_LD_EN (1 << 10) /* enable Link Down interrupt */
  21571. - rc = phy_read(phydev, MII_KSZPHY_INTCS);
  21572. -
  21573. - return (rc < 0) ? rc : 0;
  21574. -}
  21575. +#define KSZ_INT_INIT (KSZ_INT_LU_EN | KSZ_INT_LD_EN)
  21576. -static int kszphy_set_interrupt(struct phy_device *phydev)
  21577. +static int ksz8041_ack_interrupt(struct phy_device *phydev)
  21578. {
  21579. - int temp;
  21580. - temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
  21581. - KSZPHY_INTCS_ALL : 0;
  21582. - return phy_write(phydev, MII_KSZPHY_INTCS, temp);
  21583. -}
  21584. + int err;
  21585. -static int kszphy_config_intr(struct phy_device *phydev)
  21586. -{
  21587. - int temp, rc;
  21588. + err = phy_read(phydev, KSZ_REG_INT_CTRL);
  21589. - /* set the interrupt pin active low */
  21590. - temp = phy_read(phydev, MII_KSZPHY_CTRL);
  21591. - temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH;
  21592. - phy_write(phydev, MII_KSZPHY_CTRL, temp);
  21593. - rc = kszphy_set_interrupt(phydev);
  21594. - return rc < 0 ? rc : 0;
  21595. + return (err < 0) ? err : 0;
  21596. }
  21597. -static int ksz9021_config_intr(struct phy_device *phydev)
  21598. +static int ksz8041_config_intr(struct phy_device *phydev)
  21599. {
  21600. - int temp, rc;
  21601. + int err;
  21602. - /* set the interrupt pin active low */
  21603. - temp = phy_read(phydev, MII_KSZPHY_CTRL);
  21604. - temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH;
  21605. - phy_write(phydev, MII_KSZPHY_CTRL, temp);
  21606. - rc = kszphy_set_interrupt(phydev);
  21607. - return rc < 0 ? rc : 0;
  21608. -}
  21609. -
  21610. -static int ks8737_config_intr(struct phy_device *phydev)
  21611. -{
  21612. - int temp, rc;
  21613. + if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  21614. + err = phy_write(phydev, KSZ_REG_INT_CTRL,
  21615. + KSZ_INT_INIT);
  21616. + else
  21617. + err = phy_write(phydev, KSZ_REG_INT_CTRL, 0);
  21618. - /* set the interrupt pin active low */
  21619. - temp = phy_read(phydev, MII_KSZPHY_CTRL);
  21620. - temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH;
  21621. - phy_write(phydev, MII_KSZPHY_CTRL, temp);
  21622. - rc = kszphy_set_interrupt(phydev);
  21623. - return rc < 0 ? rc : 0;
  21624. + return err;
  21625. }
  21626. -static int kszphy_config_init(struct phy_device *phydev)
  21627. -{
  21628. - return 0;
  21629. -}
  21630. -
  21631. -static int ks8051_config_init(struct phy_device *phydev)
  21632. -{
  21633. - int regval;
  21634. -
  21635. - if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
  21636. - regval = phy_read(phydev, MII_KSZPHY_CTRL);
  21637. - regval |= KSZ8051_RMII_50MHZ_CLK;
  21638. - phy_write(phydev, MII_KSZPHY_CTRL, regval);
  21639. - }
  21640. -
  21641. - return 0;
  21642. -}
  21643. -
  21644. -static struct phy_driver ks8737_driver = {
  21645. - .phy_id = PHY_ID_KS8737,
  21646. - .phy_id_mask = 0x00fffff0,
  21647. - .name = "Micrel KS8737",
  21648. - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  21649. - .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  21650. - .config_init = kszphy_config_init,
  21651. +static struct phy_driver ksz8041_phy_driver = {
  21652. + .phy_id = 0x00221512,
  21653. + .name = "Micrel KSZ8041",
  21654. + .phy_id_mask = 0x001fffff,
  21655. + .features = PHY_BASIC_FEATURES,
  21656. + .flags = PHY_HAS_INTERRUPT,
  21657. .config_aneg = genphy_config_aneg,
  21658. .read_status = genphy_read_status,
  21659. - .ack_interrupt = kszphy_ack_interrupt,
  21660. - .config_intr = ks8737_config_intr,
  21661. - .driver = { .owner = THIS_MODULE,},
  21662. + .ack_interrupt = ksz8041_ack_interrupt,
  21663. + .config_intr = ksz8041_config_intr,
  21664. + .driver = {
  21665. + .owner = THIS_MODULE,
  21666. + },
  21667. };
  21668. -static struct phy_driver ks8041_driver = {
  21669. - .phy_id = PHY_ID_KS8041,
  21670. - .phy_id_mask = 0x00fffff0,
  21671. - .name = "Micrel KS8041",
  21672. - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  21673. - | SUPPORTED_Asym_Pause),
  21674. - .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  21675. - .config_init = kszphy_config_init,
  21676. - .config_aneg = genphy_config_aneg,
  21677. - .read_status = genphy_read_status,
  21678. - .ack_interrupt = kszphy_ack_interrupt,
  21679. - .config_intr = kszphy_config_intr,
  21680. - .driver = { .owner = THIS_MODULE,},
  21681. -};
  21682. -
  21683. -static struct phy_driver ks8051_driver = {
  21684. - .phy_id = PHY_ID_KS8051,
  21685. - .phy_id_mask = 0x00fffff0,
  21686. - .name = "Micrel KS8051",
  21687. - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
  21688. - | SUPPORTED_Asym_Pause),
  21689. - .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  21690. - .config_init = ks8051_config_init,
  21691. - .config_aneg = genphy_config_aneg,
  21692. - .read_status = genphy_read_status,
  21693. - .ack_interrupt = kszphy_ack_interrupt,
  21694. - .config_intr = kszphy_config_intr,
  21695. - .driver = { .owner = THIS_MODULE,},
  21696. -};
  21697. -
  21698. -static struct phy_driver ks8001_driver = {
  21699. - .phy_id = PHY_ID_KS8001,
  21700. - .name = "Micrel KS8001 or KS8721",
  21701. - .phy_id_mask = 0x00fffff0,
  21702. - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
  21703. - .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  21704. - .config_init = kszphy_config_init,
  21705. - .config_aneg = genphy_config_aneg,
  21706. - .read_status = genphy_read_status,
  21707. - .ack_interrupt = kszphy_ack_interrupt,
  21708. - .config_intr = kszphy_config_intr,
  21709. - .driver = { .owner = THIS_MODULE,},
  21710. -};
  21711. -
  21712. -static struct phy_driver ksz9021_driver = {
  21713. - .phy_id = PHY_ID_KSZ9021,
  21714. - .phy_id_mask = 0x000fff10,
  21715. - .name = "Micrel KSZ9021 Gigabit PHY",
  21716. - .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause
  21717. - | SUPPORTED_Asym_Pause),
  21718. - .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  21719. - .config_init = kszphy_config_init,
  21720. - .config_aneg = genphy_config_aneg,
  21721. - .read_status = genphy_read_status,
  21722. - .ack_interrupt = kszphy_ack_interrupt,
  21723. - .config_intr = ksz9021_config_intr,
  21724. - .driver = { .owner = THIS_MODULE, },
  21725. -};
  21726. -
  21727. -static int __init ksphy_init(void)
  21728. +static int __init micrel_phy_init(void)
  21729. {
  21730. - int ret;
  21731. -
  21732. - ret = phy_driver_register(&ks8001_driver);
  21733. - if (ret)
  21734. - goto err1;
  21735. -
  21736. - ret = phy_driver_register(&ksz9021_driver);
  21737. - if (ret)
  21738. - goto err2;
  21739. -
  21740. - ret = phy_driver_register(&ks8737_driver);
  21741. - if (ret)
  21742. - goto err3;
  21743. - ret = phy_driver_register(&ks8041_driver);
  21744. - if (ret)
  21745. - goto err4;
  21746. - ret = phy_driver_register(&ks8051_driver);
  21747. - if (ret)
  21748. - goto err5;
  21749. -
  21750. - return 0;
  21751. -
  21752. -err5:
  21753. - phy_driver_unregister(&ks8041_driver);
  21754. -err4:
  21755. - phy_driver_unregister(&ks8737_driver);
  21756. -err3:
  21757. - phy_driver_unregister(&ksz9021_driver);
  21758. -err2:
  21759. - phy_driver_unregister(&ks8001_driver);
  21760. -err1:
  21761. - return ret;
  21762. + return phy_driver_register(&ksz8041_phy_driver);
  21763. }
  21764. -static void __exit ksphy_exit(void)
  21765. +static void __exit micrel_phy_exit(void)
  21766. {
  21767. - phy_driver_unregister(&ks8001_driver);
  21768. - phy_driver_unregister(&ks8737_driver);
  21769. - phy_driver_unregister(&ksz9021_driver);
  21770. - phy_driver_unregister(&ks8041_driver);
  21771. - phy_driver_unregister(&ks8051_driver);
  21772. + phy_driver_unregister(&ksz8041_phy_driver);
  21773. }
  21774. -module_init(ksphy_init);
  21775. -module_exit(ksphy_exit);
  21776. -
  21777. -MODULE_DESCRIPTION("Micrel PHY driver");
  21778. -MODULE_AUTHOR("David J. Choi");
  21779. -MODULE_LICENSE("GPL");
  21780. -
  21781. -static struct mdio_device_id __maybe_unused micrel_tbl[] = {
  21782. - { PHY_ID_KSZ9021, 0x000fff10 },
  21783. - { PHY_ID_KS8001, 0x00fffff0 },
  21784. - { PHY_ID_KS8737, 0x00fffff0 },
  21785. - { PHY_ID_KS8041, 0x00fffff0 },
  21786. - { PHY_ID_KS8051, 0x00fffff0 },
  21787. - { }
  21788. -};
  21789. +#ifdef MODULE
  21790. +module_init(micrel_phy_init);
  21791. +module_exit(micrel_phy_exit);
  21792. +#else
  21793. +subsys_initcall(micrel_phy_init);
  21794. +#endif
  21795. -MODULE_DEVICE_TABLE(mdio, micrel_tbl);
  21796. +MODULE_DESCRIPTION("Micrel/Kendin PHY driver");
  21797. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  21798. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  21799. +MODULE_LICENSE("GPL v2");
  21800. diff -Nur linux-2.6.39.orig/drivers/net/phy/phy.c linux-2.6.39/drivers/net/phy/phy.c
  21801. --- linux-2.6.39.orig/drivers/net/phy/phy.c 2011-05-19 06:06:34.000000000 +0200
  21802. +++ linux-2.6.39/drivers/net/phy/phy.c 2011-08-22 22:00:02.067980292 +0200
  21803. @@ -297,6 +297,50 @@
  21804. }
  21805. EXPORT_SYMBOL(phy_ethtool_gset);
  21806. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
  21807. +{
  21808. + u32 cmd;
  21809. + int tmp;
  21810. + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  21811. + struct ethtool_value edata = { ETHTOOL_GLINK };
  21812. +
  21813. + if (get_user(cmd, (u32 *) useraddr))
  21814. + return -EFAULT;
  21815. +
  21816. + switch (cmd) {
  21817. + case ETHTOOL_GSET:
  21818. + phy_ethtool_gset(phydev, &ecmd);
  21819. + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  21820. + return -EFAULT;
  21821. + return 0;
  21822. +
  21823. + case ETHTOOL_SSET:
  21824. + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  21825. + return -EFAULT;
  21826. + return phy_ethtool_sset(phydev, &ecmd);
  21827. +
  21828. + case ETHTOOL_NWAY_RST:
  21829. + /* if autoneg is off, it's an error */
  21830. + tmp = phy_read(phydev, MII_BMCR);
  21831. + if (tmp & BMCR_ANENABLE) {
  21832. + tmp |= (BMCR_ANRESTART);
  21833. + phy_write(phydev, MII_BMCR, tmp);
  21834. + return 0;
  21835. + }
  21836. + return -EINVAL;
  21837. +
  21838. + case ETHTOOL_GLINK:
  21839. + edata.data = (phy_read(phydev,
  21840. + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
  21841. + if (copy_to_user(useraddr, &edata, sizeof(edata)))
  21842. + return -EFAULT;
  21843. + return 0;
  21844. + }
  21845. +
  21846. + return -EOPNOTSUPP;
  21847. +}
  21848. +EXPORT_SYMBOL(phy_ethtool_ioctl);
  21849. +
  21850. /**
  21851. * phy_mii_ioctl - generic PHY MII ioctl interface
  21852. * @phydev: the phy_device struct
  21853. @@ -472,7 +516,7 @@
  21854. int idx;
  21855. idx = phy_find_setting(phydev->speed, phydev->duplex);
  21856. -
  21857. +
  21858. idx++;
  21859. idx = phy_find_valid(idx, phydev->supported);
  21860. diff -Nur linux-2.6.39.orig/drivers/net/phy/phy_device.c linux-2.6.39/drivers/net/phy/phy_device.c
  21861. --- linux-2.6.39.orig/drivers/net/phy/phy_device.c 2011-05-19 06:06:34.000000000 +0200
  21862. +++ linux-2.6.39/drivers/net/phy/phy_device.c 2011-08-22 22:00:06.817981347 +0200
  21863. @@ -149,6 +149,18 @@
  21864. }
  21865. EXPORT_SYMBOL(phy_scan_fixups);
  21866. +static int generic_receive_skb(struct sk_buff *skb)
  21867. +{
  21868. + skb->protocol = eth_type_trans(skb, skb->dev);
  21869. + return netif_receive_skb(skb);
  21870. +}
  21871. +
  21872. +static int generic_rx(struct sk_buff *skb)
  21873. +{
  21874. + skb->protocol = eth_type_trans(skb, skb->dev);
  21875. + return netif_rx(skb);
  21876. +}
  21877. +
  21878. static struct phy_device* phy_device_create(struct mii_bus *bus,
  21879. int addr, int phy_id)
  21880. {
  21881. @@ -180,6 +192,8 @@
  21882. dev_set_name(&dev->dev, PHY_ID_FMT, bus->id, addr);
  21883. dev->state = PHY_DOWN;
  21884. + dev->netif_receive_skb = &generic_receive_skb;
  21885. + dev->netif_rx = &generic_rx;
  21886. mutex_init(&dev->lock);
  21887. INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
  21888. diff -Nur linux-2.6.39.orig/drivers/net/phy/swconfig.c linux-2.6.39/drivers/net/phy/swconfig.c
  21889. --- linux-2.6.39.orig/drivers/net/phy/swconfig.c 1970-01-01 01:00:00.000000000 +0100
  21890. +++ linux-2.6.39/drivers/net/phy/swconfig.c 2011-08-22 22:18:58.887990974 +0200
  21891. @@ -0,0 +1,954 @@
  21892. +/*
  21893. + * swconfig.c: Switch configuration API
  21894. + *
  21895. + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  21896. + *
  21897. + * This program is free software; you can redistribute it and/or
  21898. + * modify it under the terms of the GNU General Public License
  21899. + * as published by the Free Software Foundation; either version 2
  21900. + * of the License, or (at your option) any later version.
  21901. + *
  21902. + * This program is distributed in the hope that it will be useful,
  21903. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21904. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21905. + * GNU General Public License for more details.
  21906. + */
  21907. +
  21908. +#include <linux/types.h>
  21909. +#include <linux/module.h>
  21910. +#include <linux/init.h>
  21911. +#include <linux/list.h>
  21912. +#include <linux/if.h>
  21913. +#include <linux/if_ether.h>
  21914. +#include <linux/capability.h>
  21915. +#include <linux/skbuff.h>
  21916. +#include <linux/switch.h>
  21917. +
  21918. +//#define DEBUG 1
  21919. +#ifdef DEBUG
  21920. +#define DPRINTF(format, ...) printk("%s: " format, __func__, ##__VA_ARGS__)
  21921. +#else
  21922. +#define DPRINTF(...) do {} while(0)
  21923. +#endif
  21924. +
  21925. +#define SWCONFIG_DEVNAME "switch%d"
  21926. +
  21927. +MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
  21928. +MODULE_LICENSE("GPL");
  21929. +
  21930. +static int swdev_id = 0;
  21931. +static struct list_head swdevs;
  21932. +static DEFINE_SPINLOCK(swdevs_lock);
  21933. +struct swconfig_callback;
  21934. +
  21935. +struct swconfig_callback
  21936. +{
  21937. + struct sk_buff *msg;
  21938. + struct genlmsghdr *hdr;
  21939. + struct genl_info *info;
  21940. + int cmd;
  21941. +
  21942. + /* callback for filling in the message data */
  21943. + int (*fill)(struct swconfig_callback *cb, void *arg);
  21944. +
  21945. + /* callback for closing the message before sending it */
  21946. + int (*close)(struct swconfig_callback *cb, void *arg);
  21947. +
  21948. + struct nlattr *nest[4];
  21949. + int args[4];
  21950. +};
  21951. +
  21952. +/* defaults */
  21953. +
  21954. +static int
  21955. +swconfig_get_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  21956. +{
  21957. + int ret;
  21958. + if (val->port_vlan >= dev->vlans)
  21959. + return -EINVAL;
  21960. +
  21961. + if (!dev->ops->get_vlan_ports)
  21962. + return -EOPNOTSUPP;
  21963. +
  21964. + ret = dev->ops->get_vlan_ports(dev, val);
  21965. + return ret;
  21966. +}
  21967. +
  21968. +static int
  21969. +swconfig_set_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  21970. +{
  21971. + struct switch_port *ports = val->value.ports;
  21972. + const struct switch_dev_ops *ops = dev->ops;
  21973. + int i;
  21974. +
  21975. + if (val->port_vlan >= dev->vlans)
  21976. + return -EINVAL;
  21977. +
  21978. + /* validate ports */
  21979. + if (val->len > dev->ports)
  21980. + return -EINVAL;
  21981. +
  21982. + if (!ops->set_vlan_ports)
  21983. + return -EOPNOTSUPP;
  21984. +
  21985. + for (i = 0; i < val->len; i++) {
  21986. + if (ports[i].id >= dev->ports)
  21987. + return -EINVAL;
  21988. +
  21989. + if (ops->set_port_pvid &&
  21990. + !(ports[i].flags & (1 << SWITCH_PORT_FLAG_TAGGED)))
  21991. + ops->set_port_pvid(dev, ports[i].id, val->port_vlan);
  21992. + }
  21993. +
  21994. + return ops->set_vlan_ports(dev, val);
  21995. +}
  21996. +
  21997. +static int
  21998. +swconfig_set_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  21999. +{
  22000. + if (val->port_vlan >= dev->ports)
  22001. + return -EINVAL;
  22002. +
  22003. + if (!dev->ops->set_port_pvid)
  22004. + return -EOPNOTSUPP;
  22005. +
  22006. + return dev->ops->set_port_pvid(dev, val->port_vlan, val->value.i);
  22007. +}
  22008. +
  22009. +static int
  22010. +swconfig_get_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  22011. +{
  22012. + if (val->port_vlan >= dev->ports)
  22013. + return -EINVAL;
  22014. +
  22015. + if (!dev->ops->get_port_pvid)
  22016. + return -EOPNOTSUPP;
  22017. +
  22018. + return dev->ops->get_port_pvid(dev, val->port_vlan, &val->value.i);
  22019. +}
  22020. +
  22021. +static int
  22022. +swconfig_apply_config(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  22023. +{
  22024. + /* don't complain if not supported by the switch driver */
  22025. + if (!dev->ops->apply_config)
  22026. + return 0;
  22027. +
  22028. + return dev->ops->apply_config(dev);
  22029. +}
  22030. +
  22031. +static int
  22032. +swconfig_reset_switch(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
  22033. +{
  22034. + /* don't complain if not supported by the switch driver */
  22035. + if (!dev->ops->reset_switch)
  22036. + return 0;
  22037. +
  22038. + return dev->ops->reset_switch(dev);
  22039. +}
  22040. +
  22041. +enum global_defaults {
  22042. + GLOBAL_APPLY,
  22043. + GLOBAL_RESET,
  22044. +};
  22045. +
  22046. +enum vlan_defaults {
  22047. + VLAN_PORTS,
  22048. +};
  22049. +
  22050. +enum port_defaults {
  22051. + PORT_PVID,
  22052. +};
  22053. +
  22054. +static struct switch_attr default_global[] = {
  22055. + [GLOBAL_APPLY] = {
  22056. + .type = SWITCH_TYPE_NOVAL,
  22057. + .name = "apply",
  22058. + .description = "Activate changes in the hardware",
  22059. + .set = swconfig_apply_config,
  22060. + },
  22061. + [GLOBAL_RESET] = {
  22062. + .type = SWITCH_TYPE_NOVAL,
  22063. + .name = "reset",
  22064. + .description = "Reset the switch",
  22065. + .set = swconfig_reset_switch,
  22066. + }
  22067. +};
  22068. +
  22069. +static struct switch_attr default_port[] = {
  22070. + [PORT_PVID] = {
  22071. + .type = SWITCH_TYPE_INT,
  22072. + .name = "pvid",
  22073. + .description = "Primary VLAN ID",
  22074. + .set = swconfig_set_pvid,
  22075. + .get = swconfig_get_pvid,
  22076. + }
  22077. +};
  22078. +
  22079. +static struct switch_attr default_vlan[] = {
  22080. + [VLAN_PORTS] = {
  22081. + .type = SWITCH_TYPE_PORTS,
  22082. + .name = "ports",
  22083. + .description = "VLAN port mapping",
  22084. + .set = swconfig_set_vlan_ports,
  22085. + .get = swconfig_get_vlan_ports,
  22086. + },
  22087. +};
  22088. +
  22089. +
  22090. +static void swconfig_defaults_init(struct switch_dev *dev)
  22091. +{
  22092. + const struct switch_dev_ops *ops = dev->ops;
  22093. +
  22094. + dev->def_global = 0;
  22095. + dev->def_vlan = 0;
  22096. + dev->def_port = 0;
  22097. +
  22098. + if (ops->get_vlan_ports || ops->set_vlan_ports)
  22099. + set_bit(VLAN_PORTS, &dev->def_vlan);
  22100. +
  22101. + if (ops->get_port_pvid || ops->set_port_pvid)
  22102. + set_bit(PORT_PVID, &dev->def_port);
  22103. +
  22104. + /* always present, can be no-op */
  22105. + set_bit(GLOBAL_APPLY, &dev->def_global);
  22106. + set_bit(GLOBAL_RESET, &dev->def_global);
  22107. +}
  22108. +
  22109. +
  22110. +static struct genl_family switch_fam = {
  22111. + .id = GENL_ID_GENERATE,
  22112. + .name = "switch",
  22113. + .hdrsize = 0,
  22114. + .version = 1,
  22115. + .maxattr = SWITCH_ATTR_MAX,
  22116. +};
  22117. +
  22118. +static const struct nla_policy switch_policy[SWITCH_ATTR_MAX+1] = {
  22119. + [SWITCH_ATTR_ID] = { .type = NLA_U32 },
  22120. + [SWITCH_ATTR_OP_ID] = { .type = NLA_U32 },
  22121. + [SWITCH_ATTR_OP_PORT] = { .type = NLA_U32 },
  22122. + [SWITCH_ATTR_OP_VLAN] = { .type = NLA_U32 },
  22123. + [SWITCH_ATTR_OP_VALUE_INT] = { .type = NLA_U32 },
  22124. + [SWITCH_ATTR_OP_VALUE_STR] = { .type = NLA_NUL_STRING },
  22125. + [SWITCH_ATTR_OP_VALUE_PORTS] = { .type = NLA_NESTED },
  22126. + [SWITCH_ATTR_TYPE] = { .type = NLA_U32 },
  22127. +};
  22128. +
  22129. +static const struct nla_policy port_policy[SWITCH_PORT_ATTR_MAX+1] = {
  22130. + [SWITCH_PORT_ID] = { .type = NLA_U32 },
  22131. + [SWITCH_PORT_FLAG_TAGGED] = { .type = NLA_FLAG },
  22132. +};
  22133. +
  22134. +static inline void
  22135. +swconfig_lock(void)
  22136. +{
  22137. + spin_lock(&swdevs_lock);
  22138. +}
  22139. +
  22140. +static inline void
  22141. +swconfig_unlock(void)
  22142. +{
  22143. + spin_unlock(&swdevs_lock);
  22144. +}
  22145. +
  22146. +static struct switch_dev *
  22147. +swconfig_get_dev(struct genl_info *info)
  22148. +{
  22149. + struct switch_dev *dev = NULL;
  22150. + struct switch_dev *p;
  22151. + int id;
  22152. +
  22153. + if (!info->attrs[SWITCH_ATTR_ID])
  22154. + goto done;
  22155. +
  22156. + id = nla_get_u32(info->attrs[SWITCH_ATTR_ID]);
  22157. + swconfig_lock();
  22158. + list_for_each_entry(p, &swdevs, dev_list) {
  22159. + if (id != p->id)
  22160. + continue;
  22161. +
  22162. + dev = p;
  22163. + break;
  22164. + }
  22165. + if (dev)
  22166. + spin_lock(&dev->lock);
  22167. + else
  22168. + DPRINTF("device %d not found\n", id);
  22169. + swconfig_unlock();
  22170. +done:
  22171. + return dev;
  22172. +}
  22173. +
  22174. +static inline void
  22175. +swconfig_put_dev(struct switch_dev *dev)
  22176. +{
  22177. + spin_unlock(&dev->lock);
  22178. +}
  22179. +
  22180. +static int
  22181. +swconfig_dump_attr(struct swconfig_callback *cb, void *arg)
  22182. +{
  22183. + struct switch_attr *op = arg;
  22184. + struct genl_info *info = cb->info;
  22185. + struct sk_buff *msg = cb->msg;
  22186. + int id = cb->args[0];
  22187. + void *hdr;
  22188. +
  22189. + hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, &switch_fam,
  22190. + NLM_F_MULTI, SWITCH_CMD_NEW_ATTR);
  22191. + if (IS_ERR(hdr))
  22192. + return -1;
  22193. +
  22194. + NLA_PUT_U32(msg, SWITCH_ATTR_OP_ID, id);
  22195. + NLA_PUT_U32(msg, SWITCH_ATTR_OP_TYPE, op->type);
  22196. + NLA_PUT_STRING(msg, SWITCH_ATTR_OP_NAME, op->name);
  22197. + if (op->description)
  22198. + NLA_PUT_STRING(msg, SWITCH_ATTR_OP_DESCRIPTION,
  22199. + op->description);
  22200. +
  22201. + return genlmsg_end(msg, hdr);
  22202. +nla_put_failure:
  22203. + genlmsg_cancel(msg, hdr);
  22204. + return -EMSGSIZE;
  22205. +}
  22206. +
  22207. +/* spread multipart messages across multiple message buffers */
  22208. +static int
  22209. +swconfig_send_multipart(struct swconfig_callback *cb, void *arg)
  22210. +{
  22211. + struct genl_info *info = cb->info;
  22212. + int restart = 0;
  22213. + int err;
  22214. +
  22215. + do {
  22216. + if (!cb->msg) {
  22217. + cb->msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  22218. + if (cb->msg == NULL)
  22219. + goto error;
  22220. + }
  22221. +
  22222. + if (!(cb->fill(cb, arg) < 0))
  22223. + break;
  22224. +
  22225. + /* fill failed, check if this was already the second attempt */
  22226. + if (restart)
  22227. + goto error;
  22228. +
  22229. + /* try again in a new message, send the current one */
  22230. + restart = 1;
  22231. + if (cb->close) {
  22232. + if (cb->close(cb, arg) < 0)
  22233. + goto error;
  22234. + }
  22235. + err = genlmsg_reply(cb->msg, info);
  22236. + cb->msg = NULL;
  22237. + if (err < 0)
  22238. + goto error;
  22239. +
  22240. + } while (restart);
  22241. +
  22242. + return 0;
  22243. +
  22244. +error:
  22245. + if (cb->msg)
  22246. + nlmsg_free(cb->msg);
  22247. + return -1;
  22248. +}
  22249. +
  22250. +static int
  22251. +swconfig_list_attrs(struct sk_buff *skb, struct genl_info *info)
  22252. +{
  22253. + struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
  22254. + const struct switch_attrlist *alist;
  22255. + struct switch_dev *dev;
  22256. + struct swconfig_callback cb;
  22257. + int err = -EINVAL;
  22258. + int i;
  22259. +
  22260. + /* defaults */
  22261. + struct switch_attr *def_list;
  22262. + unsigned long *def_active;
  22263. + int n_def;
  22264. +
  22265. + dev = swconfig_get_dev(info);
  22266. + if (!dev)
  22267. + return -EINVAL;
  22268. +
  22269. + switch(hdr->cmd) {
  22270. + case SWITCH_CMD_LIST_GLOBAL:
  22271. + alist = &dev->ops->attr_global;
  22272. + def_list = default_global;
  22273. + def_active = &dev->def_global;
  22274. + n_def = ARRAY_SIZE(default_global);
  22275. + break;
  22276. + case SWITCH_CMD_LIST_VLAN:
  22277. + alist = &dev->ops->attr_vlan;
  22278. + def_list = default_vlan;
  22279. + def_active = &dev->def_vlan;
  22280. + n_def = ARRAY_SIZE(default_vlan);
  22281. + break;
  22282. + case SWITCH_CMD_LIST_PORT:
  22283. + alist = &dev->ops->attr_port;
  22284. + def_list = default_port;
  22285. + def_active = &dev->def_port;
  22286. + n_def = ARRAY_SIZE(default_port);
  22287. + break;
  22288. + default:
  22289. + WARN_ON(1);
  22290. + goto out;
  22291. + }
  22292. +
  22293. + memset(&cb, 0, sizeof(cb));
  22294. + cb.info = info;
  22295. + cb.fill = swconfig_dump_attr;
  22296. + for (i = 0; i < alist->n_attr; i++) {
  22297. + if (alist->attr[i].disabled)
  22298. + continue;
  22299. + cb.args[0] = i;
  22300. + err = swconfig_send_multipart(&cb, (void *) &alist->attr[i]);
  22301. + if (err < 0)
  22302. + goto error;
  22303. + }
  22304. +
  22305. + /* defaults */
  22306. + for (i = 0; i < n_def; i++) {
  22307. + if (!test_bit(i, def_active))
  22308. + continue;
  22309. + cb.args[0] = SWITCH_ATTR_DEFAULTS_OFFSET + i;
  22310. + err = swconfig_send_multipart(&cb, (void *) &def_list[i]);
  22311. + if (err < 0)
  22312. + goto error;
  22313. + }
  22314. + swconfig_put_dev(dev);
  22315. +
  22316. + if (!cb.msg)
  22317. + return 0;
  22318. +
  22319. + return genlmsg_reply(cb.msg, info);
  22320. +
  22321. +error:
  22322. + if (cb.msg)
  22323. + nlmsg_free(cb.msg);
  22324. +out:
  22325. + swconfig_put_dev(dev);
  22326. + return err;
  22327. +}
  22328. +
  22329. +static const struct switch_attr *
  22330. +swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
  22331. + struct switch_val *val)
  22332. +{
  22333. + struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
  22334. + const struct switch_attrlist *alist;
  22335. + const struct switch_attr *attr = NULL;
  22336. + int attr_id;
  22337. +
  22338. + /* defaults */
  22339. + struct switch_attr *def_list;
  22340. + unsigned long *def_active;
  22341. + int n_def;
  22342. +
  22343. + if (!info->attrs[SWITCH_ATTR_OP_ID])
  22344. + goto done;
  22345. +
  22346. + switch(hdr->cmd) {
  22347. + case SWITCH_CMD_SET_GLOBAL:
  22348. + case SWITCH_CMD_GET_GLOBAL:
  22349. + alist = &dev->ops->attr_global;
  22350. + def_list = default_global;
  22351. + def_active = &dev->def_global;
  22352. + n_def = ARRAY_SIZE(default_global);
  22353. + break;
  22354. + case SWITCH_CMD_SET_VLAN:
  22355. + case SWITCH_CMD_GET_VLAN:
  22356. + alist = &dev->ops->attr_vlan;
  22357. + def_list = default_vlan;
  22358. + def_active = &dev->def_vlan;
  22359. + n_def = ARRAY_SIZE(default_vlan);
  22360. + if (!info->attrs[SWITCH_ATTR_OP_VLAN])
  22361. + goto done;
  22362. + val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_VLAN]);
  22363. + if (val->port_vlan >= dev->vlans)
  22364. + goto done;
  22365. + break;
  22366. + case SWITCH_CMD_SET_PORT:
  22367. + case SWITCH_CMD_GET_PORT:
  22368. + alist = &dev->ops->attr_port;
  22369. + def_list = default_port;
  22370. + def_active = &dev->def_port;
  22371. + n_def = ARRAY_SIZE(default_port);
  22372. + if (!info->attrs[SWITCH_ATTR_OP_PORT])
  22373. + goto done;
  22374. + val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_PORT]);
  22375. + if (val->port_vlan >= dev->ports)
  22376. + goto done;
  22377. + break;
  22378. + default:
  22379. + WARN_ON(1);
  22380. + goto done;
  22381. + }
  22382. +
  22383. + if (!alist)
  22384. + goto done;
  22385. +
  22386. + attr_id = nla_get_u32(info->attrs[SWITCH_ATTR_OP_ID]);
  22387. + if (attr_id >= SWITCH_ATTR_DEFAULTS_OFFSET) {
  22388. + attr_id -= SWITCH_ATTR_DEFAULTS_OFFSET;
  22389. + if (attr_id >= n_def)
  22390. + goto done;
  22391. + if (!test_bit(attr_id, def_active))
  22392. + goto done;
  22393. + attr = &def_list[attr_id];
  22394. + } else {
  22395. + if (attr_id >= alist->n_attr)
  22396. + goto done;
  22397. + attr = &alist->attr[attr_id];
  22398. + }
  22399. +
  22400. + if (attr->disabled)
  22401. + attr = NULL;
  22402. +
  22403. +done:
  22404. + if (!attr)
  22405. + DPRINTF("attribute lookup failed\n");
  22406. + val->attr = attr;
  22407. + return attr;
  22408. +}
  22409. +
  22410. +static int
  22411. +swconfig_parse_ports(struct sk_buff *msg, struct nlattr *head,
  22412. + struct switch_val *val, int max)
  22413. +{
  22414. + struct nlattr *nla;
  22415. + int rem;
  22416. +
  22417. + val->len = 0;
  22418. + nla_for_each_nested(nla, head, rem) {
  22419. + struct nlattr *tb[SWITCH_PORT_ATTR_MAX+1];
  22420. + struct switch_port *port = &val->value.ports[val->len];
  22421. +
  22422. + if (val->len >= max)
  22423. + return -EINVAL;
  22424. +
  22425. + if (nla_parse_nested(tb, SWITCH_PORT_ATTR_MAX, nla,
  22426. + port_policy))
  22427. + return -EINVAL;
  22428. +
  22429. + if (!tb[SWITCH_PORT_ID])
  22430. + return -EINVAL;
  22431. +
  22432. + port->id = nla_get_u32(tb[SWITCH_PORT_ID]);
  22433. + if (tb[SWITCH_PORT_FLAG_TAGGED])
  22434. + port->flags |= (1 << SWITCH_PORT_FLAG_TAGGED);
  22435. + val->len++;
  22436. + }
  22437. +
  22438. + return 0;
  22439. +}
  22440. +
  22441. +static int
  22442. +swconfig_set_attr(struct sk_buff *skb, struct genl_info *info)
  22443. +{
  22444. + const struct switch_attr *attr;
  22445. + struct switch_dev *dev;
  22446. + struct switch_val val;
  22447. + int err = -EINVAL;
  22448. +
  22449. + dev = swconfig_get_dev(info);
  22450. + if (!dev)
  22451. + return -EINVAL;
  22452. +
  22453. + memset(&val, 0, sizeof(val));
  22454. + attr = swconfig_lookup_attr(dev, info, &val);
  22455. + if (!attr || !attr->set)
  22456. + goto error;
  22457. +
  22458. + val.attr = attr;
  22459. + switch(attr->type) {
  22460. + case SWITCH_TYPE_NOVAL:
  22461. + break;
  22462. + case SWITCH_TYPE_INT:
  22463. + if (!info->attrs[SWITCH_ATTR_OP_VALUE_INT])
  22464. + goto error;
  22465. + val.value.i =
  22466. + nla_get_u32(info->attrs[SWITCH_ATTR_OP_VALUE_INT]);
  22467. + break;
  22468. + case SWITCH_TYPE_STRING:
  22469. + if (!info->attrs[SWITCH_ATTR_OP_VALUE_STR])
  22470. + goto error;
  22471. + val.value.s =
  22472. + nla_data(info->attrs[SWITCH_ATTR_OP_VALUE_STR]);
  22473. + break;
  22474. + case SWITCH_TYPE_PORTS:
  22475. + val.value.ports = dev->portbuf;
  22476. + memset(dev->portbuf, 0,
  22477. + sizeof(struct switch_port) * dev->ports);
  22478. +
  22479. + /* TODO: implement multipart? */
  22480. + if (info->attrs[SWITCH_ATTR_OP_VALUE_PORTS]) {
  22481. + err = swconfig_parse_ports(skb,
  22482. + info->attrs[SWITCH_ATTR_OP_VALUE_PORTS], &val, dev->ports);
  22483. + if (err < 0)
  22484. + goto error;
  22485. + } else {
  22486. + val.len = 0;
  22487. + err = 0;
  22488. + }
  22489. + break;
  22490. + default:
  22491. + goto error;
  22492. + }
  22493. +
  22494. + err = attr->set(dev, attr, &val);
  22495. +error:
  22496. + swconfig_put_dev(dev);
  22497. + return err;
  22498. +}
  22499. +
  22500. +static int
  22501. +swconfig_close_portlist(struct swconfig_callback *cb, void *arg)
  22502. +{
  22503. + if (cb->nest[0])
  22504. + nla_nest_end(cb->msg, cb->nest[0]);
  22505. + return 0;
  22506. +}
  22507. +
  22508. +static int
  22509. +swconfig_send_port(struct swconfig_callback *cb, void *arg)
  22510. +{
  22511. + const struct switch_port *port = arg;
  22512. + struct nlattr *p = NULL;
  22513. +
  22514. + if (!cb->nest[0]) {
  22515. + cb->nest[0] = nla_nest_start(cb->msg, cb->cmd);
  22516. + if (!cb->nest[0])
  22517. + return -1;
  22518. + }
  22519. +
  22520. + p = nla_nest_start(cb->msg, SWITCH_ATTR_PORT);
  22521. + if (!p)
  22522. + goto error;
  22523. +
  22524. + NLA_PUT_U32(cb->msg, SWITCH_PORT_ID, port->id);
  22525. + if (port->flags & (1 << SWITCH_PORT_FLAG_TAGGED))
  22526. + NLA_PUT_FLAG(cb->msg, SWITCH_PORT_FLAG_TAGGED);
  22527. +
  22528. + nla_nest_end(cb->msg, p);
  22529. + return 0;
  22530. +
  22531. +nla_put_failure:
  22532. + nla_nest_cancel(cb->msg, p);
  22533. +error:
  22534. + nla_nest_cancel(cb->msg, cb->nest[0]);
  22535. + return -1;
  22536. +}
  22537. +
  22538. +static int
  22539. +swconfig_send_ports(struct sk_buff **msg, struct genl_info *info, int attr,
  22540. + const struct switch_val *val)
  22541. +{
  22542. + struct swconfig_callback cb;
  22543. + int err = 0;
  22544. + int i;
  22545. +
  22546. + if (!val->value.ports)
  22547. + return -EINVAL;
  22548. +
  22549. + memset(&cb, 0, sizeof(cb));
  22550. + cb.cmd = attr;
  22551. + cb.msg = *msg;
  22552. + cb.info = info;
  22553. + cb.fill = swconfig_send_port;
  22554. + cb.close = swconfig_close_portlist;
  22555. +
  22556. + cb.nest[0] = nla_nest_start(cb.msg, cb.cmd);
  22557. + for (i = 0; i < val->len; i++) {
  22558. + err = swconfig_send_multipart(&cb, &val->value.ports[i]);
  22559. + if (err)
  22560. + goto done;
  22561. + }
  22562. + err = val->len;
  22563. + swconfig_close_portlist(&cb, NULL);
  22564. + *msg = cb.msg;
  22565. +
  22566. +done:
  22567. + return err;
  22568. +}
  22569. +
  22570. +static int
  22571. +swconfig_get_attr(struct sk_buff *skb, struct genl_info *info)
  22572. +{
  22573. + struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
  22574. + const struct switch_attr *attr;
  22575. + struct switch_dev *dev;
  22576. + struct sk_buff *msg = NULL;
  22577. + struct switch_val val;
  22578. + int err = -EINVAL;
  22579. + int cmd = hdr->cmd;
  22580. +
  22581. + dev = swconfig_get_dev(info);
  22582. + if (!dev)
  22583. + return -EINVAL;
  22584. +
  22585. + memset(&val, 0, sizeof(val));
  22586. + attr = swconfig_lookup_attr(dev, info, &val);
  22587. + if (!attr || !attr->get)
  22588. + goto error;
  22589. +
  22590. + if (attr->type == SWITCH_TYPE_PORTS) {
  22591. + val.value.ports = dev->portbuf;
  22592. + memset(dev->portbuf, 0,
  22593. + sizeof(struct switch_port) * dev->ports);
  22594. + }
  22595. +
  22596. + err = attr->get(dev, attr, &val);
  22597. + if (err)
  22598. + goto error;
  22599. +
  22600. + msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  22601. + if (!msg)
  22602. + goto error;
  22603. +
  22604. + hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, &switch_fam,
  22605. + 0, cmd);
  22606. + if (IS_ERR(hdr))
  22607. + goto nla_put_failure;
  22608. +
  22609. + switch(attr->type) {
  22610. + case SWITCH_TYPE_INT:
  22611. + NLA_PUT_U32(msg, SWITCH_ATTR_OP_VALUE_INT, val.value.i);
  22612. + break;
  22613. + case SWITCH_TYPE_STRING:
  22614. + NLA_PUT_STRING(msg, SWITCH_ATTR_OP_VALUE_STR, val.value.s);
  22615. + break;
  22616. + case SWITCH_TYPE_PORTS:
  22617. + err = swconfig_send_ports(&msg, info,
  22618. + SWITCH_ATTR_OP_VALUE_PORTS, &val);
  22619. + if (err < 0)
  22620. + goto nla_put_failure;
  22621. + break;
  22622. + default:
  22623. + DPRINTF("invalid type in attribute\n");
  22624. + err = -EINVAL;
  22625. + goto error;
  22626. + }
  22627. + err = genlmsg_end(msg, hdr);
  22628. + if (err < 0)
  22629. + goto nla_put_failure;
  22630. +
  22631. + swconfig_put_dev(dev);
  22632. + return genlmsg_reply(msg, info);
  22633. +
  22634. +nla_put_failure:
  22635. + if (msg)
  22636. + nlmsg_free(msg);
  22637. +error:
  22638. + swconfig_put_dev(dev);
  22639. + if (!err)
  22640. + err = -ENOMEM;
  22641. + return err;
  22642. +}
  22643. +
  22644. +static int
  22645. +swconfig_send_switch(struct sk_buff *msg, u32 pid, u32 seq, int flags,
  22646. + const struct switch_dev *dev)
  22647. +{
  22648. + void *hdr;
  22649. +
  22650. + hdr = genlmsg_put(msg, pid, seq, &switch_fam, flags,
  22651. + SWITCH_CMD_NEW_ATTR);
  22652. + if (IS_ERR(hdr))
  22653. + return -1;
  22654. +
  22655. + NLA_PUT_U32(msg, SWITCH_ATTR_ID, dev->id);
  22656. + NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
  22657. + NLA_PUT_STRING(msg, SWITCH_ATTR_ALIAS, dev->alias);
  22658. + NLA_PUT_STRING(msg, SWITCH_ATTR_NAME, dev->name);
  22659. + NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans);
  22660. + NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports);
  22661. + NLA_PUT_U32(msg, SWITCH_ATTR_CPU_PORT, dev->cpu_port);
  22662. +
  22663. + return genlmsg_end(msg, hdr);
  22664. +nla_put_failure:
  22665. + genlmsg_cancel(msg, hdr);
  22666. + return -EMSGSIZE;
  22667. +}
  22668. +
  22669. +static int swconfig_dump_switches(struct sk_buff *skb,
  22670. + struct netlink_callback *cb)
  22671. +{
  22672. + struct switch_dev *dev;
  22673. + int start = cb->args[0];
  22674. + int idx = 0;
  22675. +
  22676. + swconfig_lock();
  22677. + list_for_each_entry(dev, &swdevs, dev_list) {
  22678. + if (++idx <= start)
  22679. + continue;
  22680. + if (swconfig_send_switch(skb, NETLINK_CB(cb->skb).pid,
  22681. + cb->nlh->nlmsg_seq, NLM_F_MULTI,
  22682. + dev) < 0)
  22683. + break;
  22684. + }
  22685. + swconfig_unlock();
  22686. + cb->args[0] = idx;
  22687. +
  22688. + return skb->len;
  22689. +}
  22690. +
  22691. +static int
  22692. +swconfig_done(struct netlink_callback *cb)
  22693. +{
  22694. + return 0;
  22695. +}
  22696. +
  22697. +static struct genl_ops swconfig_ops[] = {
  22698. + {
  22699. + .cmd = SWITCH_CMD_LIST_GLOBAL,
  22700. + .doit = swconfig_list_attrs,
  22701. + .policy = switch_policy,
  22702. + },
  22703. + {
  22704. + .cmd = SWITCH_CMD_LIST_VLAN,
  22705. + .doit = swconfig_list_attrs,
  22706. + .policy = switch_policy,
  22707. + },
  22708. + {
  22709. + .cmd = SWITCH_CMD_LIST_PORT,
  22710. + .doit = swconfig_list_attrs,
  22711. + .policy = switch_policy,
  22712. + },
  22713. + {
  22714. + .cmd = SWITCH_CMD_GET_GLOBAL,
  22715. + .doit = swconfig_get_attr,
  22716. + .policy = switch_policy,
  22717. + },
  22718. + {
  22719. + .cmd = SWITCH_CMD_GET_VLAN,
  22720. + .doit = swconfig_get_attr,
  22721. + .policy = switch_policy,
  22722. + },
  22723. + {
  22724. + .cmd = SWITCH_CMD_GET_PORT,
  22725. + .doit = swconfig_get_attr,
  22726. + .policy = switch_policy,
  22727. + },
  22728. + {
  22729. + .cmd = SWITCH_CMD_SET_GLOBAL,
  22730. + .doit = swconfig_set_attr,
  22731. + .policy = switch_policy,
  22732. + },
  22733. + {
  22734. + .cmd = SWITCH_CMD_SET_VLAN,
  22735. + .doit = swconfig_set_attr,
  22736. + .policy = switch_policy,
  22737. + },
  22738. + {
  22739. + .cmd = SWITCH_CMD_SET_PORT,
  22740. + .doit = swconfig_set_attr,
  22741. + .policy = switch_policy,
  22742. + },
  22743. + {
  22744. + .cmd = SWITCH_CMD_GET_SWITCH,
  22745. + .dumpit = swconfig_dump_switches,
  22746. + .policy = switch_policy,
  22747. + .done = swconfig_done,
  22748. + }
  22749. +};
  22750. +
  22751. +int
  22752. +register_switch(struct switch_dev *dev, struct net_device *netdev)
  22753. +{
  22754. + struct switch_dev *sdev;
  22755. + const int max_switches = 8 * sizeof(unsigned long);
  22756. + unsigned long in_use = 0;
  22757. + int i;
  22758. +
  22759. + INIT_LIST_HEAD(&dev->dev_list);
  22760. + if (netdev) {
  22761. + dev->netdev = netdev;
  22762. + if (!dev->alias)
  22763. + dev->alias = netdev->name;
  22764. + }
  22765. + BUG_ON(!dev->alias);
  22766. +
  22767. + if (dev->ports > 0) {
  22768. + dev->portbuf = kzalloc(sizeof(struct switch_port) * dev->ports,
  22769. + GFP_KERNEL);
  22770. + if (!dev->portbuf)
  22771. + return -ENOMEM;
  22772. + }
  22773. + swconfig_defaults_init(dev);
  22774. + spin_lock_init(&dev->lock);
  22775. + swconfig_lock();
  22776. + dev->id = ++swdev_id;
  22777. +
  22778. + list_for_each_entry(sdev, &swdevs, dev_list) {
  22779. + if (!sscanf(sdev->devname, SWCONFIG_DEVNAME, &i))
  22780. + continue;
  22781. + if (i < 0 || i > max_switches)
  22782. + continue;
  22783. +
  22784. + set_bit(i, &in_use);
  22785. + }
  22786. + i = find_first_zero_bit(&in_use, max_switches);
  22787. +
  22788. + if (i == max_switches)
  22789. + return -ENFILE;
  22790. +
  22791. + /* fill device name */
  22792. + snprintf(dev->devname, IFNAMSIZ, SWCONFIG_DEVNAME, i);
  22793. +
  22794. + list_add(&dev->dev_list, &swdevs);
  22795. + swconfig_unlock();
  22796. +
  22797. + return 0;
  22798. +}
  22799. +EXPORT_SYMBOL_GPL(register_switch);
  22800. +
  22801. +void
  22802. +unregister_switch(struct switch_dev *dev)
  22803. +{
  22804. + kfree(dev->portbuf);
  22805. + spin_lock(&dev->lock);
  22806. + swconfig_lock();
  22807. + list_del(&dev->dev_list);
  22808. + swconfig_unlock();
  22809. + spin_unlock(&dev->lock);
  22810. +}
  22811. +EXPORT_SYMBOL_GPL(unregister_switch);
  22812. +
  22813. +
  22814. +static int __init
  22815. +swconfig_init(void)
  22816. +{
  22817. + int i, err;
  22818. +
  22819. + INIT_LIST_HEAD(&swdevs);
  22820. + err = genl_register_family(&switch_fam);
  22821. + if (err)
  22822. + return err;
  22823. +
  22824. + for (i = 0; i < ARRAY_SIZE(swconfig_ops); i++) {
  22825. + err = genl_register_ops(&switch_fam, &swconfig_ops[i]);
  22826. + if (err)
  22827. + goto unregister;
  22828. + }
  22829. +
  22830. + return 0;
  22831. +
  22832. +unregister:
  22833. + genl_unregister_family(&switch_fam);
  22834. + return err;
  22835. +}
  22836. +
  22837. +static void __exit
  22838. +swconfig_exit(void)
  22839. +{
  22840. + genl_unregister_family(&switch_fam);
  22841. +}
  22842. +
  22843. +module_init(swconfig_init);
  22844. +module_exit(swconfig_exit);
  22845. +
  22846. diff -Nur linux-2.6.39.orig/drivers/spi/ap83_spi.c linux-2.6.39/drivers/spi/ap83_spi.c
  22847. --- linux-2.6.39.orig/drivers/spi/ap83_spi.c 1970-01-01 01:00:00.000000000 +0100
  22848. +++ linux-2.6.39/drivers/spi/ap83_spi.c 2011-04-27 12:19:22.317665385 +0200
  22849. @@ -0,0 +1,283 @@
  22850. +/*
  22851. + * Atheros AP83 board specific SPI Controller driver
  22852. + *
  22853. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  22854. + *
  22855. + * This program is free software; you can redistribute it and/or modify
  22856. + * it under the terms of the GNU General Public License version 2 as
  22857. + * published by the Free Software Foundation.
  22858. + *
  22859. + */
  22860. +
  22861. +#include <linux/kernel.h>
  22862. +#include <linux/init.h>
  22863. +#include <linux/delay.h>
  22864. +#include <linux/spinlock.h>
  22865. +#include <linux/workqueue.h>
  22866. +#include <linux/platform_device.h>
  22867. +#include <linux/io.h>
  22868. +#include <linux/spi/spi.h>
  22869. +#include <linux/spi/spi_bitbang.h>
  22870. +#include <linux/bitops.h>
  22871. +#include <linux/gpio.h>
  22872. +
  22873. +#include <asm/mach-ar71xx/ar71xx.h>
  22874. +#include <asm/mach-ar71xx/platform.h>
  22875. +
  22876. +#define DRV_DESC "Atheros AP83 board SPI Controller driver"
  22877. +#define DRV_VERSION "0.1.0"
  22878. +#define DRV_NAME "ap83-spi"
  22879. +
  22880. +#define AP83_SPI_CLK_HIGH (1 << 23)
  22881. +#define AP83_SPI_CLK_LOW 0
  22882. +#define AP83_SPI_MOSI_HIGH (1 << 22)
  22883. +#define AP83_SPI_MOSI_LOW 0
  22884. +
  22885. +#define AP83_SPI_GPIO_CS 1
  22886. +#define AP83_SPI_GPIO_MISO 3
  22887. +
  22888. +struct ap83_spi {
  22889. + struct spi_bitbang bitbang;
  22890. + void __iomem *base;
  22891. + u32 addr;
  22892. +
  22893. + struct platform_device *pdev;
  22894. +};
  22895. +
  22896. +static inline u32 ap83_spi_rr(struct ap83_spi *sp, u32 reg)
  22897. +{
  22898. + return __raw_readl(sp->base + reg);
  22899. +}
  22900. +
  22901. +static inline struct ap83_spi *spidev_to_sp(struct spi_device *spi)
  22902. +{
  22903. + return spi_master_get_devdata(spi->master);
  22904. +}
  22905. +
  22906. +static inline void setsck(struct spi_device *spi, int val)
  22907. +{
  22908. + struct ap83_spi *sp = spidev_to_sp(spi);
  22909. +
  22910. + if (val)
  22911. + sp->addr |= AP83_SPI_CLK_HIGH;
  22912. + else
  22913. + sp->addr &= ~AP83_SPI_CLK_HIGH;
  22914. +
  22915. + dev_dbg(&spi->dev, "addr=%08x, SCK set to %s\n",
  22916. + sp->addr, (val) ? "HIGH" : "LOW");
  22917. +
  22918. + ap83_spi_rr(sp, sp->addr);
  22919. +}
  22920. +
  22921. +static inline void setmosi(struct spi_device *spi, int val)
  22922. +{
  22923. + struct ap83_spi *sp = spidev_to_sp(spi);
  22924. +
  22925. + if (val)
  22926. + sp->addr |= AP83_SPI_MOSI_HIGH;
  22927. + else
  22928. + sp->addr &= ~AP83_SPI_MOSI_HIGH;
  22929. +
  22930. + dev_dbg(&spi->dev, "addr=%08x, MOSI set to %s\n",
  22931. + sp->addr, (val) ? "HIGH" : "LOW");
  22932. +
  22933. + ap83_spi_rr(sp, sp->addr);
  22934. +}
  22935. +
  22936. +static inline u32 getmiso(struct spi_device *spi)
  22937. +{
  22938. + u32 ret;
  22939. +
  22940. + ret = gpio_get_value(AP83_SPI_GPIO_MISO) ? 1 : 0;
  22941. + dev_dbg(&spi->dev, "get MISO: %d\n", ret);
  22942. +
  22943. + return ret;
  22944. +}
  22945. +
  22946. +static inline void do_spidelay(struct spi_device *spi, unsigned nsecs)
  22947. +{
  22948. + ndelay(nsecs);
  22949. +}
  22950. +
  22951. +static void ap83_spi_chipselect(struct spi_device *spi, int on)
  22952. +{
  22953. + struct ap83_spi *sp = spidev_to_sp(spi);
  22954. +
  22955. + dev_dbg(&spi->dev, "set CS to %d\n", (on) ? 0 : 1);
  22956. +
  22957. + if (on) {
  22958. + ar71xx_flash_acquire();
  22959. +
  22960. + sp->addr = 0;
  22961. + ap83_spi_rr(sp, sp->addr);
  22962. +
  22963. + gpio_set_value(AP83_SPI_GPIO_CS, 0);
  22964. + } else {
  22965. + gpio_set_value(AP83_SPI_GPIO_CS, 1);
  22966. + ar71xx_flash_release();
  22967. + }
  22968. +}
  22969. +
  22970. +#define spidelay(nsecs) \
  22971. + do { \
  22972. + /* Steal the spi_device pointer from our caller. \
  22973. + * The bitbang-API should probably get fixed here... */ \
  22974. + do_spidelay(spi, nsecs); \
  22975. + } while (0)
  22976. +
  22977. +#define EXPAND_BITBANG_TXRX
  22978. +#include <linux/spi/spi_bitbang.h>
  22979. +#include "spi_bitbang_txrx.h"
  22980. +
  22981. +static u32 ap83_spi_txrx_mode0(struct spi_device *spi,
  22982. + unsigned nsecs, u32 word, u8 bits)
  22983. +{
  22984. + dev_dbg(&spi->dev, "TXRX0 word=%08x, bits=%u\n", word, bits);
  22985. + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
  22986. +}
  22987. +
  22988. +static u32 ap83_spi_txrx_mode1(struct spi_device *spi,
  22989. + unsigned nsecs, u32 word, u8 bits)
  22990. +{
  22991. + dev_dbg(&spi->dev, "TXRX1 word=%08x, bits=%u\n", word, bits);
  22992. + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
  22993. +}
  22994. +
  22995. +static u32 ap83_spi_txrx_mode2(struct spi_device *spi,
  22996. + unsigned nsecs, u32 word, u8 bits)
  22997. +{
  22998. + dev_dbg(&spi->dev, "TXRX2 word=%08x, bits=%u\n", word, bits);
  22999. + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
  23000. +}
  23001. +
  23002. +static u32 ap83_spi_txrx_mode3(struct spi_device *spi,
  23003. + unsigned nsecs, u32 word, u8 bits)
  23004. +{
  23005. + dev_dbg(&spi->dev, "TXRX3 word=%08x, bits=%u\n", word, bits);
  23006. + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
  23007. +}
  23008. +
  23009. +static int ap83_spi_probe(struct platform_device *pdev)
  23010. +{
  23011. + struct spi_master *master;
  23012. + struct ap83_spi *sp;
  23013. + struct ap83_spi_platform_data *pdata;
  23014. + struct resource *r;
  23015. + int ret;
  23016. +
  23017. + ret = gpio_request(AP83_SPI_GPIO_MISO, "spi-miso");
  23018. + if (ret) {
  23019. + dev_err(&pdev->dev, "gpio request failed for MISO\n");
  23020. + return ret;
  23021. + }
  23022. +
  23023. + ret = gpio_request(AP83_SPI_GPIO_CS, "spi-cs");
  23024. + if (ret) {
  23025. + dev_err(&pdev->dev, "gpio request failed for CS\n");
  23026. + goto err_free_miso;
  23027. + }
  23028. +
  23029. + ret = gpio_direction_input(AP83_SPI_GPIO_MISO);
  23030. + if (ret) {
  23031. + dev_err(&pdev->dev, "unable to set direction of MISO\n");
  23032. + goto err_free_cs;
  23033. + }
  23034. +
  23035. + ret = gpio_direction_output(AP83_SPI_GPIO_CS, 0);
  23036. + if (ret) {
  23037. + dev_err(&pdev->dev, "unable to set direction of CS\n");
  23038. + goto err_free_cs;
  23039. + }
  23040. +
  23041. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  23042. + if (master == NULL) {
  23043. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  23044. + return -ENOMEM;
  23045. + }
  23046. +
  23047. + sp = spi_master_get_devdata(master);
  23048. + platform_set_drvdata(pdev, sp);
  23049. +
  23050. + pdata = pdev->dev.platform_data;
  23051. +
  23052. + sp->bitbang.master = spi_master_get(master);
  23053. + sp->bitbang.chipselect = ap83_spi_chipselect;
  23054. + sp->bitbang.txrx_word[SPI_MODE_0] = ap83_spi_txrx_mode0;
  23055. + sp->bitbang.txrx_word[SPI_MODE_1] = ap83_spi_txrx_mode1;
  23056. + sp->bitbang.txrx_word[SPI_MODE_2] = ap83_spi_txrx_mode2;
  23057. + sp->bitbang.txrx_word[SPI_MODE_3] = ap83_spi_txrx_mode3;
  23058. +
  23059. + sp->bitbang.master->bus_num = pdev->id;
  23060. + sp->bitbang.master->num_chipselect = 1;
  23061. +
  23062. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  23063. + if (r == NULL) {
  23064. + ret = -ENOENT;
  23065. + goto err_spi_put;
  23066. + }
  23067. +
  23068. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  23069. + if (!sp->base) {
  23070. + ret = -ENXIO;
  23071. + goto err_spi_put;
  23072. + }
  23073. +
  23074. + ret = spi_bitbang_start(&sp->bitbang);
  23075. + if (!ret)
  23076. + goto err_unmap;
  23077. +
  23078. + dev_info(&pdev->dev, "AP83 SPI adapter at %08x\n", r->start);
  23079. +
  23080. + return 0;
  23081. +
  23082. +err_unmap:
  23083. + iounmap(sp->base);
  23084. +err_spi_put:
  23085. + platform_set_drvdata(pdev, NULL);
  23086. + spi_master_put(sp->bitbang.master);
  23087. +
  23088. +err_free_cs:
  23089. + gpio_free(AP83_SPI_GPIO_CS);
  23090. +err_free_miso:
  23091. + gpio_free(AP83_SPI_GPIO_MISO);
  23092. + return ret;
  23093. +}
  23094. +
  23095. +static int ap83_spi_remove(struct platform_device *pdev)
  23096. +{
  23097. + struct ap83_spi *sp = platform_get_drvdata(pdev);
  23098. +
  23099. + spi_bitbang_stop(&sp->bitbang);
  23100. + iounmap(sp->base);
  23101. + platform_set_drvdata(pdev, NULL);
  23102. + spi_master_put(sp->bitbang.master);
  23103. +
  23104. + return 0;
  23105. +}
  23106. +
  23107. +static struct platform_driver ap83_spi_drv = {
  23108. + .probe = ap83_spi_probe,
  23109. + .remove = ap83_spi_remove,
  23110. + .driver = {
  23111. + .name = DRV_NAME,
  23112. + .owner = THIS_MODULE,
  23113. + },
  23114. +};
  23115. +
  23116. +static int __init ap83_spi_init(void)
  23117. +{
  23118. + return platform_driver_register(&ap83_spi_drv);
  23119. +}
  23120. +module_init(ap83_spi_init);
  23121. +
  23122. +static void __exit ap83_spi_exit(void)
  23123. +{
  23124. + platform_driver_unregister(&ap83_spi_drv);
  23125. +}
  23126. +module_exit(ap83_spi_exit);
  23127. +
  23128. +MODULE_ALIAS("platform:" DRV_NAME);
  23129. +MODULE_DESCRIPTION(DRV_DESC);
  23130. +MODULE_VERSION(DRV_VERSION);
  23131. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  23132. +MODULE_LICENSE("GPL v2");
  23133. diff -Nur linux-2.6.39.orig/drivers/spi/ar71xx_spi.c linux-2.6.39/drivers/spi/ar71xx_spi.c
  23134. --- linux-2.6.39.orig/drivers/spi/ar71xx_spi.c 1970-01-01 01:00:00.000000000 +0100
  23135. +++ linux-2.6.39/drivers/spi/ar71xx_spi.c 2011-04-27 12:19:22.317665385 +0200
  23136. @@ -0,0 +1,283 @@
  23137. +/*
  23138. + * Atheros AR71xx SPI Controller driver
  23139. + *
  23140. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  23141. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  23142. + *
  23143. + * This program is free software; you can redistribute it and/or modify
  23144. + * it under the terms of the GNU General Public License version 2 as
  23145. + * published by the Free Software Foundation.
  23146. + *
  23147. + */
  23148. +
  23149. +#include <linux/kernel.h>
  23150. +#include <linux/init.h>
  23151. +#include <linux/delay.h>
  23152. +#include <linux/spinlock.h>
  23153. +#include <linux/workqueue.h>
  23154. +#include <linux/platform_device.h>
  23155. +#include <linux/io.h>
  23156. +#include <linux/spi/spi.h>
  23157. +#include <linux/spi/spi_bitbang.h>
  23158. +#include <linux/bitops.h>
  23159. +
  23160. +#include <asm/mach-ar71xx/ar71xx.h>
  23161. +#include <asm/mach-ar71xx/platform.h>
  23162. +
  23163. +#define DRV_DESC "Atheros AR71xx SPI Controller driver"
  23164. +#define DRV_VERSION "0.2.4"
  23165. +#define DRV_NAME "ar71xx-spi"
  23166. +
  23167. +#undef PER_BIT_READ
  23168. +
  23169. +struct ar71xx_spi {
  23170. + struct spi_bitbang bitbang;
  23171. + u32 ioc_base;
  23172. + u32 reg_ctrl;
  23173. +
  23174. + void __iomem *base;
  23175. +
  23176. + struct platform_device *pdev;
  23177. + u32 (*get_ioc_base)(u8 chip_select, int cs_high,
  23178. + int is_on);
  23179. +};
  23180. +
  23181. +static inline u32 ar71xx_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  23182. +{
  23183. + return __raw_readl(sp->base + reg);
  23184. +}
  23185. +
  23186. +static inline void ar71xx_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  23187. +{
  23188. + __raw_writel(val, sp->base + reg);
  23189. +}
  23190. +
  23191. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  23192. +{
  23193. + return spi_master_get_devdata(spi->master);
  23194. +}
  23195. +
  23196. +static u32 ar71xx_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
  23197. +{
  23198. + u32 ret;
  23199. +
  23200. + if (is_on == AR71XX_SPI_CS_INACTIVE)
  23201. + ret = SPI_IOC_CS_ALL;
  23202. + else
  23203. + ret = SPI_IOC_CS_ALL & ~SPI_IOC_CS(chip_select);
  23204. +
  23205. + return ret;
  23206. +}
  23207. +
  23208. +static void ar71xx_spi_chipselect(struct spi_device *spi, int value)
  23209. +{
  23210. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  23211. + void __iomem *base = sp->base;
  23212. + u32 ioc_base;
  23213. +
  23214. + switch (value) {
  23215. + case BITBANG_CS_INACTIVE:
  23216. + ioc_base = sp->get_ioc_base(spi->chip_select,
  23217. + (spi->mode & SPI_CS_HIGH) != 0,
  23218. + AR71XX_SPI_CS_INACTIVE);
  23219. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  23220. + break;
  23221. +
  23222. + case BITBANG_CS_ACTIVE:
  23223. + ioc_base = sp->get_ioc_base(spi->chip_select,
  23224. + (spi->mode & SPI_CS_HIGH) != 0,
  23225. + AR71XX_SPI_CS_ACTIVE);
  23226. +
  23227. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  23228. + sp->ioc_base = ioc_base;
  23229. + break;
  23230. + }
  23231. +}
  23232. +
  23233. +static void ar71xx_spi_setup_regs(struct spi_device *spi)
  23234. +{
  23235. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  23236. +
  23237. + /* enable GPIO mode */
  23238. + ar71xx_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  23239. +
  23240. + /* save CTRL register */
  23241. + sp->reg_ctrl = ar71xx_spi_rr(sp, SPI_REG_CTRL);
  23242. +
  23243. + /* TODO: setup speed? */
  23244. + ar71xx_spi_wr(sp, SPI_REG_CTRL, 0x43);
  23245. +}
  23246. +
  23247. +static void ar71xx_spi_restore_regs(struct spi_device *spi)
  23248. +{
  23249. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  23250. +
  23251. + /* restore CTRL register */
  23252. + ar71xx_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  23253. + /* disable GPIO mode */
  23254. + ar71xx_spi_wr(sp, SPI_REG_FS, 0);
  23255. +}
  23256. +
  23257. +static int ar71xx_spi_setup(struct spi_device *spi)
  23258. +{
  23259. + int status;
  23260. +
  23261. + if (spi->bits_per_word > 32)
  23262. + return -EINVAL;
  23263. +
  23264. + if (!spi->controller_state)
  23265. + ar71xx_spi_setup_regs(spi);
  23266. +
  23267. + status = spi_bitbang_setup(spi);
  23268. + if (status && !spi->controller_state)
  23269. + ar71xx_spi_restore_regs(spi);
  23270. +
  23271. + return status;
  23272. +}
  23273. +
  23274. +static void ar71xx_spi_cleanup(struct spi_device *spi)
  23275. +{
  23276. + ar71xx_spi_restore_regs(spi);
  23277. + spi_bitbang_cleanup(spi);
  23278. +}
  23279. +
  23280. +static u32 ar71xx_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  23281. + u32 word, u8 bits)
  23282. +{
  23283. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  23284. + void __iomem *base = sp->base;
  23285. + u32 ioc = sp->ioc_base;
  23286. + u32 ret;
  23287. +
  23288. + /* clock starts at inactive polarity */
  23289. + for (word <<= (32 - bits); likely(bits); bits--) {
  23290. + u32 out;
  23291. +
  23292. + if (word & (1 << 31))
  23293. + out = ioc | SPI_IOC_DO;
  23294. + else
  23295. + out = ioc & ~SPI_IOC_DO;
  23296. +
  23297. + /* setup MSB (to slave) on trailing edge */
  23298. + __raw_writel(out, base + SPI_REG_IOC);
  23299. +
  23300. + __raw_writel(out | SPI_IOC_CLK, base + SPI_REG_IOC);
  23301. +
  23302. + word <<= 1;
  23303. +
  23304. +#ifdef PER_BIT_READ
  23305. + /* sample MSB (from slave) on leading edge */
  23306. + ret = __raw_readl(base + SPI_REG_RDS);
  23307. + __raw_writel(out, base + SPI_REG_IOC);
  23308. +#endif
  23309. +
  23310. + }
  23311. +
  23312. +#ifndef PER_BIT_READ
  23313. + ret = __raw_readl(base + SPI_REG_RDS);
  23314. +#endif
  23315. + return ret;
  23316. +}
  23317. +
  23318. +static int ar71xx_spi_probe(struct platform_device *pdev)
  23319. +{
  23320. + struct spi_master *master;
  23321. + struct ar71xx_spi *sp;
  23322. + struct ar71xx_spi_platform_data *pdata;
  23323. + struct resource *r;
  23324. + int ret;
  23325. +
  23326. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  23327. + if (master == NULL) {
  23328. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  23329. + return -ENOMEM;
  23330. + }
  23331. +
  23332. + sp = spi_master_get_devdata(master);
  23333. + platform_set_drvdata(pdev, sp);
  23334. +
  23335. + pdata = pdev->dev.platform_data;
  23336. +
  23337. + master->setup = ar71xx_spi_setup;
  23338. + master->cleanup = ar71xx_spi_cleanup;
  23339. +
  23340. + sp->bitbang.master = spi_master_get(master);
  23341. + sp->bitbang.chipselect = ar71xx_spi_chipselect;
  23342. + sp->bitbang.txrx_word[SPI_MODE_0] = ar71xx_spi_txrx_mode0;
  23343. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  23344. +
  23345. + sp->get_ioc_base = ar71xx_spi_get_ioc_base;
  23346. + if (pdata) {
  23347. + sp->bitbang.master->bus_num = pdata->bus_num;
  23348. + sp->bitbang.master->num_chipselect = pdata->num_chipselect;
  23349. + if (pdata->get_ioc_base)
  23350. + sp->get_ioc_base = pdata->get_ioc_base;
  23351. + } else {
  23352. + sp->bitbang.master->bus_num = 0;
  23353. + sp->bitbang.master->num_chipselect = 3;
  23354. + }
  23355. +
  23356. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  23357. + if (r == NULL) {
  23358. + ret = -ENOENT;
  23359. + goto err1;
  23360. + }
  23361. +
  23362. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  23363. + if (!sp->base) {
  23364. + ret = -ENXIO;
  23365. + goto err1;
  23366. + }
  23367. +
  23368. + ret = spi_bitbang_start(&sp->bitbang);
  23369. + if (!ret)
  23370. + return 0;
  23371. +
  23372. + iounmap(sp->base);
  23373. +err1:
  23374. + platform_set_drvdata(pdev, NULL);
  23375. + spi_master_put(sp->bitbang.master);
  23376. +
  23377. + return ret;
  23378. +}
  23379. +
  23380. +static int ar71xx_spi_remove(struct platform_device *pdev)
  23381. +{
  23382. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  23383. +
  23384. + spi_bitbang_stop(&sp->bitbang);
  23385. + iounmap(sp->base);
  23386. + platform_set_drvdata(pdev, NULL);
  23387. + spi_master_put(sp->bitbang.master);
  23388. +
  23389. + return 0;
  23390. +}
  23391. +
  23392. +static struct platform_driver ar71xx_spi_drv = {
  23393. + .probe = ar71xx_spi_probe,
  23394. + .remove = ar71xx_spi_remove,
  23395. + .driver = {
  23396. + .name = DRV_NAME,
  23397. + .owner = THIS_MODULE,
  23398. + },
  23399. +};
  23400. +
  23401. +static int __init ar71xx_spi_init(void)
  23402. +{
  23403. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  23404. + return platform_driver_register(&ar71xx_spi_drv);
  23405. +}
  23406. +module_init(ar71xx_spi_init);
  23407. +
  23408. +static void __exit ar71xx_spi_exit(void)
  23409. +{
  23410. + platform_driver_unregister(&ar71xx_spi_drv);
  23411. +}
  23412. +module_exit(ar71xx_spi_exit);
  23413. +
  23414. +MODULE_ALIAS("platform:" DRV_NAME);
  23415. +MODULE_DESCRIPTION(DRV_DESC);
  23416. +MODULE_VERSION(DRV_VERSION);
  23417. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  23418. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  23419. +MODULE_LICENSE("GPL v2");
  23420. diff -Nur linux-2.6.39.orig/drivers/spi/Kconfig linux-2.6.39/drivers/spi/Kconfig
  23421. --- linux-2.6.39.orig/drivers/spi/Kconfig 2011-05-19 06:06:34.000000000 +0200
  23422. +++ linux-2.6.39/drivers/spi/Kconfig 2011-08-23 15:10:24.167989908 +0200
  23423. @@ -67,6 +67,13 @@
  23424. This enables support for the SPI controller present on the
  23425. Atheros AR71XX/AR724X/AR913X SoCs.
  23426. +config SPI_AR71XX
  23427. + tristate "Atheros AR71xx SPI Controller"
  23428. + depends on SPI_MASTER && ATHEROS_AR71XX
  23429. + select SPI_BITBANG
  23430. + help
  23431. + This is the SPI contoller driver for Atheros AR71xx.
  23432. +
  23433. config SPI_ATMEL
  23434. tristate "Atmel SPI Controller"
  23435. depends on (ARCH_AT91 || AVR32)
  23436. @@ -301,6 +308,12 @@
  23437. config SPI_PXA2XX_PCI
  23438. def_bool SPI_PXA2XX && X86_32 && PCI
  23439. +config SPI_RB4XX
  23440. + tristate "Mikrotik RB4XX SPI master"
  23441. + depends on SPI_MASTER && AR71XX_MACH_RB4XX
  23442. + help
  23443. + SPI controller driver for the Mikrotik RB4xx series boards.
  23444. +
  23445. config SPI_S3C24XX
  23446. tristate "Samsung S3C24XX series SPI"
  23447. depends on ARCH_S3C2410 && EXPERIMENTAL
  23448. @@ -457,6 +470,13 @@
  23449. sysfs interface, with each line presented as a kind of GPIO
  23450. exposing both switch control and diagnostic feedback.
  23451. +config SPI_RB4XX_CPLD
  23452. + tristate "MikroTik RB4XX CPLD driver"
  23453. + depends on AR71XX_MACH_RB4XX
  23454. + help
  23455. + SPI driver for the Xilinx CPLD chip present on the
  23456. + MikroTik RB4xx boards.
  23457. +
  23458. #
  23459. # Add new SPI protocol masters in alphabetical order above this line
  23460. #
  23461. diff -Nur linux-2.6.39.orig/drivers/spi/Kconfig.orig linux-2.6.39/drivers/spi/Kconfig.orig
  23462. --- linux-2.6.39.orig/drivers/spi/Kconfig.orig 1970-01-01 01:00:00.000000000 +0100
  23463. +++ linux-2.6.39/drivers/spi/Kconfig.orig 2011-08-23 15:10:11.277991848 +0200
  23464. @@ -0,0 +1,482 @@
  23465. +#
  23466. +# SPI driver configuration
  23467. +#
  23468. +# NOTE: the reason this doesn't show SPI slave support is mostly that
  23469. +# nobody's needed a slave side API yet. The master-role API is not
  23470. +# fully appropriate there, so it'd need some thought to do well.
  23471. +#
  23472. +menuconfig SPI
  23473. + bool "SPI support"
  23474. + depends on HAS_IOMEM
  23475. + help
  23476. + The "Serial Peripheral Interface" is a low level synchronous
  23477. + protocol. Chips that support SPI can have data transfer rates
  23478. + up to several tens of Mbit/sec. Chips are addressed with a
  23479. + controller and a chipselect. Most SPI slaves don't support
  23480. + dynamic device discovery; some are even write-only or read-only.
  23481. +
  23482. + SPI is widely used by microcontrollers to talk with sensors,
  23483. + eeprom and flash memory, codecs and various other controller
  23484. + chips, analog to digital (and d-to-a) converters, and more.
  23485. + MMC and SD cards can be accessed using SPI protocol; and for
  23486. + DataFlash cards used in MMC sockets, SPI must always be used.
  23487. +
  23488. + SPI is one of a family of similar protocols using a four wire
  23489. + interface (select, clock, data in, data out) including Microwire
  23490. + (half duplex), SSP, SSI, and PSP. This driver framework should
  23491. + work with most such devices and controllers.
  23492. +
  23493. +if SPI
  23494. +
  23495. +config SPI_DEBUG
  23496. + boolean "Debug support for SPI drivers"
  23497. + depends on DEBUG_KERNEL
  23498. + help
  23499. + Say "yes" to enable debug messaging (like dev_dbg and pr_debug),
  23500. + sysfs, and debugfs support in SPI controller and protocol drivers.
  23501. +
  23502. +#
  23503. +# MASTER side ... talking to discrete SPI slave chips including microcontrollers
  23504. +#
  23505. +
  23506. +config SPI_MASTER
  23507. +# boolean "SPI Master Support"
  23508. + boolean
  23509. + default SPI
  23510. + help
  23511. + If your system has an master-capable SPI controller (which
  23512. + provides the clock and chipselect), you can enable that
  23513. + controller and the protocol drivers for the SPI slave chips
  23514. + that are connected.
  23515. +
  23516. +if SPI_MASTER
  23517. +
  23518. +comment "SPI Master Controller Drivers"
  23519. +
  23520. +config SPI_ALTERA
  23521. + tristate "Altera SPI Controller"
  23522. + select SPI_BITBANG
  23523. + help
  23524. + This is the driver for the Altera SPI Controller.
  23525. +
  23526. +config SPI_ATH79
  23527. + tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver"
  23528. + depends on ATH79 && GENERIC_GPIO
  23529. + select SPI_BITBANG
  23530. + help
  23531. + This enables support for the SPI controller present on the
  23532. + Atheros AR71XX/AR724X/AR913X SoCs.
  23533. +
  23534. +config SPI_AR71XX
  23535. + tristate "Atheros AR71xx SPI Controller"
  23536. + depends on SPI_MASTER && ATHEROS_AR71XX
  23537. + select SPI_BITBANG
  23538. + help
  23539. + This is the SPI contoller driver for Atheros AR71xx.
  23540. +
  23541. +config SPI_ATMEL
  23542. + tristate "Atmel SPI Controller"
  23543. + depends on (ARCH_AT91 || AVR32)
  23544. + help
  23545. + This selects a driver for the Atmel SPI Controller, present on
  23546. + many AT32 (AVR32) and AT91 (ARM) chips.
  23547. +
  23548. +config SPI_BFIN
  23549. + tristate "SPI controller driver for ADI Blackfin5xx"
  23550. + depends on BLACKFIN
  23551. + help
  23552. + This is the SPI controller master driver for Blackfin 5xx processor.
  23553. +
  23554. +config SPI_AU1550
  23555. + tristate "Au1550/Au12x0 SPI Controller"
  23556. + depends on (SOC_AU1550 || SOC_AU1200) && EXPERIMENTAL
  23557. + select SPI_BITBANG
  23558. + help
  23559. + If you say yes to this option, support will be included for the
  23560. + Au1550 SPI controller (may also work with Au1200,Au1210,Au1250).
  23561. +
  23562. + This driver can also be built as a module. If so, the module
  23563. + will be called au1550_spi.
  23564. +
  23565. +config SPI_BITBANG
  23566. + tristate "Utilities for Bitbanging SPI masters"
  23567. + help
  23568. + With a few GPIO pins, your system can bitbang the SPI protocol.
  23569. + Select this to get SPI support through I/O pins (GPIO, parallel
  23570. + port, etc). Or, some systems' SPI master controller drivers use
  23571. + this code to manage the per-word or per-transfer accesses to the
  23572. + hardware shift registers.
  23573. +
  23574. + This is library code, and is automatically selected by drivers that
  23575. + need it. You only need to select this explicitly to support driver
  23576. + modules that aren't part of this kernel tree.
  23577. +
  23578. +config SPI_BUTTERFLY
  23579. + tristate "Parallel port adapter for AVR Butterfly (DEVELOPMENT)"
  23580. + depends on PARPORT
  23581. + select SPI_BITBANG
  23582. + help
  23583. + This uses a custom parallel port cable to connect to an AVR
  23584. + Butterfly <http://www.atmel.com/products/avr/butterfly>, an
  23585. + inexpensive battery powered microcontroller evaluation board.
  23586. + This same cable can be used to flash new firmware.
  23587. +
  23588. +config SPI_COLDFIRE_QSPI
  23589. + tristate "Freescale Coldfire QSPI controller"
  23590. + depends on (M520x || M523x || M5249 || M527x || M528x || M532x)
  23591. + help
  23592. + This enables support for the Coldfire QSPI controller in master
  23593. + mode.
  23594. +
  23595. + This driver can also be built as a module. If so, the module
  23596. + will be called coldfire_qspi.
  23597. +
  23598. +config SPI_DAVINCI
  23599. + tristate "Texas Instruments DaVinci/DA8x/OMAP-L/AM1x SoC SPI controller"
  23600. + depends on SPI_MASTER && ARCH_DAVINCI
  23601. + select SPI_BITBANG
  23602. + help
  23603. + SPI master controller for DaVinci/DA8x/OMAP-L/AM1x SPI modules.
  23604. +
  23605. + This driver can also be built as a module. The module will be called
  23606. + davinci_spi.
  23607. +
  23608. +config SPI_EP93XX
  23609. + tristate "Cirrus Logic EP93xx SPI controller"
  23610. + depends on ARCH_EP93XX
  23611. + help
  23612. + This enables using the Cirrus EP93xx SPI controller in master
  23613. + mode.
  23614. +
  23615. + To compile this driver as a module, choose M here. The module will be
  23616. + called ep93xx_spi.
  23617. +
  23618. +config SPI_GPIO
  23619. + tristate "GPIO-based bitbanging SPI Master"
  23620. + depends on GENERIC_GPIO
  23621. + select SPI_BITBANG
  23622. + help
  23623. + This simple GPIO bitbanging SPI master uses the arch-neutral GPIO
  23624. + interface to manage MOSI, MISO, SCK, and chipselect signals. SPI
  23625. + slaves connected to a bus using this driver are configured as usual,
  23626. + except that the spi_board_info.controller_data holds the GPIO number
  23627. + for the chipselect used by this controller driver.
  23628. +
  23629. + Note that this driver often won't achieve even 1 Mbit/sec speeds,
  23630. + making it unusually slow for SPI. If your platform can inline
  23631. + GPIO operations, you should be able to leverage that for better
  23632. + speed with a custom version of this driver; see the source code.
  23633. +
  23634. +config SPI_IMX_VER_IMX1
  23635. + def_bool y if SOC_IMX1
  23636. +
  23637. +config SPI_IMX_VER_0_0
  23638. + def_bool y if SOC_IMX21 || SOC_IMX27
  23639. +
  23640. +config SPI_IMX_VER_0_4
  23641. + def_bool y if SOC_IMX31
  23642. +
  23643. +config SPI_IMX_VER_0_7
  23644. + def_bool y if ARCH_MX25 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
  23645. +
  23646. +config SPI_IMX_VER_2_3
  23647. + def_bool y if SOC_IMX51 || SOC_IMX53
  23648. +
  23649. +config SPI_IMX
  23650. + tristate "Freescale i.MX SPI controllers"
  23651. + depends on ARCH_MXC
  23652. + select SPI_BITBANG
  23653. + default m if IMX_HAVE_PLATFORM_SPI_IMX
  23654. + help
  23655. + This enables using the Freescale i.MX SPI controllers in master
  23656. + mode.
  23657. +
  23658. +config SPI_LM70_LLP
  23659. + tristate "Parallel port adapter for LM70 eval board (DEVELOPMENT)"
  23660. + depends on PARPORT && EXPERIMENTAL
  23661. + select SPI_BITBANG
  23662. + help
  23663. + This driver supports the NS LM70 LLP Evaluation Board,
  23664. + which interfaces to an LM70 temperature sensor using
  23665. + a parallel port.
  23666. +
  23667. +config SPI_MPC52xx
  23668. + tristate "Freescale MPC52xx SPI (non-PSC) controller support"
  23669. + depends on PPC_MPC52xx && SPI
  23670. + select SPI_MASTER_OF
  23671. + help
  23672. + This drivers supports the MPC52xx SPI controller in master SPI
  23673. + mode.
  23674. +
  23675. +config SPI_MPC52xx_PSC
  23676. + tristate "Freescale MPC52xx PSC SPI controller"
  23677. + depends on PPC_MPC52xx && EXPERIMENTAL
  23678. + help
  23679. + This enables using the Freescale MPC52xx Programmable Serial
  23680. + Controller in master SPI mode.
  23681. +
  23682. +config SPI_MPC512x_PSC
  23683. + tristate "Freescale MPC512x PSC SPI controller"
  23684. + depends on SPI_MASTER && PPC_MPC512x
  23685. + help
  23686. + This enables using the Freescale MPC5121 Programmable Serial
  23687. + Controller in SPI master mode.
  23688. +
  23689. +config SPI_FSL_LIB
  23690. + tristate
  23691. + depends on FSL_SOC
  23692. +
  23693. +config SPI_FSL_SPI
  23694. + tristate "Freescale SPI controller"
  23695. + depends on FSL_SOC
  23696. + select SPI_FSL_LIB
  23697. + help
  23698. + This enables using the Freescale SPI controllers in master mode.
  23699. + MPC83xx platform uses the controller in cpu mode or CPM/QE mode.
  23700. + MPC8569 uses the controller in QE mode, MPC8610 in cpu mode.
  23701. +
  23702. +config SPI_FSL_ESPI
  23703. + tristate "Freescale eSPI controller"
  23704. + depends on FSL_SOC
  23705. + select SPI_FSL_LIB
  23706. + help
  23707. + This enables using the Freescale eSPI controllers in master mode.
  23708. + From MPC8536, 85xx platform uses the controller, and all P10xx,
  23709. + P20xx, P30xx,P40xx, P50xx uses this controller.
  23710. +
  23711. +config SPI_OC_TINY
  23712. + tristate "OpenCores tiny SPI"
  23713. + depends on GENERIC_GPIO
  23714. + select SPI_BITBANG
  23715. + help
  23716. + This is the driver for OpenCores tiny SPI master controller.
  23717. +
  23718. +config SPI_OMAP_UWIRE
  23719. + tristate "OMAP1 MicroWire"
  23720. + depends on ARCH_OMAP1
  23721. + select SPI_BITBANG
  23722. + help
  23723. + This hooks up to the MicroWire controller on OMAP1 chips.
  23724. +
  23725. +config SPI_OMAP24XX
  23726. + tristate "McSPI driver for OMAP"
  23727. + depends on ARCH_OMAP2PLUS
  23728. + help
  23729. + SPI master controller for OMAP24XX and later Multichannel SPI
  23730. + (McSPI) modules.
  23731. +
  23732. +config SPI_OMAP_100K
  23733. + tristate "OMAP SPI 100K"
  23734. + depends on SPI_MASTER && (ARCH_OMAP850 || ARCH_OMAP730)
  23735. + help
  23736. + OMAP SPI 100K master controller for omap7xx boards.
  23737. +
  23738. +config SPI_ORION
  23739. + tristate "Orion SPI master (EXPERIMENTAL)"
  23740. + depends on PLAT_ORION && EXPERIMENTAL
  23741. + help
  23742. + This enables using the SPI master controller on the Orion chips.
  23743. +
  23744. +config SPI_PL022
  23745. + tristate "ARM AMBA PL022 SSP controller (EXPERIMENTAL)"
  23746. + depends on ARM_AMBA && EXPERIMENTAL
  23747. + default y if MACH_U300
  23748. + default y if ARCH_REALVIEW
  23749. + default y if INTEGRATOR_IMPD1
  23750. + default y if ARCH_VERSATILE
  23751. + help
  23752. + This selects the ARM(R) AMBA(R) PrimeCell PL022 SSP
  23753. + controller. If you have an embedded system with an AMBA(R)
  23754. + bus and a PL022 controller, say Y or M here.
  23755. +
  23756. +config SPI_PPC4xx
  23757. + tristate "PPC4xx SPI Controller"
  23758. + depends on PPC32 && 4xx && SPI_MASTER
  23759. + select SPI_BITBANG
  23760. + help
  23761. + This selects a driver for the PPC4xx SPI Controller.
  23762. +
  23763. +config SPI_PXA2XX
  23764. + tristate "PXA2xx SSP SPI master"
  23765. + depends on (ARCH_PXA || (X86_32 && PCI)) && EXPERIMENTAL
  23766. + select PXA_SSP if ARCH_PXA
  23767. + help
  23768. + This enables using a PXA2xx or Sodaville SSP port as a SPI master
  23769. + controller. The driver can be configured to use any SSP port and
  23770. + additional documentation can be found a Documentation/spi/pxa2xx.
  23771. +
  23772. +config SPI_PXA2XX_PCI
  23773. + def_bool SPI_PXA2XX && X86_32 && PCI
  23774. +
  23775. +config SPI_S3C24XX
  23776. + tristate "Samsung S3C24XX series SPI"
  23777. + depends on ARCH_S3C2410 && EXPERIMENTAL
  23778. + select SPI_BITBANG
  23779. + help
  23780. + SPI driver for Samsung S3C24XX series ARM SoCs
  23781. +
  23782. +config SPI_S3C24XX_FIQ
  23783. + bool "S3C24XX driver with FIQ pseudo-DMA"
  23784. + depends on SPI_S3C24XX
  23785. + select FIQ
  23786. + help
  23787. + Enable FIQ support for the S3C24XX SPI driver to provide pseudo
  23788. + DMA by using the fast-interrupt request framework, This allows
  23789. + the driver to get DMA-like performance when there are either
  23790. + no free DMA channels, or when doing transfers that required both
  23791. + TX and RX data paths.
  23792. +
  23793. +config SPI_S3C24XX_GPIO
  23794. + tristate "Samsung S3C24XX series SPI by GPIO"
  23795. + depends on ARCH_S3C2410 && EXPERIMENTAL
  23796. + select SPI_BITBANG
  23797. + help
  23798. + SPI driver for Samsung S3C24XX series ARM SoCs using
  23799. + GPIO lines to provide the SPI bus. This can be used where
  23800. + the inbuilt hardware cannot provide the transfer mode, or
  23801. + where the board is using non hardware connected pins.
  23802. +
  23803. +config SPI_S3C64XX
  23804. + tristate "Samsung S3C64XX series type SPI"
  23805. + depends on (ARCH_S3C64XX || ARCH_S5P64X0)
  23806. + select S3C64XX_DMA if ARCH_S3C64XX
  23807. + help
  23808. + SPI driver for Samsung S3C64XX and newer SoCs.
  23809. +
  23810. +config SPI_SH_MSIOF
  23811. + tristate "SuperH MSIOF SPI controller"
  23812. + depends on SUPERH && HAVE_CLK
  23813. + select SPI_BITBANG
  23814. + help
  23815. + SPI driver for SuperH MSIOF blocks.
  23816. +
  23817. +config SPI_SH
  23818. + tristate "SuperH SPI controller"
  23819. + depends on SUPERH
  23820. + help
  23821. + SPI driver for SuperH SPI blocks.
  23822. +
  23823. +config SPI_SH_SCI
  23824. + tristate "SuperH SCI SPI controller"
  23825. + depends on SUPERH
  23826. + select SPI_BITBANG
  23827. + help
  23828. + SPI driver for SuperH SCI blocks.
  23829. +
  23830. +config SPI_STMP3XXX
  23831. + tristate "Freescale STMP37xx/378x SPI/SSP controller"
  23832. + depends on ARCH_STMP3XXX && SPI_MASTER
  23833. + help
  23834. + SPI driver for Freescale STMP37xx/378x SoC SSP interface
  23835. +
  23836. +config SPI_TEGRA
  23837. + tristate "Nvidia Tegra SPI controller"
  23838. + depends on ARCH_TEGRA
  23839. + select TEGRA_SYSTEM_DMA
  23840. + help
  23841. + SPI driver for NVidia Tegra SoCs
  23842. +
  23843. +config SPI_TI_SSP
  23844. + tristate "TI Sequencer Serial Port - SPI Support"
  23845. + depends on MFD_TI_SSP
  23846. + help
  23847. + This selects an SPI master implementation using a TI sequencer
  23848. + serial port.
  23849. +
  23850. + To compile this driver as a module, choose M here: the
  23851. + module will be called ti-ssp-spi.
  23852. +
  23853. +config SPI_TOPCLIFF_PCH
  23854. + tristate "Topcliff PCH SPI Controller"
  23855. + depends on PCI
  23856. + help
  23857. + SPI driver for the Topcliff PCH (Platform Controller Hub) SPI bus
  23858. + used in some x86 embedded processors.
  23859. +
  23860. +config SPI_TXX9
  23861. + tristate "Toshiba TXx9 SPI controller"
  23862. + depends on GENERIC_GPIO && CPU_TX49XX
  23863. + help
  23864. + SPI driver for Toshiba TXx9 MIPS SoCs
  23865. +
  23866. +config SPI_XILINX
  23867. + tristate "Xilinx SPI controller common module"
  23868. + depends on HAS_IOMEM && EXPERIMENTAL
  23869. + select SPI_BITBANG
  23870. + help
  23871. + This exposes the SPI controller IP from the Xilinx EDK.
  23872. +
  23873. + See the "OPB Serial Peripheral Interface (SPI) (v1.00e)"
  23874. + Product Specification document (DS464) for hardware details.
  23875. +
  23876. + Or for the DS570, see "XPS Serial Peripheral Interface (SPI) (v2.00b)"
  23877. +
  23878. +config SPI_NUC900
  23879. + tristate "Nuvoton NUC900 series SPI"
  23880. + depends on ARCH_W90X900 && EXPERIMENTAL
  23881. + select SPI_BITBANG
  23882. + help
  23883. + SPI driver for Nuvoton NUC900 series ARM SoCs
  23884. +
  23885. +#
  23886. +# Add new SPI master controllers in alphabetical order above this line
  23887. +#
  23888. +
  23889. +config SPI_DESIGNWARE
  23890. + tristate "DesignWare SPI controller core support"
  23891. + depends on SPI_MASTER
  23892. + help
  23893. + general driver for SPI controller core from DesignWare
  23894. +
  23895. +config SPI_DW_PCI
  23896. + tristate "PCI interface driver for DW SPI core"
  23897. + depends on SPI_DESIGNWARE && PCI
  23898. +
  23899. +config SPI_DW_MID_DMA
  23900. + bool "DMA support for DW SPI controller on Intel Moorestown platform"
  23901. + depends on SPI_DW_PCI && INTEL_MID_DMAC
  23902. +
  23903. +config SPI_DW_MMIO
  23904. + tristate "Memory-mapped io interface driver for DW SPI core"
  23905. + depends on SPI_DESIGNWARE && HAVE_CLK
  23906. +
  23907. +#
  23908. +# There are lots of SPI device types, with sensors and memory
  23909. +# being probably the most widely used ones.
  23910. +#
  23911. +comment "SPI Protocol Masters"
  23912. +
  23913. +config SPI_SPIDEV
  23914. + tristate "User mode SPI device driver support"
  23915. + depends on EXPERIMENTAL
  23916. + help
  23917. + This supports user mode SPI protocol drivers.
  23918. +
  23919. + Note that this application programming interface is EXPERIMENTAL
  23920. + and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes.
  23921. +
  23922. +config SPI_TLE62X0
  23923. + tristate "Infineon TLE62X0 (for power switching)"
  23924. + depends on SYSFS
  23925. + help
  23926. + SPI driver for Infineon TLE62X0 series line driver chips,
  23927. + such as the TLE6220, TLE6230 and TLE6240. This provides a
  23928. + sysfs interface, with each line presented as a kind of GPIO
  23929. + exposing both switch control and diagnostic feedback.
  23930. +
  23931. +config SPI_RB4XX_CPLD
  23932. + tristate "MikroTik RB4XX CPLD driver"
  23933. + depends on AR71XX_MACH_RB4XX
  23934. + help
  23935. + SPI driver for the Xilinx CPLD chip present on the
  23936. + MikroTik RB4xx boards.
  23937. +
  23938. +#
  23939. +# Add new SPI protocol masters in alphabetical order above this line
  23940. +#
  23941. +
  23942. +endif # SPI_MASTER
  23943. +
  23944. +# (slave support would go here)
  23945. +
  23946. +endif # SPI
  23947. diff -Nur linux-2.6.39.orig/drivers/spi/Makefile linux-2.6.39/drivers/spi/Makefile
  23948. --- linux-2.6.39.orig/drivers/spi/Makefile 2011-05-19 06:06:34.000000000 +0200
  23949. +++ linux-2.6.39/drivers/spi/Makefile 2011-08-23 15:10:24.199233941 +0200
  23950. @@ -10,6 +10,7 @@
  23951. # SPI master controller drivers (bus)
  23952. obj-$(CONFIG_SPI_ALTERA) += spi_altera.o
  23953. +obj-$(CONFIG_SPI_AR71XX) += ar71xx_spi.o
  23954. obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o
  23955. obj-$(CONFIG_SPI_ATH79) += ath79_spi.o
  23956. obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
  23957. @@ -54,6 +55,7 @@
  23958. obj-$(CONFIG_SPI_SH_MSIOF) += spi_sh_msiof.o
  23959. obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
  23960. obj-$(CONFIG_SPI_NUC900) += spi_nuc900.o
  23961. +obj-$(CONFIG_SPI_RB4XX) += rb4xx_spi.o
  23962. # special build for s3c24xx spi driver with fiq support
  23963. spi_s3c24xx_hw-y := spi_s3c24xx.o
  23964. @@ -62,6 +64,7 @@
  23965. # ... add above this line ...
  23966. # SPI protocol drivers (device/link on bus)
  23967. +obj-$(CONFIG_SPI_RB4XX_CPLD) += spi_rb4xx_cpld.o
  23968. obj-$(CONFIG_SPI_SPIDEV) += spidev.o
  23969. obj-$(CONFIG_SPI_TLE62X0) += tle62x0.o
  23970. # ... add above this line ...
  23971. diff -Nur linux-2.6.39.orig/drivers/spi/Makefile.orig linux-2.6.39/drivers/spi/Makefile.orig
  23972. --- linux-2.6.39.orig/drivers/spi/Makefile.orig 1970-01-01 01:00:00.000000000 +0100
  23973. +++ linux-2.6.39/drivers/spi/Makefile.orig 2011-08-23 15:10:11.300479072 +0200
  23974. @@ -0,0 +1,75 @@
  23975. +#
  23976. +# Makefile for kernel SPI drivers.
  23977. +#
  23978. +
  23979. +ccflags-$(CONFIG_SPI_DEBUG) := -DDEBUG
  23980. +
  23981. +# small core, mostly translating board-specific
  23982. +# config declarations into driver model code
  23983. +obj-$(CONFIG_SPI_MASTER) += spi.o
  23984. +
  23985. +# SPI master controller drivers (bus)
  23986. +obj-$(CONFIG_SPI_ALTERA) += spi_altera.o
  23987. +obj-$(CONFIG_SPI_AR71XX) += ar71xx_spi.o
  23988. +obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o
  23989. +obj-$(CONFIG_SPI_ATH79) += ath79_spi.o
  23990. +obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
  23991. +obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
  23992. +obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
  23993. +obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
  23994. +obj-$(CONFIG_SPI_COLDFIRE_QSPI) += coldfire_qspi.o
  23995. +obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o
  23996. +obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o
  23997. +obj-$(CONFIG_SPI_DW_PCI) += dw_spi_midpci.o
  23998. +dw_spi_midpci-objs := dw_spi_pci.o dw_spi_mid.o
  23999. +obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o
  24000. +obj-$(CONFIG_SPI_EP93XX) += ep93xx_spi.o
  24001. +obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
  24002. +obj-$(CONFIG_SPI_IMX) += spi_imx.o
  24003. +obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
  24004. +obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
  24005. +obj-$(CONFIG_SPI_PXA2XX_PCI) += pxa2xx_spi_pci.o
  24006. +obj-$(CONFIG_SPI_OC_TINY) += spi_oc_tiny.o
  24007. +obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o
  24008. +obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o
  24009. +obj-$(CONFIG_SPI_OMAP_100K) += omap_spi_100k.o
  24010. +obj-$(CONFIG_SPI_ORION) += orion_spi.o
  24011. +obj-$(CONFIG_SPI_PL022) += amba-pl022.o
  24012. +obj-$(CONFIG_SPI_MPC512x_PSC) += mpc512x_psc_spi.o
  24013. +obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
  24014. +obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o
  24015. +obj-$(CONFIG_SPI_FSL_LIB) += spi_fsl_lib.o
  24016. +obj-$(CONFIG_SPI_FSL_ESPI) += spi_fsl_espi.o
  24017. +obj-$(CONFIG_SPI_FSL_SPI) += spi_fsl_spi.o
  24018. +obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o
  24019. +obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
  24020. +obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx_hw.o
  24021. +obj-$(CONFIG_SPI_S3C64XX) += spi_s3c64xx.o
  24022. +obj-$(CONFIG_SPI_TEGRA) += spi_tegra.o
  24023. +obj-$(CONFIG_SPI_TI_SSP) += ti-ssp-spi.o
  24024. +obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi_topcliff_pch.o
  24025. +obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
  24026. +obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o
  24027. +obj-$(CONFIG_SPI_SH) += spi_sh.o
  24028. +obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.o
  24029. +obj-$(CONFIG_SPI_SH_MSIOF) += spi_sh_msiof.o
  24030. +obj-$(CONFIG_SPI_STMP3XXX) += spi_stmp.o
  24031. +obj-$(CONFIG_SPI_NUC900) += spi_nuc900.o
  24032. +
  24033. +# special build for s3c24xx spi driver with fiq support
  24034. +spi_s3c24xx_hw-y := spi_s3c24xx.o
  24035. +spi_s3c24xx_hw-$(CONFIG_SPI_S3C24XX_FIQ) += spi_s3c24xx_fiq.o
  24036. +
  24037. +# ... add above this line ...
  24038. +
  24039. +# SPI protocol drivers (device/link on bus)
  24040. +obj-$(CONFIG_SPI_RB4XX_CPLD) += spi_rb4xx_cpld.o
  24041. +obj-$(CONFIG_SPI_SPIDEV) += spidev.o
  24042. +obj-$(CONFIG_SPI_TLE62X0) += tle62x0.o
  24043. +# ... add above this line ...
  24044. +
  24045. +# SPI slave controller drivers (upstream link)
  24046. +# ... add above this line ...
  24047. +
  24048. +# SPI slave drivers (protocol for that link)
  24049. +# ... add above this line ...
  24050. diff -Nur linux-2.6.39.orig/drivers/spi/pb44_spi.c linux-2.6.39/drivers/spi/pb44_spi.c
  24051. --- linux-2.6.39.orig/drivers/spi/pb44_spi.c 1970-01-01 01:00:00.000000000 +0100
  24052. +++ linux-2.6.39/drivers/spi/pb44_spi.c 2011-04-27 12:19:22.317665385 +0200
  24053. @@ -0,0 +1,299 @@
  24054. +/*
  24055. + * Atheros PB44 board SPI controller driver
  24056. + *
  24057. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  24058. + *
  24059. + * This program is free software; you can redistribute it and/or modify
  24060. + * it under the terms of the GNU General Public License version 2 as
  24061. + * published by the Free Software Foundation.
  24062. + *
  24063. + */
  24064. +
  24065. +#include <linux/kernel.h>
  24066. +#include <linux/init.h>
  24067. +#include <linux/delay.h>
  24068. +#include <linux/spinlock.h>
  24069. +#include <linux/workqueue.h>
  24070. +#include <linux/platform_device.h>
  24071. +#include <linux/io.h>
  24072. +#include <linux/spi/spi.h>
  24073. +#include <linux/spi/spi_bitbang.h>
  24074. +#include <linux/bitops.h>
  24075. +#include <linux/gpio.h>
  24076. +
  24077. +#include <asm/mach-ar71xx/ar71xx.h>
  24078. +#include <asm/mach-ar71xx/platform.h>
  24079. +
  24080. +#define DRV_DESC "Atheros PB44 SPI Controller driver"
  24081. +#define DRV_VERSION "0.1.0"
  24082. +#define DRV_NAME "pb44-spi"
  24083. +
  24084. +#undef PER_BIT_READ
  24085. +
  24086. +struct ar71xx_spi {
  24087. + struct spi_bitbang bitbang;
  24088. + u32 ioc_base;
  24089. + u32 reg_ctrl;
  24090. +
  24091. + void __iomem *base;
  24092. +
  24093. + struct platform_device *pdev;
  24094. +};
  24095. +
  24096. +static inline u32 pb44_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  24097. +{
  24098. + return __raw_readl(sp->base + reg);
  24099. +}
  24100. +
  24101. +static inline void pb44_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  24102. +{
  24103. + __raw_writel(val, sp->base + reg);
  24104. +}
  24105. +
  24106. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  24107. +{
  24108. + return spi_master_get_devdata(spi->master);
  24109. +}
  24110. +
  24111. +static void pb44_spi_chipselect(struct spi_device *spi, int is_active)
  24112. +{
  24113. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  24114. + int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
  24115. +
  24116. + if (is_active) {
  24117. + /* set initial clock polarity */
  24118. + if (spi->mode & SPI_CPOL)
  24119. + sp->ioc_base |= SPI_IOC_CLK;
  24120. + else
  24121. + sp->ioc_base &= ~SPI_IOC_CLK;
  24122. +
  24123. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  24124. + }
  24125. +
  24126. + if (spi->chip_select) {
  24127. + unsigned long gpio = (unsigned long) spi->controller_data;
  24128. +
  24129. + /* SPI is normally active-low */
  24130. + gpio_set_value(gpio, cs_high);
  24131. + } else {
  24132. + if (cs_high)
  24133. + sp->ioc_base |= SPI_IOC_CS0;
  24134. + else
  24135. + sp->ioc_base &= ~SPI_IOC_CS0;
  24136. +
  24137. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  24138. + }
  24139. +
  24140. +}
  24141. +
  24142. +static int pb44_spi_setup_cs(struct spi_device *spi)
  24143. +{
  24144. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  24145. +
  24146. + /* enable GPIO mode */
  24147. + pb44_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  24148. +
  24149. + /* save CTRL register */
  24150. + sp->reg_ctrl = pb44_spi_rr(sp, SPI_REG_CTRL);
  24151. + sp->ioc_base = pb44_spi_rr(sp, SPI_REG_IOC);
  24152. +
  24153. + /* TODO: setup speed? */
  24154. + pb44_spi_wr(sp, SPI_REG_CTRL, 0x43);
  24155. +
  24156. + if (spi->chip_select) {
  24157. + unsigned long gpio = (unsigned long) spi->controller_data;
  24158. + int status = 0;
  24159. +
  24160. + status = gpio_request(gpio, dev_name(&spi->dev));
  24161. + if (status)
  24162. + return status;
  24163. +
  24164. + status = gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH);
  24165. + if (status) {
  24166. + gpio_free(gpio);
  24167. + return status;
  24168. + }
  24169. + } else {
  24170. + if (spi->mode & SPI_CS_HIGH)
  24171. + sp->ioc_base |= SPI_IOC_CS0;
  24172. + else
  24173. + sp->ioc_base &= ~SPI_IOC_CS0;
  24174. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  24175. + }
  24176. +
  24177. + return 0;
  24178. +}
  24179. +
  24180. +static void pb44_spi_cleanup_cs(struct spi_device *spi)
  24181. +{
  24182. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  24183. +
  24184. + if (spi->chip_select) {
  24185. + unsigned long gpio = (unsigned long) spi->controller_data;
  24186. + gpio_free(gpio);
  24187. + }
  24188. +
  24189. + /* restore CTRL register */
  24190. + pb44_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  24191. + /* disable GPIO mode */
  24192. + pb44_spi_wr(sp, SPI_REG_FS, 0);
  24193. +}
  24194. +
  24195. +static int pb44_spi_setup(struct spi_device *spi)
  24196. +{
  24197. + int status = 0;
  24198. +
  24199. + if (spi->bits_per_word > 32)
  24200. + return -EINVAL;
  24201. +
  24202. + if (!spi->controller_state) {
  24203. + status = pb44_spi_setup_cs(spi);
  24204. + if (status)
  24205. + return status;
  24206. + }
  24207. +
  24208. + status = spi_bitbang_setup(spi);
  24209. + if (status && !spi->controller_state)
  24210. + pb44_spi_cleanup_cs(spi);
  24211. +
  24212. + return status;
  24213. +}
  24214. +
  24215. +static void pb44_spi_cleanup(struct spi_device *spi)
  24216. +{
  24217. + pb44_spi_cleanup_cs(spi);
  24218. + spi_bitbang_cleanup(spi);
  24219. +}
  24220. +
  24221. +static u32 pb44_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  24222. + u32 word, u8 bits)
  24223. +{
  24224. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  24225. + u32 ioc = sp->ioc_base;
  24226. + u32 ret;
  24227. +
  24228. + /* clock starts at inactive polarity */
  24229. + for (word <<= (32 - bits); likely(bits); bits--) {
  24230. + u32 out;
  24231. +
  24232. + if (word & (1 << 31))
  24233. + out = ioc | SPI_IOC_DO;
  24234. + else
  24235. + out = ioc & ~SPI_IOC_DO;
  24236. +
  24237. + /* setup MSB (to slave) on trailing edge */
  24238. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  24239. + pb44_spi_wr(sp, SPI_REG_IOC, out | SPI_IOC_CLK);
  24240. +
  24241. + word <<= 1;
  24242. +
  24243. +#ifdef PER_BIT_READ
  24244. + /* sample MSB (from slave) on leading edge */
  24245. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  24246. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  24247. +#endif
  24248. + }
  24249. +
  24250. +#ifndef PER_BIT_READ
  24251. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  24252. +#endif
  24253. + return ret;
  24254. +}
  24255. +
  24256. +static int pb44_spi_probe(struct platform_device *pdev)
  24257. +{
  24258. + struct spi_master *master;
  24259. + struct ar71xx_spi *sp;
  24260. + struct ar71xx_spi_platform_data *pdata;
  24261. + struct resource *r;
  24262. + int ret;
  24263. +
  24264. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  24265. + if (master == NULL) {
  24266. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  24267. + return -ENOMEM;
  24268. + }
  24269. +
  24270. + sp = spi_master_get_devdata(master);
  24271. + platform_set_drvdata(pdev, sp);
  24272. +
  24273. + pdata = pdev->dev.platform_data;
  24274. +
  24275. + master->setup = pb44_spi_setup;
  24276. + master->cleanup = pb44_spi_cleanup;
  24277. + if (pdata) {
  24278. + master->bus_num = pdata->bus_num;
  24279. + master->num_chipselect = pdata->num_chipselect;
  24280. + } else {
  24281. + master->bus_num = 0;
  24282. + master->num_chipselect = 1;
  24283. + }
  24284. +
  24285. + sp->bitbang.master = spi_master_get(master);
  24286. + sp->bitbang.chipselect = pb44_spi_chipselect;
  24287. + sp->bitbang.txrx_word[SPI_MODE_0] = pb44_spi_txrx_mode0;
  24288. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  24289. + sp->bitbang.flags = SPI_CS_HIGH;
  24290. +
  24291. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  24292. + if (r == NULL) {
  24293. + ret = -ENOENT;
  24294. + goto err1;
  24295. + }
  24296. +
  24297. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  24298. + if (!sp->base) {
  24299. + ret = -ENXIO;
  24300. + goto err1;
  24301. + }
  24302. +
  24303. + ret = spi_bitbang_start(&sp->bitbang);
  24304. + if (!ret)
  24305. + return 0;
  24306. +
  24307. + iounmap(sp->base);
  24308. +err1:
  24309. + platform_set_drvdata(pdev, NULL);
  24310. + spi_master_put(sp->bitbang.master);
  24311. +
  24312. + return ret;
  24313. +}
  24314. +
  24315. +static int pb44_spi_remove(struct platform_device *pdev)
  24316. +{
  24317. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  24318. +
  24319. + spi_bitbang_stop(&sp->bitbang);
  24320. + iounmap(sp->base);
  24321. + platform_set_drvdata(pdev, NULL);
  24322. + spi_master_put(sp->bitbang.master);
  24323. +
  24324. + return 0;
  24325. +}
  24326. +
  24327. +static struct platform_driver pb44_spi_drv = {
  24328. + .probe = pb44_spi_probe,
  24329. + .remove = pb44_spi_remove,
  24330. + .driver = {
  24331. + .name = DRV_NAME,
  24332. + .owner = THIS_MODULE,
  24333. + },
  24334. +};
  24335. +
  24336. +static int __init pb44_spi_init(void)
  24337. +{
  24338. + return platform_driver_register(&pb44_spi_drv);
  24339. +}
  24340. +module_init(pb44_spi_init);
  24341. +
  24342. +static void __exit pb44_spi_exit(void)
  24343. +{
  24344. + platform_driver_unregister(&pb44_spi_drv);
  24345. +}
  24346. +module_exit(pb44_spi_exit);
  24347. +
  24348. +MODULE_ALIAS("platform:" DRV_NAME);
  24349. +MODULE_DESCRIPTION(DRV_DESC);
  24350. +MODULE_VERSION(DRV_VERSION);
  24351. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  24352. +MODULE_LICENSE("GPL v2");
  24353. diff -Nur linux-2.6.39.orig/drivers/spi/rb4xx_spi.c linux-2.6.39/drivers/spi/rb4xx_spi.c
  24354. --- linux-2.6.39.orig/drivers/spi/rb4xx_spi.c 1970-01-01 01:00:00.000000000 +0100
  24355. +++ linux-2.6.39/drivers/spi/rb4xx_spi.c 2011-04-27 12:19:22.307664943 +0200
  24356. @@ -0,0 +1,474 @@
  24357. +/*
  24358. + * SPI controller driver for the Mikrotik RB4xx boards
  24359. + *
  24360. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  24361. + *
  24362. + * This file was based on the patches for Linux 2.6.27.39 published by
  24363. + * MikroTik for their RouterBoard 4xx series devices.
  24364. + *
  24365. + * This program is free software; you can redistribute it and/or modify
  24366. + * it under the terms of the GNU General Public License version 2 as
  24367. + * published by the Free Software Foundation.
  24368. + *
  24369. + */
  24370. +
  24371. +#include <linux/kernel.h>
  24372. +#include <linux/init.h>
  24373. +#include <linux/delay.h>
  24374. +#include <linux/spinlock.h>
  24375. +#include <linux/workqueue.h>
  24376. +#include <linux/platform_device.h>
  24377. +#include <linux/spi/spi.h>
  24378. +
  24379. +#include <asm/mach-ar71xx/ar71xx.h>
  24380. +
  24381. +#define DRV_NAME "rb4xx-spi"
  24382. +#define DRV_DESC "Mikrotik RB4xx SPI controller driver"
  24383. +#define DRV_VERSION "0.1.0"
  24384. +
  24385. +#define SPI_CTRL_FASTEST 0x40
  24386. +#define SPI_FLASH_HZ 33333334
  24387. +#define SPI_CPLD_HZ 33333334
  24388. +
  24389. +#define CPLD_CMD_READ_FAST 0x0b
  24390. +
  24391. +#undef RB4XX_SPI_DEBUG
  24392. +
  24393. +struct rb4xx_spi {
  24394. + void __iomem *base;
  24395. + struct spi_master *master;
  24396. +
  24397. + unsigned spi_ctrl_flash;
  24398. + unsigned spi_ctrl_fread;
  24399. +
  24400. + spinlock_t lock;
  24401. + struct list_head queue;
  24402. + int busy:1;
  24403. + int cs_wait;
  24404. +};
  24405. +
  24406. +static unsigned spi_clk_low = SPI_IOC_CS1;
  24407. +
  24408. +#ifdef RB4XX_SPI_DEBUG
  24409. +static inline void do_spi_delay(void)
  24410. +{
  24411. + ndelay(20000);
  24412. +}
  24413. +#else
  24414. +static inline void do_spi_delay(void) { }
  24415. +#endif
  24416. +
  24417. +static inline void do_spi_init(struct spi_device *spi)
  24418. +{
  24419. + unsigned cs = SPI_IOC_CS0 | SPI_IOC_CS1;
  24420. +
  24421. + if (!(spi->mode & SPI_CS_HIGH))
  24422. + cs ^= (spi->chip_select == 2) ? SPI_IOC_CS1 : SPI_IOC_CS0;
  24423. +
  24424. + spi_clk_low = cs;
  24425. +}
  24426. +
  24427. +static inline void do_spi_finish(void __iomem *base)
  24428. +{
  24429. + do_spi_delay();
  24430. + __raw_writel(SPI_IOC_CS0 | SPI_IOC_CS1, base + SPI_REG_IOC);
  24431. +}
  24432. +
  24433. +static inline void do_spi_clk(void __iomem *base, int bit)
  24434. +{
  24435. + unsigned bval = spi_clk_low | ((bit & 1) ? SPI_IOC_DO : 0);
  24436. +
  24437. + do_spi_delay();
  24438. + __raw_writel(bval, base + SPI_REG_IOC);
  24439. + do_spi_delay();
  24440. + __raw_writel(bval | SPI_IOC_CLK, base + SPI_REG_IOC);
  24441. +}
  24442. +
  24443. +static void do_spi_byte(void __iomem *base, unsigned char byte)
  24444. +{
  24445. + do_spi_clk(base, byte >> 7);
  24446. + do_spi_clk(base, byte >> 6);
  24447. + do_spi_clk(base, byte >> 5);
  24448. + do_spi_clk(base, byte >> 4);
  24449. + do_spi_clk(base, byte >> 3);
  24450. + do_spi_clk(base, byte >> 2);
  24451. + do_spi_clk(base, byte >> 1);
  24452. + do_spi_clk(base, byte);
  24453. +
  24454. + pr_debug("spi_byte sent 0x%02x got 0x%02x\n",
  24455. + (unsigned)byte,
  24456. + (unsigned char)__raw_readl(base + SPI_REG_RDS));
  24457. +}
  24458. +
  24459. +static inline void do_spi_clk_fast(void __iomem *base, unsigned bit1,
  24460. + unsigned bit2)
  24461. +{
  24462. + unsigned bval = (spi_clk_low |
  24463. + ((bit1 & 1) ? SPI_IOC_DO : 0) |
  24464. + ((bit2 & 1) ? SPI_IOC_CS2 : 0));
  24465. + do_spi_delay();
  24466. + __raw_writel(bval, base + SPI_REG_IOC);
  24467. + do_spi_delay();
  24468. + __raw_writel(bval | SPI_IOC_CLK, base + SPI_REG_IOC);
  24469. +}
  24470. +
  24471. +static void do_spi_byte_fast(void __iomem *base, unsigned char byte)
  24472. +{
  24473. + do_spi_clk_fast(base, byte >> 7, byte >> 6);
  24474. + do_spi_clk_fast(base, byte >> 5, byte >> 4);
  24475. + do_spi_clk_fast(base, byte >> 3, byte >> 2);
  24476. + do_spi_clk_fast(base, byte >> 1, byte >> 0);
  24477. +
  24478. + pr_debug("spi_byte_fast sent 0x%02x got 0x%02x\n",
  24479. + (unsigned)byte,
  24480. + (unsigned char) __raw_readl(base + SPI_REG_RDS));
  24481. +}
  24482. +
  24483. +static int rb4xx_spi_txrx(void __iomem *base, struct spi_transfer *t)
  24484. +{
  24485. + const unsigned char *rxv_ptr = NULL;
  24486. + const unsigned char *tx_ptr = t->tx_buf;
  24487. + unsigned char *rx_ptr = t->rx_buf;
  24488. + unsigned i;
  24489. +
  24490. + pr_debug("spi_txrx len %u tx %u rx %u\n",
  24491. + t->len,
  24492. + (t->tx_buf ? 1 : 0),
  24493. + (t->rx_buf ? 1 : 0));
  24494. +
  24495. + if (t->verify) {
  24496. + rxv_ptr = tx_ptr;
  24497. + tx_ptr = NULL;
  24498. + }
  24499. +
  24500. + for (i = 0; i < t->len; ++i) {
  24501. + unsigned char sdata = tx_ptr ? tx_ptr[i] : 0;
  24502. +
  24503. + if (t->fast_write)
  24504. + do_spi_byte_fast(base, sdata);
  24505. + else
  24506. + do_spi_byte(base, sdata);
  24507. +
  24508. + if (rx_ptr) {
  24509. + rx_ptr[i] = __raw_readl(base + SPI_REG_RDS) & 0xff;
  24510. + } else if (rxv_ptr) {
  24511. + unsigned char c = __raw_readl(base + SPI_REG_RDS);
  24512. + if (rxv_ptr[i] != c)
  24513. + return i;
  24514. + }
  24515. + }
  24516. +
  24517. + return i;
  24518. +}
  24519. +
  24520. +static int rb4xx_spi_read_fast(struct rb4xx_spi *rbspi,
  24521. + struct spi_message *m)
  24522. +{
  24523. + struct spi_transfer *t;
  24524. + const unsigned char *tx_ptr;
  24525. + unsigned addr;
  24526. + void __iomem *base = rbspi->base;
  24527. +
  24528. + /* check for exactly two transfers */
  24529. + if (list_empty(&m->transfers) ||
  24530. + list_is_last(m->transfers.next, &m->transfers) ||
  24531. + !list_is_last(m->transfers.next->next, &m->transfers)) {
  24532. + return -1;
  24533. + }
  24534. +
  24535. + /* first transfer contains command and address */
  24536. + t = list_entry(m->transfers.next,
  24537. + struct spi_transfer, transfer_list);
  24538. +
  24539. + if (t->len != 5 || t->tx_buf == NULL)
  24540. + return -1;
  24541. +
  24542. + tx_ptr = t->tx_buf;
  24543. + if (tx_ptr[0] != CPLD_CMD_READ_FAST)
  24544. + return -1;
  24545. +
  24546. + addr = tx_ptr[1];
  24547. + addr = tx_ptr[2] | (addr << 8);
  24548. + addr = tx_ptr[3] | (addr << 8);
  24549. + addr += (unsigned) base;
  24550. +
  24551. + m->actual_length += t->len;
  24552. +
  24553. + /* second transfer contains data itself */
  24554. + t = list_entry(m->transfers.next->next,
  24555. + struct spi_transfer, transfer_list);
  24556. +
  24557. + if (t->tx_buf && !t->verify)
  24558. + return -1;
  24559. +
  24560. + __raw_writel(SPI_FS_GPIO, base + SPI_REG_FS);
  24561. + __raw_writel(rbspi->spi_ctrl_fread, base + SPI_REG_CTRL);
  24562. + __raw_writel(0, base + SPI_REG_FS);
  24563. +
  24564. + if (t->rx_buf) {
  24565. + memcpy(t->rx_buf, (const void *)addr, t->len);
  24566. + } else if (t->tx_buf) {
  24567. + unsigned char buf[t->len];
  24568. + memcpy(buf, (const void *)addr, t->len);
  24569. + if (memcmp(t->tx_buf, buf, t->len) != 0)
  24570. + m->status = -EMSGSIZE;
  24571. + }
  24572. + m->actual_length += t->len;
  24573. +
  24574. + if (rbspi->spi_ctrl_flash != rbspi->spi_ctrl_fread) {
  24575. + __raw_writel(SPI_FS_GPIO, base + SPI_REG_FS);
  24576. + __raw_writel(rbspi->spi_ctrl_flash, base + SPI_REG_CTRL);
  24577. + __raw_writel(0, base + SPI_REG_FS);
  24578. + }
  24579. +
  24580. + return 0;
  24581. +}
  24582. +
  24583. +static int rb4xx_spi_msg(struct rb4xx_spi *rbspi, struct spi_message *m)
  24584. +{
  24585. + struct spi_transfer *t = NULL;
  24586. + void __iomem *base = rbspi->base;
  24587. +
  24588. + m->status = 0;
  24589. + if (list_empty(&m->transfers))
  24590. + return -1;
  24591. +
  24592. + if (m->fast_read)
  24593. + if (rb4xx_spi_read_fast(rbspi, m) == 0)
  24594. + return -1;
  24595. +
  24596. + __raw_writel(SPI_FS_GPIO, base + SPI_REG_FS);
  24597. + __raw_writel(SPI_CTRL_FASTEST, base + SPI_REG_CTRL);
  24598. + do_spi_init(m->spi);
  24599. +
  24600. + list_for_each_entry(t, &m->transfers, transfer_list) {
  24601. + int len;
  24602. +
  24603. + len = rb4xx_spi_txrx(base, t);
  24604. + if (len != t->len) {
  24605. + m->status = -EMSGSIZE;
  24606. + break;
  24607. + }
  24608. + m->actual_length += len;
  24609. +
  24610. + if (t->cs_change) {
  24611. + if (list_is_last(&t->transfer_list, &m->transfers)) {
  24612. + /* wait for continuation */
  24613. + return m->spi->chip_select;
  24614. + }
  24615. + do_spi_finish(base);
  24616. + ndelay(100);
  24617. + }
  24618. + }
  24619. +
  24620. + do_spi_finish(base);
  24621. + __raw_writel(rbspi->spi_ctrl_flash, base + SPI_REG_CTRL);
  24622. + __raw_writel(0, base + SPI_REG_FS);
  24623. + return -1;
  24624. +}
  24625. +
  24626. +static void rb4xx_spi_process_queue_locked(struct rb4xx_spi *rbspi,
  24627. + unsigned long *flags)
  24628. +{
  24629. + int cs = rbspi->cs_wait;
  24630. +
  24631. + rbspi->busy = 1;
  24632. + while (!list_empty(&rbspi->queue)) {
  24633. + struct spi_message *m;
  24634. +
  24635. + list_for_each_entry(m, &rbspi->queue, queue)
  24636. + if (cs < 0 || cs == m->spi->chip_select)
  24637. + break;
  24638. +
  24639. + if (&m->queue == &rbspi->queue)
  24640. + break;
  24641. +
  24642. + list_del_init(&m->queue);
  24643. + spin_unlock_irqrestore(&rbspi->lock, *flags);
  24644. +
  24645. + cs = rb4xx_spi_msg(rbspi, m);
  24646. + m->complete(m->context);
  24647. +
  24648. + spin_lock_irqsave(&rbspi->lock, *flags);
  24649. + }
  24650. +
  24651. + rbspi->cs_wait = cs;
  24652. + rbspi->busy = 0;
  24653. +
  24654. + if (cs >= 0) {
  24655. + /* TODO: add timer to unlock cs after 1s inactivity */
  24656. + }
  24657. +}
  24658. +
  24659. +static int rb4xx_spi_transfer(struct spi_device *spi,
  24660. + struct spi_message *m)
  24661. +{
  24662. + struct rb4xx_spi *rbspi = spi_master_get_devdata(spi->master);
  24663. + unsigned long flags;
  24664. +
  24665. + m->actual_length = 0;
  24666. + m->status = -EINPROGRESS;
  24667. +
  24668. + spin_lock_irqsave(&rbspi->lock, flags);
  24669. + list_add_tail(&m->queue, &rbspi->queue);
  24670. + if (rbspi->busy ||
  24671. + (rbspi->cs_wait >= 0 && rbspi->cs_wait != m->spi->chip_select)) {
  24672. + /* job will be done later */
  24673. + spin_unlock_irqrestore(&rbspi->lock, flags);
  24674. + return 0;
  24675. + }
  24676. +
  24677. + /* process job in current context */
  24678. + rb4xx_spi_process_queue_locked(rbspi, &flags);
  24679. + spin_unlock_irqrestore(&rbspi->lock, flags);
  24680. +
  24681. + return 0;
  24682. +}
  24683. +
  24684. +static int rb4xx_spi_setup(struct spi_device *spi)
  24685. +{
  24686. + struct rb4xx_spi *rbspi = spi_master_get_devdata(spi->master);
  24687. + unsigned long flags;
  24688. +
  24689. + if (spi->mode & ~(SPI_CS_HIGH)) {
  24690. + dev_err(&spi->dev, "mode %x not supported\n",
  24691. + (unsigned) spi->mode);
  24692. + return -EINVAL;
  24693. + }
  24694. +
  24695. + if (spi->bits_per_word != 8 && spi->bits_per_word != 0) {
  24696. + dev_err(&spi->dev, "bits_per_word %u not supported\n",
  24697. + (unsigned) spi->bits_per_word);
  24698. + return -EINVAL;
  24699. + }
  24700. +
  24701. + spin_lock_irqsave(&rbspi->lock, flags);
  24702. + if (rbspi->cs_wait == spi->chip_select && !rbspi->busy) {
  24703. + rbspi->cs_wait = -1;
  24704. + rb4xx_spi_process_queue_locked(rbspi, &flags);
  24705. + }
  24706. + spin_unlock_irqrestore(&rbspi->lock, flags);
  24707. +
  24708. + return 0;
  24709. +}
  24710. +
  24711. +static unsigned get_spi_ctrl(unsigned hz_max, const char *name)
  24712. +{
  24713. + unsigned div;
  24714. +
  24715. + div = (ar71xx_ahb_freq - 1) / (2 * hz_max);
  24716. +
  24717. + /*
  24718. + * CPU has a bug at (div == 0) - first bit read is random
  24719. + */
  24720. + if (div == 0)
  24721. + ++div;
  24722. +
  24723. + if (name) {
  24724. + unsigned ahb_khz = (ar71xx_ahb_freq + 500) / 1000;
  24725. + unsigned div_real = 2 * (div + 1);
  24726. + pr_debug("rb4xx: %s SPI clock %u kHz (AHB %u kHz / %u)\n",
  24727. + name,
  24728. + ahb_khz / div_real,
  24729. + ahb_khz, div_real);
  24730. + }
  24731. +
  24732. + return SPI_CTRL_FASTEST + div;
  24733. +}
  24734. +
  24735. +static int rb4xx_spi_probe(struct platform_device *pdev)
  24736. +{
  24737. + struct spi_master *master;
  24738. + struct rb4xx_spi *rbspi;
  24739. + struct resource *r;
  24740. + int err = 0;
  24741. +
  24742. + master = spi_alloc_master(&pdev->dev, sizeof(*rbspi));
  24743. + if (master == NULL) {
  24744. + dev_err(&pdev->dev, "no memory for spi_master\n");
  24745. + err = -ENOMEM;
  24746. + goto err_out;
  24747. + }
  24748. +
  24749. + master->bus_num = 0;
  24750. + master->num_chipselect = 3;
  24751. + master->setup = rb4xx_spi_setup;
  24752. + master->transfer = rb4xx_spi_transfer;
  24753. +
  24754. + rbspi = spi_master_get_devdata(master);
  24755. + platform_set_drvdata(pdev, rbspi);
  24756. +
  24757. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  24758. + if (r == NULL) {
  24759. + err = -ENOENT;
  24760. + goto err_put_master;
  24761. + }
  24762. +
  24763. + rbspi->base = ioremap(r->start, r->end - r->start + 1);
  24764. + if (!rbspi->base) {
  24765. + err = -ENXIO;
  24766. + goto err_put_master;
  24767. + }
  24768. +
  24769. + rbspi->master = master;
  24770. + rbspi->spi_ctrl_flash = get_spi_ctrl(SPI_FLASH_HZ, "FLASH");
  24771. + rbspi->spi_ctrl_fread = get_spi_ctrl(SPI_CPLD_HZ, "CPLD");
  24772. + rbspi->cs_wait = -1;
  24773. +
  24774. + spin_lock_init(&rbspi->lock);
  24775. + INIT_LIST_HEAD(&rbspi->queue);
  24776. +
  24777. + err = spi_register_master(master);
  24778. + if (err) {
  24779. + dev_err(&pdev->dev, "failed to register SPI master\n");
  24780. + goto err_iounmap;
  24781. + }
  24782. +
  24783. + return 0;
  24784. +
  24785. +err_iounmap:
  24786. + iounmap(rbspi->base);
  24787. +err_put_master:
  24788. + platform_set_drvdata(pdev, NULL);
  24789. + spi_master_put(master);
  24790. +err_out:
  24791. + return err;
  24792. +}
  24793. +
  24794. +static int rb4xx_spi_remove(struct platform_device *pdev)
  24795. +{
  24796. + struct rb4xx_spi *rbspi = platform_get_drvdata(pdev);
  24797. +
  24798. + iounmap(rbspi->base);
  24799. + platform_set_drvdata(pdev, NULL);
  24800. + spi_master_put(rbspi->master);
  24801. +
  24802. + return 0;
  24803. +}
  24804. +
  24805. +static struct platform_driver rb4xx_spi_drv = {
  24806. + .probe = rb4xx_spi_probe,
  24807. + .remove = rb4xx_spi_remove,
  24808. + .driver = {
  24809. + .name = DRV_NAME,
  24810. + .owner = THIS_MODULE,
  24811. + },
  24812. +};
  24813. +
  24814. +static int __init rb4xx_spi_init(void)
  24815. +{
  24816. + return platform_driver_register(&rb4xx_spi_drv);
  24817. +}
  24818. +subsys_initcall(rb4xx_spi_init);
  24819. +
  24820. +static void __exit rb4xx_spi_exit(void)
  24821. +{
  24822. + platform_driver_unregister(&rb4xx_spi_drv);
  24823. +}
  24824. +
  24825. +module_exit(rb4xx_spi_exit);
  24826. +
  24827. +MODULE_DESCRIPTION(DRV_DESC);
  24828. +MODULE_VERSION(DRV_VERSION);
  24829. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  24830. +MODULE_LICENSE("GPL v2");
  24831. diff -Nur linux-2.6.39.orig/drivers/spi/spi_rb4xx_cpld.c linux-2.6.39/drivers/spi/spi_rb4xx_cpld.c
  24832. --- linux-2.6.39.orig/drivers/spi/spi_rb4xx_cpld.c 1970-01-01 01:00:00.000000000 +0100
  24833. +++ linux-2.6.39/drivers/spi/spi_rb4xx_cpld.c 2011-04-27 12:19:22.317665385 +0200
  24834. @@ -0,0 +1,440 @@
  24835. +/*
  24836. + * SPI driver for the CPLD chip on the Mikrotik RB4xx boards
  24837. + *
  24838. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  24839. + *
  24840. + * This file was based on the patches for Linux 2.6.27.39 published by
  24841. + * MikroTik for their RouterBoard 4xx series devices.
  24842. + *
  24843. + * This program is free software; you can redistribute it and/or modify it
  24844. + * under the terms of the GNU General Public License version 2 as published
  24845. + * by the Free Software Foundation.
  24846. + */
  24847. +
  24848. +#include <linux/types.h>
  24849. +#include <linux/kernel.h>
  24850. +#include <linux/init.h>
  24851. +#include <linux/module.h>
  24852. +#include <linux/device.h>
  24853. +#include <linux/bitops.h>
  24854. +#include <linux/spi/spi.h>
  24855. +#include <linux/gpio.h>
  24856. +#include <linux/slab.h>
  24857. +
  24858. +#include <asm/mach-ar71xx/rb4xx_cpld.h>
  24859. +
  24860. +#define DRV_NAME "spi-rb4xx-cpld"
  24861. +#define DRV_DESC "RB4xx CPLD driver"
  24862. +#define DRV_VERSION "0.1.0"
  24863. +
  24864. +#define CPLD_CMD_WRITE_NAND 0x08 /* send cmd, n x send data, send indle */
  24865. +#define CPLD_CMD_WRITE_CFG 0x09 /* send cmd, n x send cfg */
  24866. +#define CPLD_CMD_READ_NAND 0x0a /* send cmd, send idle, n x read data */
  24867. +#define CPLD_CMD_READ_FAST 0x0b /* send cmd, 4 x idle, n x read data */
  24868. +#define CPLD_CMD_LED5_ON 0x0c /* send cmd */
  24869. +#define CPLD_CMD_LED5_OFF 0x0d /* send cmd */
  24870. +
  24871. +struct rb4xx_cpld {
  24872. + struct spi_device *spi;
  24873. + struct mutex lock;
  24874. + struct gpio_chip chip;
  24875. + unsigned int config;
  24876. +};
  24877. +
  24878. +static struct rb4xx_cpld *rb4xx_cpld;
  24879. +
  24880. +static inline struct rb4xx_cpld *gpio_to_cpld(struct gpio_chip *chip)
  24881. +{
  24882. + return container_of(chip, struct rb4xx_cpld, chip);
  24883. +}
  24884. +
  24885. +static int rb4xx_cpld_write_cmd(struct rb4xx_cpld *cpld, unsigned char cmd)
  24886. +{
  24887. + struct spi_transfer t[1];
  24888. + struct spi_message m;
  24889. + unsigned char tx_buf[1];
  24890. + int err;
  24891. +
  24892. + spi_message_init(&m);
  24893. + memset(&t, 0, sizeof(t));
  24894. +
  24895. + t[0].tx_buf = tx_buf;
  24896. + t[0].len = sizeof(tx_buf);
  24897. + spi_message_add_tail(&t[0], &m);
  24898. +
  24899. + tx_buf[0] = cmd;
  24900. +
  24901. + err = spi_sync(cpld->spi, &m);
  24902. + return err;
  24903. +}
  24904. +
  24905. +static int rb4xx_cpld_write_cfg(struct rb4xx_cpld *cpld, unsigned char config)
  24906. +{
  24907. + struct spi_transfer t[1];
  24908. + struct spi_message m;
  24909. + unsigned char cmd[2];
  24910. + int err;
  24911. +
  24912. + spi_message_init(&m);
  24913. + memset(&t, 0, sizeof(t));
  24914. +
  24915. + t[0].tx_buf = cmd;
  24916. + t[0].len = sizeof(cmd);
  24917. + spi_message_add_tail(&t[0], &m);
  24918. +
  24919. + cmd[0] = CPLD_CMD_WRITE_CFG;
  24920. + cmd[1] = config;
  24921. +
  24922. + err = spi_sync(cpld->spi, &m);
  24923. + return err;
  24924. +}
  24925. +
  24926. +static int __rb4xx_cpld_change_cfg(struct rb4xx_cpld *cpld, unsigned mask,
  24927. + unsigned value)
  24928. +{
  24929. + unsigned int config;
  24930. + int err;
  24931. +
  24932. + config = cpld->config & ~mask;
  24933. + config |= value;
  24934. +
  24935. + if ((cpld->config ^ config) & 0xff) {
  24936. + err = rb4xx_cpld_write_cfg(cpld, config);
  24937. + if (err)
  24938. + return err;
  24939. + }
  24940. +
  24941. + if ((cpld->config ^ config) & CPLD_CFG_nLED5) {
  24942. + err = rb4xx_cpld_write_cmd(cpld, (value) ? CPLD_CMD_LED5_ON :
  24943. + CPLD_CMD_LED5_OFF);
  24944. + if (err)
  24945. + return err;
  24946. + }
  24947. +
  24948. + cpld->config = config;
  24949. + return 0;
  24950. +}
  24951. +
  24952. +int rb4xx_cpld_change_cfg(unsigned mask, unsigned value)
  24953. +{
  24954. + int ret;
  24955. +
  24956. + if (rb4xx_cpld == NULL)
  24957. + return -ENODEV;
  24958. +
  24959. + mutex_lock(&rb4xx_cpld->lock);
  24960. + ret = __rb4xx_cpld_change_cfg(rb4xx_cpld, mask, value);
  24961. + mutex_unlock(&rb4xx_cpld->lock);
  24962. +
  24963. + return ret;
  24964. +}
  24965. +EXPORT_SYMBOL_GPL(rb4xx_cpld_change_cfg);
  24966. +
  24967. +int rb4xx_cpld_read_from(unsigned addr, unsigned char *rx_buf,
  24968. + const unsigned char *verify_buf, unsigned count)
  24969. +{
  24970. + const unsigned char cmd[5] = {
  24971. + CPLD_CMD_READ_FAST,
  24972. + (addr >> 16) & 0xff,
  24973. + (addr >> 8) & 0xff,
  24974. + addr & 0xff,
  24975. + 0
  24976. + };
  24977. + struct spi_transfer t[2] = {
  24978. + {
  24979. + .tx_buf = &cmd,
  24980. + .len = 5,
  24981. + },
  24982. + {
  24983. + .tx_buf = verify_buf,
  24984. + .rx_buf = rx_buf,
  24985. + .len = count,
  24986. + .verify = (verify_buf != NULL),
  24987. + },
  24988. + };
  24989. + struct spi_message m;
  24990. +
  24991. + if (rb4xx_cpld == NULL)
  24992. + return -ENODEV;
  24993. +
  24994. + spi_message_init(&m);
  24995. + m.fast_read = 1;
  24996. + spi_message_add_tail(&t[0], &m);
  24997. + spi_message_add_tail(&t[1], &m);
  24998. + return spi_sync(rb4xx_cpld->spi, &m);
  24999. +}
  25000. +EXPORT_SYMBOL_GPL(rb4xx_cpld_read_from);
  25001. +
  25002. +#if 0
  25003. +int rb4xx_cpld_read(unsigned char *buf, unsigned char *verify_buf,
  25004. + unsigned count)
  25005. +{
  25006. + struct spi_transfer t[2];
  25007. + struct spi_message m;
  25008. + unsigned char cmd[2];
  25009. +
  25010. + if (rb4xx_cpld == NULL)
  25011. + return -ENODEV;
  25012. +
  25013. + spi_message_init(&m);
  25014. + memset(&t, 0, sizeof(t));
  25015. +
  25016. + /* send command */
  25017. + t[0].tx_buf = cmd;
  25018. + t[0].len = sizeof(cmd);
  25019. + spi_message_add_tail(&t[0], &m);
  25020. +
  25021. + cmd[0] = CPLD_CMD_READ_NAND;
  25022. + cmd[1] = 0;
  25023. +
  25024. + /* read data */
  25025. + t[1].rx_buf = buf;
  25026. + t[1].len = count;
  25027. + spi_message_add_tail(&t[1], &m);
  25028. +
  25029. + return spi_sync(rb4xx_cpld->spi, &m);
  25030. +}
  25031. +#else
  25032. +int rb4xx_cpld_read(unsigned char *rx_buf, const unsigned char *verify_buf,
  25033. + unsigned count)
  25034. +{
  25035. + static const unsigned char cmd[2] = { CPLD_CMD_READ_NAND, 0 };
  25036. + struct spi_transfer t[2] = {
  25037. + {
  25038. + .tx_buf = &cmd,
  25039. + .len = 2,
  25040. + }, {
  25041. + .tx_buf = verify_buf,
  25042. + .rx_buf = rx_buf,
  25043. + .len = count,
  25044. + .verify = (verify_buf != NULL),
  25045. + },
  25046. + };
  25047. + struct spi_message m;
  25048. +
  25049. + if (rb4xx_cpld == NULL)
  25050. + return -ENODEV;
  25051. +
  25052. + spi_message_init(&m);
  25053. + spi_message_add_tail(&t[0], &m);
  25054. + spi_message_add_tail(&t[1], &m);
  25055. + return spi_sync(rb4xx_cpld->spi, &m);
  25056. +}
  25057. +#endif
  25058. +EXPORT_SYMBOL_GPL(rb4xx_cpld_read);
  25059. +
  25060. +int rb4xx_cpld_write(const unsigned char *buf, unsigned count)
  25061. +{
  25062. +#if 0
  25063. + struct spi_transfer t[3];
  25064. + struct spi_message m;
  25065. + unsigned char cmd[1];
  25066. +
  25067. + if (rb4xx_cpld == NULL)
  25068. + return -ENODEV;
  25069. +
  25070. + memset(&t, 0, sizeof(t));
  25071. + spi_message_init(&m);
  25072. +
  25073. + /* send command */
  25074. + t[0].tx_buf = cmd;
  25075. + t[0].len = sizeof(cmd);
  25076. + spi_message_add_tail(&t[0], &m);
  25077. +
  25078. + cmd[0] = CPLD_CMD_WRITE_NAND;
  25079. +
  25080. + /* write data */
  25081. + t[1].tx_buf = buf;
  25082. + t[1].len = count;
  25083. + spi_message_add_tail(&t[1], &m);
  25084. +
  25085. + /* send idle */
  25086. + t[2].len = 1;
  25087. + spi_message_add_tail(&t[2], &m);
  25088. +
  25089. + return spi_sync(rb4xx_cpld->spi, &m);
  25090. +#else
  25091. + static const unsigned char cmd = CPLD_CMD_WRITE_NAND;
  25092. + struct spi_transfer t[3] = {
  25093. + {
  25094. + .tx_buf = &cmd,
  25095. + .len = 1,
  25096. + }, {
  25097. + .tx_buf = buf,
  25098. + .len = count,
  25099. + .fast_write = 1,
  25100. + }, {
  25101. + .len = 1,
  25102. + .fast_write = 1,
  25103. + },
  25104. + };
  25105. + struct spi_message m;
  25106. +
  25107. + if (rb4xx_cpld == NULL)
  25108. + return -ENODEV;
  25109. +
  25110. + spi_message_init(&m);
  25111. + spi_message_add_tail(&t[0], &m);
  25112. + spi_message_add_tail(&t[1], &m);
  25113. + spi_message_add_tail(&t[2], &m);
  25114. + return spi_sync(rb4xx_cpld->spi, &m);
  25115. +#endif
  25116. +}
  25117. +EXPORT_SYMBOL_GPL(rb4xx_cpld_write);
  25118. +
  25119. +static int rb4xx_cpld_gpio_get(struct gpio_chip *chip, unsigned offset)
  25120. +{
  25121. + struct rb4xx_cpld *cpld = gpio_to_cpld(chip);
  25122. + int ret;
  25123. +
  25124. + mutex_lock(&cpld->lock);
  25125. + ret = (cpld->config >> offset) & 1;
  25126. + mutex_unlock(&cpld->lock);
  25127. +
  25128. + return ret;
  25129. +}
  25130. +
  25131. +static void rb4xx_cpld_gpio_set(struct gpio_chip *chip, unsigned offset,
  25132. + int value)
  25133. +{
  25134. + struct rb4xx_cpld *cpld = gpio_to_cpld(chip);
  25135. +
  25136. + mutex_lock(&cpld->lock);
  25137. + __rb4xx_cpld_change_cfg(cpld, (1 << offset), !!value << offset);
  25138. + mutex_unlock(&cpld->lock);
  25139. +}
  25140. +
  25141. +static int rb4xx_cpld_gpio_direction_input(struct gpio_chip *chip,
  25142. + unsigned offset)
  25143. +{
  25144. + return -EOPNOTSUPP;
  25145. +}
  25146. +
  25147. +static int rb4xx_cpld_gpio_direction_output(struct gpio_chip *chip,
  25148. + unsigned offset,
  25149. + int value)
  25150. +{
  25151. + struct rb4xx_cpld *cpld = gpio_to_cpld(chip);
  25152. + int ret;
  25153. +
  25154. + mutex_lock(&cpld->lock);
  25155. + ret = __rb4xx_cpld_change_cfg(cpld, (1 << offset), !!value << offset);
  25156. + mutex_unlock(&cpld->lock);
  25157. +
  25158. + return ret;
  25159. +}
  25160. +
  25161. +static int rb4xx_cpld_gpio_init(struct rb4xx_cpld *cpld, unsigned int base)
  25162. +{
  25163. + int err;
  25164. +
  25165. + /* init config */
  25166. + cpld->config = CPLD_CFG_nLED1 | CPLD_CFG_nLED2 | CPLD_CFG_nLED3 |
  25167. + CPLD_CFG_nLED4 | CPLD_CFG_nCE;
  25168. + rb4xx_cpld_write_cfg(cpld, cpld->config);
  25169. +
  25170. + /* setup GPIO chip */
  25171. + cpld->chip.label = DRV_NAME;
  25172. +
  25173. + cpld->chip.get = rb4xx_cpld_gpio_get;
  25174. + cpld->chip.set = rb4xx_cpld_gpio_set;
  25175. + cpld->chip.direction_input = rb4xx_cpld_gpio_direction_input;
  25176. + cpld->chip.direction_output = rb4xx_cpld_gpio_direction_output;
  25177. +
  25178. + cpld->chip.base = base;
  25179. + cpld->chip.ngpio = CPLD_NUM_GPIOS;
  25180. + cpld->chip.can_sleep = 1;
  25181. + cpld->chip.dev = &cpld->spi->dev;
  25182. + cpld->chip.owner = THIS_MODULE;
  25183. +
  25184. + err = gpiochip_add(&cpld->chip);
  25185. + if (err)
  25186. + dev_err(&cpld->spi->dev, "adding GPIO chip failed, err=%d\n",
  25187. + err);
  25188. +
  25189. + return err;
  25190. +}
  25191. +
  25192. +static int __devinit rb4xx_cpld_probe(struct spi_device *spi)
  25193. +{
  25194. + struct rb4xx_cpld *cpld;
  25195. + struct rb4xx_cpld_platform_data *pdata;
  25196. + int err;
  25197. +
  25198. + pdata = spi->dev.platform_data;
  25199. + if (!pdata) {
  25200. + dev_dbg(&spi->dev, "no platform data\n");
  25201. + return -EINVAL;
  25202. + }
  25203. +
  25204. + cpld = kzalloc(sizeof(*cpld), GFP_KERNEL);
  25205. + if (!cpld) {
  25206. + dev_err(&spi->dev, "no memory for private data\n");
  25207. + return -ENOMEM;
  25208. + }
  25209. +
  25210. + mutex_init(&cpld->lock);
  25211. + cpld->spi = spi_dev_get(spi);
  25212. + dev_set_drvdata(&spi->dev, cpld);
  25213. +
  25214. + spi->mode = SPI_MODE_0;
  25215. + spi->bits_per_word = 8;
  25216. + err = spi_setup(spi);
  25217. + if (err) {
  25218. + dev_err(&spi->dev, "spi_setup failed, err=%d\n", err);
  25219. + goto err_drvdata;
  25220. + }
  25221. +
  25222. + err = rb4xx_cpld_gpio_init(cpld, pdata->gpio_base);
  25223. + if (err)
  25224. + goto err_drvdata;
  25225. +
  25226. + rb4xx_cpld = cpld;
  25227. +
  25228. + return 0;
  25229. +
  25230. +err_drvdata:
  25231. + dev_set_drvdata(&spi->dev, NULL);
  25232. + kfree(cpld);
  25233. +
  25234. + return err;
  25235. +}
  25236. +
  25237. +static int __devexit rb4xx_cpld_remove(struct spi_device *spi)
  25238. +{
  25239. + struct rb4xx_cpld *cpld;
  25240. +
  25241. + rb4xx_cpld = NULL;
  25242. + cpld = dev_get_drvdata(&spi->dev);
  25243. + dev_set_drvdata(&spi->dev, NULL);
  25244. + kfree(cpld);
  25245. +
  25246. + return 0;
  25247. +}
  25248. +
  25249. +static struct spi_driver rb4xx_cpld_driver = {
  25250. + .driver = {
  25251. + .name = DRV_NAME,
  25252. + .bus = &spi_bus_type,
  25253. + .owner = THIS_MODULE,
  25254. + },
  25255. + .probe = rb4xx_cpld_probe,
  25256. + .remove = __devexit_p(rb4xx_cpld_remove),
  25257. +};
  25258. +
  25259. +static int __init rb4xx_cpld_init(void)
  25260. +{
  25261. + return spi_register_driver(&rb4xx_cpld_driver);
  25262. +}
  25263. +module_init(rb4xx_cpld_init);
  25264. +
  25265. +static void __exit rb4xx_cpld_exit(void)
  25266. +{
  25267. + spi_unregister_driver(&rb4xx_cpld_driver);
  25268. +}
  25269. +module_exit(rb4xx_cpld_exit);
  25270. +
  25271. +MODULE_DESCRIPTION(DRV_DESC);
  25272. +MODULE_VERSION(DRV_VERSION);
  25273. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  25274. +MODULE_LICENSE("GPL v2");
  25275. diff -Nur linux-2.6.39.orig/drivers/spi/spi_vsc7385.c linux-2.6.39/drivers/spi/spi_vsc7385.c
  25276. --- linux-2.6.39.orig/drivers/spi/spi_vsc7385.c 1970-01-01 01:00:00.000000000 +0100
  25277. +++ linux-2.6.39/drivers/spi/spi_vsc7385.c 2011-04-27 12:19:22.317665385 +0200
  25278. @@ -0,0 +1,621 @@
  25279. +/*
  25280. + * SPI driver for the Vitesse VSC7385 ethernet switch
  25281. + *
  25282. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  25283. + *
  25284. + * Parts of this file are based on Atheros' 2.6.15 BSP
  25285. + *
  25286. + * This program is free software; you can redistribute it and/or modify it
  25287. + * under the terms of the GNU General Public License version 2 as published
  25288. + * by the Free Software Foundation.
  25289. + */
  25290. +
  25291. +#include <linux/types.h>
  25292. +#include <linux/kernel.h>
  25293. +#include <linux/init.h>
  25294. +#include <linux/module.h>
  25295. +#include <linux/delay.h>
  25296. +#include <linux/device.h>
  25297. +#include <linux/bitops.h>
  25298. +#include <linux/firmware.h>
  25299. +#include <linux/spi/spi.h>
  25300. +#include <linux/spi/vsc7385.h>
  25301. +
  25302. +#define DRV_NAME "spi-vsc7385"
  25303. +#define DRV_DESC "Vitesse VSC7385 Gbit ethernet switch driver"
  25304. +#define DRV_VERSION "0.1.0"
  25305. +
  25306. +#define VSC73XX_BLOCK_MAC 0x1
  25307. +#define VSC73XX_BLOCK_2 0x2
  25308. +#define VSC73XX_BLOCK_MII 0x3
  25309. +#define VSC73XX_BLOCK_4 0x4
  25310. +#define VSC73XX_BLOCK_5 0x5
  25311. +#define VSC73XX_BLOCK_SYSTEM 0x7
  25312. +
  25313. +#define VSC73XX_SUBBLOCK_PORT_0 0
  25314. +#define VSC73XX_SUBBLOCK_PORT_1 1
  25315. +#define VSC73XX_SUBBLOCK_PORT_2 2
  25316. +#define VSC73XX_SUBBLOCK_PORT_3 3
  25317. +#define VSC73XX_SUBBLOCK_PORT_4 4
  25318. +#define VSC73XX_SUBBLOCK_PORT_MAC 6
  25319. +
  25320. +/* MAC Block registers */
  25321. +#define VSC73XX_MAC_CFG 0x0
  25322. +#define VSC73XX_ADVPORTM 0x19
  25323. +#define VSC73XX_RXOCT 0x50
  25324. +#define VSC73XX_TXOCT 0x51
  25325. +#define VSC73XX_C_RX0 0x52
  25326. +#define VSC73XX_C_RX1 0x53
  25327. +#define VSC73XX_C_RX2 0x54
  25328. +#define VSC73XX_C_TX0 0x55
  25329. +#define VSC73XX_C_TX1 0x56
  25330. +#define VSC73XX_C_TX2 0x57
  25331. +#define VSC73XX_C_CFG 0x58
  25332. +
  25333. +/* MAC_CFG register bits */
  25334. +#define VSC73XX_MAC_CFG_WEXC_DIS (1 << 31)
  25335. +#define VSC73XX_MAC_CFG_PORT_RST (1 << 29)
  25336. +#define VSC73XX_MAC_CFG_TX_EN (1 << 28)
  25337. +#define VSC73XX_MAC_CFG_SEED_LOAD (1 << 27)
  25338. +#define VSC73XX_MAC_CFG_FDX (1 << 18)
  25339. +#define VSC73XX_MAC_CFG_GIGE (1 << 17)
  25340. +#define VSC73XX_MAC_CFG_RX_EN (1 << 16)
  25341. +#define VSC73XX_MAC_CFG_VLAN_DBLAWR (1 << 15)
  25342. +#define VSC73XX_MAC_CFG_VLAN_AWR (1 << 14)
  25343. +#define VSC73XX_MAC_CFG_100_BASE_T (1 << 13)
  25344. +#define VSC73XX_MAC_CFG_TX_IPG(x) (((x) & 0x1f) << 6)
  25345. +#define VSC73XX_MAC_CFG_MAC_RX_RST (1 << 5)
  25346. +#define VSC73XX_MAC_CFG_MAC_TX_RST (1 << 4)
  25347. +#define VSC73XX_MAC_CFG_BIT2 (1 << 2)
  25348. +#define VSC73XX_MAC_CFG_CLK_SEL(x) ((x) & 0x3)
  25349. +
  25350. +/* ADVPORTM register bits */
  25351. +#define VSC73XX_ADVPORTM_IFG_PPM (1 << 7)
  25352. +#define VSC73XX_ADVPORTM_EXC_COL_CONT (1 << 6)
  25353. +#define VSC73XX_ADVPORTM_EXT_PORT (1 << 5)
  25354. +#define VSC73XX_ADVPORTM_INV_GTX (1 << 4)
  25355. +#define VSC73XX_ADVPORTM_ENA_GTX (1 << 3)
  25356. +#define VSC73XX_ADVPORTM_DDR_MODE (1 << 2)
  25357. +#define VSC73XX_ADVPORTM_IO_LOOPBACK (1 << 1)
  25358. +#define VSC73XX_ADVPORTM_HOST_LOOPBACK (1 << 0)
  25359. +
  25360. +/* MII Block registers */
  25361. +#define VSC73XX_MII_STAT 0x0
  25362. +#define VSC73XX_MII_CMD 0x1
  25363. +#define VSC73XX_MII_DATA 0x2
  25364. +
  25365. +/* System Block registers */
  25366. +#define VSC73XX_ICPU_SIPAD 0x01
  25367. +#define VSC73XX_ICPU_CLOCK_DELAY 0x05
  25368. +#define VSC73XX_ICPU_CTRL 0x10
  25369. +#define VSC73XX_ICPU_ADDR 0x11
  25370. +#define VSC73XX_ICPU_SRAM 0x12
  25371. +#define VSC73XX_ICPU_MBOX_VAL 0x15
  25372. +#define VSC73XX_ICPU_MBOX_SET 0x16
  25373. +#define VSC73XX_ICPU_MBOX_CLR 0x17
  25374. +#define VSC73XX_ICPU_CHIPID 0x18
  25375. +#define VSC73XX_ICPU_GPIO 0x34
  25376. +
  25377. +#define VSC73XX_ICPU_CTRL_CLK_DIV (1 << 8)
  25378. +#define VSC73XX_ICPU_CTRL_SRST_HOLD (1 << 7)
  25379. +#define VSC73XX_ICPU_CTRL_BOOT_EN (1 << 3)
  25380. +#define VSC73XX_ICPU_CTRL_EXT_ACC_EN (1 << 2)
  25381. +#define VSC73XX_ICPU_CTRL_CLK_EN (1 << 1)
  25382. +#define VSC73XX_ICPU_CTRL_SRST (1 << 0)
  25383. +
  25384. +#define VSC73XX_ICPU_CHIPID_ID_SHIFT 12
  25385. +#define VSC73XX_ICPU_CHIPID_ID_MASK 0xffff
  25386. +#define VSC73XX_ICPU_CHIPID_REV_SHIFT 28
  25387. +#define VSC73XX_ICPU_CHIPID_REV_MASK 0xf
  25388. +#define VSC73XX_ICPU_CHIPID_ID_7385 0x7385
  25389. +#define VSC73XX_ICPU_CHIPID_ID_7395 0x7395
  25390. +
  25391. +#define VSC73XX_CMD_MODE_READ 0
  25392. +#define VSC73XX_CMD_MODE_WRITE 1
  25393. +#define VSC73XX_CMD_MODE_SHIFT 4
  25394. +#define VSC73XX_CMD_BLOCK_SHIFT 5
  25395. +#define VSC73XX_CMD_BLOCK_MASK 0x7
  25396. +#define VSC73XX_CMD_SUBBLOCK_MASK 0xf
  25397. +
  25398. +#define VSC7385_CLOCK_DELAY ((3 << 4) | 3)
  25399. +#define VSC7385_CLOCK_DELAY_MASK ((3 << 4) | 3)
  25400. +
  25401. +#define VSC73XX_ICPU_CTRL_STOP (VSC73XX_ICPU_CTRL_SRST_HOLD | \
  25402. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  25403. + VSC73XX_ICPU_CTRL_EXT_ACC_EN)
  25404. +
  25405. +#define VSC73XX_ICPU_CTRL_START (VSC73XX_ICPU_CTRL_CLK_DIV | \
  25406. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  25407. + VSC73XX_ICPU_CTRL_CLK_EN | \
  25408. + VSC73XX_ICPU_CTRL_SRST)
  25409. +
  25410. +#define VSC7385_ADVPORTM_MASK (VSC73XX_ADVPORTM_IFG_PPM | \
  25411. + VSC73XX_ADVPORTM_EXC_COL_CONT | \
  25412. + VSC73XX_ADVPORTM_EXT_PORT | \
  25413. + VSC73XX_ADVPORTM_INV_GTX | \
  25414. + VSC73XX_ADVPORTM_ENA_GTX | \
  25415. + VSC73XX_ADVPORTM_DDR_MODE | \
  25416. + VSC73XX_ADVPORTM_IO_LOOPBACK | \
  25417. + VSC73XX_ADVPORTM_HOST_LOOPBACK)
  25418. +
  25419. +#define VSC7385_ADVPORTM_INIT (VSC73XX_ADVPORTM_EXT_PORT | \
  25420. + VSC73XX_ADVPORTM_ENA_GTX | \
  25421. + VSC73XX_ADVPORTM_DDR_MODE)
  25422. +
  25423. +#define VSC7385_MAC_CFG_RESET (VSC73XX_MAC_CFG_PORT_RST | \
  25424. + VSC73XX_MAC_CFG_MAC_RX_RST | \
  25425. + VSC73XX_MAC_CFG_MAC_TX_RST)
  25426. +
  25427. +#define VSC73XX_MAC_CFG_INIT (VSC73XX_MAC_CFG_TX_EN | \
  25428. + VSC73XX_MAC_CFG_FDX | \
  25429. + VSC73XX_MAC_CFG_GIGE | \
  25430. + VSC73XX_MAC_CFG_RX_EN)
  25431. +
  25432. +#define VSC73XX_RESET_DELAY 100
  25433. +
  25434. +struct vsc7385 {
  25435. + struct spi_device *spi;
  25436. + struct mutex lock;
  25437. + struct vsc7385_platform_data *pdata;
  25438. +};
  25439. +
  25440. +static int vsc7385_is_addr_valid(u8 block, u8 subblock)
  25441. +{
  25442. + switch (block) {
  25443. + case VSC73XX_BLOCK_MAC:
  25444. + switch (subblock) {
  25445. + case 0 ... 4:
  25446. + case 6:
  25447. + return 1;
  25448. + }
  25449. + break;
  25450. +
  25451. + case VSC73XX_BLOCK_2:
  25452. + case VSC73XX_BLOCK_SYSTEM:
  25453. + switch (subblock) {
  25454. + case 0:
  25455. + return 1;
  25456. + }
  25457. + break;
  25458. +
  25459. + case VSC73XX_BLOCK_MII:
  25460. + case VSC73XX_BLOCK_4:
  25461. + case VSC73XX_BLOCK_5:
  25462. + switch (subblock) {
  25463. + case 0 ... 1:
  25464. + return 1;
  25465. + }
  25466. + break;
  25467. + }
  25468. +
  25469. + return 0;
  25470. +}
  25471. +
  25472. +static inline u8 vsc7385_make_addr(u8 mode, u8 block, u8 subblock)
  25473. +{
  25474. + u8 ret;
  25475. +
  25476. + ret = (block & VSC73XX_CMD_BLOCK_MASK) << VSC73XX_CMD_BLOCK_SHIFT;
  25477. + ret |= (mode & 1) << VSC73XX_CMD_MODE_SHIFT;
  25478. + ret |= subblock & VSC73XX_CMD_SUBBLOCK_MASK;
  25479. +
  25480. + return ret;
  25481. +}
  25482. +
  25483. +static int vsc7385_read(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  25484. + u32 *value)
  25485. +{
  25486. + u8 cmd[4];
  25487. + u8 buf[4];
  25488. + struct spi_transfer t[2];
  25489. + struct spi_message m;
  25490. + int err;
  25491. +
  25492. + if (!vsc7385_is_addr_valid(block, subblock))
  25493. + return -EINVAL;
  25494. +
  25495. + spi_message_init(&m);
  25496. +
  25497. + memset(&t, 0, sizeof(t));
  25498. +
  25499. + t[0].tx_buf = cmd;
  25500. + t[0].len = sizeof(cmd);
  25501. + spi_message_add_tail(&t[0], &m);
  25502. +
  25503. + t[1].rx_buf = buf;
  25504. + t[1].len = sizeof(buf);
  25505. + spi_message_add_tail(&t[1], &m);
  25506. +
  25507. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_READ, block, subblock);
  25508. + cmd[1] = reg;
  25509. + cmd[2] = 0;
  25510. + cmd[3] = 0;
  25511. +
  25512. + mutex_lock(&vsc->lock);
  25513. + err = spi_sync(vsc->spi, &m);
  25514. + mutex_unlock(&vsc->lock);
  25515. +
  25516. + if (err)
  25517. + return err;
  25518. +
  25519. + *value = (((u32) buf[0]) << 24) | (((u32) buf[1]) << 16) |
  25520. + (((u32) buf[2]) << 8) | ((u32) buf[3]);
  25521. +
  25522. + return 0;
  25523. +}
  25524. +
  25525. +
  25526. +static int vsc7385_write(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  25527. + u32 value)
  25528. +{
  25529. + u8 cmd[2];
  25530. + u8 buf[4];
  25531. + struct spi_transfer t[2];
  25532. + struct spi_message m;
  25533. + int err;
  25534. +
  25535. + if (!vsc7385_is_addr_valid(block, subblock))
  25536. + return -EINVAL;
  25537. +
  25538. + spi_message_init(&m);
  25539. +
  25540. + memset(&t, 0, sizeof(t));
  25541. +
  25542. + t[0].tx_buf = cmd;
  25543. + t[0].len = sizeof(cmd);
  25544. + spi_message_add_tail(&t[0], &m);
  25545. +
  25546. + t[1].tx_buf = buf;
  25547. + t[1].len = sizeof(buf);
  25548. + spi_message_add_tail(&t[1], &m);
  25549. +
  25550. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_WRITE, block, subblock);
  25551. + cmd[1] = reg;
  25552. +
  25553. + buf[0] = (value >> 24) & 0xff;
  25554. + buf[1] = (value >> 16) & 0xff;
  25555. + buf[2] = (value >> 8) & 0xff;
  25556. + buf[3] = value & 0xff;
  25557. +
  25558. + mutex_lock(&vsc->lock);
  25559. + err = spi_sync(vsc->spi, &m);
  25560. + mutex_unlock(&vsc->lock);
  25561. +
  25562. + return err;
  25563. +}
  25564. +
  25565. +static inline int vsc7385_write_verify(struct vsc7385 *vsc, u8 block,
  25566. + u8 subblock, u8 reg, u32 value,
  25567. + u32 read_mask, u32 read_val)
  25568. +{
  25569. + struct spi_device *spi = vsc->spi;
  25570. + u32 t;
  25571. + int err;
  25572. +
  25573. + err = vsc7385_write(vsc, block, subblock, reg, value);
  25574. + if (err)
  25575. + return err;
  25576. +
  25577. + err = vsc7385_read(vsc, block, subblock, reg, &t);
  25578. + if (err)
  25579. + return err;
  25580. +
  25581. + if ((t & read_mask) != read_val) {
  25582. + dev_err(&spi->dev, "register write error\n");
  25583. + return -EIO;
  25584. + }
  25585. +
  25586. + return 0;
  25587. +}
  25588. +
  25589. +static inline int vsc7385_set_clock_delay(struct vsc7385 *vsc, u32 val)
  25590. +{
  25591. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25592. + VSC73XX_ICPU_CLOCK_DELAY, val);
  25593. +}
  25594. +
  25595. +static inline int vsc7385_get_clock_delay(struct vsc7385 *vsc, u32 *val)
  25596. +{
  25597. + return vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25598. + VSC73XX_ICPU_CLOCK_DELAY, val);
  25599. +}
  25600. +
  25601. +static inline int vsc7385_icpu_stop(struct vsc7385 *vsc)
  25602. +{
  25603. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  25604. + VSC73XX_ICPU_CTRL_STOP);
  25605. +}
  25606. +
  25607. +static inline int vsc7385_icpu_start(struct vsc7385 *vsc)
  25608. +{
  25609. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  25610. + VSC73XX_ICPU_CTRL_START);
  25611. +}
  25612. +
  25613. +static inline int vsc7385_icpu_reset(struct vsc7385 *vsc)
  25614. +{
  25615. + int rc;
  25616. +
  25617. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_ADDR,
  25618. + 0x0000);
  25619. + if (rc)
  25620. + dev_err(&vsc->spi->dev,
  25621. + "could not reset microcode, err=%d\n", rc);
  25622. +
  25623. + return rc;
  25624. +}
  25625. +
  25626. +static int vsc7385_upload_ucode(struct vsc7385 *vsc)
  25627. +{
  25628. + struct spi_device *spi = vsc->spi;
  25629. + const struct firmware *firmware;
  25630. + char *ucode_name;
  25631. + unsigned char *dp;
  25632. + unsigned int curVal;
  25633. + int i;
  25634. + int diffs;
  25635. + int rc;
  25636. +
  25637. + ucode_name = (vsc->pdata->ucode_name) ? vsc->pdata->ucode_name
  25638. + : "vsc7385_ucode.bin";
  25639. + rc = request_firmware(&firmware, ucode_name, &spi->dev);
  25640. + if (rc) {
  25641. + dev_err(&spi->dev, "request_firmware failed, err=%d\n",
  25642. + rc);
  25643. + return rc;
  25644. + }
  25645. +
  25646. + rc = vsc7385_icpu_stop(vsc);
  25647. + if (rc)
  25648. + goto out;
  25649. +
  25650. + rc = vsc7385_icpu_reset(vsc);
  25651. + if (rc)
  25652. + goto out;
  25653. +
  25654. + dev_info(&spi->dev, "uploading microcode...\n");
  25655. +
  25656. + dp = (unsigned char *) firmware->data;
  25657. + for (i = 0; i < firmware->size; i++) {
  25658. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25659. + VSC73XX_ICPU_SRAM, *dp++);
  25660. + if (rc) {
  25661. + dev_err(&spi->dev, "could not load microcode, err=%d\n",
  25662. + rc);
  25663. + goto out;
  25664. + }
  25665. + }
  25666. +
  25667. + rc = vsc7385_icpu_reset(vsc);
  25668. + if (rc)
  25669. + goto out;
  25670. +
  25671. + dev_info(&spi->dev, "verifying microcode...\n");
  25672. +
  25673. + dp = (unsigned char *) firmware->data;
  25674. + diffs = 0;
  25675. + for (i = 0; i < firmware->size; i++) {
  25676. + rc = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25677. + VSC73XX_ICPU_SRAM, &curVal);
  25678. + if (rc) {
  25679. + dev_err(&spi->dev, "could not read microcode %d\n",
  25680. + rc);
  25681. + goto out;
  25682. + }
  25683. +
  25684. + if (curVal > 0xff) {
  25685. + dev_err(&spi->dev, "bad val read: %04x : %02x %02x\n",
  25686. + i, *dp, curVal);
  25687. + rc = -EIO;
  25688. + goto out;
  25689. + }
  25690. +
  25691. + if ((curVal & 0xff) != *dp) {
  25692. + diffs++;
  25693. + dev_err(&spi->dev, "verify error: %04x : %02x %02x\n",
  25694. + i, *dp, curVal);
  25695. +
  25696. + if (diffs > 4)
  25697. + break;
  25698. + }
  25699. + dp++;
  25700. + }
  25701. +
  25702. + if (diffs) {
  25703. + dev_err(&spi->dev, "microcode verification failed\n");
  25704. + rc = -EIO;
  25705. + goto out;
  25706. + }
  25707. +
  25708. + dev_info(&spi->dev, "microcode uploaded\n");
  25709. +
  25710. + rc = vsc7385_icpu_start(vsc);
  25711. +
  25712. +out:
  25713. + release_firmware(firmware);
  25714. + return rc;
  25715. +}
  25716. +
  25717. +static int vsc7385_setup(struct vsc7385 *vsc)
  25718. +{
  25719. + struct vsc7385_platform_data *pdata = vsc->pdata;
  25720. + u32 t;
  25721. + int err;
  25722. +
  25723. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25724. + VSC73XX_ICPU_CLOCK_DELAY,
  25725. + VSC7385_CLOCK_DELAY,
  25726. + VSC7385_CLOCK_DELAY_MASK,
  25727. + VSC7385_CLOCK_DELAY);
  25728. + if (err)
  25729. + goto err;
  25730. +
  25731. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_MAC,
  25732. + VSC73XX_SUBBLOCK_PORT_MAC, VSC73XX_ADVPORTM,
  25733. + VSC7385_ADVPORTM_INIT,
  25734. + VSC7385_ADVPORTM_MASK,
  25735. + VSC7385_ADVPORTM_INIT);
  25736. + if (err)
  25737. + goto err;
  25738. +
  25739. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  25740. + VSC73XX_MAC_CFG, VSC7385_MAC_CFG_RESET);
  25741. + if (err)
  25742. + goto err;
  25743. +
  25744. + t = VSC73XX_MAC_CFG_INIT;
  25745. + t |= VSC73XX_MAC_CFG_TX_IPG(pdata->mac_cfg.tx_ipg);
  25746. + t |= VSC73XX_MAC_CFG_CLK_SEL(pdata->mac_cfg.clk_sel);
  25747. + if (pdata->mac_cfg.bit2)
  25748. + t |= VSC73XX_MAC_CFG_BIT2;
  25749. +
  25750. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  25751. + VSC73XX_MAC_CFG, t);
  25752. + if (err)
  25753. + goto err;
  25754. +
  25755. + return 0;
  25756. +
  25757. +err:
  25758. + return err;
  25759. +}
  25760. +
  25761. +static int vsc7385_detect(struct vsc7385 *vsc)
  25762. +{
  25763. + struct spi_device *spi = vsc->spi;
  25764. + u32 t;
  25765. + u32 id;
  25766. + u32 rev;
  25767. + int err;
  25768. +
  25769. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25770. + VSC73XX_ICPU_MBOX_VAL, &t);
  25771. + if (err) {
  25772. + dev_err(&spi->dev, "unable to read mailbox, err=%d\n", err);
  25773. + return err;
  25774. + }
  25775. +
  25776. + if (t == 0xffffffff) {
  25777. + dev_dbg(&spi->dev, "assert chip reset\n");
  25778. + if (vsc->pdata->reset)
  25779. + vsc->pdata->reset();
  25780. +
  25781. + }
  25782. +
  25783. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  25784. + VSC73XX_ICPU_CHIPID, &t);
  25785. + if (err) {
  25786. + dev_err(&spi->dev, "unable to read chip id, err=%d\n", err);
  25787. + return err;
  25788. + }
  25789. +
  25790. + id = (t >> VSC73XX_ICPU_CHIPID_ID_SHIFT) & VSC73XX_ICPU_CHIPID_ID_MASK;
  25791. + switch (id) {
  25792. + case VSC73XX_ICPU_CHIPID_ID_7385:
  25793. + case VSC73XX_ICPU_CHIPID_ID_7395:
  25794. + break;
  25795. + default:
  25796. + dev_err(&spi->dev, "unsupported chip, id=%04x\n", id);
  25797. + return -ENODEV;
  25798. + }
  25799. +
  25800. + rev = (t >> VSC73XX_ICPU_CHIPID_REV_SHIFT) &
  25801. + VSC73XX_ICPU_CHIPID_REV_MASK;
  25802. + dev_info(&spi->dev, "VSC%04X (rev. %d) switch found\n", id, rev);
  25803. +
  25804. + return 0;
  25805. +}
  25806. +
  25807. +static int __devinit vsc7385_probe(struct spi_device *spi)
  25808. +{
  25809. + struct vsc7385 *vsc;
  25810. + struct vsc7385_platform_data *pdata;
  25811. + int err;
  25812. +
  25813. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION"\n");
  25814. +
  25815. + pdata = spi->dev.platform_data;
  25816. + if (!pdata) {
  25817. + dev_err(&spi->dev, "no platform data specified\n");
  25818. + return -ENODEV;
  25819. + }
  25820. +
  25821. + vsc = kzalloc(sizeof(*vsc), GFP_KERNEL);
  25822. + if (!vsc) {
  25823. + dev_err(&spi->dev, "no memory for private data\n");
  25824. + return -ENOMEM;
  25825. + }
  25826. +
  25827. + mutex_init(&vsc->lock);
  25828. + vsc->pdata = pdata;
  25829. + vsc->spi = spi_dev_get(spi);
  25830. + dev_set_drvdata(&spi->dev, vsc);
  25831. +
  25832. + spi->mode = SPI_MODE_0;
  25833. + spi->bits_per_word = 8;
  25834. + err = spi_setup(spi);
  25835. + if (err) {
  25836. + dev_err(&spi->dev, "spi_setup failed, err=%d\n", err);
  25837. + goto err_drvdata;
  25838. + }
  25839. +
  25840. + err = vsc7385_detect(vsc);
  25841. + if (err) {
  25842. + dev_err(&spi->dev, "no chip found, err=%d\n", err);
  25843. + goto err_drvdata;
  25844. + }
  25845. +
  25846. + err = vsc7385_upload_ucode(vsc);
  25847. + if (err)
  25848. + goto err_drvdata;
  25849. +
  25850. + err = vsc7385_setup(vsc);
  25851. + if (err)
  25852. + goto err_drvdata;
  25853. +
  25854. + return 0;
  25855. +
  25856. +err_drvdata:
  25857. + dev_set_drvdata(&spi->dev, NULL);
  25858. + kfree(vsc);
  25859. + return err;
  25860. +}
  25861. +
  25862. +static int __devexit vsc7385_remove(struct spi_device *spi)
  25863. +{
  25864. + struct vsc7385_data *vsc;
  25865. +
  25866. + vsc = dev_get_drvdata(&spi->dev);
  25867. + dev_set_drvdata(&spi->dev, NULL);
  25868. + kfree(vsc);
  25869. +
  25870. + return 0;
  25871. +}
  25872. +
  25873. +static struct spi_driver vsc7385_driver = {
  25874. + .driver = {
  25875. + .name = DRV_NAME,
  25876. + .bus = &spi_bus_type,
  25877. + .owner = THIS_MODULE,
  25878. + },
  25879. + .probe = vsc7385_probe,
  25880. + .remove = __devexit_p(vsc7385_remove),
  25881. +};
  25882. +
  25883. +static int __init vsc7385_init(void)
  25884. +{
  25885. + return spi_register_driver(&vsc7385_driver);
  25886. +}
  25887. +module_init(vsc7385_init);
  25888. +
  25889. +static void __exit vsc7385_exit(void)
  25890. +{
  25891. + spi_unregister_driver(&vsc7385_driver);
  25892. +}
  25893. +module_exit(vsc7385_exit);
  25894. +
  25895. +MODULE_DESCRIPTION(DRV_DESC);
  25896. +MODULE_VERSION(DRV_VERSION);
  25897. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  25898. +MODULE_LICENSE("GPL v2");
  25899. +
  25900. diff -Nur linux-2.6.39.orig/drivers/tty/serial/ar933x_uart.c linux-2.6.39/drivers/tty/serial/ar933x_uart.c
  25901. --- linux-2.6.39.orig/drivers/tty/serial/ar933x_uart.c 1970-01-01 01:00:00.000000000 +0100
  25902. +++ linux-2.6.39/drivers/tty/serial/ar933x_uart.c 2011-08-06 09:32:37.098016752 +0200
  25903. @@ -0,0 +1,688 @@
  25904. +/*
  25905. + * Atheros AR933X SoC built-in UART driver
  25906. + *
  25907. + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  25908. + *
  25909. + * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  25910. + *
  25911. + * This program is free software; you can redistribute it and/or modify it
  25912. + * under the terms of the GNU General Public License version 2 as published
  25913. + * by the Free Software Foundation.
  25914. + */
  25915. +
  25916. +#include <linux/module.h>
  25917. +#include <linux/ioport.h>
  25918. +#include <linux/init.h>
  25919. +#include <linux/console.h>
  25920. +#include <linux/sysrq.h>
  25921. +#include <linux/delay.h>
  25922. +#include <linux/platform_device.h>
  25923. +#include <linux/tty.h>
  25924. +#include <linux/tty_flip.h>
  25925. +#include <linux/serial_core.h>
  25926. +#include <linux/serial.h>
  25927. +#include <linux/slab.h>
  25928. +#include <linux/io.h>
  25929. +#include <linux/irq.h>
  25930. +
  25931. +#include <asm/mach-ar71xx/ar933x_uart.h>
  25932. +#include <asm/mach-ar71xx/ar933x_uart_platform.h>
  25933. +
  25934. +#define DRIVER_NAME "ar933x-uart"
  25935. +
  25936. +#define AR933X_DUMMY_STATUS_RD 0x01
  25937. +
  25938. +static struct uart_driver ar933x_uart_driver;
  25939. +
  25940. +struct ar933x_uart_port {
  25941. + struct uart_port port;
  25942. + unsigned int ier; /* shadow Interrupt Enable Register */
  25943. +};
  25944. +
  25945. +static inline unsigned int ar933x_uart_read(struct ar933x_uart_port *up,
  25946. + int offset)
  25947. +{
  25948. + return readl(up->port.membase + offset);
  25949. +}
  25950. +
  25951. +static inline void ar933x_uart_write(struct ar933x_uart_port *up,
  25952. + int offset, unsigned int value)
  25953. +{
  25954. + writel(value, up->port.membase + offset);
  25955. +}
  25956. +
  25957. +static inline void ar933x_uart_rmw(struct ar933x_uart_port *up,
  25958. + unsigned int offset,
  25959. + unsigned int mask,
  25960. + unsigned int val)
  25961. +{
  25962. + unsigned int t;
  25963. +
  25964. + t = ar933x_uart_read(up, offset);
  25965. + t &= ~mask;
  25966. + t |= val;
  25967. + ar933x_uart_write(up, offset, t);
  25968. +}
  25969. +
  25970. +static inline void ar933x_uart_rmw_set(struct ar933x_uart_port *up,
  25971. + unsigned int offset,
  25972. + unsigned int val)
  25973. +{
  25974. + ar933x_uart_rmw(up, offset, 0, val);
  25975. +}
  25976. +
  25977. +static inline void ar933x_uart_rmw_clear(struct ar933x_uart_port *up,
  25978. + unsigned int offset,
  25979. + unsigned int val)
  25980. +{
  25981. + ar933x_uart_rmw(up, offset, val, 0);
  25982. +}
  25983. +
  25984. +static inline void ar933x_uart_start_tx_interrupt(struct ar933x_uart_port *up)
  25985. +{
  25986. + up->ier |= AR933X_UART_INT_TX_EMPTY;
  25987. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
  25988. +}
  25989. +
  25990. +static inline void ar933x_uart_stop_tx_interrupt(struct ar933x_uart_port *up)
  25991. +{
  25992. + up->ier &= ~AR933X_UART_INT_TX_EMPTY;
  25993. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
  25994. +}
  25995. +
  25996. +static inline void ar933x_uart_putc(struct ar933x_uart_port *up, int ch)
  25997. +{
  25998. + unsigned int rdata;
  25999. +
  26000. + rdata = ch & AR933X_UART_DATA_TX_RX_MASK;
  26001. + rdata |= AR933X_UART_DATA_TX_CSR;
  26002. + ar933x_uart_write(up, AR933X_UART_DATA_REG, rdata);
  26003. +}
  26004. +
  26005. +static unsigned int ar933x_uart_tx_empty(struct uart_port *port)
  26006. +{
  26007. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26008. + unsigned long flags;
  26009. + unsigned int rdata;
  26010. +
  26011. + spin_lock_irqsave(&up->port.lock, flags);
  26012. + rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
  26013. + spin_unlock_irqrestore(&up->port.lock, flags);
  26014. +
  26015. + return (rdata & AR933X_UART_DATA_TX_CSR) ? 0 : TIOCSER_TEMT;
  26016. +}
  26017. +
  26018. +static unsigned int ar933x_uart_get_mctrl(struct uart_port *port)
  26019. +{
  26020. + return TIOCM_CAR;
  26021. +}
  26022. +
  26023. +static void ar933x_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
  26024. +{
  26025. +}
  26026. +
  26027. +static void ar933x_uart_start_tx(struct uart_port *port)
  26028. +{
  26029. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26030. +
  26031. + ar933x_uart_start_tx_interrupt(up);
  26032. +}
  26033. +
  26034. +static void ar933x_uart_stop_tx(struct uart_port *port)
  26035. +{
  26036. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26037. +
  26038. + ar933x_uart_stop_tx_interrupt(up);
  26039. +}
  26040. +
  26041. +static void ar933x_uart_stop_rx(struct uart_port *port)
  26042. +{
  26043. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26044. +
  26045. + up->ier &= ~AR933X_UART_INT_RX_VALID;
  26046. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
  26047. +}
  26048. +
  26049. +static void ar933x_uart_break_ctl(struct uart_port *port, int break_state)
  26050. +{
  26051. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26052. + unsigned long flags;
  26053. +
  26054. + spin_lock_irqsave(&up->port.lock, flags);
  26055. + if (break_state == -1)
  26056. + ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
  26057. + AR933X_UART_CS_TX_BREAK);
  26058. + else
  26059. + ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG,
  26060. + AR933X_UART_CS_TX_BREAK);
  26061. + spin_unlock_irqrestore(&up->port.lock, flags);
  26062. +}
  26063. +
  26064. +static void ar933x_uart_enable_ms(struct uart_port *port)
  26065. +{
  26066. +}
  26067. +
  26068. +static void ar933x_uart_set_termios(struct uart_port *port,
  26069. + struct ktermios *new,
  26070. + struct ktermios *old)
  26071. +{
  26072. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26073. + unsigned int cs;
  26074. + unsigned long flags;
  26075. + unsigned int baud, scale;
  26076. +
  26077. + /* Only CS8 is supported */
  26078. + new->c_cflag &= ~CSIZE;
  26079. + new->c_cflag |= CS8;
  26080. +
  26081. + /* Only one stop bit is supported */
  26082. + new->c_cflag &= ~CSTOPB;
  26083. +
  26084. + cs = 0;
  26085. + if (new->c_cflag & PARENB) {
  26086. + if (!(new->c_cflag & PARODD))
  26087. + cs |= AR933X_UART_CS_PARITY_EVEN;
  26088. + else
  26089. + cs |= AR933X_UART_CS_PARITY_ODD;
  26090. + } else {
  26091. + cs |= AR933X_UART_CS_PARITY_NONE;
  26092. + }
  26093. +
  26094. + /* Mark/space parity is not supported */
  26095. + new->c_cflag &= ~CMSPAR;
  26096. +
  26097. + baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
  26098. + scale = (port->uartclk / (16 * baud)) - 1;
  26099. +
  26100. + /*
  26101. + * Ok, we're now changing the port state. Do it with
  26102. + * interrupts disabled.
  26103. + */
  26104. + spin_lock_irqsave(&up->port.lock, flags);
  26105. +
  26106. + /* Update the per-port timeout. */
  26107. + uart_update_timeout(port, new->c_cflag, baud);
  26108. +
  26109. + up->port.ignore_status_mask = 0;
  26110. +
  26111. + /* ignore all characters if CREAD is not set */
  26112. + if ((new->c_cflag & CREAD) == 0)
  26113. + up->port.ignore_status_mask |= AR933X_DUMMY_STATUS_RD;
  26114. +
  26115. + ar933x_uart_write(up, AR933X_UART_CLOCK_REG,
  26116. + scale << AR933X_UART_CLOCK_SCALE_S | 8192);
  26117. +
  26118. + /* setup configuration register */
  26119. + ar933x_uart_rmw(up, AR933X_UART_CS_REG, AR933X_UART_CS_PARITY_M, cs);
  26120. +
  26121. + /* enable host interrupt */
  26122. + ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
  26123. + AR933X_UART_CS_HOST_INT_EN);
  26124. +
  26125. + spin_unlock_irqrestore(&up->port.lock, flags);
  26126. +
  26127. + if (tty_termios_baud_rate(new))
  26128. + tty_termios_encode_baud_rate(new, baud, baud);
  26129. +}
  26130. +
  26131. +static void ar933x_uart_rx_chars(struct ar933x_uart_port *up)
  26132. +{
  26133. + struct tty_struct *tty;
  26134. + int max_count = 256;
  26135. +
  26136. + tty = tty_port_tty_get(&up->port.state->port);
  26137. + do {
  26138. + unsigned int rdata;
  26139. + unsigned char ch;
  26140. +
  26141. + rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
  26142. + if ((rdata & AR933X_UART_DATA_RX_CSR) == 0)
  26143. + break;
  26144. +
  26145. + /* remove the character from the FIFO */
  26146. + ar933x_uart_write(up, AR933X_UART_DATA_REG,
  26147. + AR933X_UART_DATA_RX_CSR);
  26148. +
  26149. + if (!tty) {
  26150. + /* discard the data if no tty available */
  26151. + continue;
  26152. + }
  26153. +
  26154. + up->port.icount.rx++;
  26155. + ch = rdata & AR933X_UART_DATA_TX_RX_MASK;
  26156. +
  26157. + if (uart_handle_sysrq_char(&up->port, ch))
  26158. + continue;
  26159. +
  26160. + if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0)
  26161. + tty_insert_flip_char(tty, ch, TTY_NORMAL);
  26162. + } while (max_count-- > 0);
  26163. +
  26164. + if (tty) {
  26165. + tty_flip_buffer_push(tty);
  26166. + tty_kref_put(tty);
  26167. + }
  26168. +}
  26169. +
  26170. +static void ar933x_uart_tx_chars(struct ar933x_uart_port *up)
  26171. +{
  26172. + struct circ_buf *xmit = &up->port.state->xmit;
  26173. + int count;
  26174. +
  26175. + if (uart_tx_stopped(&up->port))
  26176. + return;
  26177. +
  26178. + count = up->port.fifosize;
  26179. + do {
  26180. + unsigned int rdata;
  26181. +
  26182. + rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
  26183. + if ((rdata & AR933X_UART_DATA_TX_CSR) == 0)
  26184. + break;
  26185. +
  26186. + if (up->port.x_char) {
  26187. + ar933x_uart_putc(up, up->port.x_char);
  26188. + up->port.icount.tx++;
  26189. + up->port.x_char = 0;
  26190. + continue;
  26191. + }
  26192. +
  26193. + if (uart_circ_empty(xmit))
  26194. + break;
  26195. +
  26196. + ar933x_uart_putc(up, xmit->buf[xmit->tail]);
  26197. +
  26198. + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  26199. + up->port.icount.tx++;
  26200. + } while (--count > 0);
  26201. +
  26202. + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  26203. + uart_write_wakeup(&up->port);
  26204. +
  26205. + if (!uart_circ_empty(xmit))
  26206. + ar933x_uart_start_tx_interrupt(up);
  26207. +}
  26208. +
  26209. +static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id)
  26210. +{
  26211. + struct ar933x_uart_port *up = dev_id;
  26212. + unsigned int status;
  26213. +
  26214. + status = ar933x_uart_read(up, AR933X_UART_CS_REG);
  26215. + if ((status & AR933X_UART_CS_HOST_INT) == 0)
  26216. + return IRQ_NONE;
  26217. +
  26218. + spin_lock(&up->port.lock);
  26219. +
  26220. + status = ar933x_uart_read(up, AR933X_UART_INT_REG);
  26221. + status &= ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
  26222. +
  26223. + if (status & AR933X_UART_INT_RX_VALID) {
  26224. + ar933x_uart_write(up, AR933X_UART_INT_REG,
  26225. + AR933X_UART_INT_RX_VALID);
  26226. + ar933x_uart_rx_chars(up);
  26227. + }
  26228. +
  26229. + if (status & AR933X_UART_INT_TX_EMPTY) {
  26230. + ar933x_uart_write(up, AR933X_UART_INT_REG,
  26231. + AR933X_UART_INT_TX_EMPTY);
  26232. + ar933x_uart_stop_tx_interrupt(up);
  26233. + ar933x_uart_tx_chars(up);
  26234. + }
  26235. +
  26236. + spin_unlock(&up->port.lock);
  26237. +
  26238. + return IRQ_HANDLED;
  26239. +}
  26240. +
  26241. +static int ar933x_uart_startup(struct uart_port *port)
  26242. +{
  26243. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26244. + unsigned long flags;
  26245. + int ret;
  26246. +
  26247. + ret = request_irq(up->port.irq, ar933x_uart_interrupt,
  26248. + up->port.irqflags, dev_name(up->port.dev), up);
  26249. + if (ret)
  26250. + return ret;
  26251. +
  26252. + spin_lock_irqsave(&up->port.lock, flags);
  26253. +
  26254. + /* Enable HOST interrupts */
  26255. + ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
  26256. + AR933X_UART_CS_HOST_INT_EN);
  26257. +
  26258. + /* Enable RX interrupts */
  26259. + up->ier = AR933X_UART_INT_RX_VALID;
  26260. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
  26261. +
  26262. + spin_unlock_irqrestore(&up->port.lock, flags);
  26263. +
  26264. + return 0;
  26265. +}
  26266. +
  26267. +static void ar933x_uart_shutdown(struct uart_port *port)
  26268. +{
  26269. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26270. +
  26271. + /* Disable all interrupts */
  26272. + up->ier = 0;
  26273. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
  26274. +
  26275. + /* Disable break condition */
  26276. + ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG,
  26277. + AR933X_UART_CS_TX_BREAK);
  26278. +
  26279. + free_irq(up->port.irq, up);
  26280. +}
  26281. +
  26282. +static const char *ar933x_uart_type(struct uart_port *port)
  26283. +{
  26284. + return (port->type == PORT_AR933X) ? "AR933X UART" : NULL;
  26285. +}
  26286. +
  26287. +static void ar933x_uart_release_port(struct uart_port *port)
  26288. +{
  26289. + /* Nothing to release ... */
  26290. +}
  26291. +
  26292. +static int ar933x_uart_request_port(struct uart_port *port)
  26293. +{
  26294. + /* UARTs always present */
  26295. + return 0;
  26296. +}
  26297. +
  26298. +static void ar933x_uart_config_port(struct uart_port *port, int flags)
  26299. +{
  26300. + if (flags & UART_CONFIG_TYPE)
  26301. + port->type = PORT_AR933X;
  26302. +}
  26303. +
  26304. +static int ar933x_uart_verify_port(struct uart_port *port,
  26305. + struct serial_struct *ser)
  26306. +{
  26307. + if (ser->type != PORT_UNKNOWN &&
  26308. + ser->type != PORT_AR933X)
  26309. + return -EINVAL;
  26310. +
  26311. + if (ser->irq < 0 || ser->irq >= NR_IRQS)
  26312. + return -EINVAL;
  26313. +
  26314. + if (ser->baud_base < 28800)
  26315. + return -EINVAL;
  26316. +
  26317. + return 0;
  26318. +}
  26319. +
  26320. +static struct uart_ops ar933x_uart_ops = {
  26321. + .tx_empty = ar933x_uart_tx_empty,
  26322. + .set_mctrl = ar933x_uart_set_mctrl,
  26323. + .get_mctrl = ar933x_uart_get_mctrl,
  26324. + .stop_tx = ar933x_uart_stop_tx,
  26325. + .start_tx = ar933x_uart_start_tx,
  26326. + .stop_rx = ar933x_uart_stop_rx,
  26327. + .enable_ms = ar933x_uart_enable_ms,
  26328. + .break_ctl = ar933x_uart_break_ctl,
  26329. + .startup = ar933x_uart_startup,
  26330. + .shutdown = ar933x_uart_shutdown,
  26331. + .set_termios = ar933x_uart_set_termios,
  26332. + .type = ar933x_uart_type,
  26333. + .release_port = ar933x_uart_release_port,
  26334. + .request_port = ar933x_uart_request_port,
  26335. + .config_port = ar933x_uart_config_port,
  26336. + .verify_port = ar933x_uart_verify_port,
  26337. +};
  26338. +
  26339. +#ifdef CONFIG_SERIAL_AR933X_CONSOLE
  26340. +
  26341. +static struct ar933x_uart_port *
  26342. +ar933x_console_ports[CONFIG_SERIAL_AR933X_NR_UARTS];
  26343. +
  26344. +static void ar933x_uart_wait_xmitr(struct ar933x_uart_port *up)
  26345. +{
  26346. + unsigned int status;
  26347. + unsigned int timeout = 60000;
  26348. +
  26349. + /* Wait up to 60ms for the character(s) to be sent. */
  26350. + do {
  26351. + status = ar933x_uart_read(up, AR933X_UART_DATA_REG);
  26352. + if (--timeout == 0)
  26353. + break;
  26354. + udelay(1);
  26355. + } while ((status & AR933X_UART_DATA_TX_CSR) == 0);
  26356. +}
  26357. +
  26358. +static void ar933x_uart_console_putchar(struct uart_port *port, int ch)
  26359. +{
  26360. + struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
  26361. +
  26362. + ar933x_uart_wait_xmitr(up);
  26363. + ar933x_uart_putc(up, ch);
  26364. +}
  26365. +
  26366. +static void ar933x_uart_console_write(struct console *co, const char *s,
  26367. + unsigned int count)
  26368. +{
  26369. + struct ar933x_uart_port *up = ar933x_console_ports[co->index];
  26370. + unsigned long flags;
  26371. + unsigned int int_en;
  26372. + int locked = 1;
  26373. +
  26374. + local_irq_save(flags);
  26375. +
  26376. + if (up->port.sysrq)
  26377. + locked = 0;
  26378. + else if (oops_in_progress)
  26379. + locked = spin_trylock(&up->port.lock);
  26380. + else
  26381. + spin_lock(&up->port.lock);
  26382. +
  26383. + /*
  26384. + * First save the IER then disable the interrupts
  26385. + */
  26386. + int_en = ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
  26387. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, 0);
  26388. +
  26389. + uart_console_write(&up->port, s, count, ar933x_uart_console_putchar);
  26390. +
  26391. + /*
  26392. + * Finally, wait for transmitter to become empty
  26393. + * and restore the IER
  26394. + */
  26395. + ar933x_uart_wait_xmitr(up);
  26396. + ar933x_uart_write(up, AR933X_UART_INT_EN_REG, int_en);
  26397. +
  26398. + ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS);
  26399. +
  26400. + if (locked)
  26401. + spin_unlock(&up->port.lock);
  26402. +
  26403. + local_irq_restore(flags);
  26404. +}
  26405. +
  26406. +static int ar933x_uart_console_setup(struct console *co, char *options)
  26407. +{
  26408. + struct ar933x_uart_port *up;
  26409. + int baud = 115200;
  26410. + int bits = 8;
  26411. + int parity = 'n';
  26412. + int flow = 'n';
  26413. +
  26414. + if (co->index < 0 || co->index >= CONFIG_SERIAL_AR933X_NR_UARTS)
  26415. + return -EINVAL;
  26416. +
  26417. + up = ar933x_console_ports[co->index];
  26418. + if (!up)
  26419. + return -ENODEV;
  26420. +
  26421. + if (options)
  26422. + uart_parse_options(options, &baud, &parity, &bits, &flow);
  26423. +
  26424. + return uart_set_options(&up->port, co, baud, parity, bits, flow);
  26425. +}
  26426. +
  26427. +static struct console ar933x_uart_console = {
  26428. + .name = "ttyATH",
  26429. + .write = ar933x_uart_console_write,
  26430. + .device = uart_console_device,
  26431. + .setup = ar933x_uart_console_setup,
  26432. + .flags = CON_PRINTBUFFER,
  26433. + .index = -1,
  26434. + .data = &ar933x_uart_driver,
  26435. +};
  26436. +
  26437. +static void ar933x_uart_add_console_port(struct ar933x_uart_port *up)
  26438. +{
  26439. + ar933x_console_ports[up->port.line] = up;
  26440. +}
  26441. +
  26442. +#define AR933X_SERIAL_CONSOLE (&ar933x_uart_console)
  26443. +
  26444. +#else
  26445. +
  26446. +static inline void ar933x_uart_add_console_port(struct ar933x_uart_port *up) {}
  26447. +
  26448. +#define AR933X_SERIAL_CONSOLE NULL
  26449. +
  26450. +#endif /* CONFIG_SERIAL_AR933X_CONSOLE */
  26451. +
  26452. +static struct uart_driver ar933x_uart_driver = {
  26453. + .owner = THIS_MODULE,
  26454. + .driver_name = DRIVER_NAME,
  26455. + .dev_name = "ttyATH",
  26456. + .nr = CONFIG_SERIAL_AR933X_NR_UARTS,
  26457. + .cons = AR933X_SERIAL_CONSOLE,
  26458. +};
  26459. +
  26460. +static int __devinit ar933x_uart_probe(struct platform_device *pdev)
  26461. +{
  26462. + struct ar933x_uart_platform_data *pdata;
  26463. + struct ar933x_uart_port *up;
  26464. + struct uart_port *port;
  26465. + struct resource *mem_res;
  26466. + struct resource *irq_res;
  26467. + int id;
  26468. + int ret;
  26469. +
  26470. + pdata = pdev->dev.platform_data;
  26471. + if (!pdata)
  26472. + return -EINVAL;
  26473. +
  26474. + id = pdev->id;
  26475. + if (id == -1)
  26476. + id = 0;
  26477. +
  26478. + if (id > CONFIG_SERIAL_AR933X_NR_UARTS)
  26479. + return -EINVAL;
  26480. +
  26481. + mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  26482. + if (!mem_res) {
  26483. + dev_err(&pdev->dev, "no MEM resource\n");
  26484. + return -EINVAL;
  26485. + }
  26486. +
  26487. + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  26488. + if (!irq_res) {
  26489. + dev_err(&pdev->dev, "no IRQ resource\n");
  26490. + return -EINVAL;
  26491. + }
  26492. +
  26493. + up = kzalloc(sizeof(struct ar933x_uart_port), GFP_KERNEL);
  26494. + if (!up)
  26495. + return -ENOMEM;
  26496. +
  26497. + port = &up->port;
  26498. + port->mapbase = mem_res->start;
  26499. +
  26500. + port->membase = ioremap(mem_res->start, AR933X_UART_REGS_SIZE);
  26501. + if (!port->membase) {
  26502. + ret = -ENOMEM;
  26503. + goto err_free_up;
  26504. + }
  26505. +
  26506. + port->line = id;
  26507. + port->irq = irq_res->start;
  26508. + port->dev = &pdev->dev;
  26509. + port->type = PORT_AR933X;
  26510. + port->iotype = UPIO_MEM32;
  26511. + port->uartclk = pdata->uartclk;
  26512. +
  26513. + port->regshift = 2;
  26514. + port->fifosize = AR933X_UART_FIFO_SIZE;
  26515. + port->ops = &ar933x_uart_ops;
  26516. +
  26517. + ar933x_uart_add_console_port(up);
  26518. +
  26519. + ret = uart_add_one_port(&ar933x_uart_driver, &up->port);
  26520. + if (ret)
  26521. + goto err_unmap;
  26522. +
  26523. + platform_set_drvdata(pdev, up);
  26524. + return 0;
  26525. +
  26526. +err_unmap:
  26527. + iounmap(up->port.membase);
  26528. +err_free_up:
  26529. + kfree(up);
  26530. + return ret;
  26531. +}
  26532. +
  26533. +static int __devexit ar933x_uart_remove(struct platform_device *pdev)
  26534. +{
  26535. + struct ar933x_uart_port *up;
  26536. +
  26537. + up = platform_get_drvdata(pdev);
  26538. + platform_set_drvdata(pdev, NULL);
  26539. +
  26540. + if (up) {
  26541. + uart_remove_one_port(&ar933x_uart_driver, &up->port);
  26542. + iounmap(up->port.membase);
  26543. + kfree(up);
  26544. + }
  26545. +
  26546. + return 0;
  26547. +}
  26548. +
  26549. +static struct platform_driver ar933x_uart_platform_driver = {
  26550. + .probe = ar933x_uart_probe,
  26551. + .remove = __devexit_p(ar933x_uart_remove),
  26552. + .driver = {
  26553. + .name = DRIVER_NAME,
  26554. + .owner = THIS_MODULE,
  26555. + },
  26556. +};
  26557. +
  26558. +static int __init ar933x_uart_init(void)
  26559. +{
  26560. + int ret;
  26561. +
  26562. + ar933x_uart_driver.nr = CONFIG_SERIAL_AR933X_NR_UARTS;
  26563. + ret = uart_register_driver(&ar933x_uart_driver);
  26564. + if (ret)
  26565. + goto err_out;
  26566. +
  26567. + ret = platform_driver_register(&ar933x_uart_platform_driver);
  26568. + if (ret)
  26569. + goto err_unregister_uart_driver;
  26570. +
  26571. + return 0;
  26572. +
  26573. +err_unregister_uart_driver:
  26574. + uart_unregister_driver(&ar933x_uart_driver);
  26575. +err_out:
  26576. + return ret;
  26577. +}
  26578. +
  26579. +static void __exit ar933x_uart_exit(void)
  26580. +{
  26581. + platform_driver_unregister(&ar933x_uart_platform_driver);
  26582. + uart_unregister_driver(&ar933x_uart_driver);
  26583. +}
  26584. +
  26585. +module_init(ar933x_uart_init);
  26586. +module_exit(ar933x_uart_exit);
  26587. +
  26588. +MODULE_DESCRIPTION("Atheros AR933X UART driver");
  26589. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  26590. +MODULE_LICENSE("GPL v2");
  26591. +MODULE_ALIAS("platform:" DRIVER_NAME);
  26592. diff -Nur linux-2.6.39.orig/drivers/usb/host/ehci-ar71xx.c linux-2.6.39/drivers/usb/host/ehci-ar71xx.c
  26593. --- linux-2.6.39.orig/drivers/usb/host/ehci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  26594. +++ linux-2.6.39/drivers/usb/host/ehci-ar71xx.c 2011-04-27 12:19:22.267661616 +0200
  26595. @@ -0,0 +1,242 @@
  26596. +/*
  26597. + * Bus Glue for Atheros AR71xx built-in EHCI controller.
  26598. + *
  26599. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  26600. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  26601. + *
  26602. + * Parts of this file are based on Atheros' 2.6.15 BSP
  26603. + * Copyright (C) 2007 Atheros Communications, Inc.
  26604. + *
  26605. + * This program is free software; you can redistribute it and/or modify it
  26606. + * under the terms of the GNU General Public License version 2 as published
  26607. + * by the Free Software Foundation.
  26608. + */
  26609. +
  26610. +#include <linux/platform_device.h>
  26611. +#include <linux/delay.h>
  26612. +
  26613. +#include <asm/mach-ar71xx/platform.h>
  26614. +
  26615. +extern int usb_disabled(void);
  26616. +
  26617. +static int ehci_ar71xx_init(struct usb_hcd *hcd)
  26618. +{
  26619. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  26620. + int ret;
  26621. +
  26622. + ehci->caps = hcd->regs;
  26623. + ehci->regs = hcd->regs +
  26624. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  26625. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  26626. +
  26627. + ehci->sbrn = 0x20;
  26628. + ehci->has_synopsys_hc_bug = 1;
  26629. +
  26630. + ehci_reset(ehci);
  26631. +
  26632. + ret = ehci_init(hcd);
  26633. + if (ret)
  26634. + return ret;
  26635. +
  26636. + ehci_port_power(ehci, 0);
  26637. +
  26638. + return 0;
  26639. +}
  26640. +
  26641. +static int ehci_ar91xx_init(struct usb_hcd *hcd)
  26642. +{
  26643. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  26644. + int ret;
  26645. +
  26646. + ehci->caps = hcd->regs + 0x100;
  26647. + ehci->regs = hcd->regs + 0x100 +
  26648. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  26649. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  26650. +
  26651. + hcd->has_tt = 1;
  26652. + ehci->sbrn = 0x20;
  26653. +
  26654. + ehci_reset(ehci);
  26655. +
  26656. + ret = ehci_init(hcd);
  26657. + if (ret)
  26658. + return ret;
  26659. +
  26660. + ehci_port_power(ehci, 0);
  26661. +
  26662. + return 0;
  26663. +}
  26664. +
  26665. +static int ehci_ar71xx_probe(const struct hc_driver *driver,
  26666. + struct usb_hcd **hcd_out,
  26667. + struct platform_device *pdev)
  26668. +{
  26669. + struct usb_hcd *hcd;
  26670. + struct resource *res;
  26671. + int irq;
  26672. + int ret;
  26673. +
  26674. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  26675. + if (!res) {
  26676. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  26677. + dev_name(&pdev->dev));
  26678. + return -ENODEV;
  26679. + }
  26680. + irq = res->start;
  26681. +
  26682. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  26683. + if (!res) {
  26684. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  26685. + dev_name(&pdev->dev));
  26686. + return -ENODEV;
  26687. + }
  26688. +
  26689. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  26690. + if (!hcd)
  26691. + return -ENOMEM;
  26692. +
  26693. + hcd->rsrc_start = res->start;
  26694. + hcd->rsrc_len = res->end - res->start + 1;
  26695. +
  26696. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  26697. + dev_dbg(&pdev->dev, "controller already in use\n");
  26698. + ret = -EBUSY;
  26699. + goto err_put_hcd;
  26700. + }
  26701. +
  26702. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  26703. + if (!hcd->regs) {
  26704. + dev_dbg(&pdev->dev, "error mapping memory\n");
  26705. + ret = -EFAULT;
  26706. + goto err_release_region;
  26707. + }
  26708. +
  26709. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  26710. + if (ret)
  26711. + goto err_iounmap;
  26712. +
  26713. + return 0;
  26714. +
  26715. +err_iounmap:
  26716. + iounmap(hcd->regs);
  26717. +
  26718. +err_release_region:
  26719. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  26720. +err_put_hcd:
  26721. + usb_put_hcd(hcd);
  26722. + return ret;
  26723. +}
  26724. +
  26725. +static void ehci_ar71xx_remove(struct usb_hcd *hcd,
  26726. + struct platform_device *pdev)
  26727. +{
  26728. + usb_remove_hcd(hcd);
  26729. + iounmap(hcd->regs);
  26730. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  26731. + usb_put_hcd(hcd);
  26732. +}
  26733. +
  26734. +static const struct hc_driver ehci_ar71xx_hc_driver = {
  26735. + .description = hcd_name,
  26736. + .product_desc = "Atheros AR71xx built-in EHCI controller",
  26737. + .hcd_priv_size = sizeof(struct ehci_hcd),
  26738. +
  26739. + .irq = ehci_irq,
  26740. + .flags = HCD_MEMORY | HCD_USB2,
  26741. +
  26742. + .reset = ehci_ar71xx_init,
  26743. + .start = ehci_run,
  26744. + .stop = ehci_stop,
  26745. + .shutdown = ehci_shutdown,
  26746. +
  26747. + .urb_enqueue = ehci_urb_enqueue,
  26748. + .urb_dequeue = ehci_urb_dequeue,
  26749. + .endpoint_disable = ehci_endpoint_disable,
  26750. + .endpoint_reset = ehci_endpoint_reset,
  26751. +
  26752. + .get_frame_number = ehci_get_frame,
  26753. +
  26754. + .hub_status_data = ehci_hub_status_data,
  26755. + .hub_control = ehci_hub_control,
  26756. +#ifdef CONFIG_PM
  26757. + .hub_suspend = ehci_hub_suspend,
  26758. + .hub_resume = ehci_hub_resume,
  26759. +#endif
  26760. + .relinquish_port = ehci_relinquish_port,
  26761. + .port_handed_over = ehci_port_handed_over,
  26762. +
  26763. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  26764. +};
  26765. +
  26766. +static const struct hc_driver ehci_ar91xx_hc_driver = {
  26767. + .description = hcd_name,
  26768. + .product_desc = "Atheros AR91xx built-in EHCI controller",
  26769. + .hcd_priv_size = sizeof(struct ehci_hcd),
  26770. + .irq = ehci_irq,
  26771. + .flags = HCD_MEMORY | HCD_USB2,
  26772. +
  26773. + .reset = ehci_ar91xx_init,
  26774. + .start = ehci_run,
  26775. + .stop = ehci_stop,
  26776. + .shutdown = ehci_shutdown,
  26777. +
  26778. + .urb_enqueue = ehci_urb_enqueue,
  26779. + .urb_dequeue = ehci_urb_dequeue,
  26780. + .endpoint_disable = ehci_endpoint_disable,
  26781. + .endpoint_reset = ehci_endpoint_reset,
  26782. +
  26783. + .get_frame_number = ehci_get_frame,
  26784. +
  26785. + .hub_status_data = ehci_hub_status_data,
  26786. + .hub_control = ehci_hub_control,
  26787. +#ifdef CONFIG_PM
  26788. + .hub_suspend = ehci_hub_suspend,
  26789. + .hub_resume = ehci_hub_resume,
  26790. +#endif
  26791. + .relinquish_port = ehci_relinquish_port,
  26792. + .port_handed_over = ehci_port_handed_over,
  26793. +
  26794. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  26795. +};
  26796. +
  26797. +static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
  26798. +{
  26799. + struct ar71xx_ehci_platform_data *pdata;
  26800. + struct usb_hcd *hcd = NULL;
  26801. + int ret;
  26802. +
  26803. + if (usb_disabled())
  26804. + return -ENODEV;
  26805. +
  26806. + pdata = pdev->dev.platform_data;
  26807. + if (!pdata) {
  26808. + dev_err(&pdev->dev, "no platform data specified for %s\n",
  26809. + dev_name(&pdev->dev));
  26810. + return -ENODEV;
  26811. + }
  26812. +
  26813. + if (pdata->is_ar91xx)
  26814. + ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
  26815. + else
  26816. + ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
  26817. +
  26818. + return ret;
  26819. +}
  26820. +
  26821. +static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
  26822. +{
  26823. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  26824. +
  26825. + ehci_ar71xx_remove(hcd, pdev);
  26826. + return 0;
  26827. +}
  26828. +
  26829. +MODULE_ALIAS("platform:ar71xx-ehci");
  26830. +
  26831. +static struct platform_driver ehci_ar71xx_driver = {
  26832. + .probe = ehci_ar71xx_driver_probe,
  26833. + .remove = ehci_ar71xx_driver_remove,
  26834. + .driver = {
  26835. + .name = "ar71xx-ehci",
  26836. + }
  26837. +};
  26838. diff -Nur linux-2.6.39.orig/drivers/usb/host/ehci-hcd.c linux-2.6.39/drivers/usb/host/ehci-hcd.c
  26839. --- linux-2.6.39.orig/drivers/usb/host/ehci-hcd.c 2011-05-19 06:06:34.000000000 +0200
  26840. +++ linux-2.6.39/drivers/usb/host/ehci-hcd.c 2011-08-22 16:21:42.807985568 +0200
  26841. @@ -1265,6 +1265,11 @@
  26842. #define PLATFORM_DRIVER tegra_ehci_driver
  26843. #endif
  26844. +#ifdef CONFIG_USB_EHCI_AR71XX
  26845. +#include "ehci-ar71xx.c"
  26846. +#define PLATFORM_DRIVER ehci_ar71xx_driver
  26847. +#endif
  26848. +
  26849. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  26850. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
  26851. !defined(XILINX_OF_PLATFORM_DRIVER)
  26852. diff -Nur linux-2.6.39.orig/drivers/usb/host/Kconfig linux-2.6.39/drivers/usb/host/Kconfig
  26853. --- linux-2.6.39.orig/drivers/usb/host/Kconfig 2011-05-19 06:06:34.000000000 +0200
  26854. +++ linux-2.6.39/drivers/usb/host/Kconfig 2011-08-22 16:21:42.767983341 +0200
  26855. @@ -129,6 +129,13 @@
  26856. config USB_FSL_MPH_DR_OF
  26857. tristate
  26858. +config USB_EHCI_AR71XX
  26859. + bool "USB EHCI support for AR71xx"
  26860. + depends on USB_EHCI_HCD && ATHEROS_AR71XX
  26861. + default y
  26862. + help
  26863. + Support for Atheros AR71xx built-in EHCI controller
  26864. +
  26865. config USB_EHCI_FSL
  26866. bool "Support for Freescale on-chip EHCI USB controller"
  26867. depends on USB_EHCI_HCD && FSL_SOC
  26868. @@ -287,6 +294,13 @@
  26869. Enables support for the on-chip OHCI controller on
  26870. OMAP3 and later chips.
  26871. +config USB_OHCI_AR71XX
  26872. + bool "USB OHCI support for Atheros AR71xx"
  26873. + depends on USB_OHCI_HCD && ATHEROS_AR71XX
  26874. + default y
  26875. + help
  26876. + Support for Atheros AR71xx built-in OHCI controller
  26877. +
  26878. config USB_OHCI_HCD_PPC_SOC
  26879. bool "OHCI support for on-chip PPC USB controller"
  26880. depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx)
  26881. diff -Nur linux-2.6.39.orig/drivers/usb/host/ohci-ar71xx.c linux-2.6.39/drivers/usb/host/ohci-ar71xx.c
  26882. --- linux-2.6.39.orig/drivers/usb/host/ohci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  26883. +++ linux-2.6.39/drivers/usb/host/ohci-ar71xx.c 2011-04-27 12:19:22.267661616 +0200
  26884. @@ -0,0 +1,165 @@
  26885. +/*
  26886. + * OHCI HCD (Host Controller Driver) for USB.
  26887. + *
  26888. + * Bus Glue for Atheros AR71xx built-in OHCI controller.
  26889. + *
  26890. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  26891. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  26892. + *
  26893. + * Parts of this file are based on Atheros' 2.6.15 BSP
  26894. + * Copyright (C) 2007 Atheros Communications, Inc.
  26895. + *
  26896. + * This program is free software; you can redistribute it and/or modify it
  26897. + * under the terms of the GNU General Public License version 2 as published
  26898. + * by the Free Software Foundation.
  26899. + */
  26900. +
  26901. +#include <linux/platform_device.h>
  26902. +#include <linux/delay.h>
  26903. +
  26904. +extern int usb_disabled(void);
  26905. +
  26906. +static int usb_hcd_ar71xx_probe(const struct hc_driver *driver,
  26907. + struct platform_device *pdev)
  26908. +{
  26909. + struct usb_hcd *hcd;
  26910. + struct resource *res;
  26911. + int irq;
  26912. + int ret;
  26913. +
  26914. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  26915. + if (!res) {
  26916. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  26917. + dev_name(&pdev->dev));
  26918. + return -ENODEV;
  26919. + }
  26920. + irq = res->start;
  26921. +
  26922. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  26923. + if (!hcd)
  26924. + return -ENOMEM;
  26925. +
  26926. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  26927. + if (!res) {
  26928. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  26929. + dev_name(&pdev->dev));
  26930. + ret = -ENODEV;
  26931. + goto err_put_hcd;
  26932. + }
  26933. + hcd->rsrc_start = res->start;
  26934. + hcd->rsrc_len = res->end - res->start + 1;
  26935. +
  26936. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  26937. + dev_dbg(&pdev->dev, "controller already in use\n");
  26938. + ret = -EBUSY;
  26939. + goto err_put_hcd;
  26940. + }
  26941. +
  26942. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  26943. + if (!hcd->regs) {
  26944. + dev_dbg(&pdev->dev, "error mapping memory\n");
  26945. + ret = -EFAULT;
  26946. + goto err_release_region;
  26947. + }
  26948. +
  26949. + ohci_hcd_init(hcd_to_ohci(hcd));
  26950. +
  26951. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  26952. + if (ret)
  26953. + goto err_stop_hcd;
  26954. +
  26955. + return 0;
  26956. +
  26957. +err_stop_hcd:
  26958. + iounmap(hcd->regs);
  26959. +err_release_region:
  26960. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  26961. +err_put_hcd:
  26962. + usb_put_hcd(hcd);
  26963. + return ret;
  26964. +}
  26965. +
  26966. +void usb_hcd_ar71xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  26967. +{
  26968. + usb_remove_hcd(hcd);
  26969. + iounmap(hcd->regs);
  26970. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  26971. + usb_put_hcd(hcd);
  26972. +}
  26973. +
  26974. +static int __devinit ohci_ar71xx_start(struct usb_hcd *hcd)
  26975. +{
  26976. + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  26977. + int ret;
  26978. +
  26979. + ret = ohci_init(ohci);
  26980. + if (ret < 0)
  26981. + return ret;
  26982. +
  26983. + ret = ohci_run(ohci);
  26984. + if (ret < 0)
  26985. + goto err;
  26986. +
  26987. + return 0;
  26988. +
  26989. +err:
  26990. + ohci_stop(hcd);
  26991. + return ret;
  26992. +}
  26993. +
  26994. +static const struct hc_driver ohci_ar71xx_hc_driver = {
  26995. + .description = hcd_name,
  26996. + .product_desc = "Atheros AR71xx built-in OHCI controller",
  26997. + .hcd_priv_size = sizeof(struct ohci_hcd),
  26998. +
  26999. + .irq = ohci_irq,
  27000. + .flags = HCD_USB11 | HCD_MEMORY,
  27001. +
  27002. + .start = ohci_ar71xx_start,
  27003. + .stop = ohci_stop,
  27004. + .shutdown = ohci_shutdown,
  27005. +
  27006. + .urb_enqueue = ohci_urb_enqueue,
  27007. + .urb_dequeue = ohci_urb_dequeue,
  27008. + .endpoint_disable = ohci_endpoint_disable,
  27009. +
  27010. + /*
  27011. + * scheduling support
  27012. + */
  27013. + .get_frame_number = ohci_get_frame,
  27014. +
  27015. + /*
  27016. + * root hub support
  27017. + */
  27018. + .hub_status_data = ohci_hub_status_data,
  27019. + .hub_control = ohci_hub_control,
  27020. + .start_port_reset = ohci_start_port_reset,
  27021. +};
  27022. +
  27023. +static int ohci_hcd_ar71xx_drv_probe(struct platform_device *pdev)
  27024. +{
  27025. + if (usb_disabled())
  27026. + return -ENODEV;
  27027. +
  27028. + return usb_hcd_ar71xx_probe(&ohci_ar71xx_hc_driver, pdev);
  27029. +}
  27030. +
  27031. +static int ohci_hcd_ar71xx_drv_remove(struct platform_device *pdev)
  27032. +{
  27033. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  27034. +
  27035. + usb_hcd_ar71xx_remove(hcd, pdev);
  27036. + return 0;
  27037. +}
  27038. +
  27039. +MODULE_ALIAS("platform:ar71xx-ohci");
  27040. +
  27041. +static struct platform_driver ohci_hcd_ar71xx_driver = {
  27042. + .probe = ohci_hcd_ar71xx_drv_probe,
  27043. + .remove = ohci_hcd_ar71xx_drv_remove,
  27044. + .shutdown = usb_hcd_platform_shutdown,
  27045. + .driver = {
  27046. + .name = "ar71xx-ohci",
  27047. + .owner = THIS_MODULE,
  27048. + },
  27049. +};
  27050. diff -Nur linux-2.6.39.orig/drivers/usb/host/ohci-hcd.c linux-2.6.39/drivers/usb/host/ohci-hcd.c
  27051. --- linux-2.6.39.orig/drivers/usb/host/ohci-hcd.c 2011-05-19 06:06:34.000000000 +0200
  27052. +++ linux-2.6.39/drivers/usb/host/ohci-hcd.c 2011-08-22 16:21:42.847983209 +0200
  27053. @@ -1105,6 +1105,11 @@
  27054. #define PLATFORM_DRIVER ohci_hcd_cns3xxx_driver
  27055. #endif
  27056. +#ifdef CONFIG_USB_OHCI_AR71XX
  27057. +#include "ohci-ar71xx.c"
  27058. +#define PLATFORM_DRIVER ohci_hcd_ar71xx_driver
  27059. +#endif
  27060. +
  27061. #if !defined(PCI_DRIVER) && \
  27062. !defined(PLATFORM_DRIVER) && \
  27063. !defined(OMAP1_PLATFORM_DRIVER) && \
  27064. diff -Nur linux-2.6.39.orig/drivers/watchdog/ar71xx_wdt.c linux-2.6.39/drivers/watchdog/ar71xx_wdt.c
  27065. --- linux-2.6.39.orig/drivers/watchdog/ar71xx_wdt.c 1970-01-01 01:00:00.000000000 +0100
  27066. +++ linux-2.6.39/drivers/watchdog/ar71xx_wdt.c 2011-08-06 09:32:37.118022037 +0200
  27067. @@ -0,0 +1,299 @@
  27068. +/*
  27069. + * Driver for the Atheros AR71xx SoC's built-in hardware watchdog timer.
  27070. + *
  27071. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  27072. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  27073. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  27074. + *
  27075. + * Parts of this file are based on Atheros 2.6.31 BSP
  27076. + *
  27077. + * This driver was based on: drivers/watchdog/ixp4xx_wdt.c
  27078. + * Author: Deepak Saxena <dsaxena@plexity.net>
  27079. + * Copyright 2004 (c) MontaVista, Software, Inc.
  27080. + *
  27081. + * which again was based on sa1100 driver,
  27082. + * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
  27083. + *
  27084. + * This program is free software; you can redistribute it and/or modify it
  27085. + * under the terms of the GNU General Public License version 2 as published
  27086. + * by the Free Software Foundation.
  27087. + *
  27088. + */
  27089. +
  27090. +#include <linux/bitops.h>
  27091. +#include <linux/errno.h>
  27092. +#include <linux/fs.h>
  27093. +#include <linux/init.h>
  27094. +#include <linux/kernel.h>
  27095. +#include <linux/miscdevice.h>
  27096. +#include <linux/module.h>
  27097. +#include <linux/moduleparam.h>
  27098. +#include <linux/platform_device.h>
  27099. +#include <linux/types.h>
  27100. +#include <linux/watchdog.h>
  27101. +#include <linux/delay.h>
  27102. +
  27103. +#include <asm/mach-ar71xx/ar71xx.h>
  27104. +
  27105. +#define DRV_NAME "ar71xx-wdt"
  27106. +#define DRV_DESC "Atheros AR71xx hardware watchdog driver"
  27107. +#define DRV_VERSION "0.1.0"
  27108. +
  27109. +#define WDT_TIMEOUT 15 /* seconds */
  27110. +
  27111. +static int nowayout = WATCHDOG_NOWAYOUT;
  27112. +
  27113. +#ifdef CONFIG_WATCHDOG_NOWAYOUT
  27114. +module_param(nowayout, int, 0);
  27115. +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
  27116. + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  27117. +#endif
  27118. +
  27119. +static unsigned long wdt_flags;
  27120. +
  27121. +#define WDT_FLAGS_BUSY 0
  27122. +#define WDT_FLAGS_EXPECT_CLOSE 1
  27123. +
  27124. +static int wdt_timeout = WDT_TIMEOUT;
  27125. +static int boot_status;
  27126. +static int max_timeout;
  27127. +static u32 wdt_clk_freq;
  27128. +
  27129. +static inline void ar71xx_wdt_keepalive(void)
  27130. +{
  27131. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG, wdt_clk_freq * wdt_timeout);
  27132. +}
  27133. +
  27134. +static inline void ar71xx_wdt_enable(void)
  27135. +{
  27136. + printk(KERN_DEBUG DRV_NAME ": enabling watchdog timer\n");
  27137. + ar71xx_wdt_keepalive();
  27138. + udelay(2);
  27139. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_FCR);
  27140. +}
  27141. +
  27142. +static inline void ar71xx_wdt_disable(void)
  27143. +{
  27144. + printk(KERN_DEBUG DRV_NAME ": disabling watchdog timer\n");
  27145. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_NONE);
  27146. +}
  27147. +
  27148. +static int ar71xx_wdt_set_timeout(int val)
  27149. +{
  27150. + if (val < 1 || val > max_timeout)
  27151. + return -EINVAL;
  27152. +
  27153. + wdt_timeout = val;
  27154. + ar71xx_wdt_keepalive();
  27155. +
  27156. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs\n", wdt_timeout);
  27157. +
  27158. + return 0;
  27159. +}
  27160. +
  27161. +static int ar71xx_wdt_open(struct inode *inode, struct file *file)
  27162. +{
  27163. + if (test_and_set_bit(WDT_FLAGS_BUSY, &wdt_flags))
  27164. + return -EBUSY;
  27165. +
  27166. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  27167. +
  27168. + ar71xx_wdt_enable();
  27169. +
  27170. + return nonseekable_open(inode, file);
  27171. +}
  27172. +
  27173. +static int ar71xx_wdt_release(struct inode *inode, struct file *file)
  27174. +{
  27175. + if (test_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags)) {
  27176. + ar71xx_wdt_disable();
  27177. + } else {
  27178. + printk(KERN_CRIT DRV_NAME ": device closed unexpectedly, "
  27179. + "watchdog timer will not stop!\n");
  27180. + }
  27181. +
  27182. + clear_bit(WDT_FLAGS_BUSY, &wdt_flags);
  27183. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  27184. +
  27185. + return 0;
  27186. +}
  27187. +
  27188. +static ssize_t ar71xx_wdt_write(struct file *file, const char *data,
  27189. + size_t len, loff_t *ppos)
  27190. +{
  27191. + if (len) {
  27192. + if (!nowayout) {
  27193. + size_t i;
  27194. +
  27195. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  27196. +
  27197. + for (i = 0; i != len; i++) {
  27198. + char c;
  27199. +
  27200. + if (get_user(c, data + i))
  27201. + return -EFAULT;
  27202. +
  27203. + if (c == 'V')
  27204. + set_bit(WDT_FLAGS_EXPECT_CLOSE,
  27205. + &wdt_flags);
  27206. + }
  27207. + }
  27208. +
  27209. + ar71xx_wdt_keepalive();
  27210. + }
  27211. +
  27212. + return len;
  27213. +}
  27214. +
  27215. +static struct watchdog_info ar71xx_wdt_info = {
  27216. + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
  27217. + WDIOF_MAGICCLOSE | WDIOF_CARDRESET,
  27218. + .firmware_version = 0,
  27219. + .identity = "AR71XX watchdog",
  27220. +};
  27221. +
  27222. +static long ar71xx_wdt_ioctl(struct file *file,
  27223. + unsigned int cmd, unsigned long arg)
  27224. +{
  27225. + int t;
  27226. + int ret;
  27227. +
  27228. + switch (cmd) {
  27229. + case WDIOC_GETSUPPORT:
  27230. + ret = copy_to_user((struct watchdog_info *)arg,
  27231. + &ar71xx_wdt_info,
  27232. + sizeof(ar71xx_wdt_info)) ? -EFAULT : 0;
  27233. + break;
  27234. +
  27235. + case WDIOC_GETSTATUS:
  27236. + ret = put_user(0, (int *)arg) ? -EFAULT : 0;
  27237. + break;
  27238. +
  27239. + case WDIOC_GETBOOTSTATUS:
  27240. + ret = put_user(boot_status, (int *)arg) ? -EFAULT : 0;
  27241. + break;
  27242. +
  27243. + case WDIOC_KEEPALIVE:
  27244. + ar71xx_wdt_keepalive();
  27245. + ret = 0;
  27246. + break;
  27247. +
  27248. + case WDIOC_SETTIMEOUT:
  27249. + ret = get_user(t, (int *)arg) ? -EFAULT : 0;
  27250. + if (ret)
  27251. + break;
  27252. +
  27253. + ret = ar71xx_wdt_set_timeout(t);
  27254. + if (ret)
  27255. + break;
  27256. +
  27257. + /* fallthrough */
  27258. + case WDIOC_GETTIMEOUT:
  27259. + ret = put_user(wdt_timeout, (int *)arg) ? -EFAULT : 0;
  27260. + break;
  27261. +
  27262. + default:
  27263. + ret = -ENOTTY;
  27264. + break;
  27265. + }
  27266. +
  27267. + return ret;
  27268. +}
  27269. +
  27270. +static const struct file_operations ar71xx_wdt_fops = {
  27271. + .owner = THIS_MODULE,
  27272. + .write = ar71xx_wdt_write,
  27273. + .unlocked_ioctl = ar71xx_wdt_ioctl,
  27274. + .open = ar71xx_wdt_open,
  27275. + .release = ar71xx_wdt_release,
  27276. +};
  27277. +
  27278. +static struct miscdevice ar71xx_wdt_miscdev = {
  27279. + .minor = WATCHDOG_MINOR,
  27280. + .name = "watchdog",
  27281. + .fops = &ar71xx_wdt_fops,
  27282. +};
  27283. +
  27284. +static int __devinit ar71xx_wdt_probe(struct platform_device *pdev)
  27285. +{
  27286. + int ret;
  27287. +
  27288. + switch (ar71xx_soc) {
  27289. + case AR71XX_SOC_AR7130:
  27290. + case AR71XX_SOC_AR7141:
  27291. + case AR71XX_SOC_AR7161:
  27292. + case AR71XX_SOC_AR7240:
  27293. + case AR71XX_SOC_AR7241:
  27294. + case AR71XX_SOC_AR7242:
  27295. + case AR71XX_SOC_AR9130:
  27296. + case AR71XX_SOC_AR9132:
  27297. + wdt_clk_freq = ar71xx_ahb_freq;
  27298. + break;
  27299. +
  27300. + case AR71XX_SOC_AR9330:
  27301. + case AR71XX_SOC_AR9331:
  27302. + case AR71XX_SOC_AR9341:
  27303. + case AR71XX_SOC_AR9342:
  27304. + case AR71XX_SOC_AR9344:
  27305. + wdt_clk_freq = ar71xx_ref_freq;
  27306. + break;
  27307. +
  27308. + default:
  27309. + BUG();
  27310. + }
  27311. +
  27312. + max_timeout = (0xfffffffful / wdt_clk_freq);
  27313. + wdt_timeout = (max_timeout < WDT_TIMEOUT) ? max_timeout : WDT_TIMEOUT;
  27314. +
  27315. + if (ar71xx_reset_rr(AR71XX_RESET_REG_WDOG_CTRL) & WDOG_CTRL_LAST_RESET)
  27316. + boot_status = WDIOF_CARDRESET;
  27317. +
  27318. + ret = misc_register(&ar71xx_wdt_miscdev);
  27319. + if (ret)
  27320. + goto err_out;
  27321. +
  27322. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  27323. +
  27324. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs (max=%d)\n",
  27325. + wdt_timeout, max_timeout);
  27326. +
  27327. + return 0;
  27328. +
  27329. +err_out:
  27330. + return ret;
  27331. +}
  27332. +
  27333. +static int __devexit ar71xx_wdt_remove(struct platform_device *pdev)
  27334. +{
  27335. + misc_deregister(&ar71xx_wdt_miscdev);
  27336. + return 0;
  27337. +}
  27338. +
  27339. +static struct platform_driver ar71xx_wdt_driver = {
  27340. + .probe = ar71xx_wdt_probe,
  27341. + .remove = __devexit_p(ar71xx_wdt_remove),
  27342. + .driver = {
  27343. + .name = DRV_NAME,
  27344. + .owner = THIS_MODULE,
  27345. + },
  27346. +};
  27347. +
  27348. +static int __init ar71xx_wdt_init(void)
  27349. +{
  27350. + return platform_driver_register(&ar71xx_wdt_driver);
  27351. +}
  27352. +module_init(ar71xx_wdt_init);
  27353. +
  27354. +static void __exit ar71xx_wdt_exit(void)
  27355. +{
  27356. + platform_driver_unregister(&ar71xx_wdt_driver);
  27357. +}
  27358. +module_exit(ar71xx_wdt_exit);
  27359. +
  27360. +MODULE_DESCRIPTION(DRV_DESC);
  27361. +MODULE_VERSION(DRV_VERSION);
  27362. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
  27363. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
  27364. +MODULE_LICENSE("GPL v2");
  27365. +MODULE_ALIAS("platform:" DRV_NAME);
  27366. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  27367. diff -Nur linux-2.6.39.orig/drivers/watchdog/Kconfig linux-2.6.39/drivers/watchdog/Kconfig
  27368. --- linux-2.6.39.orig/drivers/watchdog/Kconfig 2011-05-19 06:06:34.000000000 +0200
  27369. +++ linux-2.6.39/drivers/watchdog/Kconfig 2011-08-22 16:22:00.627980889 +0200
  27370. @@ -990,6 +990,13 @@
  27371. To compile this driver as a loadable module, choose M here.
  27372. The module will be called bcm63xx_wdt.
  27373. +config AR71XX_WDT
  27374. + tristate "Atheros AR71xx Watchdog Timer"
  27375. + depends on ATHEROS_AR71XX
  27376. + help
  27377. + Hardware driver for the built-in watchdog timer on the Atheros
  27378. + AR71xx SoCs.
  27379. +
  27380. # PARISC Architecture
  27381. # POWERPC Architecture
  27382. diff -Nur linux-2.6.39.orig/drivers/watchdog/Makefile linux-2.6.39/drivers/watchdog/Makefile
  27383. --- linux-2.6.39.orig/drivers/watchdog/Makefile 2011-05-19 06:06:34.000000000 +0200
  27384. +++ linux-2.6.39/drivers/watchdog/Makefile 2011-08-22 16:22:00.647986892 +0200
  27385. @@ -119,6 +119,7 @@
  27386. obj-$(CONFIG_WDT_MTX1) += mtx-1_wdt.o
  27387. obj-$(CONFIG_PNX833X_WDT) += pnx833x_wdt.o
  27388. obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
  27389. +obj-$(CONFIG_AR71XX_WDT) += ar71xx_wdt.o
  27390. obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
  27391. obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
  27392. obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
  27393. diff -Nur linux-2.6.39.orig/include/linux/ath9k_platform.h linux-2.6.39/include/linux/ath9k_platform.h
  27394. --- linux-2.6.39.orig/include/linux/ath9k_platform.h 2011-05-19 06:06:34.000000000 +0200
  27395. +++ linux-2.6.39/include/linux/ath9k_platform.h 2011-08-06 09:32:36.638021723 +0200
  27396. @@ -23,6 +23,15 @@
  27397. struct ath9k_platform_data {
  27398. u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
  27399. + u8 *macaddr;
  27400. +
  27401. + int led_pin;
  27402. + u32 gpio_mask;
  27403. + u32 gpio_val;
  27404. +
  27405. + bool is_clk_25mhz;
  27406. + int (*get_mac_revision)(void);
  27407. + int (*external_reset)(void);
  27408. };
  27409. #endif /* _LINUX_ATH9K_PLATFORM_H */
  27410. diff -Nur linux-2.6.39.orig/include/linux/ip.h linux-2.6.39/include/linux/ip.h
  27411. --- linux-2.6.39.orig/include/linux/ip.h 2011-05-19 06:06:34.000000000 +0200
  27412. +++ linux-2.6.39/include/linux/ip.h 2011-08-24 05:53:21.239229027 +0200
  27413. @@ -102,7 +102,7 @@
  27414. __be32 saddr;
  27415. __be32 daddr;
  27416. /*The options start here. */
  27417. -};
  27418. +} __packed;
  27419. #ifdef __KERNEL__
  27420. #include <linux/skbuff.h>
  27421. diff -Nur linux-2.6.39.orig/include/linux/ipv6.h linux-2.6.39/include/linux/ipv6.h
  27422. --- linux-2.6.39.orig/include/linux/ipv6.h 2011-05-19 06:06:34.000000000 +0200
  27423. +++ linux-2.6.39/include/linux/ipv6.h 2011-08-24 05:53:21.289229059 +0200
  27424. @@ -126,7 +126,7 @@
  27425. struct in6_addr saddr;
  27426. struct in6_addr daddr;
  27427. -};
  27428. +} __packed;
  27429. #ifdef __KERNEL__
  27430. /*
  27431. diff -Nur linux-2.6.39.orig/include/linux/myloader.h linux-2.6.39/include/linux/myloader.h
  27432. --- linux-2.6.39.orig/include/linux/myloader.h 1970-01-01 01:00:00.000000000 +0100
  27433. +++ linux-2.6.39/include/linux/myloader.h 2011-08-24 03:12:08.307985040 +0200
  27434. @@ -0,0 +1,120 @@
  27435. +/*
  27436. + * Compex's MyLoader specific definitions
  27437. + *
  27438. + * Copyright (C) 2006-2008 Gabor Juhos <juhosg@openwrt.org>
  27439. + *
  27440. + * This program is free software; you can redistribute it and/or modify it
  27441. + * under the terms of the GNU General Public License version 2 as published
  27442. + * by the Free Software Foundation.
  27443. + *
  27444. + */
  27445. +
  27446. +#ifndef _MYLOADER_H_
  27447. +#define _MYLOADER_H_
  27448. +
  27449. +/* Myloader specific magic numbers */
  27450. +#define MYLO_MAGIC_SYS_PARAMS 0x20021107
  27451. +#define MYLO_MAGIC_PARTITIONS 0x20021103
  27452. +#define MYLO_MAGIC_BOARD_PARAMS 0x20021103
  27453. +
  27454. +/* Vendor ID's (seems to be same as the PCI vendor ID's) */
  27455. +#define VENID_COMPEX 0x11F6
  27456. +
  27457. +/* Devices based on the ADM5120 */
  27458. +#define DEVID_COMPEX_NP27G 0x0078
  27459. +#define DEVID_COMPEX_NP28G 0x044C
  27460. +#define DEVID_COMPEX_NP28GHS 0x044E
  27461. +#define DEVID_COMPEX_WP54Gv1C 0x0514
  27462. +#define DEVID_COMPEX_WP54G 0x0515
  27463. +#define DEVID_COMPEX_WP54AG 0x0546
  27464. +#define DEVID_COMPEX_WPP54AG 0x0550
  27465. +#define DEVID_COMPEX_WPP54G 0x0555
  27466. +
  27467. +/* Devices based on the Atheros AR2317 */
  27468. +#define DEVID_COMPEX_NP25G 0x05E6
  27469. +#define DEVID_COMPEX_WPE53G 0x05DC
  27470. +
  27471. +/* Devices based on the Atheros AR71xx */
  27472. +#define DEVID_COMPEX_WP543 0x0640
  27473. +
  27474. +/* Devices based on the IXP422 */
  27475. +#define DEVID_COMPEX_WP18 0x047E
  27476. +#define DEVID_COMPEX_NP18A 0x0489
  27477. +
  27478. +/* Other devices */
  27479. +#define DEVID_COMPEX_NP26G8M 0x03E8
  27480. +#define DEVID_COMPEX_NP26G16M 0x03E9
  27481. +
  27482. +struct mylo_partition {
  27483. + uint16_t flags; /* partition flags */
  27484. + uint16_t type; /* type of the partition */
  27485. + uint32_t addr; /* relative address of the partition from the
  27486. + flash start */
  27487. + uint32_t size; /* size of the partition in bytes */
  27488. + uint32_t param; /* if this is the active partition, the
  27489. + MyLoader load code to this address */
  27490. +};
  27491. +
  27492. +#define PARTITION_FLAG_ACTIVE 0x8000 /* this is the active partition,
  27493. + * MyLoader loads firmware from here */
  27494. +#define PARTITION_FLAG_ISRAM 0x2000 /* FIXME: this is a RAM partition? */
  27495. +#define PARTIIION_FLAG_RAMLOAD 0x1000 /* FIXME: load this partition into the RAM? */
  27496. +#define PARTITION_FLAG_PRELOAD 0x0800 /* the partition data preloaded to RAM
  27497. + * before decompression */
  27498. +#define PARTITION_FLAG_LZMA 0x0100 /* partition data compressed by LZMA */
  27499. +#define PARTITION_FLAG_HAVEHDR 0x0002 /* the partition data have a header */
  27500. +
  27501. +#define PARTITION_TYPE_FREE 0
  27502. +#define PARTITION_TYPE_USED 1
  27503. +
  27504. +#define MYLO_MAX_PARTITIONS 8 /* maximum number of partitions in the
  27505. + partition table */
  27506. +
  27507. +struct mylo_partition_table {
  27508. + uint32_t magic; /* must be MYLO_MAGIC_PARTITIONS */
  27509. + uint32_t res0; /* unknown/unused */
  27510. + uint32_t res1; /* unknown/unused */
  27511. + uint32_t res2; /* unknown/unused */
  27512. + struct mylo_partition partitions[MYLO_MAX_PARTITIONS];
  27513. +};
  27514. +
  27515. +struct mylo_partition_header {
  27516. + uint32_t len; /* length of the partition data */
  27517. + uint32_t crc; /* CRC value of the partition data */
  27518. +};
  27519. +
  27520. +struct mylo_system_params {
  27521. + uint32_t magic; /* must be MYLO_MAGIC_SYS_PARAMS */
  27522. + uint32_t res0;
  27523. + uint32_t res1;
  27524. + uint32_t mylo_ver;
  27525. + uint16_t vid; /* Vendor ID */
  27526. + uint16_t did; /* Device ID */
  27527. + uint16_t svid; /* Sub Vendor ID */
  27528. + uint16_t sdid; /* Sub Device ID */
  27529. + uint32_t rev; /* device revision */
  27530. + uint32_t fwhi;
  27531. + uint32_t fwlo;
  27532. + uint32_t tftp_addr;
  27533. + uint32_t prog_start;
  27534. + uint32_t flash_size; /* size of boot FLASH in bytes */
  27535. + uint32_t dram_size; /* size of onboard RAM in bytes */
  27536. +};
  27537. +
  27538. +struct mylo_eth_addr {
  27539. + uint8_t mac[6];
  27540. + uint8_t csum[2];
  27541. +};
  27542. +
  27543. +#define MYLO_ETHADDR_COUNT 8 /* maximum number of ethernet address
  27544. + in the board parameters */
  27545. +
  27546. +struct mylo_board_params {
  27547. + uint32_t magic; /* must be MYLO_MAGIC_BOARD_PARAMS */
  27548. + uint32_t res0;
  27549. + uint32_t res1;
  27550. + uint32_t res2;
  27551. + struct mylo_eth_addr addr[MYLO_ETHADDR_COUNT];
  27552. +};
  27553. +
  27554. +#endif /* _MYLOADER_H_*/
  27555. diff -Nur linux-2.6.39.orig/include/linux/netdevice.h linux-2.6.39/include/linux/netdevice.h
  27556. --- linux-2.6.39.orig/include/linux/netdevice.h 2011-05-19 06:06:34.000000000 +0200
  27557. +++ linux-2.6.39/include/linux/netdevice.h 2011-08-22 22:00:06.937981400 +0200
  27558. @@ -1182,6 +1182,7 @@
  27559. void *ax25_ptr; /* AX.25 specific data */
  27560. struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
  27561. assign before registering */
  27562. + void *phy_ptr; /* PHY device specific data */
  27563. /*
  27564. * Cache lines mostly used on receive path (including eth_type_trans())
  27565. diff -Nur linux-2.6.39.orig/include/linux/nxp_74hc153.h linux-2.6.39/include/linux/nxp_74hc153.h
  27566. --- linux-2.6.39.orig/include/linux/nxp_74hc153.h 1970-01-01 01:00:00.000000000 +0100
  27567. +++ linux-2.6.39/include/linux/nxp_74hc153.h 2011-04-27 12:19:21.817661653 +0200
  27568. @@ -0,0 +1,24 @@
  27569. +/*
  27570. + * NXP 74HC153 - Dual 4-input multiplexer defines
  27571. + *
  27572. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  27573. + *
  27574. + * This program is free software; you can redistribute it and/or modify
  27575. + * it under the terms of the GNU General Public License version 2 as
  27576. + * published by the Free Software Foundation.
  27577. + */
  27578. +
  27579. +#ifndef _NXP_74HC153_H
  27580. +#define _NXP_74HC153_H
  27581. +
  27582. +#define NXP_74HC153_DRIVER_NAME "nxp-74hc153"
  27583. +
  27584. +struct nxp_74hc153_platform_data {
  27585. + unsigned gpio_base;
  27586. + unsigned gpio_pin_s0;
  27587. + unsigned gpio_pin_s1;
  27588. + unsigned gpio_pin_1y;
  27589. + unsigned gpio_pin_2y;
  27590. +};
  27591. +
  27592. +#endif /* _NXP_74HC153_H */
  27593. diff -Nur linux-2.6.39.orig/include/linux/phy.h linux-2.6.39/include/linux/phy.h
  27594. --- linux-2.6.39.orig/include/linux/phy.h 2011-05-19 06:06:34.000000000 +0200
  27595. +++ linux-2.6.39/include/linux/phy.h 2011-08-22 22:00:06.867980866 +0200
  27596. @@ -332,6 +332,20 @@
  27597. void (*adjust_link)(struct net_device *dev);
  27598. void (*adjust_state)(struct net_device *dev);
  27599. +
  27600. + /*
  27601. + * By default these point to the original functions
  27602. + * with the same name. adding them to the phy_device
  27603. + * allows the phy driver to override them for packet
  27604. + * mangling if the ethernet driver supports it
  27605. + * This is required to support some really horrible
  27606. + * switches such as the Marvell 88E6060
  27607. + */
  27608. + int (*netif_receive_skb)(struct sk_buff *skb);
  27609. + int (*netif_rx)(struct sk_buff *skb);
  27610. +
  27611. + /* alignment offset for packets */
  27612. + int pkt_align;
  27613. };
  27614. #define to_phy_device(d) container_of(d, struct phy_device, dev)
  27615. @@ -508,6 +522,7 @@
  27616. void phy_stop_machine(struct phy_device *phydev);
  27617. int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  27618. int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  27619. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
  27620. int phy_mii_ioctl(struct phy_device *phydev,
  27621. struct ifreq *ifr, int cmd);
  27622. int phy_start_interrupts(struct phy_device *phydev);
  27623. diff -Nur linux-2.6.39.orig/include/linux/spi/spi.h linux-2.6.39/include/linux/spi/spi.h
  27624. --- linux-2.6.39.orig/include/linux/spi/spi.h 2011-05-19 06:06:34.000000000 +0200
  27625. +++ linux-2.6.39/include/linux/spi/spi.h 2011-08-23 15:10:37.559229523 +0200
  27626. @@ -441,6 +441,8 @@
  27627. dma_addr_t rx_dma;
  27628. unsigned cs_change:1;
  27629. + unsigned verify:1;
  27630. + unsigned fast_write:1;
  27631. u8 bits_per_word;
  27632. u16 delay_usecs;
  27633. u32 speed_hz;
  27634. @@ -482,6 +484,7 @@
  27635. struct spi_device *spi;
  27636. unsigned is_dma_mapped:1;
  27637. + unsigned fast_read:1;
  27638. /* REVISIT: we might want a flag affecting the behavior of the
  27639. * last transfer ... allowing things like "read 16 bit length L"
  27640. diff -Nur linux-2.6.39.orig/include/linux/spi/vsc7385.h linux-2.6.39/include/linux/spi/vsc7385.h
  27641. --- linux-2.6.39.orig/include/linux/spi/vsc7385.h 1970-01-01 01:00:00.000000000 +0100
  27642. +++ linux-2.6.39/include/linux/spi/vsc7385.h 2011-04-27 12:19:21.817661653 +0200
  27643. @@ -0,0 +1,19 @@
  27644. +/*
  27645. + * Platform data definition for the Vitesse VSC7385 ethernet switch driver
  27646. + *
  27647. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  27648. + *
  27649. + * This program is free software; you can redistribute it and/or modify it
  27650. + * under the terms of the GNU General Public License version 2 as published
  27651. + * by the Free Software Foundation.
  27652. + */
  27653. +
  27654. +struct vsc7385_platform_data {
  27655. + void (*reset)(void);
  27656. + char *ucode_name;
  27657. + struct {
  27658. + u32 tx_ipg:5;
  27659. + u32 bit2:1;
  27660. + u32 clk_sel:3;
  27661. + } mac_cfg;
  27662. +};
  27663. diff -Nur linux-2.6.39.orig/include/linux/switch.h linux-2.6.39/include/linux/switch.h
  27664. --- linux-2.6.39.orig/include/linux/switch.h 1970-01-01 01:00:00.000000000 +0100
  27665. +++ linux-2.6.39/include/linux/switch.h 2011-08-22 22:09:59.799231408 +0200
  27666. @@ -0,0 +1,204 @@
  27667. +/*
  27668. + * switch.h: Switch configuration API
  27669. + *
  27670. + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  27671. + *
  27672. + * This program is free software; you can redistribute it and/or
  27673. + * modify it under the terms of the GNU General Public License
  27674. + * as published by the Free Software Foundation; either version 2
  27675. + * of the License, or (at your option) any later version.
  27676. + *
  27677. + * This program is distributed in the hope that it will be useful,
  27678. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27679. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27680. + * GNU General Public License for more details.
  27681. + */
  27682. +
  27683. +#ifndef __LINUX_SWITCH_H
  27684. +#define __LINUX_SWITCH_H
  27685. +
  27686. +#include <linux/types.h>
  27687. +#include <linux/netdevice.h>
  27688. +#include <linux/netlink.h>
  27689. +#include <linux/genetlink.h>
  27690. +#ifndef __KERNEL__
  27691. +#include <netlink/netlink.h>
  27692. +#include <netlink/genl/genl.h>
  27693. +#include <netlink/genl/ctrl.h>
  27694. +#else
  27695. +#include <net/genetlink.h>
  27696. +#endif
  27697. +
  27698. +/* main attributes */
  27699. +enum {
  27700. + SWITCH_ATTR_UNSPEC,
  27701. + /* global */
  27702. + SWITCH_ATTR_TYPE,
  27703. + /* device */
  27704. + SWITCH_ATTR_ID,
  27705. + SWITCH_ATTR_DEV_NAME,
  27706. + SWITCH_ATTR_ALIAS,
  27707. + SWITCH_ATTR_NAME,
  27708. + SWITCH_ATTR_VLANS,
  27709. + SWITCH_ATTR_PORTS,
  27710. + SWITCH_ATTR_CPU_PORT,
  27711. + /* attributes */
  27712. + SWITCH_ATTR_OP_ID,
  27713. + SWITCH_ATTR_OP_TYPE,
  27714. + SWITCH_ATTR_OP_NAME,
  27715. + SWITCH_ATTR_OP_PORT,
  27716. + SWITCH_ATTR_OP_VLAN,
  27717. + SWITCH_ATTR_OP_VALUE_INT,
  27718. + SWITCH_ATTR_OP_VALUE_STR,
  27719. + SWITCH_ATTR_OP_VALUE_PORTS,
  27720. + SWITCH_ATTR_OP_DESCRIPTION,
  27721. + /* port lists */
  27722. + SWITCH_ATTR_PORT,
  27723. + SWITCH_ATTR_MAX
  27724. +};
  27725. +
  27726. +/* commands */
  27727. +enum {
  27728. + SWITCH_CMD_UNSPEC,
  27729. + SWITCH_CMD_GET_SWITCH,
  27730. + SWITCH_CMD_NEW_ATTR,
  27731. + SWITCH_CMD_LIST_GLOBAL,
  27732. + SWITCH_CMD_GET_GLOBAL,
  27733. + SWITCH_CMD_SET_GLOBAL,
  27734. + SWITCH_CMD_LIST_PORT,
  27735. + SWITCH_CMD_GET_PORT,
  27736. + SWITCH_CMD_SET_PORT,
  27737. + SWITCH_CMD_LIST_VLAN,
  27738. + SWITCH_CMD_GET_VLAN,
  27739. + SWITCH_CMD_SET_VLAN
  27740. +};
  27741. +
  27742. +/* data types */
  27743. +enum switch_val_type {
  27744. + SWITCH_TYPE_UNSPEC,
  27745. + SWITCH_TYPE_INT,
  27746. + SWITCH_TYPE_STRING,
  27747. + SWITCH_TYPE_PORTS,
  27748. + SWITCH_TYPE_NOVAL,
  27749. +};
  27750. +
  27751. +/* port nested attributes */
  27752. +enum {
  27753. + SWITCH_PORT_UNSPEC,
  27754. + SWITCH_PORT_ID,
  27755. + SWITCH_PORT_FLAG_TAGGED,
  27756. + SWITCH_PORT_ATTR_MAX
  27757. +};
  27758. +
  27759. +#define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000
  27760. +
  27761. +#ifdef __KERNEL__
  27762. +
  27763. +struct switch_dev;
  27764. +struct switch_op;
  27765. +struct switch_val;
  27766. +struct switch_attr;
  27767. +struct switch_attrlist;
  27768. +
  27769. +int register_switch(struct switch_dev *dev, struct net_device *netdev);
  27770. +void unregister_switch(struct switch_dev *dev);
  27771. +
  27772. +/**
  27773. + * struct switch_attrlist - attribute list
  27774. + *
  27775. + * @n_attr: number of attributes
  27776. + * @attr: pointer to the attributes array
  27777. + */
  27778. +struct switch_attrlist {
  27779. + int n_attr;
  27780. + const struct switch_attr *attr;
  27781. +};
  27782. +
  27783. +/**
  27784. + * struct switch_dev_ops - switch driver operations
  27785. + *
  27786. + * @attr_global: global switch attribute list
  27787. + * @attr_port: port attribute list
  27788. + * @attr_vlan: vlan attribute list
  27789. + *
  27790. + * Callbacks:
  27791. + *
  27792. + * @get_vlan_ports: read the port list of a VLAN
  27793. + * @set_vlan_ports: set the port list of a VLAN
  27794. + *
  27795. + * @get_port_pvid: get the primary VLAN ID of a port
  27796. + * @set_port_pvid: set the primary VLAN ID of a port
  27797. + *
  27798. + * @apply_config: apply all changed settings to the switch
  27799. + * @reset_switch: resetting the switch
  27800. + */
  27801. +struct switch_dev_ops {
  27802. + struct switch_attrlist attr_global, attr_port, attr_vlan;
  27803. +
  27804. + int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
  27805. + int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
  27806. +
  27807. + int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
  27808. + int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
  27809. +
  27810. + int (*apply_config)(struct switch_dev *dev);
  27811. + int (*reset_switch)(struct switch_dev *dev);
  27812. +};
  27813. +
  27814. +struct switch_dev {
  27815. + const struct switch_dev_ops *ops;
  27816. + /* will be automatically filled */
  27817. + char devname[IFNAMSIZ];
  27818. +
  27819. + const char *name;
  27820. + /* NB: either alias or netdev must be set */
  27821. + const char *alias;
  27822. + struct net_device *netdev;
  27823. +
  27824. + int ports;
  27825. + int vlans;
  27826. + int cpu_port;
  27827. +
  27828. + /* the following fields are internal for swconfig */
  27829. + int id;
  27830. + struct list_head dev_list;
  27831. + unsigned long def_global, def_port, def_vlan;
  27832. +
  27833. + spinlock_t lock;
  27834. + struct switch_port *portbuf;
  27835. +};
  27836. +
  27837. +struct switch_port {
  27838. + u32 id;
  27839. + u32 flags;
  27840. +};
  27841. +
  27842. +struct switch_val {
  27843. + const struct switch_attr *attr;
  27844. + int port_vlan;
  27845. + int len;
  27846. + union {
  27847. + const char *s;
  27848. + u32 i;
  27849. + struct switch_port *ports;
  27850. + } value;
  27851. +};
  27852. +
  27853. +struct switch_attr {
  27854. + int disabled;
  27855. + int type;
  27856. + const char *name;
  27857. + const char *description;
  27858. +
  27859. + int (*set)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
  27860. + int (*get)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
  27861. +
  27862. + /* for driver internal use */
  27863. + int id;
  27864. + int ofs;
  27865. + int max;
  27866. +};
  27867. +
  27868. +#endif
  27869. +
  27870. +#endif
  27871. diff -Nur linux-2.6.39.orig/include/linux/tcp.h linux-2.6.39/include/linux/tcp.h
  27872. --- linux-2.6.39.orig/include/linux/tcp.h 2011-05-19 06:06:34.000000000 +0200
  27873. +++ linux-2.6.39/include/linux/tcp.h 2011-08-24 05:53:21.379228748 +0200
  27874. @@ -54,7 +54,7 @@
  27875. __be16 window;
  27876. __sum16 check;
  27877. __be16 urg_ptr;
  27878. -};
  27879. +} __packed;
  27880. /*
  27881. * The union cast uses a gcc extension to avoid aliasing problems
  27882. diff -Nur linux-2.6.39.orig/include/linux/udp.h linux-2.6.39/include/linux/udp.h
  27883. --- linux-2.6.39.orig/include/linux/udp.h 2011-05-19 06:06:34.000000000 +0200
  27884. +++ linux-2.6.39/include/linux/udp.h 2011-08-24 05:53:21.428824967 +0200
  27885. @@ -24,7 +24,7 @@
  27886. __be16 dest;
  27887. __be16 len;
  27888. __sum16 check;
  27889. -};
  27890. +} __packed;
  27891. /* UDP socket options */
  27892. #define UDP_CORK 1 /* Never send partially complete segments */
  27893. diff -Nur linux-2.6.39.orig/net/dsa/mv88e6063.c linux-2.6.39/net/dsa/mv88e6063.c
  27894. --- linux-2.6.39.orig/net/dsa/mv88e6063.c 1970-01-01 01:00:00.000000000 +0100
  27895. +++ linux-2.6.39/net/dsa/mv88e6063.c 2011-04-27 12:19:21.827661792 +0200
  27896. @@ -0,0 +1,294 @@
  27897. +/*
  27898. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6063 switch chips
  27899. + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  27900. + *
  27901. + * This driver was base on: net/dsa/mv88e6060.c
  27902. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6060 switch chips
  27903. + * Copyright (c) 2008-2009 Marvell Semiconductor
  27904. + *
  27905. + * This program is free software; you can redistribute it and/or modify
  27906. + * it under the terms of the GNU General Public License as published by
  27907. + * the Free Software Foundation; either version 2 of the License, or
  27908. + * (at your option) any later version.
  27909. + */
  27910. +
  27911. +#include <linux/list.h>
  27912. +#include <linux/netdevice.h>
  27913. +#include <linux/phy.h>
  27914. +#include "dsa_priv.h"
  27915. +
  27916. +#define REG_BASE 0x10
  27917. +#define REG_PHY(p) (REG_BASE + (p))
  27918. +#define REG_PORT(p) (REG_BASE + 8 + (p))
  27919. +#define REG_GLOBAL (REG_BASE + 0x0f)
  27920. +#define NUM_PORTS 7
  27921. +
  27922. +static int reg_read(struct dsa_switch *ds, int addr, int reg)
  27923. +{
  27924. + return mdiobus_read(ds->master_mii_bus, addr, reg);
  27925. +}
  27926. +
  27927. +#define REG_READ(addr, reg) \
  27928. + ({ \
  27929. + int __ret; \
  27930. + \
  27931. + __ret = reg_read(ds, addr, reg); \
  27932. + if (__ret < 0) \
  27933. + return __ret; \
  27934. + __ret; \
  27935. + })
  27936. +
  27937. +
  27938. +static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
  27939. +{
  27940. + return mdiobus_write(ds->master_mii_bus, addr, reg, val);
  27941. +}
  27942. +
  27943. +#define REG_WRITE(addr, reg, val) \
  27944. + ({ \
  27945. + int __ret; \
  27946. + \
  27947. + __ret = reg_write(ds, addr, reg, val); \
  27948. + if (__ret < 0) \
  27949. + return __ret; \
  27950. + })
  27951. +
  27952. +static char *mv88e6063_probe(struct mii_bus *bus, int sw_addr)
  27953. +{
  27954. + int ret;
  27955. +
  27956. + ret = mdiobus_read(bus, REG_PORT(0), 0x03);
  27957. + if (ret >= 0) {
  27958. + ret &= 0xfff0;
  27959. + if (ret == 0x1530)
  27960. + return "Marvell 88E6063";
  27961. + }
  27962. +
  27963. + return NULL;
  27964. +}
  27965. +
  27966. +static int mv88e6063_switch_reset(struct dsa_switch *ds)
  27967. +{
  27968. + int i;
  27969. + int ret;
  27970. +
  27971. + /*
  27972. + * Set all ports to the disabled state.
  27973. + */
  27974. + for (i = 0; i < NUM_PORTS; i++) {
  27975. + ret = REG_READ(REG_PORT(i), 0x04);
  27976. + REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  27977. + }
  27978. +
  27979. + /*
  27980. + * Wait for transmit queues to drain.
  27981. + */
  27982. + msleep(2);
  27983. +
  27984. + /*
  27985. + * Reset the switch.
  27986. + */
  27987. + REG_WRITE(REG_GLOBAL, 0x0a, 0xa130);
  27988. +
  27989. + /*
  27990. + * Wait up to one second for reset to complete.
  27991. + */
  27992. + for (i = 0; i < 1000; i++) {
  27993. + ret = REG_READ(REG_GLOBAL, 0x00);
  27994. + if ((ret & 0x8000) == 0x0000)
  27995. + break;
  27996. +
  27997. + msleep(1);
  27998. + }
  27999. + if (i == 1000)
  28000. + return -ETIMEDOUT;
  28001. +
  28002. + return 0;
  28003. +}
  28004. +
  28005. +static int mv88e6063_setup_global(struct dsa_switch *ds)
  28006. +{
  28007. + /*
  28008. + * Disable discarding of frames with excessive collisions,
  28009. + * set the maximum frame size to 1536 bytes, and mask all
  28010. + * interrupt sources.
  28011. + */
  28012. + REG_WRITE(REG_GLOBAL, 0x04, 0x0800);
  28013. +
  28014. + /*
  28015. + * Enable automatic address learning, set the address
  28016. + * database size to 1024 entries, and set the default aging
  28017. + * time to 5 minutes.
  28018. + */
  28019. + REG_WRITE(REG_GLOBAL, 0x0a, 0x2130);
  28020. +
  28021. + return 0;
  28022. +}
  28023. +
  28024. +static int mv88e6063_setup_port(struct dsa_switch *ds, int p)
  28025. +{
  28026. + int addr = REG_PORT(p);
  28027. +
  28028. + /*
  28029. + * Do not force flow control, disable Ingress and Egress
  28030. + * Header tagging, disable VLAN tunneling, and set the port
  28031. + * state to Forwarding. Additionally, if this is the CPU
  28032. + * port, enable Ingress and Egress Trailer tagging mode.
  28033. + */
  28034. + REG_WRITE(addr, 0x04, dsa_is_cpu_port(ds, p) ? 0x4103 : 0x0003);
  28035. +
  28036. + /*
  28037. + * Port based VLAN map: give each port its own address
  28038. + * database, allow the CPU port to talk to each of the 'real'
  28039. + * ports, and allow each of the 'real' ports to only talk to
  28040. + * the CPU port.
  28041. + */
  28042. + REG_WRITE(addr, 0x06,
  28043. + ((p & 0xf) << 12) |
  28044. + (dsa_is_cpu_port(ds, p) ?
  28045. + ds->phys_port_mask :
  28046. + (1 << ds->dst->cpu_port)));
  28047. +
  28048. + /*
  28049. + * Port Association Vector: when learning source addresses
  28050. + * of packets, add the address to the address database using
  28051. + * a port bitmap that has only the bit for this port set and
  28052. + * the other bits clear.
  28053. + */
  28054. + REG_WRITE(addr, 0x0b, 1 << p);
  28055. +
  28056. + return 0;
  28057. +}
  28058. +
  28059. +static int mv88e6063_setup(struct dsa_switch *ds)
  28060. +{
  28061. + int i;
  28062. + int ret;
  28063. +
  28064. + ret = mv88e6063_switch_reset(ds);
  28065. + if (ret < 0)
  28066. + return ret;
  28067. +
  28068. + /* @@@ initialise atu */
  28069. +
  28070. + ret = mv88e6063_setup_global(ds);
  28071. + if (ret < 0)
  28072. + return ret;
  28073. +
  28074. + for (i = 0; i < NUM_PORTS; i++) {
  28075. + ret = mv88e6063_setup_port(ds, i);
  28076. + if (ret < 0)
  28077. + return ret;
  28078. + }
  28079. +
  28080. + return 0;
  28081. +}
  28082. +
  28083. +static int mv88e6063_set_addr(struct dsa_switch *ds, u8 *addr)
  28084. +{
  28085. + REG_WRITE(REG_GLOBAL, 0x01, (addr[0] << 8) | addr[1]);
  28086. + REG_WRITE(REG_GLOBAL, 0x02, (addr[2] << 8) | addr[3]);
  28087. + REG_WRITE(REG_GLOBAL, 0x03, (addr[4] << 8) | addr[5]);
  28088. +
  28089. + return 0;
  28090. +}
  28091. +
  28092. +static int mv88e6063_port_to_phy_addr(int port)
  28093. +{
  28094. + if (port >= 0 && port <= NUM_PORTS)
  28095. + return REG_PHY(port);
  28096. + return -1;
  28097. +}
  28098. +
  28099. +static int mv88e6063_phy_read(struct dsa_switch *ds, int port, int regnum)
  28100. +{
  28101. + int addr;
  28102. +
  28103. + addr = mv88e6063_port_to_phy_addr(port);
  28104. + if (addr == -1)
  28105. + return 0xffff;
  28106. +
  28107. + return reg_read(ds, addr, regnum);
  28108. +}
  28109. +
  28110. +static int
  28111. +mv88e6063_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
  28112. +{
  28113. + int addr;
  28114. +
  28115. + addr = mv88e6063_port_to_phy_addr(port);
  28116. + if (addr == -1)
  28117. + return 0xffff;
  28118. +
  28119. + return reg_write(ds, addr, regnum, val);
  28120. +}
  28121. +
  28122. +static void mv88e6063_poll_link(struct dsa_switch *ds)
  28123. +{
  28124. + int i;
  28125. +
  28126. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  28127. + struct net_device *dev;
  28128. + int uninitialized_var(port_status);
  28129. + int link;
  28130. + int speed;
  28131. + int duplex;
  28132. + int fc;
  28133. +
  28134. + dev = ds->ports[i];
  28135. + if (dev == NULL)
  28136. + continue;
  28137. +
  28138. + link = 0;
  28139. + if (dev->flags & IFF_UP) {
  28140. + port_status = reg_read(ds, REG_PORT(i), 0x00);
  28141. + if (port_status < 0)
  28142. + continue;
  28143. +
  28144. + link = !!(port_status & 0x1000);
  28145. + }
  28146. +
  28147. + if (!link) {
  28148. + if (netif_carrier_ok(dev)) {
  28149. + printk(KERN_INFO "%s: link down\n", dev->name);
  28150. + netif_carrier_off(dev);
  28151. + }
  28152. + continue;
  28153. + }
  28154. +
  28155. + speed = (port_status & 0x0100) ? 100 : 10;
  28156. + duplex = (port_status & 0x0200) ? 1 : 0;
  28157. + fc = ((port_status & 0xc000) == 0xc000) ? 1 : 0;
  28158. +
  28159. + if (!netif_carrier_ok(dev)) {
  28160. + printk(KERN_INFO "%s: link up, %d Mb/s, %s duplex, "
  28161. + "flow control %sabled\n", dev->name,
  28162. + speed, duplex ? "full" : "half",
  28163. + fc ? "en" : "dis");
  28164. + netif_carrier_on(dev);
  28165. + }
  28166. + }
  28167. +}
  28168. +
  28169. +static struct dsa_switch_driver mv88e6063_switch_driver = {
  28170. + .tag_protocol = htons(ETH_P_TRAILER),
  28171. + .probe = mv88e6063_probe,
  28172. + .setup = mv88e6063_setup,
  28173. + .set_addr = mv88e6063_set_addr,
  28174. + .phy_read = mv88e6063_phy_read,
  28175. + .phy_write = mv88e6063_phy_write,
  28176. + .poll_link = mv88e6063_poll_link,
  28177. +};
  28178. +
  28179. +static int __init mv88e6063_init(void)
  28180. +{
  28181. + register_switch_driver(&mv88e6063_switch_driver);
  28182. + return 0;
  28183. +}
  28184. +module_init(mv88e6063_init);
  28185. +
  28186. +static void __exit mv88e6063_cleanup(void)
  28187. +{
  28188. + unregister_switch_driver(&mv88e6063_switch_driver);
  28189. +}
  28190. +module_exit(mv88e6063_cleanup);
  28191. diff -Nur linux-2.6.39.orig/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c linux-2.6.39/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
  28192. --- linux-2.6.39.orig/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c 2011-05-19 06:06:34.000000000 +0200
  28193. +++ linux-2.6.39/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c 2011-08-24 05:53:21.549229118 +0200
  28194. @@ -14,6 +14,7 @@
  28195. #include <linux/skbuff.h>
  28196. #include <linux/icmp.h>
  28197. #include <linux/sysctl.h>
  28198. +#include <linux/unaligned/packed_struct.h>
  28199. #include <net/route.h>
  28200. #include <net/ip.h>
  28201. @@ -44,8 +45,8 @@
  28202. if (ap == NULL)
  28203. return false;
  28204. - tuple->src.u3.ip = ap[0];
  28205. - tuple->dst.u3.ip = ap[1];
  28206. + tuple->src.u3.ip = __get_unaligned_cpu32(ap++);
  28207. + tuple->dst.u3.ip = __get_unaligned_cpu32(ap);
  28208. return true;
  28209. }