ar71xx.patch 493 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749
  1. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/ar71xx.c linux-2.6.33.3/arch/mips/ar71xx/ar71xx.c
  2. --- linux-2.6.33.3.orig/arch/mips/ar71xx/ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.33.3/arch/mips/ar71xx/ar71xx.c 2010-04-02 11:07:51.850954806 +0200
  4. @@ -0,0 +1,177 @@
  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. +
  21. +#include <asm/mach-ar71xx/ar71xx.h>
  22. +
  23. +static DEFINE_MUTEX(ar71xx_flash_mutex);
  24. +
  25. +void __iomem *ar71xx_ddr_base;
  26. +EXPORT_SYMBOL_GPL(ar71xx_ddr_base);
  27. +
  28. +void __iomem *ar71xx_pll_base;
  29. +EXPORT_SYMBOL_GPL(ar71xx_pll_base);
  30. +
  31. +void __iomem *ar71xx_reset_base;
  32. +EXPORT_SYMBOL_GPL(ar71xx_reset_base);
  33. +
  34. +void __iomem *ar71xx_gpio_base;
  35. +EXPORT_SYMBOL_GPL(ar71xx_gpio_base);
  36. +
  37. +void __iomem *ar71xx_usb_ctrl_base;
  38. +EXPORT_SYMBOL_GPL(ar71xx_usb_ctrl_base);
  39. +
  40. +void ar71xx_device_stop(u32 mask)
  41. +{
  42. + unsigned long flags;
  43. + u32 mask_inv;
  44. + u32 t;
  45. +
  46. + switch (ar71xx_soc) {
  47. + case AR71XX_SOC_AR7130:
  48. + case AR71XX_SOC_AR7141:
  49. + case AR71XX_SOC_AR7161:
  50. + local_irq_save(flags);
  51. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  52. + ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t | mask);
  53. + local_irq_restore(flags);
  54. + break;
  55. +
  56. + case AR71XX_SOC_AR7240:
  57. + case AR71XX_SOC_AR7241:
  58. + case AR71XX_SOC_AR7242:
  59. + mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
  60. + local_irq_save(flags);
  61. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  62. + t |= mask;
  63. + t &= ~mask_inv;
  64. + ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
  65. + local_irq_restore(flags);
  66. + break;
  67. +
  68. + case AR71XX_SOC_AR9130:
  69. + case AR71XX_SOC_AR9132:
  70. + local_irq_save(flags);
  71. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  72. + ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t | mask);
  73. + local_irq_restore(flags);
  74. + break;
  75. +
  76. + default:
  77. + BUG();
  78. + }
  79. +}
  80. +EXPORT_SYMBOL_GPL(ar71xx_device_stop);
  81. +
  82. +void ar71xx_device_start(u32 mask)
  83. +{
  84. + unsigned long flags;
  85. + u32 mask_inv;
  86. + u32 t;
  87. +
  88. + switch (ar71xx_soc) {
  89. + case AR71XX_SOC_AR7130:
  90. + case AR71XX_SOC_AR7141:
  91. + case AR71XX_SOC_AR7161:
  92. + local_irq_save(flags);
  93. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  94. + ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t & ~mask);
  95. + local_irq_restore(flags);
  96. + break;
  97. +
  98. + case AR71XX_SOC_AR7240:
  99. + case AR71XX_SOC_AR7241:
  100. + case AR71XX_SOC_AR7242:
  101. + mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
  102. + local_irq_save(flags);
  103. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  104. + t &= ~mask;
  105. + t |= mask_inv;
  106. + ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
  107. + local_irq_restore(flags);
  108. + break;
  109. +
  110. + case AR71XX_SOC_AR9130:
  111. + case AR71XX_SOC_AR9132:
  112. + local_irq_save(flags);
  113. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  114. + ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t & ~mask);
  115. + local_irq_restore(flags);
  116. + break;
  117. +
  118. + default:
  119. + BUG();
  120. + }
  121. +}
  122. +EXPORT_SYMBOL_GPL(ar71xx_device_start);
  123. +
  124. +int ar71xx_device_stopped(u32 mask)
  125. +{
  126. + unsigned long flags;
  127. + u32 t;
  128. +
  129. + switch (ar71xx_soc) {
  130. + case AR71XX_SOC_AR7130:
  131. + case AR71XX_SOC_AR7141:
  132. + case AR71XX_SOC_AR7161:
  133. + local_irq_save(flags);
  134. + t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
  135. + local_irq_restore(flags);
  136. + break;
  137. +
  138. + case AR71XX_SOC_AR7240:
  139. + case AR71XX_SOC_AR7241:
  140. + case AR71XX_SOC_AR7242:
  141. + local_irq_save(flags);
  142. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  143. + local_irq_restore(flags);
  144. + break;
  145. +
  146. + case AR71XX_SOC_AR9130:
  147. + case AR71XX_SOC_AR9132:
  148. + local_irq_save(flags);
  149. + t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
  150. + local_irq_restore(flags);
  151. + break;
  152. +
  153. + default:
  154. + BUG();
  155. + }
  156. +
  157. + return ((t & mask) == mask);
  158. +}
  159. +EXPORT_SYMBOL_GPL(ar71xx_device_stopped);
  160. +
  161. +void ar71xx_ddr_flush(u32 reg)
  162. +{
  163. + ar71xx_ddr_wr(reg, 1);
  164. + while ((ar71xx_ddr_rr(reg) & 0x1));
  165. +
  166. + ar71xx_ddr_wr(reg, 1);
  167. + while ((ar71xx_ddr_rr(reg) & 0x1));
  168. +}
  169. +EXPORT_SYMBOL_GPL(ar71xx_ddr_flush);
  170. +
  171. +void ar71xx_flash_acquire(void)
  172. +{
  173. + mutex_lock(&ar71xx_flash_mutex);
  174. +}
  175. +EXPORT_SYMBOL_GPL(ar71xx_flash_acquire);
  176. +
  177. +void ar71xx_flash_release(void)
  178. +{
  179. + mutex_unlock(&ar71xx_flash_mutex);
  180. +}
  181. +EXPORT_SYMBOL_GPL(ar71xx_flash_release);
  182. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-eth.c linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-eth.c
  183. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-eth.c 1970-01-01 01:00:00.000000000 +0100
  184. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-eth.c 2010-03-23 20:31:04.580708993 +0100
  185. @@ -0,0 +1,70 @@
  186. +/*
  187. + * Atheros AP91 reference board ethernet initialization
  188. + *
  189. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  190. + *
  191. + * This program is free software; you can redistribute it and/or modify it
  192. + * under the terms of the GNU General Public License version 2 as published
  193. + * by the Free Software Foundation.
  194. + */
  195. +
  196. +#include "devices.h"
  197. +#include "dev-dsa.h"
  198. +#include "dev-ap91-eth.h"
  199. +
  200. +static struct dsa_chip_data ap91_dsa_chip = {
  201. + .port_names[0] = "cpu",
  202. + .port_names[1] = "lan1",
  203. + .port_names[2] = "lan2",
  204. + .port_names[3] = "lan3",
  205. + .port_names[4] = "lan4",
  206. +};
  207. +
  208. +static struct dsa_platform_data ap91_dsa_data = {
  209. + .nr_chips = 1,
  210. + .chip = &ap91_dsa_chip,
  211. +};
  212. +
  213. +static void ap91_eth_set_port_name(unsigned port, const char *name)
  214. +{
  215. + if (port < 1 || port > 5)
  216. + return;
  217. +
  218. + if (name)
  219. + ap91_dsa_chip.port_names[port] = (char *) name;
  220. +}
  221. +
  222. +void __init ap91_eth_init(u8 *mac_addr, const char *port_names[])
  223. +{
  224. + if (mac_addr)
  225. + ar71xx_set_mac_base(mac_addr);
  226. +
  227. + if (port_names) {
  228. + int i;
  229. +
  230. + for (i = 0; i < AP91_ETH_NUM_PORT_NAMES; i++)
  231. + ap91_eth_set_port_name(i + 1, port_names[i]);
  232. + }
  233. +
  234. + /* WAN port */
  235. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  236. + ar71xx_eth0_data.speed = SPEED_100;
  237. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  238. + ar71xx_eth0_data.fifo_cfg1 = 0x0fff0000;
  239. + ar71xx_eth0_data.fifo_cfg2 = 0x00001fff;
  240. + ar71xx_eth0_data.fifo_cfg3 = 0x008001ff;
  241. +
  242. + /* LAN ports */
  243. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  244. + ar71xx_eth1_data.speed = SPEED_1000;
  245. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  246. + ar71xx_eth1_data.fifo_cfg1 = 0x0fff0000;
  247. + ar71xx_eth1_data.fifo_cfg2 = 0x00001fff;
  248. + ar71xx_eth1_data.fifo_cfg3 = 0x008001ff;
  249. +
  250. + ar71xx_add_device_mdio(0x0);
  251. + ar71xx_add_device_eth(1);
  252. + ar71xx_add_device_eth(0);
  253. +
  254. + ar71xx_add_device_dsa(1, &ap91_dsa_data);
  255. +}
  256. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-eth.h linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-eth.h
  257. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-eth.h 1970-01-01 01:00:00.000000000 +0100
  258. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-eth.h 2010-03-12 19:31:46.886045750 +0100
  259. @@ -0,0 +1,23 @@
  260. +/*
  261. + * Atheros AP91 reference board ethernet initialization
  262. + *
  263. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  264. + *
  265. + * This program is free software; you can redistribute it and/or modify it
  266. + * under the terms of the GNU General Public License version 2 as published
  267. + * by the Free Software Foundation.
  268. + */
  269. +
  270. +#ifndef _AR71XX_DEV_AP91_ETH_H
  271. +#define _AR71XX_DEV_AP91_ETH_H
  272. +
  273. +#define AP91_ETH_NUM_PORT_NAMES 4
  274. +
  275. +#if defined(CONFIG_AR71XX_DEV_AP91_ETH)
  276. +void ap91_eth_init(u8 *mac_addr, const char *port_names[]) __init;
  277. +#else
  278. +static inline void ap91_eth_init(u8 *mac_addr) { }
  279. +#endif
  280. +
  281. +#endif /* _AR71XX_DEV_AP91_ETH_H */
  282. +
  283. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-pci.c linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-pci.c
  284. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-pci.c 1970-01-01 01:00:00.000000000 +0100
  285. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-pci.c 2009-12-25 12:10:59.596028998 +0100
  286. @@ -0,0 +1,114 @@
  287. +/*
  288. + * Atheros AP91 reference board PCI initialization
  289. + *
  290. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  291. + *
  292. + * This program is free software; you can redistribute it and/or modify it
  293. + * under the terms of the GNU General Public License version 2 as published
  294. + * by the Free Software Foundation.
  295. + */
  296. +
  297. +#include <linux/pci.h>
  298. +#include <linux/ath9k_platform.h>
  299. +#include <linux/delay.h>
  300. +
  301. +#include <asm/mach-ar71xx/ar71xx.h>
  302. +#include <asm/mach-ar71xx/pci.h>
  303. +
  304. +#include "dev-ap91-pci.h"
  305. +
  306. +static struct ath9k_platform_data ap91_wmac_data;
  307. +static char ap91_wmac_mac[6];
  308. +static int ap91_pci_fixup_enabled;
  309. +
  310. +static struct ar71xx_pci_irq ap91_pci_irqs[] __initdata = {
  311. + {
  312. + .slot = 0,
  313. + .pin = 1,
  314. + .irq = AR71XX_PCI_IRQ_DEV0,
  315. + }
  316. +};
  317. +
  318. +static int ap91_pci_plat_dev_init(struct pci_dev *dev)
  319. +{
  320. + switch(PCI_SLOT(dev->devfn)) {
  321. + case 0:
  322. + dev->dev.platform_data = &ap91_wmac_data;
  323. + break;
  324. + }
  325. +
  326. + return 0;
  327. +}
  328. +
  329. +static void ap91_pci_fixup(struct pci_dev *dev)
  330. +{
  331. + void __iomem *mem;
  332. + u16 *cal_data;
  333. + u16 cmd;
  334. + u32 val;
  335. +
  336. + if (!ap91_pci_fixup_enabled)
  337. + return;
  338. +
  339. + printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
  340. +
  341. + cal_data = ap91_wmac_data.eeprom_data;
  342. + if (*cal_data != 0xa55a) {
  343. + printk(KERN_ERR "PCI: no calibration data found for %s\n",
  344. + pci_name(dev));
  345. + return;
  346. + }
  347. +
  348. + mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
  349. + if (!mem) {
  350. + printk(KERN_ERR "PCI: ioremap error for device %s\n",
  351. + pci_name(dev));
  352. + return;
  353. + }
  354. +
  355. + /* Setup the PCI device to allow access to the internal registers */
  356. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0xffff);
  357. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  358. + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  359. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  360. +
  361. + /* set pointer to first reg address */
  362. + cal_data += 3;
  363. + while (*cal_data != 0xffff) {
  364. + u32 reg;
  365. + reg = *cal_data++;
  366. + val = *cal_data++;
  367. + val |= (*cal_data++) << 16;
  368. +
  369. + __raw_writel(val, mem + reg);
  370. + udelay(100);
  371. + }
  372. +
  373. + pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  374. + dev->vendor = val & 0xffff;
  375. + dev->device = (val >> 16) & 0xffff;
  376. +
  377. + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  378. + dev->revision = val & 0xff;
  379. + dev->class = val >> 8; /* upper 3 bytes */
  380. +
  381. + iounmap(mem);
  382. +}
  383. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ap91_pci_fixup);
  384. +
  385. +void __init ap91_pci_init(u8 *cal_data, u8 *mac_addr)
  386. +{
  387. + if (cal_data)
  388. + memcpy(ap91_wmac_data.eeprom_data, cal_data,
  389. + sizeof(ap91_wmac_data.eeprom_data));
  390. +
  391. + if (mac_addr) {
  392. + memcpy(ap91_wmac_mac, mac_addr, sizeof(ap91_wmac_mac));
  393. + ap91_wmac_data.macaddr = ap91_wmac_mac;
  394. + }
  395. +
  396. + ar71xx_pci_plat_dev_init = ap91_pci_plat_dev_init;
  397. + ar71xx_pci_init(ARRAY_SIZE(ap91_pci_irqs), ap91_pci_irqs);
  398. +
  399. + ap91_pci_fixup_enabled = 1;
  400. +}
  401. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-pci.h linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-pci.h
  402. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap91-pci.h 1970-01-01 01:00:00.000000000 +0100
  403. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap91-pci.h 2010-01-05 20:38:52.249392561 +0100
  404. @@ -0,0 +1,21 @@
  405. +/*
  406. + * Atheros AP91 reference board PCI initialization
  407. + *
  408. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  409. + *
  410. + * This program is free software; you can redistribute it and/or modify it
  411. + * under the terms of the GNU General Public License version 2 as published
  412. + * by the Free Software Foundation.
  413. + */
  414. +
  415. +#ifndef _AR71XX_DEV_AP91_PCI_H
  416. +#define _AR71XX_DEV_AP91_PCI_H
  417. +
  418. +#if defined(CONFIG_AR71XX_DEV_AP91_PCI)
  419. +void ap91_pci_init(u8 *cal_data, u8 *mac_addr) __init;
  420. +#else
  421. +static inline void ap91_pci_init(u8 *cal_data, u8 *mac_addr) { }
  422. +#endif
  423. +
  424. +#endif /* _AR71XX_DEV_AP91_PCI_H */
  425. +
  426. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap94-pci.c linux-2.6.33.3/arch/mips/ar71xx/dev-ap94-pci.c
  427. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap94-pci.c 1970-01-01 01:00:00.000000000 +0100
  428. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap94-pci.c 2010-02-13 16:30:07.244691791 +0100
  429. @@ -0,0 +1,159 @@
  430. +/*
  431. + * Atheros AP94 reference board PCI initialization
  432. + *
  433. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  434. + *
  435. + * This program is free software; you can redistribute it and/or modify it
  436. + * under the terms of the GNU General Public License version 2 as published
  437. + * by the Free Software Foundation.
  438. + */
  439. +
  440. +#include <linux/pci.h>
  441. +#include <linux/ath9k_platform.h>
  442. +#include <linux/delay.h>
  443. +
  444. +#include <asm/mach-ar71xx/ar71xx.h>
  445. +#include <asm/mach-ar71xx/pci.h>
  446. +
  447. +#include "dev-ap94-pci.h"
  448. +
  449. +static struct ath9k_platform_data ap94_wmac0_data;
  450. +static struct ath9k_platform_data ap94_wmac1_data;
  451. +static char ap94_wmac0_mac[6];
  452. +static char ap94_wmac1_mac[6];
  453. +static int ap94_pci_fixup_enabled;
  454. +
  455. +static struct ar71xx_pci_irq ap94_pci_irqs[] __initdata = {
  456. + {
  457. + .slot = 0,
  458. + .pin = 1,
  459. + .irq = AR71XX_PCI_IRQ_DEV0,
  460. + }, {
  461. + .slot = 1,
  462. + .pin = 1,
  463. + .irq = AR71XX_PCI_IRQ_DEV1,
  464. + }
  465. +};
  466. +
  467. +static int ap94_pci_plat_dev_init(struct pci_dev *dev)
  468. +{
  469. + switch(PCI_SLOT(dev->devfn)) {
  470. + case 17:
  471. + dev->dev.platform_data = &ap94_wmac0_data;
  472. + break;
  473. +
  474. + case 18:
  475. + dev->dev.platform_data = &ap94_wmac1_data;
  476. + break;
  477. + }
  478. +
  479. + return 0;
  480. +}
  481. +
  482. +static void ap94_pci_fixup(struct pci_dev *dev)
  483. +{
  484. + void __iomem *mem;
  485. + u16 *cal_data;
  486. + u16 cmd;
  487. + u32 bar0;
  488. + u32 val;
  489. +
  490. + if (!ap94_pci_fixup_enabled)
  491. + return;
  492. +
  493. + switch (PCI_SLOT(dev->devfn)) {
  494. + case 17:
  495. + cal_data = ap94_wmac0_data.eeprom_data;
  496. + break;
  497. + case 18:
  498. + cal_data = ap94_wmac1_data.eeprom_data;
  499. + break;
  500. + default:
  501. + return;
  502. + }
  503. +
  504. + if (*cal_data != 0xa55a) {
  505. + printk(KERN_ERR "PCI: no calibration data found for %s\n",
  506. + pci_name(dev));
  507. + return;
  508. + }
  509. +
  510. + mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
  511. + if (!mem) {
  512. + printk(KERN_ERR "PCI: ioremap error for device %s\n",
  513. + pci_name(dev));
  514. + return;
  515. + }
  516. +
  517. + printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
  518. +
  519. + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
  520. +
  521. + /* Setup the PCI device to allow access to the internal registers */
  522. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, AR71XX_PCI_MEM_BASE);
  523. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  524. + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  525. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  526. +
  527. + /* set pointer to first reg address */
  528. + cal_data += 3;
  529. + while (*cal_data != 0xffff) {
  530. + u32 reg;
  531. + reg = *cal_data++;
  532. + val = *cal_data++;
  533. + val |= (*cal_data++) << 16;
  534. +
  535. + __raw_writel(val, mem + reg);
  536. + udelay(100);
  537. + }
  538. +
  539. + pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  540. + dev->vendor = val & 0xffff;
  541. + dev->device = (val >> 16) & 0xffff;
  542. +
  543. + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  544. + dev->revision = val & 0xff;
  545. + dev->class = val >> 8; /* upper 3 bytes */
  546. +
  547. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  548. + cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  549. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  550. +
  551. + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  552. +
  553. + iounmap(mem);
  554. +}
  555. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ap94_pci_fixup);
  556. +
  557. +void __init ap94_pci_enable_quirk_wndr3700(void)
  558. +{
  559. + ap94_wmac0_data.quirk_wndr3700 = 1;
  560. + ap94_wmac1_data.quirk_wndr3700 = 1;
  561. +}
  562. +
  563. +void __init ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  564. + u8 *cal_data1, u8 *mac_addr1)
  565. +{
  566. + if (cal_data0)
  567. + memcpy(ap94_wmac0_data.eeprom_data, cal_data0,
  568. + sizeof(ap94_wmac0_data.eeprom_data));
  569. +
  570. + if (cal_data1)
  571. + memcpy(ap94_wmac1_data.eeprom_data, cal_data1,
  572. + sizeof(ap94_wmac1_data.eeprom_data));
  573. +
  574. + if (mac_addr0) {
  575. + memcpy(ap94_wmac0_mac, mac_addr0, sizeof(ap94_wmac0_mac));
  576. + ap94_wmac0_data.macaddr = ap94_wmac0_mac;
  577. + }
  578. +
  579. + if (mac_addr1) {
  580. + memcpy(ap94_wmac1_mac, mac_addr1, sizeof(ap94_wmac1_mac));
  581. + ap94_wmac1_data.macaddr = ap94_wmac1_mac;
  582. + }
  583. +
  584. + ar71xx_pci_plat_dev_init = ap94_pci_plat_dev_init;
  585. + ar71xx_pci_init(ARRAY_SIZE(ap94_pci_irqs), ap94_pci_irqs);
  586. +
  587. + ap94_pci_fixup_enabled = 1;
  588. +}
  589. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap94-pci.h linux-2.6.33.3/arch/mips/ar71xx/dev-ap94-pci.h
  590. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ap94-pci.h 1970-01-01 01:00:00.000000000 +0100
  591. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ap94-pci.h 2010-02-13 16:30:07.244691791 +0100
  592. @@ -0,0 +1,28 @@
  593. +/*
  594. + * Atheros AP94 reference board PCI initialization
  595. + *
  596. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  597. + *
  598. + * This program is free software; you can redistribute it and/or modify it
  599. + * under the terms of the GNU General Public License version 2 as published
  600. + * by the Free Software Foundation.
  601. + */
  602. +
  603. +#ifndef _AR71XX_DEV_AP94_PCI_H
  604. +#define _AR71XX_DEV_AP94_PCI_H
  605. +
  606. +#if defined(CONFIG_AR71XX_DEV_AP94_PCI)
  607. +void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  608. + u8 *cal_data1, u8 *mac_addr1) __init;
  609. +
  610. +void ap94_pci_enable_quirk_wndr3700(void) __init;
  611. +
  612. +#else
  613. +static inline void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  614. + u8 *cal_data1, u8 *mac_addr1) {}
  615. +
  616. +static inline void ap94_pci_enable_quirk_wndr3700(void) {}
  617. +#endif
  618. +
  619. +#endif /* _AR71XX_DEV_AP94_PCI_H */
  620. +
  621. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ar913x-wmac.c linux-2.6.33.3/arch/mips/ar71xx/dev-ar913x-wmac.c
  622. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ar913x-wmac.c 1970-01-01 01:00:00.000000000 +0100
  623. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ar913x-wmac.c 2010-03-23 20:31:04.941023040 +0100
  624. @@ -0,0 +1,68 @@
  625. +/*
  626. + * Atheros AR913x SoC built-in WMAC device support
  627. + *
  628. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  629. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  630. + *
  631. + * Parts of this file are based on Atheros' 2.6.15 BSP
  632. + *
  633. + * This program is free software; you can redistribute it and/or modify it
  634. + * under the terms of the GNU General Public License version 2 as published
  635. + * by the Free Software Foundation.
  636. + */
  637. +
  638. +#include <linux/kernel.h>
  639. +#include <linux/init.h>
  640. +#include <linux/delay.h>
  641. +#include <linux/etherdevice.h>
  642. +#include <linux/platform_device.h>
  643. +#include <linux/ath9k_platform.h>
  644. +
  645. +#include <asm/mach-ar71xx/ar71xx.h>
  646. +
  647. +#include "dev-ar913x-wmac.h"
  648. +
  649. +static struct ath9k_platform_data ar913x_wmac_data;
  650. +static char ar913x_wmac_mac[6];
  651. +
  652. +static struct resource ar913x_wmac_resources[] = {
  653. + {
  654. + .start = AR91XX_WMAC_BASE,
  655. + .end = AR91XX_WMAC_BASE + AR91XX_WMAC_SIZE - 1,
  656. + .flags = IORESOURCE_MEM,
  657. + }, {
  658. + .start = AR71XX_CPU_IRQ_IP2,
  659. + .end = AR71XX_CPU_IRQ_IP2,
  660. + .flags = IORESOURCE_IRQ,
  661. + },
  662. +};
  663. +
  664. +static struct platform_device ar913x_wmac_device = {
  665. + .name = "ath9k",
  666. + .id = -1,
  667. + .resource = ar913x_wmac_resources,
  668. + .num_resources = ARRAY_SIZE(ar913x_wmac_resources),
  669. + .dev = {
  670. + .platform_data = &ar913x_wmac_data,
  671. + },
  672. +};
  673. +
  674. +void __init ar913x_add_device_wmac(u8 *cal_data, u8 *mac_addr)
  675. +{
  676. + if (cal_data)
  677. + memcpy(ar913x_wmac_data.eeprom_data, cal_data,
  678. + sizeof(ar913x_wmac_data.eeprom_data));
  679. +
  680. + if (mac_addr) {
  681. + memcpy(ar913x_wmac_mac, mac_addr, sizeof(ar913x_wmac_mac));
  682. + ar913x_wmac_data.macaddr = ar913x_wmac_mac;
  683. + }
  684. +
  685. + ar71xx_device_stop(RESET_MODULE_AMBA2WMAC);
  686. + mdelay(10);
  687. +
  688. + ar71xx_device_start(RESET_MODULE_AMBA2WMAC);
  689. + mdelay(10);
  690. +
  691. + platform_device_register(&ar913x_wmac_device);
  692. +}
  693. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ar913x-wmac.h linux-2.6.33.3/arch/mips/ar71xx/dev-ar913x-wmac.h
  694. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-ar913x-wmac.h 1970-01-01 01:00:00.000000000 +0100
  695. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-ar913x-wmac.h 2010-01-05 20:38:52.185278525 +0100
  696. @@ -0,0 +1,19 @@
  697. +/*
  698. + * Atheros AR913x SoC built-in WMAC device support
  699. + *
  700. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  701. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  702. + *
  703. + * Parts of this file are based on Atheros' 2.6.15 BSP
  704. + *
  705. + * This program is free software; you can redistribute it and/or modify it
  706. + * under the terms of the GNU General Public License version 2 as published
  707. + * by the Free Software Foundation.
  708. + */
  709. +
  710. +#ifndef _AR71XX_DEV_AR913X_WMAC_H
  711. +#define _AR71XX_DEV_AR913X_WMAC_H
  712. +
  713. +void ar913x_add_device_wmac(u8 *cal_data, u8 *mac_addr) __init;
  714. +
  715. +#endif /* _AR71XX_DEV_AR913X_WMAC_H */
  716. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-dsa.c linux-2.6.33.3/arch/mips/ar71xx/dev-dsa.c
  717. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-dsa.c 1970-01-01 01:00:00.000000000 +0100
  718. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-dsa.c 2010-01-05 20:38:52.058900684 +0100
  719. @@ -0,0 +1,50 @@
  720. +/*
  721. + * Atheros AR71xx DSA switch device support
  722. + *
  723. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  724. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  725. + *
  726. + * This program is free software; you can redistribute it and/or modify it
  727. + * under the terms of the GNU General Public License version 2 as published
  728. + * by the Free Software Foundation.
  729. + */
  730. +
  731. +#include <linux/init.h>
  732. +#include <linux/platform_device.h>
  733. +
  734. +#include <asm/mach-ar71xx/ar71xx.h>
  735. +
  736. +#include "devices.h"
  737. +#include "dev-dsa.h"
  738. +
  739. +static struct platform_device ar71xx_dsa_switch_device = {
  740. + .name = "dsa",
  741. + .id = 0,
  742. +};
  743. +
  744. +void __init ar71xx_add_device_dsa(unsigned int id,
  745. + struct dsa_platform_data *d)
  746. +{
  747. + int i;
  748. +
  749. + switch (id) {
  750. + case 0:
  751. + d->netdev = &ar71xx_eth0_device.dev;
  752. + break;
  753. + case 1:
  754. + d->netdev = &ar71xx_eth1_device.dev;
  755. + break;
  756. + default:
  757. + printk(KERN_ERR
  758. + "ar71xx: invalid ethernet id %d for DSA switch\n",
  759. + id);
  760. + return;
  761. + }
  762. +
  763. + for (i = 0; i < d->nr_chips; i++)
  764. + d->chip[i].mii_bus = &ar71xx_mdio_device.dev;
  765. +
  766. + ar71xx_dsa_switch_device.dev.platform_data = d;
  767. +
  768. + platform_device_register(&ar71xx_dsa_switch_device);
  769. +}
  770. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-dsa.h linux-2.6.33.3/arch/mips/ar71xx/dev-dsa.h
  771. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-dsa.h 1970-01-01 01:00:00.000000000 +0100
  772. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-dsa.h 2010-01-05 20:38:52.137278273 +0100
  773. @@ -0,0 +1,20 @@
  774. +/*
  775. + * Atheros AR71xx DSA switch device support
  776. + *
  777. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  778. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  779. + *
  780. + * This program is free software; you can redistribute it and/or modify it
  781. + * under the terms of the GNU General Public License version 2 as published
  782. + * by the Free Software Foundation.
  783. + */
  784. +
  785. +#ifndef _AR71XX_DEV_DSA_H
  786. +#define _AR71XX_DEV_DSA_H
  787. +
  788. +#include <net/dsa.h>
  789. +
  790. +void ar71xx_add_device_dsa(unsigned int id,
  791. + struct dsa_platform_data *d) __init;
  792. +
  793. +#endif /* _AR71XX_DEV_DSA_H */
  794. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-gpio-buttons.c linux-2.6.33.3/arch/mips/ar71xx/dev-gpio-buttons.c
  795. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-gpio-buttons.c 1970-01-01 01:00:00.000000000 +0100
  796. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-gpio-buttons.c 2010-01-05 20:38:52.310262885 +0100
  797. @@ -0,0 +1,58 @@
  798. +/*
  799. + * Atheros AR71xx GPIO button support
  800. + *
  801. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  802. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  803. + *
  804. + * This program is free software; you can redistribute it and/or modify it
  805. + * under the terms of the GNU General Public License version 2 as published
  806. + * by the Free Software Foundation.
  807. + */
  808. +
  809. +#include "linux/init.h"
  810. +#include <linux/platform_device.h>
  811. +
  812. +#include "dev-gpio-buttons.h"
  813. +
  814. +void __init ar71xx_add_device_gpio_buttons(int id,
  815. + unsigned poll_interval,
  816. + unsigned nbuttons,
  817. + struct gpio_button *buttons)
  818. +{
  819. + struct platform_device *pdev;
  820. + struct gpio_buttons_platform_data pdata;
  821. + struct gpio_button *p;
  822. + int err;
  823. +
  824. + p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
  825. + if (!p)
  826. + return;
  827. +
  828. + memcpy(p, buttons, nbuttons * sizeof(*p));
  829. +
  830. + pdev = platform_device_alloc("gpio-buttons", id);
  831. + if (!pdev)
  832. + goto err_free_buttons;
  833. +
  834. + memset(&pdata, 0, sizeof(pdata));
  835. + pdata.poll_interval = poll_interval;
  836. + pdata.nbuttons = nbuttons;
  837. + pdata.buttons = p;
  838. +
  839. + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  840. + if (err)
  841. + goto err_put_pdev;
  842. +
  843. +
  844. + err = platform_device_add(pdev);
  845. + if (err)
  846. + goto err_put_pdev;
  847. +
  848. + return;
  849. +
  850. +err_put_pdev:
  851. + platform_device_put(pdev);
  852. +
  853. +err_free_buttons:
  854. + kfree(p);
  855. +}
  856. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-gpio-buttons.h linux-2.6.33.3/arch/mips/ar71xx/dev-gpio-buttons.h
  857. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-gpio-buttons.h 1970-01-01 01:00:00.000000000 +0100
  858. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-gpio-buttons.h 2010-01-05 20:38:52.385278021 +0100
  859. @@ -0,0 +1,25 @@
  860. +/*
  861. + * Atheros AR71xx GPIO button support
  862. + *
  863. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  864. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  865. + *
  866. + * This program is free software; you can redistribute it and/or modify it
  867. + * under the terms of the GNU General Public License version 2 as published
  868. + * by the Free Software Foundation.
  869. + */
  870. +
  871. +#ifndef _AR71XX_DEV_GPIO_BUTTONS_H
  872. +#define _AR71XX_DEV_GPIO_BUTTONS_H
  873. +
  874. +#include <linux/input.h>
  875. +#include <linux/gpio_buttons.h>
  876. +
  877. +#include <asm/mach-ar71xx/platform.h>
  878. +
  879. +void ar71xx_add_device_gpio_buttons(int id,
  880. + unsigned poll_interval,
  881. + unsigned nbuttons,
  882. + struct gpio_button *buttons) __init;
  883. +
  884. +#endif /* _AR71XX_DEV_GPIO_BUTTONS_H */
  885. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/devices.c linux-2.6.33.3/arch/mips/ar71xx/devices.c
  886. --- linux-2.6.33.3.orig/arch/mips/ar71xx/devices.c 1970-01-01 01:00:00.000000000 +0100
  887. +++ linux-2.6.33.3/arch/mips/ar71xx/devices.c 2010-04-02 11:07:51.658955496 +0200
  888. @@ -0,0 +1,575 @@
  889. +/*
  890. + * Atheros AR71xx SoC platform devices
  891. + *
  892. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  893. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  894. + *
  895. + * Parts of this file are based on Atheros' 2.6.15 BSP
  896. + *
  897. + * This program is free software; you can redistribute it and/or modify it
  898. + * under the terms of the GNU General Public License version 2 as published
  899. + * by the Free Software Foundation.
  900. + */
  901. +
  902. +#include <linux/kernel.h>
  903. +#include <linux/init.h>
  904. +#include <linux/delay.h>
  905. +#include <linux/etherdevice.h>
  906. +#include <linux/platform_device.h>
  907. +#include <linux/serial_8250.h>
  908. +
  909. +#include <asm/mach-ar71xx/ar71xx.h>
  910. +
  911. +#include "devices.h"
  912. +
  913. +static u8 ar71xx_mac_base[ETH_ALEN] __initdata;
  914. +
  915. +static struct resource ar71xx_uart_resources[] = {
  916. + {
  917. + .start = AR71XX_UART_BASE,
  918. + .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
  919. + .flags = IORESOURCE_MEM,
  920. + },
  921. +};
  922. +
  923. +#define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
  924. +static struct plat_serial8250_port ar71xx_uart_data[] = {
  925. + {
  926. + .mapbase = AR71XX_UART_BASE,
  927. + .irq = AR71XX_MISC_IRQ_UART,
  928. + .flags = AR71XX_UART_FLAGS,
  929. + .iotype = UPIO_MEM32,
  930. + .regshift = 2,
  931. + }, {
  932. + /* terminating entry */
  933. + }
  934. +};
  935. +
  936. +static struct platform_device ar71xx_uart_device = {
  937. + .name = "serial8250",
  938. + .id = PLAT8250_DEV_PLATFORM,
  939. + .resource = ar71xx_uart_resources,
  940. + .num_resources = ARRAY_SIZE(ar71xx_uart_resources),
  941. + .dev = {
  942. + .platform_data = ar71xx_uart_data
  943. + },
  944. +};
  945. +
  946. +void __init ar71xx_add_device_uart(void)
  947. +{
  948. + ar71xx_uart_data[0].uartclk = ar71xx_ahb_freq;
  949. + platform_device_register(&ar71xx_uart_device);
  950. +}
  951. +
  952. +static struct resource ar71xx_mdio_resources[] = {
  953. + {
  954. + .name = "mdio_base",
  955. + .flags = IORESOURCE_MEM,
  956. + .start = AR71XX_GE0_BASE,
  957. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  958. + }
  959. +};
  960. +
  961. +static struct ag71xx_mdio_platform_data ar71xx_mdio_data;
  962. +
  963. +struct platform_device ar71xx_mdio_device = {
  964. + .name = "ag71xx-mdio",
  965. + .id = -1,
  966. + .resource = ar71xx_mdio_resources,
  967. + .num_resources = ARRAY_SIZE(ar71xx_mdio_resources),
  968. + .dev = {
  969. + .platform_data = &ar71xx_mdio_data,
  970. + },
  971. +};
  972. +
  973. +void __init ar71xx_add_device_mdio(u32 phy_mask)
  974. +{
  975. + switch (ar71xx_soc) {
  976. + case AR71XX_SOC_AR7240:
  977. + case AR71XX_SOC_AR7241:
  978. + case AR71XX_SOC_AR7242:
  979. + ar71xx_mdio_data.is_ar7240 = 1;
  980. + break;
  981. + default:
  982. + break;
  983. + }
  984. +
  985. + ar71xx_mdio_data.phy_mask = phy_mask;
  986. +
  987. + platform_device_register(&ar71xx_mdio_device);
  988. +}
  989. +
  990. +static void ar71xx_set_pll(u32 cfg_reg, u32 pll_reg, u32 pll_val, u32 shift)
  991. +{
  992. + void __iomem *base;
  993. + u32 t;
  994. +
  995. + base = ioremap_nocache(AR71XX_PLL_BASE, AR71XX_PLL_SIZE);
  996. +
  997. + t = __raw_readl(base + cfg_reg);
  998. + t &= ~(3 << shift);
  999. + t |= (2 << shift);
  1000. + __raw_writel(t, base + cfg_reg);
  1001. + udelay(100);
  1002. +
  1003. + __raw_writel(pll_val, base + pll_reg);
  1004. +
  1005. + t |= (3 << shift);
  1006. + __raw_writel(t, base + cfg_reg);
  1007. + udelay(100);
  1008. +
  1009. + t &= ~(3 << shift);
  1010. + __raw_writel(t, base + cfg_reg);
  1011. + udelay(100);
  1012. +
  1013. + printk(KERN_DEBUG "ar71xx: pll_reg %#x: %#x\n",
  1014. + (unsigned int)(base + pll_reg), __raw_readl(base + pll_reg));
  1015. +
  1016. + iounmap(base);
  1017. +}
  1018. +
  1019. +struct ar71xx_eth_pll_data ar71xx_eth0_pll_data;
  1020. +struct ar71xx_eth_pll_data ar71xx_eth1_pll_data;
  1021. +
  1022. +static u32 ar71xx_get_eth_pll(unsigned int mac, int speed)
  1023. +{
  1024. + struct ar71xx_eth_pll_data *pll_data;
  1025. + u32 pll_val;
  1026. +
  1027. + switch (mac) {
  1028. + case 0:
  1029. + pll_data = &ar71xx_eth0_pll_data;
  1030. + break;
  1031. + case 1:
  1032. + pll_data = &ar71xx_eth1_pll_data;
  1033. + break;
  1034. + default:
  1035. + BUG();
  1036. + }
  1037. +
  1038. + switch (speed) {
  1039. + case SPEED_10:
  1040. + pll_val = pll_data->pll_10;
  1041. + break;
  1042. + case SPEED_100:
  1043. + pll_val = pll_data->pll_100;
  1044. + break;
  1045. + case SPEED_1000:
  1046. + pll_val = pll_data->pll_1000;
  1047. + break;
  1048. + default:
  1049. + BUG();
  1050. + }
  1051. +
  1052. + return pll_val;
  1053. +}
  1054. +
  1055. +static void ar71xx_set_pll_ge0(int speed)
  1056. +{
  1057. + u32 val = ar71xx_get_eth_pll(0, speed);
  1058. +
  1059. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH0_INT_CLOCK,
  1060. + val, AR71XX_ETH0_PLL_SHIFT);
  1061. +}
  1062. +
  1063. +static void ar71xx_set_pll_ge1(int speed)
  1064. +{
  1065. + u32 val = ar71xx_get_eth_pll(1, speed);
  1066. +
  1067. + ar71xx_set_pll(AR71XX_PLL_REG_SEC_CONFIG, AR71XX_PLL_REG_ETH1_INT_CLOCK,
  1068. + val, AR71XX_ETH1_PLL_SHIFT);
  1069. +}
  1070. +
  1071. +static void ar724x_set_pll_ge0(int speed)
  1072. +{
  1073. + /* TODO */
  1074. +}
  1075. +
  1076. +static void ar724x_set_pll_ge1(int speed)
  1077. +{
  1078. + /* TODO */
  1079. +}
  1080. +
  1081. +static void ar91xx_set_pll_ge0(int speed)
  1082. +{
  1083. + u32 val = ar71xx_get_eth_pll(0, speed);
  1084. +
  1085. + ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG, AR91XX_PLL_REG_ETH0_INT_CLOCK,
  1086. + val, AR91XX_ETH0_PLL_SHIFT);
  1087. +}
  1088. +
  1089. +static void ar91xx_set_pll_ge1(int speed)
  1090. +{
  1091. + u32 val = ar71xx_get_eth_pll(1, speed);
  1092. +
  1093. + ar71xx_set_pll(AR91XX_PLL_REG_ETH_CONFIG, AR91XX_PLL_REG_ETH1_INT_CLOCK,
  1094. + val, AR91XX_ETH1_PLL_SHIFT);
  1095. +}
  1096. +
  1097. +static void ar71xx_ddr_flush_ge0(void)
  1098. +{
  1099. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE0);
  1100. +}
  1101. +
  1102. +static void ar71xx_ddr_flush_ge1(void)
  1103. +{
  1104. + ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_GE1);
  1105. +}
  1106. +
  1107. +static void ar724x_ddr_flush_ge0(void)
  1108. +{
  1109. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE0);
  1110. +}
  1111. +
  1112. +static void ar724x_ddr_flush_ge1(void)
  1113. +{
  1114. + ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE1);
  1115. +}
  1116. +
  1117. +static void ar91xx_ddr_flush_ge0(void)
  1118. +{
  1119. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0);
  1120. +}
  1121. +
  1122. +static void ar91xx_ddr_flush_ge1(void)
  1123. +{
  1124. + ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1);
  1125. +}
  1126. +
  1127. +static struct resource ar71xx_eth0_resources[] = {
  1128. + {
  1129. + .name = "mac_base",
  1130. + .flags = IORESOURCE_MEM,
  1131. + .start = AR71XX_GE0_BASE,
  1132. + .end = AR71XX_GE0_BASE + 0x200 - 1,
  1133. + }, {
  1134. + .name = "mii_ctrl",
  1135. + .flags = IORESOURCE_MEM,
  1136. + .start = AR71XX_MII_BASE + MII_REG_MII0_CTRL,
  1137. + .end = AR71XX_MII_BASE + MII_REG_MII0_CTRL + 3,
  1138. + }, {
  1139. + .name = "mac_irq",
  1140. + .flags = IORESOURCE_IRQ,
  1141. + .start = AR71XX_CPU_IRQ_GE0,
  1142. + .end = AR71XX_CPU_IRQ_GE0,
  1143. + },
  1144. +};
  1145. +
  1146. +struct ag71xx_platform_data ar71xx_eth0_data = {
  1147. + .reset_bit = RESET_MODULE_GE0_MAC,
  1148. +};
  1149. +
  1150. +struct platform_device ar71xx_eth0_device = {
  1151. + .name = "ag71xx",
  1152. + .id = 0,
  1153. + .resource = ar71xx_eth0_resources,
  1154. + .num_resources = ARRAY_SIZE(ar71xx_eth0_resources),
  1155. + .dev = {
  1156. + .platform_data = &ar71xx_eth0_data,
  1157. + },
  1158. +};
  1159. +
  1160. +static struct resource ar71xx_eth1_resources[] = {
  1161. + {
  1162. + .name = "mac_base",
  1163. + .flags = IORESOURCE_MEM,
  1164. + .start = AR71XX_GE1_BASE,
  1165. + .end = AR71XX_GE1_BASE + 0x200 - 1,
  1166. + }, {
  1167. + .name = "mii_ctrl",
  1168. + .flags = IORESOURCE_MEM,
  1169. + .start = AR71XX_MII_BASE + MII_REG_MII1_CTRL,
  1170. + .end = AR71XX_MII_BASE + MII_REG_MII1_CTRL + 3,
  1171. + }, {
  1172. + .name = "mac_irq",
  1173. + .flags = IORESOURCE_IRQ,
  1174. + .start = AR71XX_CPU_IRQ_GE1,
  1175. + .end = AR71XX_CPU_IRQ_GE1,
  1176. + },
  1177. +};
  1178. +
  1179. +struct ag71xx_platform_data ar71xx_eth1_data = {
  1180. + .reset_bit = RESET_MODULE_GE1_MAC,
  1181. +};
  1182. +
  1183. +struct platform_device ar71xx_eth1_device = {
  1184. + .name = "ag71xx",
  1185. + .id = 1,
  1186. + .resource = ar71xx_eth1_resources,
  1187. + .num_resources = ARRAY_SIZE(ar71xx_eth1_resources),
  1188. + .dev = {
  1189. + .platform_data = &ar71xx_eth1_data,
  1190. + },
  1191. +};
  1192. +
  1193. +#define AR71XX_PLL_VAL_1000 0x00110000
  1194. +#define AR71XX_PLL_VAL_100 0x00001099
  1195. +#define AR71XX_PLL_VAL_10 0x00991099
  1196. +
  1197. +#define AR724X_PLL_VAL_1000 0x00110000
  1198. +#define AR724X_PLL_VAL_100 0x00001099
  1199. +#define AR724X_PLL_VAL_10 0x00991099
  1200. +
  1201. +#define AR91XX_PLL_VAL_1000 0x1a000000
  1202. +#define AR91XX_PLL_VAL_100 0x13000a44
  1203. +#define AR91XX_PLL_VAL_10 0x00441099
  1204. +
  1205. +static void __init ar71xx_init_eth_pll_data(unsigned int id)
  1206. +{
  1207. + struct ar71xx_eth_pll_data *pll_data;
  1208. + u32 pll_10, pll_100, pll_1000;
  1209. +
  1210. + switch (id) {
  1211. + case 0:
  1212. + pll_data = &ar71xx_eth0_pll_data;
  1213. + break;
  1214. + case 1:
  1215. + pll_data = &ar71xx_eth1_pll_data;
  1216. + break;
  1217. + default:
  1218. + BUG();
  1219. + }
  1220. +
  1221. + switch (ar71xx_soc) {
  1222. + case AR71XX_SOC_AR7130:
  1223. + case AR71XX_SOC_AR7141:
  1224. + case AR71XX_SOC_AR7161:
  1225. + pll_10 = AR71XX_PLL_VAL_10;
  1226. + pll_100 = AR71XX_PLL_VAL_100;
  1227. + pll_1000 = AR71XX_PLL_VAL_1000;
  1228. + break;
  1229. +
  1230. + case AR71XX_SOC_AR7240:
  1231. + case AR71XX_SOC_AR7241:
  1232. + case AR71XX_SOC_AR7242:
  1233. + pll_10 = AR724X_PLL_VAL_10;
  1234. + pll_100 = AR724X_PLL_VAL_100;
  1235. + pll_1000 = AR724X_PLL_VAL_1000;
  1236. + break;
  1237. +
  1238. + case AR71XX_SOC_AR9130:
  1239. + case AR71XX_SOC_AR9132:
  1240. + pll_10 = AR91XX_PLL_VAL_10;
  1241. + pll_100 = AR91XX_PLL_VAL_100;
  1242. + pll_1000 = AR91XX_PLL_VAL_1000;
  1243. + break;
  1244. + default:
  1245. + BUG();
  1246. + }
  1247. +
  1248. + if (!pll_data->pll_10)
  1249. + pll_data->pll_10 = pll_10;
  1250. +
  1251. + if (!pll_data->pll_100)
  1252. + pll_data->pll_100 = pll_100;
  1253. +
  1254. + if (!pll_data->pll_1000)
  1255. + pll_data->pll_1000 = pll_1000;
  1256. +}
  1257. +
  1258. +static int ar71xx_eth_instance __initdata;
  1259. +void __init ar71xx_add_device_eth(unsigned int id)
  1260. +{
  1261. + struct platform_device *pdev;
  1262. + struct ag71xx_platform_data *pdata;
  1263. +
  1264. + ar71xx_init_eth_pll_data(id);
  1265. +
  1266. + switch (id) {
  1267. + case 0:
  1268. + switch (ar71xx_eth0_data.phy_if_mode) {
  1269. + case PHY_INTERFACE_MODE_MII:
  1270. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_MII;
  1271. + break;
  1272. + case PHY_INTERFACE_MODE_GMII:
  1273. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_GMII;
  1274. + break;
  1275. + case PHY_INTERFACE_MODE_RGMII:
  1276. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RGMII;
  1277. + break;
  1278. + case PHY_INTERFACE_MODE_RMII:
  1279. + ar71xx_eth0_data.mii_if = MII0_CTRL_IF_RMII;
  1280. + break;
  1281. + default:
  1282. + printk(KERN_ERR "ar71xx: invalid PHY interface mode "
  1283. + "for eth0\n");
  1284. + return;
  1285. + }
  1286. + pdev = &ar71xx_eth0_device;
  1287. + break;
  1288. + case 1:
  1289. + switch (ar71xx_eth1_data.phy_if_mode) {
  1290. + case PHY_INTERFACE_MODE_RMII:
  1291. + ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RMII;
  1292. + break;
  1293. + case PHY_INTERFACE_MODE_RGMII:
  1294. + ar71xx_eth1_data.mii_if = MII1_CTRL_IF_RGMII;
  1295. + break;
  1296. + default:
  1297. + printk(KERN_ERR "ar71xx: invalid PHY interface mode "
  1298. + "for eth1\n");
  1299. + return;
  1300. + }
  1301. + pdev = &ar71xx_eth1_device;
  1302. + break;
  1303. + default:
  1304. + printk(KERN_ERR "ar71xx: invalid ethernet id %d\n", id);
  1305. + return;
  1306. + }
  1307. +
  1308. + pdata = pdev->dev.platform_data;
  1309. +
  1310. + switch (ar71xx_soc) {
  1311. + case AR71XX_SOC_AR7130:
  1312. + pdata->ddr_flush = id ? ar71xx_ddr_flush_ge1
  1313. + : ar71xx_ddr_flush_ge0;
  1314. + pdata->set_pll = id ? ar71xx_set_pll_ge1
  1315. + : ar71xx_set_pll_ge0;
  1316. + break;
  1317. +
  1318. + case AR71XX_SOC_AR7141:
  1319. + case AR71XX_SOC_AR7161:
  1320. + pdata->ddr_flush = id ? ar71xx_ddr_flush_ge1
  1321. + : ar71xx_ddr_flush_ge0;
  1322. + pdata->set_pll = id ? ar71xx_set_pll_ge1
  1323. + : ar71xx_set_pll_ge0;
  1324. + pdata->has_gbit = 1;
  1325. + break;
  1326. +
  1327. + case AR71XX_SOC_AR7241:
  1328. + case AR71XX_SOC_AR7242:
  1329. + ar71xx_eth0_data.reset_bit |= AR724X_RESET_GE0_MDIO;
  1330. + ar71xx_eth1_data.reset_bit |= AR724X_RESET_GE1_MDIO;
  1331. + /* fall through */
  1332. + case AR71XX_SOC_AR7240:
  1333. + pdata->ddr_flush = id ? ar724x_ddr_flush_ge1
  1334. + : ar724x_ddr_flush_ge0;
  1335. + pdata->set_pll = id ? ar724x_set_pll_ge1
  1336. + : ar724x_set_pll_ge0;
  1337. + pdata->is_ar724x = 1;
  1338. + break;
  1339. +
  1340. + case AR71XX_SOC_AR9130:
  1341. + pdata->ddr_flush = id ? ar91xx_ddr_flush_ge1
  1342. + : ar91xx_ddr_flush_ge0;
  1343. + pdata->set_pll = id ? ar91xx_set_pll_ge1
  1344. + : ar91xx_set_pll_ge0;
  1345. + pdata->is_ar91xx = 1;
  1346. + break;
  1347. +
  1348. + case AR71XX_SOC_AR9132:
  1349. + pdata->ddr_flush = id ? ar91xx_ddr_flush_ge1
  1350. + : ar91xx_ddr_flush_ge0;
  1351. + pdata->set_pll = id ? ar91xx_set_pll_ge1
  1352. + : ar91xx_set_pll_ge0;
  1353. + pdata->is_ar91xx = 1;
  1354. + pdata->has_gbit = 1;
  1355. + break;
  1356. +
  1357. + default:
  1358. + BUG();
  1359. + }
  1360. +
  1361. + switch (pdata->phy_if_mode) {
  1362. + case PHY_INTERFACE_MODE_GMII:
  1363. + case PHY_INTERFACE_MODE_RGMII:
  1364. + if (!pdata->has_gbit) {
  1365. + printk(KERN_ERR "ar71xx: no gbit available on eth%d\n",
  1366. + id);
  1367. + return;
  1368. + }
  1369. + /* fallthrough */
  1370. + default:
  1371. + break;
  1372. + }
  1373. +
  1374. + if (is_valid_ether_addr(ar71xx_mac_base)) {
  1375. + memcpy(pdata->mac_addr, ar71xx_mac_base, ETH_ALEN);
  1376. + pdata->mac_addr[5] += ar71xx_eth_instance;
  1377. + } else {
  1378. + random_ether_addr(pdata->mac_addr);
  1379. + printk(KERN_DEBUG
  1380. + "ar71xx: using random MAC address for eth%d\n",
  1381. + ar71xx_eth_instance);
  1382. + }
  1383. +
  1384. + if (pdata->mii_bus_dev == NULL)
  1385. + pdata->mii_bus_dev = &ar71xx_mdio_device.dev;
  1386. +
  1387. + /* Reset the device */
  1388. + ar71xx_device_stop(pdata->reset_bit);
  1389. + mdelay(100);
  1390. +
  1391. + ar71xx_device_start(pdata->reset_bit);
  1392. + mdelay(100);
  1393. +
  1394. + platform_device_register(pdev);
  1395. + ar71xx_eth_instance++;
  1396. +}
  1397. +
  1398. +static struct resource ar71xx_spi_resources[] = {
  1399. + [0] = {
  1400. + .start = AR71XX_SPI_BASE,
  1401. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  1402. + .flags = IORESOURCE_MEM,
  1403. + },
  1404. +};
  1405. +
  1406. +static struct platform_device ar71xx_spi_device = {
  1407. + .name = "ar71xx-spi",
  1408. + .id = -1,
  1409. + .resource = ar71xx_spi_resources,
  1410. + .num_resources = ARRAY_SIZE(ar71xx_spi_resources),
  1411. +};
  1412. +
  1413. +void __init ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
  1414. + struct spi_board_info const *info,
  1415. + unsigned n)
  1416. +{
  1417. + spi_register_board_info(info, n);
  1418. + ar71xx_spi_device.dev.platform_data = pdata;
  1419. + platform_device_register(&ar71xx_spi_device);
  1420. +}
  1421. +
  1422. +void __init ar71xx_add_device_wdt(void)
  1423. +{
  1424. + platform_device_register_simple("ar71xx-wdt", -1, NULL, 0);
  1425. +}
  1426. +
  1427. +void __init ar71xx_set_mac_base(unsigned char *mac)
  1428. +{
  1429. + memcpy(ar71xx_mac_base, mac, ETH_ALEN);
  1430. +}
  1431. +
  1432. +void __init ar71xx_parse_mac_addr(char *mac_str)
  1433. +{
  1434. + u8 tmp[ETH_ALEN];
  1435. + int t;
  1436. +
  1437. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  1438. + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
  1439. +
  1440. + if (t != ETH_ALEN)
  1441. + t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
  1442. + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
  1443. +
  1444. + if (t == ETH_ALEN)
  1445. + ar71xx_set_mac_base(tmp);
  1446. + else
  1447. + printk(KERN_DEBUG "ar71xx: failed to parse mac address "
  1448. + "\"%s\"\n", mac_str);
  1449. +}
  1450. +
  1451. +static int __init ar71xx_ethaddr_setup(char *str)
  1452. +{
  1453. + ar71xx_parse_mac_addr(str);
  1454. + return 1;
  1455. +}
  1456. +__setup("ethaddr=", ar71xx_ethaddr_setup);
  1457. +
  1458. +static int __init ar71xx_kmac_setup(char *str)
  1459. +{
  1460. + ar71xx_parse_mac_addr(str);
  1461. + return 1;
  1462. +}
  1463. +__setup("kmac=", ar71xx_kmac_setup);
  1464. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/devices.h linux-2.6.33.3/arch/mips/ar71xx/devices.h
  1465. --- linux-2.6.33.3.orig/arch/mips/ar71xx/devices.h 1970-01-01 01:00:00.000000000 +0100
  1466. +++ linux-2.6.33.3/arch/mips/ar71xx/devices.h 2010-01-05 20:38:52.093279648 +0100
  1467. @@ -0,0 +1,48 @@
  1468. +/*
  1469. + * Atheros AR71xx SoC device definitions
  1470. + *
  1471. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1472. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1473. + *
  1474. + * This program is free software; you can redistribute it and/or modify it
  1475. + * under the terms of the GNU General Public License version 2 as published
  1476. + * by the Free Software Foundation.
  1477. + */
  1478. +
  1479. +#ifndef __AR71XX_DEVICES_H
  1480. +#define __AR71XX_DEVICES_H
  1481. +
  1482. +#include <asm/mach-ar71xx/platform.h>
  1483. +
  1484. +struct platform_device;
  1485. +
  1486. +void ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
  1487. + struct spi_board_info const *info,
  1488. + unsigned n) __init;
  1489. +
  1490. +void ar71xx_set_mac_base(unsigned char *mac) __init;
  1491. +void ar71xx_parse_mac_addr(char *mac_str) __init;
  1492. +
  1493. +struct ar71xx_eth_pll_data {
  1494. + u32 pll_10;
  1495. + u32 pll_100;
  1496. + u32 pll_1000;
  1497. +};
  1498. +
  1499. +extern struct ar71xx_eth_pll_data ar71xx_eth0_pll_data;
  1500. +extern struct ar71xx_eth_pll_data ar71xx_eth1_pll_data;
  1501. +
  1502. +extern struct ag71xx_platform_data ar71xx_eth0_data;
  1503. +extern struct ag71xx_platform_data ar71xx_eth1_data;
  1504. +extern struct platform_device ar71xx_eth0_device;
  1505. +extern struct platform_device ar71xx_eth1_device;
  1506. +void ar71xx_add_device_eth(unsigned int id) __init;
  1507. +
  1508. +extern struct platform_device ar71xx_mdio_device;
  1509. +void ar71xx_add_device_mdio(u32 phy_mask) __init;
  1510. +
  1511. +void ar71xx_add_device_uart(void) __init;
  1512. +
  1513. +void ar71xx_add_device_wdt(void) __init;
  1514. +
  1515. +#endif /* __AR71XX_DEVICES_H */
  1516. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-leds-gpio.c linux-2.6.33.3/arch/mips/ar71xx/dev-leds-gpio.c
  1517. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-leds-gpio.c 1970-01-01 01:00:00.000000000 +0100
  1518. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-leds-gpio.c 2010-01-05 20:38:51.933280770 +0100
  1519. @@ -0,0 +1,56 @@
  1520. +/*
  1521. + * Atheros AR71xx GPIO LED device support
  1522. + *
  1523. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1524. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1525. + *
  1526. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1527. + *
  1528. + * This program is free software; you can redistribute it and/or modify it
  1529. + * under the terms of the GNU General Public License version 2 as published
  1530. + * by the Free Software Foundation.
  1531. + */
  1532. +
  1533. +#include <linux/init.h>
  1534. +#include <linux/platform_device.h>
  1535. +
  1536. +#include "dev-leds-gpio.h"
  1537. +
  1538. +void __init ar71xx_add_device_leds_gpio(int id, unsigned num_leds,
  1539. + struct gpio_led *leds)
  1540. +{
  1541. + struct platform_device *pdev;
  1542. + struct gpio_led_platform_data pdata;
  1543. + struct gpio_led *p;
  1544. + int err;
  1545. +
  1546. + p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
  1547. + if (!p)
  1548. + return;
  1549. +
  1550. + memcpy(p, leds, num_leds * sizeof(*p));
  1551. +
  1552. + pdev = platform_device_alloc("leds-gpio", id);
  1553. + if (!pdev)
  1554. + goto err_free_leds;
  1555. +
  1556. + memset(&pdata, 0, sizeof(pdata));
  1557. + pdata.num_leds = num_leds;
  1558. + pdata.leds = p;
  1559. +
  1560. + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  1561. + if (err)
  1562. + goto err_put_pdev;
  1563. +
  1564. + err = platform_device_add(pdev);
  1565. + if (err)
  1566. + goto err_put_pdev;
  1567. +
  1568. + return;
  1569. +
  1570. +err_put_pdev:
  1571. + platform_device_put(pdev);
  1572. +
  1573. +err_free_leds:
  1574. + kfree(p);
  1575. +}
  1576. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-leds-gpio.h linux-2.6.33.3/arch/mips/ar71xx/dev-leds-gpio.h
  1577. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-leds-gpio.h 1970-01-01 01:00:00.000000000 +0100
  1578. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-leds-gpio.h 2010-01-05 20:38:51.937279883 +0100
  1579. @@ -0,0 +1,21 @@
  1580. +/*
  1581. + * Atheros AR71xx GPIO LED device support
  1582. + *
  1583. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1584. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1585. + *
  1586. + * This program is free software; you can redistribute it and/or modify it
  1587. + * under the terms of the GNU General Public License version 2 as published
  1588. + * by the Free Software Foundation.
  1589. + */
  1590. +
  1591. +#ifndef _AR71XX_DEV_LEDS_GPIO_H
  1592. +#define _AR71XX_DEV_LEDS_GPIO_H
  1593. +
  1594. +#include <linux/leds.h>
  1595. +
  1596. +void ar71xx_add_device_leds_gpio(int id,
  1597. + unsigned num_leds,
  1598. + struct gpio_led *leds) __init;
  1599. +
  1600. +#endif /* _AR71XX_DEV_LEDS_GPIO_H */
  1601. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-m25p80.c linux-2.6.33.3/arch/mips/ar71xx/dev-m25p80.c
  1602. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-m25p80.c 1970-01-01 01:00:00.000000000 +0100
  1603. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-m25p80.c 2009-12-25 12:10:59.660426865 +0100
  1604. @@ -0,0 +1,30 @@
  1605. +/*
  1606. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1607. + *
  1608. + * This program is free software; you can redistribute it and/or modify it
  1609. + * under the terms of the GNU General Public License version 2 as published
  1610. + * by the Free Software Foundation.
  1611. + */
  1612. +
  1613. +#include <linux/init.h>
  1614. +#include <linux/spi/spi.h>
  1615. +#include <linux/spi/flash.h>
  1616. +
  1617. +#include "devices.h"
  1618. +#include "dev-m25p80.h"
  1619. +
  1620. +static struct spi_board_info ar71xx_spi_info[] = {
  1621. + {
  1622. + .bus_num = 0,
  1623. + .chip_select = 0,
  1624. + .max_speed_hz = 25000000,
  1625. + .modalias = "m25p80",
  1626. + }
  1627. +};
  1628. +
  1629. +void __init ar71xx_add_device_m25p80(struct flash_platform_data *pdata)
  1630. +{
  1631. + ar71xx_spi_info[0].platform_data = pdata;
  1632. + ar71xx_add_device_spi(NULL, ar71xx_spi_info,
  1633. + ARRAY_SIZE(ar71xx_spi_info));
  1634. +}
  1635. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-m25p80.h linux-2.6.33.3/arch/mips/ar71xx/dev-m25p80.h
  1636. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-m25p80.h 1970-01-01 01:00:00.000000000 +0100
  1637. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-m25p80.h 2009-12-25 12:10:59.660426865 +0100
  1638. @@ -0,0 +1,16 @@
  1639. +/*
  1640. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1641. + *
  1642. + * This program is free software; you can redistribute it and/or modify it
  1643. + * under the terms of the GNU General Public License version 2 as published
  1644. + * by the Free Software Foundation.
  1645. + */
  1646. +
  1647. +#ifndef _AR71XX_DEV_M25P80_H
  1648. +#define _AR71XX_DEV_M25P80_H
  1649. +
  1650. +#include <linux/spi/flash.h>
  1651. +
  1652. +void ar71xx_add_device_m25p80(struct flash_platform_data *pdata) __init;
  1653. +
  1654. +#endif /* _AR71XX_DEV_M25P80_H */
  1655. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb42-pci.c linux-2.6.33.3/arch/mips/ar71xx/dev-pb42-pci.c
  1656. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb42-pci.c 1970-01-01 01:00:00.000000000 +0100
  1657. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-pb42-pci.c 2010-01-05 20:38:52.185278525 +0100
  1658. @@ -0,0 +1,40 @@
  1659. +/*
  1660. + * Atheros PB42 reference board PCI initialization
  1661. + *
  1662. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1663. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1664. + *
  1665. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1666. + *
  1667. + * This program is free software; you can redistribute it and/or modify it
  1668. + * under the terms of the GNU General Public License version 2 as published
  1669. + * by the Free Software Foundation.
  1670. + */
  1671. +
  1672. +#include <linux/pci.h>
  1673. +
  1674. +#include <asm/mach-ar71xx/ar71xx.h>
  1675. +#include <asm/mach-ar71xx/pci.h>
  1676. +
  1677. +#include "dev-pb42-pci.h"
  1678. +
  1679. +static struct ar71xx_pci_irq pb42_pci_irqs[] __initdata = {
  1680. + {
  1681. + .slot = 0,
  1682. + .pin = 1,
  1683. + .irq = AR71XX_PCI_IRQ_DEV0,
  1684. + }, {
  1685. + .slot = 1,
  1686. + .pin = 1,
  1687. + .irq = AR71XX_PCI_IRQ_DEV1,
  1688. + }, {
  1689. + .slot = 2,
  1690. + .pin = 1,
  1691. + .irq = AR71XX_PCI_IRQ_DEV2,
  1692. + }
  1693. +};
  1694. +
  1695. +void __init pb42_pci_init(void)
  1696. +{
  1697. + ar71xx_pci_init(ARRAY_SIZE(pb42_pci_irqs), pb42_pci_irqs);
  1698. +}
  1699. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb42-pci.h linux-2.6.33.3/arch/mips/ar71xx/dev-pb42-pci.h
  1700. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb42-pci.h 1970-01-01 01:00:00.000000000 +0100
  1701. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-pb42-pci.h 2010-01-05 20:38:52.217277854 +0100
  1702. @@ -0,0 +1,21 @@
  1703. +/*
  1704. + * Atheros PB42 reference board PCI initialization
  1705. + *
  1706. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1707. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1708. + *
  1709. + * This program is free software; you can redistribute it and/or modify it
  1710. + * under the terms of the GNU General Public License version 2 as published
  1711. + * by the Free Software Foundation.
  1712. + */
  1713. +
  1714. +#ifndef _AR71XX_DEV_PB42_PCI_H
  1715. +#define _AR71XX_DEV_PB42_PCI_H
  1716. +
  1717. +#if defined(CONFIG_AR71XX_DEV_PB42_PCI)
  1718. +void pb42_pci_init(void) __init;
  1719. +#else
  1720. +static inline void pb42_pci_init(void) { }
  1721. +#endif
  1722. +
  1723. +#endif /* _AR71XX_DEV_PB42_PCI_H */
  1724. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb9x-pci.c linux-2.6.33.3/arch/mips/ar71xx/dev-pb9x-pci.c
  1725. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb9x-pci.c 1970-01-01 01:00:00.000000000 +0100
  1726. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-pb9x-pci.c 2010-04-02 11:07:51.650955594 +0200
  1727. @@ -0,0 +1,33 @@
  1728. +/*
  1729. + * Atheros PB9x reference board PCI initialization
  1730. + *
  1731. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1732. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1733. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1734. + *
  1735. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1736. + *
  1737. + * This program is free software; you can redistribute it and/or modify it
  1738. + * under the terms of the GNU General Public License version 2 as published
  1739. + * by the Free Software Foundation.
  1740. + */
  1741. +
  1742. +#include <linux/pci.h>
  1743. +
  1744. +#include <asm/mach-ar71xx/ar71xx.h>
  1745. +#include <asm/mach-ar71xx/pci.h>
  1746. +
  1747. +#include "dev-pb9x-pci.h"
  1748. +
  1749. +static struct ar71xx_pci_irq pb9x_pci_irqs[] __initdata = {
  1750. + {
  1751. + .slot = 0,
  1752. + .pin = 1,
  1753. + .irq = AR71XX_PCI_IRQ_DEV0,
  1754. + }
  1755. +};
  1756. +
  1757. +void __init pb9x_pci_init(void)
  1758. +{
  1759. + ar71xx_pci_init(ARRAY_SIZE(pb9x_pci_irqs), pb9x_pci_irqs);
  1760. +}
  1761. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb9x-pci.h linux-2.6.33.3/arch/mips/ar71xx/dev-pb9x-pci.h
  1762. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-pb9x-pci.h 1970-01-01 01:00:00.000000000 +0100
  1763. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-pb9x-pci.h 2010-04-02 11:07:51.654953031 +0200
  1764. @@ -0,0 +1,22 @@
  1765. +/*
  1766. + * Atheros PB9x reference board PCI initialization
  1767. + *
  1768. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1769. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1770. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1771. + *
  1772. + * This program is free software; you can redistribute it and/or modify it
  1773. + * under the terms of the GNU General Public License version 2 as published
  1774. + * by the Free Software Foundation.
  1775. + */
  1776. +
  1777. +#ifndef _AR71XX_DEV_PB9X_PCI_H
  1778. +#define _AR71XX_DEV_PB9X_PCI_H
  1779. +
  1780. +#if defined(CONFIG_AR71XX_DEV_PB9X_PCI)
  1781. +void pb9x_pci_init(void) __init;
  1782. +#else
  1783. +static inline void pb9x_pci_init(void) { }
  1784. +#endif
  1785. +
  1786. +#endif /* _AR71XX_DEV_PB9X_PCI_H */
  1787. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-usb.c linux-2.6.33.3/arch/mips/ar71xx/dev-usb.c
  1788. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-usb.c 1970-01-01 01:00:00.000000000 +0100
  1789. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-usb.c 2010-04-02 11:07:51.694953375 +0200
  1790. @@ -0,0 +1,181 @@
  1791. +/*
  1792. + * Atheros AR71xx USB host device support
  1793. + *
  1794. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1795. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1796. + *
  1797. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1798. + *
  1799. + * This program is free software; you can redistribute it and/or modify it
  1800. + * under the terms of the GNU General Public License version 2 as published
  1801. + * by the Free Software Foundation.
  1802. + */
  1803. +
  1804. +#include <linux/kernel.h>
  1805. +#include <linux/init.h>
  1806. +#include <linux/delay.h>
  1807. +#include <linux/dma-mapping.h>
  1808. +#include <linux/platform_device.h>
  1809. +
  1810. +#include <asm/mach-ar71xx/ar71xx.h>
  1811. +#include <asm/mach-ar71xx/platform.h>
  1812. +
  1813. +#include "dev-usb.h"
  1814. +
  1815. +/*
  1816. + * OHCI (USB full speed host controller)
  1817. + */
  1818. +static struct resource ar71xx_ohci_resources[] = {
  1819. + [0] = {
  1820. + .start = AR71XX_OHCI_BASE,
  1821. + .end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1,
  1822. + .flags = IORESOURCE_MEM,
  1823. + },
  1824. + [1] = {
  1825. + .start = AR71XX_MISC_IRQ_OHCI,
  1826. + .end = AR71XX_MISC_IRQ_OHCI,
  1827. + .flags = IORESOURCE_IRQ,
  1828. + },
  1829. +};
  1830. +
  1831. +static struct resource ar7240_ohci_resources[] = {
  1832. + [0] = {
  1833. + .start = AR7240_OHCI_BASE,
  1834. + .end = AR7240_OHCI_BASE + AR7240_OHCI_SIZE - 1,
  1835. + .flags = IORESOURCE_MEM,
  1836. + },
  1837. + [1] = {
  1838. + .start = AR71XX_CPU_IRQ_USB,
  1839. + .end = AR71XX_CPU_IRQ_USB,
  1840. + .flags = IORESOURCE_IRQ,
  1841. + },
  1842. +};
  1843. +
  1844. +static u64 ar71xx_ohci_dmamask = DMA_BIT_MASK(32);
  1845. +static struct platform_device ar71xx_ohci_device = {
  1846. + .name = "ar71xx-ohci",
  1847. + .id = -1,
  1848. + .resource = ar71xx_ohci_resources,
  1849. + .num_resources = ARRAY_SIZE(ar71xx_ohci_resources),
  1850. + .dev = {
  1851. + .dma_mask = &ar71xx_ohci_dmamask,
  1852. + .coherent_dma_mask = DMA_BIT_MASK(32),
  1853. + },
  1854. +};
  1855. +
  1856. +/*
  1857. + * EHCI (USB full speed host controller)
  1858. + */
  1859. +static struct resource ar71xx_ehci_resources[] = {
  1860. + [0] = {
  1861. + .start = AR71XX_EHCI_BASE,
  1862. + .end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1,
  1863. + .flags = IORESOURCE_MEM,
  1864. + },
  1865. + [1] = {
  1866. + .start = AR71XX_CPU_IRQ_USB,
  1867. + .end = AR71XX_CPU_IRQ_USB,
  1868. + .flags = IORESOURCE_IRQ,
  1869. + },
  1870. +};
  1871. +
  1872. +static u64 ar71xx_ehci_dmamask = DMA_BIT_MASK(32);
  1873. +static struct ar71xx_ehci_platform_data ar71xx_ehci_data;
  1874. +
  1875. +static struct platform_device ar71xx_ehci_device = {
  1876. + .name = "ar71xx-ehci",
  1877. + .id = -1,
  1878. + .resource = ar71xx_ehci_resources,
  1879. + .num_resources = ARRAY_SIZE(ar71xx_ehci_resources),
  1880. + .dev = {
  1881. + .dma_mask = &ar71xx_ehci_dmamask,
  1882. + .coherent_dma_mask = DMA_BIT_MASK(32),
  1883. + .platform_data = &ar71xx_ehci_data,
  1884. + },
  1885. +};
  1886. +
  1887. +#define AR71XX_USB_RESET_MASK \
  1888. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_PHY \
  1889. + | RESET_MODULE_USB_OHCI_DLL)
  1890. +
  1891. +#define AR7240_USB_RESET_MASK \
  1892. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_OHCI_DLL_7240)
  1893. +
  1894. +static void __init ar71xx_usb_setup(void)
  1895. +{
  1896. + ar71xx_device_stop(AR71XX_USB_RESET_MASK);
  1897. + mdelay(1000);
  1898. + ar71xx_device_start(AR71XX_USB_RESET_MASK);
  1899. +
  1900. + /* Turning on the Buff and Desc swap bits */
  1901. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_CONFIG, 0xf0000);
  1902. +
  1903. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  1904. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x20c00);
  1905. +
  1906. + mdelay(900);
  1907. +
  1908. + platform_device_register(&ar71xx_ohci_device);
  1909. + platform_device_register(&ar71xx_ehci_device);
  1910. +}
  1911. +
  1912. +static void __init ar7240_usb_setup(void)
  1913. +{
  1914. + ar71xx_device_stop(AR7240_USB_RESET_MASK);
  1915. + mdelay(1000);
  1916. + ar71xx_device_start(AR7240_USB_RESET_MASK);
  1917. +
  1918. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  1919. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x3);
  1920. +
  1921. + if (ar71xx_soc == AR71XX_SOC_AR7241 || ar71xx_soc == AR71XX_SOC_AR7242) {
  1922. + ar71xx_ehci_data.is_ar91xx = 1;
  1923. + ar71xx_ehci_device.resource = ar7240_ohci_resources;
  1924. + ar71xx_ehci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  1925. + platform_device_register(&ar71xx_ehci_device);
  1926. + } else {
  1927. + ar71xx_ohci_device.resource = ar7240_ohci_resources;
  1928. + ar71xx_ohci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  1929. + platform_device_register(&ar71xx_ohci_device);
  1930. + }
  1931. +}
  1932. +
  1933. +static void __init ar91xx_usb_setup(void)
  1934. +{
  1935. + ar71xx_device_stop(RESET_MODULE_USBSUS_OVERRIDE);
  1936. + mdelay(10);
  1937. +
  1938. + ar71xx_device_start(RESET_MODULE_USB_HOST);
  1939. + mdelay(10);
  1940. +
  1941. + ar71xx_device_start(RESET_MODULE_USB_PHY);
  1942. + mdelay(10);
  1943. +
  1944. + ar71xx_ehci_data.is_ar91xx = 1;
  1945. + platform_device_register(&ar71xx_ehci_device);
  1946. +}
  1947. +
  1948. +void __init ar71xx_add_device_usb(void)
  1949. +{
  1950. + switch (ar71xx_soc) {
  1951. + case AR71XX_SOC_AR7240:
  1952. + case AR71XX_SOC_AR7241:
  1953. + case AR71XX_SOC_AR7242:
  1954. + ar7240_usb_setup();
  1955. + break;
  1956. +
  1957. + case AR71XX_SOC_AR7130:
  1958. + case AR71XX_SOC_AR7141:
  1959. + case AR71XX_SOC_AR7161:
  1960. + ar71xx_usb_setup();
  1961. + break;
  1962. +
  1963. + case AR71XX_SOC_AR9130:
  1964. + case AR71XX_SOC_AR9132:
  1965. + ar91xx_usb_setup();
  1966. + break;
  1967. +
  1968. + default:
  1969. + BUG();
  1970. + }
  1971. +}
  1972. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/dev-usb.h linux-2.6.33.3/arch/mips/ar71xx/dev-usb.h
  1973. --- linux-2.6.33.3.orig/arch/mips/ar71xx/dev-usb.h 1970-01-01 01:00:00.000000000 +0100
  1974. +++ linux-2.6.33.3/arch/mips/ar71xx/dev-usb.h 2010-01-05 20:38:52.326200390 +0100
  1975. @@ -0,0 +1,17 @@
  1976. +/*
  1977. + * Atheros AR71xx USB host device support
  1978. + *
  1979. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1980. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1981. + *
  1982. + * This program is free software; you can redistribute it and/or modify it
  1983. + * under the terms of the GNU General Public License version 2 as published
  1984. + * by the Free Software Foundation.
  1985. + */
  1986. +
  1987. +#ifndef _AR71XX_DEV_USB_H
  1988. +#define _AR71XX_DEV_USB_H
  1989. +
  1990. +void ar71xx_add_device_usb(void) __init;
  1991. +
  1992. +#endif /* _AR71XX_DEV_USB_H */
  1993. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/early_printk.c linux-2.6.33.3/arch/mips/ar71xx/early_printk.c
  1994. --- linux-2.6.33.3.orig/arch/mips/ar71xx/early_printk.c 1970-01-01 01:00:00.000000000 +0100
  1995. +++ linux-2.6.33.3/arch/mips/ar71xx/early_printk.c 2009-12-13 20:45:21.280039916 +0100
  1996. @@ -0,0 +1,30 @@
  1997. +/*
  1998. + * Atheros AR71xx SoC early printk support
  1999. + *
  2000. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2001. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2002. + *
  2003. + * This program is free software; you can redistribute it and/or modify it
  2004. + * under the terms of the GNU General Public License version 2 as published
  2005. + * by the Free Software Foundation.
  2006. + */
  2007. +
  2008. +#include <linux/io.h>
  2009. +#include <linux/serial_reg.h>
  2010. +#include <asm/addrspace.h>
  2011. +
  2012. +#include <asm/mach-ar71xx/ar71xx.h>
  2013. +
  2014. +#define UART_READ(r) \
  2015. + __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
  2016. +
  2017. +#define UART_WRITE(r, v) \
  2018. + __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
  2019. +
  2020. +void prom_putchar(unsigned char ch)
  2021. +{
  2022. + while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
  2023. + UART_WRITE(UART_TX, ch);
  2024. + while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
  2025. +}
  2026. +
  2027. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/gpio.c linux-2.6.33.3/arch/mips/ar71xx/gpio.c
  2028. --- linux-2.6.33.3.orig/arch/mips/ar71xx/gpio.c 1970-01-01 01:00:00.000000000 +0100
  2029. +++ linux-2.6.33.3/arch/mips/ar71xx/gpio.c 2010-04-02 11:07:51.646954247 +0200
  2030. @@ -0,0 +1,182 @@
  2031. +/*
  2032. + * Atheros AR71xx SoC GPIO API support
  2033. + *
  2034. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  2035. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2036. + *
  2037. + * This program is free software; you can redistribute it and/or modify it
  2038. + * under the terms of the GNU General Public License version 2 as published
  2039. + * by the Free Software Foundation.
  2040. + */
  2041. +
  2042. +#include <linux/kernel.h>
  2043. +#include <linux/init.h>
  2044. +#include <linux/module.h>
  2045. +#include <linux/types.h>
  2046. +#include <linux/spinlock.h>
  2047. +#include <linux/io.h>
  2048. +#include <linux/ioport.h>
  2049. +#include <linux/gpio.h>
  2050. +
  2051. +#include <asm/mach-ar71xx/ar71xx.h>
  2052. +
  2053. +static DEFINE_SPINLOCK(ar71xx_gpio_lock);
  2054. +
  2055. +unsigned long ar71xx_gpio_count;
  2056. +EXPORT_SYMBOL(ar71xx_gpio_count);
  2057. +
  2058. +void __ar71xx_gpio_set_value(unsigned gpio, int value)
  2059. +{
  2060. + void __iomem *base = ar71xx_gpio_base;
  2061. +
  2062. + if (value)
  2063. + __raw_writel(1 << gpio, base + GPIO_REG_SET);
  2064. + else
  2065. + __raw_writel(1 << gpio, base + GPIO_REG_CLEAR);
  2066. +}
  2067. +EXPORT_SYMBOL(__ar71xx_gpio_set_value);
  2068. +
  2069. +int __ar71xx_gpio_get_value(unsigned gpio)
  2070. +{
  2071. + return (__raw_readl(ar71xx_gpio_base + GPIO_REG_IN) >> gpio) & 1;
  2072. +}
  2073. +EXPORT_SYMBOL(__ar71xx_gpio_get_value);
  2074. +
  2075. +static int ar71xx_gpio_get_value(struct gpio_chip *chip, unsigned offset)
  2076. +{
  2077. + return __ar71xx_gpio_get_value(offset);
  2078. +}
  2079. +
  2080. +static void ar71xx_gpio_set_value(struct gpio_chip *chip,
  2081. + unsigned offset, int value)
  2082. +{
  2083. + __ar71xx_gpio_set_value(offset, value);
  2084. +}
  2085. +
  2086. +static int ar71xx_gpio_direction_input(struct gpio_chip *chip,
  2087. + unsigned offset)
  2088. +{
  2089. + void __iomem *base = ar71xx_gpio_base;
  2090. + unsigned long flags;
  2091. +
  2092. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2093. +
  2094. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(1 << offset),
  2095. + base + GPIO_REG_OE);
  2096. +
  2097. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2098. +
  2099. + return 0;
  2100. +}
  2101. +
  2102. +static int ar71xx_gpio_direction_output(struct gpio_chip *chip,
  2103. + unsigned offset, int value)
  2104. +{
  2105. + void __iomem *base = ar71xx_gpio_base;
  2106. + unsigned long flags;
  2107. +
  2108. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2109. +
  2110. + if (value)
  2111. + __raw_writel(1 << offset, base + GPIO_REG_SET);
  2112. + else
  2113. + __raw_writel(1 << offset, base + GPIO_REG_CLEAR);
  2114. +
  2115. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | (1 << offset),
  2116. + base + GPIO_REG_OE);
  2117. +
  2118. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2119. +
  2120. + return 0;
  2121. +}
  2122. +
  2123. +static struct gpio_chip ar71xx_gpio_chip = {
  2124. + .label = "ar71xx",
  2125. + .get = ar71xx_gpio_get_value,
  2126. + .set = ar71xx_gpio_set_value,
  2127. + .direction_input = ar71xx_gpio_direction_input,
  2128. + .direction_output = ar71xx_gpio_direction_output,
  2129. + .base = 0,
  2130. + .ngpio = AR71XX_GPIO_COUNT,
  2131. +};
  2132. +
  2133. +void ar71xx_gpio_function_enable(u32 mask)
  2134. +{
  2135. + void __iomem *base = ar71xx_gpio_base;
  2136. + unsigned long flags;
  2137. +
  2138. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2139. +
  2140. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) | mask,
  2141. + base + GPIO_REG_FUNC);
  2142. + /* flush write */
  2143. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2144. +
  2145. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2146. +}
  2147. +
  2148. +void ar71xx_gpio_function_disable(u32 mask)
  2149. +{
  2150. + void __iomem *base = ar71xx_gpio_base;
  2151. + unsigned long flags;
  2152. +
  2153. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2154. +
  2155. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) & ~mask,
  2156. + base + GPIO_REG_FUNC);
  2157. + /* flush write */
  2158. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2159. +
  2160. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2161. +}
  2162. +
  2163. +void ar71xx_gpio_function_setup(u32 set, u32 clear)
  2164. +{
  2165. + void __iomem *base = ar71xx_gpio_base;
  2166. + unsigned long flags;
  2167. +
  2168. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2169. +
  2170. + __raw_writel((__raw_readl(base + GPIO_REG_FUNC) & ~clear) | set,
  2171. + base + GPIO_REG_FUNC);
  2172. + /* flush write */
  2173. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2174. +
  2175. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2176. +}
  2177. +EXPORT_SYMBOL(ar71xx_gpio_function_setup);
  2178. +
  2179. +void __init ar71xx_gpio_init(void)
  2180. +{
  2181. + int err;
  2182. +
  2183. + if (!request_mem_region(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE,
  2184. + "AR71xx GPIO controller"))
  2185. + panic("cannot allocate AR71xx GPIO registers page");
  2186. +
  2187. + switch (ar71xx_soc) {
  2188. + case AR71XX_SOC_AR7130:
  2189. + case AR71XX_SOC_AR7141:
  2190. + case AR71XX_SOC_AR7161:
  2191. + ar71xx_gpio_chip.ngpio = AR71XX_GPIO_COUNT;
  2192. + break;
  2193. +
  2194. + case AR71XX_SOC_AR7240:
  2195. + case AR71XX_SOC_AR7241:
  2196. + case AR71XX_SOC_AR7242:
  2197. + ar71xx_gpio_chip.ngpio = AR724X_GPIO_COUNT;
  2198. + break;
  2199. +
  2200. + case AR71XX_SOC_AR9130:
  2201. + case AR71XX_SOC_AR9132:
  2202. + ar71xx_gpio_chip.ngpio = AR91XX_GPIO_COUNT;
  2203. + break;
  2204. +
  2205. + default:
  2206. + BUG();
  2207. + }
  2208. +
  2209. + err = gpiochip_add(&ar71xx_gpio_chip);
  2210. + if (err)
  2211. + panic("cannot add AR71xx GPIO chip, error=%d", err);
  2212. +}
  2213. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/irq.c linux-2.6.33.3/arch/mips/ar71xx/irq.c
  2214. --- linux-2.6.33.3.orig/arch/mips/ar71xx/irq.c 1970-01-01 01:00:00.000000000 +0100
  2215. +++ linux-2.6.33.3/arch/mips/ar71xx/irq.c 2010-05-16 13:17:31.871599360 +0200
  2216. @@ -0,0 +1,295 @@
  2217. +/*
  2218. + * Atheros AR71xx SoC specific interrupt handling
  2219. + *
  2220. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  2221. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2222. + *
  2223. + * Parts of this file are based on Atheros' 2.6.15 BSP
  2224. + *
  2225. + * This program is free software; you can redistribute it and/or modify it
  2226. + * under the terms of the GNU General Public License version 2 as published
  2227. + * by the Free Software Foundation.
  2228. + */
  2229. +
  2230. +#include <linux/kernel.h>
  2231. +#include <linux/init.h>
  2232. +#include <linux/interrupt.h>
  2233. +#include <linux/irq.h>
  2234. +
  2235. +#include <asm/irq_cpu.h>
  2236. +#include <asm/mipsregs.h>
  2237. +
  2238. +#include <asm/mach-ar71xx/ar71xx.h>
  2239. +
  2240. +static int ip2_flush_reg;
  2241. +
  2242. +static void ar71xx_gpio_irq_dispatch(void)
  2243. +{
  2244. + void __iomem *base = ar71xx_gpio_base;
  2245. + u32 pending;
  2246. +
  2247. + pending = __raw_readl(base + GPIO_REG_INT_PENDING) &
  2248. + __raw_readl(base + GPIO_REG_INT_ENABLE);
  2249. +
  2250. + if (pending)
  2251. + do_IRQ(AR71XX_GPIO_IRQ_BASE + fls(pending) - 1);
  2252. + else
  2253. + spurious_interrupt();
  2254. +}
  2255. +
  2256. +static void ar71xx_gpio_irq_unmask(unsigned int irq)
  2257. +{
  2258. + void __iomem *base = ar71xx_gpio_base;
  2259. + u32 t;
  2260. +
  2261. + irq -= AR71XX_GPIO_IRQ_BASE;
  2262. +
  2263. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2264. + __raw_writel(t | (1 << irq), base + GPIO_REG_INT_ENABLE);
  2265. +
  2266. + /* flush write */
  2267. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2268. +}
  2269. +
  2270. +static void ar71xx_gpio_irq_mask(unsigned int irq)
  2271. +{
  2272. + void __iomem *base = ar71xx_gpio_base;
  2273. + u32 t;
  2274. +
  2275. + irq -= AR71XX_GPIO_IRQ_BASE;
  2276. +
  2277. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2278. + __raw_writel(t & ~(1 << irq), base + GPIO_REG_INT_ENABLE);
  2279. +
  2280. + /* flush write */
  2281. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2282. +}
  2283. +
  2284. +#if 0
  2285. +static int ar71xx_gpio_irq_set_type(unsigned int irq, unsigned int flow_type)
  2286. +{
  2287. + /* TODO: implement */
  2288. + return 0;
  2289. +}
  2290. +#else
  2291. +#define ar71xx_gpio_irq_set_type NULL
  2292. +#endif
  2293. +
  2294. +static struct irq_chip ar71xx_gpio_irq_chip = {
  2295. + .name = "AR71XX GPIO",
  2296. + .unmask = ar71xx_gpio_irq_unmask,
  2297. + .mask = ar71xx_gpio_irq_mask,
  2298. + .mask_ack = ar71xx_gpio_irq_mask,
  2299. + .set_type = ar71xx_gpio_irq_set_type,
  2300. +};
  2301. +
  2302. +static struct irqaction ar71xx_gpio_irqaction = {
  2303. + .handler = no_action,
  2304. + .name = "cascade [AR71XX GPIO]",
  2305. +};
  2306. +
  2307. +#define GPIO_IRQ_INIT_STATUS (IRQ_LEVEL | IRQ_TYPE_LEVEL_HIGH | IRQ_DISABLED)
  2308. +#define GPIO_INT_ALL 0xffff
  2309. +
  2310. +static void __init ar71xx_gpio_irq_init(void)
  2311. +{
  2312. + void __iomem *base = ar71xx_gpio_base;
  2313. + int i;
  2314. +
  2315. + __raw_writel(0, base + GPIO_REG_INT_ENABLE);
  2316. + __raw_writel(0, base + GPIO_REG_INT_PENDING);
  2317. +
  2318. + /* setup type of all GPIO interrupts to level sensitive */
  2319. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_TYPE);
  2320. +
  2321. + /* setup polarity of all GPIO interrupts to active high */
  2322. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_POLARITY);
  2323. +
  2324. + for (i = AR71XX_GPIO_IRQ_BASE;
  2325. + i < AR71XX_GPIO_IRQ_BASE + AR71XX_GPIO_IRQ_COUNT; i++) {
  2326. + irq_desc[i].status = GPIO_IRQ_INIT_STATUS;
  2327. + set_irq_chip_and_handler(i, &ar71xx_gpio_irq_chip,
  2328. + handle_level_irq);
  2329. + }
  2330. +
  2331. + setup_irq(AR71XX_MISC_IRQ_GPIO, &ar71xx_gpio_irqaction);
  2332. +}
  2333. +
  2334. +static void ar71xx_misc_irq_dispatch(void)
  2335. +{
  2336. + u32 pending;
  2337. +
  2338. + pending = ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_STATUS)
  2339. + & ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE);
  2340. +
  2341. + if (pending & MISC_INT_UART)
  2342. + do_IRQ(AR71XX_MISC_IRQ_UART);
  2343. +
  2344. + else if (pending & MISC_INT_DMA)
  2345. + do_IRQ(AR71XX_MISC_IRQ_DMA);
  2346. +
  2347. + else if (pending & MISC_INT_PERFC)
  2348. + do_IRQ(AR71XX_MISC_IRQ_PERFC);
  2349. +
  2350. + else if (pending & MISC_INT_TIMER)
  2351. + do_IRQ(AR71XX_MISC_IRQ_TIMER);
  2352. +
  2353. + else if (pending & MISC_INT_OHCI)
  2354. + do_IRQ(AR71XX_MISC_IRQ_OHCI);
  2355. +
  2356. + else if (pending & MISC_INT_ERROR)
  2357. + do_IRQ(AR71XX_MISC_IRQ_ERROR);
  2358. +
  2359. + else if (pending & MISC_INT_GPIO)
  2360. + ar71xx_gpio_irq_dispatch();
  2361. +
  2362. + else if (pending & MISC_INT_WDOG)
  2363. + do_IRQ(AR71XX_MISC_IRQ_WDOG);
  2364. +
  2365. + else
  2366. + spurious_interrupt();
  2367. +}
  2368. +
  2369. +static void ar71xx_misc_irq_unmask(unsigned int irq)
  2370. +{
  2371. + void __iomem *base = ar71xx_reset_base;
  2372. + u32 t;
  2373. +
  2374. + irq -= AR71XX_MISC_IRQ_BASE;
  2375. +
  2376. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2377. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2378. +
  2379. + /* flush write */
  2380. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2381. +}
  2382. +
  2383. +static void ar71xx_misc_irq_mask(unsigned int irq)
  2384. +{
  2385. + void __iomem *base = ar71xx_reset_base;
  2386. + u32 t;
  2387. +
  2388. + irq -= AR71XX_MISC_IRQ_BASE;
  2389. +
  2390. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2391. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2392. +
  2393. + /* flush write */
  2394. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2395. +}
  2396. +
  2397. +static void ar724x_misc_irq_ack(unsigned int irq)
  2398. +{
  2399. + void __iomem *base = ar71xx_reset_base;
  2400. + u32 t;
  2401. +
  2402. + irq -= AR71XX_MISC_IRQ_BASE;
  2403. +
  2404. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2405. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2406. +
  2407. + /* flush write */
  2408. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2409. +}
  2410. +
  2411. +static struct irq_chip ar71xx_misc_irq_chip = {
  2412. + .name = "AR71XX MISC",
  2413. + .unmask = ar71xx_misc_irq_unmask,
  2414. + .mask = ar71xx_misc_irq_mask,
  2415. +};
  2416. +
  2417. +static struct irqaction ar71xx_misc_irqaction = {
  2418. + .handler = no_action,
  2419. + .name = "cascade [AR71XX MISC]",
  2420. +};
  2421. +
  2422. +static void __init ar71xx_misc_irq_init(void)
  2423. +{
  2424. + void __iomem *base = ar71xx_reset_base;
  2425. + int i;
  2426. +
  2427. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2428. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2429. +
  2430. + switch (ar71xx_soc) {
  2431. + case AR71XX_SOC_AR7240:
  2432. + case AR71XX_SOC_AR7241:
  2433. + case AR71XX_SOC_AR7242:
  2434. + ar71xx_misc_irq_chip.ack = ar724x_misc_irq_ack;
  2435. + break;
  2436. + default:
  2437. + ar71xx_misc_irq_chip.mask_ack = ar71xx_misc_irq_mask;
  2438. + break;
  2439. + }
  2440. +
  2441. + for (i = AR71XX_MISC_IRQ_BASE;
  2442. + i < AR71XX_MISC_IRQ_BASE + AR71XX_MISC_IRQ_COUNT; i++) {
  2443. + irq_desc[i].status = IRQ_DISABLED;
  2444. + set_irq_chip_and_handler(i, &ar71xx_misc_irq_chip,
  2445. + handle_level_irq);
  2446. + }
  2447. +
  2448. + setup_irq(AR71XX_CPU_IRQ_MISC, &ar71xx_misc_irqaction);
  2449. +}
  2450. +
  2451. +asmlinkage void plat_irq_dispatch(void)
  2452. +{
  2453. + unsigned long pending;
  2454. +
  2455. + pending = read_c0_status() & read_c0_cause() & ST0_IM;
  2456. +
  2457. + if (pending & STATUSF_IP7)
  2458. + do_IRQ(AR71XX_CPU_IRQ_TIMER);
  2459. +
  2460. + else if (pending & STATUSF_IP2) {
  2461. + /*
  2462. + * This IRQ is meant for a PCI device. Drivers for PCI devices
  2463. + * typically allocate coherent DMA memory for the descriptor
  2464. + * ring, however the DMA controller may still have some
  2465. + * unsynchronized data in the FIFO.
  2466. + * Issue a flush here to ensure that the driver sees the update.
  2467. + */
  2468. + ar71xx_ddr_flush(ip2_flush_reg);
  2469. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2470. + }
  2471. +
  2472. + else if (pending & STATUSF_IP4)
  2473. + do_IRQ(AR71XX_CPU_IRQ_GE0);
  2474. +
  2475. + else if (pending & STATUSF_IP5)
  2476. + do_IRQ(AR71XX_CPU_IRQ_GE1);
  2477. +
  2478. + else if (pending & STATUSF_IP3)
  2479. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2480. +
  2481. + else if (pending & STATUSF_IP6)
  2482. + ar71xx_misc_irq_dispatch();
  2483. +
  2484. + else
  2485. + spurious_interrupt();
  2486. +}
  2487. +
  2488. +void __init arch_init_irq(void)
  2489. +{
  2490. + switch(ar71xx_soc) {
  2491. + case AR71XX_SOC_AR7240:
  2492. + case AR71XX_SOC_AR7241:
  2493. + case AR71XX_SOC_AR7242:
  2494. + ip2_flush_reg = AR724X_DDR_REG_FLUSH_PCIE;
  2495. + break;
  2496. + case AR71XX_SOC_AR9130:
  2497. + case AR71XX_SOC_AR9132:
  2498. + ip2_flush_reg = AR91XX_DDR_REG_FLUSH_WMAC;
  2499. + break;
  2500. + default:
  2501. + ip2_flush_reg = AR71XX_DDR_REG_FLUSH_PCI;
  2502. + break;
  2503. + }
  2504. + mips_cpu_irq_init();
  2505. +
  2506. + ar71xx_misc_irq_init();
  2507. +
  2508. + cp0_perfcount_irq = AR71XX_MISC_IRQ_PERFC;
  2509. +
  2510. + ar71xx_gpio_irq_init();
  2511. +}
  2512. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/Kconfig linux-2.6.33.3/arch/mips/ar71xx/Kconfig
  2513. --- linux-2.6.33.3.orig/arch/mips/ar71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  2514. +++ linux-2.6.33.3/arch/mips/ar71xx/Kconfig 2010-05-16 13:17:31.779600220 +0200
  2515. @@ -0,0 +1,264 @@
  2516. +if ATHEROS_AR71XX
  2517. +
  2518. +menu "Atheros AR71xx machine selection"
  2519. +
  2520. +config AR71XX_MACH_AP81
  2521. + bool "Atheros AP81 board support"
  2522. + select AR71XX_DEV_M25P80
  2523. + select AR71XX_DEV_AR913X_WMAC
  2524. + select AR71XX_DEV_GPIO_BUTTONS
  2525. + select AR71XX_DEV_LEDS_GPIO
  2526. + select AR71XX_DEV_USB
  2527. + default n
  2528. +
  2529. +config AR71XX_MACH_AP83
  2530. + bool "Atheros AP83 board support"
  2531. + select AR71XX_DEV_AR913X_WMAC
  2532. + select AR71XX_DEV_GPIO_BUTTONS
  2533. + select AR71XX_DEV_LEDS_GPIO
  2534. + select AR71XX_DEV_USB
  2535. + default n
  2536. +
  2537. +config AR71XX_MACH_DIR_600_A1
  2538. + bool "D-Link DIR-600 rev. A1 support"
  2539. + select AR71XX_DEV_AP91_ETH
  2540. + select AR71XX_DEV_AP91_PCI if PCI
  2541. + select AR71XX_DEV_M25P80
  2542. + select AR71XX_DEV_GPIO_BUTTONS
  2543. + select AR71XX_DEV_LEDS_GPIO
  2544. + select AR71XX_NVRAM
  2545. + default n
  2546. +
  2547. +config AR71XX_MACH_DIR_615_C1
  2548. + bool "D-Link DIR-615 rev. C1 support"
  2549. + select AR71XX_DEV_M25P80
  2550. + select AR71XX_DEV_AR913X_WMAC
  2551. + select AR71XX_DEV_GPIO_BUTTONS
  2552. + select AR71XX_DEV_LEDS_GPIO
  2553. + select AR71XX_NVRAM
  2554. + default n
  2555. +
  2556. +config AR71XX_MACH_DIR_825_B1
  2557. + bool "D-Link DIR-825 rev. B1 board support"
  2558. + select AR71XX_DEV_M25P80
  2559. + select AR71XX_DEV_AP94_PCI if PCI
  2560. + select AR71XX_DEV_GPIO_BUTTONS
  2561. + select AR71XX_DEV_LEDS_GPIO
  2562. + select AR71XX_DEV_USB
  2563. + default n
  2564. +
  2565. +config AR71XX_MACH_PB42
  2566. + bool "Atheros PB42 board support"
  2567. + select AR71XX_DEV_M25P80
  2568. + select AR71XX_DEV_GPIO_BUTTONS
  2569. + select AR71XX_DEV_PB42_PCI if PCI
  2570. + default n
  2571. +
  2572. +config AR71XX_MACH_PB44
  2573. + bool "Atheros PB44 board support"
  2574. + select AR71XX_DEV_GPIO_BUTTONS
  2575. + select AR71XX_DEV_PB42_PCI if PCI
  2576. + select AR71XX_DEV_LEDS_GPIO
  2577. + select AR71XX_DEV_USB
  2578. + default n
  2579. +
  2580. +config AR71XX_MACH_PB92
  2581. + bool "Atheros PB92 board support"
  2582. + select AR71XX_DEV_GPIO_BUTTONS
  2583. + select AR71XX_DEV_PB9X_PCI if PCI
  2584. + select AR71XX_DEV_LEDS_GPIO
  2585. + select AR71XX_DEV_USB
  2586. + default n
  2587. +
  2588. +config AR71XX_MACH_AW_NR580
  2589. + bool "AzureWave AW-NR580 board support"
  2590. + select AR71XX_DEV_M25P80
  2591. + select AR71XX_DEV_GPIO_BUTTONS
  2592. + select AR71XX_DEV_PB42_PCI if PCI
  2593. + select AR71XX_DEV_LEDS_GPIO
  2594. + default n
  2595. +
  2596. +config AR71XX_MACH_WZR_HP_G300NH
  2597. + bool "Buffalo WZR-HP-G300NH board support"
  2598. + select AR71XX_DEV_AR913X_WMAC
  2599. + select AR71XX_DEV_GPIO_BUTTONS
  2600. + select AR71XX_DEV_LEDS_GPIO
  2601. + select AR71XX_DEV_USB
  2602. + default y
  2603. +
  2604. +config AR71XX_MACH_WP543
  2605. + bool "Compex WP543/WPJ543 board support"
  2606. + select MYLOADER
  2607. + select AR71XX_DEV_M25P80
  2608. + select AR71XX_DEV_GPIO_BUTTONS
  2609. + select AR71XX_DEV_PB42_PCI if PCI
  2610. + select AR71XX_DEV_LEDS_GPIO
  2611. + select AR71XX_DEV_USB
  2612. + default n
  2613. +
  2614. +config AR71XX_MACH_WRT160NL
  2615. + bool "Linksys WRT160NL board support"
  2616. + select AR71XX_DEV_M25P80
  2617. + select AR71XX_DEV_AR913X_WMAC
  2618. + select AR71XX_DEV_GPIO_BUTTONS
  2619. + select AR71XX_DEV_LEDS_GPIO
  2620. + select AR71XX_DEV_USB
  2621. + select AR71XX_NVRAM
  2622. + default n
  2623. +
  2624. +config AR71XX_MACH_WRT400N
  2625. + bool "Linksys WRT400N board support"
  2626. + select AR71XX_DEV_AP94_PCI if PCI
  2627. + select AR71XX_DEV_M25P80
  2628. + select AR71XX_DEV_GPIO_BUTTONS
  2629. + select AR71XX_DEV_LEDS_GPIO
  2630. + default n
  2631. +
  2632. +config AR71XX_MACH_RB4XX
  2633. + bool "MikroTik RouterBOARD 4xx series support"
  2634. + select AR71XX_DEV_GPIO_BUTTONS
  2635. + select AR71XX_DEV_LEDS_GPIO
  2636. + select AR71XX_DEV_USB
  2637. + default n
  2638. +
  2639. +config AR71XX_MACH_RB750
  2640. + bool "MikroTik RouterBOARD 750 support"
  2641. + select AR71XX_DEV_AP91_ETH
  2642. + default n
  2643. +
  2644. +config AR71XX_MACH_WNDR3700
  2645. + bool "NETGEAR WNDR3700 board support"
  2646. + select AR71XX_DEV_M25P80
  2647. + select AR71XX_DEV_AP94_PCI if PCI
  2648. + select AR71XX_DEV_GPIO_BUTTONS
  2649. + select AR71XX_DEV_LEDS_GPIO
  2650. + select AR71XX_DEV_USB
  2651. + default n
  2652. +
  2653. +config AR71XX_MACH_WNR2000
  2654. + bool "NETGEAR WNR2000 board support"
  2655. + select AR71XX_DEV_M25P80
  2656. + select AR71XX_DEV_AR913X_WMAC
  2657. + select AR71XX_DEV_GPIO_BUTTONS
  2658. + select AR71XX_DEV_LEDS_GPIO
  2659. + default n
  2660. +
  2661. +config AR71XX_MACH_MZK_W04NU
  2662. + bool "Planex MZK-W04NU board support"
  2663. + select AR71XX_DEV_M25P80
  2664. + select AR71XX_DEV_AR913X_WMAC
  2665. + select AR71XX_DEV_GPIO_BUTTONS
  2666. + select AR71XX_DEV_LEDS_GPIO
  2667. + select AR71XX_DEV_USB
  2668. + default n
  2669. +
  2670. +config AR71XX_MACH_MZK_W300NH
  2671. + bool "Planex MZK-W300NH board support"
  2672. + select AR71XX_DEV_M25P80
  2673. + select AR71XX_DEV_AR913X_WMAC
  2674. + select AR71XX_DEV_GPIO_BUTTONS
  2675. + select AR71XX_DEV_LEDS_GPIO
  2676. + default n
  2677. +
  2678. +config AR71XX_MACH_NBG460N
  2679. + bool "Zyxel NBG460N/550N/550NH board support"
  2680. + select AR71XX_DEV_M25P80
  2681. + select AR71XX_DEV_AR913X_WMAC
  2682. + select AR71XX_DEV_GPIO_BUTTONS
  2683. + select AR71XX_DEV_LEDS_GPIO
  2684. + default n
  2685. +
  2686. +config AR71XX_MACH_TL_WR741ND
  2687. + bool "TP-LINK TL-WR741ND support"
  2688. + select AR71XX_DEV_M25P80
  2689. + select AR71XX_DEV_AP91_ETH
  2690. + select AR71XX_DEV_AP91_PCI if PCI
  2691. + select AR71XX_DEV_GPIO_BUTTONS
  2692. + select AR71XX_DEV_LEDS_GPIO
  2693. + default n
  2694. +
  2695. +config AR71XX_MACH_TL_WR841N_V1
  2696. + bool "TP-LINK TL-WR841N v1 support"
  2697. + select AR71XX_DEV_M25P80
  2698. + select AR71XX_DEV_PB42_PCI if PCI
  2699. + select AR71XX_DEV_DSA
  2700. + select AR71XX_DEV_GPIO_BUTTONS
  2701. + select AR71XX_DEV_LEDS_GPIO
  2702. + default n
  2703. +
  2704. +config AR71XX_MACH_TL_WR941ND
  2705. + bool "TP-LINK TL-WR941ND support"
  2706. + select AR71XX_DEV_M25P80
  2707. + select AR71XX_DEV_AR913X_WMAC
  2708. + select AR71XX_DEV_DSA
  2709. + select AR71XX_DEV_GPIO_BUTTONS
  2710. + select AR71XX_DEV_LEDS_GPIO
  2711. + default n
  2712. +
  2713. +config AR71XX_MACH_TL_WR1043ND
  2714. + bool "TP-LINK TL-WR1043ND support"
  2715. + select AR71XX_DEV_M25P80
  2716. + select AR71XX_DEV_AR913X_WMAC
  2717. + select AR71XX_DEV_GPIO_BUTTONS
  2718. + select AR71XX_DEV_LEDS_GPIO
  2719. + select AR71XX_DEV_USB
  2720. + default n
  2721. +
  2722. +config AR71XX_MACH_TEW_632BRP
  2723. + bool "TRENDnet TEW-632BRP support"
  2724. + select AR71XX_DEV_M25P80
  2725. + select AR71XX_DEV_AR913X_WMAC
  2726. + select AR71XX_DEV_GPIO_BUTTONS
  2727. + select AR71XX_DEV_LEDS_GPIO
  2728. + select AR71XX_NVRAM
  2729. + default n
  2730. +
  2731. +config AR71XX_MACH_UBNT
  2732. + bool "Ubiquiti AR71xx based boards support"
  2733. + select AR71XX_DEV_M25P80
  2734. + select AR71XX_DEV_AP91_PCI if PCI
  2735. + select AR71XX_DEV_GPIO_BUTTONS
  2736. + select AR71XX_DEV_LEDS_GPIO
  2737. + select AR71XX_DEV_PB42_PCI if PCI
  2738. + select AR71XX_DEV_USB
  2739. + default n
  2740. +
  2741. +endmenu
  2742. +
  2743. +config AR71XX_DEV_M25P80
  2744. + def_bool n
  2745. +
  2746. +config AR71XX_DEV_AP91_PCI
  2747. + def_bool n
  2748. +
  2749. +config AR71XX_DEV_AP91_ETH
  2750. + def_bool n
  2751. +
  2752. +config AR71XX_DEV_AP94_PCI
  2753. + def_bool n
  2754. +
  2755. +config AR71XX_DEV_AR913X_WMAC
  2756. + def_bool n
  2757. +
  2758. +config AR71XX_DEV_DSA
  2759. + def_bool n
  2760. +
  2761. +config AR71XX_DEV_GPIO_BUTTONS
  2762. + def_bool n
  2763. +
  2764. +config AR71XX_DEV_LEDS_GPIO
  2765. + def_bool n
  2766. +
  2767. +config AR71XX_DEV_PB42_PCI
  2768. + def_bool n
  2769. +
  2770. +config AR71XX_DEV_PB9X_PCI
  2771. + def_bool n
  2772. +
  2773. +config AR71XX_DEV_USB
  2774. + def_bool n
  2775. +
  2776. +config AR71XX_NVRAM
  2777. + def_bool n
  2778. +
  2779. +endif
  2780. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ap81.c linux-2.6.33.3/arch/mips/ar71xx/mach-ap81.c
  2781. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ap81.c 1970-01-01 01:00:00.000000000 +0100
  2782. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-ap81.c 2010-03-23 20:31:04.604705903 +0100
  2783. @@ -0,0 +1,140 @@
  2784. +/*
  2785. + * Atheros AP81 board support
  2786. + *
  2787. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  2788. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  2789. + *
  2790. + * This program is free software; you can redistribute it and/or modify it
  2791. + * under the terms of the GNU General Public License version 2 as published
  2792. + * by the Free Software Foundation.
  2793. + */
  2794. +
  2795. +#include <linux/mtd/mtd.h>
  2796. +#include <linux/mtd/partitions.h>
  2797. +
  2798. +#include <asm/mach-ar71xx/ar71xx.h>
  2799. +
  2800. +#include "machtype.h"
  2801. +#include "devices.h"
  2802. +#include "dev-m25p80.h"
  2803. +#include "dev-ar913x-wmac.h"
  2804. +#include "dev-gpio-buttons.h"
  2805. +#include "dev-leds-gpio.h"
  2806. +#include "dev-usb.h"
  2807. +
  2808. +#define AP81_GPIO_LED_STATUS 1
  2809. +#define AP81_GPIO_LED_AOSS 3
  2810. +#define AP81_GPIO_LED_WLAN 6
  2811. +#define AP81_GPIO_LED_POWER 14
  2812. +
  2813. +#define AP81_GPIO_BTN_SW4 12
  2814. +#define AP81_GPIO_BTN_SW1 21
  2815. +
  2816. +#define AP81_BUTTONS_POLL_INTERVAL 20
  2817. +
  2818. +#ifdef CONFIG_MTD_PARTITIONS
  2819. +static struct mtd_partition ap81_partitions[] = {
  2820. + {
  2821. + .name = "u-boot",
  2822. + .offset = 0,
  2823. + .size = 0x040000,
  2824. + .mask_flags = MTD_WRITEABLE,
  2825. + } , {
  2826. + .name = "u-boot-env",
  2827. + .offset = 0x040000,
  2828. + .size = 0x010000,
  2829. + } , {
  2830. + .name = "rootfs",
  2831. + .offset = 0x050000,
  2832. + .size = 0x500000,
  2833. + } , {
  2834. + .name = "uImage",
  2835. + .offset = 0x550000,
  2836. + .size = 0x100000,
  2837. + } , {
  2838. + .name = "ART",
  2839. + .offset = 0x650000,
  2840. + .size = 0x1b0000,
  2841. + .mask_flags = MTD_WRITEABLE,
  2842. + }
  2843. +};
  2844. +#endif /* CONFIG_MTD_PARTITIONS */
  2845. +
  2846. +static struct flash_platform_data ap81_flash_data = {
  2847. +#ifdef CONFIG_MTD_PARTITIONS
  2848. + .parts = ap81_partitions,
  2849. + .nr_parts = ARRAY_SIZE(ap81_partitions),
  2850. +#endif
  2851. +};
  2852. +
  2853. +static struct gpio_led ap81_leds_gpio[] __initdata = {
  2854. + {
  2855. + .name = "ap81:green:status",
  2856. + .gpio = AP81_GPIO_LED_STATUS,
  2857. + .active_low = 1,
  2858. + }, {
  2859. + .name = "ap81:amber:aoss",
  2860. + .gpio = AP81_GPIO_LED_AOSS,
  2861. + .active_low = 1,
  2862. + }, {
  2863. + .name = "ap81:green:wlan",
  2864. + .gpio = AP81_GPIO_LED_WLAN,
  2865. + .active_low = 1,
  2866. + }, {
  2867. + .name = "ap81:green:power",
  2868. + .gpio = AP81_GPIO_LED_POWER,
  2869. + .active_low = 1,
  2870. + }
  2871. +};
  2872. +
  2873. +static struct gpio_button ap81_gpio_buttons[] __initdata = {
  2874. + {
  2875. + .desc = "sw1",
  2876. + .type = EV_KEY,
  2877. + .code = BTN_0,
  2878. + .threshold = 3,
  2879. + .gpio = AP81_GPIO_BTN_SW1,
  2880. + .active_low = 1,
  2881. + } , {
  2882. + .desc = "sw4",
  2883. + .type = EV_KEY,
  2884. + .code = BTN_1,
  2885. + .threshold = 3,
  2886. + .gpio = AP81_GPIO_BTN_SW4,
  2887. + .active_low = 1,
  2888. + }
  2889. +};
  2890. +
  2891. +static void __init ap81_setup(void)
  2892. +{
  2893. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  2894. +
  2895. + ar71xx_set_mac_base(eeprom);
  2896. + ar71xx_add_device_mdio(0x0);
  2897. +
  2898. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  2899. + ar71xx_eth0_data.speed = SPEED_100;
  2900. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  2901. + ar71xx_eth0_data.has_ar8216 = 1;
  2902. +
  2903. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  2904. + ar71xx_eth1_data.phy_mask = 0x10;
  2905. +
  2906. + ar71xx_add_device_eth(0);
  2907. + ar71xx_add_device_eth(1);
  2908. +
  2909. + ar71xx_add_device_usb();
  2910. +
  2911. + ar71xx_add_device_m25p80(&ap81_flash_data);
  2912. +
  2913. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap81_leds_gpio),
  2914. + ap81_leds_gpio);
  2915. +
  2916. + ar71xx_add_device_gpio_buttons(-1, AP81_BUTTONS_POLL_INTERVAL,
  2917. + ARRAY_SIZE(ap81_gpio_buttons),
  2918. + ap81_gpio_buttons);
  2919. +
  2920. + ar913x_add_device_wmac(eeprom, NULL);
  2921. +}
  2922. +
  2923. +MIPS_MACHINE(AR71XX_MACH_AP81, "AP81", "Atheros AP81", ap81_setup);
  2924. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ap83.c linux-2.6.33.3/arch/mips/ar71xx/mach-ap83.c
  2925. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ap83.c 1970-01-01 01:00:00.000000000 +0100
  2926. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-ap83.c 2010-05-16 13:17:31.787602077 +0200
  2927. @@ -0,0 +1,266 @@
  2928. +/*
  2929. + * Atheros AP83 board support
  2930. + *
  2931. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2932. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2933. + *
  2934. + * This program is free software; you can redistribute it and/or modify it
  2935. + * under the terms of the GNU General Public License version 2 as published
  2936. + * by the Free Software Foundation.
  2937. + */
  2938. +
  2939. +#include <linux/delay.h>
  2940. +#include <linux/platform_device.h>
  2941. +#include <linux/mtd/mtd.h>
  2942. +#include <linux/mtd/partitions.h>
  2943. +#include <linux/spi/spi.h>
  2944. +#include <linux/spi/spi_gpio.h>
  2945. +#include <linux/spi/vsc7385.h>
  2946. +
  2947. +#include <asm/mach-ar71xx/ar71xx.h>
  2948. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  2949. +
  2950. +#include "machtype.h"
  2951. +#include "devices.h"
  2952. +#include "dev-ar913x-wmac.h"
  2953. +#include "dev-gpio-buttons.h"
  2954. +#include "dev-leds-gpio.h"
  2955. +#include "dev-usb.h"
  2956. +
  2957. +#define AP83_GPIO_LED_WLAN 6
  2958. +#define AP83_GPIO_LED_POWER 14
  2959. +#define AP83_GPIO_LED_JUMPSTART 15
  2960. +#define AP83_GPIO_BTN_JUMPSTART 12
  2961. +#define AP83_GPIO_BTN_RESET 21
  2962. +
  2963. +#define AP83_050_GPIO_VSC7385_CS 1
  2964. +#define AP83_050_GPIO_VSC7385_MISO 3
  2965. +#define AP83_050_GPIO_VSC7385_MOSI 16
  2966. +#define AP83_050_GPIO_VSC7385_SCK 17
  2967. +
  2968. +#define AP83_BUTTONS_POLL_INTERVAL 20
  2969. +
  2970. +#ifdef CONFIG_MTD_PARTITIONS
  2971. +static struct mtd_partition ap83_flash_partitions[] = {
  2972. + {
  2973. + .name = "u-boot",
  2974. + .offset = 0,
  2975. + .size = 0x040000,
  2976. + .mask_flags = MTD_WRITEABLE,
  2977. + } , {
  2978. + .name = "u-boot-env",
  2979. + .offset = 0x040000,
  2980. + .size = 0x020000,
  2981. + .mask_flags = MTD_WRITEABLE,
  2982. + } , {
  2983. + .name = "kernel",
  2984. + .offset = 0x060000,
  2985. + .size = 0x140000,
  2986. + } , {
  2987. + .name = "rootfs",
  2988. + .offset = 0x1a0000,
  2989. + .size = 0x650000,
  2990. + } , {
  2991. + .name = "art",
  2992. + .offset = 0x7f0000,
  2993. + .size = 0x010000,
  2994. + .mask_flags = MTD_WRITEABLE,
  2995. + } , {
  2996. + .name = "firmware",
  2997. + .offset = 0x060000,
  2998. + .size = 0x790000,
  2999. + }
  3000. +};
  3001. +#endif /* CONFIG_MTD_PARTITIONS */
  3002. +
  3003. +static struct ar91xx_flash_platform_data ap83_flash_data = {
  3004. + .width = 2,
  3005. +#ifdef CONFIG_MTD_PARTITIONS
  3006. + .parts = ap83_flash_partitions,
  3007. + .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
  3008. +#endif
  3009. +};
  3010. +
  3011. +static struct resource ap83_flash_resources[] = {
  3012. + [0] = {
  3013. + .start = AR71XX_SPI_BASE,
  3014. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3015. + .flags = IORESOURCE_MEM,
  3016. + },
  3017. +};
  3018. +
  3019. +static struct platform_device ap83_flash_device = {
  3020. + .name = "ar91xx-flash",
  3021. + .id = -1,
  3022. + .resource = ap83_flash_resources,
  3023. + .num_resources = ARRAY_SIZE(ap83_flash_resources),
  3024. + .dev = {
  3025. + .platform_data = &ap83_flash_data,
  3026. + }
  3027. +};
  3028. +
  3029. +static struct gpio_led ap83_leds_gpio[] __initdata = {
  3030. + {
  3031. + .name = "ap83:green:jumpstart",
  3032. + .gpio = AP83_GPIO_LED_JUMPSTART,
  3033. + .active_low = 0,
  3034. + }, {
  3035. + .name = "ap83:green:power",
  3036. + .gpio = AP83_GPIO_LED_POWER,
  3037. + .active_low = 0,
  3038. + }, {
  3039. + .name = "ap83:green:wlan",
  3040. + .gpio = AP83_GPIO_LED_WLAN,
  3041. + .active_low = 0,
  3042. + },
  3043. +};
  3044. +
  3045. +static struct gpio_button ap83_gpio_buttons[] __initdata = {
  3046. + {
  3047. + .desc = "soft_reset",
  3048. + .type = EV_KEY,
  3049. + .code = KEY_RESTART,
  3050. + .threshold = 3,
  3051. + .gpio = AP83_GPIO_BTN_RESET,
  3052. + .active_low = 1,
  3053. + } , {
  3054. + .desc = "jumpstart",
  3055. + .type = EV_KEY,
  3056. + .code = KEY_WPS_BUTTON,
  3057. + .threshold = 3,
  3058. + .gpio = AP83_GPIO_BTN_JUMPSTART,
  3059. + .active_low = 1,
  3060. + }
  3061. +};
  3062. +
  3063. +static struct resource ap83_040_spi_resources[] = {
  3064. + [0] = {
  3065. + .start = AR71XX_SPI_BASE,
  3066. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3067. + .flags = IORESOURCE_MEM,
  3068. + },
  3069. +};
  3070. +
  3071. +static struct platform_device ap83_040_spi_device = {
  3072. + .name = "ap83-spi",
  3073. + .id = 0,
  3074. + .resource = ap83_040_spi_resources,
  3075. + .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
  3076. +};
  3077. +
  3078. +static struct spi_gpio_platform_data ap83_050_spi_data = {
  3079. + .miso = AP83_050_GPIO_VSC7385_MISO,
  3080. + .mosi = AP83_050_GPIO_VSC7385_MOSI,
  3081. + .sck = AP83_050_GPIO_VSC7385_SCK,
  3082. + .num_chipselect = 1,
  3083. +};
  3084. +
  3085. +static struct platform_device ap83_050_spi_device = {
  3086. + .name = "spi_gpio",
  3087. + .id = 0,
  3088. + .dev = {
  3089. + .platform_data = &ap83_050_spi_data,
  3090. + }
  3091. +};
  3092. +
  3093. +static void ap83_vsc7385_reset(void)
  3094. +{
  3095. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  3096. + udelay(10);
  3097. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  3098. + mdelay(50);
  3099. +}
  3100. +
  3101. +static struct vsc7385_platform_data ap83_vsc7385_data = {
  3102. + .reset = ap83_vsc7385_reset,
  3103. + .ucode_name = "vsc7385_ucode_ap83.bin",
  3104. + .mac_cfg = {
  3105. + .tx_ipg = 6,
  3106. + .bit2 = 0,
  3107. + .clk_sel = 3,
  3108. + },
  3109. +};
  3110. +
  3111. +static struct spi_board_info ap83_spi_info[] = {
  3112. + {
  3113. + .bus_num = 0,
  3114. + .chip_select = 0,
  3115. + .max_speed_hz = 25000000,
  3116. + .modalias = "spi-vsc7385",
  3117. + .platform_data = &ap83_vsc7385_data,
  3118. + .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
  3119. + }
  3120. +};
  3121. +
  3122. +static void __init ap83_generic_setup(void)
  3123. +{
  3124. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3125. +
  3126. + ar71xx_set_mac_base(eeprom);
  3127. +
  3128. + ar71xx_add_device_mdio(0xfffffffe);
  3129. +
  3130. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3131. + ar71xx_eth0_data.phy_mask = 0x1;
  3132. +
  3133. + ar71xx_add_device_eth(0);
  3134. +
  3135. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3136. + ar71xx_eth1_data.speed = SPEED_1000;
  3137. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  3138. +
  3139. + ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
  3140. +
  3141. + ar71xx_add_device_eth(1);
  3142. +
  3143. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
  3144. + ap83_leds_gpio);
  3145. +
  3146. + ar71xx_add_device_gpio_buttons(-1, AP83_BUTTONS_POLL_INTERVAL,
  3147. + ARRAY_SIZE(ap83_gpio_buttons),
  3148. + ap83_gpio_buttons);
  3149. +
  3150. + ar71xx_add_device_usb();
  3151. +
  3152. + ar913x_add_device_wmac(eeprom, NULL);
  3153. +
  3154. + platform_device_register(&ap83_flash_device);
  3155. +
  3156. + spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
  3157. +}
  3158. +
  3159. +static void __init ap83_040_setup(void)
  3160. +{
  3161. + ap83_flash_data.is_shared=1;
  3162. + ap83_generic_setup();
  3163. + platform_device_register(&ap83_040_spi_device);
  3164. +}
  3165. +
  3166. +static void __init ap83_050_setup(void)
  3167. +{
  3168. + ap83_generic_setup();
  3169. + platform_device_register(&ap83_050_spi_device);
  3170. +}
  3171. +
  3172. +static void __init ap83_setup(void)
  3173. +{
  3174. + u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
  3175. + unsigned int board_version;
  3176. +
  3177. + board_version = (unsigned int)(board_id[0] - '0');
  3178. + board_version += ((unsigned int)(board_id[1] - '0')) * 10;
  3179. +
  3180. + switch (board_version) {
  3181. + case 40:
  3182. + ap83_040_setup();
  3183. + break;
  3184. + case 50:
  3185. + ap83_050_setup();
  3186. + break;
  3187. + default:
  3188. + printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
  3189. + board_version);
  3190. + }
  3191. +}
  3192. +
  3193. +MIPS_MACHINE(AR71XX_MACH_AP83, "AP83", "Atheros AP83", ap83_setup);
  3194. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-aw-nr580.c linux-2.6.33.3/arch/mips/ar71xx/mach-aw-nr580.c
  3195. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-aw-nr580.c 1970-01-01 01:00:00.000000000 +0100
  3196. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-aw-nr580.c 2010-05-16 13:17:33.024519409 +0200
  3197. @@ -0,0 +1,101 @@
  3198. +/*
  3199. + * AzureWave AW-NR580 board support
  3200. + *
  3201. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3202. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3203. + *
  3204. + * This program is free software; you can redistribute it and/or modify it
  3205. + * under the terms of the GNU General Public License version 2 as published
  3206. + * by the Free Software Foundation.
  3207. + */
  3208. +
  3209. +#include <linux/mtd/mtd.h>
  3210. +#include <linux/mtd/partitions.h>
  3211. +
  3212. +#include <asm/mips_machine.h>
  3213. +#include <asm/mach-ar71xx/ar71xx.h>
  3214. +
  3215. +#include "machtype.h"
  3216. +#include "devices.h"
  3217. +#include "dev-m25p80.h"
  3218. +#include "dev-gpio-buttons.h"
  3219. +#include "dev-pb42-pci.h"
  3220. +#include "dev-leds-gpio.h"
  3221. +
  3222. +#define AW_NR580_GPIO_LED_READY_RED 0
  3223. +#define AW_NR580_GPIO_LED_WLAN 1
  3224. +#define AW_NR580_GPIO_LED_READY_GREEN 2
  3225. +#define AW_NR580_GPIO_LED_WPS_GREEN 4
  3226. +#define AW_NR580_GPIO_LED_WPS_AMBER 5
  3227. +
  3228. +#define AW_NR580_GPIO_BTN_WPS 3
  3229. +#define AW_NR580_GPIO_BTN_RESET 11
  3230. +
  3231. +#define AW_NR580_BUTTONS_POLL_INTERVAL 20
  3232. +
  3233. +static struct gpio_led aw_nr580_leds_gpio[] __initdata = {
  3234. + {
  3235. + .name = "aw-nr580:red:ready",
  3236. + .gpio = AW_NR580_GPIO_LED_READY_RED,
  3237. + .active_low = 0,
  3238. + }, {
  3239. + .name = "aw-nr580:green:ready",
  3240. + .gpio = AW_NR580_GPIO_LED_READY_GREEN,
  3241. + .active_low = 0,
  3242. + }, {
  3243. + .name = "aw-nr580:green:wps",
  3244. + .gpio = AW_NR580_GPIO_LED_WPS_GREEN,
  3245. + .active_low = 0,
  3246. + }, {
  3247. + .name = "aw-nr580:amber:wps",
  3248. + .gpio = AW_NR580_GPIO_LED_WPS_AMBER,
  3249. + .active_low = 0,
  3250. + }, {
  3251. + .name = "aw-nr580:green:wlan",
  3252. + .gpio = AW_NR580_GPIO_LED_WLAN,
  3253. + .active_low = 0,
  3254. + }
  3255. +};
  3256. +
  3257. +static struct gpio_button aw_nr580_gpio_buttons[] __initdata = {
  3258. + {
  3259. + .desc = "reset",
  3260. + .type = EV_KEY,
  3261. + .code = KEY_RESTART,
  3262. + .threshold = 3,
  3263. + .gpio = AW_NR580_GPIO_BTN_RESET,
  3264. + .active_low = 1,
  3265. + }, {
  3266. + .desc = "wps",
  3267. + .type = EV_KEY,
  3268. + .code = KEY_WPS_BUTTON,
  3269. + .threshold = 3,
  3270. + .gpio = AW_NR580_GPIO_BTN_WPS,
  3271. + .active_low = 1,
  3272. + }
  3273. +};
  3274. +
  3275. +static void __init aw_nr580_setup(void)
  3276. +{
  3277. + ar71xx_add_device_mdio(0x0);
  3278. +
  3279. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  3280. + ar71xx_eth0_data.speed = SPEED_100;
  3281. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3282. +
  3283. + ar71xx_add_device_eth(0);
  3284. +
  3285. + pb42_pci_init();
  3286. +
  3287. + ar71xx_add_device_m25p80(NULL);
  3288. +
  3289. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(aw_nr580_leds_gpio),
  3290. + aw_nr580_leds_gpio);
  3291. +
  3292. + ar71xx_add_device_gpio_buttons(-1, AW_NR580_BUTTONS_POLL_INTERVAL,
  3293. + ARRAY_SIZE(aw_nr580_gpio_buttons),
  3294. + aw_nr580_gpio_buttons);
  3295. +}
  3296. +
  3297. +MIPS_MACHINE(AR71XX_MACH_AW_NR580, "AW-NR580", "AzureWave AW-NR580",
  3298. + aw_nr580_setup);
  3299. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-600-a1.c linux-2.6.33.3/arch/mips/ar71xx/mach-dir-600-a1.c
  3300. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-600-a1.c 1970-01-01 01:00:00.000000000 +0100
  3301. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-dir-600-a1.c 2010-05-16 13:17:31.839599757 +0200
  3302. @@ -0,0 +1,138 @@
  3303. +/*
  3304. + * D-Link DIR-600 rev. A1 board support
  3305. + *
  3306. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  3307. + *
  3308. + * This program is free software; you can redistribute it and/or modify it
  3309. + * under the terms of the GNU General Public License version 2 as published
  3310. + * by the Free Software Foundation.
  3311. + */
  3312. +
  3313. +#include <linux/mtd/mtd.h>
  3314. +#include <linux/mtd/partitions.h>
  3315. +
  3316. +#include <asm/mach-ar71xx/ar71xx.h>
  3317. +
  3318. +#include "machtype.h"
  3319. +#include "devices.h"
  3320. +#include "dev-m25p80.h"
  3321. +#include "dev-ap91-eth.h"
  3322. +#include "dev-ap91-pci.h"
  3323. +#include "dev-gpio-buttons.h"
  3324. +#include "dev-leds-gpio.h"
  3325. +#include "nvram.h"
  3326. +
  3327. +#define DIR_600_A1_GPIO_LED_WPS 0
  3328. +#define DIR_600_A1_GPIO_LED_POWER_AMBER 1
  3329. +#define DIR_600_A1_GPIO_LED_POWER_GREEN 6
  3330. +
  3331. +#define DIR_600_A1_GPIO_BTN_RESET 8
  3332. +#define DIR_600_A1_GPIO_BTN_WPS 12
  3333. +
  3334. +#define DIR_600_A1_BUTTONS_POLL_INTERVAL 20
  3335. +
  3336. +#define DIR_600_A1_NVRAM_ADDR 0x1f030000
  3337. +#define DIR_600_A1_NVRAM_SIZE 0x10000
  3338. +
  3339. +#ifdef CONFIG_MTD_PARTITIONS
  3340. +static struct mtd_partition dir_600_a1_partitions[] = {
  3341. + {
  3342. + .name = "u-boot",
  3343. + .offset = 0,
  3344. + .size = 0x030000,
  3345. + .mask_flags = MTD_WRITEABLE,
  3346. + }, {
  3347. + .name = "nvram",
  3348. + .offset = 0x030000,
  3349. + .size = 0x010000,
  3350. + }, {
  3351. + .name = "kernel",
  3352. + .offset = 0x040000,
  3353. + .size = 0x0e0000,
  3354. + }, {
  3355. + .name = "rootfs",
  3356. + .offset = 0x120000,
  3357. + .size = 0x2c0000,
  3358. + }, {
  3359. + .name = "mac",
  3360. + .offset = 0x3e0000,
  3361. + .size = 0x010000,
  3362. + .mask_flags = MTD_WRITEABLE,
  3363. + }, {
  3364. + .name = "art",
  3365. + .offset = 0x3f0000,
  3366. + .size = 0x010000,
  3367. + .mask_flags = MTD_WRITEABLE,
  3368. + }, {
  3369. + .name = "firmware",
  3370. + .offset = 0x040000,
  3371. + .size = 0x3a0000,
  3372. + }
  3373. +};
  3374. +#endif /* CONFIG_MTD_PARTITIONS */
  3375. +
  3376. +static struct flash_platform_data dir_600_a1_flash_data = {
  3377. +#ifdef CONFIG_MTD_PARTITIONS
  3378. + .parts = dir_600_a1_partitions,
  3379. + .nr_parts = ARRAY_SIZE(dir_600_a1_partitions),
  3380. +#endif
  3381. +};
  3382. +
  3383. +static struct gpio_led dir_600_a1_leds_gpio[] __initdata = {
  3384. + {
  3385. + .name = "dir-600-a1:green:power",
  3386. + .gpio = DIR_600_A1_GPIO_LED_POWER_GREEN,
  3387. + }, {
  3388. + .name = "dir-600-a1:amber:power",
  3389. + .gpio = DIR_600_A1_GPIO_LED_POWER_AMBER,
  3390. + }, {
  3391. + .name = "dir-600-a1:blue:wps",
  3392. + .gpio = DIR_600_A1_GPIO_LED_WPS,
  3393. + .active_low = 1,
  3394. + }
  3395. +};
  3396. +
  3397. +static struct gpio_button dir_600_a1_gpio_buttons[] __initdata = {
  3398. + {
  3399. + .desc = "reset",
  3400. + .type = EV_KEY,
  3401. + .code = KEY_RESTART,
  3402. + .threshold = 3,
  3403. + .gpio = DIR_600_A1_GPIO_BTN_RESET,
  3404. + .active_low = 1,
  3405. + }, {
  3406. + .desc = "wps",
  3407. + .type = EV_KEY,
  3408. + .code = KEY_WPS_BUTTON,
  3409. + .threshold = 3,
  3410. + .gpio = DIR_600_A1_GPIO_BTN_WPS,
  3411. + .active_low = 1,
  3412. + }
  3413. +};
  3414. +
  3415. +static void __init dir_600_a1_setup(void)
  3416. +{
  3417. + const char *nvram = (char *) KSEG1ADDR(DIR_600_A1_NVRAM_ADDR);
  3418. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  3419. + u8 mac_buff[6];
  3420. + u8 *mac = NULL;
  3421. +
  3422. + if (nvram_parse_mac_addr(nvram, DIR_600_A1_NVRAM_SIZE,
  3423. + "lan_mac=", mac_buff) == 0)
  3424. + mac = mac_buff;
  3425. +
  3426. + ar71xx_add_device_m25p80(&dir_600_a1_flash_data);
  3427. +
  3428. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_600_a1_leds_gpio),
  3429. + dir_600_a1_leds_gpio);
  3430. +
  3431. + ar71xx_add_device_gpio_buttons(-1, DIR_600_A1_BUTTONS_POLL_INTERVAL,
  3432. + ARRAY_SIZE(dir_600_a1_gpio_buttons),
  3433. + dir_600_a1_gpio_buttons);
  3434. +
  3435. + ap91_eth_init(mac, NULL);
  3436. + ap91_pci_init(ee, mac);
  3437. +}
  3438. +
  3439. +MIPS_MACHINE(AR71XX_MACH_DIR_600_A1, "DIR-600-A1", "D-Link DIR-600 rev. A1",
  3440. + dir_600_a1_setup);
  3441. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-615-c1.c linux-2.6.33.3/arch/mips/ar71xx/mach-dir-615-c1.c
  3442. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-615-c1.c 1970-01-01 01:00:00.000000000 +0100
  3443. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-dir-615-c1.c 2010-05-16 13:17:31.775600829 +0200
  3444. @@ -0,0 +1,173 @@
  3445. +/*
  3446. + * D-Link DIR-615 rev C1 board support
  3447. + *
  3448. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3449. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3450. + *
  3451. + * This program is free software; you can redistribute it and/or modify it
  3452. + * under the terms of the GNU General Public License version 2 as published
  3453. + * by the Free Software Foundation.
  3454. + */
  3455. +
  3456. +#include <linux/mtd/mtd.h>
  3457. +#include <linux/mtd/partitions.h>
  3458. +
  3459. +#include <asm/mach-ar71xx/ar71xx.h>
  3460. +
  3461. +#include "machtype.h"
  3462. +#include "devices.h"
  3463. +#include "dev-m25p80.h"
  3464. +#include "dev-ar913x-wmac.h"
  3465. +#include "dev-gpio-buttons.h"
  3466. +#include "dev-leds-gpio.h"
  3467. +#include "nvram.h"
  3468. +
  3469. +#define DIR_615C1_GPIO_LED_ORANGE_STATUS 1 /* ORANGE:STATUS:TRICOLOR */
  3470. +#define DIR_615C1_GPIO_LED_BLUE_WPS 3 /* BLUE:WPS */
  3471. +#define DIR_615C1_GPIO_LED_GREEN_WAN 4 /* GREEN:WAN:TRICOLOR */
  3472. +#define DIR_615C1_GPIO_LED_GREEN_WANCPU 5 /* GREEN:WAN:CPU:TRICOLOR */
  3473. +#define DIR_615C1_GPIO_LED_GREEN_WLAN 6 /* GREEN:WLAN */
  3474. +#define DIR_615C1_GPIO_LED_GREEN_STATUS 14 /* GREEN:STATUS:TRICOLOR */
  3475. +#define DIR_615C1_GPIO_LED_ORANGE_WAN 15 /* ORANGE:WAN:TRICOLOR */
  3476. +
  3477. +/* buttons may need refinement */
  3478. +
  3479. +#define DIR_615C1_GPIO_BTN_WPS 12
  3480. +#define DIR_615C1_GPIO_BTN_RESET 21
  3481. +
  3482. +#define DIR_615C1_BUTTONS_POLL_INTERVAL 20
  3483. +
  3484. +#define DIR_615C1_CONFIG_ADDR 0x1f020000
  3485. +#define DIR_615C1_CONFIG_SIZE 0x10000
  3486. +
  3487. +#ifdef CONFIG_MTD_PARTITIONS
  3488. +static struct mtd_partition dir_615c1_partitions[] = {
  3489. + {
  3490. + .name = "u-boot",
  3491. + .offset = 0,
  3492. + .size = 0x020000,
  3493. + .mask_flags = MTD_WRITEABLE,
  3494. + } , {
  3495. + .name = "config",
  3496. + .offset = 0x020000,
  3497. + .size = 0x010000,
  3498. + } , {
  3499. + .name = "kernel",
  3500. + .offset = 0x030000,
  3501. + .size = 0x0d0000,
  3502. + } , {
  3503. + .name = "rootfs",
  3504. + .offset = 0x100000,
  3505. + .size = 0x2f0000,
  3506. + } , {
  3507. + .name = "art",
  3508. + .offset = 0x3f0000,
  3509. + .size = 0x010000,
  3510. + .mask_flags = MTD_WRITEABLE,
  3511. + } , {
  3512. + .name = "firmware",
  3513. + .offset = 0x030000,
  3514. + .size = 0x3c0000,
  3515. + }
  3516. +};
  3517. +#endif /* CONFIG_MTD_PARTITIONS */
  3518. +
  3519. +static struct flash_platform_data dir_615c1_flash_data = {
  3520. +#ifdef CONFIG_MTD_PARTITIONS
  3521. + .parts = dir_615c1_partitions,
  3522. + .nr_parts = ARRAY_SIZE(dir_615c1_partitions),
  3523. +#endif
  3524. +};
  3525. +
  3526. +static struct gpio_led dir_615c1_leds_gpio[] __initdata = {
  3527. + {
  3528. + .name = "dir-615c1:orange:status",
  3529. + .gpio = DIR_615C1_GPIO_LED_ORANGE_STATUS,
  3530. + .active_low = 1,
  3531. + }, {
  3532. + .name = "dir-615c1:blue:wps",
  3533. + .gpio = DIR_615C1_GPIO_LED_BLUE_WPS,
  3534. + .active_low = 1,
  3535. + }, {
  3536. + .name = "dir-615c1:green:wan",
  3537. + .gpio = DIR_615C1_GPIO_LED_GREEN_WAN,
  3538. + .active_low = 1,
  3539. + }, {
  3540. + .name = "dir-615c1:green:wancpu",
  3541. + .gpio = DIR_615C1_GPIO_LED_GREEN_WANCPU,
  3542. + .active_low = 1,
  3543. + }, {
  3544. + .name = "dir-615c1:green:wlan",
  3545. + .gpio = DIR_615C1_GPIO_LED_GREEN_WLAN,
  3546. + .active_low = 1,
  3547. + }, {
  3548. + .name = "dir-615c1:green:status",
  3549. + .gpio = DIR_615C1_GPIO_LED_GREEN_STATUS,
  3550. + .active_low = 1,
  3551. + }, {
  3552. + .name = "dir-615c1:orange:wan",
  3553. + .gpio = DIR_615C1_GPIO_LED_ORANGE_WAN,
  3554. + .active_low = 1,
  3555. + }
  3556. +
  3557. +};
  3558. +
  3559. +static struct gpio_button dir_615c1_gpio_buttons[] __initdata = {
  3560. + {
  3561. + .desc = "reset",
  3562. + .type = EV_KEY,
  3563. + .code = KEY_RESTART,
  3564. + .threshold = 3,
  3565. + .gpio = DIR_615C1_GPIO_BTN_RESET,
  3566. + }, {
  3567. + .desc = "wps",
  3568. + .type = EV_KEY,
  3569. + .code = KEY_WPS_BUTTON,
  3570. + .threshold = 3,
  3571. + .gpio = DIR_615C1_GPIO_BTN_WPS,
  3572. + }
  3573. +};
  3574. +
  3575. +#define DIR_615C1_LAN_PHYMASK BIT(0)
  3576. +#define DIR_615C1_WAN_PHYMASK BIT(4)
  3577. +#define DIR_615C1_MDIO_MASK (~(DIR_615C1_LAN_PHYMASK | \
  3578. + DIR_615C1_WAN_PHYMASK))
  3579. +
  3580. +static void __init dir_615c1_setup(void)
  3581. +{
  3582. + const char *config = (char *) KSEG1ADDR(DIR_615C1_CONFIG_ADDR);
  3583. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3584. + u8 mac[6];
  3585. + u8 *wlan_mac = NULL;
  3586. +
  3587. + if (nvram_parse_mac_addr(config, DIR_615C1_CONFIG_SIZE,
  3588. + "lan_mac=", mac) == 0) {
  3589. + ar71xx_set_mac_base(mac);
  3590. + wlan_mac = mac;
  3591. + }
  3592. +
  3593. + ar71xx_add_device_mdio(DIR_615C1_MDIO_MASK);
  3594. +
  3595. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3596. + ar71xx_eth0_data.phy_mask = DIR_615C1_LAN_PHYMASK;
  3597. +
  3598. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3599. + ar71xx_eth1_data.phy_mask = DIR_615C1_WAN_PHYMASK;
  3600. +
  3601. + ar71xx_add_device_eth(0);
  3602. + ar71xx_add_device_eth(1);
  3603. +
  3604. + ar71xx_add_device_m25p80(&dir_615c1_flash_data);
  3605. +
  3606. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_615c1_leds_gpio),
  3607. + dir_615c1_leds_gpio);
  3608. +
  3609. + ar71xx_add_device_gpio_buttons(-1, DIR_615C1_BUTTONS_POLL_INTERVAL,
  3610. + ARRAY_SIZE(dir_615c1_gpio_buttons),
  3611. + dir_615c1_gpio_buttons);
  3612. +
  3613. + ar913x_add_device_wmac(eeprom, wlan_mac);
  3614. +}
  3615. +
  3616. +MIPS_MACHINE(AR71XX_MACH_DIR_615_C1, "DIR-615-C1", "D-Link DIR-615 rev. C1",
  3617. + dir_615c1_setup);
  3618. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-825-b1.c linux-2.6.33.3/arch/mips/ar71xx/mach-dir-825-b1.c
  3619. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-dir-825-b1.c 1970-01-01 01:00:00.000000000 +0100
  3620. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-dir-825-b1.c 2010-05-16 13:17:32.715628389 +0200
  3621. @@ -0,0 +1,192 @@
  3622. +/*
  3623. + * D-Link DIR-825 rev. B1 board support
  3624. + *
  3625. + * Copyright (C) 2009 Lukas Kuna, Evkanet, s.r.o.
  3626. + *
  3627. + * based on mach-wndr3700.c
  3628. + *
  3629. + * This program is free software; you can redistribute it and/or modify it
  3630. + * under the terms of the GNU General Public License version 2 as published
  3631. + * by the Free Software Foundation.
  3632. + */
  3633. +
  3634. +#include <linux/platform_device.h>
  3635. +#include <linux/mtd/mtd.h>
  3636. +#include <linux/mtd/partitions.h>
  3637. +#include <linux/delay.h>
  3638. +#include <linux/rtl8366s.h>
  3639. +
  3640. +#include <asm/mach-ar71xx/ar71xx.h>
  3641. +
  3642. +#include "machtype.h"
  3643. +#include "devices.h"
  3644. +#include "dev-m25p80.h"
  3645. +#include "dev-ap94-pci.h"
  3646. +#include "dev-gpio-buttons.h"
  3647. +#include "dev-leds-gpio.h"
  3648. +#include "dev-usb.h"
  3649. +
  3650. +#define DIR825B1_GPIO_LED_BLUE_USB 0
  3651. +#define DIR825B1_GPIO_LED_ORANGE_POWER 1
  3652. +#define DIR825B1_GPIO_LED_BLUE_POWER 2
  3653. +#define DIR825B1_GPIO_LED_BLUE_POWERSAVE 4
  3654. +#define DIR825B1_GPIO_LED_ORANGE_PLANET 6
  3655. +#define DIR825B1_GPIO_LED_BLUE_PLANET 11
  3656. +
  3657. +#define DIR825B1_GPIO_BTN_RESET 3
  3658. +#define DIR825B1_GPIO_BTN_POWERSAVE 8
  3659. +
  3660. +#define DIR825B1_GPIO_RTL8366_SDA 5
  3661. +#define DIR825B1_GPIO_RTL8366_SCK 7
  3662. +
  3663. +#define DIR825B1_BUTTONS_POLL_INTERVAL 20
  3664. +
  3665. +#define DIR825B1_CAL_LOCATION_0 0x1f661000
  3666. +#define DIR825B1_CAL_LOCATION_1 0x1f665000
  3667. +
  3668. +#define DIR825B1_MAC_LOCATION_0 0x2ffa81b8
  3669. +#define DIR825B1_MAC_LOCATION_1 0x2ffa8370
  3670. +
  3671. +#ifdef CONFIG_MTD_PARTITIONS
  3672. +static struct mtd_partition dir825b1_partitions[] = {
  3673. + {
  3674. + .name = "uboot",
  3675. + .offset = 0,
  3676. + .size = 0x040000,
  3677. + .mask_flags = MTD_WRITEABLE,
  3678. + } , {
  3679. + .name = "config",
  3680. + .offset = 0x040000,
  3681. + .size = 0x010000,
  3682. + .mask_flags = MTD_WRITEABLE,
  3683. + } , {
  3684. + .name = "firmware",
  3685. + .offset = 0x050000,
  3686. + .size = 0x610000,
  3687. + } , {
  3688. + .name = "caldata",
  3689. + .offset = 0x660000,
  3690. + .size = 0x010000,
  3691. + .mask_flags = MTD_WRITEABLE,
  3692. + } , {
  3693. + .name = "unknown",
  3694. + .offset = 0x670000,
  3695. + .size = 0x190000,
  3696. + .mask_flags = MTD_WRITEABLE,
  3697. + }
  3698. +};
  3699. +#endif /* CONFIG_MTD_PARTITIONS */
  3700. +
  3701. +static struct flash_platform_data dir825b1_flash_data = {
  3702. +#ifdef CONFIG_MTD_PARTITIONS
  3703. + .parts = dir825b1_partitions,
  3704. + .nr_parts = ARRAY_SIZE(dir825b1_partitions),
  3705. +#endif
  3706. +};
  3707. +
  3708. +static struct gpio_led dir825b1_leds_gpio[] __initdata = {
  3709. + {
  3710. + .name = "dir825b1:blue:usb",
  3711. + .gpio = DIR825B1_GPIO_LED_BLUE_USB,
  3712. + .active_low = 1,
  3713. + }, {
  3714. + .name = "dir825b1:orange:power",
  3715. + .gpio = DIR825B1_GPIO_LED_ORANGE_POWER,
  3716. + .active_low = 1,
  3717. + }, {
  3718. + .name = "dir825b1:blue:power",
  3719. + .gpio = DIR825B1_GPIO_LED_BLUE_POWER,
  3720. + .active_low = 1,
  3721. + }, {
  3722. + .name = "dir825b1:blue:powersave",
  3723. + .gpio = DIR825B1_GPIO_LED_BLUE_POWERSAVE,
  3724. + .active_low = 1,
  3725. + }, {
  3726. + .name = "dir825b1:orange:planet",
  3727. + .gpio = DIR825B1_GPIO_LED_ORANGE_PLANET,
  3728. + .active_low = 1,
  3729. + }, {
  3730. + .name = "dir825b1:blue:planet",
  3731. + .gpio = DIR825B1_GPIO_LED_BLUE_PLANET,
  3732. + .active_low = 1,
  3733. + }
  3734. +};
  3735. +
  3736. +static struct gpio_button dir825b1_gpio_buttons[] __initdata = {
  3737. + {
  3738. + .desc = "reset",
  3739. + .type = EV_KEY,
  3740. + .code = KEY_RESTART,
  3741. + .threshold = 3,
  3742. + .gpio = DIR825B1_GPIO_BTN_RESET,
  3743. + .active_low = 1,
  3744. + } , {
  3745. + .desc = "powersave",
  3746. + .type = EV_KEY,
  3747. + .code = BTN_1,
  3748. + .threshold = 3,
  3749. + .gpio = DIR825B1_GPIO_BTN_POWERSAVE,
  3750. + .active_low = 1,
  3751. + }
  3752. +};
  3753. +
  3754. +static struct rtl8366s_platform_data dir825b1_rtl8366s_data = {
  3755. + .gpio_sda = DIR825B1_GPIO_RTL8366_SDA,
  3756. + .gpio_sck = DIR825B1_GPIO_RTL8366_SCK,
  3757. +};
  3758. +
  3759. +static struct platform_device dir825b1_rtl8366s_device = {
  3760. + .name = RTL8366S_DRIVER_NAME,
  3761. + .id = -1,
  3762. + .dev = {
  3763. + .platform_data = &dir825b1_rtl8366s_data,
  3764. + }
  3765. +};
  3766. +
  3767. +static void __init dir825b1_setup(void)
  3768. +{
  3769. + u8 mac[6], i;
  3770. +
  3771. + memcpy(mac, (u8*)KSEG1ADDR(DIR825B1_MAC_LOCATION_1), 6);
  3772. + for(i = 5; i >= 3; i--)
  3773. + if(++mac[i] != 0x00) break;
  3774. +
  3775. + ar71xx_set_mac_base(mac);
  3776. +
  3777. + ar71xx_add_device_mdio(0x0);
  3778. +
  3779. + ar71xx_eth0_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  3780. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3781. + ar71xx_eth0_data.speed = SPEED_1000;
  3782. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3783. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  3784. +
  3785. + ar71xx_eth1_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  3786. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3787. + ar71xx_eth1_data.phy_mask = 0x10;
  3788. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  3789. +
  3790. + ar71xx_add_device_eth(0);
  3791. + ar71xx_add_device_eth(1);
  3792. +
  3793. + ar71xx_add_device_m25p80(&dir825b1_flash_data);
  3794. +
  3795. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir825b1_leds_gpio),
  3796. + dir825b1_leds_gpio);
  3797. +
  3798. + ar71xx_add_device_gpio_buttons(-1, DIR825B1_BUTTONS_POLL_INTERVAL,
  3799. + ARRAY_SIZE(dir825b1_gpio_buttons),
  3800. + dir825b1_gpio_buttons);
  3801. +
  3802. + ar71xx_add_device_usb();
  3803. +
  3804. + platform_device_register(&dir825b1_rtl8366s_device);
  3805. +
  3806. + ap94_pci_init((u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_0),
  3807. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_0),
  3808. + (u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_1),
  3809. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_1));
  3810. +}
  3811. +
  3812. +MIPS_MACHINE(AR71XX_MACH_DIR_825_B1, "DIR-825-B1", "D-Link DIR-825 rev. B1",
  3813. + dir825b1_setup);
  3814. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-mzk-w04nu.c linux-2.6.33.3/arch/mips/ar71xx/mach-mzk-w04nu.c
  3815. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-mzk-w04nu.c 1970-01-01 01:00:00.000000000 +0100
  3816. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-mzk-w04nu.c 2010-05-16 13:17:31.807598757 +0200
  3817. @@ -0,0 +1,165 @@
  3818. +/*
  3819. + * Planex MZK-W04NU board support
  3820. + *
  3821. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  3822. + *
  3823. + * This program is free software; you can redistribute it and/or modify it
  3824. + * under the terms of the GNU General Public License version 2 as published
  3825. + * by the Free Software Foundation.
  3826. + */
  3827. +
  3828. +#include <linux/mtd/mtd.h>
  3829. +#include <linux/mtd/partitions.h>
  3830. +
  3831. +#include <asm/mach-ar71xx/ar71xx.h>
  3832. +
  3833. +#include "machtype.h"
  3834. +#include "devices.h"
  3835. +#include "dev-ar913x-wmac.h"
  3836. +#include "dev-gpio-buttons.h"
  3837. +#include "dev-leds-gpio.h"
  3838. +#include "dev-m25p80.h"
  3839. +#include "dev-usb.h"
  3840. +
  3841. +#define MZK_W04NU_GPIO_LED_USB 0
  3842. +#define MZK_W04NU_GPIO_LED_STATUS 1
  3843. +#define MZK_W04NU_GPIO_LED_WPS 3
  3844. +#define MZK_W04NU_GPIO_LED_WLAN 6
  3845. +#define MZK_W04NU_GPIO_LED_AP 15
  3846. +#define MZK_W04NU_GPIO_LED_ROUTER 16
  3847. +
  3848. +#define MZK_W04NU_GPIO_BTN_APROUTER 5
  3849. +#define MZK_W04NU_GPIO_BTN_WPS 12
  3850. +#define MZK_W04NU_GPIO_BTN_RESET 21
  3851. +
  3852. +#define MZK_W04NU_BUTTONS_POLL_INTERVAL 20
  3853. +
  3854. +#ifdef CONFIG_MTD_PARTITIONS
  3855. +static struct mtd_partition mzk_w04nu_partitions[] = {
  3856. + {
  3857. + .name = "u-boot",
  3858. + .offset = 0,
  3859. + .size = 0x040000,
  3860. + .mask_flags = MTD_WRITEABLE,
  3861. + } , {
  3862. + .name = "u-boot-env",
  3863. + .offset = 0x040000,
  3864. + .size = 0x010000,
  3865. + } , {
  3866. + .name = "kernel",
  3867. + .offset = 0x050000,
  3868. + .size = 0x160000,
  3869. + } , {
  3870. + .name = "rootfs",
  3871. + .offset = 0x1b0000,
  3872. + .size = 0x630000,
  3873. + } , {
  3874. + .name = "art",
  3875. + .offset = 0x7e0000,
  3876. + .size = 0x020000,
  3877. + .mask_flags = MTD_WRITEABLE,
  3878. + } , {
  3879. + .name = "firmware",
  3880. + .offset = 0x050000,
  3881. + .size = 0x790000,
  3882. + }
  3883. +};
  3884. +#endif /* CONFIG_MTD_PARTITIONS */
  3885. +
  3886. +static struct flash_platform_data mzk_w04nu_flash_data = {
  3887. +#ifdef CONFIG_MTD_PARTITIONS
  3888. + .parts = mzk_w04nu_partitions,
  3889. + .nr_parts = ARRAY_SIZE(mzk_w04nu_partitions),
  3890. +#endif
  3891. +};
  3892. +
  3893. +static struct gpio_led mzk_w04nu_leds_gpio[] __initdata = {
  3894. + {
  3895. + .name = "mzk-w04nu:green:status",
  3896. + .gpio = MZK_W04NU_GPIO_LED_STATUS,
  3897. + .active_low = 1,
  3898. + }, {
  3899. + .name = "mzk-w04nu:blue:wps",
  3900. + .gpio = MZK_W04NU_GPIO_LED_WPS,
  3901. + .active_low = 1,
  3902. + }, {
  3903. + .name = "mzk-w04nu:green:wlan",
  3904. + .gpio = MZK_W04NU_GPIO_LED_WLAN,
  3905. + .active_low = 1,
  3906. + }, {
  3907. + .name = "mzk-w04nu:green:usb",
  3908. + .gpio = MZK_W04NU_GPIO_LED_USB,
  3909. + .active_low = 1,
  3910. + }, {
  3911. + .name = "mzk-w04nu:green:ap",
  3912. + .gpio = MZK_W04NU_GPIO_LED_AP,
  3913. + .active_low = 1,
  3914. + }, {
  3915. + .name = "mzk-w04nu:green:router",
  3916. + .gpio = MZK_W04NU_GPIO_LED_ROUTER,
  3917. + .active_low = 1,
  3918. + }
  3919. +};
  3920. +
  3921. +static struct gpio_button mzk_w04nu_gpio_buttons[] __initdata = {
  3922. + {
  3923. + .desc = "reset",
  3924. + .type = EV_KEY,
  3925. + .code = KEY_RESTART,
  3926. + .threshold = 3,
  3927. + .gpio = MZK_W04NU_GPIO_BTN_RESET,
  3928. + .active_low = 1,
  3929. + }, {
  3930. + .desc = "wps",
  3931. + .type = EV_KEY,
  3932. + .code = KEY_WPS_BUTTON,
  3933. + .threshold = 3,
  3934. + .gpio = MZK_W04NU_GPIO_BTN_WPS,
  3935. + .active_low = 1,
  3936. + }, {
  3937. + .desc = "aprouter",
  3938. + .type = EV_KEY,
  3939. + .code = BTN_2,
  3940. + .threshold = 3,
  3941. + .gpio = MZK_W04NU_GPIO_BTN_APROUTER,
  3942. + .active_low = 0,
  3943. + }
  3944. +};
  3945. +
  3946. +#define MZK_W04NU_WAN_PHYMASK BIT(4)
  3947. +#define MZK_W04NU_MDIO_MASK (~MZK_W04NU_WAN_PHYMASK)
  3948. +
  3949. +static void __init mzk_w04nu_setup(void)
  3950. +{
  3951. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3952. +
  3953. + ar71xx_set_mac_base(eeprom);
  3954. +
  3955. + ar71xx_add_device_mdio(MZK_W04NU_MDIO_MASK);
  3956. +
  3957. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3958. + ar71xx_eth0_data.speed = SPEED_100;
  3959. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3960. + ar71xx_eth0_data.has_ar8216 = 1;
  3961. +
  3962. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3963. + ar71xx_eth1_data.phy_mask = MZK_W04NU_WAN_PHYMASK;
  3964. +
  3965. + ar71xx_add_device_eth(0);
  3966. + ar71xx_add_device_eth(1);
  3967. +
  3968. + ar71xx_add_device_m25p80(&mzk_w04nu_flash_data);
  3969. +
  3970. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w04nu_leds_gpio),
  3971. + mzk_w04nu_leds_gpio);
  3972. +
  3973. + ar71xx_add_device_gpio_buttons(-1, MZK_W04NU_BUTTONS_POLL_INTERVAL,
  3974. + ARRAY_SIZE(mzk_w04nu_gpio_buttons),
  3975. + mzk_w04nu_gpio_buttons);
  3976. + ar71xx_add_device_usb();
  3977. +
  3978. + ar913x_add_device_wmac(eeprom, NULL);
  3979. +}
  3980. +
  3981. +MIPS_MACHINE(AR71XX_MACH_MZK_W04NU, "MZK-W04NU", "Planex MZK-W04NU",
  3982. + mzk_w04nu_setup);
  3983. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-mzk-w300nh.c linux-2.6.33.3/arch/mips/ar71xx/mach-mzk-w300nh.c
  3984. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-mzk-w300nh.c 1970-01-01 01:00:00.000000000 +0100
  3985. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-mzk-w300nh.c 2010-05-16 13:17:32.931648635 +0200
  3986. @@ -0,0 +1,158 @@
  3987. +/*
  3988. + * Planex MZK-W300NH board support
  3989. + *
  3990. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3991. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3992. + *
  3993. + * This program is free software; you can redistribute it and/or modify it
  3994. + * under the terms of the GNU General Public License version 2 as published
  3995. + * by the Free Software Foundation.
  3996. + */
  3997. +
  3998. +#include <linux/mtd/mtd.h>
  3999. +#include <linux/mtd/partitions.h>
  4000. +
  4001. +#include <asm/mach-ar71xx/ar71xx.h>
  4002. +
  4003. +#include "machtype.h"
  4004. +#include "devices.h"
  4005. +#include "dev-m25p80.h"
  4006. +#include "dev-ar913x-wmac.h"
  4007. +#include "dev-gpio-buttons.h"
  4008. +#include "dev-leds-gpio.h"
  4009. +
  4010. +#define MZK_W300NH_GPIO_LED_STATUS 1
  4011. +#define MZK_W300NH_GPIO_LED_WPS 3
  4012. +#define MZK_W300NH_GPIO_LED_WLAN 6
  4013. +#define MZK_W300NH_GPIO_LED_AP 15
  4014. +#define MZK_W300NH_GPIO_LED_ROUTER 16
  4015. +
  4016. +#define MZK_W300NH_GPIO_BTN_APROUTER 5
  4017. +#define MZK_W300NH_GPIO_BTN_WPS 12
  4018. +#define MZK_W300NH_GPIO_BTN_RESET 21
  4019. +
  4020. +#define MZK_W04NU_BUTTONS_POLL_INTERVAL 20
  4021. +
  4022. +#ifdef CONFIG_MTD_PARTITIONS
  4023. +static struct mtd_partition mzk_w300nh_partitions[] = {
  4024. + {
  4025. + .name = "u-boot",
  4026. + .offset = 0,
  4027. + .size = 0x040000,
  4028. + .mask_flags = MTD_WRITEABLE,
  4029. + } , {
  4030. + .name = "u-boot-env",
  4031. + .offset = 0x040000,
  4032. + .size = 0x010000,
  4033. + } , {
  4034. + .name = "kernel",
  4035. + .offset = 0x050000,
  4036. + .size = 0x160000,
  4037. + } , {
  4038. + .name = "rootfs",
  4039. + .offset = 0x1b0000,
  4040. + .size = 0x630000,
  4041. + } , {
  4042. + .name = "art",
  4043. + .offset = 0x7e0000,
  4044. + .size = 0x020000,
  4045. + .mask_flags = MTD_WRITEABLE,
  4046. + } , {
  4047. + .name = "firmware",
  4048. + .offset = 0x050000,
  4049. + .size = 0x790000,
  4050. + }
  4051. +};
  4052. +#endif /* CONFIG_MTD_PARTITIONS */
  4053. +
  4054. +static struct flash_platform_data mzk_w300nh_flash_data = {
  4055. +#ifdef CONFIG_MTD_PARTITIONS
  4056. + .parts = mzk_w300nh_partitions,
  4057. + .nr_parts = ARRAY_SIZE(mzk_w300nh_partitions),
  4058. +#endif
  4059. +};
  4060. +
  4061. +static struct gpio_led mzk_w300nh_leds_gpio[] __initdata = {
  4062. + {
  4063. + .name = "mzk-w300nh:green:status",
  4064. + .gpio = MZK_W300NH_GPIO_LED_STATUS,
  4065. + .active_low = 1,
  4066. + }, {
  4067. + .name = "mzk-w300nh:blue:wps",
  4068. + .gpio = MZK_W300NH_GPIO_LED_WPS,
  4069. + .active_low = 1,
  4070. + }, {
  4071. + .name = "mzk-w300nh:green:wlan",
  4072. + .gpio = MZK_W300NH_GPIO_LED_WLAN,
  4073. + .active_low = 1,
  4074. + }, {
  4075. + .name = "mzk-w300nh:green:ap",
  4076. + .gpio = MZK_W300NH_GPIO_LED_AP,
  4077. + .active_low = 1,
  4078. + }, {
  4079. + .name = "mzk-w300nh:green:router",
  4080. + .gpio = MZK_W300NH_GPIO_LED_ROUTER,
  4081. + .active_low = 1,
  4082. + }
  4083. +};
  4084. +
  4085. +static struct gpio_button mzk_w300nh_gpio_buttons[] __initdata = {
  4086. + {
  4087. + .desc = "reset",
  4088. + .type = EV_KEY,
  4089. + .code = KEY_RESTART,
  4090. + .threshold = 3,
  4091. + .gpio = MZK_W300NH_GPIO_BTN_RESET,
  4092. + .active_low = 1,
  4093. + }, {
  4094. + .desc = "wps",
  4095. + .type = EV_KEY,
  4096. + .code = KEY_WPS_BUTTON,
  4097. + .threshold = 3,
  4098. + .gpio = MZK_W300NH_GPIO_BTN_WPS,
  4099. + .active_low = 1,
  4100. + }, {
  4101. + .desc = "aprouter",
  4102. + .type = EV_KEY,
  4103. + .code = BTN_2,
  4104. + .threshold = 3,
  4105. + .gpio = MZK_W300NH_GPIO_BTN_APROUTER,
  4106. + .active_low = 0,
  4107. + }
  4108. +};
  4109. +
  4110. +#define MZK_W300NH_WAN_PHYMASK BIT(4)
  4111. +#define MZK_W300NH_MDIO_MASK (~MZK_W300NH_WAN_PHYMASK)
  4112. +
  4113. +static void __init mzk_w300nh_setup(void)
  4114. +{
  4115. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  4116. +
  4117. + ar71xx_set_mac_base(eeprom);
  4118. +
  4119. + ar71xx_add_device_mdio(MZK_W300NH_MDIO_MASK);
  4120. +
  4121. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4122. + ar71xx_eth0_data.speed = SPEED_100;
  4123. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4124. + ar71xx_eth0_data.has_ar8216 = 1;
  4125. +
  4126. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4127. + ar71xx_eth1_data.phy_mask = MZK_W300NH_WAN_PHYMASK;
  4128. +
  4129. + ar71xx_add_device_eth(0);
  4130. + ar71xx_add_device_eth(1);
  4131. +
  4132. + ar71xx_add_device_m25p80(&mzk_w300nh_flash_data);
  4133. +
  4134. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w300nh_leds_gpio),
  4135. + mzk_w300nh_leds_gpio);
  4136. +
  4137. + ar71xx_add_device_gpio_buttons(-1, MZK_W04NU_BUTTONS_POLL_INTERVAL,
  4138. + ARRAY_SIZE(mzk_w300nh_gpio_buttons),
  4139. + mzk_w300nh_gpio_buttons);
  4140. + ar913x_add_device_wmac(eeprom, NULL);
  4141. +}
  4142. +
  4143. +MIPS_MACHINE(AR71XX_MACH_MZK_W300NH, "MZK-W300NH", "Planex MZK-W300NH",
  4144. + mzk_w300nh_setup);
  4145. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-nbg460n.c linux-2.6.33.3/arch/mips/ar71xx/mach-nbg460n.c
  4146. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-nbg460n.c 1970-01-01 01:00:00.000000000 +0100
  4147. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-nbg460n.c 2010-05-16 13:17:32.947611843 +0200
  4148. @@ -0,0 +1,222 @@
  4149. +/*
  4150. + * Zyxel NBG 460N/550N/550NH board support
  4151. + *
  4152. + * Copyright (C) 2010 Michael Kurz <michi.kurz@googlemail.com>
  4153. + *
  4154. + * based on mach-tl-wr1043nd.c
  4155. + *
  4156. + * This program is free software; you can redistribute it and/or modify it
  4157. + * under the terms of the GNU General Public License version 2 as published
  4158. + * by the Free Software Foundation.
  4159. + */
  4160. +
  4161. +#include <linux/platform_device.h>
  4162. +#include <linux/mtd/mtd.h>
  4163. +#include <linux/mtd/partitions.h>
  4164. +#include <linux/delay.h>
  4165. +#include <linux/rtl8366s.h>
  4166. +
  4167. +#include <linux/i2c.h>
  4168. +#include <linux/i2c-algo-bit.h>
  4169. +#include <linux/i2c-gpio.h>
  4170. +
  4171. +#include <asm/mach-ar71xx/ar71xx.h>
  4172. +
  4173. +#include "machtype.h"
  4174. +#include "devices.h"
  4175. +#include "dev-m25p80.h"
  4176. +#include "dev-ar913x-wmac.h"
  4177. +#include "dev-gpio-buttons.h"
  4178. +#include "dev-leds-gpio.h"
  4179. +
  4180. +/* LEDs */
  4181. +#define NBG460N_GPIO_LED_WPS 3
  4182. +#define NBG460N_GPIO_LED_WAN 6
  4183. +#define NBG460N_GPIO_LED_POWER 14
  4184. +#define NBG460N_GPIO_LED_WLAN 15
  4185. +
  4186. +/* Buttons */
  4187. +#define NBG460N_GPIO_BTN_WPS 12
  4188. +#define NBG460N_GPIO_BTN_RESET 21
  4189. +#define NBG460N_BUTTONS_POLL_INTERVAL 20
  4190. +
  4191. +/* RTC chip PCF8563 I2C interface */
  4192. +#define NBG460N_GPIO_PCF8563_SDA 8
  4193. +#define NBG460N_GPIO_PCF8563_SCK 7
  4194. +
  4195. +/* Switch configuration I2C interface */
  4196. +#define NBG460N_GPIO_RTL8366_SDA 16
  4197. +#define NBG460N_GPIO_RTL8366_SCK 18
  4198. +
  4199. +#ifdef CONFIG_MTD_PARTITIONS
  4200. +static struct mtd_partition nbg460n_partitions[] = {
  4201. + {
  4202. + .name = "Bootbase",
  4203. + .offset = 0,
  4204. + .size = 0x010000,
  4205. + .mask_flags = MTD_WRITEABLE,
  4206. + } , {
  4207. + .name = "U-Boot Config",
  4208. + .offset = 0x010000,
  4209. + .size = 0x030000,
  4210. + } , {
  4211. + .name = "U-Boot",
  4212. + .offset = 0x040000,
  4213. + .size = 0x030000,
  4214. + } , {
  4215. + .name = "linux",
  4216. + .offset = 0x070000,
  4217. + .size = 0x0e0000,
  4218. + } , {
  4219. + .name = "rootfs",
  4220. + .offset = 0x150000,
  4221. + .size = 0x2a0000,
  4222. + } , {
  4223. + .name = "CalibData",
  4224. + .offset = 0x3f0000,
  4225. + .size = 0x010000,
  4226. + .mask_flags = MTD_WRITEABLE,
  4227. + } , {
  4228. + .name = "firmware",
  4229. + .offset = 0x070000,
  4230. + .size = 0x380000,
  4231. + }
  4232. +};
  4233. +#endif /* CONFIG_MTD_PARTITIONS */
  4234. +
  4235. +static struct flash_platform_data nbg460n_flash_data = {
  4236. +#ifdef CONFIG_MTD_PARTITIONS
  4237. + .parts = nbg460n_partitions,
  4238. + .nr_parts = ARRAY_SIZE(nbg460n_partitions),
  4239. +#endif
  4240. +};
  4241. +
  4242. +static struct gpio_led nbg460n_leds_gpio[] __initdata = {
  4243. + {
  4244. + .name = "nbg460n:green:power",
  4245. + .gpio = NBG460N_GPIO_LED_POWER,
  4246. + .active_low = 0,
  4247. + .default_trigger = "default-on",
  4248. + }, {
  4249. + .name = "nbg460n:green:wps",
  4250. + .gpio = NBG460N_GPIO_LED_WPS,
  4251. + .active_low = 0,
  4252. + }, {
  4253. + .name = "nbg460n:green:wlan",
  4254. + .gpio = NBG460N_GPIO_LED_WLAN,
  4255. + .active_low = 0,
  4256. + }, {
  4257. + /* Not really for controlling the LED,
  4258. + when set low the LED blinks uncontrollable */
  4259. + .name = "nbg460n:green:wan",
  4260. + .gpio = NBG460N_GPIO_LED_WAN,
  4261. + .active_low = 0,
  4262. + }
  4263. +};
  4264. +
  4265. +static struct gpio_button nbg460n_gpio_buttons[] __initdata = {
  4266. + {
  4267. + .desc = "reset",
  4268. + .type = EV_KEY,
  4269. + .code = KEY_RESTART,
  4270. + .threshold = 3,
  4271. + .gpio = NBG460N_GPIO_BTN_RESET,
  4272. + .active_low = 1,
  4273. + }, {
  4274. + .desc = "wps",
  4275. + .type = EV_KEY,
  4276. + .code = KEY_WPS_BUTTON,
  4277. + .threshold = 3,
  4278. + .gpio = NBG460N_GPIO_BTN_WPS,
  4279. + .active_low = 1,
  4280. + }
  4281. +};
  4282. +
  4283. +static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
  4284. + .sda_pin = NBG460N_GPIO_PCF8563_SDA,
  4285. + .scl_pin = NBG460N_GPIO_PCF8563_SCK,
  4286. + .udelay = 10,
  4287. +};
  4288. +
  4289. +static struct platform_device nbg460n_i2c_device = {
  4290. + .name = "i2c-gpio",
  4291. + .id = -1,
  4292. + .num_resources = 0,
  4293. + .resource = NULL,
  4294. + .dev = {
  4295. + .platform_data = &nbg460n_i2c_device_platdata,
  4296. + },
  4297. +};
  4298. +
  4299. +static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
  4300. + {
  4301. + I2C_BOARD_INFO("pcf8563", 0x51),
  4302. + },
  4303. +};
  4304. +
  4305. +static void __devinit nbg460n_i2c_init(void)
  4306. +{
  4307. + /* The gpio interface */
  4308. + platform_device_register(&nbg460n_i2c_device);
  4309. + /* I2C devices */
  4310. + i2c_register_board_info(0, nbg460n_i2c_devs,
  4311. + ARRAY_SIZE(nbg460n_i2c_devs));
  4312. +}
  4313. +
  4314. +
  4315. +static struct rtl8366s_platform_data nbg460n_rtl8366s_data = {
  4316. + .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
  4317. + .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
  4318. +};
  4319. +
  4320. +static struct platform_device nbg460n_rtl8366s_device = {
  4321. + .name = RTL8366S_DRIVER_NAME,
  4322. + .id = -1,
  4323. + .dev = {
  4324. + .platform_data = &nbg460n_rtl8366s_data,
  4325. + }
  4326. +};
  4327. +
  4328. +static void __init nbg460n_setup(void)
  4329. +{
  4330. + /* end of bootloader sector contains mac address*/
  4331. + u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
  4332. + /* last sector contains wlan calib data */
  4333. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  4334. +
  4335. + ar71xx_set_mac_base(mac);
  4336. +
  4337. + /* LAN Port */
  4338. + ar71xx_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  4339. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4340. + ar71xx_eth0_data.speed = SPEED_1000;
  4341. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4342. +
  4343. + /* WAN Port */
  4344. + ar71xx_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  4345. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4346. + ar71xx_eth1_data.phy_mask = 0x10;
  4347. +
  4348. + ar71xx_add_device_eth(0);
  4349. + ar71xx_add_device_eth(1);
  4350. +
  4351. + /* register the switch phy */
  4352. + platform_device_register(&nbg460n_rtl8366s_device);
  4353. +
  4354. + /* register flash */
  4355. + ar71xx_add_device_m25p80(&nbg460n_flash_data);
  4356. +
  4357. + ar913x_add_device_wmac(eeprom, mac);
  4358. +
  4359. + /* register RTC chip */
  4360. + nbg460n_i2c_init();
  4361. +
  4362. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
  4363. + nbg460n_leds_gpio);
  4364. +
  4365. + ar71xx_add_device_gpio_buttons(-1, NBG460N_BUTTONS_POLL_INTERVAL,
  4366. + ARRAY_SIZE(nbg460n_gpio_buttons),
  4367. + nbg460n_gpio_buttons);
  4368. +}
  4369. +
  4370. +MIPS_MACHINE(AR71XX_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH", nbg460n_setup);
  4371. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb42.c linux-2.6.33.3/arch/mips/ar71xx/mach-pb42.c
  4372. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb42.c 1970-01-01 01:00:00.000000000 +0100
  4373. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-pb42.c 2010-03-23 20:31:05.092710513 +0100
  4374. @@ -0,0 +1,71 @@
  4375. +/*
  4376. + * Atheros PB42 board support
  4377. + *
  4378. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4379. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4380. + *
  4381. + * This program is free software; you can redistribute it and/or modify it
  4382. + * under the terms of the GNU General Public License version 2 as published
  4383. + * by the Free Software Foundation.
  4384. + */
  4385. +
  4386. +#include <asm/mach-ar71xx/ar71xx.h>
  4387. +
  4388. +#include "machtype.h"
  4389. +#include "devices.h"
  4390. +#include "dev-m25p80.h"
  4391. +#include "dev-gpio-buttons.h"
  4392. +#include "dev-pb42-pci.h"
  4393. +#include "dev-usb.h"
  4394. +
  4395. +#define PB42_BUTTONS_POLL_INTERVAL 20
  4396. +
  4397. +#define PB42_GPIO_BTN_SW4 8
  4398. +#define PB42_GPIO_BTN_SW5 3
  4399. +
  4400. +static struct gpio_button pb42_gpio_buttons[] __initdata = {
  4401. + {
  4402. + .desc = "sw4",
  4403. + .type = EV_KEY,
  4404. + .code = BTN_0,
  4405. + .threshold = 3,
  4406. + .gpio = PB42_GPIO_BTN_SW4,
  4407. + .active_low = 1,
  4408. + } , {
  4409. + .desc = "sw5",
  4410. + .type = EV_KEY,
  4411. + .code = BTN_1,
  4412. + .threshold = 3,
  4413. + .gpio = PB42_GPIO_BTN_SW5,
  4414. + .active_low = 1,
  4415. + }
  4416. +};
  4417. +
  4418. +#define PB42_WAN_PHYMASK BIT(20)
  4419. +#define PB42_LAN_PHYMASK (BIT(16) | BIT(17) | BIT(18) | BIT(19))
  4420. +#define PB42_MDIO_PHYMASK (PB42_LAN_PHYMASK | PB42_WAN_PHYMASK)
  4421. +
  4422. +static void __init pb42_init(void)
  4423. +{
  4424. + ar71xx_add_device_m25p80(NULL);
  4425. +
  4426. + ar71xx_add_device_mdio(~PB42_MDIO_PHYMASK);
  4427. +
  4428. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4429. + ar71xx_eth0_data.phy_mask = PB42_WAN_PHYMASK;
  4430. +
  4431. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4432. + ar71xx_eth1_data.speed = SPEED_100;
  4433. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4434. +
  4435. + ar71xx_add_device_eth(0);
  4436. + ar71xx_add_device_eth(1);
  4437. +
  4438. + ar71xx_add_device_gpio_buttons(-1, PB42_BUTTONS_POLL_INTERVAL,
  4439. + ARRAY_SIZE(pb42_gpio_buttons),
  4440. + pb42_gpio_buttons);
  4441. +
  4442. + pb42_pci_init();
  4443. +}
  4444. +
  4445. +MIPS_MACHINE(AR71XX_MACH_PB42, "PB42", "Atheros PB42", pb42_init);
  4446. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb44.c linux-2.6.33.3/arch/mips/ar71xx/mach-pb44.c
  4447. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb44.c 1970-01-01 01:00:00.000000000 +0100
  4448. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-pb44.c 2010-05-16 13:17:32.783600171 +0200
  4449. @@ -0,0 +1,207 @@
  4450. +/*
  4451. + * Atheros PB44 board support
  4452. + *
  4453. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  4454. + *
  4455. + * This program is free software; you can redistribute it and/or modify it
  4456. + * under the terms of the GNU General Public License version 2 as published
  4457. + * by the Free Software Foundation.
  4458. + */
  4459. +
  4460. +#include <linux/init.h>
  4461. +#include <linux/bitops.h>
  4462. +#include <linux/delay.h>
  4463. +#include <linux/platform_device.h>
  4464. +#include <linux/spi/spi.h>
  4465. +#include <linux/spi/flash.h>
  4466. +#include <linux/spi/vsc7385.h>
  4467. +#include <linux/i2c.h>
  4468. +#include <linux/i2c-gpio.h>
  4469. +#include <linux/i2c/pcf857x.h>
  4470. +
  4471. +#include <asm/mach-ar71xx/ar71xx.h>
  4472. +
  4473. +#include "machtype.h"
  4474. +#include "devices.h"
  4475. +#include "dev-pb42-pci.h"
  4476. +#include "dev-gpio-buttons.h"
  4477. +#include "dev-leds-gpio.h"
  4478. +#include "dev-usb.h"
  4479. +
  4480. +#define PB44_PCF8757_VSC7395_CS 0
  4481. +#define PB44_PCF8757_STEREO_CS 1
  4482. +#define PB44_PCF8757_SLIC_CS0 2
  4483. +#define PB44_PCF8757_SLIC_TEST 3
  4484. +#define PB44_PCF8757_SLIC_INT0 4
  4485. +#define PB44_PCF8757_SLIC_INT1 5
  4486. +#define PB44_PCF8757_SW_RESET 6
  4487. +#define PB44_PCF8757_SW_JUMP 8
  4488. +#define PB44_PCF8757_LED_JUMP1 9
  4489. +#define PB44_PCF8757_LED_JUMP2 10
  4490. +#define PB44_PCF8757_TP24 11
  4491. +#define PB44_PCF8757_TP25 12
  4492. +#define PB44_PCF8757_TP26 13
  4493. +#define PB44_PCF8757_TP27 14
  4494. +#define PB44_PCF8757_TP28 15
  4495. +
  4496. +#define PB44_GPIO_I2C_SCL 0
  4497. +#define PB44_GPIO_I2C_SDA 1
  4498. +
  4499. +#define PB44_GPIO_EXP_BASE 16
  4500. +#define PB44_GPIO_VSC7395_CS (PB44_GPIO_EXP_BASE + PB44_PCF8757_VSC7395_CS)
  4501. +#define PB44_GPIO_SW_RESET (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_RESET)
  4502. +#define PB44_GPIO_SW_JUMP (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_JUMP)
  4503. +#define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP1)
  4504. +#define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP2)
  4505. +
  4506. +static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
  4507. + .sda_pin = PB44_GPIO_I2C_SDA,
  4508. + .scl_pin = PB44_GPIO_I2C_SCL,
  4509. +};
  4510. +
  4511. +static struct platform_device pb44_i2c_gpio_device = {
  4512. + .name = "i2c-gpio",
  4513. + .id = 0,
  4514. + .dev = {
  4515. + .platform_data = &pb44_i2c_gpio_data,
  4516. + }
  4517. +};
  4518. +
  4519. +static struct pcf857x_platform_data pb44_pcf857x_data = {
  4520. + .gpio_base = PB44_GPIO_EXP_BASE,
  4521. +};
  4522. +
  4523. +static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
  4524. + {
  4525. + I2C_BOARD_INFO("pcf8575", 0x20),
  4526. + .platform_data = &pb44_pcf857x_data,
  4527. + },
  4528. +};
  4529. +
  4530. +static struct gpio_led pb44_leds_gpio[] __initdata = {
  4531. + {
  4532. + .name = "pb44:amber:jump1",
  4533. + .gpio = PB44_GPIO_LED_JUMP1,
  4534. + .active_low = 1,
  4535. + }, {
  4536. + .name = "pb44:green:jump2",
  4537. + .gpio = PB44_GPIO_LED_JUMP2,
  4538. + .active_low = 1,
  4539. + },
  4540. +};
  4541. +
  4542. +static struct gpio_button pb44_gpio_buttons[] __initdata = {
  4543. + {
  4544. + .desc = "soft_reset",
  4545. + .type = EV_KEY,
  4546. + .code = KEY_RESTART,
  4547. + .threshold = 3,
  4548. + .gpio = PB44_GPIO_SW_RESET,
  4549. + .active_low = 1,
  4550. + } , {
  4551. + .desc = "jumpstart",
  4552. + .type = EV_KEY,
  4553. + .code = KEY_WPS_BUTTON,
  4554. + .threshold = 3,
  4555. + .gpio = PB44_GPIO_SW_JUMP,
  4556. + .active_low = 1,
  4557. + }
  4558. +};
  4559. +
  4560. +static void pb44_vsc7395_reset(void)
  4561. +{
  4562. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  4563. + udelay(10);
  4564. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  4565. + mdelay(50);
  4566. +}
  4567. +
  4568. +static struct vsc7385_platform_data pb44_vsc7395_data = {
  4569. + .reset = pb44_vsc7395_reset,
  4570. + .ucode_name = "vsc7395_ucode_pb44.bin",
  4571. + .mac_cfg = {
  4572. + .tx_ipg = 6,
  4573. + .bit2 = 1,
  4574. + .clk_sel = 0,
  4575. + },
  4576. +};
  4577. +
  4578. +static struct spi_board_info pb44_spi_info[] = {
  4579. + {
  4580. + .bus_num = 0,
  4581. + .chip_select = 0,
  4582. + .max_speed_hz = 25000000,
  4583. + .modalias = "m25p80",
  4584. + }, {
  4585. + .bus_num = 0,
  4586. + .chip_select = 1,
  4587. + .max_speed_hz = 25000000,
  4588. + .modalias = "spi-vsc7385",
  4589. + .platform_data = &pb44_vsc7395_data,
  4590. + .controller_data = (void *) PB44_GPIO_VSC7395_CS,
  4591. + },
  4592. +};
  4593. +
  4594. +static struct resource pb44_spi_resources[] = {
  4595. + [0] = {
  4596. + .start = AR71XX_SPI_BASE,
  4597. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  4598. + .flags = IORESOURCE_MEM,
  4599. + },
  4600. +};
  4601. +
  4602. +static struct ar71xx_spi_platform_data pb44_spi_data = {
  4603. + .bus_num = 0,
  4604. + .num_chipselect = 2,
  4605. +};
  4606. +
  4607. +static struct platform_device pb44_spi_device = {
  4608. + .name = "pb44-spi",
  4609. + .id = -1,
  4610. + .resource = pb44_spi_resources,
  4611. + .num_resources = ARRAY_SIZE(pb44_spi_resources),
  4612. + .dev = {
  4613. + .platform_data = &pb44_spi_data,
  4614. + },
  4615. +};
  4616. +
  4617. +#define PB44_WAN_PHYMASK BIT(0)
  4618. +#define PB44_LAN_PHYMASK 0
  4619. +#define PB44_MDIO_PHYMASK (PB44_LAN_PHYMASK | PB44_WAN_PHYMASK)
  4620. +
  4621. +static void __init pb44_init(void)
  4622. +{
  4623. + ar71xx_add_device_mdio(~PB44_MDIO_PHYMASK);
  4624. +
  4625. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4626. + ar71xx_eth0_data.phy_mask = PB44_WAN_PHYMASK;
  4627. +
  4628. + ar71xx_add_device_eth(0);
  4629. +
  4630. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4631. + ar71xx_eth1_data.speed = SPEED_1000;
  4632. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4633. + ar71xx_eth1_pll_data.pll_1000 = 0x110000;
  4634. +
  4635. + ar71xx_add_device_eth(1);
  4636. +
  4637. + ar71xx_add_device_usb();
  4638. +
  4639. + pb42_pci_init();
  4640. +
  4641. + i2c_register_board_info(0, pb44_i2c_board_info,
  4642. + ARRAY_SIZE(pb44_i2c_board_info));
  4643. +
  4644. + platform_device_register(&pb44_i2c_gpio_device);
  4645. +
  4646. + spi_register_board_info(pb44_spi_info, ARRAY_SIZE(pb44_spi_info));
  4647. + platform_device_register(&pb44_spi_device);
  4648. +
  4649. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
  4650. + pb44_leds_gpio);
  4651. +
  4652. + ar71xx_add_device_gpio_buttons(-1, 20, ARRAY_SIZE(pb44_gpio_buttons),
  4653. + pb44_gpio_buttons);
  4654. +}
  4655. +
  4656. +MIPS_MACHINE(AR71XX_MACH_PB44, "PB44", "Atheros PB44", pb44_init);
  4657. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb92.c linux-2.6.33.3/arch/mips/ar71xx/mach-pb92.c
  4658. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-pb92.c 1970-01-01 01:00:00.000000000 +0100
  4659. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-pb92.c 2010-04-14 21:17:12.138345698 +0200
  4660. @@ -0,0 +1,109 @@
  4661. +/*
  4662. + * Atheros PB92 board support
  4663. + *
  4664. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  4665. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4666. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4667. + *
  4668. + * This program is free software; you can redistribute it and/or modify it
  4669. + * under the terms of the GNU General Public License version 2 as published
  4670. + * by the Free Software Foundation.
  4671. + */
  4672. +
  4673. +#include <linux/mtd/mtd.h>
  4674. +#include <linux/mtd/partitions.h>
  4675. +#include <asm/mach-ar71xx/ar71xx.h>
  4676. +
  4677. +#include "machtype.h"
  4678. +#include "devices.h"
  4679. +#include "dev-m25p80.h"
  4680. +#include "dev-gpio-buttons.h"
  4681. +#include "dev-pb9x-pci.h"
  4682. +#include "dev-usb.h"
  4683. +
  4684. +#ifdef CONFIG_MTD_PARTITIONS
  4685. +static struct mtd_partition pb92_partitions[] = {
  4686. + {
  4687. + .name = "u-boot",
  4688. + .offset = 0,
  4689. + .size = 0x040000,
  4690. + .mask_flags = MTD_WRITEABLE,
  4691. + } , {
  4692. + .name = "u-boot-env",
  4693. + .offset = 0x040000,
  4694. + .size = 0x010000,
  4695. + } , {
  4696. + .name = "rootfs",
  4697. + .offset = 0x050000,
  4698. + .size = 0x2b0000,
  4699. + } , {
  4700. + .name = "uImage",
  4701. + .offset = 0x300000,
  4702. + .size = 0x0e0000,
  4703. + } , {
  4704. + .name = "ART",
  4705. + .offset = 0x3e0000,
  4706. + .size = 0x020000,
  4707. + .mask_flags = MTD_WRITEABLE,
  4708. + }
  4709. +};
  4710. +#endif /* CONFIG_MTD_PARTITIONS */
  4711. +
  4712. +static struct flash_platform_data pb92_flash_data = {
  4713. +#ifdef CONFIG_MTD_PARTITIONS
  4714. + .parts = pb92_partitions,
  4715. + .nr_parts = ARRAY_SIZE(pb92_partitions),
  4716. +#endif
  4717. +};
  4718. +
  4719. +
  4720. +#define PB92_BUTTONS_POLL_INTERVAL 20
  4721. +
  4722. +#define PB92_GPIO_BTN_SW4 8
  4723. +#define PB92_GPIO_BTN_SW5 3
  4724. +
  4725. +static struct gpio_button pb92_gpio_buttons[] __initdata = {
  4726. + {
  4727. + .desc = "sw4",
  4728. + .type = EV_KEY,
  4729. + .code = BTN_0,
  4730. + .threshold = 3,
  4731. + .gpio = PB92_GPIO_BTN_SW4,
  4732. + .active_low = 1,
  4733. + } , {
  4734. + .desc = "sw5",
  4735. + .type = EV_KEY,
  4736. + .code = BTN_1,
  4737. + .threshold = 3,
  4738. + .gpio = PB92_GPIO_BTN_SW5,
  4739. + .active_low = 1,
  4740. + }
  4741. +};
  4742. +
  4743. +static void __init pb92_init(void)
  4744. +{
  4745. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  4746. +
  4747. + ar71xx_set_mac_base(mac);
  4748. + ar71xx_add_device_m25p80(&pb92_flash_data);
  4749. +
  4750. + ar71xx_add_device_mdio(~0);
  4751. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4752. + ar71xx_eth0_data.speed = SPEED_1000;
  4753. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4754. +
  4755. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4756. + ar71xx_eth1_data.speed = SPEED_1000;
  4757. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4758. +
  4759. + ar71xx_add_device_eth(0);
  4760. + ar71xx_add_device_eth(1);
  4761. +
  4762. + ar71xx_add_device_gpio_buttons(-1, PB92_BUTTONS_POLL_INTERVAL,
  4763. + ARRAY_SIZE(pb92_gpio_buttons),
  4764. + pb92_gpio_buttons);
  4765. +
  4766. + pb9x_pci_init();
  4767. +}
  4768. +
  4769. +MIPS_MACHINE(AR71XX_MACH_PB92, "PB92", "Atheros PB92", pb92_init);
  4770. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-rb4xx.c linux-2.6.33.3/arch/mips/ar71xx/mach-rb4xx.c
  4771. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-rb4xx.c 1970-01-01 01:00:00.000000000 +0100
  4772. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-rb4xx.c 2010-05-16 13:17:32.763620812 +0200
  4773. @@ -0,0 +1,290 @@
  4774. +/*
  4775. + * MikroTik RouterBOARD 4xx series support
  4776. + *
  4777. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  4778. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4779. + *
  4780. + * This program is free software; you can redistribute it and/or modify it
  4781. + * under the terms of the GNU General Public License version 2 as published
  4782. + * by the Free Software Foundation.
  4783. + */
  4784. +
  4785. +#include <linux/platform_device.h>
  4786. +#include <linux/irq.h>
  4787. +#include <linux/mmc/host.h>
  4788. +#include <linux/spi/spi.h>
  4789. +#include <linux/spi/flash.h>
  4790. +#include <linux/spi/mmc_spi.h>
  4791. +
  4792. +#include <asm/mach-ar71xx/ar71xx.h>
  4793. +#include <asm/mach-ar71xx/pci.h>
  4794. +
  4795. +#include "machtype.h"
  4796. +#include "devices.h"
  4797. +#include "dev-gpio-buttons.h"
  4798. +#include "dev-leds-gpio.h"
  4799. +#include "dev-usb.h"
  4800. +
  4801. +#define RB4XX_GPIO_USER_LED 4
  4802. +#define RB4XX_GPIO_RESET_SWITCH 7
  4803. +
  4804. +#define RB4XX_BUTTONS_POLL_INTERVAL 20
  4805. +
  4806. +static struct gpio_led rb4xx_leds_gpio[] __initdata = {
  4807. + {
  4808. + .name = "rb4xx:yellow:user",
  4809. + .gpio = RB4XX_GPIO_USER_LED,
  4810. + .active_low = 0,
  4811. + },
  4812. +};
  4813. +
  4814. +static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
  4815. + {
  4816. + .desc = "reset_switch",
  4817. + .type = EV_KEY,
  4818. + .code = KEY_RESTART,
  4819. + .threshold = 3,
  4820. + .gpio = RB4XX_GPIO_RESET_SWITCH,
  4821. + .active_low = 1,
  4822. + }
  4823. +};
  4824. +
  4825. +static struct platform_device rb4xx_nand_device = {
  4826. + .name = "rb4xx-nand",
  4827. + .id = -1,
  4828. +};
  4829. +
  4830. +static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
  4831. + {
  4832. + .slot = 0,
  4833. + .pin = 1,
  4834. + .irq = AR71XX_PCI_IRQ_DEV2,
  4835. + }, {
  4836. + .slot = 1,
  4837. + .pin = 1,
  4838. + .irq = AR71XX_PCI_IRQ_DEV0,
  4839. + }, {
  4840. + .slot = 1,
  4841. + .pin = 2,
  4842. + .irq = AR71XX_PCI_IRQ_DEV1,
  4843. + }, {
  4844. + .slot = 2,
  4845. + .pin = 1,
  4846. + .irq = AR71XX_PCI_IRQ_DEV1,
  4847. + }, {
  4848. + .slot = 3,
  4849. + .pin = 1,
  4850. + .irq = AR71XX_PCI_IRQ_DEV2,
  4851. + }
  4852. +};
  4853. +
  4854. +#if 0
  4855. +/*
  4856. + * SPI device support is experimental
  4857. + */
  4858. +static struct flash_platform_data rb4xx_flash_data = {
  4859. + .type = "pm25lv512",
  4860. +};
  4861. +
  4862. +static struct spi_board_info rb4xx_spi_info[] = {
  4863. + {
  4864. + .bus_num = 0,
  4865. + .chip_select = 0,
  4866. + .max_speed_hz = 25000000,
  4867. + .modalias = "m25p80",
  4868. + .platform_data = &rb4xx_flash_data,
  4869. + }
  4870. +};
  4871. +
  4872. +static struct mmc_spi_platform_data rb433_mmc_data = {
  4873. + .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  4874. +};
  4875. +
  4876. +static struct spi_board_info rb433_spi_info[] = {
  4877. + {
  4878. + .bus_num = 0,
  4879. + .chip_select = 0,
  4880. + .max_speed_hz = 25000000,
  4881. + .modalias = "m25p80",
  4882. + .platform_data = &rb433_flash_data,
  4883. + }, {
  4884. + .bus_num = 0,
  4885. + .chip_select = 2,
  4886. + .max_speed_hz = 25000000,
  4887. + .modalias = "mmc_spi",
  4888. + .platform_data = &rb433_mmc_data,
  4889. + }
  4890. +};
  4891. +
  4892. +static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
  4893. +{
  4894. + u32 ret;
  4895. +
  4896. + if (is_on == AR71XX_SPI_CS_INACTIVE) {
  4897. + ret = SPI_IOC_CS0 | SPI_IOC_CS1;
  4898. + } else {
  4899. + if (cs_high) {
  4900. + ret = SPI_IOC_CS0 | SPI_IOC_CS1;
  4901. + } else {
  4902. + if ((chip_select ^ 2) == 0)
  4903. + ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
  4904. + else
  4905. + ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
  4906. + }
  4907. + }
  4908. +
  4909. + return ret;
  4910. +}
  4911. +
  4912. +struct ar71xx_spi_platform_data rb433_spi_data = {
  4913. + .bus_num = 0,
  4914. + .num_chipselect = 3,
  4915. + .get_ioc_base = rb433_spi_get_ioc_base,
  4916. +};
  4917. +
  4918. +static void rb4xx_add_device_spi(void)
  4919. +{
  4920. + ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
  4921. +}
  4922. +
  4923. +static void rb433_add_device_spi(void)
  4924. +{
  4925. + ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
  4926. + ARRAY_SIZE(rb433_spi_info));
  4927. +}
  4928. +#else
  4929. +static inline void rb4xx_add_device_spi(void) {}
  4930. +static inline void rb433_add_device_spi(void) {}
  4931. +#endif
  4932. +
  4933. +static void __init rb4xx_generic_setup(void)
  4934. +{
  4935. + ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  4936. + AR71XX_GPIO_FUNC_SPI_CS2_EN);
  4937. +
  4938. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
  4939. + rb4xx_leds_gpio);
  4940. +
  4941. + ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
  4942. + ARRAY_SIZE(rb4xx_gpio_buttons),
  4943. + rb4xx_gpio_buttons);
  4944. +
  4945. + platform_device_register(&rb4xx_nand_device);
  4946. +}
  4947. +
  4948. +static void __init rb411_setup(void)
  4949. +{
  4950. + rb4xx_generic_setup();
  4951. + rb4xx_add_device_spi();
  4952. +
  4953. + ar71xx_add_device_mdio(0xfffffffc);
  4954. +
  4955. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4956. + ar71xx_eth0_data.phy_mask = 0x00000003;
  4957. +
  4958. + ar71xx_add_device_eth(0);
  4959. +
  4960. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  4961. +}
  4962. +
  4963. +MIPS_MACHINE(AR71XX_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
  4964. + rb411_setup);
  4965. +
  4966. +static void __init rb411u_setup(void)
  4967. +{
  4968. + rb411_setup();
  4969. + ar71xx_add_device_usb();
  4970. +}
  4971. +
  4972. +MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
  4973. + rb411u_setup);
  4974. +
  4975. +static void __init rb433_setup(void)
  4976. +{
  4977. + rb4xx_generic_setup();
  4978. + rb433_add_device_spi();
  4979. +
  4980. + ar71xx_add_device_mdio(0xffffffe9);
  4981. +
  4982. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4983. + ar71xx_eth0_data.speed = SPEED_100;
  4984. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4985. +
  4986. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4987. + ar71xx_eth1_data.phy_mask = 0x00000010;
  4988. +
  4989. + ar71xx_add_device_eth(1);
  4990. + ar71xx_add_device_eth(0);
  4991. +
  4992. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  4993. +}
  4994. +
  4995. +MIPS_MACHINE(AR71XX_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
  4996. + rb433_setup);
  4997. +
  4998. +static void __init rb433u_setup(void)
  4999. +{
  5000. + rb433_setup();
  5001. + ar71xx_add_device_usb();
  5002. +}
  5003. +
  5004. +MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
  5005. + rb433u_setup);
  5006. +
  5007. +static void __init rb450_generic_setup(int gige)
  5008. +{
  5009. + rb4xx_generic_setup();
  5010. + rb4xx_add_device_spi();
  5011. +
  5012. + ar71xx_add_device_mdio(0xffffffe0);
  5013. +
  5014. + ar71xx_eth0_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
  5015. + ar71xx_eth0_data.phy_mask = (gige) ? (1 << 0) : 0;
  5016. + ar71xx_eth0_data.speed = (gige) ? SPEED_1000 : SPEED_100;
  5017. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5018. +
  5019. + ar71xx_eth1_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
  5020. + ar71xx_eth1_data.phy_mask = 0x00000010;
  5021. +
  5022. + ar71xx_add_device_eth(1);
  5023. + ar71xx_add_device_eth(0);
  5024. +}
  5025. +
  5026. +static void __init rb450_setup(void)
  5027. +{
  5028. + rb450_generic_setup(0);
  5029. +}
  5030. +
  5031. +MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
  5032. + rb450_setup);
  5033. +
  5034. +static void __init rb450g_setup(void)
  5035. +{
  5036. + rb450_generic_setup(1);
  5037. +}
  5038. +
  5039. +MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
  5040. + rb450g_setup);
  5041. +
  5042. +static void __init rb493_setup(void)
  5043. +{
  5044. + rb4xx_generic_setup();
  5045. + rb4xx_add_device_spi();
  5046. +
  5047. + ar71xx_add_device_mdio(0x3fffff00);
  5048. +
  5049. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  5050. + ar71xx_eth0_data.speed = SPEED_100;
  5051. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5052. +
  5053. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5054. + ar71xx_eth1_data.phy_mask = 0x00000001;
  5055. +
  5056. + ar71xx_add_device_eth(0);
  5057. + ar71xx_add_device_eth(1);
  5058. +
  5059. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  5060. +}
  5061. +
  5062. +MIPS_MACHINE(AR71XX_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",
  5063. + rb493_setup);
  5064. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-rb750.c linux-2.6.33.3/arch/mips/ar71xx/mach-rb750.c
  5065. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-rb750.c 1970-01-01 01:00:00.000000000 +0100
  5066. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-rb750.c 2010-03-12 19:31:46.886045750 +0100
  5067. @@ -0,0 +1,133 @@
  5068. +/*
  5069. + * MikroTik RouterBOARD 750 support
  5070. + *
  5071. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  5072. + *
  5073. + * This program is free software; you can redistribute it and/or modify it
  5074. + * under the terms of the GNU General Public License version 2 as published
  5075. + * by the Free Software Foundation.
  5076. + */
  5077. +
  5078. +#include <linux/platform_device.h>
  5079. +#include <asm/mach-ar71xx/ar71xx.h>
  5080. +#include <asm/mach-ar71xx/mach-rb750.h>
  5081. +
  5082. +#include "machtype.h"
  5083. +#include "dev-ap91-eth.h"
  5084. +
  5085. +static struct rb750_led_data rb750_leds[] = {
  5086. + {
  5087. + .name = "rb750:green:act",
  5088. + .mask = RB750_LED_ACT,
  5089. + .active_low = 1,
  5090. + }, {
  5091. + .name = "rb750:green:port1",
  5092. + .mask = RB750_LED_PORT5,
  5093. + .active_low = 1,
  5094. + }, {
  5095. + .name = "rb750:green:port2",
  5096. + .mask = RB750_LED_PORT4,
  5097. + .active_low = 1,
  5098. + }, {
  5099. + .name = "rb750:green:port3",
  5100. + .mask = RB750_LED_PORT3,
  5101. + .active_low = 1,
  5102. + }, {
  5103. + .name = "rb750:green:port4",
  5104. + .mask = RB750_LED_PORT2,
  5105. + .active_low = 1,
  5106. + }, {
  5107. + .name = "rb750:green:port5",
  5108. + .mask = RB750_LED_PORT1,
  5109. + .active_low = 1,
  5110. + }
  5111. +};
  5112. +
  5113. +static struct rb750_led_platform_data rb750_leds_data = {
  5114. + .num_leds = ARRAY_SIZE(rb750_leds),
  5115. + .leds = rb750_leds,
  5116. +};
  5117. +
  5118. +static struct platform_device rb750_leds_device = {
  5119. + .name = "leds-rb750",
  5120. + .dev = {
  5121. + .platform_data = &rb750_leds_data,
  5122. + }
  5123. +};
  5124. +
  5125. +static const char *rb750_port_names[AP91_ETH_NUM_PORT_NAMES] __initdata = {
  5126. + "port5",
  5127. + "port4",
  5128. + "port3",
  5129. + "port2",
  5130. +};
  5131. +
  5132. +static struct platform_device rb750_nand_device = {
  5133. + .name = "rb750-nand",
  5134. + .id = -1,
  5135. +};
  5136. +
  5137. +int rb750_latch_change(u32 mask_clr, u32 mask_set)
  5138. +{
  5139. + static DEFINE_SPINLOCK(lock);
  5140. + static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
  5141. + static u32 latch_oe;
  5142. + static u32 latch_clr;
  5143. + unsigned long flags;
  5144. + u32 t;
  5145. + int ret = 0;
  5146. +
  5147. + spin_lock_irqsave(&lock, flags);
  5148. +
  5149. + if ((mask_clr & BIT(31)) != 0 &&
  5150. + (latch_set & RB750_LVC573_LE) == 0) {
  5151. + goto unlock;
  5152. + }
  5153. +
  5154. + latch_set = (latch_set | mask_set) & ~mask_clr;
  5155. + latch_clr = (latch_clr | mask_clr) & ~mask_set;
  5156. +
  5157. + if (latch_oe == 0)
  5158. + latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
  5159. +
  5160. + if (likely(latch_set & RB750_LVC573_LE)) {
  5161. + void __iomem *base = ar71xx_gpio_base;
  5162. +
  5163. + t = __raw_readl(base + GPIO_REG_OE);
  5164. + t |= mask_clr | latch_oe | mask_set;
  5165. +
  5166. + __raw_writel(t, base + GPIO_REG_OE);
  5167. + __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
  5168. + __raw_writel(latch_set, base + GPIO_REG_SET);
  5169. + } else if (mask_clr & RB750_LVC573_LE) {
  5170. + void __iomem *base = ar71xx_gpio_base;
  5171. +
  5172. + latch_oe = __raw_readl(base + GPIO_REG_OE);
  5173. + __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
  5174. + /* flush write */
  5175. + __raw_readl(base + GPIO_REG_CLEAR);
  5176. + }
  5177. +
  5178. + ret = 1;
  5179. +
  5180. + unlock:
  5181. + spin_unlock_irqrestore(&lock, flags);
  5182. + return ret;
  5183. +}
  5184. +EXPORT_SYMBOL_GPL(rb750_latch_change);
  5185. +
  5186. +static void __init rb750_setup(void)
  5187. +{
  5188. + ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  5189. + AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  5190. + AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  5191. + AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  5192. + AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  5193. +
  5194. + ap91_eth_init(NULL, rb750_port_names);
  5195. + platform_device_register(&rb750_leds_device);
  5196. + platform_device_register(&rb750_nand_device);
  5197. +}
  5198. +
  5199. +MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
  5200. + rb750_setup);
  5201. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tew-632brp.c linux-2.6.33.3/arch/mips/ar71xx/mach-tew-632brp.c
  5202. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tew-632brp.c 1970-01-01 01:00:00.000000000 +0100
  5203. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-tew-632brp.c 2010-05-16 13:17:32.899597622 +0200
  5204. @@ -0,0 +1,149 @@
  5205. +/*
  5206. + * TrendNET TEW-632BRP board support
  5207. + *
  5208. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5209. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5210. + *
  5211. + * This program is free software; you can redistribute it and/or modify it
  5212. + * under the terms of the GNU General Public License version 2 as published
  5213. + * by the Free Software Foundation.
  5214. + */
  5215. +
  5216. +#include <linux/mtd/mtd.h>
  5217. +#include <linux/mtd/partitions.h>
  5218. +
  5219. +#include <asm/mach-ar71xx/ar71xx.h>
  5220. +
  5221. +#include "machtype.h"
  5222. +#include "devices.h"
  5223. +#include "dev-m25p80.h"
  5224. +#include "dev-ar913x-wmac.h"
  5225. +#include "dev-gpio-buttons.h"
  5226. +#include "dev-leds-gpio.h"
  5227. +#include "nvram.h"
  5228. +
  5229. +#define TEW_632BRP_GPIO_LED_STATUS 1
  5230. +#define TEW_632BRP_GPIO_LED_WPS 3
  5231. +#define TEW_632BRP_GPIO_LED_WLAN 6
  5232. +#define TEW_632BRP_GPIO_BTN_WPS 12
  5233. +#define TEW_632BRP_GPIO_BTN_RESET 21
  5234. +
  5235. +#define TEW_632BRP_BUTTONS_POLL_INTERVAL 20
  5236. +
  5237. +#define TEW_632BRP_CONFIG_ADDR 0x1f020000
  5238. +#define TEW_632BRP_CONFIG_SIZE 0x10000
  5239. +
  5240. +#ifdef CONFIG_MTD_PARTITIONS
  5241. +static struct mtd_partition tew_632brp_partitions[] = {
  5242. + {
  5243. + .name = "u-boot",
  5244. + .offset = 0,
  5245. + .size = 0x020000,
  5246. + .mask_flags = MTD_WRITEABLE,
  5247. + } , {
  5248. + .name = "config",
  5249. + .offset = 0x020000,
  5250. + .size = 0x010000,
  5251. + } , {
  5252. + .name = "kernel",
  5253. + .offset = 0x030000,
  5254. + .size = 0x0d0000,
  5255. + } , {
  5256. + .name = "rootfs",
  5257. + .offset = 0x100000,
  5258. + .size = 0x2f0000,
  5259. + } , {
  5260. + .name = "art",
  5261. + .offset = 0x3f0000,
  5262. + .size = 0x010000,
  5263. + .mask_flags = MTD_WRITEABLE,
  5264. + } , {
  5265. + .name = "firmware",
  5266. + .offset = 0x030000,
  5267. + .size = 0x3c0000,
  5268. + }
  5269. +};
  5270. +#endif /* CONFIG_MTD_PARTITIONS */
  5271. +
  5272. +static struct flash_platform_data tew_632brp_flash_data = {
  5273. +#ifdef CONFIG_MTD_PARTITIONS
  5274. + .parts = tew_632brp_partitions,
  5275. + .nr_parts = ARRAY_SIZE(tew_632brp_partitions),
  5276. +#endif
  5277. +};
  5278. +
  5279. +static struct gpio_led tew_632brp_leds_gpio[] __initdata = {
  5280. + {
  5281. + .name = "tew-632brp:green:status",
  5282. + .gpio = TEW_632BRP_GPIO_LED_STATUS,
  5283. + .active_low = 1,
  5284. + }, {
  5285. + .name = "tew-632brp:blue:wps",
  5286. + .gpio = TEW_632BRP_GPIO_LED_WPS,
  5287. + .active_low = 1,
  5288. + }, {
  5289. + .name = "tew-632brp:green:wlan",
  5290. + .gpio = TEW_632BRP_GPIO_LED_WLAN,
  5291. + .active_low = 1,
  5292. + }
  5293. +};
  5294. +
  5295. +static struct gpio_button tew_632brp_gpio_buttons[] __initdata = {
  5296. + {
  5297. + .desc = "reset",
  5298. + .type = EV_KEY,
  5299. + .code = KEY_RESTART,
  5300. + .threshold = 3,
  5301. + .gpio = TEW_632BRP_GPIO_BTN_RESET,
  5302. + }, {
  5303. + .desc = "wps",
  5304. + .type = EV_KEY,
  5305. + .code = KEY_WPS_BUTTON,
  5306. + .threshold = 3,
  5307. + .gpio = TEW_632BRP_GPIO_BTN_WPS,
  5308. + }
  5309. +};
  5310. +
  5311. +#define TEW_632BRP_LAN_PHYMASK BIT(0)
  5312. +#define TEW_632BRP_WAN_PHYMASK BIT(4)
  5313. +#define TEW_632BRP_MDIO_MASK (~(TEW_632BRP_LAN_PHYMASK | \
  5314. + TEW_632BRP_WAN_PHYMASK))
  5315. +
  5316. +static void __init tew_632brp_setup(void)
  5317. +{
  5318. + const char *config = (char *) KSEG1ADDR(TEW_632BRP_CONFIG_ADDR);
  5319. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5320. + u8 mac[6];
  5321. + u8 *wlan_mac = NULL;
  5322. +
  5323. + if (nvram_parse_mac_addr(config, TEW_632BRP_CONFIG_SIZE,
  5324. + "lan_mac=", mac) == 0) {
  5325. + ar71xx_set_mac_base(mac);
  5326. + wlan_mac = mac;
  5327. + }
  5328. +
  5329. + ar71xx_add_device_mdio(TEW_632BRP_MDIO_MASK);
  5330. +
  5331. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5332. + ar71xx_eth0_data.phy_mask = TEW_632BRP_LAN_PHYMASK;
  5333. +
  5334. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5335. + ar71xx_eth1_data.phy_mask = TEW_632BRP_WAN_PHYMASK;
  5336. +
  5337. + ar71xx_add_device_eth(0);
  5338. + ar71xx_add_device_eth(1);
  5339. +
  5340. + ar71xx_add_device_m25p80(&tew_632brp_flash_data);
  5341. +
  5342. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew_632brp_leds_gpio),
  5343. + tew_632brp_leds_gpio);
  5344. +
  5345. + ar71xx_add_device_gpio_buttons(-1, TEW_632BRP_BUTTONS_POLL_INTERVAL,
  5346. + ARRAY_SIZE(tew_632brp_gpio_buttons),
  5347. + tew_632brp_gpio_buttons);
  5348. +
  5349. + ar913x_add_device_wmac(eeprom, wlan_mac);
  5350. +}
  5351. +
  5352. +MIPS_MACHINE(AR71XX_MACH_TEW_632BRP, "TEW-632BRP", "TRENDnet TEW-632BRP",
  5353. + tew_632brp_setup);
  5354. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr1043nd.c
  5355. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c 1970-01-01 01:00:00.000000000 +0100
  5356. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr1043nd.c 2010-05-16 13:17:31.779600220 +0200
  5357. @@ -0,0 +1,156 @@
  5358. +/*
  5359. + * TP-LINK TL-WR1043ND board support
  5360. + *
  5361. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5362. + *
  5363. + * This program is free software; you can redistribute it and/or modify it
  5364. + * under the terms of the GNU General Public License version 2 as published
  5365. + * by the Free Software Foundation.
  5366. + */
  5367. +
  5368. +#include <linux/mtd/mtd.h>
  5369. +#include <linux/mtd/partitions.h>
  5370. +#include <linux/platform_device.h>
  5371. +#include <linux/rtl8366rb.h>
  5372. +#include <asm/mach-ar71xx/ar71xx.h>
  5373. +
  5374. +#include "machtype.h"
  5375. +#include "devices.h"
  5376. +#include "dev-m25p80.h"
  5377. +#include "dev-ar913x-wmac.h"
  5378. +#include "dev-gpio-buttons.h"
  5379. +#include "dev-leds-gpio.h"
  5380. +#include "dev-usb.h"
  5381. +
  5382. +#define TL_WR1043ND_GPIO_LED_USB 1
  5383. +#define TL_WR1043ND_GPIO_LED_SYSTEM 2
  5384. +#define TL_WR1043ND_GPIO_LED_QSS 5
  5385. +#define TL_WR1043ND_GPIO_LED_WLAN 9
  5386. +
  5387. +#define TL_WR1043ND_GPIO_BTN_RESET 3
  5388. +#define TL_WR1043ND_GPIO_BTN_QSS 7
  5389. +
  5390. +#define TL_WR1043ND_GPIO_RTL8366_SDA 18
  5391. +#define TL_WR1043ND_GPIO_RTL8366_SCK 19
  5392. +
  5393. +#define TL_WR1043ND_BUTTONS_POLL_INTERVAL 20
  5394. +
  5395. +#ifdef CONFIG_MTD_PARTITIONS
  5396. +static struct mtd_partition tl_wr1043nd_partitions[] = {
  5397. + {
  5398. + .name = "u-boot",
  5399. + .offset = 0,
  5400. + .size = 0x020000,
  5401. + .mask_flags = MTD_WRITEABLE,
  5402. + } , {
  5403. + .name = "kernel",
  5404. + .offset = 0x020000,
  5405. + .size = 0x140000,
  5406. + } , {
  5407. + .name = "rootfs",
  5408. + .offset = 0x160000,
  5409. + .size = 0x690000,
  5410. + } , {
  5411. + .name = "art",
  5412. + .offset = 0x7f0000,
  5413. + .size = 0x010000,
  5414. + .mask_flags = MTD_WRITEABLE,
  5415. + } , {
  5416. + .name = "firmware",
  5417. + .offset = 0x020000,
  5418. + .size = 0x7d0000,
  5419. + }
  5420. +};
  5421. +#endif /* CONFIG_MTD_PARTITIONS */
  5422. +
  5423. +static struct flash_platform_data tl_wr1043nd_flash_data = {
  5424. +#ifdef CONFIG_MTD_PARTITIONS
  5425. + .parts = tl_wr1043nd_partitions,
  5426. + .nr_parts = ARRAY_SIZE(tl_wr1043nd_partitions),
  5427. +#endif
  5428. +};
  5429. +
  5430. +static struct gpio_led tl_wr1043nd_leds_gpio[] __initdata = {
  5431. + {
  5432. + .name = "tl-wr1043nd:green:usb",
  5433. + .gpio = TL_WR1043ND_GPIO_LED_USB,
  5434. + .active_low = 1,
  5435. + }, {
  5436. + .name = "tl-wr1043nd:green:system",
  5437. + .gpio = TL_WR1043ND_GPIO_LED_SYSTEM,
  5438. + .active_low = 1,
  5439. + }, {
  5440. + .name = "tl-wr1043nd:green:qss",
  5441. + .gpio = TL_WR1043ND_GPIO_LED_QSS,
  5442. + .active_low = 0,
  5443. + }, {
  5444. + .name = "tl-wr1043nd:green:wlan",
  5445. + .gpio = TL_WR1043ND_GPIO_LED_WLAN,
  5446. + .active_low = 1,
  5447. + }
  5448. +};
  5449. +
  5450. +static struct gpio_button tl_wr1043nd_gpio_buttons[] __initdata = {
  5451. + {
  5452. + .desc = "reset",
  5453. + .type = EV_KEY,
  5454. + .code = KEY_RESTART,
  5455. + .threshold = 3,
  5456. + .gpio = TL_WR1043ND_GPIO_BTN_RESET,
  5457. + .active_low = 1,
  5458. + }, {
  5459. + .desc = "qss",
  5460. + .type = EV_KEY,
  5461. + .code = KEY_WPS_BUTTON,
  5462. + .threshold = 3,
  5463. + .gpio = TL_WR1043ND_GPIO_BTN_QSS,
  5464. + .active_low = 1,
  5465. + }
  5466. +};
  5467. +
  5468. +static struct rtl8366rb_platform_data tl_wr1043nd_rtl8366rb_data = {
  5469. + .gpio_sda = TL_WR1043ND_GPIO_RTL8366_SDA,
  5470. + .gpio_sck = TL_WR1043ND_GPIO_RTL8366_SCK,
  5471. +};
  5472. +
  5473. +static struct platform_device tl_wr1043nd_rtl8366rb_device = {
  5474. + .name = RTL8366RB_DRIVER_NAME,
  5475. + .id = -1,
  5476. + .dev = {
  5477. + .platform_data = &tl_wr1043nd_rtl8366rb_data,
  5478. + }
  5479. +};
  5480. +
  5481. +static void __init tl_wr1043nd_setup(void)
  5482. +{
  5483. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5484. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5485. +
  5486. + ar71xx_set_mac_base(mac);
  5487. +
  5488. + ar71xx_eth0_data.mii_bus_dev = &tl_wr1043nd_rtl8366rb_device.dev;
  5489. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5490. + ar71xx_eth0_data.speed = SPEED_1000;
  5491. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5492. + ar71xx_eth0_pll_data.pll_1000 = 0x1a000000;
  5493. +
  5494. + ar71xx_add_device_eth(0);
  5495. +
  5496. + ar71xx_add_device_usb();
  5497. +
  5498. + ar71xx_add_device_m25p80(&tl_wr1043nd_flash_data);
  5499. +
  5500. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_leds_gpio),
  5501. + tl_wr1043nd_leds_gpio);
  5502. +
  5503. + platform_device_register(&tl_wr1043nd_rtl8366rb_device);
  5504. +
  5505. + ar71xx_add_device_gpio_buttons(-1, TL_WR1043ND_BUTTONS_POLL_INTERVAL,
  5506. + ARRAY_SIZE(tl_wr1043nd_gpio_buttons),
  5507. + tl_wr1043nd_gpio_buttons);
  5508. +
  5509. + ar913x_add_device_wmac(eeprom, mac);
  5510. +}
  5511. +
  5512. +MIPS_MACHINE(AR71XX_MACH_TL_WR1043ND, "TL-WR1043ND", "TP-LINK TL-WR1043ND",
  5513. + tl_wr1043nd_setup);
  5514. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr741nd.c linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr741nd.c
  5515. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr741nd.c 1970-01-01 01:00:00.000000000 +0100
  5516. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr741nd.c 2010-05-16 13:17:33.043600332 +0200
  5517. @@ -0,0 +1,115 @@
  5518. +/*
  5519. + * TP-LINK TL-WR741ND board support
  5520. + *
  5521. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  5522. + *
  5523. + * This program is free software; you can redistribute it and/or modify it
  5524. + * under the terms of the GNU General Public License version 2 as published
  5525. + * by the Free Software Foundation.
  5526. + */
  5527. +
  5528. +#include <linux/mtd/mtd.h>
  5529. +#include <linux/mtd/partitions.h>
  5530. +
  5531. +#include <asm/mach-ar71xx/ar71xx.h>
  5532. +
  5533. +#include "machtype.h"
  5534. +#include "devices.h"
  5535. +#include "dev-m25p80.h"
  5536. +#include "dev-ap91-eth.h"
  5537. +#include "dev-ap91-pci.h"
  5538. +#include "dev-gpio-buttons.h"
  5539. +#include "dev-leds-gpio.h"
  5540. +
  5541. +#define TL_WR741ND_GPIO_LED_QSS 0
  5542. +#define TL_WR741ND_GPIO_LED_SYSTEM 1
  5543. +
  5544. +#define TL_WR741ND_GPIO_BTN_RESET 11
  5545. +#define TL_WR741ND_GPIO_BTN_QSS 12
  5546. +
  5547. +#define TL_WR741ND_BUTTONS_POLL_INTERVAL 20
  5548. +
  5549. +#ifdef CONFIG_MTD_PARTITIONS
  5550. +static struct mtd_partition tl_wr741nd_partitions[] = {
  5551. + {
  5552. + .name = "u-boot",
  5553. + .offset = 0,
  5554. + .size = 0x020000,
  5555. + .mask_flags = MTD_WRITEABLE,
  5556. + } , {
  5557. + .name = "kernel",
  5558. + .offset = 0x020000,
  5559. + .size = 0x140000,
  5560. + } , {
  5561. + .name = "rootfs",
  5562. + .offset = 0x160000,
  5563. + .size = 0x290000,
  5564. + } , {
  5565. + .name = "art",
  5566. + .offset = 0x3f0000,
  5567. + .size = 0x010000,
  5568. + .mask_flags = MTD_WRITEABLE,
  5569. + } , {
  5570. + .name = "firmware",
  5571. + .offset = 0x020000,
  5572. + .size = 0x3d0000,
  5573. + }
  5574. +};
  5575. +#endif /* CONFIG_MTD_PARTITIONS */
  5576. +
  5577. +static struct flash_platform_data tl_wr741nd_flash_data = {
  5578. +#ifdef CONFIG_MTD_PARTITIONS
  5579. + .parts = tl_wr741nd_partitions,
  5580. + .nr_parts = ARRAY_SIZE(tl_wr741nd_partitions),
  5581. +#endif
  5582. +};
  5583. +
  5584. +static struct gpio_led tl_wr741nd_leds_gpio[] __initdata = {
  5585. + {
  5586. + .name = "tl-wr741nd:green:system",
  5587. + .gpio = TL_WR741ND_GPIO_LED_SYSTEM,
  5588. + .active_low = 1,
  5589. + }, {
  5590. + .name = "tl-wr741nd:green:qss",
  5591. + .gpio = TL_WR741ND_GPIO_LED_QSS,
  5592. + .active_low = 1,
  5593. + }
  5594. +};
  5595. +
  5596. +static struct gpio_button tl_wr741nd_gpio_buttons[] __initdata = {
  5597. + {
  5598. + .desc = "reset",
  5599. + .type = EV_KEY,
  5600. + .code = KEY_RESTART,
  5601. + .threshold = 3,
  5602. + .gpio = TL_WR741ND_GPIO_BTN_RESET,
  5603. + .active_low = 1,
  5604. + }, {
  5605. + .desc = "qss",
  5606. + .type = EV_KEY,
  5607. + .code = KEY_WPS_BUTTON,
  5608. + .threshold = 3,
  5609. + .gpio = TL_WR741ND_GPIO_BTN_QSS,
  5610. + .active_low = 1,
  5611. + }
  5612. +};
  5613. +
  5614. +static void __init tl_wr741nd_setup(void)
  5615. +{
  5616. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5617. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  5618. +
  5619. + ar71xx_add_device_m25p80(&tl_wr741nd_flash_data);
  5620. +
  5621. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr741nd_leds_gpio),
  5622. + tl_wr741nd_leds_gpio);
  5623. +
  5624. + ar71xx_add_device_gpio_buttons(-1, TL_WR741ND_BUTTONS_POLL_INTERVAL,
  5625. + ARRAY_SIZE(tl_wr741nd_gpio_buttons),
  5626. + tl_wr741nd_gpio_buttons);
  5627. +
  5628. + ap91_eth_init(mac, NULL);
  5629. + ap91_pci_init(ee, mac);
  5630. +}
  5631. +MIPS_MACHINE(AR71XX_MACH_TL_WR741ND, "TL-WR741ND", "TP-LINK TL-WR741ND",
  5632. + tl_wr741nd_setup);
  5633. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr841n.c linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr841n.c
  5634. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr841n.c 1970-01-01 01:00:00.000000000 +0100
  5635. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr841n.c 2010-05-16 13:17:32.951604530 +0200
  5636. @@ -0,0 +1,143 @@
  5637. +/*
  5638. + * TP-LINK TL-WR841N board support
  5639. + *
  5640. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5641. + *
  5642. + * This program is free software; you can redistribute it and/or modify it
  5643. + * under the terms of the GNU General Public License version 2 as published
  5644. + * by the Free Software Foundation.
  5645. + */
  5646. +
  5647. +#include <linux/mtd/mtd.h>
  5648. +#include <linux/mtd/partitions.h>
  5649. +
  5650. +#include <asm/mach-ar71xx/ar71xx.h>
  5651. +
  5652. +#include "machtype.h"
  5653. +#include "devices.h"
  5654. +#include "dev-dsa.h"
  5655. +#include "dev-m25p80.h"
  5656. +#include "dev-gpio-buttons.h"
  5657. +#include "dev-pb42-pci.h"
  5658. +#include "dev-leds-gpio.h"
  5659. +
  5660. +#define TL_WR841ND_V1_GPIO_LED_SYSTEM 2
  5661. +#define TL_WR841ND_V1_GPIO_LED_QSS_GREEN 4
  5662. +#define TL_WR841ND_V1_GPIO_LED_QSS_RED 5
  5663. +
  5664. +#define TL_WR841ND_V1_GPIO_BTN_RESET 3
  5665. +#define TL_WR841ND_V1_GPIO_BTN_QSS 7
  5666. +
  5667. +#define TL_WR841ND_V1_BUTTONS_POLL_INTERVAL 20
  5668. +
  5669. +#ifdef CONFIG_MTD_PARTITIONS
  5670. +static struct mtd_partition tl_wr841n_v1_partitions[] = {
  5671. + {
  5672. + .name = "redboot",
  5673. + .offset = 0,
  5674. + .size = 0x020000,
  5675. + .mask_flags = MTD_WRITEABLE,
  5676. + } , {
  5677. + .name = "kernel",
  5678. + .offset = 0x020000,
  5679. + .size = 0x140000,
  5680. + } , {
  5681. + .name = "rootfs",
  5682. + .offset = 0x160000,
  5683. + .size = 0x280000,
  5684. + } , {
  5685. + .name = "config",
  5686. + .offset = 0x3e0000,
  5687. + .size = 0x020000,
  5688. + .mask_flags = MTD_WRITEABLE,
  5689. + } , {
  5690. + .name = "firmware",
  5691. + .offset = 0x020000,
  5692. + .size = 0x3c0000,
  5693. + }
  5694. +};
  5695. +#endif /* CONFIG_MTD_PARTITIONS */
  5696. +
  5697. +static struct flash_platform_data tl_wr841n_v1_flash_data = {
  5698. +#ifdef CONFIG_MTD_PARTITIONS
  5699. + .parts = tl_wr841n_v1_partitions,
  5700. + .nr_parts = ARRAY_SIZE(tl_wr841n_v1_partitions),
  5701. +#endif
  5702. +};
  5703. +
  5704. +static struct gpio_led tl_wr841n_v1_leds_gpio[] __initdata = {
  5705. + {
  5706. + .name = "tl-wr841n:green:system",
  5707. + .gpio = TL_WR841ND_V1_GPIO_LED_SYSTEM,
  5708. + .active_low = 1,
  5709. + }, {
  5710. + .name = "tl-wr841n:red:qss",
  5711. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_RED,
  5712. + }, {
  5713. + .name = "tl-wr841n:green:qss",
  5714. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_GREEN,
  5715. + }
  5716. +};
  5717. +
  5718. +static struct gpio_button tl_wr841n_v1_gpio_buttons[] __initdata = {
  5719. + {
  5720. + .desc = "reset",
  5721. + .type = EV_KEY,
  5722. + .code = KEY_RESTART,
  5723. + .threshold = 3,
  5724. + .gpio = TL_WR841ND_V1_GPIO_BTN_RESET,
  5725. + .active_low = 1,
  5726. + }, {
  5727. + .desc = "qss",
  5728. + .type = EV_KEY,
  5729. + .code = KEY_WPS_BUTTON,
  5730. + .threshold = 3,
  5731. + .gpio = TL_WR841ND_V1_GPIO_BTN_QSS,
  5732. + .active_low = 1,
  5733. + }
  5734. +};
  5735. +
  5736. +static struct dsa_chip_data tl_wr841n_v1_dsa_chip = {
  5737. + .port_names[0] = "wan",
  5738. + .port_names[1] = "lan1",
  5739. + .port_names[2] = "lan2",
  5740. + .port_names[3] = "lan3",
  5741. + .port_names[4] = "lan4",
  5742. + .port_names[5] = "cpu",
  5743. +};
  5744. +
  5745. +static struct dsa_platform_data tl_wr841n_v1_dsa_data = {
  5746. + .nr_chips = 1,
  5747. + .chip = &tl_wr841n_v1_dsa_chip,
  5748. +};
  5749. +
  5750. +static void __init tl_wr841n_v1_setup(void)
  5751. +{
  5752. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5753. +
  5754. + ar71xx_set_mac_base(mac);
  5755. +
  5756. + ar71xx_add_device_mdio(0x0);
  5757. +
  5758. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5759. + ar71xx_eth0_data.speed = SPEED_100;
  5760. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5761. +
  5762. + ar71xx_add_device_eth(0);
  5763. +
  5764. + ar71xx_add_device_dsa(0, &tl_wr841n_v1_dsa_data);
  5765. +
  5766. + ar71xx_add_device_m25p80(&tl_wr841n_v1_flash_data);
  5767. +
  5768. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v1_leds_gpio),
  5769. + tl_wr841n_v1_leds_gpio);
  5770. +
  5771. + ar71xx_add_device_gpio_buttons(-1, TL_WR841ND_V1_BUTTONS_POLL_INTERVAL,
  5772. + ARRAY_SIZE(tl_wr841n_v1_gpio_buttons),
  5773. + tl_wr841n_v1_gpio_buttons);
  5774. +
  5775. + pb42_pci_init();
  5776. +}
  5777. +
  5778. +MIPS_MACHINE(AR71XX_MACH_TL_WR841N_V1, "TL-WR841N-v1.5", "TP-LINK TL-WR841N v1",
  5779. + tl_wr841n_v1_setup);
  5780. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr941nd.c linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr941nd.c
  5781. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-tl-wr941nd.c 1970-01-01 01:00:00.000000000 +0100
  5782. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-tl-wr941nd.c 2010-05-16 13:17:33.088566117 +0200
  5783. @@ -0,0 +1,142 @@
  5784. +/*
  5785. + * TP-LINK TL-WR941ND board support
  5786. + *
  5787. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  5788. + *
  5789. + * This program is free software; you can redistribute it and/or modify it
  5790. + * under the terms of the GNU General Public License version 2 as published
  5791. + * by the Free Software Foundation.
  5792. + */
  5793. +
  5794. +#include <linux/mtd/mtd.h>
  5795. +#include <linux/mtd/partitions.h>
  5796. +
  5797. +#include <asm/mach-ar71xx/ar71xx.h>
  5798. +
  5799. +#include "machtype.h"
  5800. +#include "devices.h"
  5801. +#include "dev-dsa.h"
  5802. +#include "dev-m25p80.h"
  5803. +#include "dev-ar913x-wmac.h"
  5804. +#include "dev-gpio-buttons.h"
  5805. +#include "dev-leds-gpio.h"
  5806. +
  5807. +#define TL_WR941ND_GPIO_LED_SYSTEM 2
  5808. +#define TL_WR941ND_GPIO_LED_QSS_RED 4
  5809. +#define TL_WR941ND_GPIO_LED_QSS_GREEN 5
  5810. +
  5811. +#define TL_WR941ND_GPIO_BTN_RESET 3
  5812. +#define TL_WR941ND_GPIO_BTN_QSS 7
  5813. +
  5814. +#define TL_WR941ND_BUTTONS_POLL_INTERVAL 20
  5815. +
  5816. +#ifdef CONFIG_MTD_PARTITIONS
  5817. +static struct mtd_partition tl_wr941nd_partitions[] = {
  5818. + {
  5819. + .name = "u-boot",
  5820. + .offset = 0,
  5821. + .size = 0x020000,
  5822. + .mask_flags = MTD_WRITEABLE,
  5823. + } , {
  5824. + .name = "kernel",
  5825. + .offset = 0x020000,
  5826. + .size = 0x140000,
  5827. + } , {
  5828. + .name = "rootfs",
  5829. + .offset = 0x160000,
  5830. + .size = 0x290000,
  5831. + } , {
  5832. + .name = "art",
  5833. + .offset = 0x3f0000,
  5834. + .size = 0x010000,
  5835. + .mask_flags = MTD_WRITEABLE,
  5836. + } , {
  5837. + .name = "firmware",
  5838. + .offset = 0x020000,
  5839. + .size = 0x3d0000,
  5840. + }
  5841. +};
  5842. +#endif /* CONFIG_MTD_PARTITIONS */
  5843. +
  5844. +static struct flash_platform_data tl_wr941nd_flash_data = {
  5845. +#ifdef CONFIG_MTD_PARTITIONS
  5846. + .parts = tl_wr941nd_partitions,
  5847. + .nr_parts = ARRAY_SIZE(tl_wr941nd_partitions),
  5848. +#endif
  5849. +};
  5850. +
  5851. +static struct gpio_led tl_wr941nd_leds_gpio[] __initdata = {
  5852. + {
  5853. + .name = "tl-wr941nd:green:system",
  5854. + .gpio = TL_WR941ND_GPIO_LED_SYSTEM,
  5855. + .active_low = 1,
  5856. + }, {
  5857. + .name = "tl-wr941nd:red:qss",
  5858. + .gpio = TL_WR941ND_GPIO_LED_QSS_RED,
  5859. + }, {
  5860. + .name = "tl-wr941nd:green:qss",
  5861. + .gpio = TL_WR941ND_GPIO_LED_QSS_GREEN,
  5862. + }
  5863. +};
  5864. +
  5865. +static struct gpio_button tl_wr941nd_gpio_buttons[] __initdata = {
  5866. + {
  5867. + .desc = "reset",
  5868. + .type = EV_KEY,
  5869. + .code = KEY_RESTART,
  5870. + .threshold = 3,
  5871. + .gpio = TL_WR941ND_GPIO_BTN_RESET,
  5872. + .active_low = 1,
  5873. + }, {
  5874. + .desc = "qss",
  5875. + .type = EV_KEY,
  5876. + .code = KEY_WPS_BUTTON,
  5877. + .threshold = 3,
  5878. + .gpio = TL_WR941ND_GPIO_BTN_QSS,
  5879. + .active_low = 1,
  5880. + }
  5881. +};
  5882. +
  5883. +static struct dsa_chip_data tl_wr941nd_dsa_chip = {
  5884. + .port_names[0] = "wan",
  5885. + .port_names[1] = "lan1",
  5886. + .port_names[2] = "lan2",
  5887. + .port_names[3] = "lan3",
  5888. + .port_names[4] = "lan4",
  5889. + .port_names[5] = "cpu",
  5890. +};
  5891. +
  5892. +static struct dsa_platform_data tl_wr941nd_dsa_data = {
  5893. + .nr_chips = 1,
  5894. + .chip = &tl_wr941nd_dsa_chip,
  5895. +};
  5896. +
  5897. +static void __init tl_wr941nd_setup(void)
  5898. +{
  5899. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5900. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5901. +
  5902. + ar71xx_set_mac_base(mac);
  5903. +
  5904. + ar71xx_add_device_mdio(0x0);
  5905. +
  5906. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5907. + ar71xx_eth0_data.speed = SPEED_100;
  5908. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5909. +
  5910. + ar71xx_add_device_eth(0);
  5911. + ar71xx_add_device_dsa(0, &tl_wr941nd_dsa_data);
  5912. +
  5913. + ar71xx_add_device_m25p80(&tl_wr941nd_flash_data);
  5914. +
  5915. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr941nd_leds_gpio),
  5916. + tl_wr941nd_leds_gpio);
  5917. +
  5918. + ar71xx_add_device_gpio_buttons(-1, TL_WR941ND_BUTTONS_POLL_INTERVAL,
  5919. + ARRAY_SIZE(tl_wr941nd_gpio_buttons),
  5920. + tl_wr941nd_gpio_buttons);
  5921. + ar913x_add_device_wmac(eeprom, mac);
  5922. +}
  5923. +
  5924. +MIPS_MACHINE(AR71XX_MACH_TL_WR941ND, "TL-WR941ND", "TP-LINK TL-WR941ND",
  5925. + tl_wr941nd_setup);
  5926. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/machtype.h linux-2.6.33.3/arch/mips/ar71xx/machtype.h
  5927. --- linux-2.6.33.3.orig/arch/mips/ar71xx/machtype.h 1970-01-01 01:00:00.000000000 +0100
  5928. +++ linux-2.6.33.3/arch/mips/ar71xx/machtype.h 2010-05-16 13:17:32.799599694 +0200
  5929. @@ -0,0 +1,60 @@
  5930. +/*
  5931. + * Atheros AR71xx machine type definitions
  5932. + *
  5933. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  5934. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5935. + *
  5936. + * This program is free software; you can redistribute it and/or modify it
  5937. + * under the terms of the GNU General Public License version 2 as published
  5938. + * by the Free Software Foundation.
  5939. + */
  5940. +
  5941. +#ifndef _AR71XX_MACHTYPE_H
  5942. +#define _AR71XX_MACHTYPE_H
  5943. +
  5944. +#include <asm/mips_machine.h>
  5945. +
  5946. +enum ar71xx_mach_type {
  5947. + AR71XX_MACH_GENERIC = 0,
  5948. + AR71XX_MACH_AP81, /* Atheros AP81 */
  5949. + AR71XX_MACH_AP83, /* Atheros AP83 */
  5950. + AR71XX_MACH_AW_NR580, /* AzureWave AW-NR580 */
  5951. + AR71XX_MACH_DIR_600_A1, /* D-Link DIR-600 rev. A1 */
  5952. + AR71XX_MACH_DIR_615_C1, /* D-Link DIR-615 rev. C1 */
  5953. + AR71XX_MACH_DIR_825_B1, /* D-Link DIR-825 rev. B1 */
  5954. + AR71XX_MACH_RB_411, /* MikroTik RouterBOARD 411/411A/411AH */
  5955. + AR71XX_MACH_RB_411U, /* MikroTik RouterBOARD 411U */
  5956. + AR71XX_MACH_RB_433, /* MikroTik RouterBOARD 433/433AH */
  5957. + AR71XX_MACH_RB_433U, /* MikroTik RouterBOARD 433UAH */
  5958. + AR71XX_MACH_RB_450, /* MikroTik RouterBOARD 450 */
  5959. + AR71XX_MACH_RB_450G, /* MikroTik RouterBOARD 450G */
  5960. + AR71XX_MACH_RB_493, /* Mikrotik RouterBOARD 493/493AH */
  5961. + AR71XX_MACH_RB_750, /* MikroTik RouterBOARD 750 */
  5962. + AR71XX_MACH_PB42, /* Atheros PB42 */
  5963. + AR71XX_MACH_PB44, /* Atheros PB44 */
  5964. + AR71XX_MACH_PB92, /* Atheros PB92 */
  5965. + AR71XX_MACH_MZK_W04NU, /* Planex MZK-W04NU */
  5966. + AR71XX_MACH_MZK_W300NH, /* Planex MZK-W300NH */
  5967. + AR71XX_MACH_NBG460N, /* Zyxel NBG460N/550N/550NH */
  5968. + AR71XX_MACH_TEW_632BRP, /* TRENDnet TEW-632BRP */
  5969. + AR71XX_MACH_TL_WR741ND, /* TP-LINK TL-WR741ND */
  5970. + AR71XX_MACH_TL_WR841N_V1, /* TP-LINK TL-WR841N v1 */
  5971. + AR71XX_MACH_TL_WR941ND, /* TP-LINK TL-WR941ND */
  5972. + AR71XX_MACH_TL_WR1043ND, /* TP-LINK TL-WR1041ND */
  5973. + AR71XX_MACH_UBNT_LSSR71, /* Ubiquiti LS-SR71 */
  5974. + AR71XX_MACH_UBNT_LSX, /* Ubiquiti LSX */
  5975. + AR71XX_MACH_UBNT_RS, /* Ubiquiti RouterStation */
  5976. + AR71XX_MACH_UBNT_AR71XX, /* Ubiquiti AR71xx-based board */
  5977. + AR71XX_MACH_UBNT_RSPRO, /* Ubiquiti RouterStation Pro */
  5978. + AR71XX_MACH_UBNT_BULLET_M, /* Ubiquiti Bullet M */
  5979. + AR71XX_MACH_UBNT_ROCKET_M, /* Ubiquiti Rocket M */
  5980. + AR71XX_MACH_UBNT_NANO_M, /* Ubiquiti NanoStation M */
  5981. + AR71XX_MACH_WNDR3700, /* NETGEAR WNDR3700 */
  5982. + AR71XX_MACH_WNR2000, /* NETGEAR WNR2000 */
  5983. + AR71XX_MACH_WP543, /* Compex WP543 */
  5984. + AR71XX_MACH_WRT160NL, /* Linksys WRT160NL */
  5985. + AR71XX_MACH_WRT400N, /* Linksys WRT400N */
  5986. + AR71XX_MACH_WZR_HP_G300NH, /* Buffalo WZR-HP-G300NH */
  5987. +};
  5988. +
  5989. +#endif /* _AR71XX_MACHTYPE_H */
  5990. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ubnt.c linux-2.6.33.3/arch/mips/ar71xx/mach-ubnt.c
  5991. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-ubnt.c 1970-01-01 01:00:00.000000000 +0100
  5992. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-ubnt.c 2010-05-16 13:17:31.783601847 +0200
  5993. @@ -0,0 +1,281 @@
  5994. +/*
  5995. + * Ubiquiti RouterStation support
  5996. + *
  5997. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5998. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5999. + * Copyright (C) 2008 Ubiquiti <support@ubnt.com>
  6000. + *
  6001. + * This program is free software; you can redistribute it and/or modify it
  6002. + * under the terms of the GNU General Public License version 2 as published
  6003. + * by the Free Software Foundation.
  6004. + */
  6005. +
  6006. +#include <asm/mach-ar71xx/ar71xx.h>
  6007. +
  6008. +#include "machtype.h"
  6009. +#include "devices.h"
  6010. +#include "dev-m25p80.h"
  6011. +#include "dev-ap91-pci.h"
  6012. +#include "dev-gpio-buttons.h"
  6013. +#include "dev-pb42-pci.h"
  6014. +#include "dev-leds-gpio.h"
  6015. +#include "dev-usb.h"
  6016. +
  6017. +#define UBNT_RS_GPIO_LED_RF 2
  6018. +#define UBNT_RS_GPIO_SW4 8
  6019. +
  6020. +#define UBNT_LS_SR71_GPIO_LED_D25 0
  6021. +#define UBNT_LS_SR71_GPIO_LED_D26 1
  6022. +#define UBNT_LS_SR71_GPIO_LED_D24 2
  6023. +#define UBNT_LS_SR71_GPIO_LED_D23 4
  6024. +#define UBNT_LS_SR71_GPIO_LED_D22 5
  6025. +#define UBNT_LS_SR71_GPIO_LED_D27 6
  6026. +#define UBNT_LS_SR71_GPIO_LED_D28 7
  6027. +
  6028. +#define UBNT_M_GPIO_LED_L1 0
  6029. +#define UBNT_M_GPIO_LED_L2 1
  6030. +#define UBNT_M_GPIO_LED_L3 11
  6031. +#define UBNT_M_GPIO_LED_L4 7
  6032. +#define UBNT_M_GPIO_BTN_RESET 12
  6033. +
  6034. +#define UBNT_BUTTONS_POLL_INTERVAL 20
  6035. +
  6036. +static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
  6037. + {
  6038. + .name = "ubnt:green:rf",
  6039. + .gpio = UBNT_RS_GPIO_LED_RF,
  6040. + .active_low = 0,
  6041. + }
  6042. +};
  6043. +
  6044. +static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
  6045. + {
  6046. + .name = "ubnt:green:d22",
  6047. + .gpio = UBNT_LS_SR71_GPIO_LED_D22,
  6048. + .active_low = 0,
  6049. + }, {
  6050. + .name = "ubnt:green:d23",
  6051. + .gpio = UBNT_LS_SR71_GPIO_LED_D23,
  6052. + .active_low = 0,
  6053. + }, {
  6054. + .name = "ubnt:green:d24",
  6055. + .gpio = UBNT_LS_SR71_GPIO_LED_D24,
  6056. + .active_low = 0,
  6057. + }, {
  6058. + .name = "ubnt:red:d25",
  6059. + .gpio = UBNT_LS_SR71_GPIO_LED_D25,
  6060. + .active_low = 0,
  6061. + }, {
  6062. + .name = "ubnt:red:d26",
  6063. + .gpio = UBNT_LS_SR71_GPIO_LED_D26,
  6064. + .active_low = 0,
  6065. + }, {
  6066. + .name = "ubnt:green:d27",
  6067. + .gpio = UBNT_LS_SR71_GPIO_LED_D27,
  6068. + .active_low = 0,
  6069. + }, {
  6070. + .name = "ubnt:green:d28",
  6071. + .gpio = UBNT_LS_SR71_GPIO_LED_D28,
  6072. + .active_low = 0,
  6073. + }
  6074. +};
  6075. +
  6076. +static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
  6077. + {
  6078. + .name = "ubnt:red:link1",
  6079. + .gpio = UBNT_M_GPIO_LED_L1,
  6080. + .active_low = 0,
  6081. + }, {
  6082. + .name = "ubnt:orange:link2",
  6083. + .gpio = UBNT_M_GPIO_LED_L2,
  6084. + .active_low = 0,
  6085. + }, {
  6086. + .name = "ubnt:green:link3",
  6087. + .gpio = UBNT_M_GPIO_LED_L3,
  6088. + .active_low = 0,
  6089. + }, {
  6090. + .name = "ubnt:green:link4",
  6091. + .gpio = UBNT_M_GPIO_LED_L4,
  6092. + .active_low = 0,
  6093. + }
  6094. +};
  6095. +
  6096. +static struct gpio_button ubnt_gpio_buttons[] __initdata = {
  6097. + {
  6098. + .desc = "sw4",
  6099. + .type = EV_KEY,
  6100. + .code = KEY_RESTART,
  6101. + .threshold = 3,
  6102. + .gpio = UBNT_RS_GPIO_SW4,
  6103. + .active_low = 1,
  6104. + }
  6105. +};
  6106. +
  6107. +static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
  6108. + {
  6109. + .desc = "reset",
  6110. + .type = EV_KEY,
  6111. + .code = KEY_RESTART,
  6112. + .threshold = 3,
  6113. + .gpio = UBNT_M_GPIO_BTN_RESET,
  6114. + .active_low = 1,
  6115. + }
  6116. +};
  6117. +
  6118. +static void __init ubnt_generic_setup(void)
  6119. +{
  6120. + ar71xx_add_device_m25p80(NULL);
  6121. +
  6122. + ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
  6123. + ARRAY_SIZE(ubnt_gpio_buttons),
  6124. + ubnt_gpio_buttons);
  6125. +
  6126. + pb42_pci_init();
  6127. +}
  6128. +
  6129. +#define UBNT_RS_WAN_PHYMASK (1 << 20)
  6130. +#define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
  6131. +
  6132. +static void __init ubnt_rs_setup(void)
  6133. +{
  6134. + ubnt_generic_setup();
  6135. +
  6136. + ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
  6137. +
  6138. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6139. + ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
  6140. +
  6141. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6142. + ar71xx_eth1_data.speed = SPEED_100;
  6143. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6144. +
  6145. + ar71xx_add_device_eth(0);
  6146. + ar71xx_add_device_eth(1);
  6147. +
  6148. + ar71xx_add_device_usb();
  6149. +
  6150. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  6151. + ubnt_rs_leds_gpio);
  6152. +}
  6153. +
  6154. +MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
  6155. + ubnt_rs_setup);
  6156. +
  6157. +MIPS_MACHINE(AR71XX_MACH_UBNT_AR71XX, "Ubiquiti AR71xx-based board",
  6158. + "Ubiquiti RouterStation", ubnt_rs_setup);
  6159. +
  6160. +#define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
  6161. +#define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
  6162. +
  6163. +static void __init ubnt_rspro_setup(void)
  6164. +{
  6165. + ubnt_generic_setup();
  6166. +
  6167. + ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
  6168. +
  6169. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6170. + ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
  6171. +
  6172. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6173. + ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
  6174. + ar71xx_eth1_data.speed = SPEED_1000;
  6175. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6176. +
  6177. + ar71xx_add_device_eth(0);
  6178. + ar71xx_add_device_eth(1);
  6179. +
  6180. + ar71xx_add_device_usb();
  6181. +
  6182. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  6183. + ubnt_rs_leds_gpio);
  6184. +}
  6185. +
  6186. +MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
  6187. + ubnt_rspro_setup);
  6188. +
  6189. +static void __init ubnt_lsx_setup(void)
  6190. +{
  6191. + ubnt_generic_setup();
  6192. +}
  6193. +
  6194. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
  6195. +
  6196. +#define UBNT_LSSR71_PHY_MASK (1 << 1)
  6197. +
  6198. +static void __init ubnt_lssr71_setup(void)
  6199. +{
  6200. + ubnt_generic_setup();
  6201. +
  6202. + ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
  6203. +
  6204. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6205. + ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
  6206. +
  6207. + ar71xx_add_device_eth(0);
  6208. +
  6209. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
  6210. + ubnt_ls_sr71_leds_gpio);
  6211. +}
  6212. +
  6213. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
  6214. + ubnt_lssr71_setup);
  6215. +
  6216. +static void __init ubnt_m_setup(void)
  6217. +{
  6218. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  6219. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  6220. +
  6221. + ar71xx_set_mac_base(mac);
  6222. +
  6223. + ar71xx_add_device_m25p80(NULL);
  6224. +
  6225. + ar71xx_add_device_mdio(~0);
  6226. +
  6227. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6228. + ar71xx_eth0_data.speed = SPEED_100;
  6229. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6230. + ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
  6231. + ar71xx_eth0_data.fifo_cfg2 = 0x015500aa;
  6232. + ar71xx_eth0_data.fifo_cfg3 = 0x01f00140;
  6233. +
  6234. + ar71xx_add_device_eth(0);
  6235. +
  6236. + ap91_pci_init(ee, NULL);
  6237. +
  6238. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
  6239. + ubnt_m_leds_gpio);
  6240. +
  6241. + ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
  6242. + ARRAY_SIZE(ubnt_m_gpio_buttons),
  6243. + ubnt_m_gpio_buttons);
  6244. +}
  6245. +
  6246. +static void __init ubnt_rocket_m_setup(void)
  6247. +{
  6248. + ubnt_m_setup();
  6249. + ar71xx_add_device_usb();
  6250. +}
  6251. +
  6252. +MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
  6253. + ubnt_m_setup);
  6254. +MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
  6255. + ubnt_rocket_m_setup);
  6256. +
  6257. +/* TODO detect the second ethernet port and use one
  6258. + init function for all Ubiquiti MIMO series products */
  6259. +static void __init ubnt_nano_m_setup(void)
  6260. +{
  6261. + ubnt_m_setup();
  6262. +
  6263. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6264. + ar71xx_eth1_data.speed = SPEED_1000;
  6265. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6266. + ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
  6267. + ar71xx_eth1_data.fifo_cfg2 = 0x015500aa;
  6268. + ar71xx_eth1_data.fifo_cfg3 = 0x01f00140;
  6269. +
  6270. + ar71xx_add_device_eth(1);
  6271. +}
  6272. +
  6273. +MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
  6274. + ubnt_nano_m_setup);
  6275. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wndr3700.c linux-2.6.33.3/arch/mips/ar71xx/mach-wndr3700.c
  6276. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wndr3700.c 1970-01-01 01:00:00.000000000 +0100
  6277. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wndr3700.c 2010-05-16 13:17:33.059599577 +0200
  6278. @@ -0,0 +1,209 @@
  6279. +/*
  6280. + * Netgear WNDR3700 board support
  6281. + *
  6282. + * Copyright (C) 2009 Marco Porsch
  6283. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  6284. + *
  6285. + * This program is free software; you can redistribute it and/or modify it
  6286. + * under the terms of the GNU General Public License version 2 as published
  6287. + * by the Free Software Foundation.
  6288. + */
  6289. +
  6290. +#include <linux/platform_device.h>
  6291. +#include <linux/mtd/mtd.h>
  6292. +#include <linux/mtd/partitions.h>
  6293. +#include <linux/delay.h>
  6294. +#include <linux/rtl8366s.h>
  6295. +
  6296. +#include <asm/mach-ar71xx/ar71xx.h>
  6297. +
  6298. +#include "machtype.h"
  6299. +#include "devices.h"
  6300. +#include "dev-m25p80.h"
  6301. +#include "dev-ap94-pci.h"
  6302. +#include "dev-gpio-buttons.h"
  6303. +#include "dev-leds-gpio.h"
  6304. +#include "dev-usb.h"
  6305. +
  6306. +#define WNDR3700_GPIO_LED_WPS_ORANGE 0
  6307. +#define WNDR3700_GPIO_LED_POWER_ORANGE 1
  6308. +#define WNDR3700_GPIO_LED_POWER_GREEN 2
  6309. +#define WNDR3700_GPIO_LED_WPS_GREEN 4
  6310. +#define WNDR3700_GPIO_LED_WAN_GREEN 6
  6311. +
  6312. +#define WNDR3700_GPIO_BTN_WPS 3
  6313. +#define WNDR3700_GPIO_BTN_RESET 8
  6314. +#define WNDR3700_GPIO_BTN_WIFI 11
  6315. +
  6316. +#define WNDR3700_GPIO_RTL8366_SDA 5
  6317. +#define WNDR3700_GPIO_RTL8366_SCK 7
  6318. +
  6319. +#define WNDR3700_BUTTONS_POLL_INTERVAL 20
  6320. +
  6321. +#define WNDR3700_WMAC0_MAC_OFFSET 0
  6322. +#define WNDR3700_WMAC1_MAC_OFFSET 0xc
  6323. +#define WNDR3700_CALDATA0_OFFSET 0x1000
  6324. +#define WNDR3700_CALDATA1_OFFSET 0x5000
  6325. +
  6326. +#ifdef CONFIG_MTD_PARTITIONS
  6327. +static struct mtd_partition wndr3700_partitions[] = {
  6328. + {
  6329. + .name = "uboot",
  6330. + .offset = 0,
  6331. + .size = 0x050000,
  6332. + .mask_flags = MTD_WRITEABLE,
  6333. + } , {
  6334. + .name = "env",
  6335. + .offset = 0x050000,
  6336. + .size = 0x020000,
  6337. + .mask_flags = MTD_WRITEABLE,
  6338. + } , {
  6339. + .name = "rootfs",
  6340. + .offset = 0x070000,
  6341. + .size = 0x720000,
  6342. + } , {
  6343. + .name = "config",
  6344. + .offset = 0x790000,
  6345. + .size = 0x010000,
  6346. + .mask_flags = MTD_WRITEABLE,
  6347. + } , {
  6348. + .name = "config_bak",
  6349. + .offset = 0x7a0000,
  6350. + .size = 0x010000,
  6351. + .mask_flags = MTD_WRITEABLE,
  6352. + } , {
  6353. + .name = "pot",
  6354. + .offset = 0x7b0000,
  6355. + .size = 0x010000,
  6356. + .mask_flags = MTD_WRITEABLE,
  6357. + } , {
  6358. + .name = "traffic_meter",
  6359. + .offset = 0x7c0000,
  6360. + .size = 0x010000,
  6361. + .mask_flags = MTD_WRITEABLE,
  6362. + } , {
  6363. + .name = "language",
  6364. + .offset = 0x7d0000,
  6365. + .size = 0x020000,
  6366. + .mask_flags = MTD_WRITEABLE,
  6367. + } , {
  6368. + .name = "caldata",
  6369. + .offset = 0x7f0000,
  6370. + .size = 0x010000,
  6371. + .mask_flags = MTD_WRITEABLE,
  6372. + }
  6373. +};
  6374. +#endif /* CONFIG_MTD_PARTITIONS */
  6375. +
  6376. +static struct flash_platform_data wndr3700_flash_data = {
  6377. +#ifdef CONFIG_MTD_PARTITIONS
  6378. + .parts = wndr3700_partitions,
  6379. + .nr_parts = ARRAY_SIZE(wndr3700_partitions),
  6380. +#endif
  6381. +};
  6382. +
  6383. +static struct gpio_led wndr3700_leds_gpio[] __initdata = {
  6384. + {
  6385. + .name = "wndr3700:green:power",
  6386. + .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
  6387. + .active_low = 1,
  6388. + }, {
  6389. + .name = "wndr3700:orange:power",
  6390. + .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
  6391. + .active_low = 1,
  6392. + }, {
  6393. + .name = "wndr3700:green:wps",
  6394. + .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
  6395. + .active_low = 1,
  6396. + }, {
  6397. + .name = "wndr3700:orange:wps",
  6398. + .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
  6399. + .active_low = 1,
  6400. + }, {
  6401. + .name = "wndr3700:green:wan",
  6402. + .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
  6403. + .active_low = 1,
  6404. + }
  6405. +};
  6406. +
  6407. +static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
  6408. + {
  6409. + .desc = "reset",
  6410. + .type = EV_KEY,
  6411. + .code = KEY_RESTART,
  6412. + .threshold = 3,
  6413. + .gpio = WNDR3700_GPIO_BTN_RESET,
  6414. + .active_low = 1,
  6415. + }, {
  6416. + .desc = "wps",
  6417. + .type = EV_KEY,
  6418. + .code = KEY_WPS_BUTTON,
  6419. + .threshold = 3,
  6420. + .gpio = WNDR3700_GPIO_BTN_WPS,
  6421. + .active_low = 1,
  6422. + } , {
  6423. + .desc = "wifi",
  6424. + .type = EV_KEY,
  6425. + .code = BTN_2,
  6426. + .threshold = 3,
  6427. + .gpio = WNDR3700_GPIO_BTN_WIFI,
  6428. + .active_low = 1,
  6429. + }
  6430. +};
  6431. +
  6432. +static struct rtl8366s_platform_data wndr3700_rtl8366s_data = {
  6433. + .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
  6434. + .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
  6435. +};
  6436. +
  6437. +static struct platform_device wndr3700_rtl8366s_device = {
  6438. + .name = RTL8366S_DRIVER_NAME,
  6439. + .id = -1,
  6440. + .dev = {
  6441. + .platform_data = &wndr3700_rtl8366s_data,
  6442. + }
  6443. +};
  6444. +
  6445. +static void __init wndr3700_setup(void)
  6446. +{
  6447. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  6448. +
  6449. + ar71xx_set_mac_base(art);
  6450. +
  6451. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  6452. + ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  6453. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6454. + ar71xx_eth0_data.speed = SPEED_1000;
  6455. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6456. +
  6457. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  6458. + ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  6459. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6460. + ar71xx_eth1_data.phy_mask = 0x10;
  6461. +
  6462. + ar71xx_add_device_eth(0);
  6463. + ar71xx_add_device_eth(1);
  6464. +
  6465. + ar71xx_add_device_usb();
  6466. +
  6467. + ar71xx_add_device_m25p80(&wndr3700_flash_data);
  6468. +
  6469. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
  6470. + wndr3700_leds_gpio);
  6471. +
  6472. + ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
  6473. + ARRAY_SIZE(wndr3700_gpio_buttons),
  6474. + wndr3700_gpio_buttons);
  6475. +
  6476. + platform_device_register(&wndr3700_rtl8366s_device);
  6477. + platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
  6478. +
  6479. + ap94_pci_enable_quirk_wndr3700();
  6480. + ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
  6481. + art + WNDR3700_WMAC0_MAC_OFFSET,
  6482. + art + WNDR3700_CALDATA1_OFFSET,
  6483. + art + WNDR3700_WMAC1_MAC_OFFSET);
  6484. +}
  6485. +
  6486. +MIPS_MACHINE(AR71XX_MACH_WNDR3700, "WNDR3700", "NETGEAR WNDR3700",
  6487. + wndr3700_setup);
  6488. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wnr2000.c linux-2.6.33.3/arch/mips/ar71xx/mach-wnr2000.c
  6489. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wnr2000.c 1970-01-01 01:00:00.000000000 +0100
  6490. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wnr2000.c 2010-05-16 13:17:31.783601847 +0200
  6491. @@ -0,0 +1,148 @@
  6492. +/*
  6493. + * NETGEAR WNR2000 board support
  6494. + *
  6495. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6496. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6497. + * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
  6498. + *
  6499. + * This program is free software; you can redistribute it and/or modify it
  6500. + * under the terms of the GNU General Public License version 2 as published
  6501. + * by the Free Software Foundation.
  6502. + */
  6503. +
  6504. +#include <linux/mtd/mtd.h>
  6505. +#include <linux/mtd/partitions.h>
  6506. +
  6507. +#include <asm/mach-ar71xx/ar71xx.h>
  6508. +
  6509. +#include "machtype.h"
  6510. +#include "devices.h"
  6511. +#include "dev-m25p80.h"
  6512. +#include "dev-ar913x-wmac.h"
  6513. +#include "dev-gpio-buttons.h"
  6514. +#include "dev-leds-gpio.h"
  6515. +
  6516. +#define WNR2000_GPIO_LED_PWR_GREEN 14
  6517. +#define WNR2000_GPIO_LED_PWR_AMBER 7
  6518. +#define WNR2000_GPIO_LED_WPS 4
  6519. +#define WNR2000_GPIO_LED_WLAN 6
  6520. +#define WNR2000_GPIO_BTN_RESET 21
  6521. +#define WNR2000_GPIO_BTN_WPS 8
  6522. +
  6523. +#define WNR2000_BUTTONS_POLL_INTERVAL 20
  6524. +
  6525. +#ifdef CONFIG_MTD_PARTITIONS
  6526. +static struct mtd_partition wnr2000_partitions[] = {
  6527. + {
  6528. + .name = "u-boot",
  6529. + .offset = 0,
  6530. + .size = 0x040000,
  6531. + .mask_flags = MTD_WRITEABLE,
  6532. + } , {
  6533. + .name = "u-boot-env",
  6534. + .offset = 0x040000,
  6535. + .size = 0x010000,
  6536. + } , {
  6537. + .name = "rootfs",
  6538. + .offset = 0x050000,
  6539. + .size = 0x240000,
  6540. + } , {
  6541. + .name = "user-config",
  6542. + .offset = 0x290000,
  6543. + .size = 0x010000,
  6544. + } , {
  6545. + .name = "uImage",
  6546. + .offset = 0x2a0000,
  6547. + .size = 0x120000,
  6548. + } , {
  6549. + .name = "language_table",
  6550. + .offset = 0x3c0000,
  6551. + .size = 0x020000,
  6552. + } , {
  6553. + .name = "rootfs_checksum",
  6554. + .offset = 0x3e0000,
  6555. + .size = 0x010000,
  6556. + } , {
  6557. + .name = "art",
  6558. + .offset = 0x3f0000,
  6559. + .size = 0x010000,
  6560. + .mask_flags = MTD_WRITEABLE,
  6561. + }
  6562. +};
  6563. +#endif /* CONFIG_MTD_PARTITIONS */
  6564. +
  6565. +static struct flash_platform_data wnr2000_flash_data = {
  6566. +#ifdef CONFIG_MTD_PARTITIONS
  6567. + .parts = wnr2000_partitions,
  6568. + .nr_parts = ARRAY_SIZE(wnr2000_partitions),
  6569. +#endif
  6570. +};
  6571. +
  6572. +static struct gpio_led wnr2000_leds_gpio[] __initdata = {
  6573. + {
  6574. + .name = "wnr2000:green:power",
  6575. + .gpio = WNR2000_GPIO_LED_PWR_GREEN,
  6576. + .active_low = 1,
  6577. + }, {
  6578. + .name = "wnr2000:amber:power",
  6579. + .gpio = WNR2000_GPIO_LED_PWR_AMBER,
  6580. + .active_low = 1,
  6581. + }, {
  6582. + .name = "wnr2000:green:wps",
  6583. + .gpio = WNR2000_GPIO_LED_WPS,
  6584. + .active_low = 1,
  6585. + }, {
  6586. + .name = "wnr2000:blue:wlan",
  6587. + .gpio = WNR2000_GPIO_LED_WLAN,
  6588. + .active_low = 1,
  6589. + }
  6590. +};
  6591. +
  6592. +static struct gpio_button wnr2000_gpio_buttons[] __initdata = {
  6593. + {
  6594. + .desc = "reset",
  6595. + .type = EV_KEY,
  6596. + .code = KEY_RESTART,
  6597. + .threshold = 3,
  6598. + .gpio = WNR2000_GPIO_BTN_RESET,
  6599. + }, {
  6600. + .desc = "wps",
  6601. + .type = EV_KEY,
  6602. + .code = KEY_WPS_BUTTON,
  6603. + .threshold = 3,
  6604. + .gpio = WNR2000_GPIO_BTN_WPS,
  6605. + }
  6606. +};
  6607. +
  6608. +static void __init wnr2000_setup(void)
  6609. +{
  6610. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  6611. +
  6612. + ar71xx_set_mac_base(eeprom);
  6613. + ar71xx_add_device_mdio(0x0);
  6614. +
  6615. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6616. + ar71xx_eth0_data.speed = SPEED_100;
  6617. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6618. + ar71xx_eth0_data.has_ar8216 = 1;
  6619. +
  6620. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6621. + ar71xx_eth1_data.phy_mask = 0x10;
  6622. +
  6623. + ar71xx_add_device_eth(0);
  6624. + ar71xx_add_device_eth(1);
  6625. +
  6626. + ar71xx_add_device_m25p80(&wnr2000_flash_data);
  6627. +
  6628. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wnr2000_leds_gpio),
  6629. + wnr2000_leds_gpio);
  6630. +
  6631. + ar71xx_add_device_gpio_buttons(-1, WNR2000_BUTTONS_POLL_INTERVAL,
  6632. + ARRAY_SIZE(wnr2000_gpio_buttons),
  6633. + wnr2000_gpio_buttons);
  6634. +
  6635. +
  6636. + ar913x_add_device_wmac(eeprom, NULL);
  6637. +}
  6638. +
  6639. +MIPS_MACHINE(AR71XX_MACH_WNR2000, "WNR2000", "NETGEAR WNR2000", wnr2000_setup);
  6640. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wp543.c linux-2.6.33.3/arch/mips/ar71xx/mach-wp543.c
  6641. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wp543.c 1970-01-01 01:00:00.000000000 +0100
  6642. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wp543.c 2010-03-23 20:31:05.506280502 +0100
  6643. @@ -0,0 +1,99 @@
  6644. +/*
  6645. + * Compex WP543/WPJ543 board support
  6646. + *
  6647. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6648. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6649. + *
  6650. + * This program is free software; you can redistribute it and/or modify it
  6651. + * under the terms of the GNU General Public License version 2 as published
  6652. + * by the Free Software Foundation.
  6653. + */
  6654. +
  6655. +#include <linux/mtd/mtd.h>
  6656. +#include <linux/mtd/partitions.h>
  6657. +
  6658. +#include <asm/mach-ar71xx/ar71xx.h>
  6659. +
  6660. +#include "machtype.h"
  6661. +#include "devices.h"
  6662. +#include "dev-m25p80.h"
  6663. +#include "dev-pb42-pci.h"
  6664. +#include "dev-gpio-buttons.h"
  6665. +#include "dev-leds-gpio.h"
  6666. +#include "dev-usb.h"
  6667. +
  6668. +#define WP543_GPIO_SW6 2
  6669. +#define WP543_GPIO_LED_1 3
  6670. +#define WP543_GPIO_LED_2 4
  6671. +#define WP543_GPIO_LED_WLAN 5
  6672. +#define WP543_GPIO_LED_CONN 6
  6673. +#define WP543_GPIO_LED_DIAG 7
  6674. +#define WP543_GPIO_SW4 8
  6675. +
  6676. +#define WP543_BUTTONS_POLL_INTERVAL 20
  6677. +
  6678. +static struct gpio_led wp543_leds_gpio[] __initdata = {
  6679. + {
  6680. + .name = "wp543:green:led1",
  6681. + .gpio = WP543_GPIO_LED_1,
  6682. + .active_low = 1,
  6683. + }, {
  6684. + .name = "wp543:green:led2",
  6685. + .gpio = WP543_GPIO_LED_2,
  6686. + .active_low = 1,
  6687. + }, {
  6688. + .name = "wp543:green:wlan",
  6689. + .gpio = WP543_GPIO_LED_WLAN,
  6690. + .active_low = 1,
  6691. + }, {
  6692. + .name = "wp543:green:conn",
  6693. + .gpio = WP543_GPIO_LED_CONN,
  6694. + .active_low = 1,
  6695. + }, {
  6696. + .name = "wp543:green:diag",
  6697. + .gpio = WP543_GPIO_LED_DIAG,
  6698. + .active_low = 1,
  6699. + }
  6700. +};
  6701. +
  6702. +static struct gpio_button wp543_gpio_buttons[] __initdata = {
  6703. + {
  6704. + .desc = "sw6",
  6705. + .type = EV_KEY,
  6706. + .code = BTN_0,
  6707. + .threshold = 3,
  6708. + .gpio = WP543_GPIO_SW6,
  6709. + }, {
  6710. + .desc = "sw4",
  6711. + .type = EV_KEY,
  6712. + .code = BTN_1,
  6713. + .threshold = 3,
  6714. + .gpio = WP543_GPIO_SW4,
  6715. + }
  6716. +};
  6717. +
  6718. +static void __init wp543_setup(void)
  6719. +{
  6720. + ar71xx_add_device_m25p80(NULL);
  6721. +
  6722. + ar71xx_add_device_mdio(0xfffffff7);
  6723. +
  6724. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6725. + ar71xx_eth0_data.phy_mask = 0x08;
  6726. + ar71xx_eth0_data.reset_bit = RESET_MODULE_GE0_MAC |
  6727. + RESET_MODULE_GE0_PHY;
  6728. + ar71xx_add_device_eth(0);
  6729. +
  6730. + ar71xx_add_device_usb();
  6731. +
  6732. + pb42_pci_init();
  6733. +
  6734. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wp543_leds_gpio),
  6735. + wp543_leds_gpio);
  6736. +
  6737. + ar71xx_add_device_gpio_buttons(-1, WP543_BUTTONS_POLL_INTERVAL,
  6738. + ARRAY_SIZE(wp543_gpio_buttons),
  6739. + wp543_gpio_buttons);
  6740. +}
  6741. +
  6742. +MIPS_MACHINE(AR71XX_MACH_WP543, "WP543", "Compex WP543", wp543_setup);
  6743. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wrt160nl.c linux-2.6.33.3/arch/mips/ar71xx/mach-wrt160nl.c
  6744. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wrt160nl.c 1970-01-01 01:00:00.000000000 +0100
  6745. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wrt160nl.c 2010-05-16 13:17:32.731626515 +0200
  6746. @@ -0,0 +1,158 @@
  6747. +/*
  6748. + * Linksys WRT160NL board support
  6749. + *
  6750. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  6751. + *
  6752. + * This program is free software; you can redistribute it and/or modify it
  6753. + * under the terms of the GNU General Public License version 2 as published
  6754. + * by the Free Software Foundation.
  6755. + */
  6756. +
  6757. +#include <linux/mtd/mtd.h>
  6758. +#include <linux/mtd/partitions.h>
  6759. +
  6760. +#include <asm/mach-ar71xx/ar71xx.h>
  6761. +
  6762. +#include "machtype.h"
  6763. +#include "devices.h"
  6764. +#include "dev-m25p80.h"
  6765. +#include "dev-ar913x-wmac.h"
  6766. +#include "dev-gpio-buttons.h"
  6767. +#include "dev-leds-gpio.h"
  6768. +#include "dev-usb.h"
  6769. +#include "nvram.h"
  6770. +
  6771. +#define WRT160NL_GPIO_LED_POWER 14
  6772. +#define WRT160NL_GPIO_LED_WPS_AMBER 9
  6773. +#define WRT160NL_GPIO_LED_WPS_BLUE 8
  6774. +#define WRT160NL_GPIO_LED_WLAN 6
  6775. +
  6776. +#define WRT160NL_GPIO_BTN_WPS 7
  6777. +#define WRT160NL_GPIO_BTN_RESET 21
  6778. +
  6779. +#define WRT160NL_BUTTONS_POLL_INTERVAL 20
  6780. +
  6781. +#define WRT160NL_NVRAM_ADDR 0x1f7e0000
  6782. +#define WRT160NL_NVRAM_SIZE 0x10000
  6783. +
  6784. +#ifdef CONFIG_MTD_PARTITIONS
  6785. +static struct mtd_partition wrt160nl_partitions[] = {
  6786. + {
  6787. + .name = "u-boot",
  6788. + .offset = 0,
  6789. + .size = 0x040000,
  6790. + .mask_flags = MTD_WRITEABLE,
  6791. + } , {
  6792. + .name = "kernel",
  6793. + .offset = 0x040000,
  6794. + .size = 0x0e0000,
  6795. + } , {
  6796. + .name = "filesytem",
  6797. + .offset = 0x120000,
  6798. + .size = 0x6c0000,
  6799. + } , {
  6800. + .name = "nvram",
  6801. + .offset = 0x7e0000,
  6802. + .size = 0x010000,
  6803. + .mask_flags = MTD_WRITEABLE,
  6804. + } , {
  6805. + .name = "ART",
  6806. + .offset = 0x7f0000,
  6807. + .size = 0x010000,
  6808. + .mask_flags = MTD_WRITEABLE,
  6809. + } , {
  6810. + .name = "firmware",
  6811. + .offset = 0x040000,
  6812. + .size = 0x7a0000,
  6813. + }
  6814. +};
  6815. +#endif /* CONFIG_MTD_PARTITIONS */
  6816. +
  6817. +static struct flash_platform_data wrt160nl_flash_data = {
  6818. +#ifdef CONFIG_MTD_PARTITIONS
  6819. + .parts = wrt160nl_partitions,
  6820. + .nr_parts = ARRAY_SIZE(wrt160nl_partitions),
  6821. +#endif
  6822. +};
  6823. +
  6824. +static struct gpio_led wrt160nl_leds_gpio[] __initdata = {
  6825. + {
  6826. + .name = "wrt160nl:blue:power",
  6827. + .gpio = WRT160NL_GPIO_LED_POWER,
  6828. + .active_low = 1,
  6829. + .default_trigger = "default-on",
  6830. + }, {
  6831. + .name = "wrt160nl:amber:wps",
  6832. + .gpio = WRT160NL_GPIO_LED_WPS_AMBER,
  6833. + .active_low = 1,
  6834. + }, {
  6835. + .name = "wrt160nl:blue:wps",
  6836. + .gpio = WRT160NL_GPIO_LED_WPS_BLUE,
  6837. + .active_low = 1,
  6838. + }, {
  6839. + .name = "wrt160nl:blue:wlan",
  6840. + .gpio = WRT160NL_GPIO_LED_WLAN,
  6841. + .active_low = 1,
  6842. + }
  6843. +};
  6844. +
  6845. +static struct gpio_button wrt160nl_gpio_buttons[] __initdata = {
  6846. + {
  6847. + .desc = "reset",
  6848. + .type = EV_KEY,
  6849. + .code = KEY_RESTART,
  6850. + .threshold = 3,
  6851. + .gpio = WRT160NL_GPIO_BTN_RESET,
  6852. + .active_low = 1,
  6853. + }, {
  6854. + .desc = "wps",
  6855. + .type = EV_KEY,
  6856. + .code = KEY_WPS_BUTTON,
  6857. + .threshold = 3,
  6858. + .gpio = WRT160NL_GPIO_BTN_WPS,
  6859. + .active_low = 1,
  6860. + }
  6861. +};
  6862. +
  6863. +static void __init wrt160nl_setup(void)
  6864. +{
  6865. + const char *nvram = (char *) KSEG1ADDR(WRT160NL_NVRAM_ADDR);
  6866. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  6867. + u8 mac[6];
  6868. +
  6869. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  6870. + "lan_hwaddr=", mac) == 0)
  6871. + ar71xx_set_mac_base(mac);
  6872. +
  6873. + ar71xx_add_device_mdio(0x0);
  6874. +
  6875. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6876. + ar71xx_eth0_data.phy_mask = 0x01;
  6877. +
  6878. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6879. + ar71xx_eth1_data.phy_mask = 0x10;
  6880. +
  6881. + ar71xx_add_device_eth(0);
  6882. + ar71xx_add_device_eth(1);
  6883. +
  6884. + ar71xx_add_device_m25p80(&wrt160nl_flash_data);
  6885. +
  6886. + ar71xx_add_device_usb();
  6887. +
  6888. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  6889. + "wl0_hwaddr=", mac) == 0)
  6890. + ar913x_add_device_wmac(eeprom, mac);
  6891. + else
  6892. + ar913x_add_device_wmac(eeprom, NULL);
  6893. +
  6894. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt160nl_leds_gpio),
  6895. + wrt160nl_leds_gpio);
  6896. +
  6897. + ar71xx_add_device_gpio_buttons(-1, WRT160NL_BUTTONS_POLL_INTERVAL,
  6898. + ARRAY_SIZE(wrt160nl_gpio_buttons),
  6899. + wrt160nl_gpio_buttons);
  6900. +
  6901. +}
  6902. +
  6903. +MIPS_MACHINE(AR71XX_MACH_WRT160NL, "WRT160NL", "Linksys WRT160NL",
  6904. + wrt160nl_setup);
  6905. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wrt400n.c linux-2.6.33.3/arch/mips/ar71xx/mach-wrt400n.c
  6906. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wrt400n.c 1970-01-01 01:00:00.000000000 +0100
  6907. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wrt400n.c 2010-05-16 13:17:31.823599676 +0200
  6908. @@ -0,0 +1,168 @@
  6909. +/*
  6910. + * Linksys WRT400N board support
  6911. + *
  6912. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  6913. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  6914. + *
  6915. + * This program is free software; you can redistribute it and/or modify it
  6916. + * under the terms of the GNU General Public License version 2 as published
  6917. + * by the Free Software Foundation.
  6918. + */
  6919. +
  6920. +#include <linux/mtd/mtd.h>
  6921. +#include <linux/mtd/partitions.h>
  6922. +
  6923. +#include <asm/mach-ar71xx/ar71xx.h>
  6924. +
  6925. +#include "machtype.h"
  6926. +#include "devices.h"
  6927. +#include "dev-ap94-pci.h"
  6928. +#include "dev-m25p80.h"
  6929. +#include "dev-gpio-buttons.h"
  6930. +#include "dev-leds-gpio.h"
  6931. +
  6932. +#define WRT400N_GPIO_LED_ORANGE 5
  6933. +#define WRT400N_GPIO_LED_GREEN 4
  6934. +#define WRT400N_GPIO_LED_POWER 1
  6935. +#define WRT400N_GPIO_LED_WLAN 0
  6936. +
  6937. +#define WRT400N_GPIO_BTN_RESET 8
  6938. +#define WRT400N_GPIO_BTN_WLSEC 3
  6939. +
  6940. +#define WRT400N_BUTTONS_POLL_INTERVAL 20
  6941. +
  6942. +#define WRT400N_MAC_ADDR_OFFSET 0x120c
  6943. +#define WRT400N_CALDATA0_OFFSET 0x1000
  6944. +#define WRT400N_CALDATA1_OFFSET 0x5000
  6945. +
  6946. +#ifdef CONFIG_MTD_PARTITIONS
  6947. +static struct mtd_partition wrt400n_partitions[] = {
  6948. + {
  6949. + .name = "uboot",
  6950. + .offset = 0,
  6951. + .size = 0x030000,
  6952. + .mask_flags = MTD_WRITEABLE,
  6953. + } , {
  6954. + .name = "env",
  6955. + .offset = 0x030000,
  6956. + .size = 0x010000,
  6957. + .mask_flags = MTD_WRITEABLE,
  6958. + } , {
  6959. + .name = "linux",
  6960. + .offset = 0x040000,
  6961. + .size = 0x140000,
  6962. + } , {
  6963. + .name = "rootfs",
  6964. + .offset = 0x180000,
  6965. + .size = 0x630000,
  6966. + } , {
  6967. + .name = "nvram",
  6968. + .offset = 0x7b0000,
  6969. + .size = 0x010000,
  6970. + .mask_flags = MTD_WRITEABLE,
  6971. + } , {
  6972. + .name = "factory",
  6973. + .offset = 0x7c0000,
  6974. + .size = 0x010000,
  6975. + .mask_flags = MTD_WRITEABLE,
  6976. + } , {
  6977. + .name = "language",
  6978. + .offset = 0x7d0000,
  6979. + .size = 0x020000,
  6980. + .mask_flags = MTD_WRITEABLE,
  6981. + } , {
  6982. + .name = "caldata",
  6983. + .offset = 0x7f0000,
  6984. + .size = 0x010000,
  6985. + .mask_flags = MTD_WRITEABLE,
  6986. + } , {
  6987. + .name = "firmware",
  6988. + .offset = 0x040000,
  6989. + .size = 0x770000,
  6990. + }
  6991. +};
  6992. +#endif /* CONFIG_MTD_PARTITIONS */
  6993. +
  6994. +static struct flash_platform_data wrt400n_flash_data = {
  6995. +#ifdef CONFIG_MTD_PARTITIONS
  6996. + .parts = wrt400n_partitions,
  6997. + .nr_parts = ARRAY_SIZE(wrt400n_partitions),
  6998. +#endif
  6999. +};
  7000. +
  7001. +static struct gpio_led wrt400n_leds_gpio[] __initdata = {
  7002. + {
  7003. + .name = "wrt400n:green:status",
  7004. + .gpio = WRT400N_GPIO_LED_GREEN,
  7005. + .active_low = 1,
  7006. + }, {
  7007. + .name = "wrt400n:amber:aoss",
  7008. + .gpio = WRT400N_GPIO_LED_ORANGE,
  7009. + .active_low = 1,
  7010. + }, {
  7011. + .name = "wrt400n:green:wlan",
  7012. + .gpio = WRT400N_GPIO_LED_WLAN,
  7013. + .active_low = 1,
  7014. + }, {
  7015. + .name = "wrt400n:green:power",
  7016. + .gpio = WRT400N_GPIO_LED_POWER,
  7017. + .active_low = 1,
  7018. + }
  7019. +};
  7020. +
  7021. +static struct gpio_button wrt400n_gpio_buttons[] __initdata = {
  7022. + {
  7023. + .desc = "reset",
  7024. + .type = EV_KEY,
  7025. + .code = KEY_RESTART,
  7026. + .threshold = 3,
  7027. + .gpio = WRT400N_GPIO_BTN_RESET,
  7028. + .active_low = 1,
  7029. + } , {
  7030. + .desc = "wlsec",
  7031. + .type = EV_KEY,
  7032. + .code = KEY_WPS_BUTTON,
  7033. + .threshold = 3,
  7034. + .gpio = WRT400N_GPIO_BTN_WLSEC,
  7035. + .active_low = 1,
  7036. + }
  7037. +};
  7038. +
  7039. +static void __init wrt400n_setup(void)
  7040. +{
  7041. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  7042. + u8 mac[6];
  7043. + int i;
  7044. +
  7045. + memcpy(mac, art + WRT400N_MAC_ADDR_OFFSET, 6);
  7046. + for (i = 5; i >= 3; i--)
  7047. + if (++mac[i] != 0x00) break;
  7048. +
  7049. + ar71xx_set_mac_base(mac);
  7050. +
  7051. + ar71xx_add_device_mdio(0x0);
  7052. +
  7053. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7054. + ar71xx_eth0_data.speed = SPEED_100;
  7055. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7056. +
  7057. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7058. + ar71xx_eth1_data.phy_mask = 0x10;
  7059. +
  7060. + ar71xx_add_device_eth(0);
  7061. + ar71xx_add_device_eth(1);
  7062. +
  7063. + ar71xx_add_device_m25p80(&wrt400n_flash_data);
  7064. +
  7065. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt400n_leds_gpio),
  7066. + wrt400n_leds_gpio);
  7067. +
  7068. + ar71xx_add_device_gpio_buttons(-1, WRT400N_BUTTONS_POLL_INTERVAL,
  7069. + ARRAY_SIZE(wrt400n_gpio_buttons),
  7070. + wrt400n_gpio_buttons);
  7071. +
  7072. + ap94_pci_init(art + WRT400N_CALDATA0_OFFSET, NULL,
  7073. + art + WRT400N_CALDATA1_OFFSET, NULL);
  7074. +}
  7075. +
  7076. +MIPS_MACHINE(AR71XX_MACH_WRT400N, "WRT400N", "Linksys WRT400N", wrt400n_setup);
  7077. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c linux-2.6.33.3/arch/mips/ar71xx/mach-wzr-hp-g300nh.c
  7078. --- linux-2.6.33.3.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 1970-01-01 01:00:00.000000000 +0100
  7079. +++ linux-2.6.33.3/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 2010-05-16 13:17:31.855600117 +0200
  7080. @@ -0,0 +1,265 @@
  7081. +/*
  7082. + * Buffalo WZR-HP-G300NH board support
  7083. + *
  7084. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  7085. + *
  7086. + * This program is free software; you can redistribute it and/or modify it
  7087. + * under the terms of the GNU General Public License version 2 as published
  7088. + * by the Free Software Foundation.
  7089. + */
  7090. +
  7091. +#include <linux/platform_device.h>
  7092. +#include <linux/mtd/mtd.h>
  7093. +#include <linux/mtd/partitions.h>
  7094. +#include <linux/nxp_74hc153.h>
  7095. +#include <linux/rtl8366s.h>
  7096. +
  7097. +#include <asm/mips_machine.h>
  7098. +#include <asm/mach-ar71xx/ar71xx.h>
  7099. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  7100. +
  7101. +#include "machtype.h"
  7102. +#include "devices.h"
  7103. +#include "dev-ar913x-wmac.h"
  7104. +#include "dev-gpio-buttons.h"
  7105. +#include "dev-leds-gpio.h"
  7106. +#include "dev-usb.h"
  7107. +
  7108. +#define WZRHPG300NH_GPIO_LED_USB 0
  7109. +#define WZRHPG300NH_GPIO_LED_DIAG 1
  7110. +#define WZRHPG300NH_GPIO_LED_WIRELESS 6
  7111. +#define WZRHPG300NH_GPIO_LED_SECURITY 17
  7112. +#define WZRHPG300NH_GPIO_LED_ROUTER 18
  7113. +
  7114. +#define WZRHPG300NH_GPIO_RTL8366_SDA 19
  7115. +#define WZRHPG300NH_GPIO_RTL8366_SCK 20
  7116. +
  7117. +#define WZRHPG300NH_GPIO_74HC153_S0 9
  7118. +#define WZRHPG300NH_GPIO_74HC153_S1 11
  7119. +#define WZRHPG300NH_GPIO_74HC153_1Y 12
  7120. +#define WZRHPG300NH_GPIO_74HC153_2Y 14
  7121. +
  7122. +#define WZRHPG300NH_GPIO_EXP_BASE 32
  7123. +#define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
  7124. +#define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
  7125. +#define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
  7126. +#define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
  7127. +#define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
  7128. +#define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
  7129. +#define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
  7130. +
  7131. +#define WZRHPG300NH_BUTTONS_POLL_INTERVAL 20
  7132. +
  7133. +#define WZRHPG300NH_MAC_OFFSET 0x20c
  7134. +
  7135. +#ifdef CONFIG_MTD_PARTITIONS
  7136. +static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
  7137. + {
  7138. + .name = "u-boot",
  7139. + .offset = 0,
  7140. + .size = 0x0040000,
  7141. + .mask_flags = MTD_WRITEABLE,
  7142. + }, {
  7143. + .name = "u-boot-env",
  7144. + .offset = 0x0040000,
  7145. + .size = 0x0020000,
  7146. + .mask_flags = MTD_WRITEABLE,
  7147. + }, {
  7148. + .name = "kernel",
  7149. + .offset = 0x0060000,
  7150. + .size = 0x0100000,
  7151. + }, {
  7152. + .name = "rootfs",
  7153. + .offset = 0x0160000,
  7154. + .size = 0x1e60000,
  7155. + }, {
  7156. + .name = "user_property",
  7157. + .offset = 0x1fc0000,
  7158. + .size = 0x0020000,
  7159. + .mask_flags = MTD_WRITEABLE,
  7160. + }, {
  7161. + .name = "art",
  7162. + .offset = 0x1fe0000,
  7163. + .size = 0x0020000,
  7164. + .mask_flags = MTD_WRITEABLE,
  7165. + }, {
  7166. + .name = "firmware",
  7167. + .offset = 0x0060000,
  7168. + .size = 0x1f60000,
  7169. + }
  7170. +};
  7171. +#endif /* CONFIG_MTD_PARTITIONS */
  7172. +
  7173. +static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
  7174. + .width = 2,
  7175. +#ifdef CONFIG_MTD_PARTITIONS
  7176. + .parts = wzrhpg300nh_flash_partitions,
  7177. + .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
  7178. +#endif
  7179. +};
  7180. +
  7181. +#define WZRHPG300NH_FLASH_BASE 0x1e000000
  7182. +#define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
  7183. +
  7184. +static struct resource wzrhpg300nh_flash_resources[] = {
  7185. + [0] = {
  7186. + .start = WZRHPG300NH_FLASH_BASE,
  7187. + .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
  7188. + .flags = IORESOURCE_MEM,
  7189. + },
  7190. +};
  7191. +
  7192. +static struct platform_device wzrhpg300nh_flash_device = {
  7193. + .name = "ar91xx-flash",
  7194. + .id = -1,
  7195. + .resource = wzrhpg300nh_flash_resources,
  7196. + .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
  7197. + .dev = {
  7198. + .platform_data = &wzrhpg300nh_flash_data,
  7199. + }
  7200. +};
  7201. +
  7202. +static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
  7203. + {
  7204. + .name = "wzr-hp-g300nh:orange:security",
  7205. + .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
  7206. + .active_low = 1,
  7207. + }, {
  7208. + .name = "wzr-hp-g300nh:green:wireless",
  7209. + .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
  7210. + .active_low = 1,
  7211. + }, {
  7212. + .name = "wzr-hp-g300nh:green:router",
  7213. + .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
  7214. + .active_low = 1,
  7215. + }, {
  7216. + .name = "wzr-hp-g300nh:red:diag",
  7217. + .gpio = WZRHPG300NH_GPIO_LED_DIAG,
  7218. + .active_low = 1,
  7219. + }, {
  7220. + .name = "wzr-hp-g300nh:blue:usb",
  7221. + .gpio = WZRHPG300NH_GPIO_LED_USB,
  7222. + .active_low = 1,
  7223. + }
  7224. +};
  7225. +
  7226. +static struct gpio_button wzrhpg300nh_gpio_buttons[] __initdata = {
  7227. + {
  7228. + .desc = "reset",
  7229. + .type = EV_KEY,
  7230. + .code = KEY_RESTART,
  7231. + .threshold = 3,
  7232. + .gpio = WZRHPG300NH_GPIO_BTN_RESET,
  7233. + .active_low = 1,
  7234. + }, {
  7235. + .desc = "aoss",
  7236. + .type = EV_KEY,
  7237. + .code = KEY_WPS_BUTTON,
  7238. + .threshold = 3,
  7239. + .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
  7240. + .active_low = 1,
  7241. + }, {
  7242. + .desc = "usb",
  7243. + .type = EV_KEY,
  7244. + .code = BTN_2,
  7245. + .threshold = 3,
  7246. + .gpio = WZRHPG300NH_GPIO_BTN_USB,
  7247. + .active_low = 1,
  7248. + }, {
  7249. + .desc = "qos_on",
  7250. + .type = EV_KEY,
  7251. + .code = BTN_3,
  7252. + .threshold = 3,
  7253. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
  7254. + .active_low = 0,
  7255. + }, {
  7256. + .desc = "qos_off",
  7257. + .type = EV_KEY,
  7258. + .code = BTN_4,
  7259. + .threshold = 3,
  7260. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
  7261. + .active_low = 0,
  7262. + }, {
  7263. + .desc = "router_on",
  7264. + .type = EV_KEY,
  7265. + .code = BTN_5,
  7266. + .threshold = 3,
  7267. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
  7268. + .active_low = 0,
  7269. + }, {
  7270. + .desc = "router_auto",
  7271. + .type = EV_KEY,
  7272. + .code = BTN_6,
  7273. + .threshold = 3,
  7274. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
  7275. + .active_low = 0,
  7276. + }
  7277. +};
  7278. +
  7279. +static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
  7280. + .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
  7281. + .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
  7282. + .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
  7283. + .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
  7284. + .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
  7285. +};
  7286. +
  7287. +static struct platform_device wzrhpg300nh_74hc153_device = {
  7288. + .name = NXP_74HC153_DRIVER_NAME,
  7289. + .id = -1,
  7290. + .dev = {
  7291. + .platform_data = &wzrhpg300nh_74hc153_data,
  7292. + }
  7293. +};
  7294. +
  7295. +static struct rtl8366s_platform_data wzrhpg300nh_rtl8366s_data = {
  7296. + .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
  7297. + .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
  7298. +};
  7299. +
  7300. +static struct platform_device wzrhpg300nh_rtl8366s_device = {
  7301. + .name = RTL8366S_DRIVER_NAME,
  7302. + .id = -1,
  7303. + .dev = {
  7304. + .platform_data = &wzrhpg300nh_rtl8366s_data,
  7305. + }
  7306. +};
  7307. +
  7308. +static void __init wzrhpg300nh_setup(void)
  7309. +{
  7310. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  7311. +
  7312. + ar71xx_set_mac_base(eeprom + WZRHPG300NH_MAC_OFFSET);
  7313. +
  7314. + ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
  7315. + ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  7316. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  7317. + ar71xx_eth0_data.speed = SPEED_1000;
  7318. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7319. +
  7320. + ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
  7321. + ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  7322. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  7323. + ar71xx_eth1_data.phy_mask = 0x10;
  7324. +
  7325. + ar71xx_add_device_eth(0);
  7326. + ar71xx_add_device_eth(1);
  7327. +
  7328. + ar71xx_add_device_usb();
  7329. + ar913x_add_device_wmac(eeprom, NULL);
  7330. +
  7331. + platform_device_register(&wzrhpg300nh_74hc153_device);
  7332. + platform_device_register(&wzrhpg300nh_flash_device);
  7333. + platform_device_register(&wzrhpg300nh_rtl8366s_device);
  7334. +
  7335. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
  7336. + wzrhpg300nh_leds_gpio);
  7337. +
  7338. + ar71xx_add_device_gpio_buttons(-1, WZRHPG300NH_BUTTONS_POLL_INTERVAL,
  7339. + ARRAY_SIZE(wzrhpg300nh_gpio_buttons),
  7340. + wzrhpg300nh_gpio_buttons);
  7341. +
  7342. +}
  7343. +
  7344. +MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
  7345. + "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);
  7346. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/Makefile linux-2.6.33.3/arch/mips/ar71xx/Makefile
  7347. --- linux-2.6.33.3.orig/arch/mips/ar71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  7348. +++ linux-2.6.33.3/arch/mips/ar71xx/Makefile 2010-05-17 21:19:51.539114190 +0200
  7349. @@ -0,0 +1,54 @@
  7350. +#
  7351. +# Makefile for the Atheros AR71xx SoC specific parts of the kernel
  7352. +#
  7353. +# Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7354. +# Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7355. +#
  7356. +# This program is free software; you can redistribute it and/or modify it
  7357. +# under the terms of the GNU General Public License version 2 as published
  7358. +# by the Free Software Foundation.
  7359. +
  7360. +obj-y := prom.o irq.o setup.o devices.o gpio.o ar71xx.o
  7361. +
  7362. +obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  7363. +obj-$(CONFIG_PCI) += pci.o
  7364. +
  7365. +obj-$(CONFIG_AR71XX_DEV_AP91_ETH) += dev-ap91-eth.o
  7366. +obj-$(CONFIG_AR71XX_DEV_AP91_PCI) += dev-ap91-pci.o
  7367. +obj-$(CONFIG_AR71XX_DEV_AP94_PCI) += dev-ap94-pci.o
  7368. +obj-$(CONFIG_AR71XX_DEV_AR913X_WMAC) += dev-ar913x-wmac.o
  7369. +obj-$(CONFIG_AR71XX_DEV_DSA) += dev-dsa.o
  7370. +obj-$(CONFIG_AR71XX_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o
  7371. +obj-$(CONFIG_AR71XX_DEV_LEDS_GPIO) += dev-leds-gpio.o
  7372. +obj-$(CONFIG_AR71XX_DEV_M25P80) += dev-m25p80.o
  7373. +obj-$(CONFIG_AR71XX_DEV_PB42_PCI) += dev-pb42-pci.o
  7374. +obj-$(CONFIG_AR71XX_DEV_PB9X_PCI) += dev-pb9x-pci.o
  7375. +obj-$(CONFIG_AR71XX_DEV_USB) += dev-usb.o
  7376. +
  7377. +obj-$(CONFIG_AR71XX_NVRAM) += nvram.o
  7378. +
  7379. +obj-$(CONFIG_AR71XX_MACH_AP81) += mach-ap81.o
  7380. +obj-$(CONFIG_AR71XX_MACH_AP83) += mach-ap83.o
  7381. +obj-$(CONFIG_AR71XX_MACH_AW_NR580) += mach-aw-nr580.o
  7382. +obj-$(CONFIG_AR71XX_MACH_DIR_600_A1) += mach-dir-600-a1.o
  7383. +obj-$(CONFIG_AR71XX_MACH_DIR_615_C1) += mach-dir-615-c1.o
  7384. +obj-$(CONFIG_AR71XX_MACH_DIR_825_B1) += mach-dir-825-b1.o
  7385. +obj-$(CONFIG_AR71XX_MACH_MZK_W04NU) += mach-mzk-w04nu.o
  7386. +obj-$(CONFIG_AR71XX_MACH_MZK_W300NH) += mach-mzk-w300nh.o
  7387. +obj-$(CONFIG_AR71XX_MACH_NBG460N) += mach-nbg460n.o
  7388. +obj-$(CONFIG_AR71XX_MACH_PB42) += mach-pb42.o
  7389. +obj-$(CONFIG_AR71XX_MACH_PB44) += mach-pb44.o
  7390. +obj-$(CONFIG_AR71XX_MACH_PB92) += mach-pb92.o
  7391. +obj-$(CONFIG_AR71XX_MACH_RB4XX) += mach-rb4xx.o
  7392. +obj-$(CONFIG_AR71XX_MACH_RB750) += mach-rb750.o
  7393. +obj-$(CONFIG_AR71XX_MACH_TEW_632BRP) += mach-tew-632brp.o
  7394. +obj-$(CONFIG_AR71XX_MACH_TL_WR741ND) += mach-tl-wr741nd.o
  7395. +obj-$(CONFIG_AR71XX_MACH_TL_WR841N_V1) += mach-tl-wr841n.o
  7396. +obj-$(CONFIG_AR71XX_MACH_TL_WR941ND) += mach-tl-wr941nd.o
  7397. +obj-$(CONFIG_AR71XX_MACH_TL_WR1043ND) += mach-tl-wr1043nd.o
  7398. +obj-$(CONFIG_AR71XX_MACH_UBNT) += mach-ubnt.o
  7399. +obj-$(CONFIG_AR71XX_MACH_WNDR3700) += mach-wndr3700.o
  7400. +obj-$(CONFIG_AR71XX_MACH_WNR2000) += mach-wnr2000.o
  7401. +obj-$(CONFIG_AR71XX_MACH_WP543) += mach-wp543.o
  7402. +obj-$(CONFIG_AR71XX_MACH_WRT160NL) += mach-wrt160nl.o
  7403. +obj-$(CONFIG_AR71XX_MACH_WRT400N) += mach-wrt400n.o
  7404. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/nvram.c linux-2.6.33.3/arch/mips/ar71xx/nvram.c
  7405. --- linux-2.6.33.3.orig/arch/mips/ar71xx/nvram.c 1970-01-01 01:00:00.000000000 +0100
  7406. +++ linux-2.6.33.3/arch/mips/ar71xx/nvram.c 2010-01-05 20:38:52.061278082 +0100
  7407. @@ -0,0 +1,75 @@
  7408. +/*
  7409. + * Atheros AR71xx minimal nvram support
  7410. + *
  7411. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7412. + *
  7413. + * This program is free software; you can redistribute it and/or modify it
  7414. + * under the terms of the GNU General Public License version 2 as published
  7415. + * by the Free Software Foundation.
  7416. + */
  7417. +
  7418. +#include <linux/kernel.h>
  7419. +#include <linux/vmalloc.h>
  7420. +#include <linux/errno.h>
  7421. +#include <linux/init.h>
  7422. +#include <linux/string.h>
  7423. +
  7424. +#include "nvram.h"
  7425. +
  7426. +char *nvram_find_var(const char *name, const char *buf, unsigned buf_len)
  7427. +{
  7428. + unsigned len = strlen(name);
  7429. + char *cur, *last;
  7430. +
  7431. + if (buf_len == 0 || len == 0)
  7432. + return NULL;
  7433. +
  7434. + if (buf_len < len)
  7435. + return NULL;
  7436. +
  7437. + if (len == 1)
  7438. + return memchr(buf, (int) *name, buf_len);
  7439. +
  7440. + last = (char *) buf + buf_len - len;
  7441. + for (cur = (char *) buf; cur <= last; cur++)
  7442. + if (cur[0] == name[0] && memcmp(cur, name, len) == 0)
  7443. + return cur + len;
  7444. +
  7445. + return NULL;
  7446. +}
  7447. +
  7448. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  7449. + const char *name, char *mac)
  7450. +{
  7451. + char *buf;
  7452. + char *mac_str;
  7453. + int ret;
  7454. + int t;
  7455. +
  7456. + buf = vmalloc(nvram_len);
  7457. + if (!buf)
  7458. + return -ENOMEM;
  7459. +
  7460. + memcpy(buf, nvram, nvram_len);
  7461. + buf[nvram_len - 1] = '\0';
  7462. +
  7463. + mac_str = nvram_find_var(name, buf, nvram_len);
  7464. + if (!mac_str) {
  7465. + ret = -EINVAL;
  7466. + goto free;
  7467. + }
  7468. +
  7469. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  7470. + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  7471. +
  7472. + if (t != 6) {
  7473. + ret = -EINVAL;
  7474. + goto free;
  7475. + }
  7476. +
  7477. + ret = 0;
  7478. +
  7479. + free:
  7480. + vfree(buf);
  7481. + return ret;
  7482. +}
  7483. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/nvram.h linux-2.6.33.3/arch/mips/ar71xx/nvram.h
  7484. --- linux-2.6.33.3.orig/arch/mips/ar71xx/nvram.h 1970-01-01 01:00:00.000000000 +0100
  7485. +++ linux-2.6.33.3/arch/mips/ar71xx/nvram.h 2010-01-05 20:38:52.137278273 +0100
  7486. @@ -0,0 +1,19 @@
  7487. +/*
  7488. + * Atheros AR71xx minimal nvram support
  7489. + *
  7490. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7491. + *
  7492. + * This program is free software; you can redistribute it and/or modify it
  7493. + * under the terms of the GNU General Public License version 2 as published
  7494. + * by the Free Software Foundation.
  7495. + */
  7496. +
  7497. +#ifndef _AR71XX_NVRAM_H
  7498. +#define _AR71XX_NVRAM_H
  7499. +
  7500. +char *nvram_find_var(const char *name, const char *buf,
  7501. + unsigned buf_len) __init;
  7502. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  7503. + const char *name, char *mac) __init;
  7504. +
  7505. +#endif /* _AR71XX_NVRAM_H */
  7506. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/pci.c linux-2.6.33.3/arch/mips/ar71xx/pci.c
  7507. --- linux-2.6.33.3.orig/arch/mips/ar71xx/pci.c 1970-01-01 01:00:00.000000000 +0100
  7508. +++ linux-2.6.33.3/arch/mips/ar71xx/pci.c 2010-04-02 11:07:51.847025813 +0200
  7509. @@ -0,0 +1,93 @@
  7510. +/*
  7511. + * Atheros AR71xx PCI setup code
  7512. + *
  7513. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7514. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7515. + *
  7516. + * Parts of this file are based on Atheros' 2.6.15 BSP
  7517. + *
  7518. + * This program is free software; you can redistribute it and/or modify it
  7519. + * under the terms of the GNU General Public License version 2 as published
  7520. + * by the Free Software Foundation.
  7521. + */
  7522. +
  7523. +#include <linux/kernel.h>
  7524. +
  7525. +#include <asm/traps.h>
  7526. +
  7527. +#include <asm/mach-ar71xx/ar71xx.h>
  7528. +#include <asm/mach-ar71xx/pci.h>
  7529. +
  7530. +unsigned ar71xx_pci_nr_irqs __initdata;
  7531. +struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  7532. +
  7533. +int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  7534. +
  7535. +static int ar71xx_be_handler(struct pt_regs *regs, int is_fixup)
  7536. +{
  7537. + int err = 0;
  7538. +
  7539. + err = ar71xx_pci_be_handler(is_fixup);
  7540. +
  7541. + return (is_fixup && !err) ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
  7542. +}
  7543. +
  7544. +int pcibios_plat_dev_init(struct pci_dev *dev)
  7545. +{
  7546. + if (ar71xx_pci_plat_dev_init)
  7547. + return ar71xx_pci_plat_dev_init(dev);
  7548. +
  7549. + return 0;
  7550. +}
  7551. +
  7552. +int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  7553. +{
  7554. + int ret = 0;
  7555. +
  7556. + switch (ar71xx_soc) {
  7557. + case AR71XX_SOC_AR7130:
  7558. + case AR71XX_SOC_AR7141:
  7559. + case AR71XX_SOC_AR7161:
  7560. + ret = ar71xx_pcibios_map_irq(dev, slot, pin);
  7561. + break;
  7562. +
  7563. + case AR71XX_SOC_AR7240:
  7564. + case AR71XX_SOC_AR7241:
  7565. + case AR71XX_SOC_AR7242:
  7566. + ret = ar724x_pcibios_map_irq(dev, slot, pin);
  7567. + break;
  7568. +
  7569. + default:
  7570. + break;
  7571. + }
  7572. +
  7573. + return ret;
  7574. +}
  7575. +
  7576. +int __init ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map)
  7577. +{
  7578. + int ret = 0;
  7579. +
  7580. + switch (ar71xx_soc) {
  7581. + case AR71XX_SOC_AR7130:
  7582. + case AR71XX_SOC_AR7141:
  7583. + case AR71XX_SOC_AR7161:
  7584. + board_be_handler = ar71xx_be_handler;
  7585. + ret = ar71xx_pcibios_init();
  7586. + break;
  7587. +
  7588. + case AR71XX_SOC_AR7240:
  7589. + case AR71XX_SOC_AR7241:
  7590. + case AR71XX_SOC_AR7242:
  7591. + ret = ar724x_pcibios_init();
  7592. + break;
  7593. +
  7594. + default:
  7595. + return 0;
  7596. + }
  7597. +
  7598. + ar71xx_pci_nr_irqs = nr_irqs;
  7599. + ar71xx_pci_irq_map = map;
  7600. +
  7601. + return ret;
  7602. +}
  7603. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/prom.c linux-2.6.33.3/arch/mips/ar71xx/prom.c
  7604. --- linux-2.6.33.3.orig/arch/mips/ar71xx/prom.c 1970-01-01 01:00:00.000000000 +0100
  7605. +++ linux-2.6.33.3/arch/mips/ar71xx/prom.c 2010-05-20 17:47:32.151849828 +0200
  7606. @@ -0,0 +1,105 @@
  7607. +/*
  7608. + * Atheros AR71xx SoC specific prom routines
  7609. + *
  7610. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7611. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7612. + *
  7613. + * This program is free software; you can redistribute it and/or modify it
  7614. + * under the terms of the GNU General Public License version 2 as published
  7615. + * by the Free Software Foundation.
  7616. + */
  7617. +
  7618. +#include <linux/kernel.h>
  7619. +#include <linux/init.h>
  7620. +#include <linux/io.h>
  7621. +#include <linux/string.h>
  7622. +
  7623. +#include <asm/bootinfo.h>
  7624. +#include <asm/addrspace.h>
  7625. +
  7626. +#include <asm/mach-ar71xx/ar71xx.h>
  7627. +
  7628. +static inline int is_valid_ram_addr(void *addr)
  7629. +{
  7630. + if (((u32) addr > KSEG0) &&
  7631. + ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
  7632. + return 1;
  7633. +
  7634. + if (((u32) addr > KSEG1) &&
  7635. + ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
  7636. + return 1;
  7637. +
  7638. + return 0;
  7639. +}
  7640. +
  7641. +static void __init ar71xx_prom_append_cmdline(const char *name,
  7642. + const char *value)
  7643. +{
  7644. + char buf[COMMAND_LINE_SIZE];
  7645. +
  7646. + snprintf(buf, sizeof(buf), " %s=%s", name, value);
  7647. + strlcat(arcs_cmdline, buf, sizeof(arcs_cmdline));
  7648. +}
  7649. +
  7650. +static void __init ar71xx_prom_find_env(char **envp, const char *name)
  7651. +{
  7652. + int len = strlen(name);
  7653. + char **p;
  7654. +
  7655. + if (!is_valid_ram_addr(envp))
  7656. + return;
  7657. +
  7658. + for (p = envp; is_valid_ram_addr(*p); p++) {
  7659. + if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') {
  7660. + ar71xx_prom_append_cmdline(name, *p + len + 1);
  7661. + break;
  7662. + }
  7663. +
  7664. + /* RedBoot env comes in pointer pairs - key, value */
  7665. + if (strncmp(name, *p, len) == 0 && (*p)[len] == 0)
  7666. + if (is_valid_ram_addr(*(++p))) {
  7667. + ar71xx_prom_append_cmdline(name, *p);
  7668. + break;
  7669. + }
  7670. + }
  7671. +}
  7672. +
  7673. +static int inline ar71xx_use__image_cmdline(void) { return 0; }
  7674. +
  7675. +static __init void ar71xx_prom_init_cmdline(int argc, char **argv)
  7676. +{
  7677. + int i;
  7678. +
  7679. + if (ar71xx_use__image_cmdline())
  7680. + return;
  7681. +
  7682. + if (!is_valid_ram_addr(argv))
  7683. + return;
  7684. +
  7685. + for (i = 0; i < argc; i++)
  7686. + if (is_valid_ram_addr(argv[i])) {
  7687. + strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
  7688. + strlcat(arcs_cmdline, argv[i], sizeof(arcs_cmdline));
  7689. + }
  7690. +}
  7691. +
  7692. +void __init prom_init(void)
  7693. +{
  7694. + char **envp;
  7695. +
  7696. + printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
  7697. + "fw_arg2=%08x, fw_arg3=%08x\n",
  7698. + (unsigned int)fw_arg0, (unsigned int)fw_arg1,
  7699. + (unsigned int)fw_arg2, (unsigned int)fw_arg3);
  7700. +
  7701. +
  7702. + ar71xx_prom_init_cmdline(fw_arg0, (char **)fw_arg1);
  7703. +
  7704. + envp = (char **)fw_arg2;
  7705. + ar71xx_prom_find_env(envp, "board");
  7706. +}
  7707. +
  7708. +void __init prom_free_prom_memory(void)
  7709. +{
  7710. + /* We do not have to prom memory to free */
  7711. +}
  7712. diff -Nur linux-2.6.33.3.orig/arch/mips/ar71xx/setup.c linux-2.6.33.3/arch/mips/ar71xx/setup.c
  7713. --- linux-2.6.33.3.orig/arch/mips/ar71xx/setup.c 1970-01-01 01:00:00.000000000 +0100
  7714. +++ linux-2.6.33.3/arch/mips/ar71xx/setup.c 2010-04-02 11:07:51.650955594 +0200
  7715. @@ -0,0 +1,310 @@
  7716. +/*
  7717. + * Atheros AR71xx SoC specific setup
  7718. + *
  7719. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7720. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7721. + *
  7722. + * Parts of this file are based on Atheros' 2.6.15 BSP
  7723. + *
  7724. + * This program is free software; you can redistribute it and/or modify it
  7725. + * under the terms of the GNU General Public License version 2 as published
  7726. + * by the Free Software Foundation.
  7727. + */
  7728. +
  7729. +#include <linux/kernel.h>
  7730. +#include <linux/init.h>
  7731. +#include <linux/bootmem.h>
  7732. +
  7733. +#include <asm/bootinfo.h>
  7734. +#include <asm/time.h> /* for mips_hpt_frequency */
  7735. +#include <asm/reboot.h> /* for _machine_{restart,halt} */
  7736. +#include <asm/mips_machine.h>
  7737. +
  7738. +#include <asm/mach-ar71xx/ar71xx.h>
  7739. +
  7740. +#include "machtype.h"
  7741. +#include "devices.h"
  7742. +
  7743. +#define AR71XX_SYS_TYPE_LEN 64
  7744. +#define AR71XX_BASE_FREQ 40000000
  7745. +#define AR91XX_BASE_FREQ 5000000
  7746. +#define AR724X_BASE_FREQ 5000000
  7747. +
  7748. +u32 ar71xx_cpu_freq;
  7749. +EXPORT_SYMBOL_GPL(ar71xx_cpu_freq);
  7750. +
  7751. +u32 ar71xx_ahb_freq;
  7752. +EXPORT_SYMBOL_GPL(ar71xx_ahb_freq);
  7753. +
  7754. +u32 ar71xx_ddr_freq;
  7755. +EXPORT_SYMBOL_GPL(ar71xx_ddr_freq);
  7756. +
  7757. +enum ar71xx_soc_type ar71xx_soc;
  7758. +EXPORT_SYMBOL_GPL(ar71xx_soc);
  7759. +
  7760. +static char ar71xx_sys_type[AR71XX_SYS_TYPE_LEN];
  7761. +
  7762. +static void ar71xx_restart(char *command)
  7763. +{
  7764. + ar71xx_device_stop(RESET_MODULE_FULL_CHIP);
  7765. + for (;;)
  7766. + if (cpu_wait)
  7767. + cpu_wait();
  7768. +}
  7769. +
  7770. +static void ar71xx_halt(void)
  7771. +{
  7772. + while (1)
  7773. + cpu_wait();
  7774. +}
  7775. +
  7776. +static void __init ar71xx_detect_mem_size(void)
  7777. +{
  7778. + unsigned long size;
  7779. +
  7780. + for (size = AR71XX_MEM_SIZE_MIN; size < AR71XX_MEM_SIZE_MAX;
  7781. + size <<= 1 ) {
  7782. + if (!memcmp(ar71xx_detect_mem_size,
  7783. + ar71xx_detect_mem_size + size, 1024))
  7784. + break;
  7785. + }
  7786. +
  7787. + add_memory_region(0, size, BOOT_MEM_RAM);
  7788. +}
  7789. +
  7790. +static void __init ar71xx_detect_sys_type(void)
  7791. +{
  7792. + char *chip = "????";
  7793. + u32 id;
  7794. + u32 major;
  7795. + u32 minor;
  7796. + u32 rev = 0;
  7797. +
  7798. + id = ar71xx_reset_rr(AR71XX_RESET_REG_REV_ID);
  7799. + major = id & REV_ID_MAJOR_MASK;
  7800. +
  7801. + switch (major) {
  7802. + case REV_ID_MAJOR_AR71XX:
  7803. + minor = id & AR71XX_REV_ID_MINOR_MASK;
  7804. + rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  7805. + rev &= AR71XX_REV_ID_REVISION_MASK;
  7806. + switch (minor) {
  7807. + case AR71XX_REV_ID_MINOR_AR7130:
  7808. + ar71xx_soc = AR71XX_SOC_AR7130;
  7809. + chip = "7130";
  7810. + break;
  7811. +
  7812. + case AR71XX_REV_ID_MINOR_AR7141:
  7813. + ar71xx_soc = AR71XX_SOC_AR7141;
  7814. + chip = "7141";
  7815. + break;
  7816. +
  7817. + case AR71XX_REV_ID_MINOR_AR7161:
  7818. + ar71xx_soc = AR71XX_SOC_AR7161;
  7819. + chip = "7161";
  7820. + break;
  7821. + }
  7822. + break;
  7823. +
  7824. + case REV_ID_MAJOR_AR7240:
  7825. + ar71xx_soc = AR71XX_SOC_AR7240;
  7826. + chip = "7240";
  7827. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7828. + break;
  7829. +
  7830. + case REV_ID_MAJOR_AR7241:
  7831. + ar71xx_soc = AR71XX_SOC_AR7241;
  7832. + chip = "7241";
  7833. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7834. + break;
  7835. +
  7836. + case REV_ID_MAJOR_AR7242:
  7837. + ar71xx_soc = AR71XX_SOC_AR7242;
  7838. + chip = "7242";
  7839. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7840. + break;
  7841. +
  7842. + case REV_ID_MAJOR_AR913X:
  7843. + minor = id & AR91XX_REV_ID_MINOR_MASK;
  7844. + rev = id >> AR91XX_REV_ID_REVISION_SHIFT;
  7845. + rev &= AR91XX_REV_ID_REVISION_MASK;
  7846. + switch (minor) {
  7847. + case AR91XX_REV_ID_MINOR_AR9130:
  7848. + ar71xx_soc = AR71XX_SOC_AR9130;
  7849. + chip = "9130";
  7850. + break;
  7851. +
  7852. + case AR91XX_REV_ID_MINOR_AR9132:
  7853. + ar71xx_soc = AR71XX_SOC_AR9132;
  7854. + chip = "9132";
  7855. + break;
  7856. + }
  7857. + break;
  7858. +
  7859. + default:
  7860. + panic("ar71xx: unknown chip id:0x%08x\n", id);
  7861. + }
  7862. +
  7863. + sprintf(ar71xx_sys_type, "Atheros AR%s rev %u", chip, rev);
  7864. +}
  7865. +
  7866. +static void __init ar91xx_detect_sys_frequency(void)
  7867. +{
  7868. + u32 pll;
  7869. + u32 freq;
  7870. + u32 div;
  7871. +
  7872. + pll = ar71xx_pll_rr(AR91XX_PLL_REG_CPU_CONFIG);
  7873. +
  7874. + div = ((pll >> AR91XX_PLL_DIV_SHIFT) & AR91XX_PLL_DIV_MASK);
  7875. + freq = div * AR91XX_BASE_FREQ;
  7876. +
  7877. + ar71xx_cpu_freq = freq;
  7878. +
  7879. + div = ((pll >> AR91XX_DDR_DIV_SHIFT) & AR91XX_DDR_DIV_MASK) + 1;
  7880. + ar71xx_ddr_freq = freq / div;
  7881. +
  7882. + div = (((pll >> AR91XX_AHB_DIV_SHIFT) & AR91XX_AHB_DIV_MASK) + 1) * 2;
  7883. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7884. +}
  7885. +
  7886. +static void __init ar71xx_detect_sys_frequency(void)
  7887. +{
  7888. + u32 pll;
  7889. + u32 freq;
  7890. + u32 div;
  7891. +
  7892. + pll = ar71xx_pll_rr(AR71XX_PLL_REG_CPU_CONFIG);
  7893. +
  7894. + div = ((pll >> AR71XX_PLL_DIV_SHIFT) & AR71XX_PLL_DIV_MASK) + 1;
  7895. + freq = div * AR71XX_BASE_FREQ;
  7896. +
  7897. + div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1;
  7898. + ar71xx_cpu_freq = freq / div;
  7899. +
  7900. + div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1;
  7901. + ar71xx_ddr_freq = freq / div;
  7902. +
  7903. + div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  7904. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7905. +}
  7906. +
  7907. +static void __init ar724x_detect_sys_frequency(void)
  7908. +{
  7909. + u32 pll;
  7910. + u32 freq;
  7911. + u32 div;
  7912. +
  7913. + pll = ar71xx_pll_rr(AR724X_PLL_REG_CPU_CONFIG);
  7914. +
  7915. + div = ((pll >> AR724X_PLL_DIV_SHIFT) & AR724X_PLL_DIV_MASK);
  7916. + freq = div * AR724X_BASE_FREQ;
  7917. +
  7918. + div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK);
  7919. + freq *= div;
  7920. +
  7921. + ar71xx_cpu_freq = freq;
  7922. +
  7923. + div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  7924. + ar71xx_ddr_freq = freq / div;
  7925. +
  7926. + div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  7927. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7928. +}
  7929. +
  7930. +static void __init detect_sys_frequency(void)
  7931. +{
  7932. + switch (ar71xx_soc) {
  7933. + case AR71XX_SOC_AR7130:
  7934. + case AR71XX_SOC_AR7141:
  7935. + case AR71XX_SOC_AR7161:
  7936. + ar71xx_detect_sys_frequency();
  7937. + break;
  7938. +
  7939. + case AR71XX_SOC_AR7240:
  7940. + case AR71XX_SOC_AR7241:
  7941. + case AR71XX_SOC_AR7242:
  7942. + ar724x_detect_sys_frequency();
  7943. + break;
  7944. +
  7945. + case AR71XX_SOC_AR9130:
  7946. + case AR71XX_SOC_AR9132:
  7947. + ar91xx_detect_sys_frequency();
  7948. + break;
  7949. +
  7950. + default:
  7951. + BUG();
  7952. + }
  7953. +}
  7954. +
  7955. +const char *get_system_type(void)
  7956. +{
  7957. + return ar71xx_sys_type;
  7958. +}
  7959. +
  7960. +unsigned int __cpuinit get_c0_compare_irq(void)
  7961. +{
  7962. + return CP0_LEGACY_COMPARE_IRQ;
  7963. +}
  7964. +
  7965. +void __init plat_mem_setup(void)
  7966. +{
  7967. + set_io_port_base(KSEG1);
  7968. +
  7969. + ar71xx_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  7970. + AR71XX_DDR_CTRL_SIZE);
  7971. +
  7972. + ar71xx_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  7973. + AR71XX_PLL_SIZE);
  7974. +
  7975. + ar71xx_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  7976. + AR71XX_RESET_SIZE);
  7977. +
  7978. + ar71xx_gpio_base = ioremap_nocache(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
  7979. +
  7980. + ar71xx_usb_ctrl_base = ioremap_nocache(AR71XX_USB_CTRL_BASE,
  7981. + AR71XX_USB_CTRL_SIZE);
  7982. +
  7983. + ar71xx_detect_mem_size();
  7984. + ar71xx_detect_sys_type();
  7985. + detect_sys_frequency();
  7986. +
  7987. + printk(KERN_INFO
  7988. + "%s, CPU:%u.%03u MHz, AHB:%u.%03u MHz, DDR:%u.%03u MHz\n",
  7989. + ar71xx_sys_type,
  7990. + ar71xx_cpu_freq / 1000000, (ar71xx_cpu_freq / 1000) % 1000,
  7991. + ar71xx_ahb_freq / 1000000, (ar71xx_ahb_freq / 1000) % 1000,
  7992. + ar71xx_ddr_freq / 1000000, (ar71xx_ddr_freq / 1000) % 1000);
  7993. +
  7994. + _machine_restart = ar71xx_restart;
  7995. + _machine_halt = ar71xx_halt;
  7996. + pm_power_off = ar71xx_halt;
  7997. +}
  7998. +
  7999. +void __init plat_time_init(void)
  8000. +{
  8001. + mips_hpt_frequency = ar71xx_cpu_freq / 2;
  8002. +}
  8003. +
  8004. +__setup("board=", mips_machtype_setup);
  8005. +
  8006. +static int __init ar71xx_machine_setup(void)
  8007. +{
  8008. + ar71xx_gpio_init();
  8009. +
  8010. + ar71xx_add_device_uart();
  8011. + ar71xx_add_device_wdt();
  8012. +
  8013. + mips_machine_setup();
  8014. + return 0;
  8015. +}
  8016. +
  8017. +arch_initcall(ar71xx_machine_setup);
  8018. +
  8019. +static void __init ar71xx_generic_init(void)
  8020. +{
  8021. + /* Nothing to do */
  8022. +}
  8023. +
  8024. +MIPS_MACHINE(AR71XX_MACH_GENERIC, "Generic", "Generic AR71xx board",
  8025. + ar71xx_generic_init);
  8026. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/ar71xx.h
  8027. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h 1970-01-01 01:00:00.000000000 +0100
  8028. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/ar71xx.h 2010-04-02 11:07:50.806953666 +0200
  8029. @@ -0,0 +1,514 @@
  8030. +/*
  8031. + * Atheros AR71xx SoC specific definitions
  8032. + *
  8033. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8034. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8035. + *
  8036. + * Parts of this file are based on Atheros' 2.6.15 BSP
  8037. + *
  8038. + * This program is free software; you can redistribute it and/or modify it
  8039. + * under the terms of the GNU General Public License version 2 as published
  8040. + * by the Free Software Foundation.
  8041. + */
  8042. +
  8043. +#ifndef __ASM_MACH_AR71XX_H
  8044. +#define __ASM_MACH_AR71XX_H
  8045. +
  8046. +#include <linux/types.h>
  8047. +#include <linux/init.h>
  8048. +#include <linux/io.h>
  8049. +#include <linux/bitops.h>
  8050. +
  8051. +#ifndef __ASSEMBLER__
  8052. +
  8053. +#define AR71XX_PCI_MEM_BASE 0x10000000
  8054. +#define AR71XX_PCI_MEM_SIZE 0x08000000
  8055. +#define AR71XX_APB_BASE 0x18000000
  8056. +#define AR71XX_GE0_BASE 0x19000000
  8057. +#define AR71XX_GE0_SIZE 0x01000000
  8058. +#define AR71XX_GE1_BASE 0x1a000000
  8059. +#define AR71XX_GE1_SIZE 0x01000000
  8060. +#define AR71XX_EHCI_BASE 0x1b000000
  8061. +#define AR71XX_EHCI_SIZE 0x01000000
  8062. +#define AR71XX_OHCI_BASE 0x1c000000
  8063. +#define AR71XX_OHCI_SIZE 0x01000000
  8064. +#define AR7240_OHCI_BASE 0x1b000000
  8065. +#define AR7240_OHCI_SIZE 0x01000000
  8066. +#define AR71XX_SPI_BASE 0x1f000000
  8067. +#define AR71XX_SPI_SIZE 0x01000000
  8068. +
  8069. +#define AR71XX_DDR_CTRL_BASE (AR71XX_APB_BASE + 0x00000000)
  8070. +#define AR71XX_DDR_CTRL_SIZE 0x10000
  8071. +#define AR71XX_CPU_BASE (AR71XX_APB_BASE + 0x00010000)
  8072. +#define AR71XX_UART_BASE (AR71XX_APB_BASE + 0x00020000)
  8073. +#define AR71XX_UART_SIZE 0x10000
  8074. +#define AR71XX_USB_CTRL_BASE (AR71XX_APB_BASE + 0x00030000)
  8075. +#define AR71XX_USB_CTRL_SIZE 0x10000
  8076. +#define AR71XX_GPIO_BASE (AR71XX_APB_BASE + 0x00040000)
  8077. +#define AR71XX_GPIO_SIZE 0x10000
  8078. +#define AR71XX_PLL_BASE (AR71XX_APB_BASE + 0x00050000)
  8079. +#define AR71XX_PLL_SIZE 0x10000
  8080. +#define AR71XX_RESET_BASE (AR71XX_APB_BASE + 0x00060000)
  8081. +#define AR71XX_RESET_SIZE 0x10000
  8082. +#define AR71XX_MII_BASE (AR71XX_APB_BASE + 0x00070000)
  8083. +#define AR71XX_MII_SIZE 0x10000
  8084. +#define AR71XX_SLIC_BASE (AR71XX_APB_BASE + 0x00090000)
  8085. +#define AR71XX_SLIC_SIZE 0x10000
  8086. +#define AR71XX_DMA_BASE (AR71XX_APB_BASE + 0x000A0000)
  8087. +#define AR71XX_DMA_SIZE 0x10000
  8088. +#define AR71XX_STEREO_BASE (AR71XX_APB_BASE + 0x000B0000)
  8089. +#define AR71XX_STEREO_SIZE 0x10000
  8090. +
  8091. +#define AR724X_PCI_CRP_BASE (AR71XX_APB_BASE + 0x000C0000)
  8092. +#define AR724X_PCI_CRP_SIZE 0x100
  8093. +
  8094. +#define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000F0000)
  8095. +#define AR724X_PCI_CTRL_SIZE 0x100
  8096. +
  8097. +#define AR91XX_WMAC_BASE (AR71XX_APB_BASE + 0x000C0000)
  8098. +#define AR91XX_WMAC_SIZE 0x30000
  8099. +
  8100. +#define AR71XX_MEM_SIZE_MIN 0x0200000
  8101. +#define AR71XX_MEM_SIZE_MAX 0x10000000
  8102. +
  8103. +#define AR71XX_CPU_IRQ_BASE 0
  8104. +#define AR71XX_MISC_IRQ_BASE 8
  8105. +#define AR71XX_MISC_IRQ_COUNT 8
  8106. +#define AR71XX_GPIO_IRQ_BASE 16
  8107. +#define AR71XX_GPIO_IRQ_COUNT 32
  8108. +#define AR71XX_PCI_IRQ_BASE 48
  8109. +#define AR71XX_PCI_IRQ_COUNT 8
  8110. +
  8111. +#define AR71XX_CPU_IRQ_IP2 (AR71XX_CPU_IRQ_BASE + 2)
  8112. +#define AR71XX_CPU_IRQ_USB (AR71XX_CPU_IRQ_BASE + 3)
  8113. +#define AR71XX_CPU_IRQ_GE0 (AR71XX_CPU_IRQ_BASE + 4)
  8114. +#define AR71XX_CPU_IRQ_GE1 (AR71XX_CPU_IRQ_BASE + 5)
  8115. +#define AR71XX_CPU_IRQ_MISC (AR71XX_CPU_IRQ_BASE + 6)
  8116. +#define AR71XX_CPU_IRQ_TIMER (AR71XX_CPU_IRQ_BASE + 7)
  8117. +
  8118. +#define AR71XX_MISC_IRQ_TIMER (AR71XX_MISC_IRQ_BASE + 0)
  8119. +#define AR71XX_MISC_IRQ_ERROR (AR71XX_MISC_IRQ_BASE + 1)
  8120. +#define AR71XX_MISC_IRQ_GPIO (AR71XX_MISC_IRQ_BASE + 2)
  8121. +#define AR71XX_MISC_IRQ_UART (AR71XX_MISC_IRQ_BASE + 3)
  8122. +#define AR71XX_MISC_IRQ_WDOG (AR71XX_MISC_IRQ_BASE + 4)
  8123. +#define AR71XX_MISC_IRQ_PERFC (AR71XX_MISC_IRQ_BASE + 5)
  8124. +#define AR71XX_MISC_IRQ_OHCI (AR71XX_MISC_IRQ_BASE + 6)
  8125. +#define AR71XX_MISC_IRQ_DMA (AR71XX_MISC_IRQ_BASE + 7)
  8126. +
  8127. +#define AR71XX_GPIO_IRQ(_x) (AR71XX_GPIO_IRQ_BASE + (_x))
  8128. +
  8129. +#define AR71XX_PCI_IRQ_DEV0 (AR71XX_PCI_IRQ_BASE + 0)
  8130. +#define AR71XX_PCI_IRQ_DEV1 (AR71XX_PCI_IRQ_BASE + 1)
  8131. +#define AR71XX_PCI_IRQ_DEV2 (AR71XX_PCI_IRQ_BASE + 2)
  8132. +#define AR71XX_PCI_IRQ_CORE (AR71XX_PCI_IRQ_BASE + 4)
  8133. +
  8134. +extern u32 ar71xx_ahb_freq;
  8135. +extern u32 ar71xx_cpu_freq;
  8136. +extern u32 ar71xx_ddr_freq;
  8137. +
  8138. +enum ar71xx_soc_type {
  8139. + AR71XX_SOC_UNKNOWN,
  8140. + AR71XX_SOC_AR7130,
  8141. + AR71XX_SOC_AR7141,
  8142. + AR71XX_SOC_AR7161,
  8143. + AR71XX_SOC_AR7240,
  8144. + AR71XX_SOC_AR7241,
  8145. + AR71XX_SOC_AR7242,
  8146. + AR71XX_SOC_AR9130,
  8147. + AR71XX_SOC_AR9132
  8148. +};
  8149. +
  8150. +extern enum ar71xx_soc_type ar71xx_soc;
  8151. +
  8152. +/*
  8153. + * PLL block
  8154. + */
  8155. +#define AR71XX_PLL_REG_CPU_CONFIG 0x00
  8156. +#define AR71XX_PLL_REG_SEC_CONFIG 0x04
  8157. +#define AR71XX_PLL_REG_ETH0_INT_CLOCK 0x10
  8158. +#define AR71XX_PLL_REG_ETH1_INT_CLOCK 0x14
  8159. +
  8160. +#define AR71XX_PLL_DIV_SHIFT 3
  8161. +#define AR71XX_PLL_DIV_MASK 0x1f
  8162. +#define AR71XX_CPU_DIV_SHIFT 16
  8163. +#define AR71XX_CPU_DIV_MASK 0x3
  8164. +#define AR71XX_DDR_DIV_SHIFT 18
  8165. +#define AR71XX_DDR_DIV_MASK 0x3
  8166. +#define AR71XX_AHB_DIV_SHIFT 20
  8167. +#define AR71XX_AHB_DIV_MASK 0x7
  8168. +
  8169. +#define AR71XX_ETH0_PLL_SHIFT 17
  8170. +#define AR71XX_ETH1_PLL_SHIFT 19
  8171. +
  8172. +#define AR724X_PLL_REG_CPU_CONFIG 0x00
  8173. +#define AR724X_PLL_REG_PCIE_CONFIG 0x18
  8174. +
  8175. +#define AR724X_PLL_DIV_SHIFT 0
  8176. +#define AR724X_PLL_DIV_MASK 0x3ff
  8177. +#define AR724X_PLL_REF_DIV_SHIFT 10
  8178. +#define AR724X_PLL_REF_DIV_MASK 0xf
  8179. +#define AR724X_AHB_DIV_SHIFT 19
  8180. +#define AR724X_AHB_DIV_MASK 0x1
  8181. +#define AR724X_DDR_DIV_SHIFT 22
  8182. +#define AR724X_DDR_DIV_MASK 0x3
  8183. +
  8184. +#define AR91XX_PLL_REG_CPU_CONFIG 0x00
  8185. +#define AR91XX_PLL_REG_ETH_CONFIG 0x04
  8186. +#define AR91XX_PLL_REG_ETH0_INT_CLOCK 0x14
  8187. +#define AR91XX_PLL_REG_ETH1_INT_CLOCK 0x18
  8188. +
  8189. +#define AR91XX_PLL_DIV_SHIFT 0
  8190. +#define AR91XX_PLL_DIV_MASK 0x3ff
  8191. +#define AR91XX_DDR_DIV_SHIFT 22
  8192. +#define AR91XX_DDR_DIV_MASK 0x3
  8193. +#define AR91XX_AHB_DIV_SHIFT 19
  8194. +#define AR91XX_AHB_DIV_MASK 0x1
  8195. +
  8196. +#define AR91XX_ETH0_PLL_SHIFT 20
  8197. +#define AR91XX_ETH1_PLL_SHIFT 22
  8198. +
  8199. +extern void __iomem *ar71xx_pll_base;
  8200. +
  8201. +static inline void ar71xx_pll_wr(unsigned reg, u32 val)
  8202. +{
  8203. + __raw_writel(val, ar71xx_pll_base + reg);
  8204. +}
  8205. +
  8206. +static inline u32 ar71xx_pll_rr(unsigned reg)
  8207. +{
  8208. + return __raw_readl(ar71xx_pll_base + reg);
  8209. +}
  8210. +
  8211. +/*
  8212. + * USB_CONFIG block
  8213. + */
  8214. +#define USB_CTRL_REG_FLADJ 0x00
  8215. +#define USB_CTRL_REG_CONFIG 0x04
  8216. +
  8217. +extern void __iomem *ar71xx_usb_ctrl_base;
  8218. +
  8219. +static inline void ar71xx_usb_ctrl_wr(unsigned reg, u32 val)
  8220. +{
  8221. + __raw_writel(val, ar71xx_usb_ctrl_base + reg);
  8222. +}
  8223. +
  8224. +static inline u32 ar71xx_usb_ctrl_rr(unsigned reg)
  8225. +{
  8226. + return __raw_readl(ar71xx_usb_ctrl_base + reg);
  8227. +}
  8228. +
  8229. +/*
  8230. + * GPIO block
  8231. + */
  8232. +#define GPIO_REG_OE 0x00
  8233. +#define GPIO_REG_IN 0x04
  8234. +#define GPIO_REG_OUT 0x08
  8235. +#define GPIO_REG_SET 0x0c
  8236. +#define GPIO_REG_CLEAR 0x10
  8237. +#define GPIO_REG_INT_MODE 0x14
  8238. +#define GPIO_REG_INT_TYPE 0x18
  8239. +#define GPIO_REG_INT_POLARITY 0x1c
  8240. +#define GPIO_REG_INT_PENDING 0x20
  8241. +#define GPIO_REG_INT_ENABLE 0x24
  8242. +#define GPIO_REG_FUNC 0x28
  8243. +
  8244. +#define AR71XX_GPIO_FUNC_STEREO_EN BIT(17)
  8245. +#define AR71XX_GPIO_FUNC_SLIC_EN BIT(16)
  8246. +#define AR71XX_GPIO_FUNC_SPI_CS2_EN BIT(13)
  8247. +#define AR71XX_GPIO_FUNC_SPI_CS1_EN BIT(12)
  8248. +#define AR71XX_GPIO_FUNC_UART_EN BIT(8)
  8249. +#define AR71XX_GPIO_FUNC_USB_OC_EN BIT(4)
  8250. +#define AR71XX_GPIO_FUNC_USB_CLK_EN BIT(0)
  8251. +
  8252. +#define AR71XX_GPIO_COUNT 16
  8253. +
  8254. +#define AR724X_GPIO_FUNC_GE0_MII_CLK_EN BIT(19)
  8255. +#define AR724X_GPIO_FUNC_SPI_EN BIT(18)
  8256. +#define AR724X_GPIO_FUNC_SPI_CS_EN2 BIT(14)
  8257. +#define AR724X_GPIO_FUNC_SPI_CS_EN1 BIT(13)
  8258. +#define AR724X_GPIO_FUNC_CLK_OBS5_EN BIT(12)
  8259. +#define AR724X_GPIO_FUNC_CLK_OBS4_EN BIT(11)
  8260. +#define AR724X_GPIO_FUNC_CLK_OBS3_EN BIT(10)
  8261. +#define AR724X_GPIO_FUNC_CLK_OBS2_EN BIT(9)
  8262. +#define AR724X_GPIO_FUNC_CLK_OBS1_EN BIT(8)
  8263. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN BIT(7)
  8264. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN BIT(6)
  8265. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN BIT(5)
  8266. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN BIT(4)
  8267. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN BIT(3)
  8268. +#define AR724X_GPIO_FUNC_UART_RTS_CTS_EN BIT(2)
  8269. +#define AR724X_GPIO_FUNC_UART_EN BIT(1)
  8270. +#define AR724X_GPIO_FUNC_JTAG_DISABLE BIT(0)
  8271. +
  8272. +#define AR724X_GPIO_COUNT 18
  8273. +
  8274. +#define AR91XX_GPIO_FUNC_WMAC_LED_EN BIT(22)
  8275. +#define AR91XX_GPIO_FUNC_EXP_PORT_CS_EN BIT(21)
  8276. +#define AR91XX_GPIO_FUNC_I2S_REFCLKEN BIT(20)
  8277. +#define AR91XX_GPIO_FUNC_I2S_MCKEN BIT(19)
  8278. +#define AR91XX_GPIO_FUNC_I2S1_EN BIT(18)
  8279. +#define AR91XX_GPIO_FUNC_I2S0_EN BIT(17)
  8280. +#define AR91XX_GPIO_FUNC_SLIC_EN BIT(16)
  8281. +#define AR91XX_GPIO_FUNC_UART_RTSCTS_EN BIT(9)
  8282. +#define AR91XX_GPIO_FUNC_UART_EN BIT(8)
  8283. +#define AR91XX_GPIO_FUNC_USB_CLK_EN BIT(4)
  8284. +
  8285. +#define AR91XX_GPIO_COUNT 22
  8286. +
  8287. +extern void __iomem *ar71xx_gpio_base;
  8288. +
  8289. +static inline void ar71xx_gpio_wr(unsigned reg, u32 value)
  8290. +{
  8291. + __raw_writel(value, ar71xx_gpio_base + reg);
  8292. +}
  8293. +
  8294. +static inline u32 ar71xx_gpio_rr(unsigned reg)
  8295. +{
  8296. + return __raw_readl(ar71xx_gpio_base + reg);
  8297. +}
  8298. +
  8299. +void ar71xx_gpio_init(void) __init;
  8300. +void ar71xx_gpio_function_enable(u32 mask);
  8301. +void ar71xx_gpio_function_disable(u32 mask);
  8302. +void ar71xx_gpio_function_setup(u32 set, u32 clear);
  8303. +
  8304. +/*
  8305. + * DDR_CTRL block
  8306. + */
  8307. +#define AR71XX_DDR_REG_PCI_WIN0 0x7c
  8308. +#define AR71XX_DDR_REG_PCI_WIN1 0x80
  8309. +#define AR71XX_DDR_REG_PCI_WIN2 0x84
  8310. +#define AR71XX_DDR_REG_PCI_WIN3 0x88
  8311. +#define AR71XX_DDR_REG_PCI_WIN4 0x8c
  8312. +#define AR71XX_DDR_REG_PCI_WIN5 0x90
  8313. +#define AR71XX_DDR_REG_PCI_WIN6 0x94
  8314. +#define AR71XX_DDR_REG_PCI_WIN7 0x98
  8315. +#define AR71XX_DDR_REG_FLUSH_GE0 0x9c
  8316. +#define AR71XX_DDR_REG_FLUSH_GE1 0xa0
  8317. +#define AR71XX_DDR_REG_FLUSH_USB 0xa4
  8318. +#define AR71XX_DDR_REG_FLUSH_PCI 0xa8
  8319. +
  8320. +#define AR724X_DDR_REG_FLUSH_GE0 0x7c
  8321. +#define AR724X_DDR_REG_FLUSH_GE1 0x80
  8322. +#define AR724X_DDR_REG_FLUSH_USB 0x84
  8323. +#define AR724X_DDR_REG_FLUSH_PCIE 0x88
  8324. +
  8325. +#define AR91XX_DDR_REG_FLUSH_GE0 0x7c
  8326. +#define AR91XX_DDR_REG_FLUSH_GE1 0x80
  8327. +#define AR91XX_DDR_REG_FLUSH_USB 0x84
  8328. +#define AR91XX_DDR_REG_FLUSH_WMAC 0x88
  8329. +
  8330. +#define PCI_WIN0_OFFS 0x10000000
  8331. +#define PCI_WIN1_OFFS 0x11000000
  8332. +#define PCI_WIN2_OFFS 0x12000000
  8333. +#define PCI_WIN3_OFFS 0x13000000
  8334. +#define PCI_WIN4_OFFS 0x14000000
  8335. +#define PCI_WIN5_OFFS 0x15000000
  8336. +#define PCI_WIN6_OFFS 0x16000000
  8337. +#define PCI_WIN7_OFFS 0x07000000
  8338. +
  8339. +extern void __iomem *ar71xx_ddr_base;
  8340. +
  8341. +static inline void ar71xx_ddr_wr(unsigned reg, u32 val)
  8342. +{
  8343. + __raw_writel(val, ar71xx_ddr_base + reg);
  8344. +}
  8345. +
  8346. +static inline u32 ar71xx_ddr_rr(unsigned reg)
  8347. +{
  8348. + return __raw_readl(ar71xx_ddr_base + reg);
  8349. +}
  8350. +
  8351. +void ar71xx_ddr_flush(u32 reg);
  8352. +
  8353. +/*
  8354. + * PCI block
  8355. + */
  8356. +#define AR71XX_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + PCI_WIN7_OFFS + 0x10000)
  8357. +#define AR71XX_PCI_CFG_SIZE 0x100
  8358. +
  8359. +#define PCI_REG_CRP_AD_CBE 0x00
  8360. +#define PCI_REG_CRP_WRDATA 0x04
  8361. +#define PCI_REG_CRP_RDDATA 0x08
  8362. +#define PCI_REG_CFG_AD 0x0c
  8363. +#define PCI_REG_CFG_CBE 0x10
  8364. +#define PCI_REG_CFG_WRDATA 0x14
  8365. +#define PCI_REG_CFG_RDDATA 0x18
  8366. +#define PCI_REG_PCI_ERR 0x1c
  8367. +#define PCI_REG_PCI_ERR_ADDR 0x20
  8368. +#define PCI_REG_AHB_ERR 0x24
  8369. +#define PCI_REG_AHB_ERR_ADDR 0x28
  8370. +
  8371. +#define PCI_CRP_CMD_WRITE 0x00010000
  8372. +#define PCI_CRP_CMD_READ 0x00000000
  8373. +#define PCI_CFG_CMD_READ 0x0000000a
  8374. +#define PCI_CFG_CMD_WRITE 0x0000000b
  8375. +
  8376. +#define PCI_IDSEL_ADL_START 17
  8377. +
  8378. +#define AR724X_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + 0x4000000)
  8379. +#define AR724X_PCI_CFG_SIZE 0x1000
  8380. +
  8381. +#define AR724X_PCI_REG_APP 0x00
  8382. +#define AR724X_PCI_REG_RESET 0x18
  8383. +#define AR724X_PCI_REG_INT_STATUS 0x4c
  8384. +#define AR724X_PCI_REG_INT_MASK 0x50
  8385. +
  8386. +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
  8387. +#define AR724X_PCI_RESET_LINK_UP BIT(0)
  8388. +
  8389. +#define AR724X_PCI_INT_DEV0 BIT(14)
  8390. +
  8391. +/*
  8392. + * RESET block
  8393. + */
  8394. +#define AR71XX_RESET_REG_TIMER 0x00
  8395. +#define AR71XX_RESET_REG_TIMER_RELOAD 0x04
  8396. +#define AR71XX_RESET_REG_WDOG_CTRL 0x08
  8397. +#define AR71XX_RESET_REG_WDOG 0x0c
  8398. +#define AR71XX_RESET_REG_MISC_INT_STATUS 0x10
  8399. +#define AR71XX_RESET_REG_MISC_INT_ENABLE 0x14
  8400. +#define AR71XX_RESET_REG_PCI_INT_STATUS 0x18
  8401. +#define AR71XX_RESET_REG_PCI_INT_ENABLE 0x1c
  8402. +#define AR71XX_RESET_REG_GLOBAL_INT_STATUS 0x20
  8403. +#define AR71XX_RESET_REG_RESET_MODULE 0x24
  8404. +#define AR71XX_RESET_REG_PERFC_CTRL 0x2c
  8405. +#define AR71XX_RESET_REG_PERFC0 0x30
  8406. +#define AR71XX_RESET_REG_PERFC1 0x34
  8407. +#define AR71XX_RESET_REG_REV_ID 0x90
  8408. +
  8409. +#define AR91XX_RESET_REG_GLOBAL_INT_STATUS 0x18
  8410. +#define AR91XX_RESET_REG_RESET_MODULE 0x1c
  8411. +#define AR91XX_RESET_REG_PERF_CTRL 0x20
  8412. +#define AR91XX_RESET_REG_PERFC0 0x24
  8413. +#define AR91XX_RESET_REG_PERFC1 0x28
  8414. +
  8415. +#define AR724X_RESET_REG_RESET_MODULE 0x1c
  8416. +
  8417. +#define WDOG_CTRL_LAST_RESET BIT(31)
  8418. +#define WDOG_CTRL_ACTION_MASK 3
  8419. +#define WDOG_CTRL_ACTION_NONE 0 /* no action */
  8420. +#define WDOG_CTRL_ACTION_GPI 1 /* general purpose interrupt */
  8421. +#define WDOG_CTRL_ACTION_NMI 2 /* NMI */
  8422. +#define WDOG_CTRL_ACTION_FCR 3 /* full chip reset */
  8423. +
  8424. +#define MISC_INT_DMA BIT(7)
  8425. +#define MISC_INT_OHCI BIT(6)
  8426. +#define MISC_INT_PERFC BIT(5)
  8427. +#define MISC_INT_WDOG BIT(4)
  8428. +#define MISC_INT_UART BIT(3)
  8429. +#define MISC_INT_GPIO BIT(2)
  8430. +#define MISC_INT_ERROR BIT(1)
  8431. +#define MISC_INT_TIMER BIT(0)
  8432. +
  8433. +#define PCI_INT_CORE BIT(4)
  8434. +#define PCI_INT_DEV2 BIT(2)
  8435. +#define PCI_INT_DEV1 BIT(1)
  8436. +#define PCI_INT_DEV0 BIT(0)
  8437. +
  8438. +#define RESET_MODULE_EXTERNAL BIT(28)
  8439. +#define RESET_MODULE_FULL_CHIP BIT(24)
  8440. +#define RESET_MODULE_AMBA2WMAC BIT(22)
  8441. +#define RESET_MODULE_CPU_NMI BIT(21)
  8442. +#define RESET_MODULE_CPU_COLD BIT(20)
  8443. +#define RESET_MODULE_DMA BIT(19)
  8444. +#define RESET_MODULE_SLIC BIT(18)
  8445. +#define RESET_MODULE_STEREO BIT(17)
  8446. +#define RESET_MODULE_DDR BIT(16)
  8447. +#define RESET_MODULE_GE1_MAC BIT(13)
  8448. +#define RESET_MODULE_GE1_PHY BIT(12)
  8449. +#define RESET_MODULE_USBSUS_OVERRIDE BIT(10)
  8450. +#define RESET_MODULE_GE0_MAC BIT(9)
  8451. +#define RESET_MODULE_GE0_PHY BIT(8)
  8452. +#define RESET_MODULE_USB_OHCI_DLL BIT(6)
  8453. +#define RESET_MODULE_USB_HOST BIT(5)
  8454. +#define RESET_MODULE_USB_PHY BIT(4)
  8455. +#define RESET_MODULE_USB_OHCI_DLL_7240 BIT(3)
  8456. +#define RESET_MODULE_PCI_BUS BIT(1)
  8457. +#define RESET_MODULE_PCI_CORE BIT(0)
  8458. +
  8459. +#define AR724X_RESET_GE1_MDIO BIT(23)
  8460. +#define AR724X_RESET_GE0_MDIO BIT(22)
  8461. +#define AR724X_RESET_PCIE_PHY_SERIAL BIT(10)
  8462. +#define AR724X_RESET_PCIE_PHY BIT(7)
  8463. +#define AR724X_RESET_PCIE BIT(6)
  8464. +
  8465. +#define REV_ID_MAJOR_MASK 0xfff0
  8466. +#define REV_ID_MAJOR_AR71XX 0x00a0
  8467. +#define REV_ID_MAJOR_AR913X 0x00b0
  8468. +#define REV_ID_MAJOR_AR7240 0x00c0
  8469. +#define REV_ID_MAJOR_AR7241 0x0100
  8470. +#define REV_ID_MAJOR_AR7242 0x1100
  8471. +
  8472. +#define AR71XX_REV_ID_MINOR_MASK 0x3
  8473. +#define AR71XX_REV_ID_MINOR_AR7130 0x0
  8474. +#define AR71XX_REV_ID_MINOR_AR7141 0x1
  8475. +#define AR71XX_REV_ID_MINOR_AR7161 0x2
  8476. +#define AR71XX_REV_ID_REVISION_MASK 0x3
  8477. +#define AR71XX_REV_ID_REVISION_SHIFT 2
  8478. +
  8479. +#define AR91XX_REV_ID_MINOR_MASK 0x3
  8480. +#define AR91XX_REV_ID_MINOR_AR9130 0x0
  8481. +#define AR91XX_REV_ID_MINOR_AR9132 0x1
  8482. +#define AR91XX_REV_ID_REVISION_MASK 0x3
  8483. +#define AR91XX_REV_ID_REVISION_SHIFT 2
  8484. +
  8485. +#define AR724X_REV_ID_REVISION_MASK 0x3
  8486. +
  8487. +extern void __iomem *ar71xx_reset_base;
  8488. +
  8489. +static inline void ar71xx_reset_wr(unsigned reg, u32 val)
  8490. +{
  8491. + __raw_writel(val, ar71xx_reset_base + reg);
  8492. +}
  8493. +
  8494. +static inline u32 ar71xx_reset_rr(unsigned reg)
  8495. +{
  8496. + return __raw_readl(ar71xx_reset_base + reg);
  8497. +}
  8498. +
  8499. +void ar71xx_device_stop(u32 mask);
  8500. +void ar71xx_device_start(u32 mask);
  8501. +int ar71xx_device_stopped(u32 mask);
  8502. +
  8503. +/*
  8504. + * SPI block
  8505. + */
  8506. +#define SPI_REG_FS 0x00 /* Function Select */
  8507. +#define SPI_REG_CTRL 0x04 /* SPI Control */
  8508. +#define SPI_REG_IOC 0x08 /* SPI I/O Control */
  8509. +#define SPI_REG_RDS 0x0c /* Read Data Shift */
  8510. +
  8511. +#define SPI_FS_GPIO BIT(0) /* Enable GPIO mode */
  8512. +
  8513. +#define SPI_CTRL_RD BIT(6) /* Remap Disable */
  8514. +#define SPI_CTRL_DIV_MASK 0x3f
  8515. +
  8516. +#define SPI_IOC_DO BIT(0) /* Data Out pin */
  8517. +#define SPI_IOC_CLK BIT(8) /* CLK pin */
  8518. +#define SPI_IOC_CS(n) BIT(16 + (n))
  8519. +#define SPI_IOC_CS0 SPI_IOC_CS(0)
  8520. +#define SPI_IOC_CS1 SPI_IOC_CS(1)
  8521. +#define SPI_IOC_CS2 SPI_IOC_CS(2)
  8522. +#define SPI_IOC_CS_ALL (SPI_IOC_CS0 | SPI_IOC_CS1 | SPI_IOC_CS2)
  8523. +
  8524. +void ar71xx_flash_acquire(void);
  8525. +void ar71xx_flash_release(void);
  8526. +
  8527. +/*
  8528. + * MII_CTRL block
  8529. + */
  8530. +#define MII_REG_MII0_CTRL 0x00
  8531. +#define MII_REG_MII1_CTRL 0x04
  8532. +
  8533. +#define MII0_CTRL_IF_GMII 0
  8534. +#define MII0_CTRL_IF_MII 1
  8535. +#define MII0_CTRL_IF_RGMII 2
  8536. +#define MII0_CTRL_IF_RMII 3
  8537. +
  8538. +#define MII1_CTRL_IF_RGMII 0
  8539. +#define MII1_CTRL_IF_RMII 1
  8540. +
  8541. +#endif /* __ASSEMBLER__ */
  8542. +
  8543. +#endif /* __ASM_MACH_AR71XX_H */
  8544. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h
  8545. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 1970-01-01 01:00:00.000000000 +0100
  8546. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 2009-12-13 20:45:20.439922318 +0100
  8547. @@ -0,0 +1,26 @@
  8548. +/*
  8549. + * AR91xx parallel flash driver platform data definitions
  8550. + *
  8551. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8552. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8553. + *
  8554. + * This program is free software; you can redistribute it and/or modify it
  8555. + * under the terms of the GNU General Public License version 2 as published
  8556. + * by the Free Software Foundation.
  8557. + */
  8558. +
  8559. +#ifndef __AR91XX_FLASH_H
  8560. +#define __AR91XX_FLASH_H
  8561. +
  8562. +struct mtd_partition;
  8563. +
  8564. +struct ar91xx_flash_platform_data {
  8565. + unsigned int width;
  8566. + u8 is_shared:1;
  8567. +#ifdef CONFIG_MTD_PARTITIONS
  8568. + unsigned int nr_parts;
  8569. + struct mtd_partition *parts;
  8570. +#endif
  8571. +};
  8572. +
  8573. +#endif /* __AR91XX_FLASH_H */
  8574. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h
  8575. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 1970-01-01 01:00:00.000000000 +0100
  8576. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 2009-12-13 20:45:20.471921431 +0100
  8577. @@ -0,0 +1,56 @@
  8578. +/*
  8579. + * Atheros AR71xx specific CPU feature overrides
  8580. + *
  8581. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8582. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8583. + *
  8584. + * This file was derived from: include/asm-mips/cpu-features.h
  8585. + * Copyright (C) 2003, 2004 Ralf Baechle
  8586. + * Copyright (C) 2004 Maciej W. Rozycki
  8587. + *
  8588. + * This program is free software; you can redistribute it and/or modify it
  8589. + * under the terms of the GNU General Public License version 2 as published
  8590. + * by the Free Software Foundation.
  8591. + *
  8592. + */
  8593. +#ifndef __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  8594. +#define __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  8595. +
  8596. +#define cpu_has_tlb 1
  8597. +#define cpu_has_4kex 1
  8598. +#define cpu_has_3k_cache 0
  8599. +#define cpu_has_4k_cache 1
  8600. +#define cpu_has_tx39_cache 0
  8601. +#define cpu_has_sb1_cache 0
  8602. +#define cpu_has_fpu 0
  8603. +#define cpu_has_32fpr 0
  8604. +#define cpu_has_counter 1
  8605. +#define cpu_has_watch 1
  8606. +#define cpu_has_divec 1
  8607. +
  8608. +#define cpu_has_prefetch 1
  8609. +#define cpu_has_ejtag 1
  8610. +#define cpu_has_llsc 1
  8611. +
  8612. +#define cpu_has_mips16 1
  8613. +#define cpu_has_mdmx 0
  8614. +#define cpu_has_mips3d 0
  8615. +#define cpu_has_smartmips 0
  8616. +
  8617. +#define cpu_has_mips32r1 1
  8618. +#define cpu_has_mips32r2 1
  8619. +#define cpu_has_mips64r1 0
  8620. +#define cpu_has_mips64r2 0
  8621. +
  8622. +#define cpu_has_dsp 0
  8623. +#define cpu_has_mipsmt 0
  8624. +
  8625. +#define cpu_has_64bits 0
  8626. +#define cpu_has_64bit_zero_reg 0
  8627. +#define cpu_has_64bit_gp_regs 0
  8628. +#define cpu_has_64bit_addresses 0
  8629. +
  8630. +#define cpu_dcache_line_size() 32
  8631. +#define cpu_icache_line_size() 32
  8632. +
  8633. +#endif /* __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H */
  8634. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/gpio.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/gpio.h
  8635. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/gpio.h 1970-01-01 01:00:00.000000000 +0100
  8636. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/gpio.h 2009-12-13 20:45:20.471921431 +0100
  8637. @@ -0,0 +1,53 @@
  8638. +/*
  8639. + * Atheros AR71xx GPIO API definitions
  8640. + *
  8641. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8642. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8643. + *
  8644. + * This program is free software; you can redistribute it and/or modify it
  8645. + * under the terms of the GNU General Public License version 2 as published
  8646. + * by the Free Software Foundation.
  8647. + *
  8648. + */
  8649. +
  8650. +#ifndef __ASM_MACH_AR71XX_GPIO_H
  8651. +#define __ASM_MACH_AR71XX_GPIO_H
  8652. +
  8653. +#define ARCH_NR_GPIOS 64
  8654. +#include <asm-generic/gpio.h>
  8655. +
  8656. +#include <asm/mach-ar71xx/ar71xx.h>
  8657. +
  8658. +extern unsigned long ar71xx_gpio_count;
  8659. +extern void __ar71xx_gpio_set_value(unsigned gpio, int value);
  8660. +extern int __ar71xx_gpio_get_value(unsigned gpio);
  8661. +
  8662. +static inline int gpio_to_irq(unsigned gpio)
  8663. +{
  8664. + return AR71XX_GPIO_IRQ(gpio);
  8665. +}
  8666. +
  8667. +static inline int irq_to_gpio(unsigned irq)
  8668. +{
  8669. + return irq - AR71XX_GPIO_IRQ_BASE;
  8670. +}
  8671. +
  8672. +static inline int gpio_get_value(unsigned gpio)
  8673. +{
  8674. + if (gpio < ar71xx_gpio_count)
  8675. + return __ar71xx_gpio_get_value(gpio);
  8676. +
  8677. + return __gpio_get_value(gpio);
  8678. +}
  8679. +
  8680. +static inline void gpio_set_value(unsigned gpio, int value)
  8681. +{
  8682. + if (gpio < ar71xx_gpio_count)
  8683. + __ar71xx_gpio_set_value(gpio, value);
  8684. + else
  8685. + __gpio_set_value(gpio, value);
  8686. +}
  8687. +
  8688. +#define gpio_cansleep __gpio_cansleep
  8689. +
  8690. +#endif /* __ASM_MACH_AR71XX_GPIO_H */
  8691. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/irq.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/irq.h
  8692. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/irq.h 1970-01-01 01:00:00.000000000 +0100
  8693. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/irq.h 2009-12-13 20:45:20.447923983 +0100
  8694. @@ -0,0 +1,17 @@
  8695. +/*
  8696. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8697. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8698. + *
  8699. + * This program is free software; you can redistribute it and/or modify it
  8700. + * under the terms of the GNU General Public License version 2 as published
  8701. + * by the Free Software Foundation.
  8702. + */
  8703. +#ifndef __ASM_MACH_AR71XX_IRQ_H
  8704. +#define __ASM_MACH_AR71XX_IRQ_H
  8705. +
  8706. +#define MIPS_CPU_IRQ_BASE 0
  8707. +#define NR_IRQS 56
  8708. +
  8709. +#include_next <irq.h>
  8710. +
  8711. +#endif /* __ASM_MACH_AR71XX_IRQ_H */
  8712. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h
  8713. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 1970-01-01 01:00:00.000000000 +0100
  8714. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 2009-12-13 20:45:20.611920954 +0100
  8715. @@ -0,0 +1,32 @@
  8716. +/*
  8717. + * Atheros AR71xx specific kernel entry setup
  8718. + *
  8719. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  8720. + *
  8721. + * This program is free software; you can redistribute it and/or modify it
  8722. + * under the terms of the GNU General Public License version 2 as published
  8723. + * by the Free Software Foundation.
  8724. + *
  8725. + */
  8726. +#ifndef __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  8727. +#define __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  8728. +
  8729. + /*
  8730. + * Some bootloaders set the 'Kseg0 coherency algorithm' to
  8731. + * 'Cacheable, noncoherent, write-through, no write allocate'
  8732. + * and this cause performance issues. Let's go and change it to
  8733. + * 'Cacheable, noncoherent, write-back, write allocate'
  8734. + */
  8735. + .macro kernel_entry_setup
  8736. + mfc0 t0, CP0_CONFIG
  8737. + li t1, ~CONF_CM_CMASK
  8738. + and t0, t1
  8739. + ori t0, CONF_CM_CACHABLE_NONCOHERENT
  8740. + mtc0 t0, CP0_CONFIG
  8741. + nop
  8742. + .endm
  8743. +
  8744. + .macro smp_slave_setup
  8745. + .endm
  8746. +
  8747. +#endif /* __ASM_MACH_AR71XX_KERNEL_ENTRY_H */
  8748. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/mach-rb750.h
  8749. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 1970-01-01 01:00:00.000000000 +0100
  8750. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 2010-03-12 19:31:45.750044904 +0100
  8751. @@ -0,0 +1,66 @@
  8752. +/*
  8753. + * MikroTik RouterBOARD 750 definitions
  8754. + *
  8755. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  8756. + *
  8757. + * This program is free software; you can redistribute it and/or modify it
  8758. + * under the terms of the GNU General Public License version 2 as published
  8759. + * by the Free Software Foundation.
  8760. + */
  8761. +#ifndef _MACH_RB750_H
  8762. +#define _MACH_RB750_H
  8763. +
  8764. +#include <linux/bitops.h>
  8765. +
  8766. +#define RB750_GPIO_LVC573_LE 0 /* Latch enable on LVC573 */
  8767. +#define RB750_GPIO_NAND_IO0 1 /* NAND I/O 0 */
  8768. +#define RB750_GPIO_NAND_IO1 2 /* NAND I/O 1 */
  8769. +#define RB750_GPIO_NAND_IO2 3 /* NAND I/O 2 */
  8770. +#define RB750_GPIO_NAND_IO3 4 /* NAND I/O 3 */
  8771. +#define RB750_GPIO_NAND_IO4 5 /* NAND I/O 4 */
  8772. +#define RB750_GPIO_NAND_IO5 6 /* NAND I/O 5 */
  8773. +#define RB750_GPIO_NAND_IO6 7 /* NAND I/O 6 */
  8774. +#define RB750_GPIO_NAND_IO7 8 /* NAND I/O 7 */
  8775. +#define RB750_GPIO_NAND_NCE 11 /* NAND Chip Enable (active low) */
  8776. +#define RB750_GPIO_NAND_RDY 12 /* NAND Ready */
  8777. +#define RB750_GPIO_NAND_CLE 14 /* NAND Command Latch Enable */
  8778. +#define RB750_GPIO_NAND_ALE 15 /* NAND Address Latch Enable */
  8779. +#define RB750_GPIO_NAND_NRE 16 /* NAND Read Enable (active low) */
  8780. +#define RB750_GPIO_NAND_NWE 17 /* NAND Write Enable (active low) */
  8781. +
  8782. +#define RB750_GPIO_BTN_RESET 1
  8783. +#define RB750_GPIO_SPI_CS0 2
  8784. +#define RB750_GPIO_LED_ACT 12
  8785. +#define RB750_GPIO_LED_PORT1 13
  8786. +#define RB750_GPIO_LED_PORT2 14
  8787. +#define RB750_GPIO_LED_PORT3 15
  8788. +#define RB750_GPIO_LED_PORT4 16
  8789. +#define RB750_GPIO_LED_PORT5 17
  8790. +
  8791. +#define RB750_LED_ACT BIT(RB750_GPIO_LED_ACT)
  8792. +#define RB750_LED_PORT1 BIT(RB750_GPIO_LED_PORT1)
  8793. +#define RB750_LED_PORT2 BIT(RB750_GPIO_LED_PORT2)
  8794. +#define RB750_LED_PORT3 BIT(RB750_GPIO_LED_PORT3)
  8795. +#define RB750_LED_PORT4 BIT(RB750_GPIO_LED_PORT4)
  8796. +#define RB750_LED_PORT5 BIT(RB750_GPIO_LED_PORT5)
  8797. +
  8798. +#define RB750_LVC573_LE BIT(RB750_GPIO_LVC573_LE)
  8799. +
  8800. +#define RB750_LED_BITS (RB750_LED_PORT1 | RB750_LED_PORT2 | RB750_LED_PORT3 | \
  8801. + RB750_LED_PORT4 | RB750_LED_PORT5 | RB750_LED_ACT)
  8802. +
  8803. +struct rb750_led_data {
  8804. + char *name;
  8805. + char *default_trigger;
  8806. + u32 mask;
  8807. + int active_low;
  8808. +};
  8809. +
  8810. +struct rb750_led_platform_data {
  8811. + int num_leds;
  8812. + struct rb750_led_data *leds;
  8813. +};
  8814. +
  8815. +int rb750_latch_change(u32 mask_clr, u32 mask_set);
  8816. +
  8817. +#endif /* _MACH_RB750_H */
  8818. \ No newline at end of file
  8819. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/mangle-port.h
  8820. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h 1970-01-01 01:00:00.000000000 +0100
  8821. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/mangle-port.h 2009-12-13 20:45:20.615923464 +0100
  8822. @@ -0,0 +1,45 @@
  8823. +/*
  8824. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8825. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8826. + *
  8827. + * This file was derived from: inlude/asm-mips/mach-generic/mangle-port.h
  8828. + * Copyright (C) 2003, 2004 Ralf Baechle
  8829. + *
  8830. + * This program is free software; you can redistribute it and/or modify it
  8831. + * under the terms of the GNU General Public License version 2 as published
  8832. + * by the Free Software Foundation.
  8833. + */
  8834. +
  8835. +#ifndef __ASM_MACH_AR71XX_MANGLE_PORT_H
  8836. +#define __ASM_MACH_AR71XX_MANGLE_PORT_H
  8837. +
  8838. +#define __swizzle_addr_b(port) ((port) ^ 3)
  8839. +#define __swizzle_addr_w(port) ((port) ^ 2)
  8840. +#define __swizzle_addr_l(port) (port)
  8841. +#define __swizzle_addr_q(port) (port)
  8842. +
  8843. +#if defined(CONFIG_SWAP_IO_SPACE)
  8844. +
  8845. +# define ioswabb(a, x) (x)
  8846. +# define __mem_ioswabb(a, x) (x)
  8847. +# define ioswabw(a, x) le16_to_cpu(x)
  8848. +# define __mem_ioswabw(a, x) (x)
  8849. +# define ioswabl(a, x) le32_to_cpu(x)
  8850. +# define __mem_ioswabl(a, x) (x)
  8851. +# define ioswabq(a, x) le64_to_cpu(x)
  8852. +# define __mem_ioswabq(a, x) (x)
  8853. +
  8854. +#else
  8855. +
  8856. +# define ioswabb(a, x) (x)
  8857. +# define __mem_ioswabb(a, x) (x)
  8858. +# define ioswabw(a, x) (x)
  8859. +# define __mem_ioswabw(a, x) cpu_to_le16(x)
  8860. +# define ioswabl(a, x) (x)
  8861. +# define __mem_ioswabl(a, x) cpu_to_le32(x)
  8862. +# define ioswabq(a, x) (x)
  8863. +# define __mem_ioswabq(a, x) cpu_to_le64(x)
  8864. +
  8865. +#endif
  8866. +
  8867. +#endif /* __ASM_MACH_AR71XX_MANGLE_PORT_H */
  8868. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/pci.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/pci.h
  8869. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/pci.h 1970-01-01 01:00:00.000000000 +0100
  8870. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/pci.h 2009-12-13 20:45:20.471921431 +0100
  8871. @@ -0,0 +1,39 @@
  8872. +/*
  8873. + * Atheros AR71xx SoC specific PCI definitions
  8874. + *
  8875. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8876. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8877. + *
  8878. + * This program is free software; you can redistribute it and/or modify it
  8879. + * under the terms of the GNU General Public License version 2 as published
  8880. + * by the Free Software Foundation.
  8881. + */
  8882. +
  8883. +#ifndef __ASM_MACH_AR71XX_PCI_H
  8884. +#define __ASM_MACH_AR71XX_PCI_H
  8885. +
  8886. +struct pci_dev;
  8887. +
  8888. +struct ar71xx_pci_irq {
  8889. + int irq;
  8890. + u8 slot;
  8891. + u8 pin;
  8892. +};
  8893. +
  8894. +extern int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  8895. +extern unsigned ar71xx_pci_nr_irqs __initdata;
  8896. +extern struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  8897. +
  8898. +int ar71xx_pcibios_map_irq(const struct pci_dev *dev,
  8899. + uint8_t slot, uint8_t pin) __init;
  8900. +int ar71xx_pcibios_init(void) __init;
  8901. +
  8902. +int ar71xx_pci_be_handler(int is_fixup);
  8903. +
  8904. +int ar724x_pcibios_map_irq(const struct pci_dev *dev,
  8905. + uint8_t slot, uint8_t pin) __init;
  8906. +int ar724x_pcibios_init(void) __init;
  8907. +
  8908. +int ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map) __init;
  8909. +
  8910. +#endif /* __ASM_MACH_AR71XX_PCI_H */
  8911. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/platform.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/platform.h
  8912. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/platform.h 1970-01-01 01:00:00.000000000 +0100
  8913. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/platform.h 2009-12-13 20:45:20.611920954 +0100
  8914. @@ -0,0 +1,61 @@
  8915. +/*
  8916. + * Atheros AR71xx SoC specific platform data definitions
  8917. + *
  8918. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8919. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8920. + *
  8921. + * This program is free software; you can redistribute it and/or modify it
  8922. + * under the terms of the GNU General Public License version 2 as published
  8923. + * by the Free Software Foundation.
  8924. + */
  8925. +
  8926. +#ifndef __ASM_MACH_AR71XX_PLATFORM_H
  8927. +#define __ASM_MACH_AR71XX_PLATFORM_H
  8928. +
  8929. +#include <linux/if_ether.h>
  8930. +#include <linux/skbuff.h>
  8931. +#include <linux/phy.h>
  8932. +#include <linux/spi/spi.h>
  8933. +
  8934. +struct ag71xx_platform_data {
  8935. + phy_interface_t phy_if_mode;
  8936. + u32 phy_mask;
  8937. + int speed;
  8938. + int duplex;
  8939. + u32 reset_bit;
  8940. + u32 mii_if;
  8941. + u8 mac_addr[ETH_ALEN];
  8942. + struct device *mii_bus_dev;
  8943. +
  8944. + u8 has_gbit:1;
  8945. + u8 is_ar91xx:1;
  8946. + u8 is_ar724x:1;
  8947. + u8 has_ar8216:1;
  8948. +
  8949. + void (* ddr_flush)(void);
  8950. + void (* set_pll)(int speed);
  8951. +
  8952. + u32 fifo_cfg1;
  8953. + u32 fifo_cfg2;
  8954. + u32 fifo_cfg3;
  8955. +};
  8956. +
  8957. +struct ag71xx_mdio_platform_data {
  8958. + u32 phy_mask;
  8959. + int is_ar7240;
  8960. +};
  8961. +
  8962. +struct ar71xx_ehci_platform_data {
  8963. + u8 is_ar91xx;
  8964. +};
  8965. +
  8966. +struct ar71xx_spi_platform_data {
  8967. + unsigned bus_num;
  8968. + unsigned num_chipselect;
  8969. + u32 (*get_ioc_base)(u8 chip_select, int cs_high, int is_on);
  8970. +};
  8971. +
  8972. +#define AR71XX_SPI_CS_INACTIVE 0
  8973. +#define AR71XX_SPI_CS_ACTIVE 1
  8974. +
  8975. +#endif /* __ASM_MACH_AR71XX_PLATFORM_H */
  8976. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/war.h linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/war.h
  8977. --- linux-2.6.33.3.orig/arch/mips/include/asm/mach-ar71xx/war.h 1970-01-01 01:00:00.000000000 +0100
  8978. +++ linux-2.6.33.3/arch/mips/include/asm/mach-ar71xx/war.h 2009-12-13 20:45:20.443925666 +0100
  8979. @@ -0,0 +1,25 @@
  8980. +/*
  8981. + * This file is subject to the terms and conditions of the GNU General Public
  8982. + * License. See the file "COPYING" in the main directory of this archive
  8983. + * for more details.
  8984. + *
  8985. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  8986. + */
  8987. +#ifndef __ASM_MACH_AR71XX_WAR_H
  8988. +#define __ASM_MACH_AR71XX_WAR_H
  8989. +
  8990. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  8991. +#define R4600_V1_HIT_CACHEOP_WAR 0
  8992. +#define R4600_V2_HIT_CACHEOP_WAR 0
  8993. +#define R5432_CP0_INTERRUPT_WAR 0
  8994. +#define BCM1250_M3_WAR 0
  8995. +#define SIBYTE_1956_WAR 0
  8996. +#define MIPS4K_ICACHE_REFILL_WAR 0
  8997. +#define MIPS_CACHE_SYNC_WAR 0
  8998. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  8999. +#define RM9000_CDEX_SMP_WAR 0
  9000. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  9001. +#define R10000_LLSC_WAR 0
  9002. +#define MIPS34K_MISSED_ITLB_WAR 0
  9003. +
  9004. +#endif /* __ASM_MACH_AR71XX_WAR_H */
  9005. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/mips_machine.h linux-2.6.33.3/arch/mips/include/asm/mips_machine.h
  9006. --- linux-2.6.33.3.orig/arch/mips/include/asm/mips_machine.h 1970-01-01 01:00:00.000000000 +0100
  9007. +++ linux-2.6.33.3/arch/mips/include/asm/mips_machine.h 2010-05-17 19:36:16.051124934 +0200
  9008. @@ -0,0 +1,54 @@
  9009. +/*
  9010. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  9011. + *
  9012. + * This program is free software; you can redistribute it and/or modify it
  9013. + * under the terms of the GNU General Public License version 2 as published
  9014. + * by the Free Software Foundation.
  9015. + *
  9016. + */
  9017. +
  9018. +#ifndef __ASM_MIPS_MACHINE_H
  9019. +#define __ASM_MIPS_MACHINE_H
  9020. +
  9021. +#include <linux/init.h>
  9022. +#include <linux/list.h>
  9023. +
  9024. +#include <asm/bootinfo.h>
  9025. +
  9026. +struct mips_machine {
  9027. + unsigned long mach_type;
  9028. + char *mach_id;
  9029. + char *mach_name;
  9030. + void (*mach_setup)(void);
  9031. + struct list_head list;
  9032. +};
  9033. +
  9034. +void mips_machine_register(struct mips_machine *) __init;
  9035. +void mips_machine_setup(void) __init;
  9036. +int mips_machtype_setup(char *id) __init;
  9037. +void mips_machine_set_name(char *name) __init;
  9038. +
  9039. +extern char *mips_machine_name;
  9040. +
  9041. +#define MIPS_MACHINE(_type, _id, _name, _setup) \
  9042. +static const char machine_name_##_type[] __initconst \
  9043. + __aligned(1) = _name; \
  9044. +static const char machine_id_##_type[] __initconst \
  9045. + __aligned(1) = _id; \
  9046. +static struct mips_machine machine_##_type __initdata = \
  9047. +{ \
  9048. + .mach_type = _type, \
  9049. + .mach_id = (char *) machine_id_##_type, \
  9050. + .mach_name = (char *) machine_name_##_type, \
  9051. + .mach_setup = _setup, \
  9052. +}; \
  9053. + \
  9054. +static int __init register_machine_##_type(void) \
  9055. +{ \
  9056. + mips_machine_register(&machine_##_type); \
  9057. + return 0; \
  9058. +} \
  9059. + \
  9060. +pure_initcall(register_machine_##_type)
  9061. +
  9062. +#endif /* __ASM_MIPS_MACHINE_H */
  9063. diff -Nur linux-2.6.33.3.orig/arch/mips/include/asm/time.h linux-2.6.33.3/arch/mips/include/asm/time.h
  9064. --- linux-2.6.33.3.orig/arch/mips/include/asm/time.h 2010-04-26 16:48:30.000000000 +0200
  9065. +++ linux-2.6.33.3/arch/mips/include/asm/time.h 2010-05-18 19:33:35.811338021 +0200
  9066. @@ -52,6 +52,7 @@
  9067. */
  9068. #ifdef CONFIG_CEVT_R4K_LIB
  9069. extern unsigned int __weak get_c0_compare_int(void);
  9070. +extern unsigned int __weak get_c0_compare_irq(void);
  9071. extern int r4k_clockevent_init(void);
  9072. #endif
  9073. diff -Nur linux-2.6.33.3.orig/arch/mips/Kconfig linux-2.6.33.3/arch/mips/Kconfig
  9074. --- linux-2.6.33.3.orig/arch/mips/Kconfig 2010-04-26 16:48:30.000000000 +0200
  9075. +++ linux-2.6.33.3/arch/mips/Kconfig 2010-05-20 16:39:56.083849540 +0200
  9076. @@ -48,6 +48,23 @@
  9077. Support for the Texas Instruments AR7 System-on-a-Chip
  9078. family: TNETD7100, 7200 and 7300.
  9079. +config ATHEROS_AR71XX
  9080. + bool "Atheros AR71xx based boards"
  9081. + select CEVT_R4K
  9082. + select CSRC_R4K
  9083. + select DMA_NONCOHERENT
  9084. + select HW_HAS_PCI
  9085. + select IRQ_CPU
  9086. + select ARCH_REQUIRE_GPIOLIB
  9087. + select SYS_HAS_CPU_MIPS32_R1
  9088. + select SYS_HAS_CPU_MIPS32_R2
  9089. + select SYS_SUPPORTS_32BIT_KERNEL
  9090. + select SYS_SUPPORTS_BIG_ENDIAN
  9091. + select SYS_HAS_EARLY_PRINTK
  9092. + select MIPS_MACHINE
  9093. + help
  9094. + Support for Atheros AR71xx based boards.
  9095. +
  9096. config BCM47XX
  9097. bool "BCM47XX based boards"
  9098. select CEVT_R4K
  9099. @@ -682,6 +699,7 @@
  9100. endchoice
  9101. source "arch/mips/alchemy/Kconfig"
  9102. +source "arch/mips/ar71xx/Kconfig"
  9103. source "arch/mips/bcm63xx/Kconfig"
  9104. source "arch/mips/jazz/Kconfig"
  9105. source "arch/mips/lasat/Kconfig"
  9106. @@ -848,9 +866,15 @@
  9107. config MIPS_DISABLE_OBSOLETE_IDE
  9108. bool
  9109. +config MYLOADER
  9110. + bool
  9111. +
  9112. config SYNC_R4K
  9113. bool
  9114. +config MIPS_MACHINE
  9115. + def_bool n
  9116. +
  9117. config NO_IOPORT
  9118. def_bool n
  9119. diff -Nur linux-2.6.33.3.orig/arch/mips/kernel/Makefile linux-2.6.33.3/arch/mips/kernel/Makefile
  9120. --- linux-2.6.33.3.orig/arch/mips/kernel/Makefile 2010-04-26 16:48:30.000000000 +0200
  9121. +++ linux-2.6.33.3/arch/mips/kernel/Makefile 2010-05-17 18:51:38.331117283 +0200
  9122. @@ -93,6 +93,7 @@
  9123. obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
  9124. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  9125. +obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o
  9126. CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
  9127. diff -Nur linux-2.6.33.3.orig/arch/mips/kernel/mips_machine.c linux-2.6.33.3/arch/mips/kernel/mips_machine.c
  9128. --- linux-2.6.33.3.orig/arch/mips/kernel/mips_machine.c 1970-01-01 01:00:00.000000000 +0100
  9129. +++ linux-2.6.33.3/arch/mips/kernel/mips_machine.c 2010-05-17 19:36:16.035122334 +0200
  9130. @@ -0,0 +1,120 @@
  9131. +/*
  9132. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  9133. + *
  9134. + * This program is free software; you can redistribute it and/or modify it
  9135. + * under the terms of the GNU General Public License version 2 as published
  9136. + * by the Free Software Foundation.
  9137. + *
  9138. + */
  9139. +#include <linux/mm.h>
  9140. +#include <linux/string.h>
  9141. +
  9142. +#include <asm/mips_machine.h>
  9143. +
  9144. +static struct list_head mips_machines __initdata =
  9145. + LIST_HEAD_INIT(mips_machines);
  9146. +static char *mips_machid __initdata;
  9147. +
  9148. +char *mips_machine_name = "Unknown";
  9149. +
  9150. +static struct mips_machine * __init mips_machine_find(unsigned long machtype)
  9151. +{
  9152. + struct list_head *this;
  9153. +
  9154. + list_for_each(this, &mips_machines) {
  9155. + struct mips_machine *mach;
  9156. +
  9157. + mach = list_entry(this, struct mips_machine, list);
  9158. + if (mach->mach_type == machtype)
  9159. + return mach;
  9160. + }
  9161. +
  9162. + return NULL;
  9163. +}
  9164. +
  9165. +void __init mips_machine_register(struct mips_machine *mach)
  9166. +{
  9167. + list_add_tail(&mach->list, &mips_machines);
  9168. +}
  9169. +
  9170. +void __init mips_machine_set_name(char *name)
  9171. +{
  9172. + unsigned int len;
  9173. + char *p;
  9174. +
  9175. + if (name == NULL)
  9176. + return;
  9177. +
  9178. + len = strlen(name);
  9179. + p = kmalloc(len + 1, GFP_KERNEL);
  9180. + if (p) {
  9181. + strncpy(p, name, len);
  9182. + p[len] = '\0';
  9183. + mips_machine_name = p;
  9184. + } else {
  9185. + printk(KERN_WARNING "MIPS: no memory for machine_name\n");
  9186. + }
  9187. +}
  9188. +
  9189. +void __init mips_machine_setup(void)
  9190. +{
  9191. + struct mips_machine *mach;
  9192. +
  9193. + mach = mips_machine_find(mips_machtype);
  9194. + if (!mach) {
  9195. + printk(KERN_WARNING "MIPS: no machine registered for "
  9196. + "machtype %lu\n", mips_machtype);
  9197. + return;
  9198. + }
  9199. +
  9200. + mips_machine_set_name(mach->mach_name);
  9201. + printk(KERN_NOTICE "MIPS: machine is %s\n", mips_machine_name);
  9202. +
  9203. + if (mach->mach_setup)
  9204. + mach->mach_setup();
  9205. +}
  9206. +
  9207. +int __init mips_machtype_setup(char *id)
  9208. +{
  9209. + if (mips_machid == NULL)
  9210. + mips_machid = id;
  9211. +
  9212. + return 1;
  9213. +}
  9214. +
  9215. +__setup("machtype=", mips_machtype_setup);
  9216. +
  9217. +static int __init mips_machtype_init(void)
  9218. +{
  9219. + struct list_head *this;
  9220. + struct mips_machine *mach;
  9221. +
  9222. + if (mips_machid == NULL)
  9223. + return 0;
  9224. +
  9225. + list_for_each(this, &mips_machines) {
  9226. + mach = list_entry(this, struct mips_machine, list);
  9227. + if (mach->mach_id == NULL)
  9228. + continue;
  9229. +
  9230. + if (strcmp(mach->mach_id, mips_machid) == 0) {
  9231. + mips_machtype = mach->mach_type;
  9232. + return 0;
  9233. + }
  9234. + }
  9235. +
  9236. + printk(KERN_WARNING
  9237. + "MIPS: no machine found for id: '%s', registered machines:\n",
  9238. + mips_machid);
  9239. + printk(KERN_WARNING "%32s %s\n", "id", "name");
  9240. +
  9241. + list_for_each(this, &mips_machines) {
  9242. + mach = list_entry(this, struct mips_machine, list);
  9243. + printk(KERN_WARNING "%32s %s\n",
  9244. + mach->mach_id ? mach->mach_id : "", mach->mach_name);
  9245. + }
  9246. +
  9247. + return 0;
  9248. +}
  9249. +
  9250. +core_initcall(mips_machtype_init);
  9251. diff -Nur linux-2.6.33.3.orig/arch/mips/kernel/proc.c linux-2.6.33.3/arch/mips/kernel/proc.c
  9252. --- linux-2.6.33.3.orig/arch/mips/kernel/proc.c 2010-04-26 16:48:30.000000000 +0200
  9253. +++ linux-2.6.33.3/arch/mips/kernel/proc.c 2010-05-17 18:51:38.335115558 +0200
  9254. @@ -12,6 +12,7 @@
  9255. #include <asm/cpu-features.h>
  9256. #include <asm/mipsregs.h>
  9257. #include <asm/processor.h>
  9258. +#include <asm/mips_machine.h>
  9259. unsigned int vced_count, vcei_count;
  9260. @@ -31,8 +32,12 @@
  9261. /*
  9262. * For the first processor also print the system type
  9263. */
  9264. - if (n == 0)
  9265. + if (n == 0) {
  9266. seq_printf(m, "system type\t\t: %s\n", get_system_type());
  9267. +#ifdef CONFIG_MIPS_MACHINE
  9268. + seq_printf(m, "machine\t\t\t: %s\n", mips_machine_name);
  9269. +#endif
  9270. + }
  9271. seq_printf(m, "processor\t\t: %ld\n", n);
  9272. sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n",
  9273. diff -Nur linux-2.6.33.3.orig/arch/mips/kernel/traps.c linux-2.6.33.3/arch/mips/kernel/traps.c
  9274. --- linux-2.6.33.3.orig/arch/mips/kernel/traps.c 2010-04-26 16:48:30.000000000 +0200
  9275. +++ linux-2.6.33.3/arch/mips/kernel/traps.c 2010-05-18 19:33:35.691116007 +0200
  9276. @@ -50,6 +50,7 @@
  9277. #include <asm/types.h>
  9278. #include <asm/stacktrace.h>
  9279. #include <asm/irq.h>
  9280. +#include <asm/time.h>
  9281. extern void check_wait(void);
  9282. extern asmlinkage void r4k_wait(void);
  9283. @@ -1496,6 +1497,8 @@
  9284. if (cpu_has_mips_r2) {
  9285. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  9286. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  9287. + if (get_c0_compare_irq)
  9288. + cp0_compare_irq = get_c0_compare_irq();
  9289. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  9290. if (cp0_perfcount_irq == cp0_compare_irq)
  9291. cp0_perfcount_irq = -1;
  9292. diff -Nur linux-2.6.33.3.orig/arch/mips/Makefile linux-2.6.33.3/arch/mips/Makefile
  9293. --- linux-2.6.33.3.orig/arch/mips/Makefile 2010-04-26 16:48:30.000000000 +0200
  9294. +++ linux-2.6.33.3/arch/mips/Makefile 2010-05-20 17:40:10.159860905 +0200
  9295. @@ -166,6 +166,13 @@
  9296. cflags-$(CONFIG_CPU_CAVIUM_OCTEON) += -Wa,-march=octeon
  9297. endif
  9298. +#
  9299. +# Atheros AR71xx
  9300. +#
  9301. +core-$(CONFIG_ATHEROS_AR71XX) += arch/mips/ar71xx/
  9302. +cflags-$(CONFIG_ATHEROS_AR71XX) += -I$(srctree)/arch/mips/include/asm/mach-ar71xx
  9303. +load-$(CONFIG_ATHEROS_AR71XX) += 0xffffffff80060000
  9304. +
  9305. cflags-$(CONFIG_CPU_R4000_WORKAROUNDS) += $(call cc-option,-mfix-r4000,)
  9306. cflags-$(CONFIG_CPU_R4400_WORKAROUNDS) += $(call cc-option,-mfix-r4400,)
  9307. cflags-$(CONFIG_CPU_DADDI_WORKAROUNDS) += $(call cc-option,-mno-daddi,)
  9308. diff -Nur linux-2.6.33.3.orig/arch/mips/pci/Makefile linux-2.6.33.3/arch/mips/pci/Makefile
  9309. --- linux-2.6.33.3.orig/arch/mips/pci/Makefile 2010-04-26 16:48:30.000000000 +0200
  9310. +++ linux-2.6.33.3/arch/mips/pci/Makefile 2010-05-17 16:28:23.988293766 +0200
  9311. @@ -18,6 +18,7 @@
  9312. obj-$(CONFIG_BCM47XX) += pci-bcm47xx.o
  9313. obj-$(CONFIG_BCM63XX) += pci-bcm63xx.o fixup-bcm63xx.o \
  9314. ops-bcm63xx.o
  9315. +obj-$(CONFIG_ATHEROS_AR71XX) += pci-ar71xx.o pci-ar724x.o
  9316. #
  9317. # These are still pretty much in the old state, watch, go blind.
  9318. diff -Nur linux-2.6.33.3.orig/arch/mips/pci/pci-ar71xx.c linux-2.6.33.3/arch/mips/pci/pci-ar71xx.c
  9319. --- linux-2.6.33.3.orig/arch/mips/pci/pci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  9320. +++ linux-2.6.33.3/arch/mips/pci/pci-ar71xx.c 2010-03-23 20:31:05.824706267 +0100
  9321. @@ -0,0 +1,409 @@
  9322. +/*
  9323. + * Atheros AR71xx PCI host controller driver
  9324. + *
  9325. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  9326. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  9327. + *
  9328. + * Parts of this file are based on Atheros' 2.6.15 BSP
  9329. + *
  9330. + * This program is free software; you can redistribute it and/or modify it
  9331. + * under the terms of the GNU General Public License version 2 as published
  9332. + * by the Free Software Foundation.
  9333. + */
  9334. +
  9335. +#include <linux/resource.h>
  9336. +#include <linux/types.h>
  9337. +#include <linux/delay.h>
  9338. +#include <linux/bitops.h>
  9339. +#include <linux/pci.h>
  9340. +#include <linux/pci_regs.h>
  9341. +#include <linux/interrupt.h>
  9342. +
  9343. +#include <asm/mach-ar71xx/ar71xx.h>
  9344. +#include <asm/mach-ar71xx/pci.h>
  9345. +
  9346. +#undef DEBUG
  9347. +#ifdef DEBUG
  9348. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  9349. +#else
  9350. +#define DBG(fmt, args...)
  9351. +#endif
  9352. +
  9353. +#define AR71XX_PCI_DELAY 100 /* msecs */
  9354. +
  9355. +#if 0
  9356. +#define PCI_IDSEL_BASE PCI_IDSEL_ADL_START
  9357. +#else
  9358. +#define PCI_IDSEL_BASE 0
  9359. +#endif
  9360. +
  9361. +static void __iomem *ar71xx_pcicfg_base;
  9362. +static DEFINE_SPINLOCK(ar71xx_pci_lock);
  9363. +static int ar71xx_pci_fixup_enable;
  9364. +
  9365. +static inline void ar71xx_pci_delay(void)
  9366. +{
  9367. + mdelay(AR71XX_PCI_DELAY);
  9368. +}
  9369. +
  9370. +/* Byte lane enable bits */
  9371. +static u8 ble_table[4][4] = {
  9372. + {0x0, 0xf, 0xf, 0xf},
  9373. + {0xe, 0xd, 0xb, 0x7},
  9374. + {0xc, 0xf, 0x3, 0xf},
  9375. + {0xf, 0xf, 0xf, 0xf},
  9376. +};
  9377. +
  9378. +static inline u32 ar71xx_pci_get_ble(int where, int size, int local)
  9379. +{
  9380. + u32 t;
  9381. +
  9382. + t = ble_table[size & 3][where & 3];
  9383. + BUG_ON(t == 0xf);
  9384. + t <<= (local) ? 20 : 4;
  9385. + return t;
  9386. +}
  9387. +
  9388. +static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
  9389. + int where)
  9390. +{
  9391. + u32 ret;
  9392. +
  9393. + if (!bus->number) {
  9394. + /* type 0 */
  9395. + ret = (1 << (PCI_IDSEL_BASE + PCI_SLOT(devfn)))
  9396. + | (PCI_FUNC(devfn) << 8) | (where & ~3);
  9397. + } else {
  9398. + /* type 1 */
  9399. + ret = (bus->number << 16) | (PCI_SLOT(devfn) << 11)
  9400. + | (PCI_FUNC(devfn) << 8) | (where & ~3) | 1;
  9401. + }
  9402. +
  9403. + return ret;
  9404. +}
  9405. +
  9406. +int ar71xx_pci_be_handler(int is_fixup)
  9407. +{
  9408. + void __iomem *base = ar71xx_pcicfg_base;
  9409. + u32 pci_err;
  9410. + u32 ahb_err;
  9411. +
  9412. + pci_err = __raw_readl(base + PCI_REG_PCI_ERR) & 3;
  9413. + if (pci_err) {
  9414. + if (!is_fixup)
  9415. + printk(KERN_ALERT "PCI error %d at PCI addr 0x%x\n",
  9416. + pci_err,
  9417. + __raw_readl(base + PCI_REG_PCI_ERR_ADDR));
  9418. +
  9419. + __raw_writel(pci_err, base + PCI_REG_PCI_ERR);
  9420. + }
  9421. +
  9422. + ahb_err = __raw_readl(base + PCI_REG_AHB_ERR) & 1;
  9423. + if (ahb_err) {
  9424. + if (!is_fixup)
  9425. + printk(KERN_ALERT "AHB error at AHB address 0x%x\n",
  9426. + __raw_readl(base + PCI_REG_AHB_ERR_ADDR));
  9427. +
  9428. + __raw_writel(ahb_err, base + PCI_REG_AHB_ERR);
  9429. + }
  9430. +
  9431. + return ((ahb_err | pci_err) ? 1 : 0);
  9432. +}
  9433. +
  9434. +static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
  9435. + unsigned int devfn, int where, int size, u32 cmd)
  9436. +{
  9437. + void __iomem *base = ar71xx_pcicfg_base;
  9438. + u32 addr;
  9439. +
  9440. + addr = ar71xx_pci_bus_addr(bus, devfn, where);
  9441. +
  9442. + DBG("PCI: set cfgaddr: %02x:%02x.%01x/%02x:%01d, addr=%08x\n",
  9443. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9444. + where, size, addr);
  9445. +
  9446. + __raw_writel(addr, base + PCI_REG_CFG_AD);
  9447. + __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0),
  9448. + base + PCI_REG_CFG_CBE);
  9449. +
  9450. + return ar71xx_pci_be_handler(1);
  9451. +}
  9452. +
  9453. +static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  9454. + int where, int size, u32 *value)
  9455. +{
  9456. + void __iomem *base = ar71xx_pcicfg_base;
  9457. + static u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
  9458. + unsigned long flags;
  9459. + u32 data;
  9460. + int ret;
  9461. +
  9462. + ret = PCIBIOS_SUCCESSFUL;
  9463. +
  9464. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d\n", bus->number,
  9465. + PCI_SLOT(devfn), PCI_FUNC(devfn), where, size);
  9466. +
  9467. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  9468. +
  9469. + if (bus->number == 0 && devfn == 0) {
  9470. + u32 t;
  9471. +
  9472. + t = PCI_CRP_CMD_READ | (where & ~3);
  9473. +
  9474. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  9475. + data = __raw_readl(base + PCI_REG_CRP_RDDATA);
  9476. +
  9477. + DBG("PCI: rd local cfg, ad_cbe:%08x, data:%08x\n", t, data);
  9478. +
  9479. + } else {
  9480. + int err;
  9481. +
  9482. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  9483. + PCI_CFG_CMD_READ);
  9484. +
  9485. + if (err == 0) {
  9486. + data = __raw_readl(base + PCI_REG_CFG_RDDATA);
  9487. + } else {
  9488. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  9489. + data = ~0;
  9490. + }
  9491. + }
  9492. +
  9493. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  9494. +
  9495. + DBG("PCI: read config: data=%08x raw=%08x\n",
  9496. + (data >> (8 * (where & 3))) & mask[size & 7], data);
  9497. +
  9498. + *value = (data >> (8 * (where & 3))) & mask[size & 7];
  9499. +
  9500. + return ret;
  9501. +}
  9502. +
  9503. +static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  9504. + int where, int size, u32 value)
  9505. +{
  9506. + void __iomem *base = ar71xx_pcicfg_base;
  9507. + unsigned long flags;
  9508. + int ret;
  9509. +
  9510. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d value=%08x\n",
  9511. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9512. + where, size, value);
  9513. +
  9514. + value = value << (8 * (where & 3));
  9515. + ret = PCIBIOS_SUCCESSFUL;
  9516. +
  9517. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  9518. + if (bus->number == 0 && devfn == 0) {
  9519. + u32 t;
  9520. +
  9521. + t = PCI_CRP_CMD_WRITE | (where & ~3);
  9522. + t |= ar71xx_pci_get_ble(where, size, 1);
  9523. +
  9524. + DBG("PCI: wr local cfg, ad_cbe:%08x, value:%08x\n", t, value);
  9525. +
  9526. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  9527. + __raw_writel(value, base + PCI_REG_CRP_WRDATA);
  9528. + } else {
  9529. + int err;
  9530. +
  9531. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  9532. + PCI_CFG_CMD_WRITE);
  9533. +
  9534. + if (err == 0)
  9535. + __raw_writel(value, base + PCI_REG_CFG_WRDATA);
  9536. + else
  9537. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  9538. + }
  9539. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  9540. +
  9541. + return ret;
  9542. +}
  9543. +
  9544. +static void ar71xx_pci_fixup(struct pci_dev *dev)
  9545. +{
  9546. + u32 t;
  9547. +
  9548. + if (!ar71xx_pci_fixup_enable)
  9549. + return;
  9550. +
  9551. + if (dev->bus->number != 0 || dev->devfn != 0)
  9552. + return;
  9553. +
  9554. + DBG("PCI: fixup host controller %s (%04x:%04x)\n", pci_name(dev),
  9555. + dev->vendor, dev->device);
  9556. +
  9557. + /* setup COMMAND register */
  9558. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
  9559. + | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
  9560. +
  9561. + pci_write_config_word(dev, PCI_COMMAND, t);
  9562. +}
  9563. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar71xx_pci_fixup);
  9564. +
  9565. +int __init ar71xx_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  9566. + uint8_t pin)
  9567. +{
  9568. + int irq = -1;
  9569. + int i;
  9570. +
  9571. + slot -= PCI_IDSEL_ADL_START - PCI_IDSEL_BASE;
  9572. +
  9573. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  9574. + struct ar71xx_pci_irq *entry;
  9575. +
  9576. + entry = &ar71xx_pci_irq_map[i];
  9577. + if (entry->slot == slot && entry->pin == pin) {
  9578. + irq = entry->irq;
  9579. + break;
  9580. + }
  9581. + }
  9582. +
  9583. + if (irq < 0) {
  9584. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  9585. + pin, pci_name((struct pci_dev *)dev));
  9586. + } else {
  9587. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  9588. + irq, pin, pci_name((struct pci_dev *)dev));
  9589. + }
  9590. +
  9591. + return irq;
  9592. +}
  9593. +
  9594. +static struct pci_ops ar71xx_pci_ops = {
  9595. + .read = ar71xx_pci_read_config,
  9596. + .write = ar71xx_pci_write_config,
  9597. +};
  9598. +
  9599. +static struct resource ar71xx_pci_io_resource = {
  9600. + .name = "PCI IO space",
  9601. + .start = 0,
  9602. + .end = 0,
  9603. + .flags = IORESOURCE_IO,
  9604. +};
  9605. +
  9606. +static struct resource ar71xx_pci_mem_resource = {
  9607. + .name = "PCI memory space",
  9608. + .start = AR71XX_PCI_MEM_BASE,
  9609. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  9610. + .flags = IORESOURCE_MEM
  9611. +};
  9612. +
  9613. +static struct pci_controller ar71xx_pci_controller = {
  9614. + .pci_ops = &ar71xx_pci_ops,
  9615. + .mem_resource = &ar71xx_pci_mem_resource,
  9616. + .io_resource = &ar71xx_pci_io_resource,
  9617. +};
  9618. +
  9619. +static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  9620. +{
  9621. + void __iomem *base = ar71xx_reset_base;
  9622. + u32 pending;
  9623. +
  9624. + pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
  9625. + __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9626. +
  9627. + if (pending & PCI_INT_DEV0)
  9628. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  9629. +
  9630. + else if (pending & PCI_INT_DEV1)
  9631. + generic_handle_irq(AR71XX_PCI_IRQ_DEV1);
  9632. +
  9633. + else if (pending & PCI_INT_DEV2)
  9634. + generic_handle_irq(AR71XX_PCI_IRQ_DEV2);
  9635. +
  9636. + else if (pending & PCI_INT_CORE)
  9637. + generic_handle_irq(AR71XX_PCI_IRQ_CORE);
  9638. +
  9639. + else
  9640. + spurious_interrupt();
  9641. +}
  9642. +
  9643. +static void ar71xx_pci_irq_unmask(unsigned int irq)
  9644. +{
  9645. + void __iomem *base = ar71xx_reset_base;
  9646. + u32 t;
  9647. +
  9648. + irq -= AR71XX_PCI_IRQ_BASE;
  9649. +
  9650. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9651. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9652. +
  9653. + /* flush write */
  9654. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9655. +}
  9656. +
  9657. +static void ar71xx_pci_irq_mask(unsigned int irq)
  9658. +{
  9659. + void __iomem *base = ar71xx_reset_base;
  9660. + u32 t;
  9661. +
  9662. + irq -= AR71XX_PCI_IRQ_BASE;
  9663. +
  9664. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9665. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9666. +
  9667. + /* flush write */
  9668. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9669. +}
  9670. +
  9671. +static struct irq_chip ar71xx_pci_irq_chip = {
  9672. + .name = "AR71XX PCI ",
  9673. + .mask = ar71xx_pci_irq_mask,
  9674. + .unmask = ar71xx_pci_irq_unmask,
  9675. + .mask_ack = ar71xx_pci_irq_mask,
  9676. +};
  9677. +
  9678. +static void __init ar71xx_pci_irq_init(void)
  9679. +{
  9680. + void __iomem *base = ar71xx_reset_base;
  9681. + int i;
  9682. +
  9683. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9684. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_STATUS);
  9685. +
  9686. + for (i = AR71XX_PCI_IRQ_BASE;
  9687. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) {
  9688. + irq_desc[i].status = IRQ_DISABLED;
  9689. + set_irq_chip_and_handler(i, &ar71xx_pci_irq_chip,
  9690. + handle_level_irq);
  9691. + }
  9692. +
  9693. + set_irq_chained_handler(AR71XX_CPU_IRQ_IP2, ar71xx_pci_irq_handler);
  9694. +}
  9695. +
  9696. +int __init ar71xx_pcibios_init(void)
  9697. +{
  9698. + void __iomem *ddr_base = ar71xx_ddr_base;
  9699. +
  9700. + ar71xx_device_stop(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  9701. + ar71xx_pci_delay();
  9702. +
  9703. + ar71xx_device_start(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  9704. + ar71xx_pci_delay();
  9705. +
  9706. + ar71xx_pcicfg_base = ioremap_nocache(AR71XX_PCI_CFG_BASE,
  9707. + AR71XX_PCI_CFG_SIZE);
  9708. + if (ar71xx_pcicfg_base == NULL)
  9709. + return -ENOMEM;
  9710. +
  9711. + __raw_writel(PCI_WIN0_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN0);
  9712. + __raw_writel(PCI_WIN1_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN1);
  9713. + __raw_writel(PCI_WIN2_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN2);
  9714. + __raw_writel(PCI_WIN3_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN3);
  9715. + __raw_writel(PCI_WIN4_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN4);
  9716. + __raw_writel(PCI_WIN5_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN5);
  9717. + __raw_writel(PCI_WIN6_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN6);
  9718. + __raw_writel(PCI_WIN7_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN7);
  9719. +
  9720. + ar71xx_pci_delay();
  9721. +
  9722. + /* clear bus errors */
  9723. + (void)ar71xx_pci_be_handler(1);
  9724. +
  9725. + ar71xx_pci_fixup_enable = 1;
  9726. + ar71xx_pci_irq_init();
  9727. + register_pci_controller(&ar71xx_pci_controller);
  9728. +
  9729. + return 0;
  9730. +}
  9731. diff -Nur linux-2.6.33.3.orig/arch/mips/pci/pci-ar724x.c linux-2.6.33.3/arch/mips/pci/pci-ar724x.c
  9732. --- linux-2.6.33.3.orig/arch/mips/pci/pci-ar724x.c 1970-01-01 01:00:00.000000000 +0100
  9733. +++ linux-2.6.33.3/arch/mips/pci/pci-ar724x.c 2010-04-02 11:07:52.002954061 +0200
  9734. @@ -0,0 +1,395 @@
  9735. +/*
  9736. + * Atheros AR724x PCI host controller driver
  9737. + *
  9738. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  9739. + *
  9740. + * Parts of this file are based on Atheros' 2.6.15 BSP
  9741. + *
  9742. + * This program is free software; you can redistribute it and/or modify it
  9743. + * under the terms of the GNU General Public License version 2 as published
  9744. + * by the Free Software Foundation.
  9745. + */
  9746. +
  9747. +#include <linux/resource.h>
  9748. +#include <linux/types.h>
  9749. +#include <linux/delay.h>
  9750. +#include <linux/bitops.h>
  9751. +#include <linux/pci.h>
  9752. +#include <linux/pci_regs.h>
  9753. +#include <linux/interrupt.h>
  9754. +
  9755. +#include <asm/mach-ar71xx/ar71xx.h>
  9756. +#include <asm/mach-ar71xx/pci.h>
  9757. +
  9758. +#undef DEBUG
  9759. +#ifdef DEBUG
  9760. +#define DBG(fmt, args...) printk(KERN_INFO fmt, ## args)
  9761. +#else
  9762. +#define DBG(fmt, args...)
  9763. +#endif
  9764. +
  9765. +static void __iomem *ar724x_pci_localcfg_base;
  9766. +static void __iomem *ar724x_pci_devcfg_base;
  9767. +static void __iomem *ar724x_pci_ctrl_base;
  9768. +static int ar724x_pci_fixup_enable;
  9769. +
  9770. +static DEFINE_SPINLOCK(ar724x_pci_lock);
  9771. +
  9772. +static void ar724x_pci_read(void __iomem *base, int where, int size, u32 *value)
  9773. +{
  9774. + unsigned long flags;
  9775. + u32 data;
  9776. +
  9777. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  9778. + data = __raw_readl(base + (where & ~3));
  9779. +
  9780. + switch (size) {
  9781. + case 1:
  9782. + if (where & 1)
  9783. + data >>= 8;
  9784. + if (where & 2)
  9785. + data >>= 16;
  9786. + data &= 0xFF;
  9787. + break;
  9788. + case 2:
  9789. + if (where & 2)
  9790. + data >>= 16;
  9791. + data &= 0xFFFF;
  9792. + break;
  9793. + }
  9794. +
  9795. + *value = data;
  9796. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  9797. +}
  9798. +
  9799. +static void ar724x_pci_write(void __iomem *base, int where, int size, u32 value)
  9800. +{
  9801. + unsigned long flags;
  9802. + u32 data;
  9803. + int s;
  9804. +
  9805. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  9806. + data = __raw_readl(base + (where & ~3));
  9807. +
  9808. + switch (size) {
  9809. + case 1:
  9810. + s = ((where & 3) << 3);
  9811. + data &= ~(0xFF << s);
  9812. + data |= ((value & 0xFF) << s);
  9813. + break;
  9814. + case 2:
  9815. + s = ((where & 2) << 3);
  9816. + data &= ~(0xFFFF << s);
  9817. + data |= ((value & 0xFFFF) << s);
  9818. + break;
  9819. + case 4:
  9820. + data = value;
  9821. + break;
  9822. + }
  9823. +
  9824. + __raw_writel(data, base + (where & ~3));
  9825. + /* flush write */
  9826. + (void)__raw_readl(base + (where & ~3));
  9827. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  9828. +}
  9829. +
  9830. +static int ar724x_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  9831. + int where, int size, u32 *value)
  9832. +{
  9833. +
  9834. + if (bus->number != 0 || devfn != 0)
  9835. + return PCIBIOS_DEVICE_NOT_FOUND;
  9836. +
  9837. + ar724x_pci_read(ar724x_pci_devcfg_base, where, size, value);
  9838. +
  9839. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  9840. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9841. + where, size, *value);
  9842. +
  9843. + /*
  9844. + * WAR for BAR issue - We are unable to access the PCI device space
  9845. + * if we set the BAR with proper base address
  9846. + */
  9847. + if ((where == 0x10) && (size == 4)) {
  9848. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  9849. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, 0xffff);
  9850. + else
  9851. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, 0x1000ffff);
  9852. + }
  9853. +
  9854. + return PCIBIOS_SUCCESSFUL;
  9855. +}
  9856. +
  9857. +static int ar724x_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  9858. + int where, int size, u32 value)
  9859. +{
  9860. + if (bus->number != 0 || devfn != 0)
  9861. + return PCIBIOS_DEVICE_NOT_FOUND;
  9862. +
  9863. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  9864. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9865. + where, size, value);
  9866. +
  9867. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, value);
  9868. +
  9869. + return PCIBIOS_SUCCESSFUL;
  9870. +}
  9871. +
  9872. +static void ar724x_pci_fixup(struct pci_dev *dev)
  9873. +{
  9874. + u16 cmd;
  9875. +
  9876. + if (!ar724x_pci_fixup_enable)
  9877. + return;
  9878. +
  9879. + if (dev->bus->number != 0 || dev->devfn != 0)
  9880. + return;
  9881. +
  9882. + /* setup COMMAND register */
  9883. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  9884. + cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  9885. + PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY | PCI_COMMAND_SERR |
  9886. + PCI_COMMAND_FAST_BACK;
  9887. +
  9888. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  9889. +}
  9890. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar724x_pci_fixup);
  9891. +
  9892. +int __init ar724x_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  9893. + uint8_t pin)
  9894. +{
  9895. + int irq = -1;
  9896. + int i;
  9897. +
  9898. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  9899. + struct ar71xx_pci_irq *entry;
  9900. + entry = &ar71xx_pci_irq_map[i];
  9901. +
  9902. + if (entry->slot == slot && entry->pin == pin) {
  9903. + irq = entry->irq;
  9904. + break;
  9905. + }
  9906. + }
  9907. +
  9908. + if (irq < 0)
  9909. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  9910. + pin, pci_name((struct pci_dev *)dev));
  9911. + else
  9912. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  9913. + irq, pin, pci_name((struct pci_dev *)dev));
  9914. +
  9915. + return irq;
  9916. +}
  9917. +
  9918. +static struct pci_ops ar724x_pci_ops = {
  9919. + .read = ar724x_pci_read_config,
  9920. + .write = ar724x_pci_write_config,
  9921. +};
  9922. +
  9923. +static struct resource ar724x_pci_io_resource = {
  9924. + .name = "PCI IO space",
  9925. + .start = 0,
  9926. + .end = 0,
  9927. + .flags = IORESOURCE_IO,
  9928. +};
  9929. +
  9930. +static struct resource ar724x_pci_mem_resource = {
  9931. + .name = "PCI memory space",
  9932. + .start = AR71XX_PCI_MEM_BASE,
  9933. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  9934. + .flags = IORESOURCE_MEM
  9935. +};
  9936. +
  9937. +static struct pci_controller ar724x_pci_controller = {
  9938. + .pci_ops = &ar724x_pci_ops,
  9939. + .mem_resource = &ar724x_pci_mem_resource,
  9940. + .io_resource = &ar724x_pci_io_resource,
  9941. +};
  9942. +
  9943. +static void __init ar724x_pci_reset(void)
  9944. +{
  9945. + ar71xx_device_stop(AR724X_RESET_PCIE);
  9946. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY);
  9947. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY_SERIAL);
  9948. + udelay(100);
  9949. +
  9950. + ar71xx_device_start(AR724X_RESET_PCIE_PHY_SERIAL);
  9951. + udelay(100);
  9952. + ar71xx_device_start(AR724X_RESET_PCIE_PHY);
  9953. + ar71xx_device_start(AR724X_RESET_PCIE);
  9954. +}
  9955. +
  9956. +static int __init ar724x_pci_setup(void)
  9957. +{
  9958. + void __iomem *base = ar724x_pci_ctrl_base;
  9959. + u32 t;
  9960. +
  9961. + /* setup COMMAND register */
  9962. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE |
  9963. + PCI_COMMAND_PARITY|PCI_COMMAND_SERR|PCI_COMMAND_FAST_BACK;
  9964. +
  9965. + ar724x_pci_write(ar724x_pci_localcfg_base, PCI_COMMAND, 4, t);
  9966. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x20, 4, 0x1ff01000);
  9967. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x24, 4, 0x1ff01000);
  9968. +
  9969. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  9970. + if (t != 0x7) {
  9971. + udelay(100000);
  9972. + __raw_writel(0, base + AR724X_PCI_REG_RESET);
  9973. + udelay(100);
  9974. + __raw_writel(4, base + AR724X_PCI_REG_RESET);
  9975. + udelay(100000);
  9976. + }
  9977. +
  9978. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  9979. + t = AR724X_PCI_APP_LTSSM_ENABLE;
  9980. + else
  9981. + t = 0x1ffc1;
  9982. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  9983. + /* flush write */
  9984. + (void) __raw_readl(base + AR724X_PCI_REG_APP);
  9985. + udelay(1000);
  9986. +
  9987. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  9988. + if ((t & AR724X_PCI_RESET_LINK_UP) == 0x0) {
  9989. + printk(KERN_WARNING "PCI: no PCIe module found\n");
  9990. + return -ENODEV;
  9991. + }
  9992. +
  9993. + if (ar71xx_soc == AR71XX_SOC_AR7241 || ar71xx_soc == AR71XX_SOC_AR7242) {
  9994. + t = __raw_readl(base + AR724X_PCI_REG_APP);
  9995. + t |= BIT(16);
  9996. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  9997. + }
  9998. +
  9999. + return 0;
  10000. +}
  10001. +
  10002. +static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  10003. +{
  10004. + void __iomem *base = ar724x_pci_ctrl_base;
  10005. + u32 pending;
  10006. +
  10007. + pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
  10008. + __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10009. +
  10010. + if (pending & AR724X_PCI_INT_DEV0)
  10011. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  10012. +
  10013. + else
  10014. + spurious_interrupt();
  10015. +}
  10016. +
  10017. +static void ar724x_pci_irq_unmask(unsigned int irq)
  10018. +{
  10019. + void __iomem *base = ar724x_pci_ctrl_base;
  10020. + u32 t;
  10021. +
  10022. + switch (irq) {
  10023. + case AR71XX_PCI_IRQ_DEV0:
  10024. + irq -= AR71XX_PCI_IRQ_BASE;
  10025. +
  10026. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10027. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  10028. + base + AR724X_PCI_REG_INT_MASK);
  10029. + /* flush write */
  10030. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10031. + }
  10032. +}
  10033. +
  10034. +static void ar724x_pci_irq_mask(unsigned int irq)
  10035. +{
  10036. + void __iomem *base = ar724x_pci_ctrl_base;
  10037. + u32 t;
  10038. +
  10039. + switch (irq) {
  10040. + case AR71XX_PCI_IRQ_DEV0:
  10041. + irq -= AR71XX_PCI_IRQ_BASE;
  10042. +
  10043. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10044. + __raw_writel(t & ~AR724X_PCI_INT_DEV0,
  10045. + base + AR724X_PCI_REG_INT_MASK);
  10046. +
  10047. + /* flush write */
  10048. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10049. +
  10050. + t = __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  10051. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  10052. + base + AR724X_PCI_REG_INT_STATUS);
  10053. +
  10054. + /* flush write */
  10055. + (void) __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  10056. + }
  10057. +}
  10058. +
  10059. +static struct irq_chip ar724x_pci_irq_chip = {
  10060. + .name = "AR724X PCI ",
  10061. + .mask = ar724x_pci_irq_mask,
  10062. + .unmask = ar724x_pci_irq_unmask,
  10063. + .mask_ack = ar724x_pci_irq_mask,
  10064. +};
  10065. +
  10066. +static void __init ar724x_pci_irq_init(void)
  10067. +{
  10068. + void __iomem *base = ar724x_pci_ctrl_base;
  10069. + u32 t;
  10070. + int i;
  10071. +
  10072. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  10073. + if (t & (AR724X_RESET_PCIE | AR724X_RESET_PCIE_PHY |
  10074. + AR724X_RESET_PCIE_PHY_SERIAL)) {
  10075. + return;
  10076. + }
  10077. +
  10078. + __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
  10079. + __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
  10080. +
  10081. + for (i = AR71XX_PCI_IRQ_BASE;
  10082. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) {
  10083. + irq_desc[i].status = IRQ_DISABLED;
  10084. + set_irq_chip_and_handler(i, &ar724x_pci_irq_chip,
  10085. + handle_level_irq);
  10086. + }
  10087. +
  10088. + set_irq_chained_handler(AR71XX_CPU_IRQ_IP2, ar724x_pci_irq_handler);
  10089. +}
  10090. +
  10091. +int __init ar724x_pcibios_init(void)
  10092. +{
  10093. + int ret = -ENOMEM;
  10094. +
  10095. + ar724x_pci_localcfg_base = ioremap_nocache(AR724X_PCI_CRP_BASE,
  10096. + AR724X_PCI_CRP_SIZE);
  10097. + if (ar724x_pci_localcfg_base == NULL)
  10098. + goto err;
  10099. +
  10100. + ar724x_pci_devcfg_base = ioremap_nocache(AR724X_PCI_CFG_BASE,
  10101. + AR724X_PCI_CFG_SIZE);
  10102. + if (ar724x_pci_devcfg_base == NULL)
  10103. + goto err_unmap_localcfg;
  10104. +
  10105. + ar724x_pci_ctrl_base = ioremap_nocache(AR724X_PCI_CTRL_BASE,
  10106. + AR724X_PCI_CTRL_SIZE);
  10107. + if (ar724x_pci_ctrl_base == NULL)
  10108. + goto err_unmap_devcfg;
  10109. +
  10110. + ar724x_pci_reset();
  10111. + ret = ar724x_pci_setup();
  10112. + if (ret)
  10113. + goto err_unmap_ctrl;
  10114. +
  10115. + ar724x_pci_fixup_enable = 1;
  10116. + ar724x_pci_irq_init();
  10117. + register_pci_controller(&ar724x_pci_controller);
  10118. +
  10119. + return 0;
  10120. +
  10121. + err_unmap_ctrl:
  10122. + iounmap(ar724x_pci_ctrl_base);
  10123. + err_unmap_devcfg:
  10124. + iounmap(ar724x_pci_devcfg_base);
  10125. + err_unmap_localcfg:
  10126. + iounmap(ar724x_pci_localcfg_base);
  10127. + err:
  10128. + return ret;
  10129. +}
  10130. diff -Nur linux-2.6.33.3.orig/drivers/char/Kconfig linux-2.6.33.3/drivers/char/Kconfig
  10131. --- linux-2.6.33.3.orig/drivers/char/Kconfig 2010-04-26 16:48:30.000000000 +0200
  10132. +++ linux-2.6.33.3/drivers/char/Kconfig 2010-05-17 20:29:49.263661210 +0200
  10133. @@ -1016,6 +1016,14 @@
  10134. If compiled as a module, it will be called cs5535_gpio.
  10135. +config GPIO_DEVICE
  10136. + tristate "GPIO device support"
  10137. + depends on GENERIC_GPIO
  10138. + help
  10139. + Say Y to enable Linux GPIO device support. This allows control of
  10140. + GPIO pins using a character device
  10141. +
  10142. +
  10143. config RAW_DRIVER
  10144. tristate "RAW driver (/dev/raw/rawN)"
  10145. depends on BLOCK
  10146. diff -Nur linux-2.6.33.3.orig/drivers/char/Makefile linux-2.6.33.3/drivers/char/Makefile
  10147. --- linux-2.6.33.3.orig/drivers/char/Makefile 2010-04-26 16:48:30.000000000 +0200
  10148. +++ linux-2.6.33.3/drivers/char/Makefile 2010-05-17 20:29:49.267113605 +0200
  10149. @@ -95,6 +95,7 @@
  10150. obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
  10151. obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
  10152. obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
  10153. +obj-$(CONFIG_GPIO_DEVICE) += gpio_dev.o
  10154. obj-$(CONFIG_GPIO_TB0219) += tb0219.o
  10155. obj-$(CONFIG_TELCLOCK) += tlclk.o
  10156. diff -Nur linux-2.6.33.3.orig/drivers/gpio/nxp_74hc153.c linux-2.6.33.3/drivers/gpio/nxp_74hc153.c
  10157. --- linux-2.6.33.3.orig/drivers/gpio/nxp_74hc153.c 1970-01-01 01:00:00.000000000 +0100
  10158. +++ linux-2.6.33.3/drivers/gpio/nxp_74hc153.c 2010-01-19 19:26:38.721436935 +0100
  10159. @@ -0,0 +1,246 @@
  10160. +/*
  10161. + * NXP 74HC153 - Dual 4-input multiplexer GPIO driver
  10162. + *
  10163. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  10164. + *
  10165. + * This program is free software; you can redistribute it and/or modify
  10166. + * it under the terms of the GNU General Public License version 2 as
  10167. + * published by the Free Software Foundation.
  10168. + */
  10169. +
  10170. +#include <linux/module.h>
  10171. +#include <linux/init.h>
  10172. +#include <linux/gpio.h>
  10173. +#include <linux/platform_device.h>
  10174. +#include <linux/nxp_74hc153.h>
  10175. +
  10176. +#define NXP_74HC153_NUM_GPIOS 8
  10177. +#define NXP_74HC153_S0_MASK 0x1
  10178. +#define NXP_74HC153_S1_MASK 0x2
  10179. +#define NXP_74HC153_BANK_MASK 0x4
  10180. +
  10181. +struct nxp_74hc153_chip {
  10182. + struct device *parent;
  10183. + struct gpio_chip gpio_chip;
  10184. + struct mutex lock;
  10185. +};
  10186. +
  10187. +static struct nxp_74hc153_chip *gpio_to_nxp(struct gpio_chip *gc)
  10188. +{
  10189. + return container_of(gc, struct nxp_74hc153_chip, gpio_chip);
  10190. +}
  10191. +
  10192. +static int nxp_74hc153_direction_input(struct gpio_chip *gc, unsigned offset)
  10193. +{
  10194. + return 0;
  10195. +}
  10196. +
  10197. +static int nxp_74hc153_direction_output(struct gpio_chip *gc,
  10198. + unsigned offset, int val)
  10199. +{
  10200. + return -EINVAL;
  10201. +}
  10202. +
  10203. +static int nxp_74hc153_get_value(struct gpio_chip *gc, unsigned offset)
  10204. +{
  10205. + struct nxp_74hc153_chip *nxp;
  10206. + struct nxp_74hc153_platform_data *pdata;
  10207. + unsigned s0;
  10208. + unsigned s1;
  10209. + unsigned pin;
  10210. + int ret;
  10211. +
  10212. + nxp = gpio_to_nxp(gc);
  10213. + pdata = nxp->parent->platform_data;
  10214. +
  10215. + s0 = !!(offset & NXP_74HC153_S0_MASK);
  10216. + s1 = !!(offset & NXP_74HC153_S1_MASK);
  10217. + pin = (offset & NXP_74HC153_BANK_MASK) ? pdata->gpio_pin_2y
  10218. + : pdata->gpio_pin_1y;
  10219. +
  10220. + mutex_lock(&nxp->lock);
  10221. + gpio_set_value(pdata->gpio_pin_s0, s0);
  10222. + gpio_set_value(pdata->gpio_pin_s1, s1);
  10223. + ret = gpio_get_value(pin);
  10224. + mutex_unlock(&nxp->lock);
  10225. +
  10226. + return ret;
  10227. +}
  10228. +
  10229. +static void nxp_74hc153_set_value(struct gpio_chip *gc,
  10230. + unsigned offset, int val)
  10231. +{
  10232. + /* not supported */
  10233. +}
  10234. +
  10235. +static int __devinit nxp_74hc153_probe(struct platform_device *pdev)
  10236. +{
  10237. + struct nxp_74hc153_platform_data *pdata;
  10238. + struct nxp_74hc153_chip *nxp;
  10239. + struct gpio_chip *gc;
  10240. + int err;
  10241. +
  10242. + pdata = pdev->dev.platform_data;
  10243. + if (pdata == NULL) {
  10244. + dev_dbg(&pdev->dev, "no platform data specified\n");
  10245. + return -EINVAL;
  10246. + }
  10247. +
  10248. + nxp = kzalloc(sizeof(struct nxp_74hc153_chip), GFP_KERNEL);
  10249. + if (nxp == NULL) {
  10250. + dev_err(&pdev->dev, "no memory for private data\n");
  10251. + return -ENOMEM;
  10252. + }
  10253. +
  10254. + err = gpio_request(pdata->gpio_pin_s0, dev_name(&pdev->dev));
  10255. + if (err) {
  10256. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10257. + pdata->gpio_pin_s0, err);
  10258. + goto err_free_nxp;
  10259. + }
  10260. +
  10261. + err = gpio_request(pdata->gpio_pin_s1, dev_name(&pdev->dev));
  10262. + if (err) {
  10263. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10264. + pdata->gpio_pin_s1, err);
  10265. + goto err_free_s0;
  10266. + }
  10267. +
  10268. + err = gpio_request(pdata->gpio_pin_1y, dev_name(&pdev->dev));
  10269. + if (err) {
  10270. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10271. + pdata->gpio_pin_1y, err);
  10272. + goto err_free_s1;
  10273. + }
  10274. +
  10275. + err = gpio_request(pdata->gpio_pin_2y, dev_name(&pdev->dev));
  10276. + if (err) {
  10277. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10278. + pdata->gpio_pin_2y, err);
  10279. + goto err_free_1y;
  10280. + }
  10281. +
  10282. + err = gpio_direction_output(pdata->gpio_pin_s0, 0);
  10283. + if (err) {
  10284. + dev_err(&pdev->dev,
  10285. + "unable to set direction of gpio %u, err=%d\n",
  10286. + pdata->gpio_pin_s0, err);
  10287. + goto err_free_2y;
  10288. + }
  10289. +
  10290. + err = gpio_direction_output(pdata->gpio_pin_s1, 0);
  10291. + if (err) {
  10292. + dev_err(&pdev->dev,
  10293. + "unable to set direction of gpio %u, err=%d\n",
  10294. + pdata->gpio_pin_s1, err);
  10295. + goto err_free_2y;
  10296. + }
  10297. +
  10298. + err = gpio_direction_input(pdata->gpio_pin_1y);
  10299. + if (err) {
  10300. + dev_err(&pdev->dev,
  10301. + "unable to set direction of gpio %u, err=%d\n",
  10302. + pdata->gpio_pin_1y, err);
  10303. + goto err_free_2y;
  10304. + }
  10305. +
  10306. + err = gpio_direction_input(pdata->gpio_pin_2y);
  10307. + if (err) {
  10308. + dev_err(&pdev->dev,
  10309. + "unable to set direction of gpio %u, err=%d\n",
  10310. + pdata->gpio_pin_2y, err);
  10311. + goto err_free_2y;
  10312. + }
  10313. +
  10314. + nxp->parent = &pdev->dev;
  10315. + mutex_init(&nxp->lock);
  10316. +
  10317. + gc = &nxp->gpio_chip;
  10318. +
  10319. + gc->direction_input = nxp_74hc153_direction_input;
  10320. + gc->direction_output = nxp_74hc153_direction_output;
  10321. + gc->get = nxp_74hc153_get_value;
  10322. + gc->set = nxp_74hc153_set_value;
  10323. + gc->can_sleep = 1;
  10324. +
  10325. + gc->base = pdata->gpio_base;
  10326. + gc->ngpio = NXP_74HC153_NUM_GPIOS;
  10327. + gc->label = dev_name(nxp->parent);
  10328. + gc->dev = nxp->parent;
  10329. + gc->owner = THIS_MODULE;
  10330. +
  10331. + err = gpiochip_add(&nxp->gpio_chip);
  10332. + if (err) {
  10333. + dev_err(&pdev->dev, "unable to add gpio chip, err=%d\n", err);
  10334. + goto err_free_2y;
  10335. + }
  10336. +
  10337. + platform_set_drvdata(pdev, nxp);
  10338. + return 0;
  10339. +
  10340. + err_free_2y:
  10341. + gpio_free(pdata->gpio_pin_2y);
  10342. + err_free_1y:
  10343. + gpio_free(pdata->gpio_pin_1y);
  10344. + err_free_s1:
  10345. + gpio_free(pdata->gpio_pin_s1);
  10346. + err_free_s0:
  10347. + gpio_free(pdata->gpio_pin_s0);
  10348. + err_free_nxp:
  10349. + kfree(nxp);
  10350. + return err;
  10351. +}
  10352. +
  10353. +static int nxp_74hc153_remove(struct platform_device *pdev)
  10354. +{
  10355. + struct nxp_74hc153_chip *nxp = platform_get_drvdata(pdev);
  10356. + struct nxp_74hc153_platform_data *pdata = pdev->dev.platform_data;
  10357. +
  10358. + if (nxp) {
  10359. + int err;
  10360. +
  10361. + err = gpiochip_remove(&nxp->gpio_chip);
  10362. + if (err) {
  10363. + dev_err(&pdev->dev,
  10364. + "unable to remove gpio chip, err=%d\n",
  10365. + err);
  10366. + return err;
  10367. + }
  10368. +
  10369. + gpio_free(pdata->gpio_pin_2y);
  10370. + gpio_free(pdata->gpio_pin_1y);
  10371. + gpio_free(pdata->gpio_pin_s1);
  10372. + gpio_free(pdata->gpio_pin_s0);
  10373. +
  10374. + kfree(nxp);
  10375. + platform_set_drvdata(pdev, NULL);
  10376. + }
  10377. +
  10378. + return 0;
  10379. +}
  10380. +
  10381. +static struct platform_driver nxp_74hc153_driver = {
  10382. + .probe = nxp_74hc153_probe,
  10383. + .remove = __devexit_p(nxp_74hc153_remove),
  10384. + .driver = {
  10385. + .name = NXP_74HC153_DRIVER_NAME,
  10386. + .owner = THIS_MODULE,
  10387. + },
  10388. +};
  10389. +
  10390. +static int __init nxp_74hc153_init(void)
  10391. +{
  10392. + return platform_driver_register(&nxp_74hc153_driver);
  10393. +}
  10394. +subsys_initcall(nxp_74hc153_init);
  10395. +
  10396. +static void __exit nxp_74hc153_exit(void)
  10397. +{
  10398. + platform_driver_unregister(&nxp_74hc153_driver);
  10399. +}
  10400. +module_exit(nxp_74hc153_exit);
  10401. +
  10402. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10403. +MODULE_DESCRIPTION("GPIO expander driver for NXP 74HC153");
  10404. +MODULE_LICENSE("GPL v2");
  10405. +MODULE_ALIAS("platform:" NXP_74HC153_DRIVER_NAME);
  10406. diff -Nur linux-2.6.33.3.orig/drivers/input/misc/gpio_buttons.c linux-2.6.33.3/drivers/input/misc/gpio_buttons.c
  10407. --- linux-2.6.33.3.orig/drivers/input/misc/gpio_buttons.c 1970-01-01 01:00:00.000000000 +0100
  10408. +++ linux-2.6.33.3/drivers/input/misc/gpio_buttons.c 2010-05-16 13:16:51.715600731 +0200
  10409. @@ -0,0 +1,216 @@
  10410. +/*
  10411. + * Driver for buttons on GPIO lines not capable of generating interrupts
  10412. + *
  10413. + * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
  10414. + * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
  10415. + *
  10416. + * This file was based on: /drivers/input/misc/cobalt_btns.c
  10417. + * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  10418. + *
  10419. + * also was based on: /drivers/input/keyboard/gpio_keys.c
  10420. + * Copyright 2005 Phil Blundell
  10421. + *
  10422. + * This program is free software; you can redistribute it and/or modify
  10423. + * it under the terms of the GNU General Public License version 2 as
  10424. + * published by the Free Software Foundation.
  10425. + *
  10426. + */
  10427. +
  10428. +#include <linux/kernel.h>
  10429. +#include <linux/module.h>
  10430. +#include <linux/init.h>
  10431. +#include <linux/slab.h>
  10432. +
  10433. +#include <linux/input.h>
  10434. +#include <linux/input-polldev.h>
  10435. +#include <linux/ioport.h>
  10436. +#include <linux/platform_device.h>
  10437. +
  10438. +#include <linux/gpio_buttons.h>
  10439. +
  10440. +#include <asm/gpio.h>
  10441. +
  10442. +#define DRV_NAME "gpio-buttons"
  10443. +#define DRV_VERSION "0.1.2"
  10444. +#define PFX DRV_NAME ": "
  10445. +
  10446. +struct gpio_button_data {
  10447. + int last_state;
  10448. + int count;
  10449. +};
  10450. +
  10451. +struct gpio_buttons_dev {
  10452. + struct input_polled_dev *poll_dev;
  10453. + struct gpio_buttons_platform_data *pdata;
  10454. + struct gpio_button_data *data;
  10455. +};
  10456. +
  10457. +static void gpio_buttons_poll(struct input_polled_dev *dev)
  10458. +{
  10459. + struct gpio_buttons_dev *bdev = dev->private;
  10460. + struct gpio_buttons_platform_data *pdata = bdev->pdata;
  10461. + struct input_dev *input = dev->input;
  10462. + int i;
  10463. +
  10464. + for (i = 0; i < bdev->pdata->nbuttons; i++) {
  10465. + struct gpio_button *button = &pdata->buttons[i];
  10466. + unsigned int type = button->type ?: EV_KEY;
  10467. + int state;
  10468. +
  10469. + if (bdev->data[i].count < button->threshold) {
  10470. + bdev->data[i].count++;
  10471. + continue;
  10472. + }
  10473. +
  10474. + state = gpio_get_value(button->gpio) ? 1 : 0;
  10475. + if (state != bdev->data[i].last_state) {
  10476. + input_event(input, type, button->code,
  10477. + !!(state ^ button->active_low));
  10478. + input_sync(input);
  10479. + bdev->data[i].count = 0;
  10480. + bdev->data[i].last_state = state;
  10481. + }
  10482. + }
  10483. +}
  10484. +
  10485. +static int __devinit gpio_buttons_probe(struct platform_device *pdev)
  10486. +{
  10487. + struct gpio_buttons_platform_data *pdata = pdev->dev.platform_data;
  10488. + struct gpio_buttons_dev *bdev;
  10489. + struct input_polled_dev *poll_dev;
  10490. + struct input_dev *input;
  10491. + int error, i;
  10492. +
  10493. + if (!pdata)
  10494. + return -ENXIO;
  10495. +
  10496. + bdev = kzalloc(sizeof(struct gpio_buttons_dev) +
  10497. + sizeof(struct gpio_button_data) * pdata->nbuttons,
  10498. + GFP_KERNEL);
  10499. + if (!bdev) {
  10500. + printk(KERN_ERR DRV_NAME "no memory for device\n");
  10501. + return -ENOMEM;
  10502. + }
  10503. +
  10504. + bdev->data = (struct gpio_button_data *) &bdev[1];
  10505. +
  10506. + poll_dev = input_allocate_polled_device();
  10507. + if (!poll_dev) {
  10508. + printk(KERN_ERR DRV_NAME "no memory for polled device\n");
  10509. + error = -ENOMEM;
  10510. + goto err_free_bdev;
  10511. + }
  10512. +
  10513. + poll_dev->private = bdev;
  10514. + poll_dev->poll = gpio_buttons_poll;
  10515. + poll_dev->poll_interval = pdata->poll_interval;
  10516. +
  10517. + input = poll_dev->input;
  10518. +
  10519. + input->evbit[0] = BIT(EV_KEY);
  10520. + input->name = pdev->name;
  10521. + input->phys = "gpio-buttons/input0";
  10522. + input->dev.parent = &pdev->dev;
  10523. +
  10524. + input->id.bustype = BUS_HOST;
  10525. + input->id.vendor = 0x0001;
  10526. + input->id.product = 0x0001;
  10527. + input->id.version = 0x0100;
  10528. +
  10529. + for (i = 0; i < pdata->nbuttons; i++) {
  10530. + struct gpio_button *button = &pdata->buttons[i];
  10531. + unsigned int gpio = button->gpio;
  10532. + unsigned int type = button->type ?: EV_KEY;
  10533. +
  10534. + error = gpio_request(gpio, button->desc ?
  10535. + button->desc : DRV_NAME);
  10536. + if (error) {
  10537. + printk(KERN_ERR PFX "unable to claim gpio %u, "
  10538. + "error %d\n", gpio, error);
  10539. + goto err_free_gpio;
  10540. + }
  10541. +
  10542. + error = gpio_direction_input(gpio);
  10543. + if (error) {
  10544. + printk(KERN_ERR PFX "unable to set direction on "
  10545. + "gpio %u, error %d\n", gpio, error);
  10546. + goto err_free_gpio;
  10547. + }
  10548. +
  10549. + input_set_capability(input, type, button->code);
  10550. + bdev->data[i].last_state = gpio_get_value(button->gpio) ? 1 : 0;
  10551. + }
  10552. +
  10553. + bdev->poll_dev = poll_dev;
  10554. + bdev->pdata = pdata;
  10555. + platform_set_drvdata(pdev, bdev);
  10556. +
  10557. + error = input_register_polled_device(poll_dev);
  10558. + if (error) {
  10559. + printk(KERN_ERR PFX "unable to register polled device, "
  10560. + "error %d\n", error);
  10561. + goto err_free_gpio;
  10562. + }
  10563. +
  10564. + return 0;
  10565. +
  10566. +err_free_gpio:
  10567. + for (i = i - 1; i >= 0; i--)
  10568. + gpio_free(pdata->buttons[i].gpio);
  10569. +
  10570. + input_free_polled_device(poll_dev);
  10571. +
  10572. +err_free_bdev:
  10573. + kfree(bdev);
  10574. +
  10575. + platform_set_drvdata(pdev, NULL);
  10576. + return error;
  10577. +}
  10578. +
  10579. +static int __devexit gpio_buttons_remove(struct platform_device *pdev)
  10580. +{
  10581. + struct gpio_buttons_dev *bdev = platform_get_drvdata(pdev);
  10582. + struct gpio_buttons_platform_data *pdata = bdev->pdata;
  10583. + int i;
  10584. +
  10585. + input_unregister_polled_device(bdev->poll_dev);
  10586. +
  10587. + for (i = 0; i < pdata->nbuttons; i++)
  10588. + gpio_free(pdata->buttons[i].gpio);
  10589. +
  10590. + input_free_polled_device(bdev->poll_dev);
  10591. +
  10592. + kfree(bdev);
  10593. + platform_set_drvdata(pdev, NULL);
  10594. +
  10595. + return 0;
  10596. +}
  10597. +
  10598. +static struct platform_driver gpio_buttons_driver = {
  10599. + .probe = gpio_buttons_probe,
  10600. + .remove = __devexit_p(gpio_buttons_remove),
  10601. + .driver = {
  10602. + .name = DRV_NAME,
  10603. + .owner = THIS_MODULE,
  10604. + },
  10605. +};
  10606. +
  10607. +static int __init gpio_buttons_init(void)
  10608. +{
  10609. + printk(KERN_INFO DRV_NAME " driver version " DRV_VERSION "\n");
  10610. + return platform_driver_register(&gpio_buttons_driver);
  10611. +}
  10612. +
  10613. +static void __exit gpio_buttons_exit(void)
  10614. +{
  10615. + platform_driver_unregister(&gpio_buttons_driver);
  10616. +}
  10617. +
  10618. +module_init(gpio_buttons_init);
  10619. +module_exit(gpio_buttons_exit);
  10620. +
  10621. +MODULE_LICENSE("GPL");
  10622. +MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
  10623. +MODULE_VERSION(DRV_VERSION);
  10624. +MODULE_DESCRIPTION("Polled buttons driver for CPU GPIOs");
  10625. +
  10626. diff -Nur linux-2.6.33.3.orig/drivers/input/misc/Kconfig linux-2.6.33.3/drivers/input/misc/Kconfig
  10627. --- linux-2.6.33.3.orig/drivers/input/misc/Kconfig 2010-04-26 16:48:30.000000000 +0200
  10628. +++ linux-2.6.33.3/drivers/input/misc/Kconfig 2010-05-17 20:29:41.363933213 +0200
  10629. @@ -319,4 +319,20 @@
  10630. To compile this driver as a module, choose M here: the
  10631. module will be called pcap_keys.
  10632. +config INPUT_GPIO_BUTTONS
  10633. + tristate "Polled GPIO buttons interface"
  10634. + depends on GENERIC_GPIO
  10635. + select INPUT_POLLDEV
  10636. + help
  10637. + This driver implements support for buttons connected
  10638. + to GPIO pins of various CPUs (and some other chips).
  10639. +
  10640. + Say Y here if your device has buttons connected
  10641. + directly to such GPIO pins. Your board-specific
  10642. + setup logic must also provide a platform device,
  10643. + with configuration data saying which GPIOs are used.
  10644. +
  10645. + To compile this driver as a module, choose M here: the
  10646. + module will be called gpio-buttons.
  10647. +
  10648. endif
  10649. diff -Nur linux-2.6.33.3.orig/drivers/input/misc/Makefile linux-2.6.33.3/drivers/input/misc/Makefile
  10650. --- linux-2.6.33.3.orig/drivers/input/misc/Makefile 2010-04-26 16:48:30.000000000 +0200
  10651. +++ linux-2.6.33.3/drivers/input/misc/Makefile 2010-05-17 20:29:41.363933213 +0200
  10652. @@ -30,4 +30,5 @@
  10653. obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
  10654. obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
  10655. obj-$(CONFIG_INPUT_YEALINK) += yealink.o
  10656. +obj-$(CONFIG_INPUT_GPIO_BUTTONS) += gpio_buttons.o
  10657. diff -Nur linux-2.6.33.3.orig/drivers/leds/leds-rb750.c linux-2.6.33.3/drivers/leds/leds-rb750.c
  10658. --- linux-2.6.33.3.orig/drivers/leds/leds-rb750.c 1970-01-01 01:00:00.000000000 +0100
  10659. +++ linux-2.6.33.3/drivers/leds/leds-rb750.c 2010-03-12 19:31:47.358041350 +0100
  10660. @@ -0,0 +1,140 @@
  10661. +/*
  10662. + * LED driver for the RouterBOARD 750
  10663. + *
  10664. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  10665. + *
  10666. + * This program is free software; you can redistribute it and/or modify
  10667. + * it under the terms of the GNU General Public License version 2 as
  10668. + * published by the Free Software Foundation.
  10669. + *
  10670. + */
  10671. +#include <linux/kernel.h>
  10672. +#include <linux/init.h>
  10673. +#include <linux/platform_device.h>
  10674. +#include <linux/leds.h>
  10675. +
  10676. +#include <asm/mach-ar71xx/mach-rb750.h>
  10677. +
  10678. +#define DRV_NAME "leds-rb750"
  10679. +
  10680. +struct rb750_led_dev {
  10681. + struct led_classdev cdev;
  10682. + u32 mask;
  10683. + int active_low;
  10684. +};
  10685. +
  10686. +struct rb750_led_drvdata {
  10687. + struct rb750_led_dev *led_devs;
  10688. + int num_leds;
  10689. +};
  10690. +
  10691. +static inline struct rb750_led_dev *to_rbled(struct led_classdev *led_cdev)
  10692. +{
  10693. + return (struct rb750_led_dev *)container_of(led_cdev,
  10694. + struct rb750_led_dev, cdev);
  10695. +}
  10696. +
  10697. +static void rb750_led_brightness_set(struct led_classdev *led_cdev,
  10698. + enum led_brightness value)
  10699. +{
  10700. + struct rb750_led_dev *rbled = to_rbled(led_cdev);
  10701. + int level;
  10702. +
  10703. + level = (value == LED_OFF) ? 0 : 1;
  10704. + level ^= rbled->active_low;
  10705. +
  10706. + if (level)
  10707. + rb750_latch_change(0, rbled->mask);
  10708. + else
  10709. + rb750_latch_change(rbled->mask, 0);
  10710. +}
  10711. +
  10712. +static int __devinit rb750_led_probe(struct platform_device *pdev)
  10713. +{
  10714. + struct rb750_led_platform_data *pdata;
  10715. + struct rb750_led_drvdata *drvdata;
  10716. + int ret = 0;
  10717. + int i;
  10718. +
  10719. + pdata = pdev->dev.platform_data;
  10720. + if (!pdata)
  10721. + return -EINVAL;
  10722. +
  10723. + drvdata = kzalloc(sizeof(struct rb750_led_drvdata) +
  10724. + sizeof(struct rb750_led_dev) * pdata->num_leds,
  10725. + GFP_KERNEL);
  10726. + if (!drvdata)
  10727. + return -ENOMEM;
  10728. +
  10729. + drvdata->num_leds = pdata->num_leds;
  10730. + drvdata->led_devs = (struct rb750_led_dev *) &drvdata[1];
  10731. +
  10732. + for (i = 0; i < drvdata->num_leds; i++) {
  10733. + struct rb750_led_dev *rbled = &drvdata->led_devs[i];
  10734. + struct rb750_led_data *led_data = &pdata->leds[i];
  10735. +
  10736. + rbled->cdev.name = led_data->name;
  10737. + rbled->cdev.default_trigger = led_data->default_trigger;
  10738. + rbled->cdev.brightness_set = rb750_led_brightness_set;
  10739. + rbled->cdev.brightness = LED_OFF;
  10740. +
  10741. + rbled->mask = led_data->mask;
  10742. + rbled->active_low = !!led_data->active_low;
  10743. +
  10744. + ret = led_classdev_register(&pdev->dev, &rbled->cdev);
  10745. + if (ret)
  10746. + goto err;
  10747. + }
  10748. +
  10749. + platform_set_drvdata(pdev, drvdata);
  10750. + return 0;
  10751. +
  10752. + err:
  10753. + for (i = i - 1; i >= 0; i--)
  10754. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  10755. +
  10756. + kfree(drvdata);
  10757. + return ret;
  10758. +}
  10759. +
  10760. +static int __devexit rb750_led_remove(struct platform_device *pdev)
  10761. +{
  10762. + struct rb750_led_drvdata *drvdata;
  10763. + int i;
  10764. +
  10765. + drvdata = platform_get_drvdata(pdev);
  10766. + for (i = 0; i < drvdata->num_leds; i++)
  10767. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  10768. +
  10769. + kfree(drvdata);
  10770. + return 0;
  10771. +}
  10772. +
  10773. +static struct platform_driver rb750_led_driver = {
  10774. + .probe = rb750_led_probe,
  10775. + .remove = __devexit_p(rb750_led_remove),
  10776. + .driver = {
  10777. + .name = DRV_NAME,
  10778. + .owner = THIS_MODULE,
  10779. + },
  10780. +};
  10781. +
  10782. +MODULE_ALIAS("platform:leds-rb750");
  10783. +
  10784. +static int __init rb750_led_init(void)
  10785. +{
  10786. + return platform_driver_register(&rb750_led_driver);
  10787. +}
  10788. +
  10789. +static void __exit rb750_led_exit(void)
  10790. +{
  10791. + platform_driver_unregister(&rb750_led_driver);
  10792. +}
  10793. +
  10794. +module_init(rb750_led_init);
  10795. +module_exit(rb750_led_exit);
  10796. +
  10797. +MODULE_DESCRIPTION(DRV_NAME);
  10798. +MODULE_DESCRIPTION("LED driver for the RouterBOARD 750");
  10799. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10800. +MODULE_LICENSE("GPL v2");
  10801. diff -Nur linux-2.6.33.3.orig/drivers/leds/leds-wndr3700-usb.c linux-2.6.33.3/drivers/leds/leds-wndr3700-usb.c
  10802. --- linux-2.6.33.3.orig/drivers/leds/leds-wndr3700-usb.c 1970-01-01 01:00:00.000000000 +0100
  10803. +++ linux-2.6.33.3/drivers/leds/leds-wndr3700-usb.c 2009-12-13 20:45:24.579920576 +0100
  10804. @@ -0,0 +1,75 @@
  10805. +/*
  10806. + * USB LED driver for the NETGEAR WNDR3700
  10807. + *
  10808. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10809. + *
  10810. + * This program is free software; you can redistribute it and/or modify it
  10811. + * under the terms of the GNU General Public License version 2 as published
  10812. + * by the Free Software Foundation.
  10813. + */
  10814. +
  10815. +#include <linux/leds.h>
  10816. +#include <linux/module.h>
  10817. +#include <linux/platform_device.h>
  10818. +
  10819. +#include <asm/mach-ar71xx/ar71xx.h>
  10820. +
  10821. +#define DRIVER_NAME "wndr3700-led-usb"
  10822. +
  10823. +static void wndr3700_usb_led_set(struct led_classdev *cdev,
  10824. + enum led_brightness brightness)
  10825. +{
  10826. + if (brightness)
  10827. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  10828. + else
  10829. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  10830. +}
  10831. +
  10832. +static enum led_brightness wndr3700_usb_led_get(struct led_classdev *cdev)
  10833. +{
  10834. + return ar71xx_device_stopped(RESET_MODULE_GE1_PHY) ? LED_OFF : LED_FULL;
  10835. +}
  10836. +
  10837. +static struct led_classdev wndr3700_usb_led = {
  10838. + .name = "wndr3700:green:usb",
  10839. + .brightness_set = wndr3700_usb_led_set,
  10840. + .brightness_get = wndr3700_usb_led_get,
  10841. +};
  10842. +
  10843. +static int __devinit wndr3700_usb_led_probe(struct platform_device *pdev)
  10844. +{
  10845. + return led_classdev_register(&pdev->dev, &wndr3700_usb_led);
  10846. +}
  10847. +
  10848. +static int __devexit wndr3700_usb_led_remove(struct platform_device *pdev)
  10849. +{
  10850. + led_classdev_unregister(&wndr3700_usb_led);
  10851. + return 0;
  10852. +}
  10853. +
  10854. +static struct platform_driver wndr3700_usb_led_driver = {
  10855. + .probe = wndr3700_usb_led_probe,
  10856. + .remove = __devexit_p(wndr3700_usb_led_remove),
  10857. + .driver = {
  10858. + .name = DRIVER_NAME,
  10859. + .owner = THIS_MODULE,
  10860. + },
  10861. +};
  10862. +
  10863. +static int __init wndr3700_usb_led_init(void)
  10864. +{
  10865. + return platform_driver_register(&wndr3700_usb_led_driver);
  10866. +}
  10867. +
  10868. +static void __exit wndr3700_usb_led_exit(void)
  10869. +{
  10870. + platform_driver_unregister(&wndr3700_usb_led_driver);
  10871. +}
  10872. +
  10873. +module_init(wndr3700_usb_led_init);
  10874. +module_exit(wndr3700_usb_led_exit);
  10875. +
  10876. +MODULE_DESCRIPTION("USB LED driver for the NETGEAR WNDR3700");
  10877. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10878. +MODULE_LICENSE("GPL v2");
  10879. +MODULE_ALIAS("platform:" DRIVER_NAME);
  10880. diff -Nur linux-2.6.33.3.orig/drivers/mtd/maps/ar91xx_flash.c linux-2.6.33.3/drivers/mtd/maps/ar91xx_flash.c
  10881. --- linux-2.6.33.3.orig/drivers/mtd/maps/ar91xx_flash.c 1970-01-01 01:00:00.000000000 +0100
  10882. +++ linux-2.6.33.3/drivers/mtd/maps/ar91xx_flash.c 2009-12-13 20:45:22.067931737 +0100
  10883. @@ -0,0 +1,310 @@
  10884. +/*
  10885. + * Parallel flash driver for the Atheros AR91xx SoC
  10886. + *
  10887. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10888. + *
  10889. + * This program is free software; you can redistribute it and/or modify
  10890. + * it under the terms of the GNU General Public License version 2 as
  10891. + * published by the Free Software Foundation.
  10892. + *
  10893. + */
  10894. +
  10895. +#include <linux/module.h>
  10896. +#include <linux/types.h>
  10897. +#include <linux/kernel.h>
  10898. +#include <linux/init.h>
  10899. +#include <linux/slab.h>
  10900. +#include <linux/device.h>
  10901. +#include <linux/platform_device.h>
  10902. +#include <linux/mtd/mtd.h>
  10903. +#include <linux/mtd/map.h>
  10904. +#include <linux/mtd/partitions.h>
  10905. +#include <linux/io.h>
  10906. +
  10907. +#include <asm/mach-ar71xx/ar71xx.h>
  10908. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  10909. +
  10910. +#define DRV_NAME "ar91xx-flash"
  10911. +
  10912. +struct ar91xx_flash_info {
  10913. + struct mtd_info *mtd;
  10914. + struct map_info map;
  10915. +#ifdef CONFIG_MTD_PARTITIONS
  10916. + int nr_parts;
  10917. + struct mtd_partition *parts;
  10918. +#endif
  10919. +};
  10920. +
  10921. +static map_word ar91xx_flash_read(struct map_info *map, unsigned long ofs)
  10922. +{
  10923. + map_word val;
  10924. +
  10925. + if (map_bankwidth_is_1(map))
  10926. + val.x[0] = __raw_readb(map->virt + (ofs ^ 3));
  10927. + else if (map_bankwidth_is_2(map))
  10928. + val.x[0] = __raw_readw(map->virt + (ofs ^ 2));
  10929. + else
  10930. + val = map_word_ff(map);
  10931. +
  10932. + return val;
  10933. +}
  10934. +
  10935. +static void ar91xx_flash_write(struct map_info *map, map_word d,
  10936. + unsigned long ofs)
  10937. +{
  10938. + if (map_bankwidth_is_1(map))
  10939. + __raw_writeb(d.x[0], map->virt + (ofs ^ 3));
  10940. + else if (map_bankwidth_is_2(map))
  10941. + __raw_writew(d.x[0], map->virt + (ofs ^ 2));
  10942. +
  10943. + mb();
  10944. +}
  10945. +
  10946. +static map_word ar91xx_flash_read_lock(struct map_info *map, unsigned long ofs)
  10947. +{
  10948. + map_word ret;
  10949. +
  10950. + ar71xx_flash_acquire();
  10951. + ret = ar91xx_flash_read(map, ofs);
  10952. + ar71xx_flash_release();
  10953. +
  10954. + return ret;
  10955. +}
  10956. +
  10957. +static void ar91xx_flash_write_lock(struct map_info *map, map_word d,
  10958. + unsigned long ofs)
  10959. +{
  10960. + ar71xx_flash_acquire();
  10961. + ar91xx_flash_write(map, d, ofs);
  10962. + ar71xx_flash_release();
  10963. +}
  10964. +
  10965. +static void ar91xx_flash_copy_from_lock(struct map_info *map, void *to,
  10966. + unsigned long from, ssize_t len)
  10967. +{
  10968. + ar71xx_flash_acquire();
  10969. + inline_map_copy_from(map, to, from, len);
  10970. + ar71xx_flash_release();
  10971. +}
  10972. +
  10973. +static void ar91xx_flash_copy_to_lock(struct map_info *map, unsigned long to,
  10974. + const void *from, ssize_t len)
  10975. +{
  10976. + ar71xx_flash_acquire();
  10977. + inline_map_copy_to(map, to, from, len);
  10978. + ar71xx_flash_release();
  10979. +}
  10980. +
  10981. +static int ar91xx_flash_remove(struct platform_device *pdev)
  10982. +{
  10983. + struct ar91xx_flash_platform_data *pdata;
  10984. + struct ar91xx_flash_info *info;
  10985. +
  10986. + info = platform_get_drvdata(pdev);
  10987. + if (info == NULL)
  10988. + return 0;
  10989. +
  10990. + platform_set_drvdata(pdev, NULL);
  10991. +
  10992. + if (info->mtd == NULL)
  10993. + return 0;
  10994. +
  10995. + pdata = pdev->dev.platform_data;
  10996. +#ifdef CONFIG_MTD_PARTITIONS
  10997. + if (info->nr_parts) {
  10998. + del_mtd_partitions(info->mtd);
  10999. + kfree(info->parts);
  11000. + } else if (pdata->nr_parts) {
  11001. + del_mtd_partitions(info->mtd);
  11002. + } else {
  11003. + del_mtd_device(info->mtd);
  11004. + }
  11005. +#else
  11006. + del_mtd_device(info->mtd);
  11007. +#endif
  11008. + map_destroy(info->mtd);
  11009. +
  11010. + return 0;
  11011. +}
  11012. +
  11013. +static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
  11014. +#ifdef CONFIG_MTD_PARTITIONS
  11015. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  11016. +#endif
  11017. +
  11018. +static int ar91xx_flash_probe(struct platform_device *pdev)
  11019. +{
  11020. + struct ar91xx_flash_platform_data *pdata;
  11021. + struct ar91xx_flash_info *info;
  11022. + struct resource *res;
  11023. + struct resource *region;
  11024. + const char **probe_type;
  11025. + int err = 0;
  11026. +
  11027. + pdata = pdev->dev.platform_data;
  11028. + if (pdata == NULL)
  11029. + return -EINVAL;
  11030. +
  11031. + info = devm_kzalloc(&pdev->dev, sizeof(struct ar91xx_flash_info),
  11032. + GFP_KERNEL);
  11033. + if (info == NULL) {
  11034. + err = -ENOMEM;
  11035. + goto err_out;
  11036. + }
  11037. +
  11038. + platform_set_drvdata(pdev, info);
  11039. +
  11040. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11041. + if (res == NULL) {
  11042. + err = -ENOENT;
  11043. + goto err_out;
  11044. + }
  11045. +
  11046. + dev_info(&pdev->dev, "%.8llx at %.8llx\n",
  11047. + (unsigned long long)(res->end - res->start + 1),
  11048. + (unsigned long long)res->start);
  11049. +
  11050. + region = devm_request_mem_region(&pdev->dev,
  11051. + res->start, res->end - res->start + 1,
  11052. + dev_name(&pdev->dev));
  11053. + if (region == NULL) {
  11054. + dev_err(&pdev->dev, "could not reserve memory region\n");
  11055. + err = -ENOMEM;
  11056. + goto err_out;
  11057. + }
  11058. +
  11059. + info->map.name = dev_name(&pdev->dev);
  11060. + info->map.phys = res->start;
  11061. + info->map.size = res->end - res->start + 1;
  11062. + info->map.bankwidth = pdata->width;
  11063. +
  11064. + info->map.virt = devm_ioremap(&pdev->dev, info->map.phys,
  11065. + info->map.size);
  11066. + if (info->map.virt == NULL) {
  11067. + dev_err(&pdev->dev, "failed to ioremap flash region\n");
  11068. + err = -EIO;
  11069. + goto err_out;
  11070. + }
  11071. +
  11072. + simple_map_init(&info->map);
  11073. + if (pdata->is_shared) {
  11074. + info->map.read = ar91xx_flash_read_lock;
  11075. + info->map.write = ar91xx_flash_write_lock;
  11076. + info->map.copy_from = ar91xx_flash_copy_from_lock;
  11077. + info->map.copy_to = ar91xx_flash_copy_to_lock;
  11078. + } else {
  11079. + info->map.read = ar91xx_flash_read;
  11080. + info->map.write = ar91xx_flash_write;
  11081. + }
  11082. +
  11083. + probe_type = rom_probe_types;
  11084. + for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
  11085. + info->mtd = do_map_probe(*probe_type, &info->map);
  11086. +
  11087. + if (info->mtd == NULL) {
  11088. + dev_err(&pdev->dev, "map_probe failed\n");
  11089. + err = -ENXIO;
  11090. + goto err_out;
  11091. + }
  11092. +
  11093. + info->mtd->owner = THIS_MODULE;
  11094. +
  11095. +#ifdef CONFIG_MTD_PARTITIONS
  11096. + if (pdata->nr_parts) {
  11097. + dev_info(&pdev->dev, "using static partition mapping\n");
  11098. + add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
  11099. + return 0;
  11100. + }
  11101. +
  11102. + err = parse_mtd_partitions(info->mtd, part_probe_types,
  11103. + &info->parts, 0);
  11104. + if (err > 0) {
  11105. + add_mtd_partitions(info->mtd, info->parts, err);
  11106. + return 0;
  11107. + }
  11108. +#endif
  11109. +
  11110. + add_mtd_device(info->mtd);
  11111. + return 0;
  11112. +
  11113. + err_out:
  11114. + ar91xx_flash_remove(pdev);
  11115. + return err;
  11116. +}
  11117. +
  11118. +#ifdef CONFIG_PM
  11119. +static int ar91xx_flash_suspend(struct platform_device *dev, pm_message_t state)
  11120. +{
  11121. + struct ar91xx_flash_info *info = platform_get_drvdata(dev);
  11122. + int ret = 0;
  11123. +
  11124. + if (info->mtd->suspend)
  11125. + ret = info->mtd->suspend(info->mtd);
  11126. +
  11127. + if (ret)
  11128. + goto fail;
  11129. +
  11130. + return 0;
  11131. +
  11132. + fail:
  11133. + if (info->mtd->suspend) {
  11134. + BUG_ON(!info->mtd->resume);
  11135. + info->mtd->resume(info->mtd);
  11136. + }
  11137. +
  11138. + return ret;
  11139. +}
  11140. +
  11141. +static int ar91xx_flash_resume(struct platform_device *pdev)
  11142. +{
  11143. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  11144. +
  11145. + if (info->mtd->resume)
  11146. + info->mtd->resume(info->mtd);
  11147. +
  11148. + return 0;
  11149. +}
  11150. +
  11151. +static void ar91xx_flash_shutdown(struct platform_device *pdev)
  11152. +{
  11153. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  11154. +
  11155. + if (info->mtd->suspend && info->mtd->resume)
  11156. + if (info->mtd->suspend(info->mtd) == 0)
  11157. + info->mtd->resume(info->mtd);
  11158. +}
  11159. +#else
  11160. +#define ar91xx_flash_suspend NULL
  11161. +#define ar91xx_flash_resume NULL
  11162. +#define ar91xx_flash_shutdown NULL
  11163. +#endif
  11164. +
  11165. +static struct platform_driver ar91xx_flash_driver = {
  11166. + .probe = ar91xx_flash_probe,
  11167. + .remove = ar91xx_flash_remove,
  11168. + .suspend = ar91xx_flash_suspend,
  11169. + .resume = ar91xx_flash_resume,
  11170. + .shutdown = ar91xx_flash_shutdown,
  11171. + .driver = {
  11172. + .name = DRV_NAME,
  11173. + .owner = THIS_MODULE,
  11174. + },
  11175. +};
  11176. +
  11177. +static int __init ar91xx_flash_init(void)
  11178. +{
  11179. + return platform_driver_register(&ar91xx_flash_driver);
  11180. +}
  11181. +
  11182. +static void __exit ar91xx_flash_exit(void)
  11183. +{
  11184. + platform_driver_unregister(&ar91xx_flash_driver);
  11185. +}
  11186. +
  11187. +module_init(ar91xx_flash_init);
  11188. +module_exit(ar91xx_flash_exit);
  11189. +
  11190. +MODULE_LICENSE("GPL v2");
  11191. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  11192. +MODULE_DESCRIPTION("Parallel flash driver for the Atheros AR91xx SoC");
  11193. +MODULE_ALIAS("platform:" DRV_NAME);
  11194. diff -Nur linux-2.6.33.3.orig/drivers/mtd/maps/Kconfig linux-2.6.33.3/drivers/mtd/maps/Kconfig
  11195. --- linux-2.6.33.3.orig/drivers/mtd/maps/Kconfig 2010-04-26 16:48:30.000000000 +0200
  11196. +++ linux-2.6.33.3/drivers/mtd/maps/Kconfig 2010-05-17 16:28:48.419315145 +0200
  11197. @@ -257,6 +257,13 @@
  11198. help
  11199. Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
  11200. +config MTD_AR91XX_FLASH
  11201. + tristate "Atheros AR91xx parallel flash support"
  11202. + depends on ATHEROS_AR71XX
  11203. + select MTD_COMPLEX_MAPPINGS
  11204. + help
  11205. + Parallel flash driver for the Atheros AR91xx based boards.
  11206. +
  11207. config MTD_DILNETPC
  11208. tristate "CFI Flash device mapped on DIL/Net PC"
  11209. depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
  11210. diff -Nur linux-2.6.33.3.orig/drivers/mtd/maps/Makefile linux-2.6.33.3/drivers/mtd/maps/Makefile
  11211. --- linux-2.6.33.3.orig/drivers/mtd/maps/Makefile 2010-04-26 16:48:30.000000000 +0200
  11212. +++ linux-2.6.33.3/drivers/mtd/maps/Makefile 2010-05-17 16:28:48.419315145 +0200
  11213. @@ -41,6 +41,7 @@
  11214. obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
  11215. obj-$(CONFIG_MTD_PCI) += pci.o
  11216. obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o
  11217. +obj-$(CONFIG_MTD_AR91XX_FLASH) += ar91xx_flash.o
  11218. obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
  11219. obj-$(CONFIG_MTD_EDB7312) += edb7312.o
  11220. obj-$(CONFIG_MTD_IMPA7) += impa7.o
  11221. diff -Nur linux-2.6.33.3.orig/drivers/mtd/nand/Kconfig linux-2.6.33.3/drivers/mtd/nand/Kconfig
  11222. --- linux-2.6.33.3.orig/drivers/mtd/nand/Kconfig 2010-04-26 16:48:30.000000000 +0200
  11223. +++ linux-2.6.33.3/drivers/mtd/nand/Kconfig 2010-05-17 16:29:54.255116284 +0200
  11224. @@ -488,4 +488,8 @@
  11225. This enables the driver for the NAND Flash on evaluation board based
  11226. on w90p910.
  11227. +config MTD_NAND_RB4XX
  11228. + tristate "NAND flash driver for RouterBoard 4xx series"
  11229. + depends on MTD_NAND && AR71XX_MACH_RB4XX
  11230. +
  11231. endif # MTD_NAND
  11232. diff -Nur linux-2.6.33.3.orig/drivers/mtd/nand/Makefile linux-2.6.33.3/drivers/mtd/nand/Makefile
  11233. --- linux-2.6.33.3.orig/drivers/mtd/nand/Makefile 2010-04-26 16:48:30.000000000 +0200
  11234. +++ linux-2.6.33.3/drivers/mtd/nand/Makefile 2010-05-17 16:29:54.255116284 +0200
  11235. @@ -30,6 +30,7 @@
  11236. obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
  11237. obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o
  11238. obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
  11239. +obj-$(CONFIG_MTD_NAND_RB4XX) += rb4xx_nand.o
  11240. obj-$(CONFIG_MTD_ALAUDA) += alauda.o
  11241. obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
  11242. obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
  11243. diff -Nur linux-2.6.33.3.orig/drivers/mtd/nand/rb4xx_nand.c linux-2.6.33.3/drivers/mtd/nand/rb4xx_nand.c
  11244. --- linux-2.6.33.3.orig/drivers/mtd/nand/rb4xx_nand.c 1970-01-01 01:00:00.000000000 +0100
  11245. +++ linux-2.6.33.3/drivers/mtd/nand/rb4xx_nand.c 2010-05-19 18:58:03.499116406 +0200
  11246. @@ -0,0 +1,512 @@
  11247. +/*
  11248. + * NAND flash driver for the MikroTik RouterBoard 4xx series
  11249. + *
  11250. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  11251. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  11252. + *
  11253. + * This file was based on the driver for Linux 2.6.22 published by
  11254. + * MikroTik for their RouterBoard 4xx series devices.
  11255. + *
  11256. + * This program is free software; you can redistribute it and/or modify it
  11257. + * under the terms of the GNU General Public License version 2 as published
  11258. + * by the Free Software Foundation.
  11259. + */
  11260. +
  11261. +#include <linux/init.h>
  11262. +#include <linux/mtd/nand.h>
  11263. +#include <linux/mtd/mtd.h>
  11264. +#include <linux/mtd/partitions.h>
  11265. +#include <linux/platform_device.h>
  11266. +#include <linux/delay.h>
  11267. +#include <linux/io.h>
  11268. +#include <linux/gpio.h>
  11269. +
  11270. +#include <asm/mach-ar71xx/ar71xx.h>
  11271. +
  11272. +#define DRV_NAME "rb4xx-nand"
  11273. +#define DRV_VERSION "0.1.10"
  11274. +#define DRV_DESC "NAND flash driver for RouterBoard 4xx series"
  11275. +
  11276. +#define USE_FAST_READ 1
  11277. +#define USE_FAST_WRITE 1
  11278. +#undef RB4XX_NAND_DEBUG
  11279. +
  11280. +#ifdef RB4XX_NAND_DEBUG
  11281. +#define DBG(fmt, arg...) printk(KERN_DEBUG DRV_NAME ": " fmt, ## arg)
  11282. +#else
  11283. +#define DBG(fmt, arg...) do {} while (0)
  11284. +#endif
  11285. +
  11286. +#define RB4XX_NAND_GPIO_RDY 5
  11287. +#define RB4XX_FLASH_HZ 33333334
  11288. +#define RB4XX_NAND_HZ 33333334
  11289. +
  11290. +#define SPI_CTRL_FASTEST 0x40
  11291. +#define SPI_CTRL_SAFE 0x43 /* 25 MHz for AHB 200 MHz */
  11292. +#define SBIT_IOC_BASE SPI_IOC_CS1
  11293. +#define SBIT_IOC_DO_SHIFT 0
  11294. +#define SBIT_IOC_DO (1u << SBIT_IOC_DO_SHIFT)
  11295. +#define SBIT_IOC_DO2_SHIFT 18
  11296. +#define SBIT_IOC_DO2 (1u << SBIT_IOC_DO2_SHIFT)
  11297. +
  11298. +#define CPLD_CMD_WRITE_MULT 0x08 /* send cmd, n x send data, read data */
  11299. +#define CPLD_CMD_WRITE_CFG 0x09 /* send cmd, n x send cfg */
  11300. +#define CPLD_CMD_READ_MULT 0x0a /* send cmd, send idle, n x read data */
  11301. +#define CPLD_CMD_READ_FAST 0x0b /* send cmd, 4 x idle, n x read data */
  11302. +
  11303. +#define CFG_BIT_nCE 0x80
  11304. +#define CFG_BIT_CLE 0x40
  11305. +#define CFG_BIT_ALE 0x20
  11306. +#define CFG_BIT_FAN 0x10
  11307. +#define CFG_BIT_nLED4 0x08
  11308. +#define CFG_BIT_nLED3 0x04
  11309. +#define CFG_BIT_nLED2 0x02
  11310. +#define CFG_BIT_nLED1 0x01
  11311. +
  11312. +#define CFG_BIT_nLEDS \
  11313. + (CFG_BIT_nLED1 | CFG_BIT_nLED2 | CFG_BIT_nLED3 | CFG_BIT_nLED4)
  11314. +
  11315. +struct rb4xx_nand_info {
  11316. + struct nand_chip chip;
  11317. + struct mtd_info mtd;
  11318. +};
  11319. +
  11320. +/*
  11321. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  11322. + * will not be able to find the kernel that we load.
  11323. + */
  11324. +static struct nand_ecclayout rb4xx_nand_ecclayout = {
  11325. + .eccbytes = 6,
  11326. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  11327. + .oobavail = 9,
  11328. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  11329. +};
  11330. +
  11331. +static struct mtd_partition rb4xx_nand_partitions[] = {
  11332. + {
  11333. + .name = "booter",
  11334. + .offset = 0,
  11335. + .size = (256 * 1024),
  11336. + .mask_flags = MTD_WRITEABLE,
  11337. + },
  11338. + {
  11339. + .name = "kernel",
  11340. + .offset = (256 * 1024),
  11341. + .size = (4 * 1024 * 1024) - (256 * 1024),
  11342. + },
  11343. + {
  11344. + .name = "rootfs",
  11345. + .offset = MTDPART_OFS_NXTBLK,
  11346. + .size = (1024*1024*64) - (1024*256) - (4 * 1024 * 1024)
  11347. + },
  11348. + {
  11349. + .name = "cfgfs",
  11350. + .offset = (1024*1024*64) - (1024*256),
  11351. + .size = (1024*256),
  11352. + },
  11353. +};
  11354. +
  11355. +#if USE_FAST_READ
  11356. +#define SPI_NDATA_BASE 0x00800000
  11357. +static unsigned spi_ctrl_fread = SPI_CTRL_SAFE;
  11358. +static unsigned spi_ctrl_flash = SPI_CTRL_SAFE;
  11359. +extern unsigned mips_hpt_frequency;
  11360. +#endif
  11361. +
  11362. +static inline unsigned rb4xx_spi_rreg(unsigned r)
  11363. +{
  11364. + return __raw_readl((void * __iomem)(KSEG1ADDR(AR71XX_SPI_BASE) + r));
  11365. +}
  11366. +
  11367. +static inline void rb4xx_spi_wreg(unsigned r, unsigned v)
  11368. +{
  11369. + __raw_writel(v, (void * __iomem)(KSEG1ADDR(AR71XX_SPI_BASE) + r));
  11370. +}
  11371. +
  11372. +static inline void do_spi_clk(int bit)
  11373. +{
  11374. + unsigned bval = SBIT_IOC_BASE | (bit & 1);
  11375. +
  11376. + rb4xx_spi_wreg(SPI_REG_IOC, bval);
  11377. + rb4xx_spi_wreg(SPI_REG_IOC, bval | SPI_IOC_CLK);
  11378. +}
  11379. +
  11380. +static void do_spi_byte(uint8_t byte)
  11381. +{
  11382. + do_spi_clk(byte >> 7);
  11383. + do_spi_clk(byte >> 6);
  11384. + do_spi_clk(byte >> 5);
  11385. + do_spi_clk(byte >> 4);
  11386. + do_spi_clk(byte >> 3);
  11387. + do_spi_clk(byte >> 2);
  11388. + do_spi_clk(byte >> 1);
  11389. + do_spi_clk(byte);
  11390. +
  11391. + DBG("spi_byte sent 0x%02x got 0x%x\n",
  11392. + byte, rb4xx_spi_rreg(SPI_REG_RDS));
  11393. +}
  11394. +
  11395. +#if USE_FAST_WRITE
  11396. +static inline void do_spi_clk_fast(int bit1, int bit2)
  11397. +{
  11398. + unsigned bval = (SBIT_IOC_BASE |
  11399. + ((bit1 << SBIT_IOC_DO_SHIFT) & SBIT_IOC_DO) |
  11400. + ((bit2 << SBIT_IOC_DO2_SHIFT) & SBIT_IOC_DO2));
  11401. +
  11402. + rb4xx_spi_wreg(SPI_REG_IOC, bval);
  11403. + rb4xx_spi_wreg(SPI_REG_IOC, bval | SPI_IOC_CLK);
  11404. +}
  11405. +
  11406. +static inline void do_spi_byte_fast(uint8_t byte)
  11407. +{
  11408. + do_spi_clk_fast(byte >> 7, byte >> 6);
  11409. + do_spi_clk_fast(byte >> 5, byte >> 4);
  11410. + do_spi_clk_fast(byte >> 3, byte >> 2);
  11411. + do_spi_clk_fast(byte >> 1, byte >> 0);
  11412. +
  11413. + DBG("spi_byte_fast sent 0x%02x got 0x%x\n",
  11414. + byte, rb4xx_spi_rreg(SPI_REG_RDS));
  11415. +}
  11416. +#else
  11417. +static inline void do_spi_byte_fast(uint8_t byte)
  11418. +{
  11419. + do_spi_byte(byte);
  11420. +}
  11421. +#endif /* USE_FAST_WRITE */
  11422. +
  11423. +static int do_spi_cmd(unsigned cmd, unsigned sendCnt, const uint8_t *sendData,
  11424. + unsigned recvCnt, uint8_t *recvData,
  11425. + const uint8_t *verifyData, int fastWrite)
  11426. +{
  11427. + unsigned i;
  11428. +
  11429. + DBG("SPI cmd 0x%x send %u recv %u\n", cmd, sendCnt, recvCnt);
  11430. +
  11431. + rb4xx_spi_wreg(SPI_REG_FS, SPI_FS_GPIO);
  11432. + rb4xx_spi_wreg(SPI_REG_CTRL, SPI_CTRL_FASTEST);
  11433. +
  11434. + do_spi_byte(cmd);
  11435. +#if 0
  11436. + if (cmd == CPLD_CMD_READ_FAST) {
  11437. + do_spi_byte(0x80);
  11438. + do_spi_byte(0);
  11439. + do_spi_byte(0);
  11440. + }
  11441. +#endif
  11442. + for (i = 0; i < sendCnt; ++i) {
  11443. + if (fastWrite)
  11444. + do_spi_byte_fast(sendData[i]);
  11445. + else
  11446. + do_spi_byte(sendData[i]);
  11447. + }
  11448. +
  11449. + for (i = 0; i < recvCnt; ++i) {
  11450. + if (fastWrite)
  11451. + do_spi_byte_fast(0);
  11452. + else
  11453. + do_spi_byte(0);
  11454. +
  11455. + if (recvData) {
  11456. + recvData[i] = rb4xx_spi_rreg(SPI_REG_RDS) & 0xff;
  11457. + } else if (verifyData) {
  11458. + if (verifyData[i] != (rb4xx_spi_rreg(SPI_REG_RDS)
  11459. + & 0xff))
  11460. + break;
  11461. + }
  11462. + }
  11463. +
  11464. + rb4xx_spi_wreg(SPI_REG_IOC, SBIT_IOC_BASE | SPI_IOC_CS0);
  11465. + rb4xx_spi_wreg(SPI_REG_CTRL, spi_ctrl_flash);
  11466. + rb4xx_spi_wreg(SPI_REG_FS, 0);
  11467. +
  11468. + return i == recvCnt;
  11469. +}
  11470. +
  11471. +static int got_write = 1;
  11472. +
  11473. +static void rb4xx_nand_write_data(const uint8_t *byte, unsigned cnt)
  11474. +{
  11475. + do_spi_cmd(CPLD_CMD_WRITE_MULT, cnt, byte, 1, NULL, NULL, 1);
  11476. + got_write = 1;
  11477. +}
  11478. +
  11479. +static void rb4xx_nand_write_byte(uint8_t byte)
  11480. +{
  11481. + rb4xx_nand_write_data(&byte, 1);
  11482. +}
  11483. +
  11484. +#if USE_FAST_READ
  11485. +static uint8_t *rb4xx_nand_read_getaddr(unsigned cnt)
  11486. +{
  11487. + static unsigned nboffset = 0x100000;
  11488. + unsigned addr;
  11489. +
  11490. + if (got_write) {
  11491. + nboffset = (nboffset + 31) & ~31;
  11492. + if (nboffset >= 0x100000) /* 1MB */
  11493. + nboffset = 0;
  11494. +
  11495. + got_write = 0;
  11496. + rb4xx_spi_wreg(SPI_REG_FS, SPI_FS_GPIO);
  11497. + rb4xx_spi_wreg(SPI_REG_CTRL, spi_ctrl_fread);
  11498. + rb4xx_spi_wreg(SPI_REG_FS, 0);
  11499. + }
  11500. +
  11501. + addr = KSEG1ADDR(AR71XX_SPI_BASE + SPI_NDATA_BASE) + nboffset;
  11502. + DBG("rb4xx_nand_read_getaddr 0x%x cnt 0x%x\n", addr, cnt);
  11503. +
  11504. + nboffset += cnt;
  11505. + return (uint8_t *)addr;
  11506. +}
  11507. +
  11508. +static void rb4xx_nand_read_data(uint8_t *buf, unsigned cnt)
  11509. +{
  11510. + unsigned size32 = cnt & ~31;
  11511. + unsigned remain = cnt & 31;
  11512. +
  11513. + if (size32) {
  11514. + uint8_t *addr = rb4xx_nand_read_getaddr(size32);
  11515. + memcpy(buf, (void *)addr, size32);
  11516. + }
  11517. +
  11518. + if (remain) {
  11519. + do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, remain,
  11520. + buf + size32, NULL, 0);
  11521. + }
  11522. +}
  11523. +
  11524. +static int rb4xx_nand_verify_data(const uint8_t *buf, unsigned cnt)
  11525. +{
  11526. + unsigned size32 = cnt & ~31;
  11527. + unsigned remain = cnt & 31;
  11528. +
  11529. + if (size32) {
  11530. + uint8_t *addr = rb4xx_nand_read_getaddr(size32);
  11531. + if (memcmp(buf, (void *)addr, size32) != 0)
  11532. + return 0;
  11533. + }
  11534. +
  11535. + if (remain) {
  11536. + return do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, remain,
  11537. + NULL, buf + size32, 0);
  11538. + }
  11539. + return 1;
  11540. +}
  11541. +#else /* USE_FAST_READ */
  11542. +static void rb4xx_nand_read_data(uint8_t *buf, unsigned cnt)
  11543. +{
  11544. + do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, cnt, buf, NULL, 0);
  11545. +}
  11546. +
  11547. +static int rb4xx_nand_verify_data(const uint8_t *buf, unsigned cnt)
  11548. +{
  11549. + return do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, cnt, NULL, buf, 0);
  11550. +}
  11551. +#endif /* USE_FAST_READ */
  11552. +
  11553. +static void rb4xx_nand_write_cfg(uint8_t byte)
  11554. +{
  11555. + do_spi_cmd(CPLD_CMD_WRITE_CFG, 1, &byte, 0, NULL, NULL, 0);
  11556. + got_write = 1;
  11557. +}
  11558. +
  11559. +static int rb4xx_nand_dev_ready(struct mtd_info *mtd)
  11560. +{
  11561. + return gpio_get_value(RB4XX_NAND_GPIO_RDY);
  11562. +}
  11563. +
  11564. +static void rb4xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  11565. + unsigned int ctrl)
  11566. +{
  11567. + if (ctrl & NAND_CTRL_CHANGE) {
  11568. + uint8_t cfg = CFG_BIT_nLEDS;
  11569. +
  11570. + cfg |= (ctrl & NAND_CLE) ? CFG_BIT_CLE : 0;
  11571. + cfg |= (ctrl & NAND_ALE) ? CFG_BIT_ALE : 0;
  11572. + cfg |= (ctrl & NAND_NCE) ? 0 : CFG_BIT_nCE;
  11573. +
  11574. + rb4xx_nand_write_cfg(cfg);
  11575. + }
  11576. +
  11577. + if (cmd != NAND_CMD_NONE)
  11578. + rb4xx_nand_write_byte(cmd);
  11579. +}
  11580. +
  11581. +static uint8_t rb4xx_nand_read_byte(struct mtd_info *mtd)
  11582. +{
  11583. + uint8_t byte = 0;
  11584. +
  11585. + rb4xx_nand_read_data(&byte, 1);
  11586. + return byte;
  11587. +}
  11588. +
  11589. +static void rb4xx_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf,
  11590. + int len)
  11591. +{
  11592. + rb4xx_nand_write_data(buf, len);
  11593. +}
  11594. +
  11595. +static void rb4xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf,
  11596. + int len)
  11597. +{
  11598. + rb4xx_nand_read_data(buf, len);
  11599. +}
  11600. +
  11601. +static int rb4xx_nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf,
  11602. + int len)
  11603. +{
  11604. + if (!rb4xx_nand_verify_data(buf, len))
  11605. + return -EFAULT;
  11606. +
  11607. + return 0;
  11608. +}
  11609. +
  11610. +static unsigned get_spi_ctrl(unsigned hz_max, const char *name)
  11611. +{
  11612. + unsigned div;
  11613. +
  11614. + div = (ar71xx_ahb_freq - 1) / (2 * hz_max);
  11615. + /*
  11616. + * CPU has a bug at (div == 0) - first bit read is random
  11617. + */
  11618. + if (div == 0)
  11619. + ++div;
  11620. +
  11621. + if (name) {
  11622. + unsigned ahb_khz = (ar71xx_ahb_freq + 500) / 1000;
  11623. + unsigned div_real = 2 * (div + 1);
  11624. + printk(KERN_INFO "%s SPI clock %u kHz (AHB %u kHz / %u)\n",
  11625. + name,
  11626. + ahb_khz / div_real,
  11627. + ahb_khz, div_real);
  11628. + }
  11629. +
  11630. + return SPI_CTRL_FASTEST + div;
  11631. +}
  11632. +
  11633. +static int __init rb4xx_nand_probe(struct platform_device *pdev)
  11634. +{
  11635. + struct rb4xx_nand_info *info;
  11636. + int ret;
  11637. +
  11638. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  11639. +
  11640. + ret = gpio_request(RB4XX_NAND_GPIO_RDY, "NAND RDY");
  11641. + if (ret) {
  11642. + printk(KERN_ERR "rb4xx-nand: gpio request failed\n");
  11643. + return ret;
  11644. + }
  11645. +
  11646. + ret = gpio_direction_input(RB4XX_NAND_GPIO_RDY);
  11647. + if (ret) {
  11648. + printk(KERN_ERR "rb4xx-nand: unable to set input mode "
  11649. + "on gpio%d\n", RB4XX_NAND_GPIO_RDY);
  11650. + goto err_free_gpio;
  11651. + }
  11652. +
  11653. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  11654. + if (!info) {
  11655. + printk(KERN_ERR "rb4xx-nand: no memory for private data\n");
  11656. + ret = -ENOMEM;
  11657. + goto err_free_gpio;
  11658. + }
  11659. +
  11660. +#if USE_FAST_READ
  11661. + spi_ctrl_fread = get_spi_ctrl(RB4XX_NAND_HZ, "NAND");
  11662. +#endif
  11663. + spi_ctrl_flash = get_spi_ctrl(RB4XX_FLASH_HZ, "FLASH");
  11664. +
  11665. + rb4xx_nand_write_cfg(CFG_BIT_nLEDS | CFG_BIT_nCE);
  11666. +
  11667. + info->chip.priv = &info;
  11668. + info->mtd.priv = &info->chip;
  11669. + info->mtd.owner = THIS_MODULE;
  11670. +
  11671. + info->chip.cmd_ctrl = rb4xx_nand_cmd_ctrl;
  11672. + info->chip.dev_ready = rb4xx_nand_dev_ready;
  11673. + info->chip.read_byte = rb4xx_nand_read_byte;
  11674. + info->chip.write_buf = rb4xx_nand_write_buf;
  11675. + info->chip.read_buf = rb4xx_nand_read_buf;
  11676. + info->chip.verify_buf = rb4xx_nand_verify_buf;
  11677. +
  11678. + info->chip.chip_delay = 25;
  11679. + info->chip.ecc.mode = NAND_ECC_SOFT;
  11680. + info->chip.options |= NAND_NO_AUTOINCR;
  11681. +
  11682. + platform_set_drvdata(pdev, info);
  11683. +
  11684. + ret = nand_scan_ident(&info->mtd, 1);
  11685. + if (ret) {
  11686. + ret = -ENXIO;
  11687. + goto err_free_info;
  11688. + }
  11689. +
  11690. + if (info->mtd.writesize == 512)
  11691. + info->chip.ecc.layout = &rb4xx_nand_ecclayout;
  11692. +
  11693. + ret = nand_scan_tail(&info->mtd);
  11694. + if (ret) {
  11695. + return -ENXIO;
  11696. + goto err_set_drvdata;
  11697. + }
  11698. +
  11699. +#ifdef CONFIG_MTD_PARTITIONS
  11700. + ret = add_mtd_partitions(&info->mtd, rb4xx_nand_partitions,
  11701. + ARRAY_SIZE(rb4xx_nand_partitions));
  11702. +#else
  11703. + ret = add_mtd_device(&info->mtd);
  11704. +#endif
  11705. + if (ret)
  11706. + goto err_release_nand;
  11707. +
  11708. + return 0;
  11709. +
  11710. +err_release_nand:
  11711. + nand_release(&info->mtd);
  11712. +err_set_drvdata:
  11713. + platform_set_drvdata(pdev, NULL);
  11714. +err_free_info:
  11715. + kfree(info);
  11716. +err_free_gpio:
  11717. + gpio_free(RB4XX_NAND_GPIO_RDY);
  11718. + return ret;
  11719. +}
  11720. +
  11721. +static int __devexit rb4xx_nand_remove(struct platform_device *pdev)
  11722. +{
  11723. + struct rb4xx_nand_info *info = platform_get_drvdata(pdev);
  11724. +
  11725. + nand_release(&info->mtd);
  11726. + platform_set_drvdata(pdev, NULL);
  11727. + kfree(info);
  11728. +
  11729. + return 0;
  11730. +}
  11731. +
  11732. +static struct platform_driver rb4xx_nand_driver = {
  11733. + .probe = rb4xx_nand_probe,
  11734. + .remove = __devexit_p(rb4xx_nand_remove),
  11735. + .driver = {
  11736. + .name = DRV_NAME,
  11737. + .owner = THIS_MODULE,
  11738. + },
  11739. +};
  11740. +
  11741. +static int __init rb4xx_nand_init(void)
  11742. +{
  11743. + return platform_driver_register(&rb4xx_nand_driver);
  11744. +}
  11745. +
  11746. +static void __exit rb4xx_nand_exit(void)
  11747. +{
  11748. + platform_driver_unregister(&rb4xx_nand_driver);
  11749. +}
  11750. +
  11751. +module_init(rb4xx_nand_init);
  11752. +module_exit(rb4xx_nand_exit);
  11753. +
  11754. +MODULE_DESCRIPTION(DRV_DESC);
  11755. +MODULE_VERSION(DRV_VERSION);
  11756. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  11757. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  11758. +MODULE_LICENSE("GPL v2");
  11759. diff -Nur linux-2.6.33.3.orig/drivers/mtd/nand/rb750_nand.c linux-2.6.33.3/drivers/mtd/nand/rb750_nand.c
  11760. --- linux-2.6.33.3.orig/drivers/mtd/nand/rb750_nand.c 1970-01-01 01:00:00.000000000 +0100
  11761. +++ linux-2.6.33.3/drivers/mtd/nand/rb750_nand.c 2010-03-12 19:31:47.026043474 +0100
  11762. @@ -0,0 +1,360 @@
  11763. +/*
  11764. + * NAND flash driver for the MikroTik RouterBOARD 750
  11765. + *
  11766. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  11767. + *
  11768. + * This program is free software; you can redistribute it and/or modify it
  11769. + * under the terms of the GNU General Public License version 2 as published
  11770. + * by the Free Software Foundation.
  11771. + */
  11772. +
  11773. +#include <linux/init.h>
  11774. +#include <linux/mtd/nand.h>
  11775. +#include <linux/mtd/mtd.h>
  11776. +#include <linux/mtd/partitions.h>
  11777. +#include <linux/platform_device.h>
  11778. +#include <linux/io.h>
  11779. +
  11780. +#include <asm/mach-ar71xx/ar71xx.h>
  11781. +#include <asm/mach-ar71xx/mach-rb750.h>
  11782. +
  11783. +#define DRV_NAME "rb750-nand"
  11784. +#define DRV_VERSION "0.1.0"
  11785. +#define DRV_DESC "NAND flash driver for the RouterBOARD 750"
  11786. +
  11787. +#define RB750_NAND_IO0 BIT(RB750_GPIO_NAND_IO0)
  11788. +#define RB750_NAND_ALE BIT(RB750_GPIO_NAND_ALE)
  11789. +#define RB750_NAND_CLE BIT(RB750_GPIO_NAND_CLE)
  11790. +#define RB750_NAND_NRE BIT(RB750_GPIO_NAND_NRE)
  11791. +#define RB750_NAND_NWE BIT(RB750_GPIO_NAND_NWE)
  11792. +#define RB750_NAND_RDY BIT(RB750_GPIO_NAND_RDY)
  11793. +#define RB750_NAND_NCE BIT(RB750_GPIO_NAND_NCE)
  11794. +
  11795. +#define RB750_NAND_DATA_SHIFT 1
  11796. +#define RB750_NAND_DATA_BITS (0xff << RB750_NAND_DATA_SHIFT)
  11797. +#define RB750_NAND_INPUT_BITS (RB750_NAND_DATA_BITS | RB750_NAND_RDY)
  11798. +#define RB750_NAND_OUTPUT_BITS (RB750_NAND_ALE | RB750_NAND_CLE | \
  11799. + RB750_NAND_NRE | RB750_NAND_NWE | \
  11800. + RB750_NAND_NCE)
  11801. +
  11802. +struct rb750_nand_info {
  11803. + struct nand_chip chip;
  11804. + struct mtd_info mtd;
  11805. +};
  11806. +
  11807. +/*
  11808. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  11809. + * will not be able to find the kernel that we load.
  11810. + */
  11811. +static struct nand_ecclayout rb750_nand_ecclayout = {
  11812. + .eccbytes = 6,
  11813. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  11814. + .oobavail = 9,
  11815. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  11816. +};
  11817. +
  11818. +static struct mtd_partition rb750_nand_partitions[] = {
  11819. + {
  11820. + .name = "booter",
  11821. + .offset = 0,
  11822. + .size = (256 * 1024),
  11823. + .mask_flags = MTD_WRITEABLE,
  11824. + }, {
  11825. + .name = "kernel",
  11826. + .offset = (256 * 1024),
  11827. + .size = (4 * 1024 * 1024) - (256 * 1024),
  11828. + }, {
  11829. + .name = "rootfs",
  11830. + .offset = MTDPART_OFS_NXTBLK,
  11831. + .size = MTDPART_SIZ_FULL,
  11832. + },
  11833. +};
  11834. +
  11835. +static void rb750_nand_write(const u8 *buf, unsigned len)
  11836. +{
  11837. + void __iomem *base = ar71xx_gpio_base;
  11838. + u32 out;
  11839. + unsigned i;
  11840. +
  11841. + /* set data lines to output mode */
  11842. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_DATA_BITS,
  11843. + base + GPIO_REG_OE);
  11844. +
  11845. + out = __raw_readl(base + GPIO_REG_OUT);
  11846. + out &= ~(RB750_NAND_DATA_BITS | RB750_NAND_NWE);
  11847. + for (i = 0; i != len; i++) {
  11848. + u32 data;
  11849. +
  11850. + data = buf[i];
  11851. + data <<= RB750_NAND_DATA_SHIFT;
  11852. + data |= out;
  11853. + __raw_writel(data, base + GPIO_REG_OUT);
  11854. +
  11855. + __raw_writel(data | RB750_NAND_NWE, base + GPIO_REG_OUT);
  11856. + /* flush write */
  11857. + __raw_readl(base + GPIO_REG_OUT);
  11858. + }
  11859. +
  11860. + /* set data lines to input mode */
  11861. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~RB750_NAND_DATA_BITS,
  11862. + base + GPIO_REG_OE);
  11863. + /* flush write */
  11864. + __raw_readl(base + GPIO_REG_OE);
  11865. +}
  11866. +
  11867. +static int rb750_nand_read_verify(u8 *read_buf, unsigned len,
  11868. + const u8 *verify_buf)
  11869. +{
  11870. + void __iomem *base = ar71xx_gpio_base;
  11871. + unsigned i;
  11872. +
  11873. + for (i = 0; i < len; i++) {
  11874. + u8 data;
  11875. +
  11876. + /* activate RE line */
  11877. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_CLEAR);
  11878. + /* flush write */
  11879. + __raw_readl(base + GPIO_REG_CLEAR);
  11880. +
  11881. + /* read input lines */
  11882. + data = __raw_readl(base + GPIO_REG_IN) >> RB750_NAND_DATA_SHIFT;
  11883. +
  11884. + /* deactivate RE line */
  11885. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_SET);
  11886. +
  11887. + if (read_buf)
  11888. + read_buf[i] = data;
  11889. + else if (verify_buf && verify_buf[i] != data)
  11890. + return -EFAULT;
  11891. + }
  11892. +
  11893. + return 0;
  11894. +}
  11895. +
  11896. +static void rb750_nand_select_chip(struct mtd_info *mtd, int chip)
  11897. +{
  11898. + void __iomem *base = ar71xx_gpio_base;
  11899. + u32 func;
  11900. +
  11901. + func = __raw_readl(base + GPIO_REG_FUNC);
  11902. + if (chip >= 0) {
  11903. + /* disable latch */
  11904. + rb750_latch_change(RB750_LVC573_LE, 0);
  11905. +
  11906. + /* disable alternate functions */
  11907. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  11908. + AR724X_GPIO_FUNC_SPI_EN);
  11909. +
  11910. + /* set input mode for data lines */
  11911. + __raw_writel(__raw_readl(base + GPIO_REG_OE) &
  11912. + ~RB750_NAND_INPUT_BITS,
  11913. + base + GPIO_REG_OE);
  11914. +
  11915. + /* deactivate RE and WE lines */
  11916. + __raw_writel(RB750_NAND_NRE | RB750_NAND_NWE,
  11917. + base + GPIO_REG_SET);
  11918. + /* flush write */
  11919. + (void) __raw_readl(base + GPIO_REG_SET);
  11920. +
  11921. + /* activate CE line */
  11922. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_CLEAR);
  11923. + } else {
  11924. + /* deactivate CE line */
  11925. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_SET);
  11926. + /* flush write */
  11927. + (void) __raw_readl(base + GPIO_REG_SET);
  11928. +
  11929. + __raw_writel(__raw_readl(base + GPIO_REG_OE) |
  11930. + RB750_NAND_IO0 | RB750_NAND_RDY,
  11931. + base + GPIO_REG_OE);
  11932. +
  11933. + /* restore alternate functions */
  11934. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
  11935. + AR724X_GPIO_FUNC_JTAG_DISABLE);
  11936. +
  11937. + /* enable latch */
  11938. + rb750_latch_change(0, RB750_LVC573_LE);
  11939. + }
  11940. +}
  11941. +
  11942. +static int rb750_nand_dev_ready(struct mtd_info *mtd)
  11943. +{
  11944. + void __iomem *base = ar71xx_gpio_base;
  11945. +
  11946. + return !!(__raw_readl(base + GPIO_REG_IN) & RB750_NAND_RDY);
  11947. +}
  11948. +
  11949. +static void rb750_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  11950. + unsigned int ctrl)
  11951. +{
  11952. + if (ctrl & NAND_CTRL_CHANGE) {
  11953. + void __iomem *base = ar71xx_gpio_base;
  11954. + u32 t;
  11955. +
  11956. + t = __raw_readl(base + GPIO_REG_OUT);
  11957. +
  11958. + t &= ~(RB750_NAND_CLE | RB750_NAND_ALE);
  11959. + t |= (ctrl & NAND_CLE) ? RB750_NAND_CLE : 0;
  11960. + t |= (ctrl & NAND_ALE) ? RB750_NAND_ALE : 0;
  11961. +
  11962. + __raw_writel(t, base + GPIO_REG_OUT);
  11963. + /* flush write */
  11964. + __raw_readl(base + GPIO_REG_OUT);
  11965. + }
  11966. +
  11967. + if (cmd != NAND_CMD_NONE) {
  11968. + u8 t = cmd;
  11969. + rb750_nand_write(&t, 1);
  11970. + }
  11971. +}
  11972. +
  11973. +static u8 rb750_nand_read_byte(struct mtd_info *mtd)
  11974. +{
  11975. + u8 data = 0;
  11976. + rb750_nand_read_verify(&data, 1, NULL);
  11977. + return data;
  11978. +}
  11979. +
  11980. +static void rb750_nand_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  11981. +{
  11982. + rb750_nand_read_verify(buf, len, NULL);
  11983. +}
  11984. +
  11985. +static void rb750_nand_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  11986. +{
  11987. + rb750_nand_write(buf, len);
  11988. +}
  11989. +
  11990. +static int rb750_nand_verify_buf(struct mtd_info *mtd, const u8 *buf, int len)
  11991. +{
  11992. + return rb750_nand_read_verify(NULL, len, buf);
  11993. +}
  11994. +
  11995. +static void __init rb750_nand_gpio_init(void)
  11996. +{
  11997. + void __iomem *base = ar71xx_gpio_base;
  11998. + u32 out;
  11999. +
  12000. + out = __raw_readl(base + GPIO_REG_OUT);
  12001. +
  12002. + /* setup output levels */
  12003. + __raw_writel(RB750_NAND_NCE | RB750_NAND_NRE | RB750_NAND_NWE,
  12004. + base + GPIO_REG_SET);
  12005. +
  12006. + __raw_writel(RB750_NAND_ALE | RB750_NAND_CLE,
  12007. + base + GPIO_REG_CLEAR);
  12008. +
  12009. + /* setup input lines */
  12010. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(RB750_NAND_INPUT_BITS),
  12011. + base + GPIO_REG_OE);
  12012. +
  12013. + /* setup output lines */
  12014. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_OUTPUT_BITS,
  12015. + base + GPIO_REG_OE);
  12016. +
  12017. + rb750_latch_change(~out & RB750_NAND_IO0, out & RB750_NAND_IO0);
  12018. +}
  12019. +
  12020. +static int __init rb750_nand_probe(struct platform_device *pdev)
  12021. +{
  12022. + struct rb750_nand_info *info;
  12023. + int ret;
  12024. +
  12025. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  12026. +
  12027. + rb750_nand_gpio_init();
  12028. +
  12029. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  12030. + if (!info)
  12031. + return -ENOMEM;
  12032. +
  12033. + info->chip.priv = &info;
  12034. + info->mtd.priv = &info->chip;
  12035. + info->mtd.owner = THIS_MODULE;
  12036. +
  12037. + info->chip.select_chip = rb750_nand_select_chip;
  12038. + info->chip.cmd_ctrl = rb750_nand_cmd_ctrl;
  12039. + info->chip.dev_ready = rb750_nand_dev_ready;
  12040. + info->chip.read_byte = rb750_nand_read_byte;
  12041. + info->chip.write_buf = rb750_nand_write_buf;
  12042. + info->chip.read_buf = rb750_nand_read_buf;
  12043. + info->chip.verify_buf = rb750_nand_verify_buf;
  12044. +
  12045. + info->chip.chip_delay = 25;
  12046. + info->chip.ecc.mode = NAND_ECC_SOFT;
  12047. + info->chip.options |= NAND_NO_AUTOINCR;
  12048. +
  12049. + platform_set_drvdata(pdev, info);
  12050. +
  12051. + ret = nand_scan_ident(&info->mtd, 1);
  12052. + if (ret) {
  12053. + ret = -ENXIO;
  12054. + goto err_free_info;
  12055. + }
  12056. +
  12057. + if (info->mtd.writesize == 512)
  12058. + info->chip.ecc.layout = &rb750_nand_ecclayout;
  12059. +
  12060. + ret = nand_scan_tail(&info->mtd);
  12061. + if (ret) {
  12062. + return -ENXIO;
  12063. + goto err_set_drvdata;
  12064. + }
  12065. +
  12066. +#ifdef CONFIG_MTD_PARTITIONS
  12067. + ret = add_mtd_partitions(&info->mtd, rb750_nand_partitions,
  12068. + ARRAY_SIZE(rb750_nand_partitions));
  12069. +#else
  12070. + ret = add_mtd_device(&info->mtd);
  12071. +#endif
  12072. + if (ret)
  12073. + goto err_release_nand;
  12074. +
  12075. + return 0;
  12076. +
  12077. + err_release_nand:
  12078. + nand_release(&info->mtd);
  12079. + err_set_drvdata:
  12080. + platform_set_drvdata(pdev, NULL);
  12081. + err_free_info:
  12082. + kfree(info);
  12083. + return ret;
  12084. +}
  12085. +
  12086. +static int __devexit rb750_nand_remove(struct platform_device *pdev)
  12087. +{
  12088. + struct rb750_nand_info *info = platform_get_drvdata(pdev);
  12089. +
  12090. + nand_release(&info->mtd);
  12091. + platform_set_drvdata(pdev, NULL);
  12092. + kfree(info);
  12093. +
  12094. + return 0;
  12095. +}
  12096. +
  12097. +static struct platform_driver rb750_nand_driver = {
  12098. + .probe = rb750_nand_probe,
  12099. + .remove = __devexit_p(rb750_nand_remove),
  12100. + .driver = {
  12101. + .name = DRV_NAME,
  12102. + .owner = THIS_MODULE,
  12103. + },
  12104. +};
  12105. +
  12106. +static int __init rb750_nand_init(void)
  12107. +{
  12108. + return platform_driver_register(&rb750_nand_driver);
  12109. +}
  12110. +
  12111. +static void __exit rb750_nand_exit(void)
  12112. +{
  12113. + platform_driver_unregister(&rb750_nand_driver);
  12114. +}
  12115. +
  12116. +module_init(rb750_nand_init);
  12117. +module_exit(rb750_nand_exit);
  12118. +
  12119. +MODULE_DESCRIPTION(DRV_DESC);
  12120. +MODULE_VERSION(DRV_VERSION);
  12121. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  12122. +MODULE_LICENSE("GPL v2");
  12123. diff -Nur linux-2.6.33.3.orig/drivers/mtd/wrt160nl_part.c linux-2.6.33.3/drivers/mtd/wrt160nl_part.c
  12124. --- linux-2.6.33.3.orig/drivers/mtd/wrt160nl_part.c 1970-01-01 01:00:00.000000000 +0100
  12125. +++ linux-2.6.33.3/drivers/mtd/wrt160nl_part.c 2010-04-02 11:07:52.154964482 +0200
  12126. @@ -0,0 +1,181 @@
  12127. +/*
  12128. + * Copyright (C) 2009 Christian Daniel <cd@maintech.de>
  12129. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  12130. + *
  12131. + * This program is free software; you can redistribute it and/or modify
  12132. + * it under the terms of the GNU General Public License as published by
  12133. + * the Free Software Foundation; either version 2 of the License, or
  12134. + * (at your option) any later version.
  12135. + *
  12136. + * This program is distributed in the hope that it will be useful,
  12137. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12138. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12139. + * GNU General Public License for more details.
  12140. + *
  12141. + * You should have received a copy of the GNU General Public License
  12142. + * along with this program; if not, write to the Free Software
  12143. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  12144. + *
  12145. + * TRX flash partition table.
  12146. + * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
  12147. + *
  12148. + */
  12149. +
  12150. +#include <linux/kernel.h>
  12151. +#include <linux/slab.h>
  12152. +#include <linux/vmalloc.h>
  12153. +
  12154. +#include <linux/mtd/mtd.h>
  12155. +#include <linux/mtd/partitions.h>
  12156. +
  12157. +struct cybertan_header {
  12158. + char magic[4];
  12159. + u8 res1[4];
  12160. + char fw_date[3];
  12161. + char fw_ver[3];
  12162. + char id[4];
  12163. + char hw_ver;
  12164. + char unused;
  12165. + u8 flags[2];
  12166. + u8 res2[10];
  12167. +};
  12168. +
  12169. +#define TRX_PARTS 6
  12170. +#define TRX_MAGIC 0x30524448
  12171. +#define TRX_MAX_OFFSET 3
  12172. +
  12173. +struct trx_header {
  12174. + uint32_t magic; /* "HDR0" */
  12175. + uint32_t len; /* Length of file including header */
  12176. + uint32_t crc32; /* 32-bit CRC from flag_version to end of file */
  12177. + uint32_t flag_version; /* 0:15 flags, 16:31 version */
  12178. + uint32_t offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */
  12179. +};
  12180. +
  12181. +#define IH_MAGIC 0x27051956 /* Image Magic Number */
  12182. +#define IH_NMLEN 32 /* Image Name Length */
  12183. +
  12184. +struct uimage_header {
  12185. + uint32_t ih_magic; /* Image Header Magic Number */
  12186. + uint32_t ih_hcrc; /* Image Header CRC Checksum */
  12187. + uint32_t ih_time; /* Image Creation Timestamp */
  12188. + uint32_t ih_size; /* Image Data Size */
  12189. + uint32_t ih_load; /* Data» Load Address */
  12190. + uint32_t ih_ep; /* Entry Point Address */
  12191. + uint32_t ih_dcrc; /* Image Data CRC Checksum */
  12192. + uint8_t ih_os; /* Operating System */
  12193. + uint8_t ih_arch; /* CPU architecture */
  12194. + uint8_t ih_type; /* Image Type */
  12195. + uint8_t ih_comp; /* Compression Type */
  12196. + uint8_t ih_name[IH_NMLEN]; /* Image Name */
  12197. +};
  12198. +
  12199. +struct wrt160nl_header {
  12200. + struct cybertan_header cybertan;
  12201. + struct trx_header trx;
  12202. + struct uimage_header uimage;
  12203. +} __attribute__ ((packed));
  12204. +
  12205. +static struct mtd_partition trx_parts[TRX_PARTS];
  12206. +
  12207. +static int wrt160nl_parse_partitions(struct mtd_info *master,
  12208. + struct mtd_partition **pparts,
  12209. + unsigned long origin)
  12210. +{
  12211. + struct wrt160nl_header *header;
  12212. + struct trx_header *theader;
  12213. + struct uimage_header *uheader;
  12214. + size_t retlen;
  12215. + unsigned int kernel_len;
  12216. + int ret;
  12217. +
  12218. + header = vmalloc(sizeof(*header));
  12219. + if (!header) {
  12220. + return -ENOMEM;
  12221. + goto out;
  12222. + }
  12223. +
  12224. + ret = master->read(master, 4 * master->erasesize, sizeof(*header),
  12225. + &retlen, (void *) header);
  12226. + if (ret)
  12227. + goto free_hdr;
  12228. +
  12229. + if (retlen != sizeof(*header)) {
  12230. + ret = -EIO;
  12231. + goto free_hdr;
  12232. + }
  12233. +
  12234. + if (strncmp(header->cybertan.magic, "NL16", 4) != 0) {
  12235. + printk(KERN_NOTICE "%s: no WRT160NL signature found\n",
  12236. + master->name);
  12237. + goto free_hdr;
  12238. + }
  12239. +
  12240. + theader = &header->trx;
  12241. + if (le32_to_cpu(theader->magic) != TRX_MAGIC) {
  12242. + printk(KERN_NOTICE "%s: no TRX header found\n", master->name);
  12243. + goto free_hdr;
  12244. + }
  12245. +
  12246. + uheader = &header->uimage;
  12247. + if (uheader->ih_magic != IH_MAGIC) {
  12248. + printk(KERN_NOTICE "%s: no uImage found\n", master->name);
  12249. + goto free_hdr;
  12250. + }
  12251. +
  12252. + kernel_len = le32_to_cpu(theader->offsets[1]) + sizeof(struct cybertan_header);
  12253. +
  12254. + trx_parts[0].name = "u-boot";
  12255. + trx_parts[0].offset = 0;
  12256. + trx_parts[0].size = 4 * master->erasesize;
  12257. + trx_parts[0].mask_flags = MTD_WRITEABLE;
  12258. +
  12259. + trx_parts[1].name = "kernel";
  12260. + trx_parts[1].offset = trx_parts[0].offset + trx_parts[0].size;
  12261. + trx_parts[1].size = kernel_len;
  12262. + trx_parts[1].mask_flags = 0;
  12263. +
  12264. + trx_parts[2].name = "rootfs";
  12265. + trx_parts[2].offset = trx_parts[1].offset + trx_parts[1].size;
  12266. + trx_parts[2].size = master->size - 6 * master->erasesize - trx_parts[1].size;
  12267. + trx_parts[2].mask_flags = 0;
  12268. +
  12269. + trx_parts[3].name = "nvram";
  12270. + trx_parts[3].offset = master->size - 2 * master->erasesize;
  12271. + trx_parts[3].size = master->erasesize;
  12272. + trx_parts[3].mask_flags = MTD_WRITEABLE;
  12273. +
  12274. + trx_parts[4].name = "art";
  12275. + trx_parts[4].offset = master->size - master->erasesize;
  12276. + trx_parts[4].size = master->erasesize;
  12277. + trx_parts[4].mask_flags = MTD_WRITEABLE;
  12278. +
  12279. + trx_parts[5].name = "firmware";
  12280. + trx_parts[5].offset = 4 * master->erasesize;
  12281. + trx_parts[5].size = master->size - 6 * master->erasesize;
  12282. + trx_parts[5].mask_flags = 0;
  12283. +
  12284. + *pparts = trx_parts;
  12285. + ret = TRX_PARTS;
  12286. +
  12287. + free_hdr:
  12288. + vfree(header);
  12289. + out:
  12290. + return ret;
  12291. +}
  12292. +
  12293. +static struct mtd_part_parser wrt160nl_parser = {
  12294. + .owner = THIS_MODULE,
  12295. + .parse_fn = wrt160nl_parse_partitions,
  12296. + .name = "wrt160nl",
  12297. +};
  12298. +
  12299. +static int __init wrt160nl_parser_init(void)
  12300. +{
  12301. + return register_mtd_parser(&wrt160nl_parser);
  12302. +}
  12303. +
  12304. +module_init(wrt160nl_parser_init);
  12305. +
  12306. +MODULE_LICENSE("GPL");
  12307. +MODULE_AUTHOR("Christian Daniel <cd@maintech.de>");
  12308. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_ar8216.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_ar8216.c
  12309. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_ar8216.c 1970-01-01 01:00:00.000000000 +0100
  12310. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_ar8216.c 2010-05-16 13:17:33.387600561 +0200
  12311. @@ -0,0 +1,44 @@
  12312. +/*
  12313. + * Atheros AR71xx built-in ethernet mac driver
  12314. + * Special support for the Atheros ar8216 switch chip
  12315. + *
  12316. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  12317. + *
  12318. + * Based on Atheros' AG7100 driver
  12319. + *
  12320. + * This program is free software; you can redistribute it and/or modify it
  12321. + * under the terms of the GNU General Public License version 2 as published
  12322. + * by the Free Software Foundation.
  12323. + */
  12324. +
  12325. +#include "ag71xx.h"
  12326. +
  12327. +#define AR8216_PACKET_TYPE_MASK 0xf
  12328. +#define AR8216_PACKET_TYPE_NORMAL 0
  12329. +
  12330. +#define AR8216_HEADER_LEN 2
  12331. +
  12332. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb)
  12333. +{
  12334. + skb_push(skb, AR8216_HEADER_LEN);
  12335. + skb->data[0] = 0x10;
  12336. + skb->data[1] = 0x80;
  12337. +}
  12338. +
  12339. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  12340. + int pktlen)
  12341. +{
  12342. + u8 type;
  12343. +
  12344. + type = skb->data[1] & AR8216_PACKET_TYPE_MASK;
  12345. + switch (type) {
  12346. + case AR8216_PACKET_TYPE_NORMAL:
  12347. + break;
  12348. +
  12349. + default:
  12350. + return -EINVAL;
  12351. + }
  12352. +
  12353. + skb_pull(skb, AR8216_HEADER_LEN);
  12354. + return 0;
  12355. +}
  12356. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_debugfs.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_debugfs.c
  12357. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  12358. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_debugfs.c 2010-01-11 19:25:55.893395656 +0100
  12359. @@ -0,0 +1,197 @@
  12360. +/*
  12361. + * Atheros AR71xx built-in ethernet mac driver
  12362. + *
  12363. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12364. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12365. + *
  12366. + * Based on Atheros' AG7100 driver
  12367. + *
  12368. + * This program is free software; you can redistribute it and/or modify it
  12369. + * under the terms of the GNU General Public License version 2 as published
  12370. + * by the Free Software Foundation.
  12371. + */
  12372. +
  12373. +#include <linux/debugfs.h>
  12374. +
  12375. +#include "ag71xx.h"
  12376. +
  12377. +static struct dentry *ag71xx_debugfs_root;
  12378. +
  12379. +static int ag71xx_debugfs_generic_open(struct inode *inode, struct file *file)
  12380. +{
  12381. + file->private_data = inode->i_private;
  12382. + return 0;
  12383. +}
  12384. +
  12385. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status)
  12386. +{
  12387. + if (status)
  12388. + ag->debug.int_stats.total++;
  12389. + if (status & AG71XX_INT_TX_PS)
  12390. + ag->debug.int_stats.tx_ps++;
  12391. + if (status & AG71XX_INT_TX_UR)
  12392. + ag->debug.int_stats.tx_ur++;
  12393. + if (status & AG71XX_INT_TX_BE)
  12394. + ag->debug.int_stats.tx_be++;
  12395. + if (status & AG71XX_INT_RX_PR)
  12396. + ag->debug.int_stats.rx_pr++;
  12397. + if (status & AG71XX_INT_RX_OF)
  12398. + ag->debug.int_stats.rx_of++;
  12399. + if (status & AG71XX_INT_RX_BE)
  12400. + ag->debug.int_stats.rx_be++;
  12401. +}
  12402. +
  12403. +static ssize_t read_file_int_stats(struct file *file, char __user *user_buf,
  12404. + size_t count, loff_t *ppos)
  12405. +{
  12406. +#define PR_INT_STAT(_label, _field) \
  12407. + len += snprintf(buf + len, sizeof(buf) - len, \
  12408. + "%20s: %10lu\n", _label, ag->debug.int_stats._field);
  12409. +
  12410. + struct ag71xx *ag = file->private_data;
  12411. + char buf[256];
  12412. + unsigned int len = 0;
  12413. +
  12414. + PR_INT_STAT("TX Packet Sent", tx_ps);
  12415. + PR_INT_STAT("TX Underrun", tx_ur);
  12416. + PR_INT_STAT("TX Bus Error", tx_be);
  12417. + PR_INT_STAT("RX Packet Received", rx_pr);
  12418. + PR_INT_STAT("RX Overflow", rx_of);
  12419. + PR_INT_STAT("RX Bus Error", rx_be);
  12420. + len += snprintf(buf + len, sizeof(buf) - len, "\n");
  12421. + PR_INT_STAT("Total", total);
  12422. +
  12423. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  12424. +#undef PR_INT_STAT
  12425. +}
  12426. +
  12427. +static const struct file_operations ag71xx_fops_int_stats = {
  12428. + .open = ag71xx_debugfs_generic_open,
  12429. + .read = read_file_int_stats,
  12430. + .owner = THIS_MODULE
  12431. +};
  12432. +
  12433. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx)
  12434. +{
  12435. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  12436. +
  12437. + if (rx) {
  12438. + stats->rx_count++;
  12439. + stats->rx_packets += rx;
  12440. + if (rx <= AG71XX_NAPI_WEIGHT)
  12441. + stats->rx[rx]++;
  12442. + if (rx > stats->rx_packets_max)
  12443. + stats->rx_packets_max = rx;
  12444. + }
  12445. +
  12446. + if (tx) {
  12447. + stats->tx_count++;
  12448. + stats->tx_packets += tx;
  12449. + if (tx <= AG71XX_NAPI_WEIGHT)
  12450. + stats->tx[tx]++;
  12451. + if (tx > stats->tx_packets_max)
  12452. + stats->tx_packets_max = tx;
  12453. + }
  12454. +}
  12455. +
  12456. +static ssize_t read_file_napi_stats(struct file *file, char __user *user_buf,
  12457. + size_t count, loff_t *ppos)
  12458. +{
  12459. + struct ag71xx *ag = file->private_data;
  12460. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  12461. + char buf[2048];
  12462. + unsigned int len = 0;
  12463. + unsigned long rx_avg = 0;
  12464. + unsigned long tx_avg = 0;
  12465. + int i;
  12466. +
  12467. + if (stats->rx_count)
  12468. + rx_avg = stats->rx_packets / stats->rx_count;
  12469. +
  12470. + if (stats->tx_count)
  12471. + tx_avg = stats->tx_packets / stats->tx_count;
  12472. +
  12473. + len += snprintf(buf + len, sizeof(buf) - len, "%3s %10s %10s\n",
  12474. + "len", "rx", "tx");
  12475. +
  12476. + for (i = 1; i <= AG71XX_NAPI_WEIGHT; i++)
  12477. + len += snprintf(buf + len, sizeof(buf) - len,
  12478. + "%3d: %10lu %10lu\n",
  12479. + i, stats->rx[i], stats->tx[i]);
  12480. +
  12481. + len += snprintf(buf + len, sizeof(buf) - len, "\n");
  12482. +
  12483. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12484. + "sum", stats->rx_count, stats->tx_count);
  12485. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12486. + "avg", rx_avg, tx_avg);
  12487. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12488. + "max", stats->rx_packets_max, stats->tx_packets_max);
  12489. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12490. + "pkt", stats->rx_packets, stats->tx_packets);
  12491. +
  12492. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  12493. +}
  12494. +
  12495. +static const struct file_operations ag71xx_fops_napi_stats = {
  12496. + .open = ag71xx_debugfs_generic_open,
  12497. + .read = read_file_napi_stats,
  12498. + .owner = THIS_MODULE
  12499. +};
  12500. +
  12501. +void ag71xx_debugfs_exit(struct ag71xx *ag)
  12502. +{
  12503. + debugfs_remove(ag->debug.debugfs_napi_stats);
  12504. + debugfs_remove(ag->debug.debugfs_int_stats);
  12505. + debugfs_remove(ag->debug.debugfs_dir);
  12506. +}
  12507. +
  12508. +int ag71xx_debugfs_init(struct ag71xx *ag)
  12509. +{
  12510. + ag->debug.debugfs_dir = debugfs_create_dir(ag->dev->name,
  12511. + ag71xx_debugfs_root);
  12512. + if (!ag->debug.debugfs_dir)
  12513. + goto err;
  12514. +
  12515. + ag->debug.debugfs_int_stats =
  12516. + debugfs_create_file("int_stats",
  12517. + S_IRUGO,
  12518. + ag->debug.debugfs_dir,
  12519. + ag,
  12520. + &ag71xx_fops_int_stats);
  12521. + if (!ag->debug.debugfs_int_stats)
  12522. + goto err;
  12523. +
  12524. + ag->debug.debugfs_napi_stats =
  12525. + debugfs_create_file("napi_stats",
  12526. + S_IRUGO,
  12527. + ag->debug.debugfs_dir,
  12528. + ag,
  12529. + &ag71xx_fops_napi_stats);
  12530. + if (!ag->debug.debugfs_napi_stats)
  12531. + goto err;
  12532. +
  12533. + return 0;
  12534. +
  12535. + err:
  12536. + ag71xx_debugfs_exit(ag);
  12537. + return -ENOMEM;
  12538. +}
  12539. +
  12540. +int ag71xx_debugfs_root_init(void)
  12541. +{
  12542. + if (ag71xx_debugfs_root)
  12543. + return -EBUSY;
  12544. +
  12545. + ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  12546. + if (!ag71xx_debugfs_root)
  12547. + return -ENOENT;
  12548. +
  12549. + return 0;
  12550. +}
  12551. +
  12552. +void ag71xx_debugfs_root_exit(void)
  12553. +{
  12554. + debugfs_remove(ag71xx_debugfs_root);
  12555. + ag71xx_debugfs_root = NULL;
  12556. +}
  12557. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_ethtool.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_ethtool.c
  12558. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_ethtool.c 1970-01-01 01:00:00.000000000 +0100
  12559. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_ethtool.c 2010-01-05 20:38:53.433277722 +0100
  12560. @@ -0,0 +1,71 @@
  12561. +/*
  12562. + * Atheros AR71xx built-in ethernet mac driver
  12563. + *
  12564. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12565. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12566. + *
  12567. + * Based on Atheros' AG7100 driver
  12568. + *
  12569. + * This program is free software; you can redistribute it and/or modify it
  12570. + * under the terms of the GNU General Public License version 2 as published
  12571. + * by the Free Software Foundation.
  12572. + */
  12573. +
  12574. +#include "ag71xx.h"
  12575. +
  12576. +static int ag71xx_ethtool_get_settings(struct net_device *dev,
  12577. + struct ethtool_cmd *cmd)
  12578. +{
  12579. + struct ag71xx *ag = netdev_priv(dev);
  12580. + struct phy_device *phydev = ag->phy_dev;
  12581. +
  12582. + if (!phydev)
  12583. + return -ENODEV;
  12584. +
  12585. + return phy_ethtool_gset(phydev, cmd);
  12586. +}
  12587. +
  12588. +static int ag71xx_ethtool_set_settings(struct net_device *dev,
  12589. + struct ethtool_cmd *cmd)
  12590. +{
  12591. + struct ag71xx *ag = netdev_priv(dev);
  12592. + struct phy_device *phydev = ag->phy_dev;
  12593. +
  12594. + if (!phydev)
  12595. + return -ENODEV;
  12596. +
  12597. + return phy_ethtool_sset(phydev, cmd);
  12598. +}
  12599. +
  12600. +static void ag71xx_ethtool_get_drvinfo(struct net_device *dev,
  12601. + struct ethtool_drvinfo *info)
  12602. +{
  12603. + struct ag71xx *ag = netdev_priv(dev);
  12604. +
  12605. + strcpy(info->driver, ag->pdev->dev.driver->name);
  12606. + strcpy(info->version, AG71XX_DRV_VERSION);
  12607. + strcpy(info->bus_info, dev_name(&ag->pdev->dev));
  12608. +}
  12609. +
  12610. +static u32 ag71xx_ethtool_get_msglevel(struct net_device *dev)
  12611. +{
  12612. + struct ag71xx *ag = netdev_priv(dev);
  12613. +
  12614. + return ag->msg_enable;
  12615. +}
  12616. +
  12617. +static void ag71xx_ethtool_set_msglevel(struct net_device *dev, u32 msg_level)
  12618. +{
  12619. + struct ag71xx *ag = netdev_priv(dev);
  12620. +
  12621. + ag->msg_enable = msg_level;
  12622. +}
  12623. +
  12624. +struct ethtool_ops ag71xx_ethtool_ops = {
  12625. + .set_settings = ag71xx_ethtool_set_settings,
  12626. + .get_settings = ag71xx_ethtool_get_settings,
  12627. + .get_drvinfo = ag71xx_ethtool_get_drvinfo,
  12628. + .get_msglevel = ag71xx_ethtool_get_msglevel,
  12629. + .set_msglevel = ag71xx_ethtool_set_msglevel,
  12630. + .get_link = ethtool_op_get_link,
  12631. +};
  12632. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx.h linux-2.6.33.3/drivers/net/ag71xx/ag71xx.h
  12633. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx.h 1970-01-01 01:00:00.000000000 +0100
  12634. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx.h 2010-04-14 21:17:13.718345809 +0200
  12635. @@ -0,0 +1,500 @@
  12636. +/*
  12637. + * Atheros AR71xx built-in ethernet mac driver
  12638. + *
  12639. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12640. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12641. + *
  12642. + * Based on Atheros' AG7100 driver
  12643. + *
  12644. + * This program is free software; you can redistribute it and/or modify it
  12645. + * under the terms of the GNU General Public License version 2 as published
  12646. + * by the Free Software Foundation.
  12647. + */
  12648. +
  12649. +#ifndef __AG71XX_H
  12650. +#define __AG71XX_H
  12651. +
  12652. +#include <linux/kernel.h>
  12653. +#include <linux/version.h>
  12654. +#include <linux/module.h>
  12655. +#include <linux/init.h>
  12656. +#include <linux/types.h>
  12657. +#include <linux/random.h>
  12658. +#include <linux/spinlock.h>
  12659. +#include <linux/interrupt.h>
  12660. +#include <linux/platform_device.h>
  12661. +#include <linux/ethtool.h>
  12662. +#include <linux/etherdevice.h>
  12663. +#include <linux/phy.h>
  12664. +#include <linux/skbuff.h>
  12665. +#include <linux/dma-mapping.h>
  12666. +#include <linux/workqueue.h>
  12667. +
  12668. +#include <linux/bitops.h>
  12669. +
  12670. +#include <asm/mach-ar71xx/ar71xx.h>
  12671. +#include <asm/mach-ar71xx/platform.h>
  12672. +
  12673. +#define ETH_FCS_LEN 4
  12674. +
  12675. +#define AG71XX_DRV_NAME "ag71xx"
  12676. +#define AG71XX_DRV_VERSION "0.5.35"
  12677. +
  12678. +#define AG71XX_NAPI_WEIGHT 64
  12679. +#define AG71XX_OOM_REFILL (1 + HZ/10)
  12680. +
  12681. +#define AG71XX_INT_ERR (AG71XX_INT_RX_BE | AG71XX_INT_TX_BE)
  12682. +#define AG71XX_INT_TX (AG71XX_INT_TX_PS)
  12683. +#define AG71XX_INT_RX (AG71XX_INT_RX_PR | AG71XX_INT_RX_OF)
  12684. +
  12685. +#define AG71XX_INT_POLL (AG71XX_INT_RX | AG71XX_INT_TX)
  12686. +#define AG71XX_INT_INIT (AG71XX_INT_ERR | AG71XX_INT_POLL)
  12687. +
  12688. +#define AG71XX_TX_FIFO_LEN 2048
  12689. +#define AG71XX_TX_MTU_LEN 1536
  12690. +#define AG71XX_RX_PKT_RESERVE 64
  12691. +#define AG71XX_RX_PKT_SIZE \
  12692. + (AG71XX_RX_PKT_RESERVE + ETH_HLEN + ETH_FRAME_LEN + ETH_FCS_LEN)
  12693. +
  12694. +#define AG71XX_TX_RING_SIZE 64
  12695. +#define AG71XX_TX_THRES_STOP (AG71XX_TX_RING_SIZE - 4)
  12696. +#define AG71XX_TX_THRES_WAKEUP \
  12697. + (AG71XX_TX_RING_SIZE - (AG71XX_TX_RING_SIZE / 4))
  12698. +
  12699. +#define AG71XX_RX_RING_SIZE 128
  12700. +
  12701. +#ifdef CONFIG_AG71XX_DEBUG
  12702. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  12703. +#else
  12704. +#define DBG(fmt, args...) do {} while (0)
  12705. +#endif
  12706. +
  12707. +#define ag71xx_assert(_cond) \
  12708. +do { \
  12709. + if (_cond) \
  12710. + break; \
  12711. + printk("%s,%d: assertion failed\n", __FILE__, __LINE__); \
  12712. + BUG(); \
  12713. +} while (0)
  12714. +
  12715. +struct ag71xx_desc {
  12716. + u32 data;
  12717. + u32 ctrl;
  12718. +#define DESC_EMPTY BIT(31)
  12719. +#define DESC_MORE BIT(24)
  12720. +#define DESC_PKTLEN_M 0xfff
  12721. + u32 next;
  12722. + u32 pad;
  12723. +} __attribute__((aligned(4)));
  12724. +
  12725. +struct ag71xx_buf {
  12726. + struct sk_buff *skb;
  12727. + struct ag71xx_desc *desc;
  12728. + dma_addr_t dma_addr;
  12729. + u32 pad;
  12730. +};
  12731. +
  12732. +struct ag71xx_ring {
  12733. + struct ag71xx_buf *buf;
  12734. + u8 *descs_cpu;
  12735. + dma_addr_t descs_dma;
  12736. + unsigned int desc_size;
  12737. + unsigned int curr;
  12738. + unsigned int dirty;
  12739. + unsigned int size;
  12740. +};
  12741. +
  12742. +struct ag71xx_mdio {
  12743. + struct mii_bus *mii_bus;
  12744. + int mii_irq[PHY_MAX_ADDR];
  12745. + void __iomem *mdio_base;
  12746. + struct ag71xx_mdio_platform_data *pdata;
  12747. +};
  12748. +
  12749. +struct ag71xx_int_stats {
  12750. + unsigned long rx_pr;
  12751. + unsigned long rx_be;
  12752. + unsigned long rx_of;
  12753. + unsigned long tx_ps;
  12754. + unsigned long tx_be;
  12755. + unsigned long tx_ur;
  12756. + unsigned long total;
  12757. +};
  12758. +
  12759. +struct ag71xx_napi_stats {
  12760. + unsigned long napi_calls;
  12761. + unsigned long rx_count;
  12762. + unsigned long rx_packets;
  12763. + unsigned long rx_packets_max;
  12764. + unsigned long tx_count;
  12765. + unsigned long tx_packets;
  12766. + unsigned long tx_packets_max;
  12767. +
  12768. + unsigned long rx[AG71XX_NAPI_WEIGHT + 1];
  12769. + unsigned long tx[AG71XX_NAPI_WEIGHT + 1];
  12770. +};
  12771. +
  12772. +struct ag71xx_debug {
  12773. + struct dentry *debugfs_dir;
  12774. + struct dentry *debugfs_int_stats;
  12775. + struct dentry *debugfs_napi_stats;
  12776. +
  12777. + struct ag71xx_int_stats int_stats;
  12778. + struct ag71xx_napi_stats napi_stats;
  12779. +};
  12780. +
  12781. +struct ag71xx {
  12782. + void __iomem *mac_base;
  12783. + void __iomem *mii_ctrl;
  12784. +
  12785. + spinlock_t lock;
  12786. + struct platform_device *pdev;
  12787. + struct net_device *dev;
  12788. + struct napi_struct napi;
  12789. + u32 msg_enable;
  12790. +
  12791. + struct ag71xx_ring rx_ring;
  12792. + struct ag71xx_ring tx_ring;
  12793. +
  12794. + struct mii_bus *mii_bus;
  12795. + struct phy_device *phy_dev;
  12796. +
  12797. + unsigned int link;
  12798. + unsigned int speed;
  12799. + int duplex;
  12800. +
  12801. + struct work_struct restart_work;
  12802. + struct timer_list oom_timer;
  12803. +
  12804. +#ifdef CONFIG_AG71XX_DEBUG_FS
  12805. + struct ag71xx_debug debug;
  12806. +#endif
  12807. +};
  12808. +
  12809. +extern struct ethtool_ops ag71xx_ethtool_ops;
  12810. +void ag71xx_link_adjust(struct ag71xx *ag);
  12811. +
  12812. +int ag71xx_mdio_driver_init(void) __init;
  12813. +void ag71xx_mdio_driver_exit(void);
  12814. +
  12815. +int ag71xx_phy_connect(struct ag71xx *ag);
  12816. +void ag71xx_phy_disconnect(struct ag71xx *ag);
  12817. +void ag71xx_phy_start(struct ag71xx *ag);
  12818. +void ag71xx_phy_stop(struct ag71xx *ag);
  12819. +
  12820. +static inline struct ag71xx_platform_data *ag71xx_get_pdata(struct ag71xx *ag)
  12821. +{
  12822. + return ag->pdev->dev.platform_data;
  12823. +}
  12824. +
  12825. +static inline int ag71xx_desc_empty(struct ag71xx_desc *desc)
  12826. +{
  12827. + return ((desc->ctrl & DESC_EMPTY) != 0);
  12828. +}
  12829. +
  12830. +static inline int ag71xx_desc_pktlen(struct ag71xx_desc *desc)
  12831. +{
  12832. + return (desc->ctrl & DESC_PKTLEN_M);
  12833. +}
  12834. +
  12835. +/* Register offsets */
  12836. +#define AG71XX_REG_MAC_CFG1 0x0000
  12837. +#define AG71XX_REG_MAC_CFG2 0x0004
  12838. +#define AG71XX_REG_MAC_IPG 0x0008
  12839. +#define AG71XX_REG_MAC_HDX 0x000c
  12840. +#define AG71XX_REG_MAC_MFL 0x0010
  12841. +#define AG71XX_REG_MII_CFG 0x0020
  12842. +#define AG71XX_REG_MII_CMD 0x0024
  12843. +#define AG71XX_REG_MII_ADDR 0x0028
  12844. +#define AG71XX_REG_MII_CTRL 0x002c
  12845. +#define AG71XX_REG_MII_STATUS 0x0030
  12846. +#define AG71XX_REG_MII_IND 0x0034
  12847. +#define AG71XX_REG_MAC_IFCTL 0x0038
  12848. +#define AG71XX_REG_MAC_ADDR1 0x0040
  12849. +#define AG71XX_REG_MAC_ADDR2 0x0044
  12850. +#define AG71XX_REG_FIFO_CFG0 0x0048
  12851. +#define AG71XX_REG_FIFO_CFG1 0x004c
  12852. +#define AG71XX_REG_FIFO_CFG2 0x0050
  12853. +#define AG71XX_REG_FIFO_CFG3 0x0054
  12854. +#define AG71XX_REG_FIFO_CFG4 0x0058
  12855. +#define AG71XX_REG_FIFO_CFG5 0x005c
  12856. +#define AG71XX_REG_FIFO_RAM0 0x0060
  12857. +#define AG71XX_REG_FIFO_RAM1 0x0064
  12858. +#define AG71XX_REG_FIFO_RAM2 0x0068
  12859. +#define AG71XX_REG_FIFO_RAM3 0x006c
  12860. +#define AG71XX_REG_FIFO_RAM4 0x0070
  12861. +#define AG71XX_REG_FIFO_RAM5 0x0074
  12862. +#define AG71XX_REG_FIFO_RAM6 0x0078
  12863. +#define AG71XX_REG_FIFO_RAM7 0x007c
  12864. +
  12865. +#define AG71XX_REG_TX_CTRL 0x0180
  12866. +#define AG71XX_REG_TX_DESC 0x0184
  12867. +#define AG71XX_REG_TX_STATUS 0x0188
  12868. +#define AG71XX_REG_RX_CTRL 0x018c
  12869. +#define AG71XX_REG_RX_DESC 0x0190
  12870. +#define AG71XX_REG_RX_STATUS 0x0194
  12871. +#define AG71XX_REG_INT_ENABLE 0x0198
  12872. +#define AG71XX_REG_INT_STATUS 0x019c
  12873. +
  12874. +#define MAC_CFG1_TXE BIT(0) /* Tx Enable */
  12875. +#define MAC_CFG1_STX BIT(1) /* Synchronize Tx Enable */
  12876. +#define MAC_CFG1_RXE BIT(2) /* Rx Enable */
  12877. +#define MAC_CFG1_SRX BIT(3) /* Synchronize Rx Enable */
  12878. +#define MAC_CFG1_TFC BIT(4) /* Tx Flow Control Enable */
  12879. +#define MAC_CFG1_RFC BIT(5) /* Rx Flow Control Enable */
  12880. +#define MAC_CFG1_LB BIT(8) /* Loopback mode */
  12881. +#define MAC_CFG1_SR BIT(31) /* Soft Reset */
  12882. +
  12883. +#define MAC_CFG2_FDX BIT(0)
  12884. +#define MAC_CFG2_CRC_EN BIT(1)
  12885. +#define MAC_CFG2_PAD_CRC_EN BIT(2)
  12886. +#define MAC_CFG2_LEN_CHECK BIT(4)
  12887. +#define MAC_CFG2_HUGE_FRAME_EN BIT(5)
  12888. +#define MAC_CFG2_IF_1000 BIT(9)
  12889. +#define MAC_CFG2_IF_10_100 BIT(8)
  12890. +
  12891. +#define FIFO_CFG0_WTM BIT(0) /* Watermark Module */
  12892. +#define FIFO_CFG0_RXS BIT(1) /* Rx System Module */
  12893. +#define FIFO_CFG0_RXF BIT(2) /* Rx Fabric Module */
  12894. +#define FIFO_CFG0_TXS BIT(3) /* Tx System Module */
  12895. +#define FIFO_CFG0_TXF BIT(4) /* Tx Fabric Module */
  12896. +#define FIFO_CFG0_ALL (FIFO_CFG0_WTM | FIFO_CFG0_RXS | FIFO_CFG0_RXF \
  12897. + | FIFO_CFG0_TXS | FIFO_CFG0_TXF)
  12898. +
  12899. +#define FIFO_CFG0_ENABLE_SHIFT 8
  12900. +
  12901. +#define FIFO_CFG4_DE BIT(0) /* Drop Event */
  12902. +#define FIFO_CFG4_DV BIT(1) /* RX_DV Event */
  12903. +#define FIFO_CFG4_FC BIT(2) /* False Carrier */
  12904. +#define FIFO_CFG4_CE BIT(3) /* Code Error */
  12905. +#define FIFO_CFG4_CR BIT(4) /* CRC error */
  12906. +#define FIFO_CFG4_LM BIT(5) /* Length Mismatch */
  12907. +#define FIFO_CFG4_LO BIT(6) /* Length out of range */
  12908. +#define FIFO_CFG4_OK BIT(7) /* Packet is OK */
  12909. +#define FIFO_CFG4_MC BIT(8) /* Multicast Packet */
  12910. +#define FIFO_CFG4_BC BIT(9) /* Broadcast Packet */
  12911. +#define FIFO_CFG4_DR BIT(10) /* Dribble */
  12912. +#define FIFO_CFG4_LE BIT(11) /* Long Event */
  12913. +#define FIFO_CFG4_CF BIT(12) /* Control Frame */
  12914. +#define FIFO_CFG4_PF BIT(13) /* Pause Frame */
  12915. +#define FIFO_CFG4_UO BIT(14) /* Unsupported Opcode */
  12916. +#define FIFO_CFG4_VT BIT(15) /* VLAN tag detected */
  12917. +#define FIFO_CFG4_FT BIT(16) /* Frame Truncated */
  12918. +#define FIFO_CFG4_UC BIT(17) /* Unicast Packet */
  12919. +
  12920. +#define FIFO_CFG5_DE BIT(0) /* Drop Event */
  12921. +#define FIFO_CFG5_DV BIT(1) /* RX_DV Event */
  12922. +#define FIFO_CFG5_FC BIT(2) /* False Carrier */
  12923. +#define FIFO_CFG5_CE BIT(3) /* Code Error */
  12924. +#define FIFO_CFG5_LM BIT(4) /* Length Mismatch */
  12925. +#define FIFO_CFG5_LO BIT(5) /* Length Out of Range */
  12926. +#define FIFO_CFG5_OK BIT(6) /* Packet is OK */
  12927. +#define FIFO_CFG5_MC BIT(7) /* Multicast Packet */
  12928. +#define FIFO_CFG5_BC BIT(8) /* Broadcast Packet */
  12929. +#define FIFO_CFG5_DR BIT(9) /* Dribble */
  12930. +#define FIFO_CFG5_CF BIT(10) /* Control Frame */
  12931. +#define FIFO_CFG5_PF BIT(11) /* Pause Frame */
  12932. +#define FIFO_CFG5_UO BIT(12) /* Unsupported Opcode */
  12933. +#define FIFO_CFG5_VT BIT(13) /* VLAN tag detected */
  12934. +#define FIFO_CFG5_LE BIT(14) /* Long Event */
  12935. +#define FIFO_CFG5_FT BIT(15) /* Frame Truncated */
  12936. +#define FIFO_CFG5_16 BIT(16) /* unknown */
  12937. +#define FIFO_CFG5_17 BIT(17) /* unknown */
  12938. +#define FIFO_CFG5_SF BIT(18) /* Short Frame */
  12939. +#define FIFO_CFG5_BM BIT(19) /* Byte Mode */
  12940. +
  12941. +#define AG71XX_INT_TX_PS BIT(0)
  12942. +#define AG71XX_INT_TX_UR BIT(1)
  12943. +#define AG71XX_INT_TX_BE BIT(3)
  12944. +#define AG71XX_INT_RX_PR BIT(4)
  12945. +#define AG71XX_INT_RX_OF BIT(6)
  12946. +#define AG71XX_INT_RX_BE BIT(7)
  12947. +
  12948. +#define MAC_IFCTL_SPEED BIT(16)
  12949. +
  12950. +#define MII_CFG_CLK_DIV_4 0
  12951. +#define MII_CFG_CLK_DIV_6 2
  12952. +#define MII_CFG_CLK_DIV_8 3
  12953. +#define MII_CFG_CLK_DIV_10 4
  12954. +#define MII_CFG_CLK_DIV_14 5
  12955. +#define MII_CFG_CLK_DIV_20 6
  12956. +#define MII_CFG_CLK_DIV_28 7
  12957. +#define MII_CFG_RESET BIT(31)
  12958. +
  12959. +#define MII_CMD_WRITE 0x0
  12960. +#define MII_CMD_READ 0x1
  12961. +#define MII_ADDR_SHIFT 8
  12962. +#define MII_IND_BUSY BIT(0)
  12963. +#define MII_IND_INVALID BIT(2)
  12964. +
  12965. +#define TX_CTRL_TXE BIT(0) /* Tx Enable */
  12966. +
  12967. +#define TX_STATUS_PS BIT(0) /* Packet Sent */
  12968. +#define TX_STATUS_UR BIT(1) /* Tx Underrun */
  12969. +#define TX_STATUS_BE BIT(3) /* Bus Error */
  12970. +
  12971. +#define RX_CTRL_RXE BIT(0) /* Rx Enable */
  12972. +
  12973. +#define RX_STATUS_PR BIT(0) /* Packet Received */
  12974. +#define RX_STATUS_OF BIT(2) /* Rx Overflow */
  12975. +#define RX_STATUS_BE BIT(3) /* Bus Error */
  12976. +
  12977. +#define MII_CTRL_IF_MASK 3
  12978. +#define MII_CTRL_SPEED_SHIFT 4
  12979. +#define MII_CTRL_SPEED_MASK 3
  12980. +#define MII_CTRL_SPEED_10 0
  12981. +#define MII_CTRL_SPEED_100 1
  12982. +#define MII_CTRL_SPEED_1000 2
  12983. +
  12984. +static inline void ag71xx_check_reg_offset(struct ag71xx *ag, unsigned reg)
  12985. +{
  12986. + switch (reg) {
  12987. + case AG71XX_REG_MAC_CFG1 ... AG71XX_REG_MAC_MFL:
  12988. + case AG71XX_REG_MAC_IFCTL ... AG71XX_REG_INT_STATUS:
  12989. + break;
  12990. +
  12991. + default:
  12992. + BUG();
  12993. + }
  12994. +}
  12995. +
  12996. +static inline void ag71xx_wr(struct ag71xx *ag, unsigned reg, u32 value)
  12997. +{
  12998. + ag71xx_check_reg_offset(ag, reg);
  12999. +
  13000. + __raw_writel(value, ag->mac_base + reg);
  13001. + /* flush write */
  13002. + (void) __raw_readl(ag->mac_base + reg);
  13003. +}
  13004. +
  13005. +static inline u32 ag71xx_rr(struct ag71xx *ag, unsigned reg)
  13006. +{
  13007. + ag71xx_check_reg_offset(ag, reg);
  13008. +
  13009. + return __raw_readl(ag->mac_base + reg);
  13010. +}
  13011. +
  13012. +static inline void ag71xx_sb(struct ag71xx *ag, unsigned reg, u32 mask)
  13013. +{
  13014. + void __iomem *r;
  13015. +
  13016. + ag71xx_check_reg_offset(ag, reg);
  13017. +
  13018. + r = ag->mac_base + reg;
  13019. + __raw_writel(__raw_readl(r) | mask, r);
  13020. + /* flush write */
  13021. + (void)__raw_readl(r);
  13022. +}
  13023. +
  13024. +static inline void ag71xx_cb(struct ag71xx *ag, unsigned reg, u32 mask)
  13025. +{
  13026. + void __iomem *r;
  13027. +
  13028. + ag71xx_check_reg_offset(ag, reg);
  13029. +
  13030. + r = ag->mac_base + reg;
  13031. + __raw_writel(__raw_readl(r) & ~mask, r);
  13032. + /* flush write */
  13033. + (void) __raw_readl(r);
  13034. +}
  13035. +
  13036. +static inline void ag71xx_int_enable(struct ag71xx *ag, u32 ints)
  13037. +{
  13038. + ag71xx_sb(ag, AG71XX_REG_INT_ENABLE, ints);
  13039. +}
  13040. +
  13041. +static inline void ag71xx_int_disable(struct ag71xx *ag, u32 ints)
  13042. +{
  13043. + ag71xx_cb(ag, AG71XX_REG_INT_ENABLE, ints);
  13044. +}
  13045. +
  13046. +static inline void ag71xx_mii_ctrl_wr(struct ag71xx *ag, u32 value)
  13047. +{
  13048. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13049. +
  13050. + if (pdata->is_ar724x)
  13051. + return;
  13052. +
  13053. + __raw_writel(value, ag->mii_ctrl);
  13054. +
  13055. + /* flush write */
  13056. + __raw_readl(ag->mii_ctrl);
  13057. +}
  13058. +
  13059. +static inline u32 ag71xx_mii_ctrl_rr(struct ag71xx *ag)
  13060. +{
  13061. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13062. +
  13063. + if (pdata->is_ar724x)
  13064. + return 0xffffffff;
  13065. +
  13066. + return __raw_readl(ag->mii_ctrl);
  13067. +}
  13068. +
  13069. +static void inline ag71xx_mii_ctrl_set_if(struct ag71xx *ag,
  13070. + unsigned int mii_if)
  13071. +{
  13072. + u32 t;
  13073. +
  13074. + t = ag71xx_mii_ctrl_rr(ag);
  13075. + t &= ~(MII_CTRL_IF_MASK);
  13076. + t |= (mii_if & MII_CTRL_IF_MASK);
  13077. + ag71xx_mii_ctrl_wr(ag, t);
  13078. +}
  13079. +
  13080. +static void inline ag71xx_mii_ctrl_set_speed(struct ag71xx *ag,
  13081. + unsigned int speed)
  13082. +{
  13083. + u32 t;
  13084. +
  13085. + t = ag71xx_mii_ctrl_rr(ag);
  13086. + t &= ~(MII_CTRL_SPEED_MASK << MII_CTRL_SPEED_SHIFT);
  13087. + t |= (speed & MII_CTRL_SPEED_MASK) << MII_CTRL_SPEED_SHIFT;
  13088. + ag71xx_mii_ctrl_wr(ag, t);
  13089. +}
  13090. +
  13091. +#ifdef CONFIG_AG71XX_AR8216_SUPPORT
  13092. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb);
  13093. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  13094. + int pktlen);
  13095. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  13096. +{
  13097. + return ag71xx_get_pdata(ag)->has_ar8216;
  13098. +}
  13099. +#else
  13100. +static inline void ag71xx_add_ar8216_header(struct ag71xx *ag,
  13101. + struct sk_buff *skb)
  13102. +{
  13103. +}
  13104. +
  13105. +static inline int ag71xx_remove_ar8216_header(struct ag71xx *ag,
  13106. + struct sk_buff *skb,
  13107. + int pktlen)
  13108. +{
  13109. + return 0;
  13110. +}
  13111. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  13112. +{
  13113. + return 0;
  13114. +}
  13115. +#endif
  13116. +
  13117. +#ifdef CONFIG_AG71XX_DEBUG_FS
  13118. +int ag71xx_debugfs_root_init(void);
  13119. +void ag71xx_debugfs_root_exit(void);
  13120. +int ag71xx_debugfs_init(struct ag71xx *ag);
  13121. +void ag71xx_debugfs_exit(struct ag71xx *ag);
  13122. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status);
  13123. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx);
  13124. +#else
  13125. +static inline int ag71xx_debugfs_root_init(void) { return 0; }
  13126. +static inline void ag71xx_debugfs_root_exit(void) {}
  13127. +static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; }
  13128. +static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {}
  13129. +static inline void ag71xx_debugfs_update_int_stats(struct ag71xx *ag,
  13130. + u32 status) {}
  13131. +static inline void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag,
  13132. + int rx, int tx) {}
  13133. +#endif /* CONFIG_AG71XX_DEBUG_FS */
  13134. +
  13135. +#endif /* _AG71XX_H */
  13136. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_main.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_main.c
  13137. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_main.c 1970-01-01 01:00:00.000000000 +0100
  13138. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_main.c 2010-05-16 13:17:33.403605954 +0200
  13139. @@ -0,0 +1,1184 @@
  13140. +/*
  13141. + * Atheros AR71xx built-in ethernet mac driver
  13142. + *
  13143. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  13144. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  13145. + *
  13146. + * Based on Atheros' AG7100 driver
  13147. + *
  13148. + * This program is free software; you can redistribute it and/or modify it
  13149. + * under the terms of the GNU General Public License version 2 as published
  13150. + * by the Free Software Foundation.
  13151. + */
  13152. +
  13153. +#include "ag71xx.h"
  13154. +
  13155. +#define AG71XX_DEFAULT_MSG_ENABLE \
  13156. + ( NETIF_MSG_DRV \
  13157. + | NETIF_MSG_PROBE \
  13158. + | NETIF_MSG_LINK \
  13159. + | NETIF_MSG_TIMER \
  13160. + | NETIF_MSG_IFDOWN \
  13161. + | NETIF_MSG_IFUP \
  13162. + | NETIF_MSG_RX_ERR \
  13163. + | NETIF_MSG_TX_ERR )
  13164. +
  13165. +static int ag71xx_msg_level = -1;
  13166. +
  13167. +module_param_named(msg_level, ag71xx_msg_level, int, 0);
  13168. +MODULE_PARM_DESC(msg_level, "Message level (-1=defaults,0=none,...,16=all)");
  13169. +
  13170. +static void ag71xx_dump_dma_regs(struct ag71xx *ag)
  13171. +{
  13172. + DBG("%s: dma_tx_ctrl=%08x, dma_tx_desc=%08x, dma_tx_status=%08x\n",
  13173. + ag->dev->name,
  13174. + ag71xx_rr(ag, AG71XX_REG_TX_CTRL),
  13175. + ag71xx_rr(ag, AG71XX_REG_TX_DESC),
  13176. + ag71xx_rr(ag, AG71XX_REG_TX_STATUS));
  13177. +
  13178. + DBG("%s: dma_rx_ctrl=%08x, dma_rx_desc=%08x, dma_rx_status=%08x\n",
  13179. + ag->dev->name,
  13180. + ag71xx_rr(ag, AG71XX_REG_RX_CTRL),
  13181. + ag71xx_rr(ag, AG71XX_REG_RX_DESC),
  13182. + ag71xx_rr(ag, AG71XX_REG_RX_STATUS));
  13183. +}
  13184. +
  13185. +static void ag71xx_dump_regs(struct ag71xx *ag)
  13186. +{
  13187. + DBG("%s: mac_cfg1=%08x, mac_cfg2=%08x, ipg=%08x, hdx=%08x, mfl=%08x\n",
  13188. + ag->dev->name,
  13189. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG1),
  13190. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  13191. + ag71xx_rr(ag, AG71XX_REG_MAC_IPG),
  13192. + ag71xx_rr(ag, AG71XX_REG_MAC_HDX),
  13193. + ag71xx_rr(ag, AG71XX_REG_MAC_MFL));
  13194. + DBG("%s: mac_ifctl=%08x, mac_addr1=%08x, mac_addr2=%08x\n",
  13195. + ag->dev->name,
  13196. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  13197. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR1),
  13198. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR2));
  13199. + DBG("%s: fifo_cfg0=%08x, fifo_cfg1=%08x, fifo_cfg2=%08x\n",
  13200. + ag->dev->name,
  13201. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  13202. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  13203. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  13204. + DBG("%s: fifo_cfg3=%08x, fifo_cfg4=%08x, fifo_cfg5=%08x\n",
  13205. + ag->dev->name,
  13206. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  13207. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  13208. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  13209. +}
  13210. +
  13211. +static inline void ag71xx_dump_intr(struct ag71xx *ag, char *label, u32 intr)
  13212. +{
  13213. + DBG("%s: %s intr=%08x %s%s%s%s%s%s\n",
  13214. + ag->dev->name, label, intr,
  13215. + (intr & AG71XX_INT_TX_PS) ? "TXPS " : "",
  13216. + (intr & AG71XX_INT_TX_UR) ? "TXUR " : "",
  13217. + (intr & AG71XX_INT_TX_BE) ? "TXBE " : "",
  13218. + (intr & AG71XX_INT_RX_PR) ? "RXPR " : "",
  13219. + (intr & AG71XX_INT_RX_OF) ? "RXOF " : "",
  13220. + (intr & AG71XX_INT_RX_BE) ? "RXBE " : "");
  13221. +}
  13222. +
  13223. +static void ag71xx_ring_free(struct ag71xx_ring *ring)
  13224. +{
  13225. + kfree(ring->buf);
  13226. +
  13227. + if (ring->descs_cpu)
  13228. + dma_free_coherent(NULL, ring->size * ring->desc_size,
  13229. + ring->descs_cpu, ring->descs_dma);
  13230. +}
  13231. +
  13232. +static int ag71xx_ring_alloc(struct ag71xx_ring *ring, unsigned int size)
  13233. +{
  13234. + int err;
  13235. + int i;
  13236. +
  13237. + ring->desc_size = sizeof(struct ag71xx_desc);
  13238. + if (ring->desc_size % cache_line_size()) {
  13239. + DBG("ag71xx: ring %p, desc size %u rounded to %u\n",
  13240. + ring, ring->desc_size,
  13241. + roundup(ring->desc_size, cache_line_size()));
  13242. + ring->desc_size = roundup(ring->desc_size, cache_line_size());
  13243. + }
  13244. +
  13245. + ring->descs_cpu = dma_alloc_coherent(NULL, size * ring->desc_size,
  13246. + &ring->descs_dma, GFP_ATOMIC);
  13247. + if (!ring->descs_cpu) {
  13248. + err = -ENOMEM;
  13249. + goto err;
  13250. + }
  13251. +
  13252. + ring->size = size;
  13253. +
  13254. + ring->buf = kzalloc(size * sizeof(*ring->buf), GFP_KERNEL);
  13255. + if (!ring->buf) {
  13256. + err = -ENOMEM;
  13257. + goto err;
  13258. + }
  13259. +
  13260. + for (i = 0; i < size; i++) {
  13261. + ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[i * ring->desc_size];
  13262. + DBG("ag71xx: ring %p, desc %d at %p\n",
  13263. + ring, i, ring->buf[i].desc);
  13264. + }
  13265. +
  13266. + return 0;
  13267. +
  13268. + err:
  13269. + return err;
  13270. +}
  13271. +
  13272. +static void ag71xx_ring_tx_clean(struct ag71xx *ag)
  13273. +{
  13274. + struct ag71xx_ring *ring = &ag->tx_ring;
  13275. + struct net_device *dev = ag->dev;
  13276. +
  13277. + while (ring->curr != ring->dirty) {
  13278. + u32 i = ring->dirty % AG71XX_TX_RING_SIZE;
  13279. +
  13280. + if (!ag71xx_desc_empty(ring->buf[i].desc)) {
  13281. + ring->buf[i].desc->ctrl = 0;
  13282. + dev->stats.tx_errors++;
  13283. + }
  13284. +
  13285. + if (ring->buf[i].skb)
  13286. + dev_kfree_skb_any(ring->buf[i].skb);
  13287. +
  13288. + ring->buf[i].skb = NULL;
  13289. +
  13290. + ring->dirty++;
  13291. + }
  13292. +
  13293. + /* flush descriptors */
  13294. + wmb();
  13295. +
  13296. +}
  13297. +
  13298. +static void ag71xx_ring_tx_init(struct ag71xx *ag)
  13299. +{
  13300. + struct ag71xx_ring *ring = &ag->tx_ring;
  13301. + int i;
  13302. +
  13303. + for (i = 0; i < AG71XX_TX_RING_SIZE; i++) {
  13304. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  13305. + ring->desc_size * ((i + 1) % AG71XX_TX_RING_SIZE));
  13306. +
  13307. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13308. + ring->buf[i].skb = NULL;
  13309. + }
  13310. +
  13311. + /* flush descriptors */
  13312. + wmb();
  13313. +
  13314. + ring->curr = 0;
  13315. + ring->dirty = 0;
  13316. +}
  13317. +
  13318. +static void ag71xx_ring_rx_clean(struct ag71xx *ag)
  13319. +{
  13320. + struct ag71xx_ring *ring = &ag->rx_ring;
  13321. + int i;
  13322. +
  13323. + if (!ring->buf)
  13324. + return;
  13325. +
  13326. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++)
  13327. + if (ring->buf[i].skb) {
  13328. + dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
  13329. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  13330. + kfree_skb(ring->buf[i].skb);
  13331. + }
  13332. +}
  13333. +
  13334. +static int ag71xx_rx_reserve(struct ag71xx *ag)
  13335. +{
  13336. + int reserve = 0;
  13337. +
  13338. + if (ag71xx_get_pdata(ag)->is_ar724x) {
  13339. + if (!ag71xx_has_ar8216(ag))
  13340. + reserve = 2;
  13341. +
  13342. + if (ag->phy_dev)
  13343. + reserve += 4 - (ag->phy_dev->pkt_align % 4);
  13344. +
  13345. + reserve %= 4;
  13346. + }
  13347. +
  13348. + return reserve + AG71XX_RX_PKT_RESERVE;
  13349. +}
  13350. +
  13351. +
  13352. +static int ag71xx_ring_rx_init(struct ag71xx *ag)
  13353. +{
  13354. + struct ag71xx_ring *ring = &ag->rx_ring;
  13355. + unsigned int reserve = ag71xx_rx_reserve(ag);
  13356. + unsigned int i;
  13357. + int ret;
  13358. +
  13359. + ret = 0;
  13360. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++) {
  13361. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  13362. + ring->desc_size * ((i + 1) % AG71XX_RX_RING_SIZE));
  13363. +
  13364. + DBG("ag71xx: RX desc at %p, next is %08x\n",
  13365. + ring->buf[i].desc,
  13366. + ring->buf[i].desc->next);
  13367. + }
  13368. +
  13369. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++) {
  13370. + struct sk_buff *skb;
  13371. + dma_addr_t dma_addr;
  13372. +
  13373. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  13374. + if (!skb) {
  13375. + ret = -ENOMEM;
  13376. + break;
  13377. + }
  13378. +
  13379. + skb->dev = ag->dev;
  13380. + skb_reserve(skb, reserve);
  13381. +
  13382. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  13383. + AG71XX_RX_PKT_SIZE,
  13384. + DMA_FROM_DEVICE);
  13385. + ring->buf[i].skb = skb;
  13386. + ring->buf[i].dma_addr = dma_addr;
  13387. + ring->buf[i].desc->data = (u32) dma_addr;
  13388. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13389. + }
  13390. +
  13391. + /* flush descriptors */
  13392. + wmb();
  13393. +
  13394. + ring->curr = 0;
  13395. + ring->dirty = 0;
  13396. +
  13397. + return ret;
  13398. +}
  13399. +
  13400. +static int ag71xx_ring_rx_refill(struct ag71xx *ag)
  13401. +{
  13402. + struct ag71xx_ring *ring = &ag->rx_ring;
  13403. + unsigned int reserve = ag71xx_rx_reserve(ag);
  13404. + unsigned int count;
  13405. +
  13406. + count = 0;
  13407. + for (; ring->curr - ring->dirty > 0; ring->dirty++) {
  13408. + unsigned int i;
  13409. +
  13410. + i = ring->dirty % AG71XX_RX_RING_SIZE;
  13411. +
  13412. + if (ring->buf[i].skb == NULL) {
  13413. + dma_addr_t dma_addr;
  13414. + struct sk_buff *skb;
  13415. +
  13416. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  13417. + if (skb == NULL)
  13418. + break;
  13419. +
  13420. + skb_reserve(skb, reserve);
  13421. + skb->dev = ag->dev;
  13422. +
  13423. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  13424. + AG71XX_RX_PKT_SIZE,
  13425. + DMA_FROM_DEVICE);
  13426. +
  13427. + ring->buf[i].skb = skb;
  13428. + ring->buf[i].dma_addr = dma_addr;
  13429. + ring->buf[i].desc->data = (u32) dma_addr;
  13430. + }
  13431. +
  13432. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13433. + count++;
  13434. + }
  13435. +
  13436. + /* flush descriptors */
  13437. + wmb();
  13438. +
  13439. + DBG("%s: %u rx descriptors refilled\n", ag->dev->name, count);
  13440. +
  13441. + return count;
  13442. +}
  13443. +
  13444. +static int ag71xx_rings_init(struct ag71xx *ag)
  13445. +{
  13446. + int ret;
  13447. +
  13448. + ret = ag71xx_ring_alloc(&ag->tx_ring, AG71XX_TX_RING_SIZE);
  13449. + if (ret)
  13450. + return ret;
  13451. +
  13452. + ag71xx_ring_tx_init(ag);
  13453. +
  13454. + ret = ag71xx_ring_alloc(&ag->rx_ring, AG71XX_RX_RING_SIZE);
  13455. + if (ret)
  13456. + return ret;
  13457. +
  13458. + ret = ag71xx_ring_rx_init(ag);
  13459. + return ret;
  13460. +}
  13461. +
  13462. +static void ag71xx_rings_cleanup(struct ag71xx *ag)
  13463. +{
  13464. + ag71xx_ring_rx_clean(ag);
  13465. + ag71xx_ring_free(&ag->rx_ring);
  13466. +
  13467. + ag71xx_ring_tx_clean(ag);
  13468. + ag71xx_ring_free(&ag->tx_ring);
  13469. +}
  13470. +
  13471. +static unsigned char *ag71xx_speed_str(struct ag71xx *ag)
  13472. +{
  13473. + switch (ag->speed) {
  13474. + case SPEED_1000:
  13475. + return "1000";
  13476. + case SPEED_100:
  13477. + return "100";
  13478. + case SPEED_10:
  13479. + return "10";
  13480. + }
  13481. +
  13482. + return "?";
  13483. +}
  13484. +
  13485. +void ag71xx_link_adjust(struct ag71xx *ag)
  13486. +{
  13487. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13488. + u32 cfg2;
  13489. + u32 ifctl;
  13490. + u32 fifo5;
  13491. + u32 mii_speed;
  13492. +
  13493. + if (!ag->link) {
  13494. + netif_carrier_off(ag->dev);
  13495. + if (netif_msg_link(ag))
  13496. + printk(KERN_INFO "%s: link down\n", ag->dev->name);
  13497. + return;
  13498. + }
  13499. +
  13500. + cfg2 = ag71xx_rr(ag, AG71XX_REG_MAC_CFG2);
  13501. + cfg2 &= ~(MAC_CFG2_IF_1000 | MAC_CFG2_IF_10_100 | MAC_CFG2_FDX);
  13502. + cfg2 |= (ag->duplex) ? MAC_CFG2_FDX : 0;
  13503. +
  13504. + ifctl = ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL);
  13505. + ifctl &= ~(MAC_IFCTL_SPEED);
  13506. +
  13507. + fifo5 = ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5);
  13508. + fifo5 &= ~FIFO_CFG5_BM;
  13509. +
  13510. + switch (ag->speed) {
  13511. + case SPEED_1000:
  13512. + mii_speed = MII_CTRL_SPEED_1000;
  13513. + cfg2 |= MAC_CFG2_IF_1000;
  13514. + fifo5 |= FIFO_CFG5_BM;
  13515. + break;
  13516. + case SPEED_100:
  13517. + mii_speed = MII_CTRL_SPEED_100;
  13518. + cfg2 |= MAC_CFG2_IF_10_100;
  13519. + ifctl |= MAC_IFCTL_SPEED;
  13520. + break;
  13521. + case SPEED_10:
  13522. + mii_speed = MII_CTRL_SPEED_10;
  13523. + cfg2 |= MAC_CFG2_IF_10_100;
  13524. + break;
  13525. + default:
  13526. + BUG();
  13527. + return;
  13528. + }
  13529. +
  13530. + if (pdata->is_ar91xx)
  13531. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x00780fff);
  13532. + else if (pdata->is_ar724x)
  13533. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, pdata->fifo_cfg3);
  13534. + else
  13535. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x008001ff);
  13536. +
  13537. + if (pdata->set_pll)
  13538. + pdata->set_pll(ag->speed);
  13539. +
  13540. + ag71xx_mii_ctrl_set_speed(ag, mii_speed);
  13541. +
  13542. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG2, cfg2);
  13543. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, fifo5);
  13544. + ag71xx_wr(ag, AG71XX_REG_MAC_IFCTL, ifctl);
  13545. +
  13546. + netif_carrier_on(ag->dev);
  13547. + if (netif_msg_link(ag))
  13548. + printk(KERN_INFO "%s: link up (%sMbps/%s duplex)\n",
  13549. + ag->dev->name,
  13550. + ag71xx_speed_str(ag),
  13551. + (DUPLEX_FULL == ag->duplex) ? "Full" : "Half");
  13552. +
  13553. + DBG("%s: fifo_cfg0=%#x, fifo_cfg1=%#x, fifo_cfg2=%#x\n",
  13554. + ag->dev->name,
  13555. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  13556. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  13557. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  13558. +
  13559. + DBG("%s: fifo_cfg3=%#x, fifo_cfg4=%#x, fifo_cfg5=%#x\n",
  13560. + ag->dev->name,
  13561. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  13562. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  13563. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  13564. +
  13565. + DBG("%s: mac_cfg2=%#x, mac_ifctl=%#x, mii_ctrl=%#x\n",
  13566. + ag->dev->name,
  13567. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  13568. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  13569. + ag71xx_mii_ctrl_rr(ag));
  13570. +}
  13571. +
  13572. +static void ag71xx_hw_set_macaddr(struct ag71xx *ag, unsigned char *mac)
  13573. +{
  13574. + u32 t;
  13575. +
  13576. + t = (((u32) mac[5]) << 24) | (((u32) mac[4]) << 16)
  13577. + | (((u32) mac[3]) << 8) | ((u32) mac[2]);
  13578. +
  13579. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR1, t);
  13580. +
  13581. + t = (((u32) mac[1]) << 24) | (((u32) mac[0]) << 16);
  13582. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR2, t);
  13583. +}
  13584. +
  13585. +static void ag71xx_dma_reset(struct ag71xx *ag)
  13586. +{
  13587. + u32 val;
  13588. + int i;
  13589. +
  13590. + ag71xx_dump_dma_regs(ag);
  13591. +
  13592. + /* stop RX and TX */
  13593. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, 0);
  13594. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, 0);
  13595. +
  13596. + /* clear descriptor addresses */
  13597. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, 0);
  13598. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, 0);
  13599. +
  13600. + /* clear pending RX/TX interrupts */
  13601. + for (i = 0; i < 256; i++) {
  13602. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  13603. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  13604. + }
  13605. +
  13606. + /* clear pending errors */
  13607. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE | RX_STATUS_OF);
  13608. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE | TX_STATUS_UR);
  13609. +
  13610. + val = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  13611. + if (val)
  13612. + printk(KERN_ALERT "%s: unable to clear DMA Rx status: %08x\n",
  13613. + ag->dev->name, val);
  13614. +
  13615. + val = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  13616. +
  13617. + /* mask out reserved bits */
  13618. + val &= ~0xff000000;
  13619. +
  13620. + if (val)
  13621. + printk(KERN_ALERT "%s: unable to clear DMA Tx status: %08x\n",
  13622. + ag->dev->name, val);
  13623. +
  13624. + ag71xx_dump_dma_regs(ag);
  13625. +}
  13626. +
  13627. +#define MAC_CFG1_INIT (MAC_CFG1_RXE | MAC_CFG1_TXE | \
  13628. + MAC_CFG1_SRX | MAC_CFG1_STX)
  13629. +
  13630. +#define FIFO_CFG0_INIT (FIFO_CFG0_ALL << FIFO_CFG0_ENABLE_SHIFT)
  13631. +
  13632. +#define FIFO_CFG4_INIT (FIFO_CFG4_DE | FIFO_CFG4_DV | FIFO_CFG4_FC | \
  13633. + FIFO_CFG4_CE | FIFO_CFG4_CR | FIFO_CFG4_LM | \
  13634. + FIFO_CFG4_LO | FIFO_CFG4_OK | FIFO_CFG4_MC | \
  13635. + FIFO_CFG4_BC | FIFO_CFG4_DR | FIFO_CFG4_LE | \
  13636. + FIFO_CFG4_CF | FIFO_CFG4_PF | FIFO_CFG4_UO | \
  13637. + FIFO_CFG4_VT)
  13638. +
  13639. +#define FIFO_CFG5_INIT (FIFO_CFG5_DE | FIFO_CFG5_DV | FIFO_CFG5_FC | \
  13640. + FIFO_CFG5_CE | FIFO_CFG5_LO | FIFO_CFG5_OK | \
  13641. + FIFO_CFG5_MC | FIFO_CFG5_BC | FIFO_CFG5_DR | \
  13642. + FIFO_CFG5_CF | FIFO_CFG5_PF | FIFO_CFG5_VT | \
  13643. + FIFO_CFG5_LE | FIFO_CFG5_FT | FIFO_CFG5_16 | \
  13644. + FIFO_CFG5_17 | FIFO_CFG5_SF)
  13645. +
  13646. +static void ag71xx_hw_init(struct ag71xx *ag)
  13647. +{
  13648. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13649. +
  13650. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_SR);
  13651. + udelay(20);
  13652. +
  13653. + ar71xx_device_stop(pdata->reset_bit);
  13654. + mdelay(100);
  13655. + ar71xx_device_start(pdata->reset_bit);
  13656. + mdelay(100);
  13657. +
  13658. + /* setup MAC configuration registers */
  13659. + if (pdata->is_ar724x)
  13660. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG1,
  13661. + MAC_CFG1_INIT | MAC_CFG1_TFC | MAC_CFG1_RFC);
  13662. + else
  13663. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_INIT);
  13664. +
  13665. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG2,
  13666. + MAC_CFG2_PAD_CRC_EN | MAC_CFG2_LEN_CHECK);
  13667. +
  13668. + /* setup max frame length */
  13669. + ag71xx_wr(ag, AG71XX_REG_MAC_MFL, AG71XX_TX_MTU_LEN);
  13670. +
  13671. + /* setup MII interface type */
  13672. + ag71xx_mii_ctrl_set_if(ag, pdata->mii_if);
  13673. +
  13674. + /* setup FIFO configuration registers */
  13675. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG0, FIFO_CFG0_INIT);
  13676. + if (pdata->is_ar724x) {
  13677. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, pdata->fifo_cfg1);
  13678. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, pdata->fifo_cfg2);
  13679. + } else {
  13680. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, 0x0fff0000);
  13681. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, 0x00001fff);
  13682. + }
  13683. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG4, FIFO_CFG4_INIT);
  13684. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, FIFO_CFG5_INIT);
  13685. +
  13686. + ag71xx_dma_reset(ag);
  13687. +}
  13688. +
  13689. +static void ag71xx_hw_start(struct ag71xx *ag)
  13690. +{
  13691. + /* start RX engine */
  13692. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  13693. +
  13694. + /* enable interrupts */
  13695. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, AG71XX_INT_INIT);
  13696. +}
  13697. +
  13698. +static void ag71xx_hw_stop(struct ag71xx *ag)
  13699. +{
  13700. + /* disable all interrupts */
  13701. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, 0);
  13702. +
  13703. + ag71xx_dma_reset(ag);
  13704. +}
  13705. +
  13706. +static int ag71xx_open(struct net_device *dev)
  13707. +{
  13708. + struct ag71xx *ag = netdev_priv(dev);
  13709. + int ret;
  13710. +
  13711. + ret = ag71xx_rings_init(ag);
  13712. + if (ret)
  13713. + goto err;
  13714. +
  13715. + napi_enable(&ag->napi);
  13716. +
  13717. + netif_carrier_off(dev);
  13718. + ag71xx_phy_start(ag);
  13719. +
  13720. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, ag->tx_ring.descs_dma);
  13721. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, ag->rx_ring.descs_dma);
  13722. +
  13723. + ag71xx_hw_set_macaddr(ag, dev->dev_addr);
  13724. +
  13725. + ag71xx_hw_start(ag);
  13726. +
  13727. + netif_start_queue(dev);
  13728. +
  13729. + return 0;
  13730. +
  13731. + err:
  13732. + ag71xx_rings_cleanup(ag);
  13733. + return ret;
  13734. +}
  13735. +
  13736. +static int ag71xx_stop(struct net_device *dev)
  13737. +{
  13738. + struct ag71xx *ag = netdev_priv(dev);
  13739. + unsigned long flags;
  13740. +
  13741. + netif_carrier_off(dev);
  13742. + ag71xx_phy_stop(ag);
  13743. +
  13744. + spin_lock_irqsave(&ag->lock, flags);
  13745. +
  13746. + netif_stop_queue(dev);
  13747. +
  13748. + ag71xx_hw_stop(ag);
  13749. +
  13750. + napi_disable(&ag->napi);
  13751. + del_timer_sync(&ag->oom_timer);
  13752. +
  13753. + spin_unlock_irqrestore(&ag->lock, flags);
  13754. +
  13755. + ag71xx_rings_cleanup(ag);
  13756. +
  13757. + return 0;
  13758. +}
  13759. +
  13760. +static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
  13761. + struct net_device *dev)
  13762. +{
  13763. + struct ag71xx *ag = netdev_priv(dev);
  13764. + struct ag71xx_ring *ring = &ag->tx_ring;
  13765. + struct ag71xx_desc *desc;
  13766. + dma_addr_t dma_addr;
  13767. + int i;
  13768. +
  13769. + i = ring->curr % AG71XX_TX_RING_SIZE;
  13770. + desc = ring->buf[i].desc;
  13771. +
  13772. + if (!ag71xx_desc_empty(desc))
  13773. + goto err_drop;
  13774. +
  13775. + if (ag71xx_has_ar8216(ag))
  13776. + ag71xx_add_ar8216_header(ag, skb);
  13777. +
  13778. + if (skb->len <= 0) {
  13779. + DBG("%s: packet len is too small\n", ag->dev->name);
  13780. + goto err_drop;
  13781. + }
  13782. +
  13783. + dma_addr = dma_map_single(&dev->dev, skb->data, skb->len,
  13784. + DMA_TO_DEVICE);
  13785. +
  13786. + ring->buf[i].skb = skb;
  13787. +
  13788. + /* setup descriptor fields */
  13789. + desc->data = (u32) dma_addr;
  13790. + desc->ctrl = (skb->len & DESC_PKTLEN_M);
  13791. +
  13792. + /* flush descriptor */
  13793. + wmb();
  13794. +
  13795. + ring->curr++;
  13796. + if (ring->curr == (ring->dirty + AG71XX_TX_THRES_STOP)) {
  13797. + DBG("%s: tx queue full\n", ag->dev->name);
  13798. + netif_stop_queue(dev);
  13799. + }
  13800. +
  13801. + DBG("%s: packet injected into TX queue\n", ag->dev->name);
  13802. +
  13803. + /* enable TX engine */
  13804. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, TX_CTRL_TXE);
  13805. +
  13806. + return NETDEV_TX_OK;
  13807. +
  13808. + err_drop:
  13809. + dev->stats.tx_dropped++;
  13810. +
  13811. + dev_kfree_skb(skb);
  13812. + return NETDEV_TX_OK;
  13813. +}
  13814. +
  13815. +static int ag71xx_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  13816. +{
  13817. + struct mii_ioctl_data *data = (struct mii_ioctl_data *) &ifr->ifr_data;
  13818. + struct ag71xx *ag = netdev_priv(dev);
  13819. + int ret;
  13820. +
  13821. + switch (cmd) {
  13822. + case SIOCETHTOOL:
  13823. + if (ag->phy_dev == NULL)
  13824. + break;
  13825. +
  13826. + spin_lock_irq(&ag->lock);
  13827. + ret = phy_ethtool_ioctl(ag->phy_dev, (void *) ifr->ifr_data);
  13828. + spin_unlock_irq(&ag->lock);
  13829. + return ret;
  13830. +
  13831. + case SIOCSIFHWADDR:
  13832. + if (copy_from_user
  13833. + (dev->dev_addr, ifr->ifr_data, sizeof(dev->dev_addr)))
  13834. + return -EFAULT;
  13835. + return 0;
  13836. +
  13837. + case SIOCGIFHWADDR:
  13838. + if (copy_to_user
  13839. + (ifr->ifr_data, dev->dev_addr, sizeof(dev->dev_addr)))
  13840. + return -EFAULT;
  13841. + return 0;
  13842. +
  13843. + case SIOCGMIIPHY:
  13844. + case SIOCGMIIREG:
  13845. + case SIOCSMIIREG:
  13846. + if (ag->phy_dev == NULL)
  13847. + break;
  13848. +
  13849. + return phy_mii_ioctl(ag->phy_dev, data, cmd);
  13850. +
  13851. + default:
  13852. + break;
  13853. + }
  13854. +
  13855. + return -EOPNOTSUPP;
  13856. +}
  13857. +
  13858. +static void ag71xx_oom_timer_handler(unsigned long data)
  13859. +{
  13860. + struct net_device *dev = (struct net_device *) data;
  13861. + struct ag71xx *ag = netdev_priv(dev);
  13862. +
  13863. + napi_schedule(&ag->napi);
  13864. +}
  13865. +
  13866. +static void ag71xx_tx_timeout(struct net_device *dev)
  13867. +{
  13868. + struct ag71xx *ag = netdev_priv(dev);
  13869. +
  13870. + if (netif_msg_tx_err(ag))
  13871. + printk(KERN_DEBUG "%s: tx timeout\n", ag->dev->name);
  13872. +
  13873. + schedule_work(&ag->restart_work);
  13874. +}
  13875. +
  13876. +static void ag71xx_restart_work_func(struct work_struct *work)
  13877. +{
  13878. + struct ag71xx *ag = container_of(work, struct ag71xx, restart_work);
  13879. +
  13880. + ag71xx_stop(ag->dev);
  13881. + ag71xx_open(ag->dev);
  13882. +}
  13883. +
  13884. +static int ag71xx_tx_packets(struct ag71xx *ag)
  13885. +{
  13886. + struct ag71xx_ring *ring = &ag->tx_ring;
  13887. + int sent;
  13888. +
  13889. + DBG("%s: processing TX ring\n", ag->dev->name);
  13890. +
  13891. + sent = 0;
  13892. + while (ring->dirty != ring->curr) {
  13893. + unsigned int i = ring->dirty % AG71XX_TX_RING_SIZE;
  13894. + struct ag71xx_desc *desc = ring->buf[i].desc;
  13895. + struct sk_buff *skb = ring->buf[i].skb;
  13896. +
  13897. + if (!ag71xx_desc_empty(desc))
  13898. + break;
  13899. +
  13900. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  13901. +
  13902. + ag->dev->stats.tx_bytes += skb->len;
  13903. + ag->dev->stats.tx_packets++;
  13904. +
  13905. + dev_kfree_skb_any(skb);
  13906. + ring->buf[i].skb = NULL;
  13907. +
  13908. + ring->dirty++;
  13909. + sent++;
  13910. + }
  13911. +
  13912. + DBG("%s: %d packets sent out\n", ag->dev->name, sent);
  13913. +
  13914. + if ((ring->curr - ring->dirty) < AG71XX_TX_THRES_WAKEUP)
  13915. + netif_wake_queue(ag->dev);
  13916. +
  13917. + return sent;
  13918. +}
  13919. +
  13920. +static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
  13921. +{
  13922. + struct net_device *dev = ag->dev;
  13923. + struct ag71xx_ring *ring = &ag->rx_ring;
  13924. + int done = 0;
  13925. +
  13926. + DBG("%s: rx packets, limit=%d, curr=%u, dirty=%u\n",
  13927. + dev->name, limit, ring->curr, ring->dirty);
  13928. +
  13929. + while (done < limit) {
  13930. + unsigned int i = ring->curr % AG71XX_RX_RING_SIZE;
  13931. + struct ag71xx_desc *desc = ring->buf[i].desc;
  13932. + struct sk_buff *skb;
  13933. + int pktlen;
  13934. + int err = 0;
  13935. +
  13936. + if (ag71xx_desc_empty(desc))
  13937. + break;
  13938. +
  13939. + if ((ring->dirty + AG71XX_RX_RING_SIZE) == ring->curr) {
  13940. + ag71xx_assert(0);
  13941. + break;
  13942. + }
  13943. +
  13944. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  13945. +
  13946. + skb = ring->buf[i].skb;
  13947. + pktlen = ag71xx_desc_pktlen(desc);
  13948. + pktlen -= ETH_FCS_LEN;
  13949. +
  13950. + dma_unmap_single(&dev->dev, ring->buf[i].dma_addr,
  13951. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  13952. +
  13953. + dev->last_rx = jiffies;
  13954. + dev->stats.rx_packets++;
  13955. + dev->stats.rx_bytes += pktlen;
  13956. +
  13957. + skb_put(skb, pktlen);
  13958. + if (ag71xx_has_ar8216(ag))
  13959. + err = ag71xx_remove_ar8216_header(ag, skb, pktlen);
  13960. +
  13961. + if (err) {
  13962. + dev->stats.rx_dropped++;
  13963. + kfree_skb(skb);
  13964. + } else {
  13965. + skb->dev = dev;
  13966. + skb->ip_summed = CHECKSUM_NONE;
  13967. + if (ag->phy_dev) {
  13968. + ag->phy_dev->netif_receive_skb(skb);
  13969. + } else {
  13970. + skb->protocol = eth_type_trans(skb, dev);
  13971. + netif_receive_skb(skb);
  13972. + }
  13973. + }
  13974. +
  13975. + ring->buf[i].skb = NULL;
  13976. + done++;
  13977. +
  13978. + ring->curr++;
  13979. + }
  13980. +
  13981. + ag71xx_ring_rx_refill(ag);
  13982. +
  13983. + DBG("%s: rx finish, curr=%u, dirty=%u, done=%d\n",
  13984. + dev->name, ring->curr, ring->dirty, done);
  13985. +
  13986. + return done;
  13987. +}
  13988. +
  13989. +static int ag71xx_poll(struct napi_struct *napi, int limit)
  13990. +{
  13991. + struct ag71xx *ag = container_of(napi, struct ag71xx, napi);
  13992. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13993. + struct net_device *dev = ag->dev;
  13994. + struct ag71xx_ring *rx_ring;
  13995. + unsigned long flags;
  13996. + u32 status;
  13997. + int tx_done;
  13998. + int rx_done;
  13999. +
  14000. + pdata->ddr_flush();
  14001. + tx_done = ag71xx_tx_packets(ag);
  14002. +
  14003. + DBG("%s: processing RX ring\n", dev->name);
  14004. + rx_done = ag71xx_rx_packets(ag, limit);
  14005. +
  14006. + ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done);
  14007. +
  14008. + rx_ring = &ag->rx_ring;
  14009. + if (rx_ring->buf[rx_ring->dirty % AG71XX_RX_RING_SIZE].skb == NULL)
  14010. + goto oom;
  14011. +
  14012. + status = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  14013. + if (unlikely(status & RX_STATUS_OF)) {
  14014. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_OF);
  14015. + dev->stats.rx_fifo_errors++;
  14016. +
  14017. + /* restart RX */
  14018. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  14019. + }
  14020. +
  14021. + if (rx_done < limit) {
  14022. + if (status & RX_STATUS_PR)
  14023. + goto more;
  14024. +
  14025. + status = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  14026. + if (status & TX_STATUS_PS)
  14027. + goto more;
  14028. +
  14029. + DBG("%s: disable polling mode, rx=%d, tx=%d,limit=%d\n",
  14030. + dev->name, rx_done, tx_done, limit);
  14031. +
  14032. + napi_complete(napi);
  14033. +
  14034. + /* enable interrupts */
  14035. + spin_lock_irqsave(&ag->lock, flags);
  14036. + ag71xx_int_enable(ag, AG71XX_INT_POLL);
  14037. + spin_unlock_irqrestore(&ag->lock, flags);
  14038. + return rx_done;
  14039. + }
  14040. +
  14041. + more:
  14042. + DBG("%s: stay in polling mode, rx=%d, tx=%d, limit=%d\n",
  14043. + dev->name, rx_done, tx_done, limit);
  14044. + return rx_done;
  14045. +
  14046. + oom:
  14047. + if (netif_msg_rx_err(ag))
  14048. + printk(KERN_DEBUG "%s: out of memory\n", dev->name);
  14049. +
  14050. + mod_timer(&ag->oom_timer, jiffies + AG71XX_OOM_REFILL);
  14051. + napi_complete(napi);
  14052. + return 0;
  14053. +}
  14054. +
  14055. +static irqreturn_t ag71xx_interrupt(int irq, void *dev_id)
  14056. +{
  14057. + struct net_device *dev = dev_id;
  14058. + struct ag71xx *ag = netdev_priv(dev);
  14059. + u32 status;
  14060. +
  14061. + status = ag71xx_rr(ag, AG71XX_REG_INT_STATUS);
  14062. + ag71xx_dump_intr(ag, "raw", status);
  14063. +
  14064. + if (unlikely(!status))
  14065. + return IRQ_NONE;
  14066. +
  14067. + if (unlikely(status & AG71XX_INT_ERR)) {
  14068. + if (status & AG71XX_INT_TX_BE) {
  14069. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE);
  14070. + dev_err(&dev->dev, "TX BUS error\n");
  14071. + }
  14072. + if (status & AG71XX_INT_RX_BE) {
  14073. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE);
  14074. + dev_err(&dev->dev, "RX BUS error\n");
  14075. + }
  14076. + }
  14077. +
  14078. + if (likely(status & AG71XX_INT_POLL)) {
  14079. + ag71xx_int_disable(ag, AG71XX_INT_POLL);
  14080. + DBG("%s: enable polling mode\n", dev->name);
  14081. + napi_schedule(&ag->napi);
  14082. + }
  14083. +
  14084. + ag71xx_debugfs_update_int_stats(ag, status);
  14085. +
  14086. + return IRQ_HANDLED;
  14087. +}
  14088. +
  14089. +static void ag71xx_set_multicast_list(struct net_device *dev)
  14090. +{
  14091. + /* TODO */
  14092. +}
  14093. +
  14094. +#ifdef CONFIG_NET_POLL_CONTROLLER
  14095. +/*
  14096. + * Polling 'interrupt' - used by things like netconsole to send skbs
  14097. + * without having to re-enable interrupts. It's not called while
  14098. + * the interrupt routine is executing.
  14099. + */
  14100. +static void ag71xx_netpoll(struct net_device *dev)
  14101. +{
  14102. + disable_irq(dev->irq);
  14103. + ag71xx_interrupt(dev->irq, dev);
  14104. + enable_irq(dev->irq);
  14105. +}
  14106. +#endif
  14107. +
  14108. +static const struct net_device_ops ag71xx_netdev_ops = {
  14109. + .ndo_open = ag71xx_open,
  14110. + .ndo_stop = ag71xx_stop,
  14111. + .ndo_start_xmit = ag71xx_hard_start_xmit,
  14112. + .ndo_set_multicast_list = ag71xx_set_multicast_list,
  14113. + .ndo_do_ioctl = ag71xx_do_ioctl,
  14114. + .ndo_tx_timeout = ag71xx_tx_timeout,
  14115. + .ndo_change_mtu = eth_change_mtu,
  14116. + .ndo_set_mac_address = eth_mac_addr,
  14117. + .ndo_validate_addr = eth_validate_addr,
  14118. +#ifdef CONFIG_NET_POLL_CONTROLLER
  14119. + .ndo_poll_controller = ag71xx_netpoll,
  14120. +#endif
  14121. +};
  14122. +
  14123. +static int __init ag71xx_probe(struct platform_device *pdev)
  14124. +{
  14125. + struct net_device *dev;
  14126. + struct resource *res;
  14127. + struct ag71xx *ag;
  14128. + struct ag71xx_platform_data *pdata;
  14129. + int err;
  14130. +
  14131. + pdata = pdev->dev.platform_data;
  14132. + if (!pdata) {
  14133. + dev_err(&pdev->dev, "no platform data specified\n");
  14134. + err = -ENXIO;
  14135. + goto err_out;
  14136. + }
  14137. +
  14138. + if (pdata->mii_bus_dev == NULL) {
  14139. + dev_err(&pdev->dev, "no MII bus device specified\n");
  14140. + err = -EINVAL;
  14141. + goto err_out;
  14142. + }
  14143. +
  14144. + dev = alloc_etherdev(sizeof(*ag));
  14145. + if (!dev) {
  14146. + dev_err(&pdev->dev, "alloc_etherdev failed\n");
  14147. + err = -ENOMEM;
  14148. + goto err_out;
  14149. + }
  14150. +
  14151. + SET_NETDEV_DEV(dev, &pdev->dev);
  14152. +
  14153. + ag = netdev_priv(dev);
  14154. + ag->pdev = pdev;
  14155. + ag->dev = dev;
  14156. + ag->msg_enable = netif_msg_init(ag71xx_msg_level,
  14157. + AG71XX_DEFAULT_MSG_ENABLE);
  14158. + spin_lock_init(&ag->lock);
  14159. +
  14160. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mac_base");
  14161. + if (!res) {
  14162. + dev_err(&pdev->dev, "no mac_base resource found\n");
  14163. + err = -ENXIO;
  14164. + goto err_out;
  14165. + }
  14166. +
  14167. + ag->mac_base = ioremap_nocache(res->start, res->end - res->start + 1);
  14168. + if (!ag->mac_base) {
  14169. + dev_err(&pdev->dev, "unable to ioremap mac_base\n");
  14170. + err = -ENOMEM;
  14171. + goto err_free_dev;
  14172. + }
  14173. +
  14174. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mii_ctrl");
  14175. + if (!res) {
  14176. + dev_err(&pdev->dev, "no mii_ctrl resource found\n");
  14177. + err = -ENXIO;
  14178. + goto err_unmap_base;
  14179. + }
  14180. +
  14181. + ag->mii_ctrl = ioremap_nocache(res->start, res->end - res->start + 1);
  14182. + if (!ag->mii_ctrl) {
  14183. + dev_err(&pdev->dev, "unable to ioremap mii_ctrl\n");
  14184. + err = -ENOMEM;
  14185. + goto err_unmap_base;
  14186. + }
  14187. +
  14188. + dev->irq = platform_get_irq(pdev, 0);
  14189. + err = request_irq(dev->irq, ag71xx_interrupt,
  14190. + IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  14191. + dev->name, dev);
  14192. + if (err) {
  14193. + dev_err(&pdev->dev, "unable to request IRQ %d\n", dev->irq);
  14194. + goto err_unmap_mii_ctrl;
  14195. + }
  14196. +
  14197. + dev->base_addr = (unsigned long)ag->mac_base;
  14198. + dev->netdev_ops = &ag71xx_netdev_ops;
  14199. + dev->ethtool_ops = &ag71xx_ethtool_ops;
  14200. +
  14201. + INIT_WORK(&ag->restart_work, ag71xx_restart_work_func);
  14202. +
  14203. + init_timer(&ag->oom_timer);
  14204. + ag->oom_timer.data = (unsigned long) dev;
  14205. + ag->oom_timer.function = ag71xx_oom_timer_handler;
  14206. +
  14207. + memcpy(dev->dev_addr, pdata->mac_addr, ETH_ALEN);
  14208. +
  14209. + netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
  14210. +
  14211. + err = register_netdev(dev);
  14212. + if (err) {
  14213. + dev_err(&pdev->dev, "unable to register net device\n");
  14214. + goto err_free_irq;
  14215. + }
  14216. +
  14217. + printk(KERN_INFO "%s: Atheros AG71xx at 0x%08lx, irq %d\n",
  14218. + dev->name, dev->base_addr, dev->irq);
  14219. +
  14220. + ag71xx_dump_regs(ag);
  14221. +
  14222. + ag71xx_hw_init(ag);
  14223. +
  14224. + ag71xx_dump_regs(ag);
  14225. +
  14226. + err = ag71xx_phy_connect(ag);
  14227. + if (err)
  14228. + goto err_unregister_netdev;
  14229. +
  14230. + err = ag71xx_debugfs_init(ag);
  14231. + if (err)
  14232. + goto err_phy_disconnect;
  14233. +
  14234. + platform_set_drvdata(pdev, dev);
  14235. +
  14236. + return 0;
  14237. +
  14238. + err_phy_disconnect:
  14239. + ag71xx_phy_disconnect(ag);
  14240. + err_unregister_netdev:
  14241. + unregister_netdev(dev);
  14242. + err_free_irq:
  14243. + free_irq(dev->irq, dev);
  14244. + err_unmap_mii_ctrl:
  14245. + iounmap(ag->mii_ctrl);
  14246. + err_unmap_base:
  14247. + iounmap(ag->mac_base);
  14248. + err_free_dev:
  14249. + kfree(dev);
  14250. + err_out:
  14251. + platform_set_drvdata(pdev, NULL);
  14252. + return err;
  14253. +}
  14254. +
  14255. +static int __exit ag71xx_remove(struct platform_device *pdev)
  14256. +{
  14257. + struct net_device *dev = platform_get_drvdata(pdev);
  14258. +
  14259. + if (dev) {
  14260. + struct ag71xx *ag = netdev_priv(dev);
  14261. +
  14262. + ag71xx_debugfs_exit(ag);
  14263. + ag71xx_phy_disconnect(ag);
  14264. + unregister_netdev(dev);
  14265. + free_irq(dev->irq, dev);
  14266. + iounmap(ag->mii_ctrl);
  14267. + iounmap(ag->mac_base);
  14268. + kfree(dev);
  14269. + platform_set_drvdata(pdev, NULL);
  14270. + }
  14271. +
  14272. + return 0;
  14273. +}
  14274. +
  14275. +static struct platform_driver ag71xx_driver = {
  14276. + .probe = ag71xx_probe,
  14277. + .remove = __exit_p(ag71xx_remove),
  14278. + .driver = {
  14279. + .name = AG71XX_DRV_NAME,
  14280. + }
  14281. +};
  14282. +
  14283. +static int __init ag71xx_module_init(void)
  14284. +{
  14285. + int ret;
  14286. +
  14287. + ret = ag71xx_debugfs_root_init();
  14288. + if (ret)
  14289. + goto err_out;
  14290. +
  14291. + ret = ag71xx_mdio_driver_init();
  14292. + if (ret)
  14293. + goto err_debugfs_exit;
  14294. +
  14295. + ret = platform_driver_register(&ag71xx_driver);
  14296. + if (ret)
  14297. + goto err_mdio_exit;
  14298. +
  14299. + return 0;
  14300. +
  14301. + err_mdio_exit:
  14302. + ag71xx_mdio_driver_exit();
  14303. + err_debugfs_exit:
  14304. + ag71xx_debugfs_root_exit();
  14305. + err_out:
  14306. + return ret;
  14307. +}
  14308. +
  14309. +static void __exit ag71xx_module_exit(void)
  14310. +{
  14311. + platform_driver_unregister(&ag71xx_driver);
  14312. + ag71xx_mdio_driver_exit();
  14313. + ag71xx_debugfs_root_exit();
  14314. +}
  14315. +
  14316. +module_init(ag71xx_module_init);
  14317. +module_exit(ag71xx_module_exit);
  14318. +
  14319. +MODULE_VERSION(AG71XX_DRV_VERSION);
  14320. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  14321. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  14322. +MODULE_LICENSE("GPL v2");
  14323. +MODULE_ALIAS("platform:" AG71XX_DRV_NAME);
  14324. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_mdio.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_mdio.c
  14325. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_mdio.c 1970-01-01 01:00:00.000000000 +0100
  14326. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_mdio.c 2010-01-05 20:38:53.413280204 +0100
  14327. @@ -0,0 +1,243 @@
  14328. +/*
  14329. + * Atheros AR71xx built-in ethernet mac driver
  14330. + *
  14331. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  14332. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  14333. + *
  14334. + * Based on Atheros' AG7100 driver
  14335. + *
  14336. + * This program is free software; you can redistribute it and/or modify it
  14337. + * under the terms of the GNU General Public License version 2 as published
  14338. + * by the Free Software Foundation.
  14339. + */
  14340. +
  14341. +#include "ag71xx.h"
  14342. +
  14343. +#define AG71XX_MDIO_RETRY 1000
  14344. +#define AG71XX_MDIO_DELAY 5
  14345. +
  14346. +static inline void ag71xx_mdio_wr(struct ag71xx_mdio *am, unsigned reg,
  14347. + u32 value)
  14348. +{
  14349. + void __iomem *r;
  14350. +
  14351. + r = am->mdio_base + reg;
  14352. + __raw_writel(value, r);
  14353. +
  14354. + /* flush write */
  14355. + (void) __raw_readl(r);
  14356. +}
  14357. +
  14358. +static inline u32 ag71xx_mdio_rr(struct ag71xx_mdio *am, unsigned reg)
  14359. +{
  14360. + return __raw_readl(am->mdio_base + reg);
  14361. +}
  14362. +
  14363. +static void ag71xx_mdio_dump_regs(struct ag71xx_mdio *am)
  14364. +{
  14365. + DBG("%s: mii_cfg=%08x, mii_cmd=%08x, mii_addr=%08x\n",
  14366. + am->mii_bus->name,
  14367. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CFG),
  14368. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CMD),
  14369. + ag71xx_mdio_rr(am, AG71XX_REG_MII_ADDR));
  14370. + DBG("%s: mii_ctrl=%08x, mii_status=%08x, mii_ind=%08x\n",
  14371. + am->mii_bus->name,
  14372. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CTRL),
  14373. + ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS),
  14374. + ag71xx_mdio_rr(am, AG71XX_REG_MII_IND));
  14375. +}
  14376. +
  14377. +static int ag71xx_mdio_mii_read(struct ag71xx_mdio *am, int addr, int reg)
  14378. +{
  14379. + int ret;
  14380. + int i;
  14381. +
  14382. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  14383. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  14384. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  14385. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_READ);
  14386. +
  14387. + i = AG71XX_MDIO_RETRY;
  14388. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  14389. + if (i-- == 0) {
  14390. + printk(KERN_ERR "%s: mii_read timed out\n",
  14391. + am->mii_bus->name);
  14392. + ret = 0xffff;
  14393. + goto out;
  14394. + }
  14395. + udelay(AG71XX_MDIO_DELAY);
  14396. + }
  14397. +
  14398. + ret = ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS) & 0xffff;
  14399. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  14400. +
  14401. + DBG("mii_read: addr=%04x, reg=%04x, value=%04x\n", addr, reg, ret);
  14402. +
  14403. + out:
  14404. + return ret;
  14405. +}
  14406. +
  14407. +static void ag71xx_mdio_mii_write(struct ag71xx_mdio *am,
  14408. + int addr, int reg, u16 val)
  14409. +{
  14410. + int i;
  14411. +
  14412. + DBG("mii_write: addr=%04x, reg=%04x, value=%04x\n", addr, reg, val);
  14413. +
  14414. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  14415. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  14416. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CTRL, val);
  14417. +
  14418. + i = AG71XX_MDIO_RETRY;
  14419. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  14420. + if (i-- == 0) {
  14421. + printk(KERN_ERR "%s: mii_write timed out\n",
  14422. + am->mii_bus->name);
  14423. + break;
  14424. + }
  14425. + udelay(AG71XX_MDIO_DELAY);
  14426. + }
  14427. +}
  14428. +
  14429. +static int ag71xx_mdio_reset(struct mii_bus *bus)
  14430. +{
  14431. + struct ag71xx_mdio *am = bus->priv;
  14432. + u32 t;
  14433. +
  14434. + if (am->pdata->is_ar7240)
  14435. + t = MII_CFG_CLK_DIV_6;
  14436. + else
  14437. + t = MII_CFG_CLK_DIV_28;
  14438. +
  14439. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t | MII_CFG_RESET);
  14440. + udelay(100);
  14441. +
  14442. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t);
  14443. + udelay(100);
  14444. +
  14445. + return 0;
  14446. +}
  14447. +
  14448. +static int ag71xx_mdio_read(struct mii_bus *bus, int addr, int reg)
  14449. +{
  14450. + struct ag71xx_mdio *am = bus->priv;
  14451. +
  14452. + return ag71xx_mdio_mii_read(am, addr, reg);
  14453. +}
  14454. +
  14455. +static int ag71xx_mdio_write(struct mii_bus *bus, int addr, int reg, u16 val)
  14456. +{
  14457. + struct ag71xx_mdio *am = bus->priv;
  14458. +
  14459. + ag71xx_mdio_mii_write(am, addr, reg, val);
  14460. + return 0;
  14461. +}
  14462. +
  14463. +static int __init ag71xx_mdio_probe(struct platform_device *pdev)
  14464. +{
  14465. + struct ag71xx_mdio_platform_data *pdata;
  14466. + struct ag71xx_mdio *am;
  14467. + struct resource *res;
  14468. + int i;
  14469. + int err;
  14470. +
  14471. + pdata = pdev->dev.platform_data;
  14472. + if (!pdata) {
  14473. + dev_err(&pdev->dev, "no platform data specified\n");
  14474. + return -EINVAL;
  14475. + }
  14476. +
  14477. + am = kzalloc(sizeof(*am), GFP_KERNEL);
  14478. + if (!am) {
  14479. + err = -ENOMEM;
  14480. + goto err_out;
  14481. + }
  14482. +
  14483. + am->pdata = pdata;
  14484. +
  14485. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  14486. + if (!res) {
  14487. + dev_err(&pdev->dev, "no iomem resource found\n");
  14488. + err = -ENXIO;
  14489. + goto err_out;
  14490. + }
  14491. +
  14492. + am->mdio_base = ioremap_nocache(res->start, res->end - res->start + 1);
  14493. + if (!am->mdio_base) {
  14494. + dev_err(&pdev->dev, "unable to ioremap registers\n");
  14495. + err = -ENOMEM;
  14496. + goto err_free_mdio;
  14497. + }
  14498. +
  14499. + am->mii_bus = mdiobus_alloc();
  14500. + if (am->mii_bus == NULL) {
  14501. + err = -ENOMEM;
  14502. + goto err_iounmap;
  14503. + }
  14504. +
  14505. + am->mii_bus->name = "ag71xx_mdio";
  14506. + am->mii_bus->read = ag71xx_mdio_read;
  14507. + am->mii_bus->write = ag71xx_mdio_write;
  14508. + am->mii_bus->reset = ag71xx_mdio_reset;
  14509. + am->mii_bus->irq = am->mii_irq;
  14510. + am->mii_bus->priv = am;
  14511. + am->mii_bus->parent = &pdev->dev;
  14512. + snprintf(am->mii_bus->id, MII_BUS_ID_SIZE, "%s", dev_name(&pdev->dev));
  14513. + am->mii_bus->phy_mask = pdata->phy_mask;
  14514. +
  14515. + for (i = 0; i < PHY_MAX_ADDR; i++)
  14516. + am->mii_irq[i] = PHY_POLL;
  14517. +
  14518. + ag71xx_mdio_wr(am, AG71XX_REG_MAC_CFG1, 0);
  14519. +
  14520. + err = mdiobus_register(am->mii_bus);
  14521. + if (err)
  14522. + goto err_free_bus;
  14523. +
  14524. + ag71xx_mdio_dump_regs(am);
  14525. +
  14526. + platform_set_drvdata(pdev, am);
  14527. + return 0;
  14528. +
  14529. + err_free_bus:
  14530. + mdiobus_free(am->mii_bus);
  14531. + err_iounmap:
  14532. + iounmap(am->mdio_base);
  14533. + err_free_mdio:
  14534. + kfree(am);
  14535. + err_out:
  14536. + return err;
  14537. +}
  14538. +
  14539. +static int __exit ag71xx_mdio_remove(struct platform_device *pdev)
  14540. +{
  14541. + struct ag71xx_mdio *am = platform_get_drvdata(pdev);
  14542. +
  14543. + if (am) {
  14544. + mdiobus_unregister(am->mii_bus);
  14545. + mdiobus_free(am->mii_bus);
  14546. + iounmap(am->mdio_base);
  14547. + kfree(am);
  14548. + platform_set_drvdata(pdev, NULL);
  14549. + }
  14550. +
  14551. + return 0;
  14552. +}
  14553. +
  14554. +static struct platform_driver ag71xx_mdio_driver = {
  14555. + .probe = ag71xx_mdio_probe,
  14556. + .remove = __exit_p(ag71xx_mdio_remove),
  14557. + .driver = {
  14558. + .name = "ag71xx-mdio",
  14559. + }
  14560. +};
  14561. +
  14562. +int ag71xx_mdio_driver_init(void)
  14563. +{
  14564. + return platform_driver_register(&ag71xx_mdio_driver);
  14565. +}
  14566. +
  14567. +void ag71xx_mdio_driver_exit(void)
  14568. +{
  14569. + platform_driver_unregister(&ag71xx_mdio_driver);
  14570. +}
  14571. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_phy.c linux-2.6.33.3/drivers/net/ag71xx/ag71xx_phy.c
  14572. --- linux-2.6.33.3.orig/drivers/net/ag71xx/ag71xx_phy.c 1970-01-01 01:00:00.000000000 +0100
  14573. +++ linux-2.6.33.3/drivers/net/ag71xx/ag71xx_phy.c 2010-03-23 20:31:06.040706961 +0100
  14574. @@ -0,0 +1,213 @@
  14575. +/*
  14576. + * Atheros AR71xx built-in ethernet mac driver
  14577. + *
  14578. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  14579. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  14580. + *
  14581. + * Based on Atheros' AG7100 driver
  14582. + *
  14583. + * This program is free software; you can redistribute it and/or modify it
  14584. + * under the terms of the GNU General Public License version 2 as published
  14585. + * by the Free Software Foundation.
  14586. + */
  14587. +
  14588. +#include "ag71xx.h"
  14589. +
  14590. +static void ag71xx_phy_link_adjust(struct net_device *dev)
  14591. +{
  14592. + struct ag71xx *ag = netdev_priv(dev);
  14593. + struct phy_device *phydev = ag->phy_dev;
  14594. + unsigned long flags;
  14595. + int status_change = 0;
  14596. +
  14597. + spin_lock_irqsave(&ag->lock, flags);
  14598. +
  14599. + if (phydev->link) {
  14600. + if (ag->duplex != phydev->duplex
  14601. + || ag->speed != phydev->speed) {
  14602. + status_change = 1;
  14603. + }
  14604. + }
  14605. +
  14606. + if (phydev->link != ag->link)
  14607. + status_change = 1;
  14608. +
  14609. + ag->link = phydev->link;
  14610. + ag->duplex = phydev->duplex;
  14611. + ag->speed = phydev->speed;
  14612. +
  14613. + if (status_change)
  14614. + ag71xx_link_adjust(ag);
  14615. +
  14616. + spin_unlock_irqrestore(&ag->lock, flags);
  14617. +}
  14618. +
  14619. +void ag71xx_phy_start(struct ag71xx *ag)
  14620. +{
  14621. + if (ag->phy_dev) {
  14622. + phy_start(ag->phy_dev);
  14623. + } else {
  14624. + ag->link = 1;
  14625. + ag71xx_link_adjust(ag);
  14626. + }
  14627. +}
  14628. +
  14629. +void ag71xx_phy_stop(struct ag71xx *ag)
  14630. +{
  14631. + if (ag->phy_dev) {
  14632. + phy_stop(ag->phy_dev);
  14633. + } else {
  14634. + ag->link = 0;
  14635. + ag71xx_link_adjust(ag);
  14636. + }
  14637. +}
  14638. +
  14639. +static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
  14640. +{
  14641. + struct net_device *dev = ag->dev;
  14642. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14643. + int ret = 0;
  14644. +
  14645. + /* use fixed settings */
  14646. + switch (pdata->speed) {
  14647. + case SPEED_10:
  14648. + case SPEED_100:
  14649. + case SPEED_1000:
  14650. + break;
  14651. + default:
  14652. + printk(KERN_ERR "%s: invalid speed specified\n", dev->name);
  14653. + ret = -EINVAL;
  14654. + break;
  14655. + }
  14656. +
  14657. + printk(KERN_DEBUG "%s: using fixed link parameters\n", dev->name);
  14658. +
  14659. + ag->duplex = pdata->duplex;
  14660. + ag->speed = pdata->speed;
  14661. +
  14662. + return ret;
  14663. +}
  14664. +
  14665. +static int ag71xx_phy_connect_multi(struct ag71xx *ag)
  14666. +{
  14667. + struct net_device *dev = ag->dev;
  14668. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14669. + struct phy_device *phydev = NULL;
  14670. + int phy_addr;
  14671. + int ret = 0;
  14672. +
  14673. + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
  14674. + if (!(pdata->phy_mask & (1 << phy_addr)))
  14675. + continue;
  14676. +
  14677. + if (ag->mii_bus->phy_map[phy_addr] == NULL)
  14678. + continue;
  14679. +
  14680. + DBG("%s: PHY found at %s, uid=%08x\n",
  14681. + dev->name,
  14682. + dev_name(&ag->mii_bus->phy_map[phy_addr]->dev),
  14683. + ag->mii_bus->phy_map[phy_addr]->phy_id);
  14684. +
  14685. + if (phydev == NULL)
  14686. + phydev = ag->mii_bus->phy_map[phy_addr];
  14687. + }
  14688. +
  14689. + if (!phydev) {
  14690. + printk(KERN_ERR "%s: no PHY found with phy_mask=%08x\n",
  14691. + dev->name, pdata->phy_mask);
  14692. + return -ENODEV;
  14693. + }
  14694. +
  14695. + ag->phy_dev = phy_connect(dev, dev_name(&phydev->dev),
  14696. + &ag71xx_phy_link_adjust, 0,
  14697. + pdata->phy_if_mode);
  14698. +
  14699. + if (IS_ERR(ag->phy_dev)) {
  14700. + printk(KERN_ERR "%s: could not connect to PHY at %s\n",
  14701. + dev->name, dev_name(&phydev->dev));
  14702. + return PTR_ERR(ag->phy_dev);
  14703. + }
  14704. +
  14705. + /* mask with MAC supported features */
  14706. + if (pdata->has_gbit)
  14707. + phydev->supported &= PHY_GBIT_FEATURES;
  14708. + else
  14709. + phydev->supported &= PHY_BASIC_FEATURES;
  14710. +
  14711. + phydev->advertising = phydev->supported;
  14712. +
  14713. + printk(KERN_DEBUG "%s: connected to PHY at %s [uid=%08x, driver=%s]\n",
  14714. + dev->name, dev_name(&phydev->dev),
  14715. + phydev->phy_id, phydev->drv->name);
  14716. +
  14717. + ag->link = 0;
  14718. + ag->speed = 0;
  14719. + ag->duplex = -1;
  14720. +
  14721. + return ret;
  14722. +}
  14723. +
  14724. +static int dev_is_class(struct device *dev, void *class)
  14725. +{
  14726. + if (dev->class != NULL && !strcmp(dev->class->name, class))
  14727. + return 1;
  14728. +
  14729. + return 0;
  14730. +}
  14731. +
  14732. +static struct device *dev_find_class(struct device *parent, char *class)
  14733. +{
  14734. + if (dev_is_class(parent, class)) {
  14735. + get_device(parent);
  14736. + return parent;
  14737. + }
  14738. +
  14739. + return device_find_child(parent, class, dev_is_class);
  14740. +}
  14741. +
  14742. +static struct mii_bus *dev_to_mii_bus(struct device *dev)
  14743. +{
  14744. + struct device *d;
  14745. +
  14746. + d = dev_find_class(dev, "mdio_bus");
  14747. + if (d != NULL) {
  14748. + struct mii_bus *bus;
  14749. +
  14750. + bus = to_mii_bus(d);
  14751. + put_device(d);
  14752. +
  14753. + return bus;
  14754. + }
  14755. +
  14756. + return NULL;
  14757. +}
  14758. +
  14759. +int ag71xx_phy_connect(struct ag71xx *ag)
  14760. +{
  14761. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14762. +
  14763. + ag->mii_bus = dev_to_mii_bus(pdata->mii_bus_dev);
  14764. + if (ag->mii_bus == NULL) {
  14765. + printk(KERN_ERR "%s: unable to find MII bus on device '%s'\n",
  14766. + ag->dev->name, dev_name(pdata->mii_bus_dev));
  14767. + return -ENODEV;
  14768. + }
  14769. +
  14770. + /* Reset the mdio bus explicitly */
  14771. + if (ag->mii_bus->reset) {
  14772. + mutex_lock(&ag->mii_bus->mdio_lock);
  14773. + ag->mii_bus->reset(ag->mii_bus);
  14774. + mutex_unlock(&ag->mii_bus->mdio_lock);
  14775. + }
  14776. +
  14777. + if (pdata->phy_mask)
  14778. + return ag71xx_phy_connect_multi(ag);
  14779. +
  14780. + return ag71xx_phy_connect_fixed(ag);
  14781. +}
  14782. +
  14783. +void ag71xx_phy_disconnect(struct ag71xx *ag)
  14784. +{
  14785. + if (ag->phy_dev)
  14786. + phy_disconnect(ag->phy_dev);
  14787. +}
  14788. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/Kconfig linux-2.6.33.3/drivers/net/ag71xx/Kconfig
  14789. --- linux-2.6.33.3.orig/drivers/net/ag71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  14790. +++ linux-2.6.33.3/drivers/net/ag71xx/Kconfig 2010-04-02 11:07:52.574971060 +0200
  14791. @@ -0,0 +1,33 @@
  14792. +config AG71XX
  14793. + tristate "Atheros AR71xx built-in ethernet mac support"
  14794. + depends on ATHEROS_AR71XX
  14795. + select PHYLIB
  14796. + help
  14797. + If you wish to compile a kernel for AR71xx/91xx and enable
  14798. + ethernet support, then you should always answer Y to this.
  14799. +
  14800. +if AG71XX
  14801. +
  14802. +config AG71XX_DEBUG
  14803. + bool "Atheros AR71xx built-in ethernet driver debugging"
  14804. + default n
  14805. + help
  14806. + Atheros AR71xx built-in ethernet driver debugging messages.
  14807. +
  14808. +config AG71XX_DEBUG_FS
  14809. + bool "Atheros AR71xx built-in ethernet driver debugfs support"
  14810. + depends on DEBUG_FS
  14811. + default n
  14812. + help
  14813. + Say Y, if you need access to various statistics provided by
  14814. + the ag71xx driver.
  14815. +
  14816. +config AG71XX_AR8216_SUPPORT
  14817. + bool "special support for the Atheros AR8216 switch"
  14818. + default n
  14819. + default y if AR71XX_MACH_WNR2000 || AR71XX_MACH_MZK_W04NU
  14820. + help
  14821. + Say 'y' here if you want to enable special support for the
  14822. + Atheros AR8216 switch found on some boards.
  14823. +
  14824. +endif
  14825. diff -Nur linux-2.6.33.3.orig/drivers/net/ag71xx/Makefile linux-2.6.33.3/drivers/net/ag71xx/Makefile
  14826. --- linux-2.6.33.3.orig/drivers/net/ag71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  14827. +++ linux-2.6.33.3/drivers/net/ag71xx/Makefile 2010-01-05 20:38:53.413280204 +0100
  14828. @@ -0,0 +1,14 @@
  14829. +#
  14830. +# Makefile for the Atheros AR71xx built-in ethernet macs
  14831. +#
  14832. +
  14833. +ag71xx-y += ag71xx_main.o
  14834. +ag71xx-y += ag71xx_ethtool.o
  14835. +ag71xx-y += ag71xx_phy.o
  14836. +ag71xx-y += ag71xx_mdio.o
  14837. +
  14838. +ag71xx-$(CONFIG_AG71XX_DEBUG_FS) += ag71xx_debugfs.o
  14839. +ag71xx-$(CONFIG_AG71XX_AR8216_SUPPORT) += ag71xx_ar8216.o
  14840. +
  14841. +obj-$(CONFIG_AG71XX) += ag71xx.o
  14842. +
  14843. diff -Nur linux-2.6.33.3.orig/drivers/net/Kconfig linux-2.6.33.3/drivers/net/Kconfig
  14844. --- linux-2.6.33.3.orig/drivers/net/Kconfig 2010-04-26 16:48:30.000000000 +0200
  14845. +++ linux-2.6.33.3/drivers/net/Kconfig 2010-05-17 16:28:38.519115009 +0200
  14846. @@ -2005,6 +2005,8 @@
  14847. The safe and default value for this is N.
  14848. +source drivers/net/ag71xx/Kconfig
  14849. +
  14850. config DL2K
  14851. tristate "DL2000/TC902x-based Gigabit Ethernet support"
  14852. depends on PCI
  14853. diff -Nur linux-2.6.33.3.orig/drivers/net/Makefile linux-2.6.33.3/drivers/net/Makefile
  14854. --- linux-2.6.33.3.orig/drivers/net/Makefile 2010-04-26 16:48:30.000000000 +0200
  14855. +++ linux-2.6.33.3/drivers/net/Makefile 2010-05-17 16:28:38.519115009 +0200
  14856. @@ -106,6 +106,7 @@
  14857. # end link order section
  14858. #
  14859. +obj-$(CONFIG_AG71XX) += ag71xx/
  14860. obj-$(CONFIG_SUNDANCE) += sundance.o
  14861. obj-$(CONFIG_HAMACHI) += hamachi.o
  14862. obj-$(CONFIG_NET) += Space.o loopback.o
  14863. diff -Nur linux-2.6.33.3.orig/drivers/net/phy/Kconfig linux-2.6.33.3/drivers/net/phy/Kconfig
  14864. --- linux-2.6.33.3.orig/drivers/net/phy/Kconfig 2010-04-26 16:48:30.000000000 +0200
  14865. +++ linux-2.6.33.3/drivers/net/phy/Kconfig 2010-05-17 22:25:24.119127715 +0200
  14866. @@ -88,6 +88,10 @@
  14867. ---help---
  14868. Supports the LSI ET1011C PHY.
  14869. +config IP175C_PHY
  14870. + tristate "Driver for IC+ IP175C/IP178C switches"
  14871. + select SWCONFIG
  14872. +
  14873. config FIXED_PHY
  14874. bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
  14875. depends on PHYLIB=y
  14876. diff -Nur linux-2.6.33.3.orig/drivers/net/phy/micrel.c linux-2.6.33.3/drivers/net/phy/micrel.c
  14877. --- linux-2.6.33.3.orig/drivers/net/phy/micrel.c 1970-01-01 01:00:00.000000000 +0100
  14878. +++ linux-2.6.33.3/drivers/net/phy/micrel.c 2009-12-13 20:45:24.083925758 +0100
  14879. @@ -0,0 +1,82 @@
  14880. +/*
  14881. + * Driver for Micrel/Kendin PHYs
  14882. + *
  14883. + * Copyright (c) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  14884. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  14885. + *
  14886. + * This program is free software; you can redistribute it and/or modify it
  14887. + * under the terms of the GNU General Public License version 2 as published
  14888. + * by the Free Software Foundation.
  14889. + *
  14890. + */
  14891. +
  14892. +#include <linux/delay.h>
  14893. +#include <linux/skbuff.h>
  14894. +#include <linux/phy.h>
  14895. +
  14896. +#define KSZ_REG_INT_CTRL 0x1b
  14897. +
  14898. +#define KSZ_INT_LU_EN (1 << 8) /* enable Link Up interrupt */
  14899. +#define KSZ_INT_RF_EN (1 << 9) /* enable Remote Fault interrupt */
  14900. +#define KSZ_INT_LD_EN (1 << 10) /* enable Link Down interrupt */
  14901. +
  14902. +#define KSZ_INT_INIT (KSZ_INT_LU_EN | KSZ_INT_LD_EN)
  14903. +
  14904. +static int ksz8041_ack_interrupt(struct phy_device *phydev)
  14905. +{
  14906. + int err;
  14907. +
  14908. + err = phy_read(phydev, KSZ_REG_INT_CTRL);
  14909. +
  14910. + return (err < 0) ? err : 0;
  14911. +}
  14912. +
  14913. +static int ksz8041_config_intr(struct phy_device *phydev)
  14914. +{
  14915. + int err;
  14916. +
  14917. + if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  14918. + err = phy_write(phydev, KSZ_REG_INT_CTRL,
  14919. + KSZ_INT_INIT);
  14920. + else
  14921. + err = phy_write(phydev, KSZ_REG_INT_CTRL, 0);
  14922. +
  14923. + return err;
  14924. +}
  14925. +
  14926. +static struct phy_driver ksz8041_phy_driver = {
  14927. + .phy_id = 0x00221512,
  14928. + .name = "Micrel KSZ8041",
  14929. + .phy_id_mask = 0x001fffff,
  14930. + .features = PHY_BASIC_FEATURES,
  14931. + .flags = PHY_HAS_INTERRUPT,
  14932. + .config_aneg = genphy_config_aneg,
  14933. + .read_status = genphy_read_status,
  14934. + .ack_interrupt = ksz8041_ack_interrupt,
  14935. + .config_intr = ksz8041_config_intr,
  14936. + .driver = {
  14937. + .owner = THIS_MODULE,
  14938. + },
  14939. +};
  14940. +
  14941. +static int __init micrel_phy_init(void)
  14942. +{
  14943. + return phy_driver_register(&ksz8041_phy_driver);
  14944. +}
  14945. +
  14946. +static void __exit micrel_phy_exit(void)
  14947. +{
  14948. + phy_driver_unregister(&ksz8041_phy_driver);
  14949. +}
  14950. +
  14951. +#ifdef MODULE
  14952. +module_init(micrel_phy_init);
  14953. +module_exit(micrel_phy_exit);
  14954. +#else
  14955. +subsys_initcall(micrel_phy_init);
  14956. +#endif
  14957. +
  14958. +MODULE_DESCRIPTION("Micrel/Kendin PHY driver");
  14959. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  14960. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  14961. +MODULE_LICENSE("GPL v2");
  14962. diff -Nur linux-2.6.33.3.orig/drivers/net/phy/phy.c linux-2.6.33.3/drivers/net/phy/phy.c
  14963. --- linux-2.6.33.3.orig/drivers/net/phy/phy.c 2010-04-26 16:48:30.000000000 +0200
  14964. +++ linux-2.6.33.3/drivers/net/phy/phy.c 2010-05-17 21:40:09.635111896 +0200
  14965. @@ -299,6 +299,50 @@
  14966. }
  14967. EXPORT_SYMBOL(phy_ethtool_gset);
  14968. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
  14969. +{
  14970. + u32 cmd;
  14971. + int tmp;
  14972. + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  14973. + struct ethtool_value edata = { ETHTOOL_GLINK };
  14974. +
  14975. + if (get_user(cmd, (u32 *) useraddr))
  14976. + return -EFAULT;
  14977. +
  14978. + switch (cmd) {
  14979. + case ETHTOOL_GSET:
  14980. + phy_ethtool_gset(phydev, &ecmd);
  14981. + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  14982. + return -EFAULT;
  14983. + return 0;
  14984. +
  14985. + case ETHTOOL_SSET:
  14986. + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  14987. + return -EFAULT;
  14988. + return phy_ethtool_sset(phydev, &ecmd);
  14989. +
  14990. + case ETHTOOL_NWAY_RST:
  14991. + /* if autoneg is off, it's an error */
  14992. + tmp = phy_read(phydev, MII_BMCR);
  14993. + if (tmp & BMCR_ANENABLE) {
  14994. + tmp |= (BMCR_ANRESTART);
  14995. + phy_write(phydev, MII_BMCR, tmp);
  14996. + return 0;
  14997. + }
  14998. + return -EINVAL;
  14999. +
  15000. + case ETHTOOL_GLINK:
  15001. + edata.data = (phy_read(phydev,
  15002. + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
  15003. + if (copy_to_user(useraddr, &edata, sizeof(edata)))
  15004. + return -EFAULT;
  15005. + return 0;
  15006. + }
  15007. +
  15008. + return -EOPNOTSUPP;
  15009. +}
  15010. +EXPORT_SYMBOL(phy_ethtool_ioctl);
  15011. +
  15012. /**
  15013. * phy_mii_ioctl - generic PHY MII ioctl interface
  15014. * @phydev: the phy_device struct
  15015. @@ -352,7 +396,7 @@
  15016. }
  15017. phy_write(phydev, mii_data->reg_num, val);
  15018. -
  15019. +
  15020. if (mii_data->reg_num == MII_BMCR &&
  15021. val & BMCR_RESET &&
  15022. phydev->drv->config_init) {
  15023. @@ -466,7 +510,7 @@
  15024. int idx;
  15025. idx = phy_find_setting(phydev->speed, phydev->duplex);
  15026. -
  15027. +
  15028. idx++;
  15029. idx = phy_find_valid(idx, phydev->supported);
  15030. diff -Nur linux-2.6.33.3.orig/drivers/net/phy/phy_device.c linux-2.6.33.3/drivers/net/phy/phy_device.c
  15031. --- linux-2.6.33.3.orig/drivers/net/phy/phy_device.c 2010-04-26 16:48:30.000000000 +0200
  15032. +++ linux-2.6.33.3/drivers/net/phy/phy_device.c 2010-05-17 21:40:17.019371728 +0200
  15033. @@ -146,6 +146,18 @@
  15034. }
  15035. EXPORT_SYMBOL(phy_scan_fixups);
  15036. +static int generic_receive_skb(struct sk_buff *skb)
  15037. +{
  15038. + skb->protocol = eth_type_trans(skb, skb->dev);
  15039. + return netif_receive_skb(skb);
  15040. +}
  15041. +
  15042. +static int generic_rx(struct sk_buff *skb)
  15043. +{
  15044. + skb->protocol = eth_type_trans(skb, skb->dev);
  15045. + return netif_rx(skb);
  15046. +}
  15047. +
  15048. struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
  15049. {
  15050. struct phy_device *dev;
  15051. @@ -175,6 +187,8 @@
  15052. dev_set_name(&dev->dev, PHY_ID_FMT, bus->id, addr);
  15053. dev->state = PHY_DOWN;
  15054. + dev->netif_receive_skb = &generic_receive_skb;
  15055. + dev->netif_rx = &generic_rx;
  15056. mutex_init(&dev->lock);
  15057. INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
  15058. diff -Nur linux-2.6.33.3.orig/drivers/spi/ap83_spi.c linux-2.6.33.3/drivers/spi/ap83_spi.c
  15059. --- linux-2.6.33.3.orig/drivers/spi/ap83_spi.c 1970-01-01 01:00:00.000000000 +0100
  15060. +++ linux-2.6.33.3/drivers/spi/ap83_spi.c 2009-12-13 20:45:24.855922705 +0100
  15061. @@ -0,0 +1,282 @@
  15062. +/*
  15063. + * Atheros AP83 board specific SPI Controller driver
  15064. + *
  15065. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  15066. + *
  15067. + * This program is free software; you can redistribute it and/or modify
  15068. + * it under the terms of the GNU General Public License version 2 as
  15069. + * published by the Free Software Foundation.
  15070. + *
  15071. + */
  15072. +
  15073. +#include <linux/kernel.h>
  15074. +#include <linux/init.h>
  15075. +#include <linux/delay.h>
  15076. +#include <linux/spinlock.h>
  15077. +#include <linux/workqueue.h>
  15078. +#include <linux/platform_device.h>
  15079. +#include <linux/io.h>
  15080. +#include <linux/spi/spi.h>
  15081. +#include <linux/spi/spi_bitbang.h>
  15082. +#include <linux/bitops.h>
  15083. +#include <linux/gpio.h>
  15084. +
  15085. +#include <asm/mach-ar71xx/ar71xx.h>
  15086. +#include <asm/mach-ar71xx/platform.h>
  15087. +
  15088. +#define DRV_DESC "Atheros AP83 board SPI Controller driver"
  15089. +#define DRV_VERSION "0.1.0"
  15090. +#define DRV_NAME "ap83-spi"
  15091. +
  15092. +#define AP83_SPI_CLK_HIGH (1 << 23)
  15093. +#define AP83_SPI_CLK_LOW 0
  15094. +#define AP83_SPI_MOSI_HIGH (1 << 22)
  15095. +#define AP83_SPI_MOSI_LOW 0
  15096. +
  15097. +#define AP83_SPI_GPIO_CS 1
  15098. +#define AP83_SPI_GPIO_MISO 3
  15099. +
  15100. +struct ap83_spi {
  15101. + struct spi_bitbang bitbang;
  15102. + void __iomem *base;
  15103. + u32 addr;
  15104. +
  15105. + struct platform_device *pdev;
  15106. +};
  15107. +
  15108. +static inline u32 ap83_spi_rr(struct ap83_spi *sp, u32 reg)
  15109. +{
  15110. + return __raw_readl(sp->base + reg);
  15111. +}
  15112. +
  15113. +static inline struct ap83_spi *spidev_to_sp(struct spi_device *spi)
  15114. +{
  15115. + return spi_master_get_devdata(spi->master);
  15116. +}
  15117. +
  15118. +static inline void setsck(struct spi_device *spi, int val)
  15119. +{
  15120. + struct ap83_spi *sp = spidev_to_sp(spi);
  15121. +
  15122. + if (val)
  15123. + sp->addr |= AP83_SPI_CLK_HIGH;
  15124. + else
  15125. + sp->addr &= ~AP83_SPI_CLK_HIGH;
  15126. +
  15127. + dev_dbg(&spi->dev, "addr=%08x, SCK set to %s\n",
  15128. + sp->addr, (val) ? "HIGH" : "LOW");
  15129. +
  15130. + ap83_spi_rr(sp, sp->addr);
  15131. +}
  15132. +
  15133. +static inline void setmosi(struct spi_device *spi, int val)
  15134. +{
  15135. + struct ap83_spi *sp = spidev_to_sp(spi);
  15136. +
  15137. + if (val)
  15138. + sp->addr |= AP83_SPI_MOSI_HIGH;
  15139. + else
  15140. + sp->addr &= ~AP83_SPI_MOSI_HIGH;
  15141. +
  15142. + dev_dbg(&spi->dev, "addr=%08x, MOSI set to %s\n",
  15143. + sp->addr, (val) ? "HIGH" : "LOW");
  15144. +
  15145. + ap83_spi_rr(sp, sp->addr);
  15146. +}
  15147. +
  15148. +static inline u32 getmiso(struct spi_device *spi)
  15149. +{
  15150. + u32 ret;
  15151. +
  15152. + ret = gpio_get_value(AP83_SPI_GPIO_MISO) ? 1 : 0;
  15153. + dev_dbg(&spi->dev, "get MISO: %d\n", ret);
  15154. +
  15155. + return ret;
  15156. +}
  15157. +
  15158. +static inline void do_spidelay(struct spi_device *spi, unsigned nsecs)
  15159. +{
  15160. + ndelay(nsecs);
  15161. +}
  15162. +
  15163. +static void ap83_spi_chipselect(struct spi_device *spi, int on)
  15164. +{
  15165. + struct ap83_spi *sp = spidev_to_sp(spi);
  15166. +
  15167. + dev_dbg(&spi->dev, "set CS to %d\n", (on) ? 0 : 1);
  15168. +
  15169. + if (on) {
  15170. + ar71xx_flash_acquire();
  15171. +
  15172. + sp->addr = 0;
  15173. + ap83_spi_rr(sp, sp->addr);
  15174. +
  15175. + gpio_set_value(AP83_SPI_GPIO_CS, 0);
  15176. + } else {
  15177. + gpio_set_value(AP83_SPI_GPIO_CS, 1);
  15178. + ar71xx_flash_release();
  15179. + }
  15180. +}
  15181. +
  15182. +#define spidelay(nsecs) \
  15183. + do { \
  15184. + /* Steal the spi_device pointer from our caller. \
  15185. + * The bitbang-API should probably get fixed here... */ \
  15186. + do_spidelay(spi, nsecs); \
  15187. + } while (0)
  15188. +
  15189. +#define EXPAND_BITBANG_TXRX
  15190. +#include <linux/spi/spi_bitbang.h>
  15191. +
  15192. +static u32 ap83_spi_txrx_mode0(struct spi_device *spi,
  15193. + unsigned nsecs, u32 word, u8 bits)
  15194. +{
  15195. + dev_dbg(&spi->dev, "TXRX0 word=%08x, bits=%u\n", word, bits);
  15196. + return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  15197. +}
  15198. +
  15199. +static u32 ap83_spi_txrx_mode1(struct spi_device *spi,
  15200. + unsigned nsecs, u32 word, u8 bits)
  15201. +{
  15202. + dev_dbg(&spi->dev, "TXRX1 word=%08x, bits=%u\n", word, bits);
  15203. + return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
  15204. +}
  15205. +
  15206. +static u32 ap83_spi_txrx_mode2(struct spi_device *spi,
  15207. + unsigned nsecs, u32 word, u8 bits)
  15208. +{
  15209. + dev_dbg(&spi->dev, "TXRX2 word=%08x, bits=%u\n", word, bits);
  15210. + return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
  15211. +}
  15212. +
  15213. +static u32 ap83_spi_txrx_mode3(struct spi_device *spi,
  15214. + unsigned nsecs, u32 word, u8 bits)
  15215. +{
  15216. + dev_dbg(&spi->dev, "TXRX3 word=%08x, bits=%u\n", word, bits);
  15217. + return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
  15218. +}
  15219. +
  15220. +static int ap83_spi_probe(struct platform_device *pdev)
  15221. +{
  15222. + struct spi_master *master;
  15223. + struct ap83_spi *sp;
  15224. + struct ap83_spi_platform_data *pdata;
  15225. + struct resource *r;
  15226. + int ret;
  15227. +
  15228. + ret = gpio_request(AP83_SPI_GPIO_MISO, "spi-miso");
  15229. + if (ret) {
  15230. + dev_err(&pdev->dev, "gpio request failed for MISO\n");
  15231. + return ret;
  15232. + }
  15233. +
  15234. + ret = gpio_request(AP83_SPI_GPIO_CS, "spi-cs");
  15235. + if (ret) {
  15236. + dev_err(&pdev->dev, "gpio request failed for CS\n");
  15237. + goto err_free_miso;
  15238. + }
  15239. +
  15240. + ret = gpio_direction_input(AP83_SPI_GPIO_MISO);
  15241. + if (ret) {
  15242. + dev_err(&pdev->dev, "unable to set direction of MISO\n");
  15243. + goto err_free_cs;
  15244. + }
  15245. +
  15246. + ret = gpio_direction_output(AP83_SPI_GPIO_CS, 0);
  15247. + if (ret) {
  15248. + dev_err(&pdev->dev, "unable to set direction of CS\n");
  15249. + goto err_free_cs;
  15250. + }
  15251. +
  15252. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15253. + if (master == NULL) {
  15254. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15255. + return -ENOMEM;
  15256. + }
  15257. +
  15258. + sp = spi_master_get_devdata(master);
  15259. + platform_set_drvdata(pdev, sp);
  15260. +
  15261. + pdata = pdev->dev.platform_data;
  15262. +
  15263. + sp->bitbang.master = spi_master_get(master);
  15264. + sp->bitbang.chipselect = ap83_spi_chipselect;
  15265. + sp->bitbang.txrx_word[SPI_MODE_0] = ap83_spi_txrx_mode0;
  15266. + sp->bitbang.txrx_word[SPI_MODE_1] = ap83_spi_txrx_mode1;
  15267. + sp->bitbang.txrx_word[SPI_MODE_2] = ap83_spi_txrx_mode2;
  15268. + sp->bitbang.txrx_word[SPI_MODE_3] = ap83_spi_txrx_mode3;
  15269. +
  15270. + sp->bitbang.master->bus_num = pdev->id;
  15271. + sp->bitbang.master->num_chipselect = 1;
  15272. +
  15273. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15274. + if (r == NULL) {
  15275. + ret = -ENOENT;
  15276. + goto err_spi_put;
  15277. + }
  15278. +
  15279. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15280. + if (!sp->base) {
  15281. + ret = -ENXIO;
  15282. + goto err_spi_put;
  15283. + }
  15284. +
  15285. + ret = spi_bitbang_start(&sp->bitbang);
  15286. + if (!ret)
  15287. + goto err_unmap;
  15288. +
  15289. + dev_info(&pdev->dev, "AP83 SPI adapter at %08x\n", r->start);
  15290. +
  15291. + return 0;
  15292. +
  15293. + err_unmap:
  15294. + iounmap(sp->base);
  15295. + err_spi_put:
  15296. + platform_set_drvdata(pdev, NULL);
  15297. + spi_master_put(sp->bitbang.master);
  15298. +
  15299. + err_free_cs:
  15300. + gpio_free(AP83_SPI_GPIO_CS);
  15301. + err_free_miso:
  15302. + gpio_free(AP83_SPI_GPIO_MISO);
  15303. + return ret;
  15304. +}
  15305. +
  15306. +static int ap83_spi_remove(struct platform_device *pdev)
  15307. +{
  15308. + struct ap83_spi *sp = platform_get_drvdata(pdev);
  15309. +
  15310. + spi_bitbang_stop(&sp->bitbang);
  15311. + iounmap(sp->base);
  15312. + platform_set_drvdata(pdev, NULL);
  15313. + spi_master_put(sp->bitbang.master);
  15314. +
  15315. + return 0;
  15316. +}
  15317. +
  15318. +static struct platform_driver ap83_spi_drv = {
  15319. + .probe = ap83_spi_probe,
  15320. + .remove = ap83_spi_remove,
  15321. + .driver = {
  15322. + .name = DRV_NAME,
  15323. + .owner = THIS_MODULE,
  15324. + },
  15325. +};
  15326. +
  15327. +static int __init ap83_spi_init(void)
  15328. +{
  15329. + return platform_driver_register(&ap83_spi_drv);
  15330. +}
  15331. +module_init(ap83_spi_init);
  15332. +
  15333. +static void __exit ap83_spi_exit(void)
  15334. +{
  15335. + platform_driver_unregister(&ap83_spi_drv);
  15336. +}
  15337. +module_exit(ap83_spi_exit);
  15338. +
  15339. +MODULE_ALIAS("platform:" DRV_NAME);
  15340. +MODULE_DESCRIPTION(DRV_DESC);
  15341. +MODULE_VERSION(DRV_VERSION);
  15342. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15343. +MODULE_LICENSE("GPL v2");
  15344. diff -Nur linux-2.6.33.3.orig/drivers/spi/ar71xx_spi.c linux-2.6.33.3/drivers/spi/ar71xx_spi.c
  15345. --- linux-2.6.33.3.orig/drivers/spi/ar71xx_spi.c 1970-01-01 01:00:00.000000000 +0100
  15346. +++ linux-2.6.33.3/drivers/spi/ar71xx_spi.c 2009-12-13 20:45:24.851921034 +0100
  15347. @@ -0,0 +1,283 @@
  15348. +/*
  15349. + * Atheros AR71xx SPI Controller driver
  15350. + *
  15351. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  15352. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  15353. + *
  15354. + * This program is free software; you can redistribute it and/or modify
  15355. + * it under the terms of the GNU General Public License version 2 as
  15356. + * published by the Free Software Foundation.
  15357. + *
  15358. + */
  15359. +
  15360. +#include <linux/kernel.h>
  15361. +#include <linux/init.h>
  15362. +#include <linux/delay.h>
  15363. +#include <linux/spinlock.h>
  15364. +#include <linux/workqueue.h>
  15365. +#include <linux/platform_device.h>
  15366. +#include <linux/io.h>
  15367. +#include <linux/spi/spi.h>
  15368. +#include <linux/spi/spi_bitbang.h>
  15369. +#include <linux/bitops.h>
  15370. +
  15371. +#include <asm/mach-ar71xx/ar71xx.h>
  15372. +#include <asm/mach-ar71xx/platform.h>
  15373. +
  15374. +#define DRV_DESC "Atheros AR71xx SPI Controller driver"
  15375. +#define DRV_VERSION "0.2.4"
  15376. +#define DRV_NAME "ar71xx-spi"
  15377. +
  15378. +#undef PER_BIT_READ
  15379. +
  15380. +struct ar71xx_spi {
  15381. + struct spi_bitbang bitbang;
  15382. + u32 ioc_base;
  15383. + u32 reg_ctrl;
  15384. +
  15385. + void __iomem *base;
  15386. +
  15387. + struct platform_device *pdev;
  15388. + u32 (*get_ioc_base)(u8 chip_select, int cs_high,
  15389. + int is_on);
  15390. +};
  15391. +
  15392. +static inline u32 ar71xx_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  15393. +{
  15394. + return __raw_readl(sp->base + reg);
  15395. +}
  15396. +
  15397. +static inline void ar71xx_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  15398. +{
  15399. + __raw_writel(val, sp->base + reg);
  15400. +}
  15401. +
  15402. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  15403. +{
  15404. + return spi_master_get_devdata(spi->master);
  15405. +}
  15406. +
  15407. +static u32 ar71xx_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
  15408. +{
  15409. + u32 ret;
  15410. +
  15411. + if (is_on == AR71XX_SPI_CS_INACTIVE)
  15412. + ret = SPI_IOC_CS_ALL;
  15413. + else
  15414. + ret = SPI_IOC_CS_ALL & ~SPI_IOC_CS(chip_select);
  15415. +
  15416. + return ret;
  15417. +}
  15418. +
  15419. +static void ar71xx_spi_chipselect(struct spi_device *spi, int value)
  15420. +{
  15421. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15422. + void __iomem *base = sp->base;
  15423. + u32 ioc_base;
  15424. +
  15425. + switch (value) {
  15426. + case BITBANG_CS_INACTIVE:
  15427. + ioc_base = sp->get_ioc_base(spi->chip_select,
  15428. + (spi->mode & SPI_CS_HIGH) != 0,
  15429. + AR71XX_SPI_CS_INACTIVE);
  15430. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  15431. + break;
  15432. +
  15433. + case BITBANG_CS_ACTIVE:
  15434. + ioc_base = sp->get_ioc_base(spi->chip_select,
  15435. + (spi->mode & SPI_CS_HIGH) != 0,
  15436. + AR71XX_SPI_CS_ACTIVE);
  15437. +
  15438. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  15439. + sp->ioc_base = ioc_base;
  15440. + break;
  15441. + }
  15442. +}
  15443. +
  15444. +static void ar71xx_spi_setup_regs(struct spi_device *spi)
  15445. +{
  15446. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15447. +
  15448. + /* enable GPIO mode */
  15449. + ar71xx_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  15450. +
  15451. + /* save CTRL register */
  15452. + sp->reg_ctrl = ar71xx_spi_rr(sp, SPI_REG_CTRL);
  15453. +
  15454. + /* TODO: setup speed? */
  15455. + ar71xx_spi_wr(sp, SPI_REG_CTRL, 0x43);
  15456. +}
  15457. +
  15458. +static void ar71xx_spi_restore_regs(struct spi_device *spi)
  15459. +{
  15460. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15461. +
  15462. + /* restore CTRL register */
  15463. + ar71xx_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  15464. + /* disable GPIO mode */
  15465. + ar71xx_spi_wr(sp, SPI_REG_FS, 0);
  15466. +}
  15467. +
  15468. +static int ar71xx_spi_setup(struct spi_device *spi)
  15469. +{
  15470. + int status;
  15471. +
  15472. + if (spi->bits_per_word > 32)
  15473. + return -EINVAL;
  15474. +
  15475. + if (!spi->controller_state)
  15476. + ar71xx_spi_setup_regs(spi);
  15477. +
  15478. + status = spi_bitbang_setup(spi);
  15479. + if (status && !spi->controller_state)
  15480. + ar71xx_spi_restore_regs(spi);
  15481. +
  15482. + return status;
  15483. +}
  15484. +
  15485. +static void ar71xx_spi_cleanup(struct spi_device *spi)
  15486. +{
  15487. + ar71xx_spi_restore_regs(spi);
  15488. + spi_bitbang_cleanup(spi);
  15489. +}
  15490. +
  15491. +static u32 ar71xx_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  15492. + u32 word, u8 bits)
  15493. +{
  15494. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15495. + void __iomem *base = sp->base;
  15496. + u32 ioc = sp->ioc_base;
  15497. + u32 ret;
  15498. +
  15499. + /* clock starts at inactive polarity */
  15500. + for (word <<= (32 - bits); likely(bits); bits--) {
  15501. + u32 out;
  15502. +
  15503. + if (word & (1 << 31))
  15504. + out = ioc | SPI_IOC_DO;
  15505. + else
  15506. + out = ioc & ~SPI_IOC_DO;
  15507. +
  15508. + /* setup MSB (to slave) on trailing edge */
  15509. + __raw_writel(out, base + SPI_REG_IOC);
  15510. +
  15511. + __raw_writel(out | SPI_IOC_CLK, base + SPI_REG_IOC);
  15512. +
  15513. + word <<= 1;
  15514. +
  15515. +#ifdef PER_BIT_READ
  15516. + /* sample MSB (from slave) on leading edge */
  15517. + ret = __raw_readl(base + SPI_REG_RDS);
  15518. + __raw_writel(out, base + SPI_REG_IOC);
  15519. +#endif
  15520. +
  15521. + }
  15522. +
  15523. +#ifndef PER_BIT_READ
  15524. + ret = __raw_readl(base + SPI_REG_RDS);
  15525. +#endif
  15526. + return ret;
  15527. +}
  15528. +
  15529. +static int ar71xx_spi_probe(struct platform_device *pdev)
  15530. +{
  15531. + struct spi_master *master;
  15532. + struct ar71xx_spi *sp;
  15533. + struct ar71xx_spi_platform_data *pdata;
  15534. + struct resource *r;
  15535. + int ret;
  15536. +
  15537. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15538. + if (master == NULL) {
  15539. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15540. + return -ENOMEM;
  15541. + }
  15542. +
  15543. + sp = spi_master_get_devdata(master);
  15544. + platform_set_drvdata(pdev, sp);
  15545. +
  15546. + pdata = pdev->dev.platform_data;
  15547. +
  15548. + master->setup = ar71xx_spi_setup;
  15549. + master->cleanup = ar71xx_spi_cleanup;
  15550. +
  15551. + sp->bitbang.master = spi_master_get(master);
  15552. + sp->bitbang.chipselect = ar71xx_spi_chipselect;
  15553. + sp->bitbang.txrx_word[SPI_MODE_0] = ar71xx_spi_txrx_mode0;
  15554. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  15555. +
  15556. + sp->get_ioc_base = ar71xx_spi_get_ioc_base;
  15557. + if (pdata) {
  15558. + sp->bitbang.master->bus_num = pdata->bus_num;
  15559. + sp->bitbang.master->num_chipselect = pdata->num_chipselect;
  15560. + if (pdata->get_ioc_base)
  15561. + sp->get_ioc_base = pdata->get_ioc_base;
  15562. + } else {
  15563. + sp->bitbang.master->bus_num = 0;
  15564. + sp->bitbang.master->num_chipselect = 3;
  15565. + }
  15566. +
  15567. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15568. + if (r == NULL) {
  15569. + ret = -ENOENT;
  15570. + goto err1;
  15571. + }
  15572. +
  15573. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15574. + if (!sp->base) {
  15575. + ret = -ENXIO;
  15576. + goto err1;
  15577. + }
  15578. +
  15579. + ret = spi_bitbang_start(&sp->bitbang);
  15580. + if (!ret)
  15581. + return 0;
  15582. +
  15583. + iounmap(sp->base);
  15584. + err1:
  15585. + platform_set_drvdata(pdev, NULL);
  15586. + spi_master_put(sp->bitbang.master);
  15587. +
  15588. + return ret;
  15589. +}
  15590. +
  15591. +static int ar71xx_spi_remove(struct platform_device *pdev)
  15592. +{
  15593. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  15594. +
  15595. + spi_bitbang_stop(&sp->bitbang);
  15596. + iounmap(sp->base);
  15597. + platform_set_drvdata(pdev, NULL);
  15598. + spi_master_put(sp->bitbang.master);
  15599. +
  15600. + return 0;
  15601. +}
  15602. +
  15603. +static struct platform_driver ar71xx_spi_drv = {
  15604. + .probe = ar71xx_spi_probe,
  15605. + .remove = ar71xx_spi_remove,
  15606. + .driver = {
  15607. + .name = DRV_NAME,
  15608. + .owner = THIS_MODULE,
  15609. + },
  15610. +};
  15611. +
  15612. +static int __init ar71xx_spi_init(void)
  15613. +{
  15614. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  15615. + return platform_driver_register(&ar71xx_spi_drv);
  15616. +}
  15617. +module_init(ar71xx_spi_init);
  15618. +
  15619. +static void __exit ar71xx_spi_exit(void)
  15620. +{
  15621. + platform_driver_unregister(&ar71xx_spi_drv);
  15622. +}
  15623. +module_exit(ar71xx_spi_exit);
  15624. +
  15625. +MODULE_ALIAS("platform:" DRV_NAME);
  15626. +MODULE_DESCRIPTION(DRV_DESC);
  15627. +MODULE_VERSION(DRV_VERSION);
  15628. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15629. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  15630. +MODULE_LICENSE("GPL v2");
  15631. diff -Nur linux-2.6.33.3.orig/drivers/spi/Kconfig linux-2.6.33.3/drivers/spi/Kconfig
  15632. --- linux-2.6.33.3.orig/drivers/spi/Kconfig 2010-04-26 16:48:30.000000000 +0200
  15633. +++ linux-2.6.33.3/drivers/spi/Kconfig 2010-05-17 16:28:32.431125868 +0200
  15634. @@ -53,6 +53,13 @@
  15635. comment "SPI Master Controller Drivers"
  15636. +config SPI_AR71XX
  15637. + tristate "Atheros AR71xx SPI Controller"
  15638. + depends on SPI_MASTER && ATHEROS_AR71XX
  15639. + select SPI_BITBANG
  15640. + help
  15641. + This is the SPI contoller driver for Atheros AR71xx.
  15642. +
  15643. config SPI_ATMEL
  15644. tristate "Atmel SPI Controller"
  15645. depends on (ARCH_AT91 || AVR32)
  15646. diff -Nur linux-2.6.33.3.orig/drivers/spi/Makefile linux-2.6.33.3/drivers/spi/Makefile
  15647. --- linux-2.6.33.3.orig/drivers/spi/Makefile 2010-04-26 16:48:30.000000000 +0200
  15648. +++ linux-2.6.33.3/drivers/spi/Makefile 2010-05-17 16:28:32.431125868 +0200
  15649. @@ -11,6 +11,7 @@
  15650. obj-$(CONFIG_SPI_MASTER) += spi.o
  15651. # SPI master controller drivers (bus)
  15652. +obj-$(CONFIG_SPI_AR71XX) += ar71xx_spi.o
  15653. obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o
  15654. obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
  15655. obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
  15656. diff -Nur linux-2.6.33.3.orig/drivers/spi/pb44_spi.c linux-2.6.33.3/drivers/spi/pb44_spi.c
  15657. --- linux-2.6.33.3.orig/drivers/spi/pb44_spi.c 1970-01-01 01:00:00.000000000 +0100
  15658. +++ linux-2.6.33.3/drivers/spi/pb44_spi.c 2009-12-13 20:45:24.847920760 +0100
  15659. @@ -0,0 +1,299 @@
  15660. +/*
  15661. + * Atheros PB44 board SPI controller driver
  15662. + *
  15663. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  15664. + *
  15665. + * This program is free software; you can redistribute it and/or modify
  15666. + * it under the terms of the GNU General Public License version 2 as
  15667. + * published by the Free Software Foundation.
  15668. + *
  15669. + */
  15670. +
  15671. +#include <linux/kernel.h>
  15672. +#include <linux/init.h>
  15673. +#include <linux/delay.h>
  15674. +#include <linux/spinlock.h>
  15675. +#include <linux/workqueue.h>
  15676. +#include <linux/platform_device.h>
  15677. +#include <linux/io.h>
  15678. +#include <linux/spi/spi.h>
  15679. +#include <linux/spi/spi_bitbang.h>
  15680. +#include <linux/bitops.h>
  15681. +#include <linux/gpio.h>
  15682. +
  15683. +#include <asm/mach-ar71xx/ar71xx.h>
  15684. +#include <asm/mach-ar71xx/platform.h>
  15685. +
  15686. +#define DRV_DESC "Atheros PB44 SPI Controller driver"
  15687. +#define DRV_VERSION "0.1.0"
  15688. +#define DRV_NAME "pb44-spi"
  15689. +
  15690. +#undef PER_BIT_READ
  15691. +
  15692. +struct ar71xx_spi {
  15693. + struct spi_bitbang bitbang;
  15694. + u32 ioc_base;
  15695. + u32 reg_ctrl;
  15696. +
  15697. + void __iomem *base;
  15698. +
  15699. + struct platform_device *pdev;
  15700. +};
  15701. +
  15702. +static inline u32 pb44_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  15703. +{
  15704. + return __raw_readl(sp->base + reg);
  15705. +}
  15706. +
  15707. +static inline void pb44_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  15708. +{
  15709. + __raw_writel(val, sp->base + reg);
  15710. +}
  15711. +
  15712. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  15713. +{
  15714. + return spi_master_get_devdata(spi->master);
  15715. +}
  15716. +
  15717. +static void pb44_spi_chipselect(struct spi_device *spi, int is_active)
  15718. +{
  15719. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15720. + int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
  15721. +
  15722. + if (is_active) {
  15723. + /* set initial clock polarity */
  15724. + if (spi->mode & SPI_CPOL)
  15725. + sp->ioc_base |= SPI_IOC_CLK;
  15726. + else
  15727. + sp->ioc_base &= ~SPI_IOC_CLK;
  15728. +
  15729. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15730. + }
  15731. +
  15732. + if (spi->chip_select) {
  15733. + unsigned long gpio = (unsigned long) spi->controller_data;
  15734. +
  15735. + /* SPI is normally active-low */
  15736. + gpio_set_value(gpio, cs_high);
  15737. + } else {
  15738. + if (cs_high)
  15739. + sp->ioc_base |= SPI_IOC_CS0;
  15740. + else
  15741. + sp->ioc_base &= ~SPI_IOC_CS0;
  15742. +
  15743. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15744. + }
  15745. +
  15746. +}
  15747. +
  15748. +static int pb44_spi_setup_cs(struct spi_device *spi)
  15749. +{
  15750. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15751. +
  15752. + /* enable GPIO mode */
  15753. + pb44_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  15754. +
  15755. + /* save CTRL register */
  15756. + sp->reg_ctrl = pb44_spi_rr(sp, SPI_REG_CTRL);
  15757. + sp->ioc_base = pb44_spi_rr(sp, SPI_REG_IOC);
  15758. +
  15759. + /* TODO: setup speed? */
  15760. + pb44_spi_wr(sp, SPI_REG_CTRL, 0x43);
  15761. +
  15762. + if (spi->chip_select) {
  15763. + unsigned long gpio = (unsigned long) spi->controller_data;
  15764. + int status = 0;
  15765. +
  15766. + status = gpio_request(gpio, dev_name(&spi->dev));
  15767. + if (status)
  15768. + return status;
  15769. +
  15770. + status = gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH);
  15771. + if (status) {
  15772. + gpio_free(gpio);
  15773. + return status;
  15774. + }
  15775. + } else {
  15776. + if (spi->mode & SPI_CS_HIGH)
  15777. + sp->ioc_base |= SPI_IOC_CS0;
  15778. + else
  15779. + sp->ioc_base &= ~SPI_IOC_CS0;
  15780. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15781. + }
  15782. +
  15783. + return 0;
  15784. +}
  15785. +
  15786. +static void pb44_spi_cleanup_cs(struct spi_device *spi)
  15787. +{
  15788. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15789. +
  15790. + if (spi->chip_select) {
  15791. + unsigned long gpio = (unsigned long) spi->controller_data;
  15792. + gpio_free(gpio);
  15793. + }
  15794. +
  15795. + /* restore CTRL register */
  15796. + pb44_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  15797. + /* disable GPIO mode */
  15798. + pb44_spi_wr(sp, SPI_REG_FS, 0);
  15799. +}
  15800. +
  15801. +static int pb44_spi_setup(struct spi_device *spi)
  15802. +{
  15803. + int status = 0;
  15804. +
  15805. + if (spi->bits_per_word > 32)
  15806. + return -EINVAL;
  15807. +
  15808. + if (!spi->controller_state) {
  15809. + status = pb44_spi_setup_cs(spi);
  15810. + if (status)
  15811. + return status;
  15812. + }
  15813. +
  15814. + status = spi_bitbang_setup(spi);
  15815. + if (status && !spi->controller_state)
  15816. + pb44_spi_cleanup_cs(spi);
  15817. +
  15818. + return status;
  15819. +}
  15820. +
  15821. +static void pb44_spi_cleanup(struct spi_device *spi)
  15822. +{
  15823. + pb44_spi_cleanup_cs(spi);
  15824. + spi_bitbang_cleanup(spi);
  15825. +}
  15826. +
  15827. +static u32 pb44_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  15828. + u32 word, u8 bits)
  15829. +{
  15830. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15831. + u32 ioc = sp->ioc_base;
  15832. + u32 ret;
  15833. +
  15834. + /* clock starts at inactive polarity */
  15835. + for (word <<= (32 - bits); likely(bits); bits--) {
  15836. + u32 out;
  15837. +
  15838. + if (word & (1 << 31))
  15839. + out = ioc | SPI_IOC_DO;
  15840. + else
  15841. + out = ioc & ~SPI_IOC_DO;
  15842. +
  15843. + /* setup MSB (to slave) on trailing edge */
  15844. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  15845. + pb44_spi_wr(sp, SPI_REG_IOC, out | SPI_IOC_CLK);
  15846. +
  15847. + word <<= 1;
  15848. +
  15849. +#ifdef PER_BIT_READ
  15850. + /* sample MSB (from slave) on leading edge */
  15851. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  15852. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  15853. +#endif
  15854. + }
  15855. +
  15856. +#ifndef PER_BIT_READ
  15857. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  15858. +#endif
  15859. + return ret;
  15860. +}
  15861. +
  15862. +static int pb44_spi_probe(struct platform_device *pdev)
  15863. +{
  15864. + struct spi_master *master;
  15865. + struct ar71xx_spi *sp;
  15866. + struct ar71xx_spi_platform_data *pdata;
  15867. + struct resource *r;
  15868. + int ret;
  15869. +
  15870. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15871. + if (master == NULL) {
  15872. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15873. + return -ENOMEM;
  15874. + }
  15875. +
  15876. + sp = spi_master_get_devdata(master);
  15877. + platform_set_drvdata(pdev, sp);
  15878. +
  15879. + pdata = pdev->dev.platform_data;
  15880. +
  15881. + master->setup = pb44_spi_setup;
  15882. + master->cleanup = pb44_spi_cleanup;
  15883. + if (pdata) {
  15884. + master->bus_num = pdata->bus_num;
  15885. + master->num_chipselect = pdata->num_chipselect;
  15886. + } else {
  15887. + master->bus_num = 0;
  15888. + master->num_chipselect = 1;
  15889. + }
  15890. +
  15891. + sp->bitbang.master = spi_master_get(master);
  15892. + sp->bitbang.chipselect = pb44_spi_chipselect;
  15893. + sp->bitbang.txrx_word[SPI_MODE_0] = pb44_spi_txrx_mode0;
  15894. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  15895. + sp->bitbang.flags = SPI_CS_HIGH;
  15896. +
  15897. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15898. + if (r == NULL) {
  15899. + ret = -ENOENT;
  15900. + goto err1;
  15901. + }
  15902. +
  15903. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15904. + if (!sp->base) {
  15905. + ret = -ENXIO;
  15906. + goto err1;
  15907. + }
  15908. +
  15909. + ret = spi_bitbang_start(&sp->bitbang);
  15910. + if (!ret)
  15911. + return 0;
  15912. +
  15913. + iounmap(sp->base);
  15914. + err1:
  15915. + platform_set_drvdata(pdev, NULL);
  15916. + spi_master_put(sp->bitbang.master);
  15917. +
  15918. + return ret;
  15919. +}
  15920. +
  15921. +static int pb44_spi_remove(struct platform_device *pdev)
  15922. +{
  15923. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  15924. +
  15925. + spi_bitbang_stop(&sp->bitbang);
  15926. + iounmap(sp->base);
  15927. + platform_set_drvdata(pdev, NULL);
  15928. + spi_master_put(sp->bitbang.master);
  15929. +
  15930. + return 0;
  15931. +}
  15932. +
  15933. +static struct platform_driver pb44_spi_drv = {
  15934. + .probe = pb44_spi_probe,
  15935. + .remove = pb44_spi_remove,
  15936. + .driver = {
  15937. + .name = DRV_NAME,
  15938. + .owner = THIS_MODULE,
  15939. + },
  15940. +};
  15941. +
  15942. +static int __init pb44_spi_init(void)
  15943. +{
  15944. + return platform_driver_register(&pb44_spi_drv);
  15945. +}
  15946. +module_init(pb44_spi_init);
  15947. +
  15948. +static void __exit pb44_spi_exit(void)
  15949. +{
  15950. + platform_driver_unregister(&pb44_spi_drv);
  15951. +}
  15952. +module_exit(pb44_spi_exit);
  15953. +
  15954. +MODULE_ALIAS("platform:" DRV_NAME);
  15955. +MODULE_DESCRIPTION(DRV_DESC);
  15956. +MODULE_VERSION(DRV_VERSION);
  15957. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15958. +MODULE_LICENSE("GPL v2");
  15959. diff -Nur linux-2.6.33.3.orig/drivers/spi/spi_vsc7385.c linux-2.6.33.3/drivers/spi/spi_vsc7385.c
  15960. --- linux-2.6.33.3.orig/drivers/spi/spi_vsc7385.c 1970-01-01 01:00:00.000000000 +0100
  15961. +++ linux-2.6.33.3/drivers/spi/spi_vsc7385.c 2009-12-13 20:45:24.863922134 +0100
  15962. @@ -0,0 +1,620 @@
  15963. +/*
  15964. + * SPI driver for the Vitesse VSC7385 ethernet switch
  15965. + *
  15966. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  15967. + *
  15968. + * Parts of this file are based on Atheros' 2.6.15 BSP
  15969. + *
  15970. + * This program is free software; you can redistribute it and/or modify it
  15971. + * under the terms of the GNU General Public License version 2 as published
  15972. + * by the Free Software Foundation.
  15973. + */
  15974. +
  15975. +#include <linux/types.h>
  15976. +#include <linux/kernel.h>
  15977. +#include <linux/init.h>
  15978. +#include <linux/module.h>
  15979. +#include <linux/delay.h>
  15980. +#include <linux/device.h>
  15981. +#include <linux/bitops.h>
  15982. +#include <linux/firmware.h>
  15983. +#include <linux/spi/spi.h>
  15984. +#include <linux/spi/vsc7385.h>
  15985. +
  15986. +#define DRV_NAME "spi-vsc7385"
  15987. +#define DRV_DESC "Vitesse VSC7385 Gbit ethernet switch driver"
  15988. +#define DRV_VERSION "0.1.0"
  15989. +
  15990. +#define VSC73XX_BLOCK_MAC 0x1
  15991. +#define VSC73XX_BLOCK_2 0x2
  15992. +#define VSC73XX_BLOCK_MII 0x3
  15993. +#define VSC73XX_BLOCK_4 0x4
  15994. +#define VSC73XX_BLOCK_5 0x5
  15995. +#define VSC73XX_BLOCK_SYSTEM 0x7
  15996. +
  15997. +#define VSC73XX_SUBBLOCK_PORT_0 0
  15998. +#define VSC73XX_SUBBLOCK_PORT_1 1
  15999. +#define VSC73XX_SUBBLOCK_PORT_2 2
  16000. +#define VSC73XX_SUBBLOCK_PORT_3 3
  16001. +#define VSC73XX_SUBBLOCK_PORT_4 4
  16002. +#define VSC73XX_SUBBLOCK_PORT_MAC 6
  16003. +
  16004. +/* MAC Block registers */
  16005. +#define VSC73XX_MAC_CFG 0x0
  16006. +#define VSC73XX_ADVPORTM 0x19
  16007. +#define VSC73XX_RXOCT 0x50
  16008. +#define VSC73XX_TXOCT 0x51
  16009. +#define VSC73XX_C_RX0 0x52
  16010. +#define VSC73XX_C_RX1 0x53
  16011. +#define VSC73XX_C_RX2 0x54
  16012. +#define VSC73XX_C_TX0 0x55
  16013. +#define VSC73XX_C_TX1 0x56
  16014. +#define VSC73XX_C_TX2 0x57
  16015. +#define VSC73XX_C_CFG 0x58
  16016. +
  16017. +/* MAC_CFG register bits */
  16018. +#define VSC73XX_MAC_CFG_WEXC_DIS (1 << 31)
  16019. +#define VSC73XX_MAC_CFG_PORT_RST (1 << 29)
  16020. +#define VSC73XX_MAC_CFG_TX_EN (1 << 28)
  16021. +#define VSC73XX_MAC_CFG_SEED_LOAD (1 << 27)
  16022. +#define VSC73XX_MAC_CFG_FDX (1 << 18)
  16023. +#define VSC73XX_MAC_CFG_GIGE (1 << 17)
  16024. +#define VSC73XX_MAC_CFG_RX_EN (1 << 16)
  16025. +#define VSC73XX_MAC_CFG_VLAN_DBLAWR (1 << 15)
  16026. +#define VSC73XX_MAC_CFG_VLAN_AWR (1 << 14)
  16027. +#define VSC73XX_MAC_CFG_100_BASE_T (1 << 13)
  16028. +#define VSC73XX_MAC_CFG_TX_IPG(x) (((x) & 0x1f) << 6)
  16029. +#define VSC73XX_MAC_CFG_MAC_RX_RST (1 << 5)
  16030. +#define VSC73XX_MAC_CFG_MAC_TX_RST (1 << 4)
  16031. +#define VSC73XX_MAC_CFG_BIT2 (1 << 2)
  16032. +#define VSC73XX_MAC_CFG_CLK_SEL(x) ((x) & 0x3)
  16033. +
  16034. +/* ADVPORTM register bits */
  16035. +#define VSC73XX_ADVPORTM_IFG_PPM (1 << 7)
  16036. +#define VSC73XX_ADVPORTM_EXC_COL_CONT (1 << 6)
  16037. +#define VSC73XX_ADVPORTM_EXT_PORT (1 << 5)
  16038. +#define VSC73XX_ADVPORTM_INV_GTX (1 << 4)
  16039. +#define VSC73XX_ADVPORTM_ENA_GTX (1 << 3)
  16040. +#define VSC73XX_ADVPORTM_DDR_MODE (1 << 2)
  16041. +#define VSC73XX_ADVPORTM_IO_LOOPBACK (1 << 1)
  16042. +#define VSC73XX_ADVPORTM_HOST_LOOPBACK (1 << 0)
  16043. +
  16044. +/* MII Block registers */
  16045. +#define VSC73XX_MII_STAT 0x0
  16046. +#define VSC73XX_MII_CMD 0x1
  16047. +#define VSC73XX_MII_DATA 0x2
  16048. +
  16049. +/* System Block registers */
  16050. +#define VSC73XX_ICPU_SIPAD 0x01
  16051. +#define VSC73XX_ICPU_CLOCK_DELAY 0x05
  16052. +#define VSC73XX_ICPU_CTRL 0x10
  16053. +#define VSC73XX_ICPU_ADDR 0x11
  16054. +#define VSC73XX_ICPU_SRAM 0x12
  16055. +#define VSC73XX_ICPU_MBOX_VAL 0x15
  16056. +#define VSC73XX_ICPU_MBOX_SET 0x16
  16057. +#define VSC73XX_ICPU_MBOX_CLR 0x17
  16058. +#define VSC73XX_ICPU_CHIPID 0x18
  16059. +#define VSC73XX_ICPU_GPIO 0x34
  16060. +
  16061. +#define VSC73XX_ICPU_CTRL_CLK_DIV (1 << 8)
  16062. +#define VSC73XX_ICPU_CTRL_SRST_HOLD (1 << 7)
  16063. +#define VSC73XX_ICPU_CTRL_BOOT_EN (1 << 3)
  16064. +#define VSC73XX_ICPU_CTRL_EXT_ACC_EN (1 << 2)
  16065. +#define VSC73XX_ICPU_CTRL_CLK_EN (1 << 1)
  16066. +#define VSC73XX_ICPU_CTRL_SRST (1 << 0)
  16067. +
  16068. +#define VSC73XX_ICPU_CHIPID_ID_SHIFT 12
  16069. +#define VSC73XX_ICPU_CHIPID_ID_MASK 0xffff
  16070. +#define VSC73XX_ICPU_CHIPID_REV_SHIFT 28
  16071. +#define VSC73XX_ICPU_CHIPID_REV_MASK 0xf
  16072. +#define VSC73XX_ICPU_CHIPID_ID_7385 0x7385
  16073. +#define VSC73XX_ICPU_CHIPID_ID_7395 0x7395
  16074. +
  16075. +#define VSC73XX_CMD_MODE_READ 0
  16076. +#define VSC73XX_CMD_MODE_WRITE 1
  16077. +#define VSC73XX_CMD_MODE_SHIFT 4
  16078. +#define VSC73XX_CMD_BLOCK_SHIFT 5
  16079. +#define VSC73XX_CMD_BLOCK_MASK 0x7
  16080. +#define VSC73XX_CMD_SUBBLOCK_MASK 0xf
  16081. +
  16082. +#define VSC7385_CLOCK_DELAY ((3 << 4) | 3)
  16083. +#define VSC7385_CLOCK_DELAY_MASK ((3 << 4) | 3)
  16084. +
  16085. +#define VSC73XX_ICPU_CTRL_STOP (VSC73XX_ICPU_CTRL_SRST_HOLD | \
  16086. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  16087. + VSC73XX_ICPU_CTRL_EXT_ACC_EN)
  16088. +
  16089. +#define VSC73XX_ICPU_CTRL_START (VSC73XX_ICPU_CTRL_CLK_DIV | \
  16090. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  16091. + VSC73XX_ICPU_CTRL_CLK_EN | \
  16092. + VSC73XX_ICPU_CTRL_SRST)
  16093. +
  16094. +#define VSC7385_ADVPORTM_MASK (VSC73XX_ADVPORTM_IFG_PPM | \
  16095. + VSC73XX_ADVPORTM_EXC_COL_CONT | \
  16096. + VSC73XX_ADVPORTM_EXT_PORT | \
  16097. + VSC73XX_ADVPORTM_INV_GTX | \
  16098. + VSC73XX_ADVPORTM_ENA_GTX | \
  16099. + VSC73XX_ADVPORTM_DDR_MODE | \
  16100. + VSC73XX_ADVPORTM_IO_LOOPBACK | \
  16101. + VSC73XX_ADVPORTM_HOST_LOOPBACK)
  16102. +
  16103. +#define VSC7385_ADVPORTM_INIT (VSC73XX_ADVPORTM_EXT_PORT | \
  16104. + VSC73XX_ADVPORTM_ENA_GTX | \
  16105. + VSC73XX_ADVPORTM_DDR_MODE)
  16106. +
  16107. +#define VSC7385_MAC_CFG_RESET (VSC73XX_MAC_CFG_PORT_RST | \
  16108. + VSC73XX_MAC_CFG_MAC_RX_RST | \
  16109. + VSC73XX_MAC_CFG_MAC_TX_RST)
  16110. +
  16111. +#define VSC73XX_MAC_CFG_INIT (VSC73XX_MAC_CFG_TX_EN | \
  16112. + VSC73XX_MAC_CFG_FDX | \
  16113. + VSC73XX_MAC_CFG_GIGE | \
  16114. + VSC73XX_MAC_CFG_RX_EN)
  16115. +
  16116. +#define VSC73XX_RESET_DELAY 100
  16117. +
  16118. +struct vsc7385 {
  16119. + struct spi_device *spi;
  16120. + struct mutex lock;
  16121. + struct vsc7385_platform_data *pdata;
  16122. +};
  16123. +
  16124. +static int vsc7385_is_addr_valid(u8 block, u8 subblock)
  16125. +{
  16126. + switch (block) {
  16127. + case VSC73XX_BLOCK_MAC:
  16128. + switch (subblock) {
  16129. + case 0 ... 4:
  16130. + case 6:
  16131. + return 1;
  16132. + }
  16133. + break;
  16134. +
  16135. + case VSC73XX_BLOCK_2:
  16136. + case VSC73XX_BLOCK_SYSTEM:
  16137. + switch (subblock) {
  16138. + case 0:
  16139. + return 1;
  16140. + }
  16141. + break;
  16142. +
  16143. + case VSC73XX_BLOCK_MII:
  16144. + case VSC73XX_BLOCK_4:
  16145. + case VSC73XX_BLOCK_5:
  16146. + switch (subblock) {
  16147. + case 0 ... 1:
  16148. + return 1;
  16149. + }
  16150. + break;
  16151. + }
  16152. +
  16153. + return 0;
  16154. +}
  16155. +
  16156. +static inline u8 vsc7385_make_addr(u8 mode, u8 block, u8 subblock)
  16157. +{
  16158. + u8 ret;
  16159. +
  16160. + ret = (block & VSC73XX_CMD_BLOCK_MASK) << VSC73XX_CMD_BLOCK_SHIFT;
  16161. + ret |= (mode & 1) << VSC73XX_CMD_MODE_SHIFT;
  16162. + ret |= subblock & VSC73XX_CMD_SUBBLOCK_MASK;
  16163. +
  16164. + return ret;
  16165. +}
  16166. +
  16167. +static int vsc7385_read(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  16168. + u32 *value)
  16169. +{
  16170. + u8 cmd[4];
  16171. + u8 buf[4];
  16172. + struct spi_transfer t[2];
  16173. + struct spi_message m;
  16174. + int err;
  16175. +
  16176. + if (!vsc7385_is_addr_valid(block, subblock))
  16177. + return -EINVAL;
  16178. +
  16179. + spi_message_init(&m);
  16180. +
  16181. + memset(&t, 0, sizeof(t));
  16182. +
  16183. + t[0].tx_buf = cmd;
  16184. + t[0].len = sizeof(cmd);
  16185. + spi_message_add_tail(&t[0], &m);
  16186. +
  16187. + t[1].rx_buf = buf;
  16188. + t[1].len = sizeof(buf);
  16189. + spi_message_add_tail(&t[1], &m);
  16190. +
  16191. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_READ, block, subblock);
  16192. + cmd[1] = reg;
  16193. + cmd[2] = 0;
  16194. + cmd[3] = 0;
  16195. +
  16196. + mutex_lock(&vsc->lock);
  16197. + err = spi_sync(vsc->spi, &m);
  16198. + mutex_unlock(&vsc->lock);
  16199. +
  16200. + if (err)
  16201. + return err;
  16202. +
  16203. + *value = (((u32) buf[0]) << 24) | (((u32) buf[1]) << 16) |
  16204. + (((u32) buf[2]) << 8) | ((u32) buf[3]);
  16205. +
  16206. + return 0;
  16207. +}
  16208. +
  16209. +
  16210. +static int vsc7385_write(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  16211. + u32 value)
  16212. +{
  16213. + u8 cmd[2];
  16214. + u8 buf[4];
  16215. + struct spi_transfer t[2];
  16216. + struct spi_message m;
  16217. + int err;
  16218. +
  16219. + if (!vsc7385_is_addr_valid(block, subblock))
  16220. + return -EINVAL;
  16221. +
  16222. + spi_message_init(&m);
  16223. +
  16224. + memset(&t, 0, sizeof(t));
  16225. +
  16226. + t[0].tx_buf = cmd;
  16227. + t[0].len = sizeof(cmd);
  16228. + spi_message_add_tail(&t[0], &m);
  16229. +
  16230. + t[1].tx_buf = buf;
  16231. + t[1].len = sizeof(buf);
  16232. + spi_message_add_tail(&t[1], &m);
  16233. +
  16234. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_WRITE, block, subblock);
  16235. + cmd[1] = reg;
  16236. +
  16237. + buf[0] = (value >> 24) & 0xff;
  16238. + buf[1] = (value >> 16) & 0xff;
  16239. + buf[2] = (value >> 8) & 0xff;
  16240. + buf[3] = value & 0xff;
  16241. +
  16242. + mutex_lock(&vsc->lock);
  16243. + err = spi_sync(vsc->spi, &m);
  16244. + mutex_unlock(&vsc->lock);
  16245. +
  16246. + return err;
  16247. +}
  16248. +
  16249. +static inline int vsc7385_write_verify(struct vsc7385 *vsc, u8 block,
  16250. + u8 subblock, u8 reg, u32 value,
  16251. + u32 read_mask, u32 read_val)
  16252. +{
  16253. + struct spi_device *spi = vsc->spi;
  16254. + u32 t;
  16255. + int err;
  16256. +
  16257. + err = vsc7385_write(vsc, block, subblock, reg, value);
  16258. + if (err)
  16259. + return err;
  16260. +
  16261. + err = vsc7385_read(vsc, block, subblock, reg, &t);
  16262. + if (err)
  16263. + return err;
  16264. +
  16265. + if ((t & read_mask) != read_val) {
  16266. + dev_err(&spi->dev, "register write error\n");
  16267. + return -EIO;
  16268. + }
  16269. +
  16270. + return 0;
  16271. +}
  16272. +
  16273. +static inline int vsc7385_set_clock_delay(struct vsc7385 *vsc, u32 val)
  16274. +{
  16275. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16276. + VSC73XX_ICPU_CLOCK_DELAY, val);
  16277. +}
  16278. +
  16279. +static inline int vsc7385_get_clock_delay(struct vsc7385 *vsc, u32 *val)
  16280. +{
  16281. + return vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16282. + VSC73XX_ICPU_CLOCK_DELAY, val);
  16283. +}
  16284. +
  16285. +static inline int vsc7385_icpu_stop(struct vsc7385 *vsc)
  16286. +{
  16287. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  16288. + VSC73XX_ICPU_CTRL_STOP);
  16289. +}
  16290. +
  16291. +static inline int vsc7385_icpu_start(struct vsc7385 *vsc)
  16292. +{
  16293. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  16294. + VSC73XX_ICPU_CTRL_START);
  16295. +}
  16296. +
  16297. +static inline int vsc7385_icpu_reset(struct vsc7385 *vsc)
  16298. +{
  16299. + int rc;
  16300. +
  16301. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_ADDR,
  16302. + 0x0000);
  16303. + if (rc)
  16304. + dev_err(&vsc->spi->dev,
  16305. + "could not reset microcode, err=%d\n", rc);
  16306. +
  16307. + return rc;
  16308. +}
  16309. +
  16310. +static int vsc7385_upload_ucode(struct vsc7385 *vsc)
  16311. +{
  16312. + struct spi_device *spi = vsc->spi;
  16313. + const struct firmware *firmware;
  16314. + char *ucode_name;
  16315. + unsigned char *dp;
  16316. + unsigned int curVal;
  16317. + int i;
  16318. + int diffs;
  16319. + int rc;
  16320. +
  16321. + ucode_name = (vsc->pdata->ucode_name) ? vsc->pdata->ucode_name
  16322. + : "vsc7385_ucode.bin";
  16323. + rc = request_firmware(&firmware, ucode_name, &spi->dev);
  16324. + if (rc) {
  16325. + dev_err(&spi->dev, "request_firmware failed, err=%d\n",
  16326. + rc);
  16327. + return rc;
  16328. + }
  16329. +
  16330. + rc = vsc7385_icpu_stop(vsc);
  16331. + if (rc)
  16332. + goto out;
  16333. +
  16334. + rc = vsc7385_icpu_reset(vsc);
  16335. + if (rc)
  16336. + goto out;
  16337. +
  16338. + dev_info(&spi->dev, "uploading microcode...\n");
  16339. +
  16340. + dp = (unsigned char *) firmware->data;
  16341. + for (i = 0; i < firmware->size; i++) {
  16342. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16343. + VSC73XX_ICPU_SRAM, *dp++);
  16344. + if (rc) {
  16345. + dev_err(&spi->dev, "could not load microcode, err=%d\n",
  16346. + rc);
  16347. + goto out;
  16348. + }
  16349. + }
  16350. +
  16351. + rc = vsc7385_icpu_reset(vsc);
  16352. + if (rc)
  16353. + goto out;
  16354. +
  16355. + dev_info(&spi->dev, "verifying microcode...\n");
  16356. +
  16357. + dp = (unsigned char *) firmware->data;
  16358. + diffs = 0;
  16359. + for (i = 0; i < firmware->size; i++) {
  16360. + rc = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16361. + VSC73XX_ICPU_SRAM, &curVal);
  16362. + if (rc) {
  16363. + dev_err(&spi->dev, "could not read microcode %d\n",rc);
  16364. + goto out;
  16365. + }
  16366. +
  16367. + if (curVal > 0xff) {
  16368. + dev_err(&spi->dev, "bad val read: %04x : %02x %02x\n",
  16369. + i, *dp, curVal);
  16370. + rc = -EIO;
  16371. + goto out;
  16372. + }
  16373. +
  16374. + if ((curVal & 0xff) != *dp) {
  16375. + diffs++;
  16376. + dev_err(&spi->dev, "verify error: %04x : %02x %02x\n",
  16377. + i, *dp, curVal);
  16378. +
  16379. + if (diffs > 4)
  16380. + break;
  16381. + }
  16382. + dp++;
  16383. + }
  16384. +
  16385. + if (diffs) {
  16386. + dev_err(&spi->dev, "microcode verification failed\n");
  16387. + rc = -EIO;
  16388. + goto out;
  16389. + }
  16390. +
  16391. + dev_info(&spi->dev, "microcode uploaded\n");
  16392. +
  16393. + rc = vsc7385_icpu_start(vsc);
  16394. +
  16395. + out:
  16396. + release_firmware(firmware);
  16397. + return rc;
  16398. +}
  16399. +
  16400. +static int vsc7385_setup(struct vsc7385 *vsc)
  16401. +{
  16402. + struct vsc7385_platform_data *pdata = vsc->pdata;
  16403. + u32 t;
  16404. + int err;
  16405. +
  16406. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16407. + VSC73XX_ICPU_CLOCK_DELAY,
  16408. + VSC7385_CLOCK_DELAY,
  16409. + VSC7385_CLOCK_DELAY_MASK,
  16410. + VSC7385_CLOCK_DELAY);
  16411. + if (err)
  16412. + goto err;
  16413. +
  16414. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_MAC,
  16415. + VSC73XX_SUBBLOCK_PORT_MAC, VSC73XX_ADVPORTM,
  16416. + VSC7385_ADVPORTM_INIT,
  16417. + VSC7385_ADVPORTM_MASK,
  16418. + VSC7385_ADVPORTM_INIT);
  16419. + if (err)
  16420. + goto err;
  16421. +
  16422. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  16423. + VSC73XX_MAC_CFG, VSC7385_MAC_CFG_RESET);
  16424. + if (err)
  16425. + goto err;
  16426. +
  16427. + t = VSC73XX_MAC_CFG_INIT;
  16428. + t |= VSC73XX_MAC_CFG_TX_IPG(pdata->mac_cfg.tx_ipg);
  16429. + t |= VSC73XX_MAC_CFG_CLK_SEL(pdata->mac_cfg.clk_sel);
  16430. + if (pdata->mac_cfg.bit2)
  16431. + t |= VSC73XX_MAC_CFG_BIT2;
  16432. +
  16433. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  16434. + VSC73XX_MAC_CFG, t);
  16435. + if (err)
  16436. + goto err;
  16437. +
  16438. + return 0;
  16439. +
  16440. + err:
  16441. + return err;
  16442. +}
  16443. +
  16444. +static int vsc7385_detect(struct vsc7385 *vsc)
  16445. +{
  16446. + struct spi_device *spi = vsc->spi;
  16447. + u32 t;
  16448. + u32 id;
  16449. + u32 rev;
  16450. + int err;
  16451. +
  16452. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16453. + VSC73XX_ICPU_MBOX_VAL, &t);
  16454. + if (err) {
  16455. + dev_err(&spi->dev, "unable to read mailbox, err=%d\n", err);
  16456. + return err;
  16457. + }
  16458. +
  16459. + if (t == 0xffffffff) {
  16460. + dev_dbg(&spi->dev, "assert chip reset\n");
  16461. + if (vsc->pdata->reset)
  16462. + vsc->pdata->reset();
  16463. +
  16464. + }
  16465. +
  16466. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16467. + VSC73XX_ICPU_CHIPID, &t);
  16468. + if (err) {
  16469. + dev_err(&spi->dev, "unable to read chip id, err=%d\n", err);
  16470. + return err;
  16471. + }
  16472. +
  16473. + id = (t >> VSC73XX_ICPU_CHIPID_ID_SHIFT) & VSC73XX_ICPU_CHIPID_ID_MASK;
  16474. + switch (id) {
  16475. + case VSC73XX_ICPU_CHIPID_ID_7385:
  16476. + case VSC73XX_ICPU_CHIPID_ID_7395:
  16477. + break;
  16478. + default:
  16479. + dev_err(&spi->dev, "unsupported chip, id=%04x\n", id);
  16480. + return -ENODEV;
  16481. + }
  16482. +
  16483. + rev = (t >> VSC73XX_ICPU_CHIPID_REV_SHIFT) &
  16484. + VSC73XX_ICPU_CHIPID_REV_MASK;
  16485. + dev_info(&spi->dev, "VSC%04X (rev. %d) switch found \n", id, rev);
  16486. +
  16487. + return 0;
  16488. +}
  16489. +
  16490. +static int __devinit vsc7385_probe(struct spi_device *spi)
  16491. +{
  16492. + struct vsc7385 *vsc;
  16493. + struct vsc7385_platform_data *pdata;
  16494. + int err;
  16495. +
  16496. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION"\n");
  16497. +
  16498. + pdata = spi->dev.platform_data;
  16499. + if (!pdata) {
  16500. + dev_err(&spi->dev, "no platform data specified\n");
  16501. + return-ENODEV;
  16502. + }
  16503. +
  16504. + vsc = kzalloc(sizeof(*vsc), GFP_KERNEL);
  16505. + if (!vsc) {
  16506. + dev_err(&spi->dev, "no memory for private data\n");
  16507. + return-ENOMEM;
  16508. + }
  16509. +
  16510. + mutex_init(&vsc->lock);
  16511. + vsc->pdata = pdata;
  16512. + vsc->spi = spi_dev_get(spi);
  16513. + dev_set_drvdata(&spi->dev, vsc);
  16514. +
  16515. + spi->mode = SPI_MODE_0;
  16516. + spi->bits_per_word = 8;
  16517. + err = spi_setup(spi);
  16518. + if (err) {
  16519. + dev_err(&spi->dev, "spi_setup failed, err=%d \n", err);
  16520. + goto err_drvdata;
  16521. + }
  16522. +
  16523. + err = vsc7385_detect(vsc);
  16524. + if (err) {
  16525. + dev_err(&spi->dev, "no chip found, err=%d \n", err);
  16526. + goto err_drvdata;
  16527. + }
  16528. +
  16529. + err = vsc7385_upload_ucode(vsc);
  16530. + if (err)
  16531. + goto err_drvdata;
  16532. +
  16533. + err = vsc7385_setup(vsc);
  16534. + if (err)
  16535. + goto err_drvdata;
  16536. +
  16537. + return 0;
  16538. +
  16539. + err_drvdata:
  16540. + dev_set_drvdata(&spi->dev, NULL);
  16541. + kfree(vsc);
  16542. + return err;
  16543. +}
  16544. +
  16545. +static int __devexit vsc7385_remove(struct spi_device *spi)
  16546. +{
  16547. + struct vsc7385_data *vsc;
  16548. +
  16549. + vsc = dev_get_drvdata(&spi->dev);
  16550. + dev_set_drvdata(&spi->dev, NULL);
  16551. + kfree(vsc);
  16552. +
  16553. + return 0;
  16554. +}
  16555. +
  16556. +static struct spi_driver vsc7385_driver = {
  16557. + .driver = {
  16558. + .name = DRV_NAME,
  16559. + .bus = &spi_bus_type,
  16560. + .owner = THIS_MODULE,
  16561. + },
  16562. + .probe = vsc7385_probe,
  16563. + .remove = __devexit_p(vsc7385_remove),
  16564. +};
  16565. +
  16566. +static int __init vsc7385_init(void)
  16567. +{
  16568. + return spi_register_driver(&vsc7385_driver);
  16569. +}
  16570. +module_init(vsc7385_init);
  16571. +
  16572. +static void __exit vsc7385_exit(void)
  16573. +{
  16574. + spi_unregister_driver(&vsc7385_driver);
  16575. +}
  16576. +module_exit(vsc7385_exit);
  16577. +
  16578. +MODULE_DESCRIPTION(DRV_DESC);
  16579. +MODULE_VERSION(DRV_VERSION);
  16580. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16581. +MODULE_LICENSE("GPL v2");
  16582. +
  16583. diff -Nur linux-2.6.33.3.orig/drivers/usb/host/ehci-ar71xx.c linux-2.6.33.3/drivers/usb/host/ehci-ar71xx.c
  16584. --- linux-2.6.33.3.orig/drivers/usb/host/ehci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  16585. +++ linux-2.6.33.3/drivers/usb/host/ehci-ar71xx.c 2010-02-09 00:28:55.636370581 +0100
  16586. @@ -0,0 +1,242 @@
  16587. +/*
  16588. + * Bus Glue for Atheros AR71xx built-in EHCI controller.
  16589. + *
  16590. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  16591. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16592. + *
  16593. + * Parts of this file are based on Atheros' 2.6.15 BSP
  16594. + * Copyright (C) 2007 Atheros Communications, Inc.
  16595. + *
  16596. + * This program is free software; you can redistribute it and/or modify it
  16597. + * under the terms of the GNU General Public License version 2 as published
  16598. + * by the Free Software Foundation.
  16599. + */
  16600. +
  16601. +#include <linux/platform_device.h>
  16602. +#include <linux/delay.h>
  16603. +
  16604. +#include <asm/mach-ar71xx/platform.h>
  16605. +
  16606. +extern int usb_disabled(void);
  16607. +
  16608. +static int ehci_ar71xx_init(struct usb_hcd *hcd)
  16609. +{
  16610. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  16611. + int ret;
  16612. +
  16613. + ehci->caps = hcd->regs;
  16614. + ehci->regs = hcd->regs +
  16615. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  16616. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  16617. +
  16618. + ehci->sbrn = 0x20;
  16619. + ehci->has_synopsys_hc_bug = 1;
  16620. +
  16621. + ehci_reset(ehci);
  16622. +
  16623. + ret = ehci_init(hcd);
  16624. + if (ret)
  16625. + return ret;
  16626. +
  16627. + ehci_port_power(ehci, 0);
  16628. +
  16629. + return 0;
  16630. +}
  16631. +
  16632. +static int ehci_ar91xx_init(struct usb_hcd *hcd)
  16633. +{
  16634. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  16635. + int ret;
  16636. +
  16637. + ehci->caps = hcd->regs + 0x100;
  16638. + ehci->regs = hcd->regs + 0x100 +
  16639. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  16640. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  16641. +
  16642. + hcd->has_tt = 1;
  16643. + ehci->sbrn = 0x20;
  16644. +
  16645. + ehci_reset(ehci);
  16646. +
  16647. + ret = ehci_init(hcd);
  16648. + if (ret)
  16649. + return ret;
  16650. +
  16651. + ehci_port_power(ehci, 0);
  16652. +
  16653. + return 0;
  16654. +}
  16655. +
  16656. +static int ehci_ar71xx_probe(const struct hc_driver *driver,
  16657. + struct usb_hcd **hcd_out,
  16658. + struct platform_device *pdev)
  16659. +{
  16660. + struct usb_hcd *hcd;
  16661. + struct resource *res;
  16662. + int irq;
  16663. + int ret;
  16664. +
  16665. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  16666. + if (!res) {
  16667. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  16668. + dev_name(&pdev->dev));
  16669. + return -ENODEV;
  16670. + }
  16671. + irq = res->start;
  16672. +
  16673. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  16674. + if (!res) {
  16675. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  16676. + dev_name(&pdev->dev));
  16677. + return -ENODEV;
  16678. + }
  16679. +
  16680. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  16681. + if (!hcd)
  16682. + return -ENOMEM;
  16683. +
  16684. + hcd->rsrc_start = res->start;
  16685. + hcd->rsrc_len = res->end - res->start + 1;
  16686. +
  16687. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  16688. + dev_dbg(&pdev->dev, "controller already in use\n");
  16689. + ret = -EBUSY;
  16690. + goto err_put_hcd;
  16691. + }
  16692. +
  16693. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  16694. + if (!hcd->regs) {
  16695. + dev_dbg(&pdev->dev, "error mapping memory\n");
  16696. + ret = -EFAULT;
  16697. + goto err_release_region;
  16698. + }
  16699. +
  16700. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  16701. + if (ret)
  16702. + goto err_iounmap;
  16703. +
  16704. + return 0;
  16705. +
  16706. + err_iounmap:
  16707. + iounmap(hcd->regs);
  16708. +
  16709. + err_release_region:
  16710. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16711. + err_put_hcd:
  16712. + usb_put_hcd(hcd);
  16713. + return ret;
  16714. +}
  16715. +
  16716. +static void ehci_ar71xx_remove(struct usb_hcd *hcd,
  16717. + struct platform_device *pdev)
  16718. +{
  16719. + usb_remove_hcd(hcd);
  16720. + iounmap(hcd->regs);
  16721. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16722. + usb_put_hcd(hcd);
  16723. +}
  16724. +
  16725. +static const struct hc_driver ehci_ar71xx_hc_driver = {
  16726. + .description = hcd_name,
  16727. + .product_desc = "Atheros AR71xx built-in EHCI controller",
  16728. + .hcd_priv_size = sizeof(struct ehci_hcd),
  16729. +
  16730. + .irq = ehci_irq,
  16731. + .flags = HCD_MEMORY | HCD_USB2,
  16732. +
  16733. + .reset = ehci_ar71xx_init,
  16734. + .start = ehci_run,
  16735. + .stop = ehci_stop,
  16736. + .shutdown = ehci_shutdown,
  16737. +
  16738. + .urb_enqueue = ehci_urb_enqueue,
  16739. + .urb_dequeue = ehci_urb_dequeue,
  16740. + .endpoint_disable = ehci_endpoint_disable,
  16741. + .endpoint_reset = ehci_endpoint_reset,
  16742. +
  16743. + .get_frame_number = ehci_get_frame,
  16744. +
  16745. + .hub_status_data = ehci_hub_status_data,
  16746. + .hub_control = ehci_hub_control,
  16747. +#ifdef CONFIG_PM
  16748. + .hub_suspend = ehci_hub_suspend,
  16749. + .hub_resume = ehci_hub_resume,
  16750. +#endif
  16751. + .relinquish_port = ehci_relinquish_port,
  16752. + .port_handed_over = ehci_port_handed_over,
  16753. +
  16754. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  16755. +};
  16756. +
  16757. +static const struct hc_driver ehci_ar91xx_hc_driver = {
  16758. + .description = hcd_name,
  16759. + .product_desc = "Atheros AR91xx built-in EHCI controller",
  16760. + .hcd_priv_size = sizeof(struct ehci_hcd),
  16761. + .irq = ehci_irq,
  16762. + .flags = HCD_MEMORY | HCD_USB2,
  16763. +
  16764. + .reset = ehci_ar91xx_init,
  16765. + .start = ehci_run,
  16766. + .stop = ehci_stop,
  16767. + .shutdown = ehci_shutdown,
  16768. +
  16769. + .urb_enqueue = ehci_urb_enqueue,
  16770. + .urb_dequeue = ehci_urb_dequeue,
  16771. + .endpoint_disable = ehci_endpoint_disable,
  16772. + .endpoint_reset = ehci_endpoint_reset,
  16773. +
  16774. + .get_frame_number = ehci_get_frame,
  16775. +
  16776. + .hub_status_data = ehci_hub_status_data,
  16777. + .hub_control = ehci_hub_control,
  16778. +#ifdef CONFIG_PM
  16779. + .hub_suspend = ehci_hub_suspend,
  16780. + .hub_resume = ehci_hub_resume,
  16781. +#endif
  16782. + .relinquish_port = ehci_relinquish_port,
  16783. + .port_handed_over = ehci_port_handed_over,
  16784. +
  16785. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  16786. +};
  16787. +
  16788. +static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
  16789. +{
  16790. + struct ar71xx_ehci_platform_data *pdata;
  16791. + struct usb_hcd *hcd = NULL;
  16792. + int ret;
  16793. +
  16794. + if (usb_disabled())
  16795. + return -ENODEV;
  16796. +
  16797. + pdata = pdev->dev.platform_data;
  16798. + if (!pdata) {
  16799. + dev_err(&pdev->dev, "no platform data specified for %s\n",
  16800. + dev_name(&pdev->dev));
  16801. + return -ENODEV;
  16802. + }
  16803. +
  16804. + if (pdata->is_ar91xx)
  16805. + ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
  16806. + else
  16807. + ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
  16808. +
  16809. + return ret;
  16810. +}
  16811. +
  16812. +static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
  16813. +{
  16814. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  16815. +
  16816. + ehci_ar71xx_remove(hcd, pdev);
  16817. + return 0;
  16818. +}
  16819. +
  16820. +MODULE_ALIAS("platform:ar71xx-ehci");
  16821. +
  16822. +static struct platform_driver ehci_ar71xx_driver = {
  16823. + .probe = ehci_ar71xx_driver_probe,
  16824. + .remove = ehci_ar71xx_driver_remove,
  16825. + .driver = {
  16826. + .name = "ar71xx-ehci",
  16827. + }
  16828. +};
  16829. diff -Nur linux-2.6.33.3.orig/drivers/usb/host/ehci-hcd.c linux-2.6.33.3/drivers/usb/host/ehci-hcd.c
  16830. --- linux-2.6.33.3.orig/drivers/usb/host/ehci-hcd.c 2010-04-26 16:48:30.000000000 +0200
  16831. +++ linux-2.6.33.3/drivers/usb/host/ehci-hcd.c 2010-05-17 16:28:28.159113855 +0200
  16832. @@ -1158,6 +1158,11 @@
  16833. #define PLATFORM_DRIVER ehci_atmel_driver
  16834. #endif
  16835. +#ifdef CONFIG_USB_EHCI_AR71XX
  16836. +#include "ehci-ar71xx.c"
  16837. +#define PLATFORM_DRIVER ehci_ar71xx_driver
  16838. +#endif
  16839. +
  16840. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  16841. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
  16842. #error "missing bus glue for ehci-hcd"
  16843. diff -Nur linux-2.6.33.3.orig/drivers/usb/host/Kconfig linux-2.6.33.3/drivers/usb/host/Kconfig
  16844. --- linux-2.6.33.3.orig/drivers/usb/host/Kconfig 2010-04-26 16:48:30.000000000 +0200
  16845. +++ linux-2.6.33.3/drivers/usb/host/Kconfig 2010-05-17 16:28:28.155130666 +0200
  16846. @@ -109,6 +109,13 @@
  16847. support both high speed and full speed devices, or high speed
  16848. devices only.
  16849. +config USB_EHCI_AR71XX
  16850. + bool "USB EHCI support for AR71xx"
  16851. + depends on USB_EHCI_HCD && ATHEROS_AR71XX
  16852. + default y
  16853. + help
  16854. + Support for Atheros AR71xx built-in EHCI controller
  16855. +
  16856. config USB_EHCI_FSL
  16857. bool "Support for Freescale on-chip EHCI USB controller"
  16858. depends on USB_EHCI_HCD && FSL_SOC
  16859. @@ -207,6 +214,13 @@
  16860. To compile this driver as a module, choose M here: the
  16861. module will be called ohci-hcd.
  16862. +config USB_OHCI_AR71XX
  16863. + bool "USB OHCI support for Atheros AR71xx"
  16864. + depends on USB_OHCI_HCD && ATHEROS_AR71XX
  16865. + default y
  16866. + help
  16867. + Support for Atheros AR71xx built-in OHCI controller
  16868. +
  16869. config USB_OHCI_HCD_PPC_SOC
  16870. bool "OHCI support for on-chip PPC USB controller"
  16871. depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx)
  16872. diff -Nur linux-2.6.33.3.orig/drivers/usb/host/ohci-ar71xx.c linux-2.6.33.3/drivers/usb/host/ohci-ar71xx.c
  16873. --- linux-2.6.33.3.orig/drivers/usb/host/ohci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  16874. +++ linux-2.6.33.3/drivers/usb/host/ohci-ar71xx.c 2009-12-13 20:45:24.747935158 +0100
  16875. @@ -0,0 +1,165 @@
  16876. +/*
  16877. + * OHCI HCD (Host Controller Driver) for USB.
  16878. + *
  16879. + * Bus Glue for Atheros AR71xx built-in OHCI controller.
  16880. + *
  16881. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  16882. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16883. + *
  16884. + * Parts of this file are based on Atheros' 2.6.15 BSP
  16885. + * Copyright (C) 2007 Atheros Communications, Inc.
  16886. + *
  16887. + * This program is free software; you can redistribute it and/or modify it
  16888. + * under the terms of the GNU General Public License version 2 as published
  16889. + * by the Free Software Foundation.
  16890. + */
  16891. +
  16892. +#include <linux/platform_device.h>
  16893. +#include <linux/delay.h>
  16894. +
  16895. +extern int usb_disabled(void);
  16896. +
  16897. +static int usb_hcd_ar71xx_probe(const struct hc_driver *driver,
  16898. + struct platform_device *pdev)
  16899. +{
  16900. + struct usb_hcd *hcd;
  16901. + struct resource *res;
  16902. + int irq;
  16903. + int ret;
  16904. +
  16905. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  16906. + if (!res) {
  16907. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  16908. + dev_name(&pdev->dev));
  16909. + return -ENODEV;
  16910. + }
  16911. + irq = res->start;
  16912. +
  16913. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  16914. + if (!hcd)
  16915. + return -ENOMEM;
  16916. +
  16917. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  16918. + if (!res) {
  16919. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  16920. + dev_name(&pdev->dev));
  16921. + ret = -ENODEV;
  16922. + goto err_put_hcd;
  16923. + }
  16924. + hcd->rsrc_start = res->start;
  16925. + hcd->rsrc_len = res->end - res->start + 1;
  16926. +
  16927. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  16928. + dev_dbg(&pdev->dev, "controller already in use\n");
  16929. + ret = -EBUSY;
  16930. + goto err_put_hcd;
  16931. + }
  16932. +
  16933. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  16934. + if (!hcd->regs) {
  16935. + dev_dbg(&pdev->dev, "error mapping memory\n");
  16936. + ret = -EFAULT;
  16937. + goto err_release_region;
  16938. + }
  16939. +
  16940. + ohci_hcd_init(hcd_to_ohci(hcd));
  16941. +
  16942. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  16943. + if (ret)
  16944. + goto err_stop_hcd;
  16945. +
  16946. + return 0;
  16947. +
  16948. + err_stop_hcd:
  16949. + iounmap(hcd->regs);
  16950. + err_release_region:
  16951. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16952. + err_put_hcd:
  16953. + usb_put_hcd(hcd);
  16954. + return ret;
  16955. +}
  16956. +
  16957. +void usb_hcd_ar71xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  16958. +{
  16959. + usb_remove_hcd(hcd);
  16960. + iounmap(hcd->regs);
  16961. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16962. + usb_put_hcd(hcd);
  16963. +}
  16964. +
  16965. +static int __devinit ohci_ar71xx_start(struct usb_hcd *hcd)
  16966. +{
  16967. + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  16968. + int ret;
  16969. +
  16970. + ret = ohci_init(ohci);
  16971. + if (ret < 0)
  16972. + return ret;
  16973. +
  16974. + ret = ohci_run(ohci);
  16975. + if (ret < 0)
  16976. + goto err;
  16977. +
  16978. + return 0;
  16979. +
  16980. + err:
  16981. + ohci_stop(hcd);
  16982. + return ret;
  16983. +}
  16984. +
  16985. +static const struct hc_driver ohci_ar71xx_hc_driver = {
  16986. + .description = hcd_name,
  16987. + .product_desc = "Atheros AR71xx built-in OHCI controller",
  16988. + .hcd_priv_size = sizeof(struct ohci_hcd),
  16989. +
  16990. + .irq = ohci_irq,
  16991. + .flags = HCD_USB11 | HCD_MEMORY,
  16992. +
  16993. + .start = ohci_ar71xx_start,
  16994. + .stop = ohci_stop,
  16995. + .shutdown = ohci_shutdown,
  16996. +
  16997. + .urb_enqueue = ohci_urb_enqueue,
  16998. + .urb_dequeue = ohci_urb_dequeue,
  16999. + .endpoint_disable = ohci_endpoint_disable,
  17000. +
  17001. + /*
  17002. + * scheduling support
  17003. + */
  17004. + .get_frame_number = ohci_get_frame,
  17005. +
  17006. + /*
  17007. + * root hub support
  17008. + */
  17009. + .hub_status_data = ohci_hub_status_data,
  17010. + .hub_control = ohci_hub_control,
  17011. + .start_port_reset = ohci_start_port_reset,
  17012. +};
  17013. +
  17014. +static int ohci_hcd_ar71xx_drv_probe(struct platform_device *pdev)
  17015. +{
  17016. + if (usb_disabled())
  17017. + return -ENODEV;
  17018. +
  17019. + return usb_hcd_ar71xx_probe(&ohci_ar71xx_hc_driver, pdev);
  17020. +}
  17021. +
  17022. +static int ohci_hcd_ar71xx_drv_remove(struct platform_device *pdev)
  17023. +{
  17024. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  17025. +
  17026. + usb_hcd_ar71xx_remove(hcd, pdev);
  17027. + return 0;
  17028. +}
  17029. +
  17030. +MODULE_ALIAS("platform:ar71xx-ohci");
  17031. +
  17032. +static struct platform_driver ohci_hcd_ar71xx_driver = {
  17033. + .probe = ohci_hcd_ar71xx_drv_probe,
  17034. + .remove = ohci_hcd_ar71xx_drv_remove,
  17035. + .shutdown = usb_hcd_platform_shutdown,
  17036. + .driver = {
  17037. + .name = "ar71xx-ohci",
  17038. + .owner = THIS_MODULE,
  17039. + },
  17040. +};
  17041. diff -Nur linux-2.6.33.3.orig/drivers/usb/host/ohci-hcd.c linux-2.6.33.3/drivers/usb/host/ohci-hcd.c
  17042. --- linux-2.6.33.3.orig/drivers/usb/host/ohci-hcd.c 2010-04-26 16:48:30.000000000 +0200
  17043. +++ linux-2.6.33.3/drivers/usb/host/ohci-hcd.c 2010-05-17 16:28:28.163114085 +0200
  17044. @@ -1085,6 +1085,11 @@
  17045. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  17046. #endif
  17047. +#ifdef CONFIG_USB_OHCI_AR71XX
  17048. +#include "ohci-ar71xx.c"
  17049. +#define PLATFORM_DRIVER ohci_hcd_ar71xx_driver
  17050. +#endif
  17051. +
  17052. #if !defined(PCI_DRIVER) && \
  17053. !defined(PLATFORM_DRIVER) && \
  17054. !defined(OF_PLATFORM_DRIVER) && \
  17055. diff -Nur linux-2.6.33.3.orig/drivers/watchdog/ar71xx_wdt.c linux-2.6.33.3/drivers/watchdog/ar71xx_wdt.c
  17056. --- linux-2.6.33.3.orig/drivers/watchdog/ar71xx_wdt.c 1970-01-01 01:00:00.000000000 +0100
  17057. +++ linux-2.6.33.3/drivers/watchdog/ar71xx_wdt.c 2009-12-13 20:45:21.895926395 +0100
  17058. @@ -0,0 +1,270 @@
  17059. +/*
  17060. + * Driver for the Atheros AR71xx SoC's built-in hardware watchdog timer.
  17061. + *
  17062. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  17063. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  17064. + *
  17065. + * This driver was based on: drivers/watchdog/ixp4xx_wdt.c
  17066. + * Author: Deepak Saxena <dsaxena@plexity.net>
  17067. + * Copyright 2004 (c) MontaVista, Software, Inc.
  17068. + *
  17069. + * which again was based on sa1100 driver,
  17070. + * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
  17071. + *
  17072. + * This program is free software; you can redistribute it and/or modify it
  17073. + * under the terms of the GNU General Public License version 2 as published
  17074. + * by the Free Software Foundation.
  17075. + *
  17076. + */
  17077. +
  17078. +#include <linux/bitops.h>
  17079. +#include <linux/errno.h>
  17080. +#include <linux/fs.h>
  17081. +#include <linux/init.h>
  17082. +#include <linux/kernel.h>
  17083. +#include <linux/miscdevice.h>
  17084. +#include <linux/module.h>
  17085. +#include <linux/moduleparam.h>
  17086. +#include <linux/platform_device.h>
  17087. +#include <linux/types.h>
  17088. +#include <linux/watchdog.h>
  17089. +
  17090. +#include <asm/mach-ar71xx/ar71xx.h>
  17091. +
  17092. +#define DRV_NAME "ar71xx-wdt"
  17093. +#define DRV_DESC "Atheros AR71xx hardware watchdog driver"
  17094. +#define DRV_VERSION "0.1.0"
  17095. +
  17096. +#define WDT_TIMEOUT 15 /* seconds */
  17097. +
  17098. +static int nowayout = WATCHDOG_NOWAYOUT;
  17099. +
  17100. +#ifdef CONFIG_WATCHDOG_NOWAYOUT
  17101. +module_param(nowayout, int, 0);
  17102. +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
  17103. + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  17104. +#endif
  17105. +
  17106. +static unsigned long wdt_flags;
  17107. +
  17108. +#define WDT_FLAGS_BUSY 0
  17109. +#define WDT_FLAGS_EXPECT_CLOSE 1
  17110. +
  17111. +static int wdt_timeout = WDT_TIMEOUT;
  17112. +static int boot_status;
  17113. +static int max_timeout;
  17114. +
  17115. +static void inline ar71xx_wdt_keepalive(void)
  17116. +{
  17117. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG, ar71xx_ahb_freq * wdt_timeout);
  17118. +}
  17119. +
  17120. +static void inline ar71xx_wdt_enable(void)
  17121. +{
  17122. + printk(KERN_DEBUG DRV_NAME ": enabling watchdog timer\n");
  17123. + ar71xx_wdt_keepalive();
  17124. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_FCR);
  17125. +}
  17126. +
  17127. +static void inline ar71xx_wdt_disable(void)
  17128. +{
  17129. + printk(KERN_DEBUG DRV_NAME ": disabling watchdog timer\n");
  17130. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_NONE);
  17131. +}
  17132. +
  17133. +static int ar71xx_wdt_set_timeout(int val)
  17134. +{
  17135. + if (val < 1 || val > max_timeout)
  17136. + return -EINVAL;
  17137. +
  17138. + wdt_timeout = val;
  17139. + ar71xx_wdt_keepalive();
  17140. +
  17141. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs\n", wdt_timeout);
  17142. +
  17143. + return 0;
  17144. +}
  17145. +
  17146. +static int ar71xx_wdt_open(struct inode *inode, struct file *file)
  17147. +{
  17148. + if (test_and_set_bit(WDT_FLAGS_BUSY, &wdt_flags))
  17149. + return -EBUSY;
  17150. +
  17151. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17152. +
  17153. + ar71xx_wdt_enable();
  17154. +
  17155. + return nonseekable_open(inode, file);
  17156. +}
  17157. +
  17158. +static int ar71xx_wdt_release(struct inode *inode, struct file *file)
  17159. +{
  17160. + if (test_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags)) {
  17161. + ar71xx_wdt_disable();
  17162. + } else {
  17163. + printk(KERN_CRIT DRV_NAME ": device closed unexpectedly, "
  17164. + "watchdog timer will not stop!\n");
  17165. + }
  17166. +
  17167. + clear_bit(WDT_FLAGS_BUSY, &wdt_flags);
  17168. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17169. +
  17170. + return 0;
  17171. +}
  17172. +
  17173. +static ssize_t ar71xx_wdt_write(struct file *file, const char *data,
  17174. + size_t len, loff_t *ppos)
  17175. +{
  17176. + if (len) {
  17177. + if (!nowayout) {
  17178. + size_t i;
  17179. +
  17180. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17181. +
  17182. + for (i = 0; i != len; i++) {
  17183. + char c;
  17184. +
  17185. + if (get_user(c, data + i))
  17186. + return -EFAULT;
  17187. +
  17188. + if (c == 'V')
  17189. + set_bit(WDT_FLAGS_EXPECT_CLOSE,
  17190. + &wdt_flags);
  17191. + }
  17192. + }
  17193. +
  17194. + ar71xx_wdt_keepalive();
  17195. + }
  17196. +
  17197. + return len;
  17198. +}
  17199. +
  17200. +static struct watchdog_info ar71xx_wdt_info = {
  17201. + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
  17202. + WDIOF_MAGICCLOSE | WDIOF_CARDRESET,
  17203. + .firmware_version = 0,
  17204. + .identity = "AR71XX watchdog",
  17205. +};
  17206. +
  17207. +static int ar71xx_wdt_ioctl(struct inode *inode, struct file *file,
  17208. + unsigned int cmd, unsigned long arg)
  17209. +{
  17210. + int t;
  17211. + int ret;
  17212. +
  17213. + switch (cmd) {
  17214. + case WDIOC_GETSUPPORT:
  17215. + ret = copy_to_user((struct watchdog_info *)arg,
  17216. + &ar71xx_wdt_info,
  17217. + sizeof(&ar71xx_wdt_info)) ? -EFAULT : 0;
  17218. + break;
  17219. +
  17220. + case WDIOC_GETSTATUS:
  17221. + ret = put_user(0, (int *)arg) ? -EFAULT : 0;
  17222. + break;
  17223. +
  17224. + case WDIOC_GETBOOTSTATUS:
  17225. + ret = put_user(boot_status, (int *)arg) ? -EFAULT : 0;
  17226. + break;
  17227. +
  17228. + case WDIOC_KEEPALIVE:
  17229. + ar71xx_wdt_keepalive();
  17230. + ret = 0;
  17231. + break;
  17232. +
  17233. + case WDIOC_SETTIMEOUT:
  17234. + ret = get_user(t, (int *)arg) ? -EFAULT : 0;
  17235. + if (ret)
  17236. + break;
  17237. +
  17238. + ret = ar71xx_wdt_set_timeout(t);
  17239. + if (ret)
  17240. + break;
  17241. +
  17242. + /* fallthrough */
  17243. + case WDIOC_GETTIMEOUT:
  17244. + ret = put_user(wdt_timeout, (int *)arg) ? -EFAULT : 0;
  17245. + break;
  17246. +
  17247. + default:
  17248. + ret = -ENOTTY;
  17249. + break;
  17250. + }
  17251. +
  17252. + return ret;
  17253. +}
  17254. +
  17255. +static const struct file_operations ar71xx_wdt_fops = {
  17256. + .owner = THIS_MODULE,
  17257. + .write = ar71xx_wdt_write,
  17258. + .ioctl = ar71xx_wdt_ioctl,
  17259. + .open = ar71xx_wdt_open,
  17260. + .release = ar71xx_wdt_release,
  17261. +};
  17262. +
  17263. +static struct miscdevice ar71xx_wdt_miscdev = {
  17264. + .minor = WATCHDOG_MINOR,
  17265. + .name = "watchdog",
  17266. + .fops = &ar71xx_wdt_fops,
  17267. +};
  17268. +
  17269. +static int __devinit ar71xx_wdt_probe(struct platform_device *pdev)
  17270. +{
  17271. + int ret;
  17272. +
  17273. + max_timeout = (0xfffffffful / ar71xx_ahb_freq);
  17274. + wdt_timeout = (max_timeout < WDT_TIMEOUT) ? max_timeout : WDT_TIMEOUT;
  17275. +
  17276. + boot_status =
  17277. + (ar71xx_reset_rr(AR71XX_RESET_REG_WDOG_CTRL) & WDOG_CTRL_LAST_RESET) ?
  17278. + WDIOF_CARDRESET : 0;
  17279. +
  17280. + ret = misc_register(&ar71xx_wdt_miscdev);
  17281. + if (ret)
  17282. + goto err_out;
  17283. +
  17284. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  17285. +
  17286. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs (max=%d)\n",
  17287. + wdt_timeout, max_timeout);
  17288. +
  17289. + return 0;
  17290. +
  17291. +err_out:
  17292. + return ret;
  17293. +}
  17294. +
  17295. +static int __devexit ar71xx_wdt_remove(struct platform_device *pdev)
  17296. +{
  17297. + misc_deregister(&ar71xx_wdt_miscdev);
  17298. + return 0;
  17299. +}
  17300. +
  17301. +static struct platform_driver ar71xx_wdt_driver = {
  17302. + .probe = ar71xx_wdt_probe,
  17303. + .remove = __devexit_p(ar71xx_wdt_remove),
  17304. + .driver = {
  17305. + .name = DRV_NAME,
  17306. + .owner = THIS_MODULE,
  17307. + },
  17308. +};
  17309. +
  17310. +static int __init ar71xx_wdt_init(void)
  17311. +{
  17312. + return platform_driver_register(&ar71xx_wdt_driver);
  17313. +}
  17314. +module_init(ar71xx_wdt_init);
  17315. +
  17316. +static void __exit ar71xx_wdt_exit(void)
  17317. +{
  17318. + platform_driver_unregister(&ar71xx_wdt_driver);
  17319. +}
  17320. +module_exit(ar71xx_wdt_exit);
  17321. +
  17322. +MODULE_DESCRIPTION(DRV_DESC);
  17323. +MODULE_VERSION(DRV_VERSION);
  17324. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
  17325. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
  17326. +MODULE_LICENSE("GPL v2");
  17327. +MODULE_ALIAS("platform:" DRV_NAME);
  17328. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  17329. diff -Nur linux-2.6.33.3.orig/drivers/watchdog/Kconfig linux-2.6.33.3/drivers/watchdog/Kconfig
  17330. --- linux-2.6.33.3.orig/drivers/watchdog/Kconfig 2010-04-26 16:48:30.000000000 +0200
  17331. +++ linux-2.6.33.3/drivers/watchdog/Kconfig 2010-05-17 16:28:43.991113674 +0200
  17332. @@ -840,6 +840,13 @@
  17333. help
  17334. Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
  17335. +config AR71XX_WDT
  17336. + tristate "Atheros AR71xx Watchdog Timer"
  17337. + depends on ATHEROS_AR71XX
  17338. + help
  17339. + Hardware driver for the built-in watchdog timer on the Atheros
  17340. + AR71xx SoCs.
  17341. +
  17342. # PARISC Architecture
  17343. # POWERPC Architecture
  17344. diff -Nur linux-2.6.33.3.orig/drivers/watchdog/Makefile linux-2.6.33.3/drivers/watchdog/Makefile
  17345. --- linux-2.6.33.3.orig/drivers/watchdog/Makefile 2010-04-26 16:48:30.000000000 +0200
  17346. +++ linux-2.6.33.3/drivers/watchdog/Makefile 2010-05-17 16:28:43.991113674 +0200
  17347. @@ -112,6 +112,7 @@
  17348. obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
  17349. obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
  17350. obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
  17351. +obj-$(CONFIG_AR71XX_WDT) += ar71xx_wdt.o
  17352. # PARISC Architecture
  17353. diff -Nur linux-2.6.33.3.orig/include/linux/ath9k_platform.h linux-2.6.33.3/include/linux/ath9k_platform.h
  17354. --- linux-2.6.33.3.orig/include/linux/ath9k_platform.h 2010-04-26 16:48:30.000000000 +0200
  17355. +++ linux-2.6.33.3/include/linux/ath9k_platform.h 2010-02-13 16:30:06.932691714 +0100
  17356. @@ -1,19 +1,11 @@
  17357. /*
  17358. - * Copyright (c) 2008 Atheros Communications Inc.
  17359. - * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  17360. - * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
  17361. + * ath9k platform data defines
  17362. *
  17363. - * Permission to use, copy, modify, and/or distribute this software for any
  17364. - * purpose with or without fee is hereby granted, provided that the above
  17365. - * copyright notice and this permission notice appear in all copies.
  17366. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  17367. *
  17368. - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  17369. - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  17370. - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  17371. - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17372. - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17373. - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17374. - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17375. + * This program is free software; you can redistribute it and/or modify it
  17376. + * under the terms of the GNU General Public License version 2 as published
  17377. + * by the Free Software Foundation.
  17378. */
  17379. #ifndef _LINUX_ATH9K_PLATFORM_H
  17380. @@ -23,6 +15,9 @@
  17381. struct ath9k_platform_data {
  17382. u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
  17383. + u8 *macaddr;
  17384. +
  17385. + unsigned long quirk_wndr3700:1;
  17386. };
  17387. #endif /* _LINUX_ATH9K_PLATFORM_H */
  17388. diff -Nur linux-2.6.33.3.orig/include/linux/gpio_buttons.h linux-2.6.33.3/include/linux/gpio_buttons.h
  17389. --- linux-2.6.33.3.orig/include/linux/gpio_buttons.h 1970-01-01 01:00:00.000000000 +0100
  17390. +++ linux-2.6.33.3/include/linux/gpio_buttons.h 2010-05-17 20:56:04.279120442 +0200
  17391. @@ -0,0 +1,33 @@
  17392. +/*
  17393. + * Definitions for the GPIO buttons interface driver
  17394. + *
  17395. + * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
  17396. + *
  17397. + * This file was based on: /include/linux/gpio_keys.h
  17398. + * The original gpio_keys.h seems not to have a license.
  17399. + *
  17400. + * This program is free software; you can redistribute it and/or modify
  17401. + * it under the terms of the GNU General Public License version 2 as
  17402. + * published by the Free Software Foundation.
  17403. + *
  17404. + */
  17405. +
  17406. +#ifndef _GPIO_BUTTONS_H_
  17407. +#define _GPIO_BUTTONS_H_
  17408. +
  17409. +struct gpio_button {
  17410. + int gpio; /* GPIO line number */
  17411. + int active_low;
  17412. + char *desc; /* button description */
  17413. + int type; /* input event type (EV_KEY, EV_SW) */
  17414. + int code; /* input event code (KEY_*, SW_*) */
  17415. + int threshold; /* count threshold */
  17416. +};
  17417. +
  17418. +struct gpio_buttons_platform_data {
  17419. + struct gpio_button *buttons;
  17420. + int nbuttons; /* number of buttons */
  17421. + int poll_interval; /* polling interval */
  17422. +};
  17423. +
  17424. +#endif /* _GPIO_BUTTONS_H_ */
  17425. diff -Nur linux-2.6.33.3.orig/include/linux/gpio_dev.h linux-2.6.33.3/include/linux/gpio_dev.h
  17426. --- linux-2.6.33.3.orig/include/linux/gpio_dev.h 1970-01-01 01:00:00.000000000 +0100
  17427. +++ linux-2.6.33.3/include/linux/gpio_dev.h 2010-05-17 20:56:04.293291521 +0200
  17428. @@ -0,0 +1,11 @@
  17429. +#ifndef _GPIODEV_H__
  17430. +#define _GPIODEV_H__
  17431. +
  17432. +#define IOC_GPIODEV_MAGIC 'B'
  17433. +#define GPIO_GET _IO(IOC_GPIODEV_MAGIC, 10)
  17434. +#define GPIO_SET _IO(IOC_GPIODEV_MAGIC, 11)
  17435. +#define GPIO_CLEAR _IO(IOC_GPIODEV_MAGIC, 12)
  17436. +#define GPIO_DIR_IN _IO(IOC_GPIODEV_MAGIC, 13)
  17437. +#define GPIO_DIR_OUT _IO(IOC_GPIODEV_MAGIC, 14)
  17438. +
  17439. +#endif
  17440. diff -Nur linux-2.6.33.3.orig/include/linux/netdevice.h linux-2.6.33.3/include/linux/netdevice.h
  17441. --- linux-2.6.33.3.orig/include/linux/netdevice.h 2010-04-26 16:48:30.000000000 +0200
  17442. +++ linux-2.6.33.3/include/linux/netdevice.h 2010-05-17 21:40:17.027115732 +0200
  17443. @@ -844,6 +844,7 @@
  17444. void *ax25_ptr; /* AX.25 specific data */
  17445. struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
  17446. assign before registering */
  17447. + void *phy_ptr; /* PHY device specific data */
  17448. /*
  17449. * Cache line mostly used on receive path (including eth_type_trans())
  17450. diff -Nur linux-2.6.33.3.orig/include/linux/nxp_74hc153.h linux-2.6.33.3/include/linux/nxp_74hc153.h
  17451. --- linux-2.6.33.3.orig/include/linux/nxp_74hc153.h 1970-01-01 01:00:00.000000000 +0100
  17452. +++ linux-2.6.33.3/include/linux/nxp_74hc153.h 2010-01-19 19:26:36.441435904 +0100
  17453. @@ -0,0 +1,24 @@
  17454. +/*
  17455. + * NXP 74HC153 - Dual 4-input multiplexer defines
  17456. + *
  17457. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  17458. + *
  17459. + * This program is free software; you can redistribute it and/or modify
  17460. + * it under the terms of the GNU General Public License version 2 as
  17461. + * published by the Free Software Foundation.
  17462. + */
  17463. +
  17464. +#ifndef _NXP_74HC153_H
  17465. +#define _NXP_74HC153_H
  17466. +
  17467. +#define NXP_74HC153_DRIVER_NAME "nxp-74hc153"
  17468. +
  17469. +struct nxp_74hc153_platform_data {
  17470. + unsigned gpio_base;
  17471. + unsigned gpio_pin_s0;
  17472. + unsigned gpio_pin_s1;
  17473. + unsigned gpio_pin_1y;
  17474. + unsigned gpio_pin_2y;
  17475. +};
  17476. +
  17477. +#endif /* _NXP_74HC153_H */
  17478. diff -Nur linux-2.6.33.3.orig/include/linux/phy.h linux-2.6.33.3/include/linux/phy.h
  17479. --- linux-2.6.33.3.orig/include/linux/phy.h 2010-04-26 16:48:30.000000000 +0200
  17480. +++ linux-2.6.33.3/include/linux/phy.h 2010-05-17 21:40:17.023114663 +0200
  17481. @@ -325,6 +325,20 @@
  17482. void (*adjust_link)(struct net_device *dev);
  17483. void (*adjust_state)(struct net_device *dev);
  17484. +
  17485. + /*
  17486. + * By default these point to the original functions
  17487. + * with the same name. adding them to the phy_device
  17488. + * allows the phy driver to override them for packet
  17489. + * mangling if the ethernet driver supports it
  17490. + * This is required to support some really horrible
  17491. + * switches such as the Marvell 88E6060
  17492. + */
  17493. + int (*netif_receive_skb)(struct sk_buff *skb);
  17494. + int (*netif_rx)(struct sk_buff *skb);
  17495. +
  17496. + /* alignment offset for packets */
  17497. + int pkt_align;
  17498. };
  17499. #define to_phy_device(d) container_of(d, struct phy_device, dev)
  17500. @@ -491,6 +505,7 @@
  17501. void phy_stop_machine(struct phy_device *phydev);
  17502. int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  17503. int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  17504. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
  17505. int phy_mii_ioctl(struct phy_device *phydev,
  17506. struct mii_ioctl_data *mii_data, int cmd);
  17507. int phy_start_interrupts(struct phy_device *phydev);
  17508. diff -Nur linux-2.6.33.3.orig/include/linux/spi/vsc7385.h linux-2.6.33.3/include/linux/spi/vsc7385.h
  17509. --- linux-2.6.33.3.orig/include/linux/spi/vsc7385.h 1970-01-01 01:00:00.000000000 +0100
  17510. +++ linux-2.6.33.3/include/linux/spi/vsc7385.h 2009-12-13 20:45:19.923921372 +0100
  17511. @@ -0,0 +1,19 @@
  17512. +/*
  17513. + * Platform data definition for the Vitesse VSC7385 ethernet switch driver
  17514. + *
  17515. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  17516. + *
  17517. + * This program is free software; you can redistribute it and/or modify it
  17518. + * under the terms of the GNU General Public License version 2 as published
  17519. + * by the Free Software Foundation.
  17520. + */
  17521. +
  17522. +struct vsc7385_platform_data {
  17523. + void (* reset)(void);
  17524. + char *ucode_name;
  17525. + struct {
  17526. + u32 tx_ipg:5;
  17527. + u32 bit2:1;
  17528. + u32 clk_sel:3;
  17529. + } mac_cfg;
  17530. +};
  17531. diff -Nur linux-2.6.33.3.orig/net/dsa/ar7240.c linux-2.6.33.3/net/dsa/ar7240.c
  17532. --- linux-2.6.33.3.orig/net/dsa/ar7240.c 1970-01-01 01:00:00.000000000 +0100
  17533. +++ linux-2.6.33.3/net/dsa/ar7240.c 2010-03-12 19:31:45.562053091 +0100
  17534. @@ -0,0 +1,736 @@
  17535. +/*
  17536. + * DSA driver for the built-in ethernet switch of the Atheros AR7240 SoC
  17537. + * Copyright (c) 2010 Gabor Juhos <juhosg@openwrt.org>
  17538. + *
  17539. + * This file was based on:
  17540. + * net/dsa/mv88e6060.c - Driver for Marvell 88e6060 switch chips
  17541. + * Copyright (c) 2008 Marvell Semiconductor
  17542. + *
  17543. + * This program is free software; you can redistribute it and/or modify it
  17544. + * under the terms of the GNU General Public License version 2 as published
  17545. + * by the Free Software Foundation.
  17546. + *
  17547. + */
  17548. +
  17549. +#include <linux/etherdevice.h>
  17550. +#include <linux/list.h>
  17551. +#include <linux/netdevice.h>
  17552. +#include <linux/phy.h>
  17553. +#include <linux/mii.h>
  17554. +#include <linux/bitops.h>
  17555. +
  17556. +#include "dsa_priv.h"
  17557. +
  17558. +#define BITM(_count) (BIT(_count) - 1)
  17559. +
  17560. +#define AR7240_REG_MASK_CTRL 0x00
  17561. +#define AR7240_MASK_CTRL_REVISION_M BITM(8)
  17562. +#define AR7240_MASK_CTRL_VERSION_M BITM(8)
  17563. +#define AR7240_MASK_CTRL_VERSION_S 8
  17564. +#define AR7240_MASK_CTRL_SOFT_RESET BIT(31)
  17565. +
  17566. +#define AR7240_REG_MAC_ADDR0 0x20
  17567. +#define AR7240_REG_MAC_ADDR1 0x24
  17568. +
  17569. +#define AR7240_REG_FLOOD_MASK 0x2c
  17570. +#define AR7240_FLOOD_MASK_BROAD_TO_CPU BIT(26)
  17571. +
  17572. +#define AR7240_REG_GLOBAL_CTRL 0x30
  17573. +#define AR7240_GLOBAL_CTRL_MTU_M BITM(12)
  17574. +
  17575. +#define AR7240_REG_AT_CTRL 0x5c
  17576. +#define AR7240_AT_CTRL_ARP_EN BIT(20)
  17577. +
  17578. +#define AR7240_REG_TAG_PRIORITY 0x70
  17579. +
  17580. +#define AR7240_REG_SERVICE_TAG 0x74
  17581. +#define AR7240_SERVICE_TAG_M BITM(16)
  17582. +
  17583. +#define AR7240_REG_CPU_PORT 0x78
  17584. +#define AR7240_MIRROR_PORT_S 4
  17585. +#define AR7240_CPU_PORT_EN BIT(8)
  17586. +
  17587. +#define AR7240_REG_MIB_FUNCTION0 0x80
  17588. +#define AR7240_MIB_TIMER_M BITM(16)
  17589. +#define AR7240_MIB_AT_HALF_EN BIT(16)
  17590. +#define AR7240_MIB_BUSY BIT(17)
  17591. +#define AR7240_MIB_FUNC_S 24
  17592. +#define AR7240_MIB_FUNC_NO_OP 0x0
  17593. +#define AR7240_MIB_FUNC_FLUSH 0x1
  17594. +#define AR7240_MIB_FUNC_CAPTURE 0x3
  17595. +
  17596. +#define AR7240_REG_MDIO_CTRL 0x98
  17597. +#define AR7240_MDIO_CTRL_DATA_M BITM(16)
  17598. +#define AR7240_MDIO_CTRL_REG_ADDR_S 16
  17599. +#define AR7240_MDIO_CTRL_PHY_ADDR_S 21
  17600. +#define AR7240_MDIO_CTRL_CMD_WRITE 0
  17601. +#define AR7240_MDIO_CTRL_CMD_READ BIT(27)
  17602. +#define AR7240_MDIO_CTRL_MASTER_EN BIT(30)
  17603. +#define AR7240_MDIO_CTRL_BUSY BIT(31)
  17604. +
  17605. +#define AR7240_REG_PORT_BASE(_port) (0x100 + (_port) * 0x100)
  17606. +
  17607. +#define AR7240_REG_PORT_STATUS(_port) (AR7240_REG_PORT_BASE((_port)) + 0x00)
  17608. +#define AR7240_PORT_STATUS_SPEED_M BITM(2)
  17609. +#define AR7240_PORT_STATUS_SPEED_10 0
  17610. +#define AR7240_PORT_STATUS_SPEED_100 1
  17611. +#define AR7240_PORT_STATUS_SPEED_1000 2
  17612. +#define AR7240_PORT_STATUS_TXMAC BIT(2)
  17613. +#define AR7240_PORT_STATUS_RXMAC BIT(3)
  17614. +#define AR7240_PORT_STATUS_TXFLOW BIT(4)
  17615. +#define AR7240_PORT_STATUS_RXFLOW BIT(5)
  17616. +#define AR7240_PORT_STATUS_DUPLEX BIT(6)
  17617. +#define AR7240_PORT_STATUS_LINK_UP BIT(8)
  17618. +#define AR7240_PORT_STATUS_LINK_AUTO BIT(9)
  17619. +#define AR7240_PORT_STATUS_LINK_PAUSE BIT(10)
  17620. +
  17621. +#define AR7240_REG_PORT_CTRL(_port) (AR7240_REG_PORT_BASE((_port)) + 0x04)
  17622. +#define AR7240_PORT_CTRL_STATE_M BITM(3)
  17623. +#define AR7240_PORT_CTRL_STATE_DISABLED 0
  17624. +#define AR7240_PORT_CTRL_STATE_BLOCK 1
  17625. +#define AR7240_PORT_CTRL_STATE_LISTEN 2
  17626. +#define AR7240_PORT_CTRL_STATE_LEARN 3
  17627. +#define AR7240_PORT_CTRL_STATE_FORWARD 4
  17628. +#define AR7240_PORT_CTRL_LEARN_LOCK BIT(7)
  17629. +#define AR7240_PORT_CTRL_VLAN_MODE_S 8
  17630. +#define AR7240_PORT_CTRL_VLAN_MODE_KEEP 0
  17631. +#define AR7240_PORT_CTRL_VLAN_MODE_STRIP 1
  17632. +#define AR7240_PORT_CTRL_VLAN_MODE_ADD 2
  17633. +#define AR7240_PORT_CTRL_VLAN_MODE_DOUBLE_TAG 3
  17634. +#define AR7240_PORT_CTRL_IGMP_SNOOP BIT(10)
  17635. +#define AR7240_PORT_CTRL_HEADER BIT(11)
  17636. +#define AR7240_PORT_CTRL_MAC_LOOP BIT(12)
  17637. +#define AR7240_PORT_CTRL_SINGLE_VLAN BIT(13)
  17638. +#define AR7240_PORT_CTRL_LEARN BIT(14)
  17639. +#define AR7240_PORT_CTRL_DOUBLE_TAG BIT(15)
  17640. +#define AR7240_PORT_CTRL_MIRROR_TX BIT(16)
  17641. +#define AR7240_PORT_CTRL_MIRROR_RX BIT(17)
  17642. +
  17643. +#define AR7240_REG_PORT_VLAN(_port) (AR7240_REG_PORT_BASE((_port)) + 0x08)
  17644. +
  17645. +#define AR7240_PORT_VLAN_DEFAULT_ID_S 0
  17646. +#define AR7240_PORT_VLAN_DEST_PORTS_S 16
  17647. +
  17648. +#define AR7240_REG_STATS_BASE(_port) (0x20000 + (_port) * 0x100)
  17649. +
  17650. +#define AR7240_STATS_RXBROAD 0x00
  17651. +#define AR7240_STATS_RXPAUSE 0x04
  17652. +#define AR7240_STATS_RXMULTI 0x08
  17653. +#define AR7240_STATS_RXFCSERR 0x0c
  17654. +#define AR7240_STATS_RXALIGNERR 0x10
  17655. +#define AR7240_STATS_RXRUNT 0x14
  17656. +#define AR7240_STATS_RXFRAGMENT 0x18
  17657. +#define AR7240_STATS_RX64BYTE 0x1c
  17658. +#define AR7240_STATS_RX128BYTE 0x20
  17659. +#define AR7240_STATS_RX256BYTE 0x24
  17660. +#define AR7240_STATS_RX512BYTE 0x28
  17661. +#define AR7240_STATS_RX1024BYTE 0x2c
  17662. +#define AR7240_STATS_RX1518BYTE 0x30
  17663. +#define AR7240_STATS_RXMAXBYTE 0x34
  17664. +#define AR7240_STATS_RXTOOLONG 0x38
  17665. +#define AR7240_STATS_RXGOODBYTE 0x3c
  17666. +#define AR7240_STATS_RXBADBYTE 0x44
  17667. +#define AR7240_STATS_RXOVERFLOW 0x4c
  17668. +#define AR7240_STATS_FILTERED 0x50
  17669. +#define AR7240_STATS_TXBROAD 0x54
  17670. +#define AR7240_STATS_TXPAUSE 0x58
  17671. +#define AR7240_STATS_TXMULTI 0x5c
  17672. +#define AR7240_STATS_TXUNDERRUN 0x60
  17673. +#define AR7240_STATS_TX64BYTE 0x64
  17674. +#define AR7240_STATS_TX128BYTE 0x68
  17675. +#define AR7240_STATS_TX256BYTE 0x6c
  17676. +#define AR7240_STATS_TX512BYTE 0x70
  17677. +#define AR7240_STATS_TX1024BYTE 0x74
  17678. +#define AR7240_STATS_TX1518BYTE 0x78
  17679. +#define AR7240_STATS_TXMAXBYTE 0x7c
  17680. +#define AR7240_STATS_TXOVERSIZE 0x80
  17681. +#define AR7240_STATS_TXBYTE 0x84
  17682. +#define AR7240_STATS_TXCOLLISION 0x8c
  17683. +#define AR7240_STATS_TXABORTCOL 0x90
  17684. +#define AR7240_STATS_TXMULTICOL 0x94
  17685. +#define AR7240_STATS_TXSINGLECOL 0x98
  17686. +#define AR7240_STATS_TXEXCDEFER 0x9c
  17687. +#define AR7240_STATS_TXDEFER 0xa0
  17688. +#define AR7240_STATS_TXLATECOL 0xa4
  17689. +
  17690. +#define AR7240_PORT_CPU 0
  17691. +#define AR7240_NUM_PORTS 6
  17692. +#define AR7240_NUM_PHYS 5
  17693. +
  17694. +#define AR7240_PHY_ID1 0x004d
  17695. +#define AR7240_PHY_ID2 0xd041
  17696. +
  17697. +#define AR7240_PORT_MASK(_port) BIT((_port))
  17698. +#define AR7240_PORT_MASK_ALL BITM(AR7240_NUM_PORTS)
  17699. +#define AR7240_PORT_MASK_BUT(_port) (AR7240_PORT_MASK_ALL & ~BIT((_port)))
  17700. +
  17701. +struct ar7240sw {
  17702. + struct mii_bus *mii_bus;
  17703. + struct mutex reg_mutex;
  17704. + struct mutex stats_mutex;
  17705. +};
  17706. +
  17707. +struct ar7240sw_hw_stat {
  17708. + char string[ETH_GSTRING_LEN];
  17709. + int sizeof_stat;
  17710. + int reg;
  17711. +};
  17712. +
  17713. +static inline struct ar7240sw *dsa_to_ar7240sw(struct dsa_switch *ds)
  17714. +{
  17715. + return (struct ar7240sw *)(ds + 1);
  17716. +}
  17717. +
  17718. +static inline void ar7240sw_init(struct ar7240sw *as, struct mii_bus *mii)
  17719. +{
  17720. + as->mii_bus = mii;
  17721. + mutex_init(&as->reg_mutex);
  17722. + mutex_init(&as->stats_mutex);
  17723. +}
  17724. +
  17725. +static inline u16 mk_phy_addr(u32 reg)
  17726. +{
  17727. + return (0x17 & ((reg >> 4) | 0x10));
  17728. +}
  17729. +
  17730. +static inline u16 mk_phy_reg(u32 reg)
  17731. +{
  17732. + return ((reg << 1) & 0x1e);
  17733. +}
  17734. +
  17735. +static inline u16 mk_high_addr(u32 reg)
  17736. +{
  17737. + return ((reg >> 7) & 0x1ff);
  17738. +}
  17739. +
  17740. +static u32 __ar7240sw_reg_read(struct ar7240sw *as, u32 reg)
  17741. +{
  17742. + struct mii_bus *mii = as->mii_bus;
  17743. + u16 phy_addr;
  17744. + u16 phy_reg;
  17745. + u32 hi, lo;
  17746. +
  17747. + reg = (reg & 0xfffffffc) >> 2;
  17748. +
  17749. + mdiobus_write(mii, 0x1f, 0x10, mk_high_addr(reg));
  17750. +
  17751. + phy_addr = mk_phy_addr(reg);
  17752. + phy_reg = mk_phy_reg(reg);
  17753. +
  17754. + lo = (u32) mdiobus_read(mii, phy_addr, phy_reg);
  17755. + hi = (u32) mdiobus_read(mii, phy_addr, phy_reg + 1);
  17756. +
  17757. + return ((hi << 16) | lo);
  17758. +}
  17759. +
  17760. +static void __ar7240sw_reg_write(struct ar7240sw *as, u32 reg, u32 val)
  17761. +{
  17762. + struct mii_bus *mii = as->mii_bus;
  17763. + u16 phy_addr;
  17764. + u16 phy_reg;
  17765. +
  17766. + reg = (reg & 0xfffffffc) >> 2;
  17767. +
  17768. + mdiobus_write(mii, 0x1f, 0x10, mk_high_addr(reg));
  17769. +
  17770. + phy_addr = mk_phy_addr(reg);
  17771. + phy_reg = mk_phy_reg(reg);
  17772. +
  17773. + mdiobus_write(mii, phy_addr, phy_reg + 1, (val >> 16));
  17774. + mdiobus_write(mii, phy_addr, phy_reg, (val & 0xffff));
  17775. +}
  17776. +
  17777. +static u32 ar7240sw_reg_read(struct ar7240sw *as, u32 reg_addr)
  17778. +{
  17779. + u32 ret;
  17780. +
  17781. + mutex_lock(&as->reg_mutex);
  17782. + ret = __ar7240sw_reg_read(as, reg_addr);
  17783. + mutex_unlock(&as->reg_mutex);
  17784. +
  17785. + return ret;
  17786. +}
  17787. +
  17788. +static void ar7240sw_reg_write(struct ar7240sw *as, u32 reg_addr, u32 reg_val)
  17789. +{
  17790. + mutex_lock(&as->reg_mutex);
  17791. + __ar7240sw_reg_write(as, reg_addr, reg_val);
  17792. + mutex_unlock(&as->reg_mutex);
  17793. +}
  17794. +
  17795. +static u32 ar7240sw_reg_rmw(struct ar7240sw *as, u32 reg, u32 mask, u32 val)
  17796. +{
  17797. + u32 t;
  17798. +
  17799. + mutex_lock(&as->reg_mutex);
  17800. + t = __ar7240sw_reg_read(as, reg);
  17801. + t &= ~mask;
  17802. + t |= val;
  17803. + __ar7240sw_reg_write(as, reg, t);
  17804. + mutex_unlock(&as->reg_mutex);
  17805. +
  17806. + return t;
  17807. +}
  17808. +
  17809. +static void ar7240sw_reg_set(struct ar7240sw *as, u32 reg, u32 val)
  17810. +{
  17811. + u32 t;
  17812. +
  17813. + mutex_lock(&as->reg_mutex);
  17814. + t = __ar7240sw_reg_read(as, reg);
  17815. + t |= val;
  17816. + __ar7240sw_reg_write(as, reg, t);
  17817. + mutex_unlock(&as->reg_mutex);
  17818. +}
  17819. +
  17820. +static int ar7240sw_reg_wait(struct ar7240sw *as, u32 reg, u32 mask, u32 val,
  17821. + unsigned timeout)
  17822. +{
  17823. + int i;
  17824. +
  17825. + for (i = 0; i < timeout; i++) {
  17826. + u32 t;
  17827. +
  17828. + t = ar7240sw_reg_read(as, reg);
  17829. + if ((t & mask) == val)
  17830. + return 0;
  17831. +
  17832. + msleep(1);
  17833. + }
  17834. +
  17835. + return -ETIMEDOUT;
  17836. +}
  17837. +
  17838. +static u16 ar7240sw_phy_read(struct ar7240sw *as, unsigned phy_addr,
  17839. + unsigned reg_addr)
  17840. +{
  17841. + u32 t;
  17842. + int err;
  17843. +
  17844. + if (phy_addr >= AR7240_NUM_PHYS)
  17845. + return 0xffff;
  17846. +
  17847. + t = (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  17848. + (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  17849. + AR7240_MDIO_CTRL_MASTER_EN |
  17850. + AR7240_MDIO_CTRL_BUSY |
  17851. + AR7240_MDIO_CTRL_CMD_READ;
  17852. +
  17853. + ar7240sw_reg_write(as, AR7240_REG_MDIO_CTRL, t);
  17854. + err = ar7240sw_reg_wait(as, AR7240_REG_MDIO_CTRL,
  17855. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  17856. + if (err)
  17857. + return 0xffff;
  17858. +
  17859. + t = ar7240sw_reg_read(as, AR7240_REG_MDIO_CTRL);
  17860. + return (t & AR7240_MDIO_CTRL_DATA_M);
  17861. +}
  17862. +
  17863. +static int ar7240sw_phy_write(struct ar7240sw *as, unsigned phy_addr,
  17864. + unsigned reg_addr, u16 reg_val)
  17865. +{
  17866. + u32 t;
  17867. + int ret;
  17868. +
  17869. + if (phy_addr >= AR7240_NUM_PHYS)
  17870. + return -EINVAL;
  17871. +
  17872. + t = (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  17873. + (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  17874. + AR7240_MDIO_CTRL_MASTER_EN |
  17875. + AR7240_MDIO_CTRL_BUSY |
  17876. + AR7240_MDIO_CTRL_CMD_WRITE |
  17877. + reg_val;
  17878. +
  17879. + ar7240sw_reg_write(as, AR7240_REG_MDIO_CTRL, t);
  17880. + ret = ar7240sw_reg_wait(as, AR7240_REG_MDIO_CTRL,
  17881. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  17882. + return ret;
  17883. +}
  17884. +
  17885. +static int ar7240sw_capture_stats(struct ar7240sw *as)
  17886. +{
  17887. + int ret;
  17888. +
  17889. + /* Capture the hardware statistics for all ports */
  17890. + ar7240sw_reg_write(as, AR7240_REG_MIB_FUNCTION0,
  17891. + (AR7240_MIB_FUNC_CAPTURE << AR7240_MIB_FUNC_S));
  17892. +
  17893. + /* Wait for the capturing to complete. */
  17894. + ret = ar7240sw_reg_wait(as, AR7240_REG_MIB_FUNCTION0,
  17895. + AR7240_MIB_BUSY, 0, 10);
  17896. + return ret;
  17897. +}
  17898. +
  17899. +static void ar7240sw_disable_port(struct ar7240sw *as, unsigned port)
  17900. +{
  17901. + ar7240sw_reg_write(as, AR7240_REG_PORT_CTRL(port),
  17902. + AR7240_PORT_CTRL_STATE_DISABLED);
  17903. +}
  17904. +
  17905. +static int ar7240sw_reset(struct ar7240sw *as)
  17906. +{
  17907. + int ret;
  17908. + int i;
  17909. +
  17910. + /* Set all ports to disabled state. */
  17911. + for (i = 0; i < AR7240_NUM_PORTS; i++)
  17912. + ar7240sw_disable_port(as, i);
  17913. +
  17914. + /* Wait for transmit queues to drain. */
  17915. + msleep(2);
  17916. +
  17917. + /* Reset the switch. */
  17918. + ar7240sw_reg_write(as, AR7240_REG_MASK_CTRL,
  17919. + AR7240_MASK_CTRL_SOFT_RESET);
  17920. +
  17921. + ret = ar7240sw_reg_wait(as, AR7240_REG_MASK_CTRL,
  17922. + AR7240_MASK_CTRL_SOFT_RESET, 0, 1000);
  17923. + return ret;
  17924. +}
  17925. +
  17926. +static void ar7240sw_setup(struct ar7240sw *as)
  17927. +{
  17928. + /* Enable CPU port, and disable mirror port */
  17929. + ar7240sw_reg_write(as, AR7240_REG_CPU_PORT,
  17930. + AR7240_CPU_PORT_EN |
  17931. + (15 << AR7240_MIRROR_PORT_S));
  17932. +
  17933. + /* Setup TAG priority mapping */
  17934. + ar7240sw_reg_write(as, AR7240_REG_TAG_PRIORITY, 0xfa50);
  17935. +
  17936. + /* Enable ARP frame acknowledge */
  17937. + ar7240sw_reg_set(as, AR7240_REG_AT_CTRL, AR7240_AT_CTRL_ARP_EN);
  17938. +
  17939. + /* Enable Broadcast frames transmitted to the CPU */
  17940. + ar7240sw_reg_set(as, AR7240_REG_FLOOD_MASK,
  17941. + AR7240_FLOOD_MASK_BROAD_TO_CPU);
  17942. +
  17943. + /* setup MTU */
  17944. + ar7240sw_reg_rmw(as, AR7240_REG_GLOBAL_CTRL, AR7240_GLOBAL_CTRL_MTU_M,
  17945. + 1536);
  17946. +
  17947. + /* setup Service TAG */
  17948. + ar7240sw_reg_rmw(as, AR7240_REG_SERVICE_TAG, AR7240_SERVICE_TAG_M,
  17949. + ETH_P_QINQ);
  17950. +}
  17951. +
  17952. +static void ar7240sw_setup_port(struct ar7240sw *as, unsigned port)
  17953. +{
  17954. + u32 ctrl;
  17955. + u32 dest_ports;
  17956. + u32 vlan;
  17957. +
  17958. + ctrl = AR7240_PORT_CTRL_STATE_FORWARD;
  17959. +
  17960. + if (port == AR7240_PORT_CPU) {
  17961. + ar7240sw_reg_write(as, AR7240_REG_PORT_STATUS(port),
  17962. + AR7240_PORT_STATUS_SPEED_1000 |
  17963. + AR7240_PORT_STATUS_TXFLOW |
  17964. + AR7240_PORT_STATUS_RXFLOW |
  17965. + AR7240_PORT_STATUS_TXMAC |
  17966. + AR7240_PORT_STATUS_RXMAC |
  17967. + AR7240_PORT_STATUS_DUPLEX);
  17968. +
  17969. + /* allow the CPU port to talk to each of the 'real' ports */
  17970. + dest_ports = AR7240_PORT_MASK_BUT(port);
  17971. +
  17972. + /* remove service tag from ingress frames */
  17973. + ctrl |= AR7240_PORT_CTRL_DOUBLE_TAG;
  17974. + } else {
  17975. + ar7240sw_reg_write(as, AR7240_REG_PORT_STATUS(port),
  17976. + AR7240_PORT_STATUS_LINK_AUTO);
  17977. +
  17978. + /*
  17979. + * allow each of the 'real' ports to only talk to the CPU
  17980. + * port.
  17981. + */
  17982. + dest_ports = AR7240_PORT_MASK(port) |
  17983. + AR7240_PORT_MASK(AR7240_PORT_CPU);
  17984. +
  17985. + /* add service tag to egress frames */
  17986. + ctrl |= (AR7240_PORT_CTRL_VLAN_MODE_DOUBLE_TAG <<
  17987. + AR7240_PORT_CTRL_VLAN_MODE_S);
  17988. + }
  17989. +
  17990. + /* set default VID and and destination ports for this VLAN */
  17991. + vlan = port;
  17992. + vlan |= (dest_ports << AR7240_PORT_VLAN_DEST_PORTS_S);
  17993. +
  17994. + ar7240sw_reg_write(as, AR7240_REG_PORT_CTRL(port), ctrl);
  17995. + ar7240sw_reg_write(as, AR7240_REG_PORT_VLAN(port), vlan);
  17996. +}
  17997. +
  17998. +static char *ar7240_dsa_probe(struct mii_bus *mii, int sw_addr)
  17999. +{
  18000. + struct ar7240sw as;
  18001. + u32 ctrl;
  18002. + u16 phy_id1;
  18003. + u16 phy_id2;
  18004. + u8 ver;
  18005. +
  18006. + ar7240sw_init(&as, mii);
  18007. +
  18008. + ctrl = ar7240sw_reg_read(&as, AR7240_REG_MASK_CTRL);
  18009. +
  18010. + ver = (ctrl >> AR7240_MASK_CTRL_VERSION_S) & AR7240_MASK_CTRL_VERSION_M;
  18011. + if (ver != 1) {
  18012. + pr_err("ar7240_dsa: unsupported chip, ctrl=%08x\n", ctrl);
  18013. + return NULL;
  18014. + }
  18015. +
  18016. + phy_id1 = ar7240sw_phy_read(&as, 0, MII_PHYSID1);
  18017. + phy_id2 = ar7240sw_phy_read(&as, 0, MII_PHYSID2);
  18018. + if (phy_id1 != AR7240_PHY_ID1 || phy_id2 != AR7240_PHY_ID2) {
  18019. + pr_err("ar7240_dsa: unknown phy id '%04x:%04x'\n",
  18020. + phy_id1, phy_id2);
  18021. + return NULL;
  18022. + }
  18023. +
  18024. + return "Atheros AR7240 built-in";
  18025. +}
  18026. +
  18027. +static int ar7240_dsa_setup(struct dsa_switch *ds)
  18028. +{
  18029. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18030. + int i;
  18031. + int ret;
  18032. +
  18033. + ar7240sw_init(as, ds->master_mii_bus);
  18034. +
  18035. + ret = ar7240sw_reset(as);
  18036. + if (ret)
  18037. + return ret;
  18038. +
  18039. + ar7240sw_setup(as);
  18040. +
  18041. + for (i = 0; i < AR7240_NUM_PORTS; i++) {
  18042. + if (dsa_is_cpu_port(ds, i) || (ds->phys_port_mask & (1 << i)))
  18043. + ar7240sw_setup_port(as, i);
  18044. + else
  18045. + ar7240sw_disable_port(as, i);
  18046. + }
  18047. +
  18048. + return 0;
  18049. +}
  18050. +
  18051. +static int ar7240_dsa_set_addr(struct dsa_switch *ds, u8 *addr)
  18052. +{
  18053. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18054. + u32 t;
  18055. +
  18056. + t = (addr[4] << 8) | addr[5];
  18057. + ar7240sw_reg_write(as, AR7240_REG_MAC_ADDR0, t);
  18058. +
  18059. + t = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
  18060. + ar7240sw_reg_write(as, AR7240_REG_MAC_ADDR1, t);
  18061. +
  18062. + return 0;
  18063. +}
  18064. +
  18065. +static int ar7240_iort_to_phy_addr(int port)
  18066. +{
  18067. + if (port > 0 && port < AR7240_NUM_PORTS)
  18068. + return port - 1;
  18069. +
  18070. + return -EINVAL;
  18071. +}
  18072. +
  18073. +static int ar7240_dsa_phy_read(struct dsa_switch *ds, int port, int regnum)
  18074. +{
  18075. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18076. + int phy_addr;
  18077. +
  18078. + phy_addr = ar7240_iort_to_phy_addr(port);
  18079. + if (phy_addr < 0)
  18080. + return 0xffff;
  18081. +
  18082. + return ar7240sw_phy_read(as, phy_addr, regnum);
  18083. +}
  18084. +
  18085. +static int ar7240_dsa_phy_write(struct dsa_switch *ds, int port, int regnum,
  18086. + u16 val)
  18087. +{
  18088. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18089. + int phy_addr;
  18090. +
  18091. + phy_addr = ar7240_iort_to_phy_addr(port);
  18092. + if (phy_addr < 0)
  18093. + return 0xffff;
  18094. +
  18095. + return ar7240sw_phy_write(as, phy_addr, regnum, val);
  18096. +}
  18097. +
  18098. +static const char *ar7240sw_speed_str(unsigned speed)
  18099. +{
  18100. + switch (speed) {
  18101. + case AR7240_PORT_STATUS_SPEED_10:
  18102. + return "10";
  18103. + case AR7240_PORT_STATUS_SPEED_100:
  18104. + return "100";
  18105. + case AR7240_PORT_STATUS_SPEED_1000:
  18106. + return "1000";
  18107. + }
  18108. +
  18109. + return "????";
  18110. +}
  18111. +
  18112. +static void ar7240_dsa_poll_link(struct dsa_switch *ds)
  18113. +{
  18114. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18115. + int i;
  18116. +
  18117. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  18118. + struct net_device *dev;
  18119. + u32 status;
  18120. + int link;
  18121. + unsigned speed;
  18122. + int duplex;
  18123. +
  18124. + dev = ds->ports[i];
  18125. + if (dev == NULL)
  18126. + continue;
  18127. +
  18128. + link = 0;
  18129. + if (dev->flags & IFF_UP) {
  18130. + status = ar7240sw_reg_read(as,
  18131. + AR7240_REG_PORT_STATUS(i));
  18132. + link = !!(status & AR7240_PORT_STATUS_LINK_UP);
  18133. + }
  18134. +
  18135. + if (!link) {
  18136. + if (netif_carrier_ok(dev)) {
  18137. + pr_info("%s: link down\n", dev->name);
  18138. + netif_carrier_off(dev);
  18139. + }
  18140. + continue;
  18141. + }
  18142. +
  18143. + speed = (status & AR7240_PORT_STATUS_SPEED_M);
  18144. + duplex = (status & AR7240_PORT_STATUS_DUPLEX) ? 1 : 0;
  18145. + if (!netif_carrier_ok(dev)) {
  18146. + pr_info("%s: link up, %sMb/s, %s duplex",
  18147. + dev->name,
  18148. + ar7240sw_speed_str(speed),
  18149. + duplex ? "full" : "half");
  18150. + netif_carrier_on(dev);
  18151. + }
  18152. + }
  18153. +}
  18154. +
  18155. +static const struct ar7240sw_hw_stat ar7240_hw_stats[] = {
  18156. + { "rx_broadcast" , 4, AR7240_STATS_RXBROAD, },
  18157. + { "rx_pause" , 4, AR7240_STATS_RXPAUSE, },
  18158. + { "rx_multicast" , 4, AR7240_STATS_RXMULTI, },
  18159. + { "rx_fcs_error" , 4, AR7240_STATS_RXFCSERR, },
  18160. + { "rx_align_error" , 4, AR7240_STATS_RXALIGNERR, },
  18161. + { "rx_undersize" , 4, AR7240_STATS_RXRUNT, },
  18162. + { "rx_fragments" , 4, AR7240_STATS_RXFRAGMENT, },
  18163. + { "rx_64bytes" , 4, AR7240_STATS_RX64BYTE, },
  18164. + { "rx_65_127bytes" , 4, AR7240_STATS_RX128BYTE, },
  18165. + { "rx_128_255bytes" , 4, AR7240_STATS_RX256BYTE, },
  18166. + { "rx_256_511bytes" , 4, AR7240_STATS_RX512BYTE, },
  18167. + { "rx_512_1023bytes" , 4, AR7240_STATS_RX1024BYTE, },
  18168. + { "rx_1024_1518bytes" , 4, AR7240_STATS_RX1518BYTE, },
  18169. + { "rx_1519_max_bytes" , 4, AR7240_STATS_RXMAXBYTE, },
  18170. + { "rx_oversize" , 4, AR7240_STATS_RXTOOLONG, },
  18171. + { "rx_good_bytes" , 8, AR7240_STATS_RXGOODBYTE, },
  18172. + { "rx_bad_bytes" , 8, AR7240_STATS_RXBADBYTE, },
  18173. + { "rx_overflow" , 4, AR7240_STATS_RXOVERFLOW, },
  18174. + { "filtered" , 4, AR7240_STATS_FILTERED, },
  18175. + { "tx_broadcast" , 4, AR7240_STATS_TXBROAD, },
  18176. + { "tx_pause" , 4, AR7240_STATS_TXPAUSE, },
  18177. + { "tx_multicast" , 4, AR7240_STATS_TXMULTI, },
  18178. + { "tx_underrun" , 4, AR7240_STATS_TXUNDERRUN, },
  18179. + { "tx_64bytes" , 4, AR7240_STATS_TX64BYTE, },
  18180. + { "tx_65_127bytes" , 4, AR7240_STATS_TX128BYTE, },
  18181. + { "tx_128_255bytes" , 4, AR7240_STATS_TX256BYTE, },
  18182. + { "tx_256_511bytes" , 4, AR7240_STATS_TX512BYTE, },
  18183. + { "tx_512_1023bytes" , 4, AR7240_STATS_TX1024BYTE, },
  18184. + { "tx_1024_1518bytes" , 4, AR7240_STATS_TX1518BYTE, },
  18185. + { "tx_1519_max_bytes" , 4, AR7240_STATS_TXMAXBYTE, },
  18186. + { "tx_oversize" , 4, AR7240_STATS_TXOVERSIZE, },
  18187. + { "tx_bytes" , 8, AR7240_STATS_TXBYTE, },
  18188. + { "tx_collisions" , 4, AR7240_STATS_TXCOLLISION, },
  18189. + { "tx_abort_collisions" , 4, AR7240_STATS_TXABORTCOL, },
  18190. + { "tx_multi_collisions" , 4, AR7240_STATS_TXMULTICOL, },
  18191. + { "tx_single_collisions", 4, AR7240_STATS_TXSINGLECOL, },
  18192. + { "tx_excessive_deferred", 4, AR7240_STATS_TXEXCDEFER, },
  18193. + { "tx_deferred" , 4, AR7240_STATS_TXDEFER, },
  18194. + { "tx_late_collisions" , 4, AR7240_STATS_TXLATECOL, },
  18195. +};
  18196. +
  18197. +static void ar7240_dsa_get_strings(struct dsa_switch *ds, int port,
  18198. + uint8_t *data)
  18199. +{
  18200. + int i;
  18201. +
  18202. + for (i = 0; i < ARRAY_SIZE(ar7240_hw_stats); i++) {
  18203. + memcpy(data + i * ETH_GSTRING_LEN,
  18204. + ar7240_hw_stats[i].string, ETH_GSTRING_LEN);
  18205. + }
  18206. +}
  18207. +
  18208. +static void ar7240_dsa_get_ethtool_stats(struct dsa_switch *ds, int port,
  18209. + uint64_t *data)
  18210. +{
  18211. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18212. + int err;
  18213. + int i;
  18214. +
  18215. + mutex_lock(&as->stats_mutex);
  18216. +
  18217. + err = ar7240sw_capture_stats(as);
  18218. + if (err)
  18219. + goto unlock;
  18220. +
  18221. + for (i = 0; i < ARRAY_SIZE(ar7240_hw_stats); i++) {
  18222. + const struct ar7240sw_hw_stat *s = &ar7240_hw_stats[i];
  18223. + u32 reg = AR7240_REG_STATS_BASE(port);
  18224. + u32 low;
  18225. + u32 high;
  18226. +
  18227. + low = ar7240sw_reg_read(as, reg + s->reg);
  18228. + if (s->sizeof_stat == 8)
  18229. + high = ar7240sw_reg_read(as, reg + s->reg);
  18230. + else
  18231. + high = 0;
  18232. +
  18233. + data[i] = (((u64) high) << 32) | low;
  18234. + }
  18235. +
  18236. + unlock:
  18237. + mutex_unlock(&as->stats_mutex);
  18238. +}
  18239. +
  18240. +static int ar7240_dsa_get_sset_count(struct dsa_switch *ds)
  18241. +{
  18242. + return ARRAY_SIZE(ar7240_hw_stats);
  18243. +}
  18244. +
  18245. +static struct dsa_switch_driver ar7240_dsa_driver = {
  18246. + .tag_protocol = htons(ETH_P_QINQ),
  18247. + .priv_size = sizeof(struct ar7240sw),
  18248. + .probe = ar7240_dsa_probe,
  18249. + .setup = ar7240_dsa_setup,
  18250. + .set_addr = ar7240_dsa_set_addr,
  18251. + .phy_read = ar7240_dsa_phy_read,
  18252. + .phy_write = ar7240_dsa_phy_write,
  18253. + .poll_link = ar7240_dsa_poll_link,
  18254. + .get_strings = ar7240_dsa_get_strings,
  18255. + .get_ethtool_stats = ar7240_dsa_get_ethtool_stats,
  18256. + .get_sset_count = ar7240_dsa_get_sset_count,
  18257. +};
  18258. +
  18259. +int __init dsa_ar7240_init(void)
  18260. +{
  18261. + register_switch_driver(&ar7240_dsa_driver);
  18262. + return 0;
  18263. +}
  18264. +module_init(dsa_ar7240_init);
  18265. +
  18266. +void __exit dsa_ar7240_cleanup(void)
  18267. +{
  18268. + unregister_switch_driver(&ar7240_dsa_driver);
  18269. +}
  18270. +module_exit(dsa_ar7240_cleanup);
  18271. diff -Nur linux-2.6.33.3.orig/net/dsa/mv88e6063.c linux-2.6.33.3/net/dsa/mv88e6063.c
  18272. --- linux-2.6.33.3.orig/net/dsa/mv88e6063.c 1970-01-01 01:00:00.000000000 +0100
  18273. +++ linux-2.6.33.3/net/dsa/mv88e6063.c 2009-12-25 12:10:58.524031002 +0100
  18274. @@ -0,0 +1,294 @@
  18275. +/*
  18276. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6063 switch chips
  18277. + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  18278. + *
  18279. + * This driver was base on: net/dsa/mv88e6060.c
  18280. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6060 switch chips
  18281. + * Copyright (c) 2008-2009 Marvell Semiconductor
  18282. + *
  18283. + * This program is free software; you can redistribute it and/or modify
  18284. + * it under the terms of the GNU General Public License as published by
  18285. + * the Free Software Foundation; either version 2 of the License, or
  18286. + * (at your option) any later version.
  18287. + */
  18288. +
  18289. +#include <linux/list.h>
  18290. +#include <linux/netdevice.h>
  18291. +#include <linux/phy.h>
  18292. +#include "dsa_priv.h"
  18293. +
  18294. +#define REG_BASE 0x10
  18295. +#define REG_PHY(p) (REG_BASE + (p))
  18296. +#define REG_PORT(p) (REG_BASE + 8 + (p))
  18297. +#define REG_GLOBAL (REG_BASE + 0x0f)
  18298. +#define NUM_PORTS 7
  18299. +
  18300. +static int reg_read(struct dsa_switch *ds, int addr, int reg)
  18301. +{
  18302. + return mdiobus_read(ds->master_mii_bus, addr, reg);
  18303. +}
  18304. +
  18305. +#define REG_READ(addr, reg) \
  18306. + ({ \
  18307. + int __ret; \
  18308. + \
  18309. + __ret = reg_read(ds, addr, reg); \
  18310. + if (__ret < 0) \
  18311. + return __ret; \
  18312. + __ret; \
  18313. + })
  18314. +
  18315. +
  18316. +static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
  18317. +{
  18318. + return mdiobus_write(ds->master_mii_bus, addr, reg, val);
  18319. +}
  18320. +
  18321. +#define REG_WRITE(addr, reg, val) \
  18322. + ({ \
  18323. + int __ret; \
  18324. + \
  18325. + __ret = reg_write(ds, addr, reg, val); \
  18326. + if (__ret < 0) \
  18327. + return __ret; \
  18328. + })
  18329. +
  18330. +static char *mv88e6063_probe(struct mii_bus *bus, int sw_addr)
  18331. +{
  18332. + int ret;
  18333. +
  18334. + ret = mdiobus_read(bus, REG_PORT(0), 0x03);
  18335. + if (ret >= 0) {
  18336. + ret &= 0xfff0;
  18337. + if (ret == 0x1530)
  18338. + return "Marvell 88E6063";
  18339. + }
  18340. +
  18341. + return NULL;
  18342. +}
  18343. +
  18344. +static int mv88e6063_switch_reset(struct dsa_switch *ds)
  18345. +{
  18346. + int i;
  18347. + int ret;
  18348. +
  18349. + /*
  18350. + * Set all ports to the disabled state.
  18351. + */
  18352. + for (i = 0; i < NUM_PORTS; i++) {
  18353. + ret = REG_READ(REG_PORT(i), 0x04);
  18354. + REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  18355. + }
  18356. +
  18357. + /*
  18358. + * Wait for transmit queues to drain.
  18359. + */
  18360. + msleep(2);
  18361. +
  18362. + /*
  18363. + * Reset the switch.
  18364. + */
  18365. + REG_WRITE(REG_GLOBAL, 0x0a, 0xa130);
  18366. +
  18367. + /*
  18368. + * Wait up to one second for reset to complete.
  18369. + */
  18370. + for (i = 0; i < 1000; i++) {
  18371. + ret = REG_READ(REG_GLOBAL, 0x00);
  18372. + if ((ret & 0x8000) == 0x0000)
  18373. + break;
  18374. +
  18375. + msleep(1);
  18376. + }
  18377. + if (i == 1000)
  18378. + return -ETIMEDOUT;
  18379. +
  18380. + return 0;
  18381. +}
  18382. +
  18383. +static int mv88e6063_setup_global(struct dsa_switch *ds)
  18384. +{
  18385. + /*
  18386. + * Disable discarding of frames with excessive collisions,
  18387. + * set the maximum frame size to 1536 bytes, and mask all
  18388. + * interrupt sources.
  18389. + */
  18390. + REG_WRITE(REG_GLOBAL, 0x04, 0x0800);
  18391. +
  18392. + /*
  18393. + * Enable automatic address learning, set the address
  18394. + * database size to 1024 entries, and set the default aging
  18395. + * time to 5 minutes.
  18396. + */
  18397. + REG_WRITE(REG_GLOBAL, 0x0a, 0x2130);
  18398. +
  18399. + return 0;
  18400. +}
  18401. +
  18402. +static int mv88e6063_setup_port(struct dsa_switch *ds, int p)
  18403. +{
  18404. + int addr = REG_PORT(p);
  18405. +
  18406. + /*
  18407. + * Do not force flow control, disable Ingress and Egress
  18408. + * Header tagging, disable VLAN tunneling, and set the port
  18409. + * state to Forwarding. Additionally, if this is the CPU
  18410. + * port, enable Ingress and Egress Trailer tagging mode.
  18411. + */
  18412. + REG_WRITE(addr, 0x04, dsa_is_cpu_port(ds, p) ? 0x4103 : 0x0003);
  18413. +
  18414. + /*
  18415. + * Port based VLAN map: give each port its own address
  18416. + * database, allow the CPU port to talk to each of the 'real'
  18417. + * ports, and allow each of the 'real' ports to only talk to
  18418. + * the CPU port.
  18419. + */
  18420. + REG_WRITE(addr, 0x06,
  18421. + ((p & 0xf) << 12) |
  18422. + (dsa_is_cpu_port(ds, p) ?
  18423. + ds->phys_port_mask :
  18424. + (1 << ds->dst->cpu_port)));
  18425. +
  18426. + /*
  18427. + * Port Association Vector: when learning source addresses
  18428. + * of packets, add the address to the address database using
  18429. + * a port bitmap that has only the bit for this port set and
  18430. + * the other bits clear.
  18431. + */
  18432. + REG_WRITE(addr, 0x0b, 1 << p);
  18433. +
  18434. + return 0;
  18435. +}
  18436. +
  18437. +static int mv88e6063_setup(struct dsa_switch *ds)
  18438. +{
  18439. + int i;
  18440. + int ret;
  18441. +
  18442. + ret = mv88e6063_switch_reset(ds);
  18443. + if (ret < 0)
  18444. + return ret;
  18445. +
  18446. + /* @@@ initialise atu */
  18447. +
  18448. + ret = mv88e6063_setup_global(ds);
  18449. + if (ret < 0)
  18450. + return ret;
  18451. +
  18452. + for (i = 0; i < NUM_PORTS; i++) {
  18453. + ret = mv88e6063_setup_port(ds, i);
  18454. + if (ret < 0)
  18455. + return ret;
  18456. + }
  18457. +
  18458. + return 0;
  18459. +}
  18460. +
  18461. +static int mv88e6063_set_addr(struct dsa_switch *ds, u8 *addr)
  18462. +{
  18463. + REG_WRITE(REG_GLOBAL, 0x01, (addr[0] << 8) | addr[1]);
  18464. + REG_WRITE(REG_GLOBAL, 0x02, (addr[2] << 8) | addr[3]);
  18465. + REG_WRITE(REG_GLOBAL, 0x03, (addr[4] << 8) | addr[5]);
  18466. +
  18467. + return 0;
  18468. +}
  18469. +
  18470. +static int mv88e6063_port_to_phy_addr(int port)
  18471. +{
  18472. + if (port >= 0 && port <= NUM_PORTS)
  18473. + return REG_PHY(port);
  18474. + return -1;
  18475. +}
  18476. +
  18477. +static int mv88e6063_phy_read(struct dsa_switch *ds, int port, int regnum)
  18478. +{
  18479. + int addr;
  18480. +
  18481. + addr = mv88e6063_port_to_phy_addr(port);
  18482. + if (addr == -1)
  18483. + return 0xffff;
  18484. +
  18485. + return reg_read(ds, addr, regnum);
  18486. +}
  18487. +
  18488. +static int
  18489. +mv88e6063_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
  18490. +{
  18491. + int addr;
  18492. +
  18493. + addr = mv88e6063_port_to_phy_addr(port);
  18494. + if (addr == -1)
  18495. + return 0xffff;
  18496. +
  18497. + return reg_write(ds, addr, regnum, val);
  18498. +}
  18499. +
  18500. +static void mv88e6063_poll_link(struct dsa_switch *ds)
  18501. +{
  18502. + int i;
  18503. +
  18504. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  18505. + struct net_device *dev;
  18506. + int uninitialized_var(port_status);
  18507. + int link;
  18508. + int speed;
  18509. + int duplex;
  18510. + int fc;
  18511. +
  18512. + dev = ds->ports[i];
  18513. + if (dev == NULL)
  18514. + continue;
  18515. +
  18516. + link = 0;
  18517. + if (dev->flags & IFF_UP) {
  18518. + port_status = reg_read(ds, REG_PORT(i), 0x00);
  18519. + if (port_status < 0)
  18520. + continue;
  18521. +
  18522. + link = !!(port_status & 0x1000);
  18523. + }
  18524. +
  18525. + if (!link) {
  18526. + if (netif_carrier_ok(dev)) {
  18527. + printk(KERN_INFO "%s: link down\n", dev->name);
  18528. + netif_carrier_off(dev);
  18529. + }
  18530. + continue;
  18531. + }
  18532. +
  18533. + speed = (port_status & 0x0100) ? 100 : 10;
  18534. + duplex = (port_status & 0x0200) ? 1 : 0;
  18535. + fc = ((port_status & 0xc000) == 0xc000) ? 1 : 0;
  18536. +
  18537. + if (!netif_carrier_ok(dev)) {
  18538. + printk(KERN_INFO "%s: link up, %d Mb/s, %s duplex, "
  18539. + "flow control %sabled\n", dev->name,
  18540. + speed, duplex ? "full" : "half",
  18541. + fc ? "en" : "dis");
  18542. + netif_carrier_on(dev);
  18543. + }
  18544. + }
  18545. +}
  18546. +
  18547. +static struct dsa_switch_driver mv88e6063_switch_driver = {
  18548. + .tag_protocol = htons(ETH_P_TRAILER),
  18549. + .probe = mv88e6063_probe,
  18550. + .setup = mv88e6063_setup,
  18551. + .set_addr = mv88e6063_set_addr,
  18552. + .phy_read = mv88e6063_phy_read,
  18553. + .phy_write = mv88e6063_phy_write,
  18554. + .poll_link = mv88e6063_poll_link,
  18555. +};
  18556. +
  18557. +static int __init mv88e6063_init(void)
  18558. +{
  18559. + register_switch_driver(&mv88e6063_switch_driver);
  18560. + return 0;
  18561. +}
  18562. +module_init(mv88e6063_init);
  18563. +
  18564. +static void __exit mv88e6063_cleanup(void)
  18565. +{
  18566. + unregister_switch_driver(&mv88e6063_switch_driver);
  18567. +}
  18568. +module_exit(mv88e6063_cleanup);
  18569. diff -Nur linux-2.6.33.3.orig/net/dsa/tag_qinq.c linux-2.6.33.3/net/dsa/tag_qinq.c
  18570. --- linux-2.6.33.3.orig/net/dsa/tag_qinq.c 1970-01-01 01:00:00.000000000 +0100
  18571. +++ linux-2.6.33.3/net/dsa/tag_qinq.c 2010-03-06 12:19:54.255959609 +0100
  18572. @@ -0,0 +1,127 @@
  18573. +/*
  18574. + * net/dsa/tag_qinq.c - QinQ tag format handling
  18575. + * Copyright (c) 2010 Gabor Juhos <juhosg@openwrt.org>
  18576. + *
  18577. + * This file was based on:
  18578. + * net/dsa/tag_edsa.c - Ethertype DSA tagging
  18579. + * Copyright (c) 2008-2009 Marvell Semiconductor
  18580. + *
  18581. + * This program is free software; you can redistribute it and/or modify
  18582. + * it under the terms of the GNU General Public License as published by
  18583. + * the Free Software Foundation; either version 2 of the License, or
  18584. + * (at your option) any later version.
  18585. + */
  18586. +
  18587. +#include <linux/etherdevice.h>
  18588. +#include <linux/list.h>
  18589. +#include <linux/netdevice.h>
  18590. +#include <linux/if_vlan.h>
  18591. +
  18592. +#include "dsa_priv.h"
  18593. +
  18594. +netdev_tx_t qinq_xmit(struct sk_buff *skb, struct net_device *dev)
  18595. +{
  18596. + struct dsa_slave_priv *p = netdev_priv(dev);
  18597. + struct vlan_ethhdr *veth;
  18598. + unsigned int len;
  18599. + int ret;
  18600. +
  18601. + if (skb_cow_head(skb, VLAN_HLEN) < 0)
  18602. + goto out_free_skb;
  18603. +
  18604. + veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
  18605. +
  18606. + /* Move the mac addresses to the beginning of the new header. */
  18607. + memmove(skb->data, skb->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);
  18608. + skb->mac_header -= VLAN_HLEN;
  18609. +
  18610. + /* setup VLAN header fields */
  18611. + veth->h_vlan_proto = htons(ETH_P_QINQ);
  18612. + veth->h_vlan_TCI = htons(p->port);
  18613. +
  18614. + len = skb->len;
  18615. + skb->protocol = htons(ETH_P_QINQ);
  18616. + skb->dev = p->parent->dst->master_netdev;
  18617. +
  18618. + ret = dev_queue_xmit(skb);
  18619. + if (unlikely(ret != NET_XMIT_SUCCESS))
  18620. + goto out_dropped;
  18621. +
  18622. + dev->stats.tx_packets++;
  18623. + dev->stats.tx_bytes += len;
  18624. +
  18625. + return NETDEV_TX_OK;
  18626. +
  18627. + out_free_skb:
  18628. + kfree_skb(skb);
  18629. + out_dropped:
  18630. + dev->stats.tx_dropped++;
  18631. + return NETDEV_TX_OK;
  18632. +}
  18633. +
  18634. +static int qinq_rcv(struct sk_buff *skb, struct net_device *dev,
  18635. + struct packet_type *pt, struct net_device *orig_dev)
  18636. +{
  18637. + struct dsa_switch_tree *dst;
  18638. + struct dsa_switch *ds;
  18639. + struct vlan_hdr *vhdr;
  18640. + int source_port;
  18641. +
  18642. + dst = dev->dsa_ptr;
  18643. + if (unlikely(dst == NULL))
  18644. + goto out_drop;
  18645. + ds = dst->ds[0];
  18646. +
  18647. + skb = skb_unshare(skb, GFP_ATOMIC);
  18648. + if (skb == NULL)
  18649. + goto out;
  18650. +
  18651. + if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
  18652. + goto out_drop;
  18653. +
  18654. + vhdr = (struct vlan_hdr *)skb->data;
  18655. + source_port = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  18656. + if (source_port >= DSA_MAX_PORTS || ds->ports[source_port] == NULL)
  18657. + goto out_drop;
  18658. +
  18659. + /* Remove the outermost VLAN tag and update checksum. */
  18660. + skb_pull_rcsum(skb, VLAN_HLEN);
  18661. + memmove(skb->data - ETH_HLEN,
  18662. + skb->data - ETH_HLEN - VLAN_HLEN,
  18663. + 2 * ETH_ALEN);
  18664. +
  18665. + skb->dev = ds->ports[source_port];
  18666. + skb_push(skb, ETH_HLEN);
  18667. + skb->pkt_type = PACKET_HOST;
  18668. + skb->protocol = eth_type_trans(skb, skb->dev);
  18669. +
  18670. + skb->dev->stats.rx_packets++;
  18671. + skb->dev->stats.rx_bytes += skb->len;
  18672. +
  18673. + netif_receive_skb(skb);
  18674. +
  18675. + return 0;
  18676. +
  18677. + out_drop:
  18678. + kfree_skb(skb);
  18679. + out:
  18680. + return 0;
  18681. +}
  18682. +
  18683. +static struct packet_type qinq_packet_type __read_mostly = {
  18684. + .type = cpu_to_be16(ETH_P_QINQ),
  18685. + .func = qinq_rcv,
  18686. +};
  18687. +
  18688. +static int __init qinq_init_module(void)
  18689. +{
  18690. + dev_add_pack(&qinq_packet_type);
  18691. + return 0;
  18692. +}
  18693. +module_init(qinq_init_module);
  18694. +
  18695. +static void __exit qinq_cleanup_module(void)
  18696. +{
  18697. + dev_remove_pack(&qinq_packet_type);
  18698. +}
  18699. +module_exit(qinq_cleanup_module);