ar71xx.patch 489 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666
  1. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/ar71xx.c linux-2.6.34/arch/mips/ar71xx/ar71xx.c
  2. --- linux-2.6.34.orig/arch/mips/ar71xx/ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.34/arch/mips/ar71xx/ar71xx.c 2010-05-25 18:46:03.110979012 +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.34.orig/arch/mips/ar71xx/dev-ap91-eth.c linux-2.6.34/arch/mips/ar71xx/dev-ap91-eth.c
  183. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap91-eth.c 1970-01-01 01:00:00.000000000 +0100
  184. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap91-eth.c 2010-05-25 18:46:03.723464300 +0200
  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.34.orig/arch/mips/ar71xx/dev-ap91-eth.h linux-2.6.34/arch/mips/ar71xx/dev-ap91-eth.h
  257. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap91-eth.h 1970-01-01 01:00:00.000000000 +0100
  258. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap91-eth.h 2010-05-25 18:46:03.783696759 +0200
  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.34.orig/arch/mips/ar71xx/dev-ap91-pci.c linux-2.6.34/arch/mips/ar71xx/dev-ap91-pci.c
  284. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap91-pci.c 1970-01-01 01:00:00.000000000 +0100
  285. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap91-pci.c 2010-05-25 18:46:03.822223125 +0200
  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.34.orig/arch/mips/ar71xx/dev-ap91-pci.h linux-2.6.34/arch/mips/ar71xx/dev-ap91-pci.h
  402. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap91-pci.h 1970-01-01 01:00:00.000000000 +0100
  403. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap91-pci.h 2010-05-25 18:46:03.863464064 +0200
  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.34.orig/arch/mips/ar71xx/dev-ap94-pci.c linux-2.6.34/arch/mips/ar71xx/dev-ap94-pci.c
  427. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap94-pci.c 1970-01-01 01:00:00.000000000 +0100
  428. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap94-pci.c 2010-05-25 18:46:03.902223120 +0200
  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.34.orig/arch/mips/ar71xx/dev-ap94-pci.h linux-2.6.34/arch/mips/ar71xx/dev-ap94-pci.h
  590. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ap94-pci.h 1970-01-01 01:00:00.000000000 +0100
  591. +++ linux-2.6.34/arch/mips/ar71xx/dev-ap94-pci.h 2010-05-25 18:46:03.941521735 +0200
  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.34.orig/arch/mips/ar71xx/dev-ar913x-wmac.c linux-2.6.34/arch/mips/ar71xx/dev-ar913x-wmac.c
  622. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ar913x-wmac.c 1970-01-01 01:00:00.000000000 +0100
  623. +++ linux-2.6.34/arch/mips/ar71xx/dev-ar913x-wmac.c 2010-05-25 18:46:03.983064993 +0200
  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.34.orig/arch/mips/ar71xx/dev-ar913x-wmac.h linux-2.6.34/arch/mips/ar71xx/dev-ar913x-wmac.h
  694. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-ar913x-wmac.h 1970-01-01 01:00:00.000000000 +0100
  695. +++ linux-2.6.34/arch/mips/ar71xx/dev-ar913x-wmac.h 2010-05-25 18:46:04.023464010 +0200
  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.34.orig/arch/mips/ar71xx/dev-dsa.c linux-2.6.34/arch/mips/ar71xx/dev-dsa.c
  717. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-dsa.c 1970-01-01 01:00:00.000000000 +0100
  718. +++ linux-2.6.34/arch/mips/ar71xx/dev-dsa.c 2010-05-25 18:46:04.063473081 +0200
  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.34.orig/arch/mips/ar71xx/dev-dsa.h linux-2.6.34/arch/mips/ar71xx/dev-dsa.h
  771. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-dsa.h 1970-01-01 01:00:00.000000000 +0100
  772. +++ linux-2.6.34/arch/mips/ar71xx/dev-dsa.h 2010-05-25 18:46:04.100970143 +0200
  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.34.orig/arch/mips/ar71xx/dev-gpio-buttons.c linux-2.6.34/arch/mips/ar71xx/dev-gpio-buttons.c
  795. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-gpio-buttons.c 1970-01-01 01:00:00.000000000 +0100
  796. +++ linux-2.6.34/arch/mips/ar71xx/dev-gpio-buttons.c 2010-05-25 18:46:04.200967942 +0200
  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.34.orig/arch/mips/ar71xx/dev-gpio-buttons.h linux-2.6.34/arch/mips/ar71xx/dev-gpio-buttons.h
  857. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-gpio-buttons.h 1970-01-01 01:00:00.000000000 +0100
  858. +++ linux-2.6.34/arch/mips/ar71xx/dev-gpio-buttons.h 2010-05-25 18:46:04.242223118 +0200
  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.34.orig/arch/mips/ar71xx/devices.c linux-2.6.34/arch/mips/ar71xx/devices.c
  886. --- linux-2.6.34.orig/arch/mips/ar71xx/devices.c 1970-01-01 01:00:00.000000000 +0100
  887. +++ linux-2.6.34/arch/mips/ar71xx/devices.c 2010-05-25 18:46:04.280978624 +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.34.orig/arch/mips/ar71xx/devices.h linux-2.6.34/arch/mips/ar71xx/devices.h
  1465. --- linux-2.6.34.orig/arch/mips/ar71xx/devices.h 1970-01-01 01:00:00.000000000 +0100
  1466. +++ linux-2.6.34/arch/mips/ar71xx/devices.h 2010-05-25 18:46:04.736028570 +0200
  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.34.orig/arch/mips/ar71xx/dev-leds-gpio.c linux-2.6.34/arch/mips/ar71xx/dev-leds-gpio.c
  1517. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-leds-gpio.c 1970-01-01 01:00:00.000000000 +0100
  1518. +++ linux-2.6.34/arch/mips/ar71xx/dev-leds-gpio.c 2010-05-25 19:12:50.194723129 +0200
  1519. @@ -0,0 +1,57 @@
  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. +#include <linux/slab.h>
  1536. +
  1537. +#include "dev-leds-gpio.h"
  1538. +
  1539. +void __init ar71xx_add_device_leds_gpio(int id, unsigned num_leds,
  1540. + struct gpio_led *leds)
  1541. +{
  1542. + struct platform_device *pdev;
  1543. + struct gpio_led_platform_data pdata;
  1544. + struct gpio_led *p;
  1545. + int err;
  1546. +
  1547. + p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
  1548. + if (!p)
  1549. + return;
  1550. +
  1551. + memcpy(p, leds, num_leds * sizeof(*p));
  1552. +
  1553. + pdev = platform_device_alloc("leds-gpio", id);
  1554. + if (!pdev)
  1555. + goto err_free_leds;
  1556. +
  1557. + memset(&pdata, 0, sizeof(pdata));
  1558. + pdata.num_leds = num_leds;
  1559. + pdata.leds = p;
  1560. +
  1561. + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  1562. + if (err)
  1563. + goto err_put_pdev;
  1564. +
  1565. + err = platform_device_add(pdev);
  1566. + if (err)
  1567. + goto err_put_pdev;
  1568. +
  1569. + return;
  1570. +
  1571. +err_put_pdev:
  1572. + platform_device_put(pdev);
  1573. +
  1574. +err_free_leds:
  1575. + kfree(p);
  1576. +}
  1577. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-leds-gpio.h linux-2.6.34/arch/mips/ar71xx/dev-leds-gpio.h
  1578. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-leds-gpio.h 1970-01-01 01:00:00.000000000 +0100
  1579. +++ linux-2.6.34/arch/mips/ar71xx/dev-leds-gpio.h 2010-05-25 18:46:04.812922530 +0200
  1580. @@ -0,0 +1,21 @@
  1581. +/*
  1582. + * Atheros AR71xx GPIO LED device support
  1583. + *
  1584. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1585. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1586. + *
  1587. + * This program is free software; you can redistribute it and/or modify it
  1588. + * under the terms of the GNU General Public License version 2 as published
  1589. + * by the Free Software Foundation.
  1590. + */
  1591. +
  1592. +#ifndef _AR71XX_DEV_LEDS_GPIO_H
  1593. +#define _AR71XX_DEV_LEDS_GPIO_H
  1594. +
  1595. +#include <linux/leds.h>
  1596. +
  1597. +void ar71xx_add_device_leds_gpio(int id,
  1598. + unsigned num_leds,
  1599. + struct gpio_led *leds) __init;
  1600. +
  1601. +#endif /* _AR71XX_DEV_LEDS_GPIO_H */
  1602. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-m25p80.c linux-2.6.34/arch/mips/ar71xx/dev-m25p80.c
  1603. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-m25p80.c 1970-01-01 01:00:00.000000000 +0100
  1604. +++ linux-2.6.34/arch/mips/ar71xx/dev-m25p80.c 2010-05-25 18:46:04.852223056 +0200
  1605. @@ -0,0 +1,30 @@
  1606. +/*
  1607. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1608. + *
  1609. + * This program is free software; you can redistribute it and/or modify it
  1610. + * under the terms of the GNU General Public License version 2 as published
  1611. + * by the Free Software Foundation.
  1612. + */
  1613. +
  1614. +#include <linux/init.h>
  1615. +#include <linux/spi/spi.h>
  1616. +#include <linux/spi/flash.h>
  1617. +
  1618. +#include "devices.h"
  1619. +#include "dev-m25p80.h"
  1620. +
  1621. +static struct spi_board_info ar71xx_spi_info[] = {
  1622. + {
  1623. + .bus_num = 0,
  1624. + .chip_select = 0,
  1625. + .max_speed_hz = 25000000,
  1626. + .modalias = "m25p80",
  1627. + }
  1628. +};
  1629. +
  1630. +void __init ar71xx_add_device_m25p80(struct flash_platform_data *pdata)
  1631. +{
  1632. + ar71xx_spi_info[0].platform_data = pdata;
  1633. + ar71xx_add_device_spi(NULL, ar71xx_spi_info,
  1634. + ARRAY_SIZE(ar71xx_spi_info));
  1635. +}
  1636. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-m25p80.h linux-2.6.34/arch/mips/ar71xx/dev-m25p80.h
  1637. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-m25p80.h 1970-01-01 01:00:00.000000000 +0100
  1638. +++ linux-2.6.34/arch/mips/ar71xx/dev-m25p80.h 2010-05-25 18:46:04.892223453 +0200
  1639. @@ -0,0 +1,16 @@
  1640. +/*
  1641. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  1642. + *
  1643. + * This program is free software; you can redistribute it and/or modify it
  1644. + * under the terms of the GNU General Public License version 2 as published
  1645. + * by the Free Software Foundation.
  1646. + */
  1647. +
  1648. +#ifndef _AR71XX_DEV_M25P80_H
  1649. +#define _AR71XX_DEV_M25P80_H
  1650. +
  1651. +#include <linux/spi/flash.h>
  1652. +
  1653. +void ar71xx_add_device_m25p80(struct flash_platform_data *pdata) __init;
  1654. +
  1655. +#endif /* _AR71XX_DEV_M25P80_H */
  1656. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-pb42-pci.c linux-2.6.34/arch/mips/ar71xx/dev-pb42-pci.c
  1657. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-pb42-pci.c 1970-01-01 01:00:00.000000000 +0100
  1658. +++ linux-2.6.34/arch/mips/ar71xx/dev-pb42-pci.c 2010-05-25 18:46:04.932223237 +0200
  1659. @@ -0,0 +1,40 @@
  1660. +/*
  1661. + * Atheros PB42 reference board PCI initialization
  1662. + *
  1663. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1664. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1665. + *
  1666. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1667. + *
  1668. + * This program is free software; you can redistribute it and/or modify it
  1669. + * under the terms of the GNU General Public License version 2 as published
  1670. + * by the Free Software Foundation.
  1671. + */
  1672. +
  1673. +#include <linux/pci.h>
  1674. +
  1675. +#include <asm/mach-ar71xx/ar71xx.h>
  1676. +#include <asm/mach-ar71xx/pci.h>
  1677. +
  1678. +#include "dev-pb42-pci.h"
  1679. +
  1680. +static struct ar71xx_pci_irq pb42_pci_irqs[] __initdata = {
  1681. + {
  1682. + .slot = 0,
  1683. + .pin = 1,
  1684. + .irq = AR71XX_PCI_IRQ_DEV0,
  1685. + }, {
  1686. + .slot = 1,
  1687. + .pin = 1,
  1688. + .irq = AR71XX_PCI_IRQ_DEV1,
  1689. + }, {
  1690. + .slot = 2,
  1691. + .pin = 1,
  1692. + .irq = AR71XX_PCI_IRQ_DEV2,
  1693. + }
  1694. +};
  1695. +
  1696. +void __init pb42_pci_init(void)
  1697. +{
  1698. + ar71xx_pci_init(ARRAY_SIZE(pb42_pci_irqs), pb42_pci_irqs);
  1699. +}
  1700. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-pb42-pci.h linux-2.6.34/arch/mips/ar71xx/dev-pb42-pci.h
  1701. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-pb42-pci.h 1970-01-01 01:00:00.000000000 +0100
  1702. +++ linux-2.6.34/arch/mips/ar71xx/dev-pb42-pci.h 2010-05-25 18:46:04.972223148 +0200
  1703. @@ -0,0 +1,21 @@
  1704. +/*
  1705. + * Atheros PB42 reference board PCI initialization
  1706. + *
  1707. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1708. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1709. + *
  1710. + * This program is free software; you can redistribute it and/or modify it
  1711. + * under the terms of the GNU General Public License version 2 as published
  1712. + * by the Free Software Foundation.
  1713. + */
  1714. +
  1715. +#ifndef _AR71XX_DEV_PB42_PCI_H
  1716. +#define _AR71XX_DEV_PB42_PCI_H
  1717. +
  1718. +#if defined(CONFIG_AR71XX_DEV_PB42_PCI)
  1719. +void pb42_pci_init(void) __init;
  1720. +#else
  1721. +static inline void pb42_pci_init(void) { }
  1722. +#endif
  1723. +
  1724. +#endif /* _AR71XX_DEV_PB42_PCI_H */
  1725. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-pb9x-pci.c linux-2.6.34/arch/mips/ar71xx/dev-pb9x-pci.c
  1726. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-pb9x-pci.c 1970-01-01 01:00:00.000000000 +0100
  1727. +++ linux-2.6.34/arch/mips/ar71xx/dev-pb9x-pci.c 2010-05-25 18:46:05.003473097 +0200
  1728. @@ -0,0 +1,33 @@
  1729. +/*
  1730. + * Atheros PB9x reference board PCI initialization
  1731. + *
  1732. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1733. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1734. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1735. + *
  1736. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1737. + *
  1738. + * This program is free software; you can redistribute it and/or modify it
  1739. + * under the terms of the GNU General Public License version 2 as published
  1740. + * by the Free Software Foundation.
  1741. + */
  1742. +
  1743. +#include <linux/pci.h>
  1744. +
  1745. +#include <asm/mach-ar71xx/ar71xx.h>
  1746. +#include <asm/mach-ar71xx/pci.h>
  1747. +
  1748. +#include "dev-pb9x-pci.h"
  1749. +
  1750. +static struct ar71xx_pci_irq pb9x_pci_irqs[] __initdata = {
  1751. + {
  1752. + .slot = 0,
  1753. + .pin = 1,
  1754. + .irq = AR71XX_PCI_IRQ_DEV0,
  1755. + }
  1756. +};
  1757. +
  1758. +void __init pb9x_pci_init(void)
  1759. +{
  1760. + ar71xx_pci_init(ARRAY_SIZE(pb9x_pci_irqs), pb9x_pci_irqs);
  1761. +}
  1762. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-pb9x-pci.h linux-2.6.34/arch/mips/ar71xx/dev-pb9x-pci.h
  1763. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-pb9x-pci.h 1970-01-01 01:00:00.000000000 +0100
  1764. +++ linux-2.6.34/arch/mips/ar71xx/dev-pb9x-pci.h 2010-05-25 18:46:05.042263698 +0200
  1765. @@ -0,0 +1,22 @@
  1766. +/*
  1767. + * Atheros PB9x reference board PCI initialization
  1768. + *
  1769. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  1770. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1771. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1772. + *
  1773. + * This program is free software; you can redistribute it and/or modify it
  1774. + * under the terms of the GNU General Public License version 2 as published
  1775. + * by the Free Software Foundation.
  1776. + */
  1777. +
  1778. +#ifndef _AR71XX_DEV_PB9X_PCI_H
  1779. +#define _AR71XX_DEV_PB9X_PCI_H
  1780. +
  1781. +#if defined(CONFIG_AR71XX_DEV_PB9X_PCI)
  1782. +void pb9x_pci_init(void) __init;
  1783. +#else
  1784. +static inline void pb9x_pci_init(void) { }
  1785. +#endif
  1786. +
  1787. +#endif /* _AR71XX_DEV_PB9X_PCI_H */
  1788. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-usb.c linux-2.6.34/arch/mips/ar71xx/dev-usb.c
  1789. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-usb.c 1970-01-01 01:00:00.000000000 +0100
  1790. +++ linux-2.6.34/arch/mips/ar71xx/dev-usb.c 2010-05-25 18:46:05.082223074 +0200
  1791. @@ -0,0 +1,181 @@
  1792. +/*
  1793. + * Atheros AR71xx USB host device support
  1794. + *
  1795. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1796. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1797. + *
  1798. + * Parts of this file are based on Atheros' 2.6.15 BSP
  1799. + *
  1800. + * This program is free software; you can redistribute it and/or modify it
  1801. + * under the terms of the GNU General Public License version 2 as published
  1802. + * by the Free Software Foundation.
  1803. + */
  1804. +
  1805. +#include <linux/kernel.h>
  1806. +#include <linux/init.h>
  1807. +#include <linux/delay.h>
  1808. +#include <linux/dma-mapping.h>
  1809. +#include <linux/platform_device.h>
  1810. +
  1811. +#include <asm/mach-ar71xx/ar71xx.h>
  1812. +#include <asm/mach-ar71xx/platform.h>
  1813. +
  1814. +#include "dev-usb.h"
  1815. +
  1816. +/*
  1817. + * OHCI (USB full speed host controller)
  1818. + */
  1819. +static struct resource ar71xx_ohci_resources[] = {
  1820. + [0] = {
  1821. + .start = AR71XX_OHCI_BASE,
  1822. + .end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1,
  1823. + .flags = IORESOURCE_MEM,
  1824. + },
  1825. + [1] = {
  1826. + .start = AR71XX_MISC_IRQ_OHCI,
  1827. + .end = AR71XX_MISC_IRQ_OHCI,
  1828. + .flags = IORESOURCE_IRQ,
  1829. + },
  1830. +};
  1831. +
  1832. +static struct resource ar7240_ohci_resources[] = {
  1833. + [0] = {
  1834. + .start = AR7240_OHCI_BASE,
  1835. + .end = AR7240_OHCI_BASE + AR7240_OHCI_SIZE - 1,
  1836. + .flags = IORESOURCE_MEM,
  1837. + },
  1838. + [1] = {
  1839. + .start = AR71XX_CPU_IRQ_USB,
  1840. + .end = AR71XX_CPU_IRQ_USB,
  1841. + .flags = IORESOURCE_IRQ,
  1842. + },
  1843. +};
  1844. +
  1845. +static u64 ar71xx_ohci_dmamask = DMA_BIT_MASK(32);
  1846. +static struct platform_device ar71xx_ohci_device = {
  1847. + .name = "ar71xx-ohci",
  1848. + .id = -1,
  1849. + .resource = ar71xx_ohci_resources,
  1850. + .num_resources = ARRAY_SIZE(ar71xx_ohci_resources),
  1851. + .dev = {
  1852. + .dma_mask = &ar71xx_ohci_dmamask,
  1853. + .coherent_dma_mask = DMA_BIT_MASK(32),
  1854. + },
  1855. +};
  1856. +
  1857. +/*
  1858. + * EHCI (USB full speed host controller)
  1859. + */
  1860. +static struct resource ar71xx_ehci_resources[] = {
  1861. + [0] = {
  1862. + .start = AR71XX_EHCI_BASE,
  1863. + .end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1,
  1864. + .flags = IORESOURCE_MEM,
  1865. + },
  1866. + [1] = {
  1867. + .start = AR71XX_CPU_IRQ_USB,
  1868. + .end = AR71XX_CPU_IRQ_USB,
  1869. + .flags = IORESOURCE_IRQ,
  1870. + },
  1871. +};
  1872. +
  1873. +static u64 ar71xx_ehci_dmamask = DMA_BIT_MASK(32);
  1874. +static struct ar71xx_ehci_platform_data ar71xx_ehci_data;
  1875. +
  1876. +static struct platform_device ar71xx_ehci_device = {
  1877. + .name = "ar71xx-ehci",
  1878. + .id = -1,
  1879. + .resource = ar71xx_ehci_resources,
  1880. + .num_resources = ARRAY_SIZE(ar71xx_ehci_resources),
  1881. + .dev = {
  1882. + .dma_mask = &ar71xx_ehci_dmamask,
  1883. + .coherent_dma_mask = DMA_BIT_MASK(32),
  1884. + .platform_data = &ar71xx_ehci_data,
  1885. + },
  1886. +};
  1887. +
  1888. +#define AR71XX_USB_RESET_MASK \
  1889. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_PHY \
  1890. + | RESET_MODULE_USB_OHCI_DLL)
  1891. +
  1892. +#define AR7240_USB_RESET_MASK \
  1893. + (RESET_MODULE_USB_HOST | RESET_MODULE_USB_OHCI_DLL_7240)
  1894. +
  1895. +static void __init ar71xx_usb_setup(void)
  1896. +{
  1897. + ar71xx_device_stop(AR71XX_USB_RESET_MASK);
  1898. + mdelay(1000);
  1899. + ar71xx_device_start(AR71XX_USB_RESET_MASK);
  1900. +
  1901. + /* Turning on the Buff and Desc swap bits */
  1902. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_CONFIG, 0xf0000);
  1903. +
  1904. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  1905. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x20c00);
  1906. +
  1907. + mdelay(900);
  1908. +
  1909. + platform_device_register(&ar71xx_ohci_device);
  1910. + platform_device_register(&ar71xx_ehci_device);
  1911. +}
  1912. +
  1913. +static void __init ar7240_usb_setup(void)
  1914. +{
  1915. + ar71xx_device_stop(AR7240_USB_RESET_MASK);
  1916. + mdelay(1000);
  1917. + ar71xx_device_start(AR7240_USB_RESET_MASK);
  1918. +
  1919. + /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  1920. + ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x3);
  1921. +
  1922. + if (ar71xx_soc == AR71XX_SOC_AR7241 || ar71xx_soc == AR71XX_SOC_AR7242) {
  1923. + ar71xx_ehci_data.is_ar91xx = 1;
  1924. + ar71xx_ehci_device.resource = ar7240_ohci_resources;
  1925. + ar71xx_ehci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  1926. + platform_device_register(&ar71xx_ehci_device);
  1927. + } else {
  1928. + ar71xx_ohci_device.resource = ar7240_ohci_resources;
  1929. + ar71xx_ohci_device.num_resources = ARRAY_SIZE(ar7240_ohci_resources);
  1930. + platform_device_register(&ar71xx_ohci_device);
  1931. + }
  1932. +}
  1933. +
  1934. +static void __init ar91xx_usb_setup(void)
  1935. +{
  1936. + ar71xx_device_stop(RESET_MODULE_USBSUS_OVERRIDE);
  1937. + mdelay(10);
  1938. +
  1939. + ar71xx_device_start(RESET_MODULE_USB_HOST);
  1940. + mdelay(10);
  1941. +
  1942. + ar71xx_device_start(RESET_MODULE_USB_PHY);
  1943. + mdelay(10);
  1944. +
  1945. + ar71xx_ehci_data.is_ar91xx = 1;
  1946. + platform_device_register(&ar71xx_ehci_device);
  1947. +}
  1948. +
  1949. +void __init ar71xx_add_device_usb(void)
  1950. +{
  1951. + switch (ar71xx_soc) {
  1952. + case AR71XX_SOC_AR7240:
  1953. + case AR71XX_SOC_AR7241:
  1954. + case AR71XX_SOC_AR7242:
  1955. + ar7240_usb_setup();
  1956. + break;
  1957. +
  1958. + case AR71XX_SOC_AR7130:
  1959. + case AR71XX_SOC_AR7141:
  1960. + case AR71XX_SOC_AR7161:
  1961. + ar71xx_usb_setup();
  1962. + break;
  1963. +
  1964. + case AR71XX_SOC_AR9130:
  1965. + case AR71XX_SOC_AR9132:
  1966. + ar91xx_usb_setup();
  1967. + break;
  1968. +
  1969. + default:
  1970. + BUG();
  1971. + }
  1972. +}
  1973. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/dev-usb.h linux-2.6.34/arch/mips/ar71xx/dev-usb.h
  1974. --- linux-2.6.34.orig/arch/mips/ar71xx/dev-usb.h 1970-01-01 01:00:00.000000000 +0100
  1975. +++ linux-2.6.34/arch/mips/ar71xx/dev-usb.h 2010-05-25 18:46:05.123473207 +0200
  1976. @@ -0,0 +1,17 @@
  1977. +/*
  1978. + * Atheros AR71xx USB host device support
  1979. + *
  1980. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  1981. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  1982. + *
  1983. + * This program is free software; you can redistribute it and/or modify it
  1984. + * under the terms of the GNU General Public License version 2 as published
  1985. + * by the Free Software Foundation.
  1986. + */
  1987. +
  1988. +#ifndef _AR71XX_DEV_USB_H
  1989. +#define _AR71XX_DEV_USB_H
  1990. +
  1991. +void ar71xx_add_device_usb(void) __init;
  1992. +
  1993. +#endif /* _AR71XX_DEV_USB_H */
  1994. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/early_printk.c linux-2.6.34/arch/mips/ar71xx/early_printk.c
  1995. --- linux-2.6.34.orig/arch/mips/ar71xx/early_printk.c 1970-01-01 01:00:00.000000000 +0100
  1996. +++ linux-2.6.34/arch/mips/ar71xx/early_printk.c 2010-05-25 18:46:05.161773008 +0200
  1997. @@ -0,0 +1,30 @@
  1998. +/*
  1999. + * Atheros AR71xx SoC early printk support
  2000. + *
  2001. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2002. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2003. + *
  2004. + * This program is free software; you can redistribute it and/or modify it
  2005. + * under the terms of the GNU General Public License version 2 as published
  2006. + * by the Free Software Foundation.
  2007. + */
  2008. +
  2009. +#include <linux/io.h>
  2010. +#include <linux/serial_reg.h>
  2011. +#include <asm/addrspace.h>
  2012. +
  2013. +#include <asm/mach-ar71xx/ar71xx.h>
  2014. +
  2015. +#define UART_READ(r) \
  2016. + __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
  2017. +
  2018. +#define UART_WRITE(r, v) \
  2019. + __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
  2020. +
  2021. +void prom_putchar(unsigned char ch)
  2022. +{
  2023. + while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
  2024. + UART_WRITE(UART_TX, ch);
  2025. + while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
  2026. +}
  2027. +
  2028. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/gpio.c linux-2.6.34/arch/mips/ar71xx/gpio.c
  2029. --- linux-2.6.34.orig/arch/mips/ar71xx/gpio.c 1970-01-01 01:00:00.000000000 +0100
  2030. +++ linux-2.6.34/arch/mips/ar71xx/gpio.c 2010-05-25 18:46:05.241889944 +0200
  2031. @@ -0,0 +1,182 @@
  2032. +/*
  2033. + * Atheros AR71xx SoC GPIO API support
  2034. + *
  2035. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  2036. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2037. + *
  2038. + * This program is free software; you can redistribute it and/or modify it
  2039. + * under the terms of the GNU General Public License version 2 as published
  2040. + * by the Free Software Foundation.
  2041. + */
  2042. +
  2043. +#include <linux/kernel.h>
  2044. +#include <linux/init.h>
  2045. +#include <linux/module.h>
  2046. +#include <linux/types.h>
  2047. +#include <linux/spinlock.h>
  2048. +#include <linux/io.h>
  2049. +#include <linux/ioport.h>
  2050. +#include <linux/gpio.h>
  2051. +
  2052. +#include <asm/mach-ar71xx/ar71xx.h>
  2053. +
  2054. +static DEFINE_SPINLOCK(ar71xx_gpio_lock);
  2055. +
  2056. +unsigned long ar71xx_gpio_count;
  2057. +EXPORT_SYMBOL(ar71xx_gpio_count);
  2058. +
  2059. +void __ar71xx_gpio_set_value(unsigned gpio, int value)
  2060. +{
  2061. + void __iomem *base = ar71xx_gpio_base;
  2062. +
  2063. + if (value)
  2064. + __raw_writel(1 << gpio, base + GPIO_REG_SET);
  2065. + else
  2066. + __raw_writel(1 << gpio, base + GPIO_REG_CLEAR);
  2067. +}
  2068. +EXPORT_SYMBOL(__ar71xx_gpio_set_value);
  2069. +
  2070. +int __ar71xx_gpio_get_value(unsigned gpio)
  2071. +{
  2072. + return (__raw_readl(ar71xx_gpio_base + GPIO_REG_IN) >> gpio) & 1;
  2073. +}
  2074. +EXPORT_SYMBOL(__ar71xx_gpio_get_value);
  2075. +
  2076. +static int ar71xx_gpio_get_value(struct gpio_chip *chip, unsigned offset)
  2077. +{
  2078. + return __ar71xx_gpio_get_value(offset);
  2079. +}
  2080. +
  2081. +static void ar71xx_gpio_set_value(struct gpio_chip *chip,
  2082. + unsigned offset, int value)
  2083. +{
  2084. + __ar71xx_gpio_set_value(offset, value);
  2085. +}
  2086. +
  2087. +static int ar71xx_gpio_direction_input(struct gpio_chip *chip,
  2088. + unsigned offset)
  2089. +{
  2090. + void __iomem *base = ar71xx_gpio_base;
  2091. + unsigned long flags;
  2092. +
  2093. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2094. +
  2095. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(1 << offset),
  2096. + base + GPIO_REG_OE);
  2097. +
  2098. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2099. +
  2100. + return 0;
  2101. +}
  2102. +
  2103. +static int ar71xx_gpio_direction_output(struct gpio_chip *chip,
  2104. + unsigned offset, int value)
  2105. +{
  2106. + void __iomem *base = ar71xx_gpio_base;
  2107. + unsigned long flags;
  2108. +
  2109. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2110. +
  2111. + if (value)
  2112. + __raw_writel(1 << offset, base + GPIO_REG_SET);
  2113. + else
  2114. + __raw_writel(1 << offset, base + GPIO_REG_CLEAR);
  2115. +
  2116. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | (1 << offset),
  2117. + base + GPIO_REG_OE);
  2118. +
  2119. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2120. +
  2121. + return 0;
  2122. +}
  2123. +
  2124. +static struct gpio_chip ar71xx_gpio_chip = {
  2125. + .label = "ar71xx",
  2126. + .get = ar71xx_gpio_get_value,
  2127. + .set = ar71xx_gpio_set_value,
  2128. + .direction_input = ar71xx_gpio_direction_input,
  2129. + .direction_output = ar71xx_gpio_direction_output,
  2130. + .base = 0,
  2131. + .ngpio = AR71XX_GPIO_COUNT,
  2132. +};
  2133. +
  2134. +void ar71xx_gpio_function_enable(u32 mask)
  2135. +{
  2136. + void __iomem *base = ar71xx_gpio_base;
  2137. + unsigned long flags;
  2138. +
  2139. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2140. +
  2141. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) | mask,
  2142. + base + GPIO_REG_FUNC);
  2143. + /* flush write */
  2144. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2145. +
  2146. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2147. +}
  2148. +
  2149. +void ar71xx_gpio_function_disable(u32 mask)
  2150. +{
  2151. + void __iomem *base = ar71xx_gpio_base;
  2152. + unsigned long flags;
  2153. +
  2154. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2155. +
  2156. + __raw_writel(__raw_readl(base + GPIO_REG_FUNC) & ~mask,
  2157. + base + GPIO_REG_FUNC);
  2158. + /* flush write */
  2159. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2160. +
  2161. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2162. +}
  2163. +
  2164. +void ar71xx_gpio_function_setup(u32 set, u32 clear)
  2165. +{
  2166. + void __iomem *base = ar71xx_gpio_base;
  2167. + unsigned long flags;
  2168. +
  2169. + spin_lock_irqsave(&ar71xx_gpio_lock, flags);
  2170. +
  2171. + __raw_writel((__raw_readl(base + GPIO_REG_FUNC) & ~clear) | set,
  2172. + base + GPIO_REG_FUNC);
  2173. + /* flush write */
  2174. + (void) __raw_readl(base + GPIO_REG_FUNC);
  2175. +
  2176. + spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
  2177. +}
  2178. +EXPORT_SYMBOL(ar71xx_gpio_function_setup);
  2179. +
  2180. +void __init ar71xx_gpio_init(void)
  2181. +{
  2182. + int err;
  2183. +
  2184. + if (!request_mem_region(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE,
  2185. + "AR71xx GPIO controller"))
  2186. + panic("cannot allocate AR71xx GPIO registers page");
  2187. +
  2188. + switch (ar71xx_soc) {
  2189. + case AR71XX_SOC_AR7130:
  2190. + case AR71XX_SOC_AR7141:
  2191. + case AR71XX_SOC_AR7161:
  2192. + ar71xx_gpio_chip.ngpio = AR71XX_GPIO_COUNT;
  2193. + break;
  2194. +
  2195. + case AR71XX_SOC_AR7240:
  2196. + case AR71XX_SOC_AR7241:
  2197. + case AR71XX_SOC_AR7242:
  2198. + ar71xx_gpio_chip.ngpio = AR724X_GPIO_COUNT;
  2199. + break;
  2200. +
  2201. + case AR71XX_SOC_AR9130:
  2202. + case AR71XX_SOC_AR9132:
  2203. + ar71xx_gpio_chip.ngpio = AR91XX_GPIO_COUNT;
  2204. + break;
  2205. +
  2206. + default:
  2207. + BUG();
  2208. + }
  2209. +
  2210. + err = gpiochip_add(&ar71xx_gpio_chip);
  2211. + if (err)
  2212. + panic("cannot add AR71xx GPIO chip, error=%d", err);
  2213. +}
  2214. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/irq.c linux-2.6.34/arch/mips/ar71xx/irq.c
  2215. --- linux-2.6.34.orig/arch/mips/ar71xx/irq.c 1970-01-01 01:00:00.000000000 +0100
  2216. +++ linux-2.6.34/arch/mips/ar71xx/irq.c 2010-05-25 18:46:05.283464015 +0200
  2217. @@ -0,0 +1,295 @@
  2218. +/*
  2219. + * Atheros AR71xx SoC specific interrupt handling
  2220. + *
  2221. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  2222. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2223. + *
  2224. + * Parts of this file are based on Atheros' 2.6.15 BSP
  2225. + *
  2226. + * This program is free software; you can redistribute it and/or modify it
  2227. + * under the terms of the GNU General Public License version 2 as published
  2228. + * by the Free Software Foundation.
  2229. + */
  2230. +
  2231. +#include <linux/kernel.h>
  2232. +#include <linux/init.h>
  2233. +#include <linux/interrupt.h>
  2234. +#include <linux/irq.h>
  2235. +
  2236. +#include <asm/irq_cpu.h>
  2237. +#include <asm/mipsregs.h>
  2238. +
  2239. +#include <asm/mach-ar71xx/ar71xx.h>
  2240. +
  2241. +static int ip2_flush_reg;
  2242. +
  2243. +static void ar71xx_gpio_irq_dispatch(void)
  2244. +{
  2245. + void __iomem *base = ar71xx_gpio_base;
  2246. + u32 pending;
  2247. +
  2248. + pending = __raw_readl(base + GPIO_REG_INT_PENDING) &
  2249. + __raw_readl(base + GPIO_REG_INT_ENABLE);
  2250. +
  2251. + if (pending)
  2252. + do_IRQ(AR71XX_GPIO_IRQ_BASE + fls(pending) - 1);
  2253. + else
  2254. + spurious_interrupt();
  2255. +}
  2256. +
  2257. +static void ar71xx_gpio_irq_unmask(unsigned int irq)
  2258. +{
  2259. + void __iomem *base = ar71xx_gpio_base;
  2260. + u32 t;
  2261. +
  2262. + irq -= AR71XX_GPIO_IRQ_BASE;
  2263. +
  2264. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2265. + __raw_writel(t | (1 << irq), base + GPIO_REG_INT_ENABLE);
  2266. +
  2267. + /* flush write */
  2268. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2269. +}
  2270. +
  2271. +static void ar71xx_gpio_irq_mask(unsigned int irq)
  2272. +{
  2273. + void __iomem *base = ar71xx_gpio_base;
  2274. + u32 t;
  2275. +
  2276. + irq -= AR71XX_GPIO_IRQ_BASE;
  2277. +
  2278. + t = __raw_readl(base + GPIO_REG_INT_ENABLE);
  2279. + __raw_writel(t & ~(1 << irq), base + GPIO_REG_INT_ENABLE);
  2280. +
  2281. + /* flush write */
  2282. + (void) __raw_readl(base + GPIO_REG_INT_ENABLE);
  2283. +}
  2284. +
  2285. +#if 0
  2286. +static int ar71xx_gpio_irq_set_type(unsigned int irq, unsigned int flow_type)
  2287. +{
  2288. + /* TODO: implement */
  2289. + return 0;
  2290. +}
  2291. +#else
  2292. +#define ar71xx_gpio_irq_set_type NULL
  2293. +#endif
  2294. +
  2295. +static struct irq_chip ar71xx_gpio_irq_chip = {
  2296. + .name = "AR71XX GPIO",
  2297. + .unmask = ar71xx_gpio_irq_unmask,
  2298. + .mask = ar71xx_gpio_irq_mask,
  2299. + .mask_ack = ar71xx_gpio_irq_mask,
  2300. + .set_type = ar71xx_gpio_irq_set_type,
  2301. +};
  2302. +
  2303. +static struct irqaction ar71xx_gpio_irqaction = {
  2304. + .handler = no_action,
  2305. + .name = "cascade [AR71XX GPIO]",
  2306. +};
  2307. +
  2308. +#define GPIO_IRQ_INIT_STATUS (IRQ_LEVEL | IRQ_TYPE_LEVEL_HIGH | IRQ_DISABLED)
  2309. +#define GPIO_INT_ALL 0xffff
  2310. +
  2311. +static void __init ar71xx_gpio_irq_init(void)
  2312. +{
  2313. + void __iomem *base = ar71xx_gpio_base;
  2314. + int i;
  2315. +
  2316. + __raw_writel(0, base + GPIO_REG_INT_ENABLE);
  2317. + __raw_writel(0, base + GPIO_REG_INT_PENDING);
  2318. +
  2319. + /* setup type of all GPIO interrupts to level sensitive */
  2320. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_TYPE);
  2321. +
  2322. + /* setup polarity of all GPIO interrupts to active high */
  2323. + __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_POLARITY);
  2324. +
  2325. + for (i = AR71XX_GPIO_IRQ_BASE;
  2326. + i < AR71XX_GPIO_IRQ_BASE + AR71XX_GPIO_IRQ_COUNT; i++) {
  2327. + irq_desc[i].status = GPIO_IRQ_INIT_STATUS;
  2328. + set_irq_chip_and_handler(i, &ar71xx_gpio_irq_chip,
  2329. + handle_level_irq);
  2330. + }
  2331. +
  2332. + setup_irq(AR71XX_MISC_IRQ_GPIO, &ar71xx_gpio_irqaction);
  2333. +}
  2334. +
  2335. +static void ar71xx_misc_irq_dispatch(void)
  2336. +{
  2337. + u32 pending;
  2338. +
  2339. + pending = ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_STATUS)
  2340. + & ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE);
  2341. +
  2342. + if (pending & MISC_INT_UART)
  2343. + do_IRQ(AR71XX_MISC_IRQ_UART);
  2344. +
  2345. + else if (pending & MISC_INT_DMA)
  2346. + do_IRQ(AR71XX_MISC_IRQ_DMA);
  2347. +
  2348. + else if (pending & MISC_INT_PERFC)
  2349. + do_IRQ(AR71XX_MISC_IRQ_PERFC);
  2350. +
  2351. + else if (pending & MISC_INT_TIMER)
  2352. + do_IRQ(AR71XX_MISC_IRQ_TIMER);
  2353. +
  2354. + else if (pending & MISC_INT_OHCI)
  2355. + do_IRQ(AR71XX_MISC_IRQ_OHCI);
  2356. +
  2357. + else if (pending & MISC_INT_ERROR)
  2358. + do_IRQ(AR71XX_MISC_IRQ_ERROR);
  2359. +
  2360. + else if (pending & MISC_INT_GPIO)
  2361. + ar71xx_gpio_irq_dispatch();
  2362. +
  2363. + else if (pending & MISC_INT_WDOG)
  2364. + do_IRQ(AR71XX_MISC_IRQ_WDOG);
  2365. +
  2366. + else
  2367. + spurious_interrupt();
  2368. +}
  2369. +
  2370. +static void ar71xx_misc_irq_unmask(unsigned int irq)
  2371. +{
  2372. + void __iomem *base = ar71xx_reset_base;
  2373. + u32 t;
  2374. +
  2375. + irq -= AR71XX_MISC_IRQ_BASE;
  2376. +
  2377. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2378. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2379. +
  2380. + /* flush write */
  2381. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2382. +}
  2383. +
  2384. +static void ar71xx_misc_irq_mask(unsigned int irq)
  2385. +{
  2386. + void __iomem *base = ar71xx_reset_base;
  2387. + u32 t;
  2388. +
  2389. + irq -= AR71XX_MISC_IRQ_BASE;
  2390. +
  2391. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2392. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2393. +
  2394. + /* flush write */
  2395. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2396. +}
  2397. +
  2398. +static void ar724x_misc_irq_ack(unsigned int irq)
  2399. +{
  2400. + void __iomem *base = ar71xx_reset_base;
  2401. + u32 t;
  2402. +
  2403. + irq -= AR71XX_MISC_IRQ_BASE;
  2404. +
  2405. + t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2406. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2407. +
  2408. + /* flush write */
  2409. + (void) __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2410. +}
  2411. +
  2412. +static struct irq_chip ar71xx_misc_irq_chip = {
  2413. + .name = "AR71XX MISC",
  2414. + .unmask = ar71xx_misc_irq_unmask,
  2415. + .mask = ar71xx_misc_irq_mask,
  2416. +};
  2417. +
  2418. +static struct irqaction ar71xx_misc_irqaction = {
  2419. + .handler = no_action,
  2420. + .name = "cascade [AR71XX MISC]",
  2421. +};
  2422. +
  2423. +static void __init ar71xx_misc_irq_init(void)
  2424. +{
  2425. + void __iomem *base = ar71xx_reset_base;
  2426. + int i;
  2427. +
  2428. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  2429. + __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
  2430. +
  2431. + switch (ar71xx_soc) {
  2432. + case AR71XX_SOC_AR7240:
  2433. + case AR71XX_SOC_AR7241:
  2434. + case AR71XX_SOC_AR7242:
  2435. + ar71xx_misc_irq_chip.ack = ar724x_misc_irq_ack;
  2436. + break;
  2437. + default:
  2438. + ar71xx_misc_irq_chip.mask_ack = ar71xx_misc_irq_mask;
  2439. + break;
  2440. + }
  2441. +
  2442. + for (i = AR71XX_MISC_IRQ_BASE;
  2443. + i < AR71XX_MISC_IRQ_BASE + AR71XX_MISC_IRQ_COUNT; i++) {
  2444. + irq_desc[i].status = IRQ_DISABLED;
  2445. + set_irq_chip_and_handler(i, &ar71xx_misc_irq_chip,
  2446. + handle_level_irq);
  2447. + }
  2448. +
  2449. + setup_irq(AR71XX_CPU_IRQ_MISC, &ar71xx_misc_irqaction);
  2450. +}
  2451. +
  2452. +asmlinkage void plat_irq_dispatch(void)
  2453. +{
  2454. + unsigned long pending;
  2455. +
  2456. + pending = read_c0_status() & read_c0_cause() & ST0_IM;
  2457. +
  2458. + if (pending & STATUSF_IP7)
  2459. + do_IRQ(AR71XX_CPU_IRQ_TIMER);
  2460. +
  2461. + else if (pending & STATUSF_IP2) {
  2462. + /*
  2463. + * This IRQ is meant for a PCI device. Drivers for PCI devices
  2464. + * typically allocate coherent DMA memory for the descriptor
  2465. + * ring, however the DMA controller may still have some
  2466. + * unsynchronized data in the FIFO.
  2467. + * Issue a flush here to ensure that the driver sees the update.
  2468. + */
  2469. + ar71xx_ddr_flush(ip2_flush_reg);
  2470. + do_IRQ(AR71XX_CPU_IRQ_IP2);
  2471. + }
  2472. +
  2473. + else if (pending & STATUSF_IP4)
  2474. + do_IRQ(AR71XX_CPU_IRQ_GE0);
  2475. +
  2476. + else if (pending & STATUSF_IP5)
  2477. + do_IRQ(AR71XX_CPU_IRQ_GE1);
  2478. +
  2479. + else if (pending & STATUSF_IP3)
  2480. + do_IRQ(AR71XX_CPU_IRQ_USB);
  2481. +
  2482. + else if (pending & STATUSF_IP6)
  2483. + ar71xx_misc_irq_dispatch();
  2484. +
  2485. + else
  2486. + spurious_interrupt();
  2487. +}
  2488. +
  2489. +void __init arch_init_irq(void)
  2490. +{
  2491. + switch(ar71xx_soc) {
  2492. + case AR71XX_SOC_AR7240:
  2493. + case AR71XX_SOC_AR7241:
  2494. + case AR71XX_SOC_AR7242:
  2495. + ip2_flush_reg = AR724X_DDR_REG_FLUSH_PCIE;
  2496. + break;
  2497. + case AR71XX_SOC_AR9130:
  2498. + case AR71XX_SOC_AR9132:
  2499. + ip2_flush_reg = AR91XX_DDR_REG_FLUSH_WMAC;
  2500. + break;
  2501. + default:
  2502. + ip2_flush_reg = AR71XX_DDR_REG_FLUSH_PCI;
  2503. + break;
  2504. + }
  2505. + mips_cpu_irq_init();
  2506. +
  2507. + ar71xx_misc_irq_init();
  2508. +
  2509. + cp0_perfcount_irq = AR71XX_MISC_IRQ_PERFC;
  2510. +
  2511. + ar71xx_gpio_irq_init();
  2512. +}
  2513. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/Kconfig linux-2.6.34/arch/mips/ar71xx/Kconfig
  2514. --- linux-2.6.34.orig/arch/mips/ar71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  2515. +++ linux-2.6.34/arch/mips/ar71xx/Kconfig 2010-05-25 18:46:05.333473006 +0200
  2516. @@ -0,0 +1,264 @@
  2517. +if ATHEROS_AR71XX
  2518. +
  2519. +menu "Atheros AR71xx machine selection"
  2520. +
  2521. +config AR71XX_MACH_AP81
  2522. + bool "Atheros AP81 board support"
  2523. + select AR71XX_DEV_M25P80
  2524. + select AR71XX_DEV_AR913X_WMAC
  2525. + select AR71XX_DEV_GPIO_BUTTONS
  2526. + select AR71XX_DEV_LEDS_GPIO
  2527. + select AR71XX_DEV_USB
  2528. + default n
  2529. +
  2530. +config AR71XX_MACH_AP83
  2531. + bool "Atheros AP83 board support"
  2532. + select AR71XX_DEV_AR913X_WMAC
  2533. + select AR71XX_DEV_GPIO_BUTTONS
  2534. + select AR71XX_DEV_LEDS_GPIO
  2535. + select AR71XX_DEV_USB
  2536. + default n
  2537. +
  2538. +config AR71XX_MACH_DIR_600_A1
  2539. + bool "D-Link DIR-600 rev. A1 support"
  2540. + select AR71XX_DEV_AP91_ETH
  2541. + select AR71XX_DEV_AP91_PCI if PCI
  2542. + select AR71XX_DEV_M25P80
  2543. + select AR71XX_DEV_GPIO_BUTTONS
  2544. + select AR71XX_DEV_LEDS_GPIO
  2545. + select AR71XX_NVRAM
  2546. + default n
  2547. +
  2548. +config AR71XX_MACH_DIR_615_C1
  2549. + bool "D-Link DIR-615 rev. C1 support"
  2550. + select AR71XX_DEV_M25P80
  2551. + select AR71XX_DEV_AR913X_WMAC
  2552. + select AR71XX_DEV_GPIO_BUTTONS
  2553. + select AR71XX_DEV_LEDS_GPIO
  2554. + select AR71XX_NVRAM
  2555. + default n
  2556. +
  2557. +config AR71XX_MACH_DIR_825_B1
  2558. + bool "D-Link DIR-825 rev. B1 board support"
  2559. + select AR71XX_DEV_M25P80
  2560. + select AR71XX_DEV_AP94_PCI if PCI
  2561. + select AR71XX_DEV_GPIO_BUTTONS
  2562. + select AR71XX_DEV_LEDS_GPIO
  2563. + select AR71XX_DEV_USB
  2564. + default n
  2565. +
  2566. +config AR71XX_MACH_PB42
  2567. + bool "Atheros PB42 board support"
  2568. + select AR71XX_DEV_M25P80
  2569. + select AR71XX_DEV_GPIO_BUTTONS
  2570. + select AR71XX_DEV_PB42_PCI if PCI
  2571. + default n
  2572. +
  2573. +config AR71XX_MACH_PB44
  2574. + bool "Atheros PB44 board support"
  2575. + select AR71XX_DEV_GPIO_BUTTONS
  2576. + select AR71XX_DEV_PB42_PCI if PCI
  2577. + select AR71XX_DEV_LEDS_GPIO
  2578. + select AR71XX_DEV_USB
  2579. + default n
  2580. +
  2581. +config AR71XX_MACH_PB92
  2582. + bool "Atheros PB92 board support"
  2583. + select AR71XX_DEV_GPIO_BUTTONS
  2584. + select AR71XX_DEV_PB9X_PCI if PCI
  2585. + select AR71XX_DEV_LEDS_GPIO
  2586. + select AR71XX_DEV_USB
  2587. + default n
  2588. +
  2589. +config AR71XX_MACH_AW_NR580
  2590. + bool "AzureWave AW-NR580 board support"
  2591. + select AR71XX_DEV_M25P80
  2592. + select AR71XX_DEV_GPIO_BUTTONS
  2593. + select AR71XX_DEV_PB42_PCI if PCI
  2594. + select AR71XX_DEV_LEDS_GPIO
  2595. + default n
  2596. +
  2597. +config AR71XX_MACH_WZR_HP_G300NH
  2598. + bool "Buffalo WZR-HP-G300NH board support"
  2599. + select AR71XX_DEV_AR913X_WMAC
  2600. + select AR71XX_DEV_GPIO_BUTTONS
  2601. + select AR71XX_DEV_LEDS_GPIO
  2602. + select AR71XX_DEV_USB
  2603. + default y
  2604. +
  2605. +config AR71XX_MACH_WP543
  2606. + bool "Compex WP543/WPJ543 board support"
  2607. + select MYLOADER
  2608. + select AR71XX_DEV_M25P80
  2609. + select AR71XX_DEV_GPIO_BUTTONS
  2610. + select AR71XX_DEV_PB42_PCI if PCI
  2611. + select AR71XX_DEV_LEDS_GPIO
  2612. + select AR71XX_DEV_USB
  2613. + default n
  2614. +
  2615. +config AR71XX_MACH_WRT160NL
  2616. + bool "Linksys WRT160NL board support"
  2617. + select AR71XX_DEV_M25P80
  2618. + select AR71XX_DEV_AR913X_WMAC
  2619. + select AR71XX_DEV_GPIO_BUTTONS
  2620. + select AR71XX_DEV_LEDS_GPIO
  2621. + select AR71XX_DEV_USB
  2622. + select AR71XX_NVRAM
  2623. + default n
  2624. +
  2625. +config AR71XX_MACH_WRT400N
  2626. + bool "Linksys WRT400N board support"
  2627. + select AR71XX_DEV_AP94_PCI if PCI
  2628. + select AR71XX_DEV_M25P80
  2629. + select AR71XX_DEV_GPIO_BUTTONS
  2630. + select AR71XX_DEV_LEDS_GPIO
  2631. + default n
  2632. +
  2633. +config AR71XX_MACH_RB4XX
  2634. + bool "MikroTik RouterBOARD 4xx series support"
  2635. + select AR71XX_DEV_GPIO_BUTTONS
  2636. + select AR71XX_DEV_LEDS_GPIO
  2637. + select AR71XX_DEV_USB
  2638. + default n
  2639. +
  2640. +config AR71XX_MACH_RB750
  2641. + bool "MikroTik RouterBOARD 750 support"
  2642. + select AR71XX_DEV_AP91_ETH
  2643. + default n
  2644. +
  2645. +config AR71XX_MACH_WNDR3700
  2646. + bool "NETGEAR WNDR3700 board support"
  2647. + select AR71XX_DEV_M25P80
  2648. + select AR71XX_DEV_AP94_PCI if PCI
  2649. + select AR71XX_DEV_GPIO_BUTTONS
  2650. + select AR71XX_DEV_LEDS_GPIO
  2651. + select AR71XX_DEV_USB
  2652. + default n
  2653. +
  2654. +config AR71XX_MACH_WNR2000
  2655. + bool "NETGEAR WNR2000 board support"
  2656. + select AR71XX_DEV_M25P80
  2657. + select AR71XX_DEV_AR913X_WMAC
  2658. + select AR71XX_DEV_GPIO_BUTTONS
  2659. + select AR71XX_DEV_LEDS_GPIO
  2660. + default n
  2661. +
  2662. +config AR71XX_MACH_MZK_W04NU
  2663. + bool "Planex MZK-W04NU board support"
  2664. + select AR71XX_DEV_M25P80
  2665. + select AR71XX_DEV_AR913X_WMAC
  2666. + select AR71XX_DEV_GPIO_BUTTONS
  2667. + select AR71XX_DEV_LEDS_GPIO
  2668. + select AR71XX_DEV_USB
  2669. + default n
  2670. +
  2671. +config AR71XX_MACH_MZK_W300NH
  2672. + bool "Planex MZK-W300NH board support"
  2673. + select AR71XX_DEV_M25P80
  2674. + select AR71XX_DEV_AR913X_WMAC
  2675. + select AR71XX_DEV_GPIO_BUTTONS
  2676. + select AR71XX_DEV_LEDS_GPIO
  2677. + default n
  2678. +
  2679. +config AR71XX_MACH_NBG460N
  2680. + bool "Zyxel NBG460N/550N/550NH board support"
  2681. + select AR71XX_DEV_M25P80
  2682. + select AR71XX_DEV_AR913X_WMAC
  2683. + select AR71XX_DEV_GPIO_BUTTONS
  2684. + select AR71XX_DEV_LEDS_GPIO
  2685. + default n
  2686. +
  2687. +config AR71XX_MACH_TL_WR741ND
  2688. + bool "TP-LINK TL-WR741ND support"
  2689. + select AR71XX_DEV_M25P80
  2690. + select AR71XX_DEV_AP91_ETH
  2691. + select AR71XX_DEV_AP91_PCI if PCI
  2692. + select AR71XX_DEV_GPIO_BUTTONS
  2693. + select AR71XX_DEV_LEDS_GPIO
  2694. + default n
  2695. +
  2696. +config AR71XX_MACH_TL_WR841N_V1
  2697. + bool "TP-LINK TL-WR841N v1 support"
  2698. + select AR71XX_DEV_M25P80
  2699. + select AR71XX_DEV_PB42_PCI if PCI
  2700. + select AR71XX_DEV_DSA
  2701. + select AR71XX_DEV_GPIO_BUTTONS
  2702. + select AR71XX_DEV_LEDS_GPIO
  2703. + default n
  2704. +
  2705. +config AR71XX_MACH_TL_WR941ND
  2706. + bool "TP-LINK TL-WR941ND support"
  2707. + select AR71XX_DEV_M25P80
  2708. + select AR71XX_DEV_AR913X_WMAC
  2709. + select AR71XX_DEV_DSA
  2710. + select AR71XX_DEV_GPIO_BUTTONS
  2711. + select AR71XX_DEV_LEDS_GPIO
  2712. + default n
  2713. +
  2714. +config AR71XX_MACH_TL_WR1043ND
  2715. + bool "TP-LINK TL-WR1043ND support"
  2716. + select AR71XX_DEV_M25P80
  2717. + select AR71XX_DEV_AR913X_WMAC
  2718. + select AR71XX_DEV_GPIO_BUTTONS
  2719. + select AR71XX_DEV_LEDS_GPIO
  2720. + select AR71XX_DEV_USB
  2721. + default n
  2722. +
  2723. +config AR71XX_MACH_TEW_632BRP
  2724. + bool "TRENDnet TEW-632BRP support"
  2725. + select AR71XX_DEV_M25P80
  2726. + select AR71XX_DEV_AR913X_WMAC
  2727. + select AR71XX_DEV_GPIO_BUTTONS
  2728. + select AR71XX_DEV_LEDS_GPIO
  2729. + select AR71XX_NVRAM
  2730. + default n
  2731. +
  2732. +config AR71XX_MACH_UBNT
  2733. + bool "Ubiquiti AR71xx based boards support"
  2734. + select AR71XX_DEV_M25P80
  2735. + select AR71XX_DEV_AP91_PCI if PCI
  2736. + select AR71XX_DEV_GPIO_BUTTONS
  2737. + select AR71XX_DEV_LEDS_GPIO
  2738. + select AR71XX_DEV_PB42_PCI if PCI
  2739. + select AR71XX_DEV_USB
  2740. + default n
  2741. +
  2742. +endmenu
  2743. +
  2744. +config AR71XX_DEV_M25P80
  2745. + def_bool n
  2746. +
  2747. +config AR71XX_DEV_AP91_PCI
  2748. + def_bool n
  2749. +
  2750. +config AR71XX_DEV_AP91_ETH
  2751. + def_bool n
  2752. +
  2753. +config AR71XX_DEV_AP94_PCI
  2754. + def_bool n
  2755. +
  2756. +config AR71XX_DEV_AR913X_WMAC
  2757. + def_bool n
  2758. +
  2759. +config AR71XX_DEV_DSA
  2760. + def_bool n
  2761. +
  2762. +config AR71XX_DEV_GPIO_BUTTONS
  2763. + def_bool n
  2764. +
  2765. +config AR71XX_DEV_LEDS_GPIO
  2766. + def_bool n
  2767. +
  2768. +config AR71XX_DEV_PB42_PCI
  2769. + def_bool n
  2770. +
  2771. +config AR71XX_DEV_PB9X_PCI
  2772. + def_bool n
  2773. +
  2774. +config AR71XX_DEV_USB
  2775. + def_bool n
  2776. +
  2777. +config AR71XX_NVRAM
  2778. + def_bool n
  2779. +
  2780. +endif
  2781. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-ap81.c linux-2.6.34/arch/mips/ar71xx/mach-ap81.c
  2782. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-ap81.c 1970-01-01 01:00:00.000000000 +0100
  2783. +++ linux-2.6.34/arch/mips/ar71xx/mach-ap81.c 2010-05-25 18:46:05.373464152 +0200
  2784. @@ -0,0 +1,140 @@
  2785. +/*
  2786. + * Atheros AP81 board support
  2787. + *
  2788. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  2789. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  2790. + *
  2791. + * This program is free software; you can redistribute it and/or modify it
  2792. + * under the terms of the GNU General Public License version 2 as published
  2793. + * by the Free Software Foundation.
  2794. + */
  2795. +
  2796. +#include <linux/mtd/mtd.h>
  2797. +#include <linux/mtd/partitions.h>
  2798. +
  2799. +#include <asm/mach-ar71xx/ar71xx.h>
  2800. +
  2801. +#include "machtype.h"
  2802. +#include "devices.h"
  2803. +#include "dev-m25p80.h"
  2804. +#include "dev-ar913x-wmac.h"
  2805. +#include "dev-gpio-buttons.h"
  2806. +#include "dev-leds-gpio.h"
  2807. +#include "dev-usb.h"
  2808. +
  2809. +#define AP81_GPIO_LED_STATUS 1
  2810. +#define AP81_GPIO_LED_AOSS 3
  2811. +#define AP81_GPIO_LED_WLAN 6
  2812. +#define AP81_GPIO_LED_POWER 14
  2813. +
  2814. +#define AP81_GPIO_BTN_SW4 12
  2815. +#define AP81_GPIO_BTN_SW1 21
  2816. +
  2817. +#define AP81_BUTTONS_POLL_INTERVAL 20
  2818. +
  2819. +#ifdef CONFIG_MTD_PARTITIONS
  2820. +static struct mtd_partition ap81_partitions[] = {
  2821. + {
  2822. + .name = "u-boot",
  2823. + .offset = 0,
  2824. + .size = 0x040000,
  2825. + .mask_flags = MTD_WRITEABLE,
  2826. + } , {
  2827. + .name = "u-boot-env",
  2828. + .offset = 0x040000,
  2829. + .size = 0x010000,
  2830. + } , {
  2831. + .name = "rootfs",
  2832. + .offset = 0x050000,
  2833. + .size = 0x500000,
  2834. + } , {
  2835. + .name = "uImage",
  2836. + .offset = 0x550000,
  2837. + .size = 0x100000,
  2838. + } , {
  2839. + .name = "ART",
  2840. + .offset = 0x650000,
  2841. + .size = 0x1b0000,
  2842. + .mask_flags = MTD_WRITEABLE,
  2843. + }
  2844. +};
  2845. +#endif /* CONFIG_MTD_PARTITIONS */
  2846. +
  2847. +static struct flash_platform_data ap81_flash_data = {
  2848. +#ifdef CONFIG_MTD_PARTITIONS
  2849. + .parts = ap81_partitions,
  2850. + .nr_parts = ARRAY_SIZE(ap81_partitions),
  2851. +#endif
  2852. +};
  2853. +
  2854. +static struct gpio_led ap81_leds_gpio[] __initdata = {
  2855. + {
  2856. + .name = "ap81:green:status",
  2857. + .gpio = AP81_GPIO_LED_STATUS,
  2858. + .active_low = 1,
  2859. + }, {
  2860. + .name = "ap81:amber:aoss",
  2861. + .gpio = AP81_GPIO_LED_AOSS,
  2862. + .active_low = 1,
  2863. + }, {
  2864. + .name = "ap81:green:wlan",
  2865. + .gpio = AP81_GPIO_LED_WLAN,
  2866. + .active_low = 1,
  2867. + }, {
  2868. + .name = "ap81:green:power",
  2869. + .gpio = AP81_GPIO_LED_POWER,
  2870. + .active_low = 1,
  2871. + }
  2872. +};
  2873. +
  2874. +static struct gpio_button ap81_gpio_buttons[] __initdata = {
  2875. + {
  2876. + .desc = "sw1",
  2877. + .type = EV_KEY,
  2878. + .code = BTN_0,
  2879. + .threshold = 3,
  2880. + .gpio = AP81_GPIO_BTN_SW1,
  2881. + .active_low = 1,
  2882. + } , {
  2883. + .desc = "sw4",
  2884. + .type = EV_KEY,
  2885. + .code = BTN_1,
  2886. + .threshold = 3,
  2887. + .gpio = AP81_GPIO_BTN_SW4,
  2888. + .active_low = 1,
  2889. + }
  2890. +};
  2891. +
  2892. +static void __init ap81_setup(void)
  2893. +{
  2894. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  2895. +
  2896. + ar71xx_set_mac_base(eeprom);
  2897. + ar71xx_add_device_mdio(0x0);
  2898. +
  2899. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  2900. + ar71xx_eth0_data.speed = SPEED_100;
  2901. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  2902. + ar71xx_eth0_data.has_ar8216 = 1;
  2903. +
  2904. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  2905. + ar71xx_eth1_data.phy_mask = 0x10;
  2906. +
  2907. + ar71xx_add_device_eth(0);
  2908. + ar71xx_add_device_eth(1);
  2909. +
  2910. + ar71xx_add_device_usb();
  2911. +
  2912. + ar71xx_add_device_m25p80(&ap81_flash_data);
  2913. +
  2914. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap81_leds_gpio),
  2915. + ap81_leds_gpio);
  2916. +
  2917. + ar71xx_add_device_gpio_buttons(-1, AP81_BUTTONS_POLL_INTERVAL,
  2918. + ARRAY_SIZE(ap81_gpio_buttons),
  2919. + ap81_gpio_buttons);
  2920. +
  2921. + ar913x_add_device_wmac(eeprom, NULL);
  2922. +}
  2923. +
  2924. +MIPS_MACHINE(AR71XX_MACH_AP81, "AP81", "Atheros AP81", ap81_setup);
  2925. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-ap83.c linux-2.6.34/arch/mips/ar71xx/mach-ap83.c
  2926. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-ap83.c 1970-01-01 01:00:00.000000000 +0100
  2927. +++ linux-2.6.34/arch/mips/ar71xx/mach-ap83.c 2010-05-25 18:46:05.413464137 +0200
  2928. @@ -0,0 +1,266 @@
  2929. +/*
  2930. + * Atheros AP83 board support
  2931. + *
  2932. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  2933. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  2934. + *
  2935. + * This program is free software; you can redistribute it and/or modify it
  2936. + * under the terms of the GNU General Public License version 2 as published
  2937. + * by the Free Software Foundation.
  2938. + */
  2939. +
  2940. +#include <linux/delay.h>
  2941. +#include <linux/platform_device.h>
  2942. +#include <linux/mtd/mtd.h>
  2943. +#include <linux/mtd/partitions.h>
  2944. +#include <linux/spi/spi.h>
  2945. +#include <linux/spi/spi_gpio.h>
  2946. +#include <linux/spi/vsc7385.h>
  2947. +
  2948. +#include <asm/mach-ar71xx/ar71xx.h>
  2949. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  2950. +
  2951. +#include "machtype.h"
  2952. +#include "devices.h"
  2953. +#include "dev-ar913x-wmac.h"
  2954. +#include "dev-gpio-buttons.h"
  2955. +#include "dev-leds-gpio.h"
  2956. +#include "dev-usb.h"
  2957. +
  2958. +#define AP83_GPIO_LED_WLAN 6
  2959. +#define AP83_GPIO_LED_POWER 14
  2960. +#define AP83_GPIO_LED_JUMPSTART 15
  2961. +#define AP83_GPIO_BTN_JUMPSTART 12
  2962. +#define AP83_GPIO_BTN_RESET 21
  2963. +
  2964. +#define AP83_050_GPIO_VSC7385_CS 1
  2965. +#define AP83_050_GPIO_VSC7385_MISO 3
  2966. +#define AP83_050_GPIO_VSC7385_MOSI 16
  2967. +#define AP83_050_GPIO_VSC7385_SCK 17
  2968. +
  2969. +#define AP83_BUTTONS_POLL_INTERVAL 20
  2970. +
  2971. +#ifdef CONFIG_MTD_PARTITIONS
  2972. +static struct mtd_partition ap83_flash_partitions[] = {
  2973. + {
  2974. + .name = "u-boot",
  2975. + .offset = 0,
  2976. + .size = 0x040000,
  2977. + .mask_flags = MTD_WRITEABLE,
  2978. + } , {
  2979. + .name = "u-boot-env",
  2980. + .offset = 0x040000,
  2981. + .size = 0x020000,
  2982. + .mask_flags = MTD_WRITEABLE,
  2983. + } , {
  2984. + .name = "kernel",
  2985. + .offset = 0x060000,
  2986. + .size = 0x140000,
  2987. + } , {
  2988. + .name = "rootfs",
  2989. + .offset = 0x1a0000,
  2990. + .size = 0x650000,
  2991. + } , {
  2992. + .name = "art",
  2993. + .offset = 0x7f0000,
  2994. + .size = 0x010000,
  2995. + .mask_flags = MTD_WRITEABLE,
  2996. + } , {
  2997. + .name = "firmware",
  2998. + .offset = 0x060000,
  2999. + .size = 0x790000,
  3000. + }
  3001. +};
  3002. +#endif /* CONFIG_MTD_PARTITIONS */
  3003. +
  3004. +static struct ar91xx_flash_platform_data ap83_flash_data = {
  3005. + .width = 2,
  3006. +#ifdef CONFIG_MTD_PARTITIONS
  3007. + .parts = ap83_flash_partitions,
  3008. + .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
  3009. +#endif
  3010. +};
  3011. +
  3012. +static struct resource ap83_flash_resources[] = {
  3013. + [0] = {
  3014. + .start = AR71XX_SPI_BASE,
  3015. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3016. + .flags = IORESOURCE_MEM,
  3017. + },
  3018. +};
  3019. +
  3020. +static struct platform_device ap83_flash_device = {
  3021. + .name = "ar91xx-flash",
  3022. + .id = -1,
  3023. + .resource = ap83_flash_resources,
  3024. + .num_resources = ARRAY_SIZE(ap83_flash_resources),
  3025. + .dev = {
  3026. + .platform_data = &ap83_flash_data,
  3027. + }
  3028. +};
  3029. +
  3030. +static struct gpio_led ap83_leds_gpio[] __initdata = {
  3031. + {
  3032. + .name = "ap83:green:jumpstart",
  3033. + .gpio = AP83_GPIO_LED_JUMPSTART,
  3034. + .active_low = 0,
  3035. + }, {
  3036. + .name = "ap83:green:power",
  3037. + .gpio = AP83_GPIO_LED_POWER,
  3038. + .active_low = 0,
  3039. + }, {
  3040. + .name = "ap83:green:wlan",
  3041. + .gpio = AP83_GPIO_LED_WLAN,
  3042. + .active_low = 0,
  3043. + },
  3044. +};
  3045. +
  3046. +static struct gpio_button ap83_gpio_buttons[] __initdata = {
  3047. + {
  3048. + .desc = "soft_reset",
  3049. + .type = EV_KEY,
  3050. + .code = KEY_RESTART,
  3051. + .threshold = 3,
  3052. + .gpio = AP83_GPIO_BTN_RESET,
  3053. + .active_low = 1,
  3054. + } , {
  3055. + .desc = "jumpstart",
  3056. + .type = EV_KEY,
  3057. + .code = KEY_WPS_BUTTON,
  3058. + .threshold = 3,
  3059. + .gpio = AP83_GPIO_BTN_JUMPSTART,
  3060. + .active_low = 1,
  3061. + }
  3062. +};
  3063. +
  3064. +static struct resource ap83_040_spi_resources[] = {
  3065. + [0] = {
  3066. + .start = AR71XX_SPI_BASE,
  3067. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  3068. + .flags = IORESOURCE_MEM,
  3069. + },
  3070. +};
  3071. +
  3072. +static struct platform_device ap83_040_spi_device = {
  3073. + .name = "ap83-spi",
  3074. + .id = 0,
  3075. + .resource = ap83_040_spi_resources,
  3076. + .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
  3077. +};
  3078. +
  3079. +static struct spi_gpio_platform_data ap83_050_spi_data = {
  3080. + .miso = AP83_050_GPIO_VSC7385_MISO,
  3081. + .mosi = AP83_050_GPIO_VSC7385_MOSI,
  3082. + .sck = AP83_050_GPIO_VSC7385_SCK,
  3083. + .num_chipselect = 1,
  3084. +};
  3085. +
  3086. +static struct platform_device ap83_050_spi_device = {
  3087. + .name = "spi_gpio",
  3088. + .id = 0,
  3089. + .dev = {
  3090. + .platform_data = &ap83_050_spi_data,
  3091. + }
  3092. +};
  3093. +
  3094. +static void ap83_vsc7385_reset(void)
  3095. +{
  3096. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  3097. + udelay(10);
  3098. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  3099. + mdelay(50);
  3100. +}
  3101. +
  3102. +static struct vsc7385_platform_data ap83_vsc7385_data = {
  3103. + .reset = ap83_vsc7385_reset,
  3104. + .ucode_name = "vsc7385_ucode_ap83.bin",
  3105. + .mac_cfg = {
  3106. + .tx_ipg = 6,
  3107. + .bit2 = 0,
  3108. + .clk_sel = 3,
  3109. + },
  3110. +};
  3111. +
  3112. +static struct spi_board_info ap83_spi_info[] = {
  3113. + {
  3114. + .bus_num = 0,
  3115. + .chip_select = 0,
  3116. + .max_speed_hz = 25000000,
  3117. + .modalias = "spi-vsc7385",
  3118. + .platform_data = &ap83_vsc7385_data,
  3119. + .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
  3120. + }
  3121. +};
  3122. +
  3123. +static void __init ap83_generic_setup(void)
  3124. +{
  3125. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3126. +
  3127. + ar71xx_set_mac_base(eeprom);
  3128. +
  3129. + ar71xx_add_device_mdio(0xfffffffe);
  3130. +
  3131. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3132. + ar71xx_eth0_data.phy_mask = 0x1;
  3133. +
  3134. + ar71xx_add_device_eth(0);
  3135. +
  3136. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3137. + ar71xx_eth1_data.speed = SPEED_1000;
  3138. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  3139. +
  3140. + ar71xx_eth1_pll_data.pll_1000 = 0x1f000000;
  3141. +
  3142. + ar71xx_add_device_eth(1);
  3143. +
  3144. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
  3145. + ap83_leds_gpio);
  3146. +
  3147. + ar71xx_add_device_gpio_buttons(-1, AP83_BUTTONS_POLL_INTERVAL,
  3148. + ARRAY_SIZE(ap83_gpio_buttons),
  3149. + ap83_gpio_buttons);
  3150. +
  3151. + ar71xx_add_device_usb();
  3152. +
  3153. + ar913x_add_device_wmac(eeprom, NULL);
  3154. +
  3155. + platform_device_register(&ap83_flash_device);
  3156. +
  3157. + spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
  3158. +}
  3159. +
  3160. +static void __init ap83_040_setup(void)
  3161. +{
  3162. + ap83_flash_data.is_shared=1;
  3163. + ap83_generic_setup();
  3164. + platform_device_register(&ap83_040_spi_device);
  3165. +}
  3166. +
  3167. +static void __init ap83_050_setup(void)
  3168. +{
  3169. + ap83_generic_setup();
  3170. + platform_device_register(&ap83_050_spi_device);
  3171. +}
  3172. +
  3173. +static void __init ap83_setup(void)
  3174. +{
  3175. + u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
  3176. + unsigned int board_version;
  3177. +
  3178. + board_version = (unsigned int)(board_id[0] - '0');
  3179. + board_version += ((unsigned int)(board_id[1] - '0')) * 10;
  3180. +
  3181. + switch (board_version) {
  3182. + case 40:
  3183. + ap83_040_setup();
  3184. + break;
  3185. + case 50:
  3186. + ap83_050_setup();
  3187. + break;
  3188. + default:
  3189. + printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
  3190. + board_version);
  3191. + }
  3192. +}
  3193. +
  3194. +MIPS_MACHINE(AR71XX_MACH_AP83, "AP83", "Atheros AP83", ap83_setup);
  3195. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-aw-nr580.c linux-2.6.34/arch/mips/ar71xx/mach-aw-nr580.c
  3196. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-aw-nr580.c 1970-01-01 01:00:00.000000000 +0100
  3197. +++ linux-2.6.34/arch/mips/ar71xx/mach-aw-nr580.c 2010-05-25 18:46:05.443473125 +0200
  3198. @@ -0,0 +1,101 @@
  3199. +/*
  3200. + * AzureWave AW-NR580 board support
  3201. + *
  3202. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3203. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3204. + *
  3205. + * This program is free software; you can redistribute it and/or modify it
  3206. + * under the terms of the GNU General Public License version 2 as published
  3207. + * by the Free Software Foundation.
  3208. + */
  3209. +
  3210. +#include <linux/mtd/mtd.h>
  3211. +#include <linux/mtd/partitions.h>
  3212. +
  3213. +#include <asm/mips_machine.h>
  3214. +#include <asm/mach-ar71xx/ar71xx.h>
  3215. +
  3216. +#include "machtype.h"
  3217. +#include "devices.h"
  3218. +#include "dev-m25p80.h"
  3219. +#include "dev-gpio-buttons.h"
  3220. +#include "dev-pb42-pci.h"
  3221. +#include "dev-leds-gpio.h"
  3222. +
  3223. +#define AW_NR580_GPIO_LED_READY_RED 0
  3224. +#define AW_NR580_GPIO_LED_WLAN 1
  3225. +#define AW_NR580_GPIO_LED_READY_GREEN 2
  3226. +#define AW_NR580_GPIO_LED_WPS_GREEN 4
  3227. +#define AW_NR580_GPIO_LED_WPS_AMBER 5
  3228. +
  3229. +#define AW_NR580_GPIO_BTN_WPS 3
  3230. +#define AW_NR580_GPIO_BTN_RESET 11
  3231. +
  3232. +#define AW_NR580_BUTTONS_POLL_INTERVAL 20
  3233. +
  3234. +static struct gpio_led aw_nr580_leds_gpio[] __initdata = {
  3235. + {
  3236. + .name = "aw-nr580:red:ready",
  3237. + .gpio = AW_NR580_GPIO_LED_READY_RED,
  3238. + .active_low = 0,
  3239. + }, {
  3240. + .name = "aw-nr580:green:ready",
  3241. + .gpio = AW_NR580_GPIO_LED_READY_GREEN,
  3242. + .active_low = 0,
  3243. + }, {
  3244. + .name = "aw-nr580:green:wps",
  3245. + .gpio = AW_NR580_GPIO_LED_WPS_GREEN,
  3246. + .active_low = 0,
  3247. + }, {
  3248. + .name = "aw-nr580:amber:wps",
  3249. + .gpio = AW_NR580_GPIO_LED_WPS_AMBER,
  3250. + .active_low = 0,
  3251. + }, {
  3252. + .name = "aw-nr580:green:wlan",
  3253. + .gpio = AW_NR580_GPIO_LED_WLAN,
  3254. + .active_low = 0,
  3255. + }
  3256. +};
  3257. +
  3258. +static struct gpio_button aw_nr580_gpio_buttons[] __initdata = {
  3259. + {
  3260. + .desc = "reset",
  3261. + .type = EV_KEY,
  3262. + .code = KEY_RESTART,
  3263. + .threshold = 3,
  3264. + .gpio = AW_NR580_GPIO_BTN_RESET,
  3265. + .active_low = 1,
  3266. + }, {
  3267. + .desc = "wps",
  3268. + .type = EV_KEY,
  3269. + .code = KEY_WPS_BUTTON,
  3270. + .threshold = 3,
  3271. + .gpio = AW_NR580_GPIO_BTN_WPS,
  3272. + .active_low = 1,
  3273. + }
  3274. +};
  3275. +
  3276. +static void __init aw_nr580_setup(void)
  3277. +{
  3278. + ar71xx_add_device_mdio(0x0);
  3279. +
  3280. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  3281. + ar71xx_eth0_data.speed = SPEED_100;
  3282. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3283. +
  3284. + ar71xx_add_device_eth(0);
  3285. +
  3286. + pb42_pci_init();
  3287. +
  3288. + ar71xx_add_device_m25p80(NULL);
  3289. +
  3290. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(aw_nr580_leds_gpio),
  3291. + aw_nr580_leds_gpio);
  3292. +
  3293. + ar71xx_add_device_gpio_buttons(-1, AW_NR580_BUTTONS_POLL_INTERVAL,
  3294. + ARRAY_SIZE(aw_nr580_gpio_buttons),
  3295. + aw_nr580_gpio_buttons);
  3296. +}
  3297. +
  3298. +MIPS_MACHINE(AR71XX_MACH_AW_NR580, "AW-NR580", "AzureWave AW-NR580",
  3299. + aw_nr580_setup);
  3300. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-600-a1.c linux-2.6.34/arch/mips/ar71xx/mach-dir-600-a1.c
  3301. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-600-a1.c 1970-01-01 01:00:00.000000000 +0100
  3302. +++ linux-2.6.34/arch/mips/ar71xx/mach-dir-600-a1.c 2010-05-25 18:46:05.483473151 +0200
  3303. @@ -0,0 +1,138 @@
  3304. +/*
  3305. + * D-Link DIR-600 rev. A1 board support
  3306. + *
  3307. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  3308. + *
  3309. + * This program is free software; you can redistribute it and/or modify it
  3310. + * under the terms of the GNU General Public License version 2 as published
  3311. + * by the Free Software Foundation.
  3312. + */
  3313. +
  3314. +#include <linux/mtd/mtd.h>
  3315. +#include <linux/mtd/partitions.h>
  3316. +
  3317. +#include <asm/mach-ar71xx/ar71xx.h>
  3318. +
  3319. +#include "machtype.h"
  3320. +#include "devices.h"
  3321. +#include "dev-m25p80.h"
  3322. +#include "dev-ap91-eth.h"
  3323. +#include "dev-ap91-pci.h"
  3324. +#include "dev-gpio-buttons.h"
  3325. +#include "dev-leds-gpio.h"
  3326. +#include "nvram.h"
  3327. +
  3328. +#define DIR_600_A1_GPIO_LED_WPS 0
  3329. +#define DIR_600_A1_GPIO_LED_POWER_AMBER 1
  3330. +#define DIR_600_A1_GPIO_LED_POWER_GREEN 6
  3331. +
  3332. +#define DIR_600_A1_GPIO_BTN_RESET 8
  3333. +#define DIR_600_A1_GPIO_BTN_WPS 12
  3334. +
  3335. +#define DIR_600_A1_BUTTONS_POLL_INTERVAL 20
  3336. +
  3337. +#define DIR_600_A1_NVRAM_ADDR 0x1f030000
  3338. +#define DIR_600_A1_NVRAM_SIZE 0x10000
  3339. +
  3340. +#ifdef CONFIG_MTD_PARTITIONS
  3341. +static struct mtd_partition dir_600_a1_partitions[] = {
  3342. + {
  3343. + .name = "u-boot",
  3344. + .offset = 0,
  3345. + .size = 0x030000,
  3346. + .mask_flags = MTD_WRITEABLE,
  3347. + }, {
  3348. + .name = "nvram",
  3349. + .offset = 0x030000,
  3350. + .size = 0x010000,
  3351. + }, {
  3352. + .name = "kernel",
  3353. + .offset = 0x040000,
  3354. + .size = 0x0e0000,
  3355. + }, {
  3356. + .name = "rootfs",
  3357. + .offset = 0x120000,
  3358. + .size = 0x2c0000,
  3359. + }, {
  3360. + .name = "mac",
  3361. + .offset = 0x3e0000,
  3362. + .size = 0x010000,
  3363. + .mask_flags = MTD_WRITEABLE,
  3364. + }, {
  3365. + .name = "art",
  3366. + .offset = 0x3f0000,
  3367. + .size = 0x010000,
  3368. + .mask_flags = MTD_WRITEABLE,
  3369. + }, {
  3370. + .name = "firmware",
  3371. + .offset = 0x040000,
  3372. + .size = 0x3a0000,
  3373. + }
  3374. +};
  3375. +#endif /* CONFIG_MTD_PARTITIONS */
  3376. +
  3377. +static struct flash_platform_data dir_600_a1_flash_data = {
  3378. +#ifdef CONFIG_MTD_PARTITIONS
  3379. + .parts = dir_600_a1_partitions,
  3380. + .nr_parts = ARRAY_SIZE(dir_600_a1_partitions),
  3381. +#endif
  3382. +};
  3383. +
  3384. +static struct gpio_led dir_600_a1_leds_gpio[] __initdata = {
  3385. + {
  3386. + .name = "dir-600-a1:green:power",
  3387. + .gpio = DIR_600_A1_GPIO_LED_POWER_GREEN,
  3388. + }, {
  3389. + .name = "dir-600-a1:amber:power",
  3390. + .gpio = DIR_600_A1_GPIO_LED_POWER_AMBER,
  3391. + }, {
  3392. + .name = "dir-600-a1:blue:wps",
  3393. + .gpio = DIR_600_A1_GPIO_LED_WPS,
  3394. + .active_low = 1,
  3395. + }
  3396. +};
  3397. +
  3398. +static struct gpio_button dir_600_a1_gpio_buttons[] __initdata = {
  3399. + {
  3400. + .desc = "reset",
  3401. + .type = EV_KEY,
  3402. + .code = KEY_RESTART,
  3403. + .threshold = 3,
  3404. + .gpio = DIR_600_A1_GPIO_BTN_RESET,
  3405. + .active_low = 1,
  3406. + }, {
  3407. + .desc = "wps",
  3408. + .type = EV_KEY,
  3409. + .code = KEY_WPS_BUTTON,
  3410. + .threshold = 3,
  3411. + .gpio = DIR_600_A1_GPIO_BTN_WPS,
  3412. + .active_low = 1,
  3413. + }
  3414. +};
  3415. +
  3416. +static void __init dir_600_a1_setup(void)
  3417. +{
  3418. + const char *nvram = (char *) KSEG1ADDR(DIR_600_A1_NVRAM_ADDR);
  3419. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  3420. + u8 mac_buff[6];
  3421. + u8 *mac = NULL;
  3422. +
  3423. + if (nvram_parse_mac_addr(nvram, DIR_600_A1_NVRAM_SIZE,
  3424. + "lan_mac=", mac_buff) == 0)
  3425. + mac = mac_buff;
  3426. +
  3427. + ar71xx_add_device_m25p80(&dir_600_a1_flash_data);
  3428. +
  3429. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_600_a1_leds_gpio),
  3430. + dir_600_a1_leds_gpio);
  3431. +
  3432. + ar71xx_add_device_gpio_buttons(-1, DIR_600_A1_BUTTONS_POLL_INTERVAL,
  3433. + ARRAY_SIZE(dir_600_a1_gpio_buttons),
  3434. + dir_600_a1_gpio_buttons);
  3435. +
  3436. + ap91_eth_init(mac, NULL);
  3437. + ap91_pci_init(ee, mac);
  3438. +}
  3439. +
  3440. +MIPS_MACHINE(AR71XX_MACH_DIR_600_A1, "DIR-600-A1", "D-Link DIR-600 rev. A1",
  3441. + dir_600_a1_setup);
  3442. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-615-c1.c linux-2.6.34/arch/mips/ar71xx/mach-dir-615-c1.c
  3443. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-615-c1.c 1970-01-01 01:00:00.000000000 +0100
  3444. +++ linux-2.6.34/arch/mips/ar71xx/mach-dir-615-c1.c 2010-05-25 18:46:05.520978530 +0200
  3445. @@ -0,0 +1,173 @@
  3446. +/*
  3447. + * D-Link DIR-615 rev C1 board support
  3448. + *
  3449. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3450. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3451. + *
  3452. + * This program is free software; you can redistribute it and/or modify it
  3453. + * under the terms of the GNU General Public License version 2 as published
  3454. + * by the Free Software Foundation.
  3455. + */
  3456. +
  3457. +#include <linux/mtd/mtd.h>
  3458. +#include <linux/mtd/partitions.h>
  3459. +
  3460. +#include <asm/mach-ar71xx/ar71xx.h>
  3461. +
  3462. +#include "machtype.h"
  3463. +#include "devices.h"
  3464. +#include "dev-m25p80.h"
  3465. +#include "dev-ar913x-wmac.h"
  3466. +#include "dev-gpio-buttons.h"
  3467. +#include "dev-leds-gpio.h"
  3468. +#include "nvram.h"
  3469. +
  3470. +#define DIR_615C1_GPIO_LED_ORANGE_STATUS 1 /* ORANGE:STATUS:TRICOLOR */
  3471. +#define DIR_615C1_GPIO_LED_BLUE_WPS 3 /* BLUE:WPS */
  3472. +#define DIR_615C1_GPIO_LED_GREEN_WAN 4 /* GREEN:WAN:TRICOLOR */
  3473. +#define DIR_615C1_GPIO_LED_GREEN_WANCPU 5 /* GREEN:WAN:CPU:TRICOLOR */
  3474. +#define DIR_615C1_GPIO_LED_GREEN_WLAN 6 /* GREEN:WLAN */
  3475. +#define DIR_615C1_GPIO_LED_GREEN_STATUS 14 /* GREEN:STATUS:TRICOLOR */
  3476. +#define DIR_615C1_GPIO_LED_ORANGE_WAN 15 /* ORANGE:WAN:TRICOLOR */
  3477. +
  3478. +/* buttons may need refinement */
  3479. +
  3480. +#define DIR_615C1_GPIO_BTN_WPS 12
  3481. +#define DIR_615C1_GPIO_BTN_RESET 21
  3482. +
  3483. +#define DIR_615C1_BUTTONS_POLL_INTERVAL 20
  3484. +
  3485. +#define DIR_615C1_CONFIG_ADDR 0x1f020000
  3486. +#define DIR_615C1_CONFIG_SIZE 0x10000
  3487. +
  3488. +#ifdef CONFIG_MTD_PARTITIONS
  3489. +static struct mtd_partition dir_615c1_partitions[] = {
  3490. + {
  3491. + .name = "u-boot",
  3492. + .offset = 0,
  3493. + .size = 0x020000,
  3494. + .mask_flags = MTD_WRITEABLE,
  3495. + } , {
  3496. + .name = "config",
  3497. + .offset = 0x020000,
  3498. + .size = 0x010000,
  3499. + } , {
  3500. + .name = "kernel",
  3501. + .offset = 0x030000,
  3502. + .size = 0x0d0000,
  3503. + } , {
  3504. + .name = "rootfs",
  3505. + .offset = 0x100000,
  3506. + .size = 0x2f0000,
  3507. + } , {
  3508. + .name = "art",
  3509. + .offset = 0x3f0000,
  3510. + .size = 0x010000,
  3511. + .mask_flags = MTD_WRITEABLE,
  3512. + } , {
  3513. + .name = "firmware",
  3514. + .offset = 0x030000,
  3515. + .size = 0x3c0000,
  3516. + }
  3517. +};
  3518. +#endif /* CONFIG_MTD_PARTITIONS */
  3519. +
  3520. +static struct flash_platform_data dir_615c1_flash_data = {
  3521. +#ifdef CONFIG_MTD_PARTITIONS
  3522. + .parts = dir_615c1_partitions,
  3523. + .nr_parts = ARRAY_SIZE(dir_615c1_partitions),
  3524. +#endif
  3525. +};
  3526. +
  3527. +static struct gpio_led dir_615c1_leds_gpio[] __initdata = {
  3528. + {
  3529. + .name = "dir-615c1:orange:status",
  3530. + .gpio = DIR_615C1_GPIO_LED_ORANGE_STATUS,
  3531. + .active_low = 1,
  3532. + }, {
  3533. + .name = "dir-615c1:blue:wps",
  3534. + .gpio = DIR_615C1_GPIO_LED_BLUE_WPS,
  3535. + .active_low = 1,
  3536. + }, {
  3537. + .name = "dir-615c1:green:wan",
  3538. + .gpio = DIR_615C1_GPIO_LED_GREEN_WAN,
  3539. + .active_low = 1,
  3540. + }, {
  3541. + .name = "dir-615c1:green:wancpu",
  3542. + .gpio = DIR_615C1_GPIO_LED_GREEN_WANCPU,
  3543. + .active_low = 1,
  3544. + }, {
  3545. + .name = "dir-615c1:green:wlan",
  3546. + .gpio = DIR_615C1_GPIO_LED_GREEN_WLAN,
  3547. + .active_low = 1,
  3548. + }, {
  3549. + .name = "dir-615c1:green:status",
  3550. + .gpio = DIR_615C1_GPIO_LED_GREEN_STATUS,
  3551. + .active_low = 1,
  3552. + }, {
  3553. + .name = "dir-615c1:orange:wan",
  3554. + .gpio = DIR_615C1_GPIO_LED_ORANGE_WAN,
  3555. + .active_low = 1,
  3556. + }
  3557. +
  3558. +};
  3559. +
  3560. +static struct gpio_button dir_615c1_gpio_buttons[] __initdata = {
  3561. + {
  3562. + .desc = "reset",
  3563. + .type = EV_KEY,
  3564. + .code = KEY_RESTART,
  3565. + .threshold = 3,
  3566. + .gpio = DIR_615C1_GPIO_BTN_RESET,
  3567. + }, {
  3568. + .desc = "wps",
  3569. + .type = EV_KEY,
  3570. + .code = KEY_WPS_BUTTON,
  3571. + .threshold = 3,
  3572. + .gpio = DIR_615C1_GPIO_BTN_WPS,
  3573. + }
  3574. +};
  3575. +
  3576. +#define DIR_615C1_LAN_PHYMASK BIT(0)
  3577. +#define DIR_615C1_WAN_PHYMASK BIT(4)
  3578. +#define DIR_615C1_MDIO_MASK (~(DIR_615C1_LAN_PHYMASK | \
  3579. + DIR_615C1_WAN_PHYMASK))
  3580. +
  3581. +static void __init dir_615c1_setup(void)
  3582. +{
  3583. + const char *config = (char *) KSEG1ADDR(DIR_615C1_CONFIG_ADDR);
  3584. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3585. + u8 mac[6];
  3586. + u8 *wlan_mac = NULL;
  3587. +
  3588. + if (nvram_parse_mac_addr(config, DIR_615C1_CONFIG_SIZE,
  3589. + "lan_mac=", mac) == 0) {
  3590. + ar71xx_set_mac_base(mac);
  3591. + wlan_mac = mac;
  3592. + }
  3593. +
  3594. + ar71xx_add_device_mdio(DIR_615C1_MDIO_MASK);
  3595. +
  3596. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3597. + ar71xx_eth0_data.phy_mask = DIR_615C1_LAN_PHYMASK;
  3598. +
  3599. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3600. + ar71xx_eth1_data.phy_mask = DIR_615C1_WAN_PHYMASK;
  3601. +
  3602. + ar71xx_add_device_eth(0);
  3603. + ar71xx_add_device_eth(1);
  3604. +
  3605. + ar71xx_add_device_m25p80(&dir_615c1_flash_data);
  3606. +
  3607. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_615c1_leds_gpio),
  3608. + dir_615c1_leds_gpio);
  3609. +
  3610. + ar71xx_add_device_gpio_buttons(-1, DIR_615C1_BUTTONS_POLL_INTERVAL,
  3611. + ARRAY_SIZE(dir_615c1_gpio_buttons),
  3612. + dir_615c1_gpio_buttons);
  3613. +
  3614. + ar913x_add_device_wmac(eeprom, wlan_mac);
  3615. +}
  3616. +
  3617. +MIPS_MACHINE(AR71XX_MACH_DIR_615_C1, "DIR-615-C1", "D-Link DIR-615 rev. C1",
  3618. + dir_615c1_setup);
  3619. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-825-b1.c linux-2.6.34/arch/mips/ar71xx/mach-dir-825-b1.c
  3620. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-dir-825-b1.c 1970-01-01 01:00:00.000000000 +0100
  3621. +++ linux-2.6.34/arch/mips/ar71xx/mach-dir-825-b1.c 2010-05-25 18:46:05.560978790 +0200
  3622. @@ -0,0 +1,192 @@
  3623. +/*
  3624. + * D-Link DIR-825 rev. B1 board support
  3625. + *
  3626. + * Copyright (C) 2009 Lukas Kuna, Evkanet, s.r.o.
  3627. + *
  3628. + * based on mach-wndr3700.c
  3629. + *
  3630. + * This program is free software; you can redistribute it and/or modify it
  3631. + * under the terms of the GNU General Public License version 2 as published
  3632. + * by the Free Software Foundation.
  3633. + */
  3634. +
  3635. +#include <linux/platform_device.h>
  3636. +#include <linux/mtd/mtd.h>
  3637. +#include <linux/mtd/partitions.h>
  3638. +#include <linux/delay.h>
  3639. +#include <linux/rtl8366s.h>
  3640. +
  3641. +#include <asm/mach-ar71xx/ar71xx.h>
  3642. +
  3643. +#include "machtype.h"
  3644. +#include "devices.h"
  3645. +#include "dev-m25p80.h"
  3646. +#include "dev-ap94-pci.h"
  3647. +#include "dev-gpio-buttons.h"
  3648. +#include "dev-leds-gpio.h"
  3649. +#include "dev-usb.h"
  3650. +
  3651. +#define DIR825B1_GPIO_LED_BLUE_USB 0
  3652. +#define DIR825B1_GPIO_LED_ORANGE_POWER 1
  3653. +#define DIR825B1_GPIO_LED_BLUE_POWER 2
  3654. +#define DIR825B1_GPIO_LED_BLUE_POWERSAVE 4
  3655. +#define DIR825B1_GPIO_LED_ORANGE_PLANET 6
  3656. +#define DIR825B1_GPIO_LED_BLUE_PLANET 11
  3657. +
  3658. +#define DIR825B1_GPIO_BTN_RESET 3
  3659. +#define DIR825B1_GPIO_BTN_POWERSAVE 8
  3660. +
  3661. +#define DIR825B1_GPIO_RTL8366_SDA 5
  3662. +#define DIR825B1_GPIO_RTL8366_SCK 7
  3663. +
  3664. +#define DIR825B1_BUTTONS_POLL_INTERVAL 20
  3665. +
  3666. +#define DIR825B1_CAL_LOCATION_0 0x1f661000
  3667. +#define DIR825B1_CAL_LOCATION_1 0x1f665000
  3668. +
  3669. +#define DIR825B1_MAC_LOCATION_0 0x2ffa81b8
  3670. +#define DIR825B1_MAC_LOCATION_1 0x2ffa8370
  3671. +
  3672. +#ifdef CONFIG_MTD_PARTITIONS
  3673. +static struct mtd_partition dir825b1_partitions[] = {
  3674. + {
  3675. + .name = "uboot",
  3676. + .offset = 0,
  3677. + .size = 0x040000,
  3678. + .mask_flags = MTD_WRITEABLE,
  3679. + } , {
  3680. + .name = "config",
  3681. + .offset = 0x040000,
  3682. + .size = 0x010000,
  3683. + .mask_flags = MTD_WRITEABLE,
  3684. + } , {
  3685. + .name = "firmware",
  3686. + .offset = 0x050000,
  3687. + .size = 0x610000,
  3688. + } , {
  3689. + .name = "caldata",
  3690. + .offset = 0x660000,
  3691. + .size = 0x010000,
  3692. + .mask_flags = MTD_WRITEABLE,
  3693. + } , {
  3694. + .name = "unknown",
  3695. + .offset = 0x670000,
  3696. + .size = 0x190000,
  3697. + .mask_flags = MTD_WRITEABLE,
  3698. + }
  3699. +};
  3700. +#endif /* CONFIG_MTD_PARTITIONS */
  3701. +
  3702. +static struct flash_platform_data dir825b1_flash_data = {
  3703. +#ifdef CONFIG_MTD_PARTITIONS
  3704. + .parts = dir825b1_partitions,
  3705. + .nr_parts = ARRAY_SIZE(dir825b1_partitions),
  3706. +#endif
  3707. +};
  3708. +
  3709. +static struct gpio_led dir825b1_leds_gpio[] __initdata = {
  3710. + {
  3711. + .name = "dir825b1:blue:usb",
  3712. + .gpio = DIR825B1_GPIO_LED_BLUE_USB,
  3713. + .active_low = 1,
  3714. + }, {
  3715. + .name = "dir825b1:orange:power",
  3716. + .gpio = DIR825B1_GPIO_LED_ORANGE_POWER,
  3717. + .active_low = 1,
  3718. + }, {
  3719. + .name = "dir825b1:blue:power",
  3720. + .gpio = DIR825B1_GPIO_LED_BLUE_POWER,
  3721. + .active_low = 1,
  3722. + }, {
  3723. + .name = "dir825b1:blue:powersave",
  3724. + .gpio = DIR825B1_GPIO_LED_BLUE_POWERSAVE,
  3725. + .active_low = 1,
  3726. + }, {
  3727. + .name = "dir825b1:orange:planet",
  3728. + .gpio = DIR825B1_GPIO_LED_ORANGE_PLANET,
  3729. + .active_low = 1,
  3730. + }, {
  3731. + .name = "dir825b1:blue:planet",
  3732. + .gpio = DIR825B1_GPIO_LED_BLUE_PLANET,
  3733. + .active_low = 1,
  3734. + }
  3735. +};
  3736. +
  3737. +static struct gpio_button dir825b1_gpio_buttons[] __initdata = {
  3738. + {
  3739. + .desc = "reset",
  3740. + .type = EV_KEY,
  3741. + .code = KEY_RESTART,
  3742. + .threshold = 3,
  3743. + .gpio = DIR825B1_GPIO_BTN_RESET,
  3744. + .active_low = 1,
  3745. + } , {
  3746. + .desc = "powersave",
  3747. + .type = EV_KEY,
  3748. + .code = BTN_1,
  3749. + .threshold = 3,
  3750. + .gpio = DIR825B1_GPIO_BTN_POWERSAVE,
  3751. + .active_low = 1,
  3752. + }
  3753. +};
  3754. +
  3755. +static struct rtl8366s_platform_data dir825b1_rtl8366s_data = {
  3756. + .gpio_sda = DIR825B1_GPIO_RTL8366_SDA,
  3757. + .gpio_sck = DIR825B1_GPIO_RTL8366_SCK,
  3758. +};
  3759. +
  3760. +static struct platform_device dir825b1_rtl8366s_device = {
  3761. + .name = RTL8366S_DRIVER_NAME,
  3762. + .id = -1,
  3763. + .dev = {
  3764. + .platform_data = &dir825b1_rtl8366s_data,
  3765. + }
  3766. +};
  3767. +
  3768. +static void __init dir825b1_setup(void)
  3769. +{
  3770. + u8 mac[6], i;
  3771. +
  3772. + memcpy(mac, (u8*)KSEG1ADDR(DIR825B1_MAC_LOCATION_1), 6);
  3773. + for(i = 5; i >= 3; i--)
  3774. + if(++mac[i] != 0x00) break;
  3775. +
  3776. + ar71xx_set_mac_base(mac);
  3777. +
  3778. + ar71xx_add_device_mdio(0x0);
  3779. +
  3780. + ar71xx_eth0_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  3781. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3782. + ar71xx_eth0_data.speed = SPEED_1000;
  3783. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3784. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  3785. +
  3786. + ar71xx_eth1_data.mii_bus_dev = &dir825b1_rtl8366s_device.dev;
  3787. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  3788. + ar71xx_eth1_data.phy_mask = 0x10;
  3789. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  3790. +
  3791. + ar71xx_add_device_eth(0);
  3792. + ar71xx_add_device_eth(1);
  3793. +
  3794. + ar71xx_add_device_m25p80(&dir825b1_flash_data);
  3795. +
  3796. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir825b1_leds_gpio),
  3797. + dir825b1_leds_gpio);
  3798. +
  3799. + ar71xx_add_device_gpio_buttons(-1, DIR825B1_BUTTONS_POLL_INTERVAL,
  3800. + ARRAY_SIZE(dir825b1_gpio_buttons),
  3801. + dir825b1_gpio_buttons);
  3802. +
  3803. + ar71xx_add_device_usb();
  3804. +
  3805. + platform_device_register(&dir825b1_rtl8366s_device);
  3806. +
  3807. + ap94_pci_init((u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_0),
  3808. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_0),
  3809. + (u8 *) KSEG1ADDR(DIR825B1_CAL_LOCATION_1),
  3810. + (u8 *) KSEG1ADDR(DIR825B1_MAC_LOCATION_1));
  3811. +}
  3812. +
  3813. +MIPS_MACHINE(AR71XX_MACH_DIR_825_B1, "DIR-825-B1", "D-Link DIR-825 rev. B1",
  3814. + dir825b1_setup);
  3815. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-mzk-w04nu.c linux-2.6.34/arch/mips/ar71xx/mach-mzk-w04nu.c
  3816. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-mzk-w04nu.c 1970-01-01 01:00:00.000000000 +0100
  3817. +++ linux-2.6.34/arch/mips/ar71xx/mach-mzk-w04nu.c 2010-05-25 18:46:05.603464127 +0200
  3818. @@ -0,0 +1,165 @@
  3819. +/*
  3820. + * Planex MZK-W04NU board support
  3821. + *
  3822. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  3823. + *
  3824. + * This program is free software; you can redistribute it and/or modify it
  3825. + * under the terms of the GNU General Public License version 2 as published
  3826. + * by the Free Software Foundation.
  3827. + */
  3828. +
  3829. +#include <linux/mtd/mtd.h>
  3830. +#include <linux/mtd/partitions.h>
  3831. +
  3832. +#include <asm/mach-ar71xx/ar71xx.h>
  3833. +
  3834. +#include "machtype.h"
  3835. +#include "devices.h"
  3836. +#include "dev-ar913x-wmac.h"
  3837. +#include "dev-gpio-buttons.h"
  3838. +#include "dev-leds-gpio.h"
  3839. +#include "dev-m25p80.h"
  3840. +#include "dev-usb.h"
  3841. +
  3842. +#define MZK_W04NU_GPIO_LED_USB 0
  3843. +#define MZK_W04NU_GPIO_LED_STATUS 1
  3844. +#define MZK_W04NU_GPIO_LED_WPS 3
  3845. +#define MZK_W04NU_GPIO_LED_WLAN 6
  3846. +#define MZK_W04NU_GPIO_LED_AP 15
  3847. +#define MZK_W04NU_GPIO_LED_ROUTER 16
  3848. +
  3849. +#define MZK_W04NU_GPIO_BTN_APROUTER 5
  3850. +#define MZK_W04NU_GPIO_BTN_WPS 12
  3851. +#define MZK_W04NU_GPIO_BTN_RESET 21
  3852. +
  3853. +#define MZK_W04NU_BUTTONS_POLL_INTERVAL 20
  3854. +
  3855. +#ifdef CONFIG_MTD_PARTITIONS
  3856. +static struct mtd_partition mzk_w04nu_partitions[] = {
  3857. + {
  3858. + .name = "u-boot",
  3859. + .offset = 0,
  3860. + .size = 0x040000,
  3861. + .mask_flags = MTD_WRITEABLE,
  3862. + } , {
  3863. + .name = "u-boot-env",
  3864. + .offset = 0x040000,
  3865. + .size = 0x010000,
  3866. + } , {
  3867. + .name = "kernel",
  3868. + .offset = 0x050000,
  3869. + .size = 0x160000,
  3870. + } , {
  3871. + .name = "rootfs",
  3872. + .offset = 0x1b0000,
  3873. + .size = 0x630000,
  3874. + } , {
  3875. + .name = "art",
  3876. + .offset = 0x7e0000,
  3877. + .size = 0x020000,
  3878. + .mask_flags = MTD_WRITEABLE,
  3879. + } , {
  3880. + .name = "firmware",
  3881. + .offset = 0x050000,
  3882. + .size = 0x790000,
  3883. + }
  3884. +};
  3885. +#endif /* CONFIG_MTD_PARTITIONS */
  3886. +
  3887. +static struct flash_platform_data mzk_w04nu_flash_data = {
  3888. +#ifdef CONFIG_MTD_PARTITIONS
  3889. + .parts = mzk_w04nu_partitions,
  3890. + .nr_parts = ARRAY_SIZE(mzk_w04nu_partitions),
  3891. +#endif
  3892. +};
  3893. +
  3894. +static struct gpio_led mzk_w04nu_leds_gpio[] __initdata = {
  3895. + {
  3896. + .name = "mzk-w04nu:green:status",
  3897. + .gpio = MZK_W04NU_GPIO_LED_STATUS,
  3898. + .active_low = 1,
  3899. + }, {
  3900. + .name = "mzk-w04nu:blue:wps",
  3901. + .gpio = MZK_W04NU_GPIO_LED_WPS,
  3902. + .active_low = 1,
  3903. + }, {
  3904. + .name = "mzk-w04nu:green:wlan",
  3905. + .gpio = MZK_W04NU_GPIO_LED_WLAN,
  3906. + .active_low = 1,
  3907. + }, {
  3908. + .name = "mzk-w04nu:green:usb",
  3909. + .gpio = MZK_W04NU_GPIO_LED_USB,
  3910. + .active_low = 1,
  3911. + }, {
  3912. + .name = "mzk-w04nu:green:ap",
  3913. + .gpio = MZK_W04NU_GPIO_LED_AP,
  3914. + .active_low = 1,
  3915. + }, {
  3916. + .name = "mzk-w04nu:green:router",
  3917. + .gpio = MZK_W04NU_GPIO_LED_ROUTER,
  3918. + .active_low = 1,
  3919. + }
  3920. +};
  3921. +
  3922. +static struct gpio_button mzk_w04nu_gpio_buttons[] __initdata = {
  3923. + {
  3924. + .desc = "reset",
  3925. + .type = EV_KEY,
  3926. + .code = KEY_RESTART,
  3927. + .threshold = 3,
  3928. + .gpio = MZK_W04NU_GPIO_BTN_RESET,
  3929. + .active_low = 1,
  3930. + }, {
  3931. + .desc = "wps",
  3932. + .type = EV_KEY,
  3933. + .code = KEY_WPS_BUTTON,
  3934. + .threshold = 3,
  3935. + .gpio = MZK_W04NU_GPIO_BTN_WPS,
  3936. + .active_low = 1,
  3937. + }, {
  3938. + .desc = "aprouter",
  3939. + .type = EV_KEY,
  3940. + .code = BTN_2,
  3941. + .threshold = 3,
  3942. + .gpio = MZK_W04NU_GPIO_BTN_APROUTER,
  3943. + .active_low = 0,
  3944. + }
  3945. +};
  3946. +
  3947. +#define MZK_W04NU_WAN_PHYMASK BIT(4)
  3948. +#define MZK_W04NU_MDIO_MASK (~MZK_W04NU_WAN_PHYMASK)
  3949. +
  3950. +static void __init mzk_w04nu_setup(void)
  3951. +{
  3952. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  3953. +
  3954. + ar71xx_set_mac_base(eeprom);
  3955. +
  3956. + ar71xx_add_device_mdio(MZK_W04NU_MDIO_MASK);
  3957. +
  3958. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3959. + ar71xx_eth0_data.speed = SPEED_100;
  3960. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  3961. + ar71xx_eth0_data.has_ar8216 = 1;
  3962. +
  3963. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  3964. + ar71xx_eth1_data.phy_mask = MZK_W04NU_WAN_PHYMASK;
  3965. +
  3966. + ar71xx_add_device_eth(0);
  3967. + ar71xx_add_device_eth(1);
  3968. +
  3969. + ar71xx_add_device_m25p80(&mzk_w04nu_flash_data);
  3970. +
  3971. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w04nu_leds_gpio),
  3972. + mzk_w04nu_leds_gpio);
  3973. +
  3974. + ar71xx_add_device_gpio_buttons(-1, MZK_W04NU_BUTTONS_POLL_INTERVAL,
  3975. + ARRAY_SIZE(mzk_w04nu_gpio_buttons),
  3976. + mzk_w04nu_gpio_buttons);
  3977. + ar71xx_add_device_usb();
  3978. +
  3979. + ar913x_add_device_wmac(eeprom, NULL);
  3980. +}
  3981. +
  3982. +MIPS_MACHINE(AR71XX_MACH_MZK_W04NU, "MZK-W04NU", "Planex MZK-W04NU",
  3983. + mzk_w04nu_setup);
  3984. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-mzk-w300nh.c linux-2.6.34/arch/mips/ar71xx/mach-mzk-w300nh.c
  3985. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-mzk-w300nh.c 1970-01-01 01:00:00.000000000 +0100
  3986. +++ linux-2.6.34/arch/mips/ar71xx/mach-mzk-w300nh.c 2010-05-25 18:46:05.666212661 +0200
  3987. @@ -0,0 +1,158 @@
  3988. +/*
  3989. + * Planex MZK-W300NH board support
  3990. + *
  3991. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  3992. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  3993. + *
  3994. + * This program is free software; you can redistribute it and/or modify it
  3995. + * under the terms of the GNU General Public License version 2 as published
  3996. + * by the Free Software Foundation.
  3997. + */
  3998. +
  3999. +#include <linux/mtd/mtd.h>
  4000. +#include <linux/mtd/partitions.h>
  4001. +
  4002. +#include <asm/mach-ar71xx/ar71xx.h>
  4003. +
  4004. +#include "machtype.h"
  4005. +#include "devices.h"
  4006. +#include "dev-m25p80.h"
  4007. +#include "dev-ar913x-wmac.h"
  4008. +#include "dev-gpio-buttons.h"
  4009. +#include "dev-leds-gpio.h"
  4010. +
  4011. +#define MZK_W300NH_GPIO_LED_STATUS 1
  4012. +#define MZK_W300NH_GPIO_LED_WPS 3
  4013. +#define MZK_W300NH_GPIO_LED_WLAN 6
  4014. +#define MZK_W300NH_GPIO_LED_AP 15
  4015. +#define MZK_W300NH_GPIO_LED_ROUTER 16
  4016. +
  4017. +#define MZK_W300NH_GPIO_BTN_APROUTER 5
  4018. +#define MZK_W300NH_GPIO_BTN_WPS 12
  4019. +#define MZK_W300NH_GPIO_BTN_RESET 21
  4020. +
  4021. +#define MZK_W04NU_BUTTONS_POLL_INTERVAL 20
  4022. +
  4023. +#ifdef CONFIG_MTD_PARTITIONS
  4024. +static struct mtd_partition mzk_w300nh_partitions[] = {
  4025. + {
  4026. + .name = "u-boot",
  4027. + .offset = 0,
  4028. + .size = 0x040000,
  4029. + .mask_flags = MTD_WRITEABLE,
  4030. + } , {
  4031. + .name = "u-boot-env",
  4032. + .offset = 0x040000,
  4033. + .size = 0x010000,
  4034. + } , {
  4035. + .name = "kernel",
  4036. + .offset = 0x050000,
  4037. + .size = 0x160000,
  4038. + } , {
  4039. + .name = "rootfs",
  4040. + .offset = 0x1b0000,
  4041. + .size = 0x630000,
  4042. + } , {
  4043. + .name = "art",
  4044. + .offset = 0x7e0000,
  4045. + .size = 0x020000,
  4046. + .mask_flags = MTD_WRITEABLE,
  4047. + } , {
  4048. + .name = "firmware",
  4049. + .offset = 0x050000,
  4050. + .size = 0x790000,
  4051. + }
  4052. +};
  4053. +#endif /* CONFIG_MTD_PARTITIONS */
  4054. +
  4055. +static struct flash_platform_data mzk_w300nh_flash_data = {
  4056. +#ifdef CONFIG_MTD_PARTITIONS
  4057. + .parts = mzk_w300nh_partitions,
  4058. + .nr_parts = ARRAY_SIZE(mzk_w300nh_partitions),
  4059. +#endif
  4060. +};
  4061. +
  4062. +static struct gpio_led mzk_w300nh_leds_gpio[] __initdata = {
  4063. + {
  4064. + .name = "mzk-w300nh:green:status",
  4065. + .gpio = MZK_W300NH_GPIO_LED_STATUS,
  4066. + .active_low = 1,
  4067. + }, {
  4068. + .name = "mzk-w300nh:blue:wps",
  4069. + .gpio = MZK_W300NH_GPIO_LED_WPS,
  4070. + .active_low = 1,
  4071. + }, {
  4072. + .name = "mzk-w300nh:green:wlan",
  4073. + .gpio = MZK_W300NH_GPIO_LED_WLAN,
  4074. + .active_low = 1,
  4075. + }, {
  4076. + .name = "mzk-w300nh:green:ap",
  4077. + .gpio = MZK_W300NH_GPIO_LED_AP,
  4078. + .active_low = 1,
  4079. + }, {
  4080. + .name = "mzk-w300nh:green:router",
  4081. + .gpio = MZK_W300NH_GPIO_LED_ROUTER,
  4082. + .active_low = 1,
  4083. + }
  4084. +};
  4085. +
  4086. +static struct gpio_button mzk_w300nh_gpio_buttons[] __initdata = {
  4087. + {
  4088. + .desc = "reset",
  4089. + .type = EV_KEY,
  4090. + .code = KEY_RESTART,
  4091. + .threshold = 3,
  4092. + .gpio = MZK_W300NH_GPIO_BTN_RESET,
  4093. + .active_low = 1,
  4094. + }, {
  4095. + .desc = "wps",
  4096. + .type = EV_KEY,
  4097. + .code = KEY_WPS_BUTTON,
  4098. + .threshold = 3,
  4099. + .gpio = MZK_W300NH_GPIO_BTN_WPS,
  4100. + .active_low = 1,
  4101. + }, {
  4102. + .desc = "aprouter",
  4103. + .type = EV_KEY,
  4104. + .code = BTN_2,
  4105. + .threshold = 3,
  4106. + .gpio = MZK_W300NH_GPIO_BTN_APROUTER,
  4107. + .active_low = 0,
  4108. + }
  4109. +};
  4110. +
  4111. +#define MZK_W300NH_WAN_PHYMASK BIT(4)
  4112. +#define MZK_W300NH_MDIO_MASK (~MZK_W300NH_WAN_PHYMASK)
  4113. +
  4114. +static void __init mzk_w300nh_setup(void)
  4115. +{
  4116. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  4117. +
  4118. + ar71xx_set_mac_base(eeprom);
  4119. +
  4120. + ar71xx_add_device_mdio(MZK_W300NH_MDIO_MASK);
  4121. +
  4122. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4123. + ar71xx_eth0_data.speed = SPEED_100;
  4124. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4125. + ar71xx_eth0_data.has_ar8216 = 1;
  4126. +
  4127. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4128. + ar71xx_eth1_data.phy_mask = MZK_W300NH_WAN_PHYMASK;
  4129. +
  4130. + ar71xx_add_device_eth(0);
  4131. + ar71xx_add_device_eth(1);
  4132. +
  4133. + ar71xx_add_device_m25p80(&mzk_w300nh_flash_data);
  4134. +
  4135. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w300nh_leds_gpio),
  4136. + mzk_w300nh_leds_gpio);
  4137. +
  4138. + ar71xx_add_device_gpio_buttons(-1, MZK_W04NU_BUTTONS_POLL_INTERVAL,
  4139. + ARRAY_SIZE(mzk_w300nh_gpio_buttons),
  4140. + mzk_w300nh_gpio_buttons);
  4141. + ar913x_add_device_wmac(eeprom, NULL);
  4142. +}
  4143. +
  4144. +MIPS_MACHINE(AR71XX_MACH_MZK_W300NH, "MZK-W300NH", "Planex MZK-W300NH",
  4145. + mzk_w300nh_setup);
  4146. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-nbg460n.c linux-2.6.34/arch/mips/ar71xx/mach-nbg460n.c
  4147. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-nbg460n.c 1970-01-01 01:00:00.000000000 +0100
  4148. +++ linux-2.6.34/arch/mips/ar71xx/mach-nbg460n.c 2010-05-25 18:46:05.721448622 +0200
  4149. @@ -0,0 +1,222 @@
  4150. +/*
  4151. + * Zyxel NBG 460N/550N/550NH board support
  4152. + *
  4153. + * Copyright (C) 2010 Michael Kurz <michi.kurz@googlemail.com>
  4154. + *
  4155. + * based on mach-tl-wr1043nd.c
  4156. + *
  4157. + * This program is free software; you can redistribute it and/or modify it
  4158. + * under the terms of the GNU General Public License version 2 as published
  4159. + * by the Free Software Foundation.
  4160. + */
  4161. +
  4162. +#include <linux/platform_device.h>
  4163. +#include <linux/mtd/mtd.h>
  4164. +#include <linux/mtd/partitions.h>
  4165. +#include <linux/delay.h>
  4166. +#include <linux/rtl8366s.h>
  4167. +
  4168. +#include <linux/i2c.h>
  4169. +#include <linux/i2c-algo-bit.h>
  4170. +#include <linux/i2c-gpio.h>
  4171. +
  4172. +#include <asm/mach-ar71xx/ar71xx.h>
  4173. +
  4174. +#include "machtype.h"
  4175. +#include "devices.h"
  4176. +#include "dev-m25p80.h"
  4177. +#include "dev-ar913x-wmac.h"
  4178. +#include "dev-gpio-buttons.h"
  4179. +#include "dev-leds-gpio.h"
  4180. +
  4181. +/* LEDs */
  4182. +#define NBG460N_GPIO_LED_WPS 3
  4183. +#define NBG460N_GPIO_LED_WAN 6
  4184. +#define NBG460N_GPIO_LED_POWER 14
  4185. +#define NBG460N_GPIO_LED_WLAN 15
  4186. +
  4187. +/* Buttons */
  4188. +#define NBG460N_GPIO_BTN_WPS 12
  4189. +#define NBG460N_GPIO_BTN_RESET 21
  4190. +#define NBG460N_BUTTONS_POLL_INTERVAL 20
  4191. +
  4192. +/* RTC chip PCF8563 I2C interface */
  4193. +#define NBG460N_GPIO_PCF8563_SDA 8
  4194. +#define NBG460N_GPIO_PCF8563_SCK 7
  4195. +
  4196. +/* Switch configuration I2C interface */
  4197. +#define NBG460N_GPIO_RTL8366_SDA 16
  4198. +#define NBG460N_GPIO_RTL8366_SCK 18
  4199. +
  4200. +#ifdef CONFIG_MTD_PARTITIONS
  4201. +static struct mtd_partition nbg460n_partitions[] = {
  4202. + {
  4203. + .name = "Bootbase",
  4204. + .offset = 0,
  4205. + .size = 0x010000,
  4206. + .mask_flags = MTD_WRITEABLE,
  4207. + } , {
  4208. + .name = "U-Boot Config",
  4209. + .offset = 0x010000,
  4210. + .size = 0x030000,
  4211. + } , {
  4212. + .name = "U-Boot",
  4213. + .offset = 0x040000,
  4214. + .size = 0x030000,
  4215. + } , {
  4216. + .name = "linux",
  4217. + .offset = 0x070000,
  4218. + .size = 0x0e0000,
  4219. + } , {
  4220. + .name = "rootfs",
  4221. + .offset = 0x150000,
  4222. + .size = 0x2a0000,
  4223. + } , {
  4224. + .name = "CalibData",
  4225. + .offset = 0x3f0000,
  4226. + .size = 0x010000,
  4227. + .mask_flags = MTD_WRITEABLE,
  4228. + } , {
  4229. + .name = "firmware",
  4230. + .offset = 0x070000,
  4231. + .size = 0x380000,
  4232. + }
  4233. +};
  4234. +#endif /* CONFIG_MTD_PARTITIONS */
  4235. +
  4236. +static struct flash_platform_data nbg460n_flash_data = {
  4237. +#ifdef CONFIG_MTD_PARTITIONS
  4238. + .parts = nbg460n_partitions,
  4239. + .nr_parts = ARRAY_SIZE(nbg460n_partitions),
  4240. +#endif
  4241. +};
  4242. +
  4243. +static struct gpio_led nbg460n_leds_gpio[] __initdata = {
  4244. + {
  4245. + .name = "nbg460n:green:power",
  4246. + .gpio = NBG460N_GPIO_LED_POWER,
  4247. + .active_low = 0,
  4248. + .default_trigger = "default-on",
  4249. + }, {
  4250. + .name = "nbg460n:green:wps",
  4251. + .gpio = NBG460N_GPIO_LED_WPS,
  4252. + .active_low = 0,
  4253. + }, {
  4254. + .name = "nbg460n:green:wlan",
  4255. + .gpio = NBG460N_GPIO_LED_WLAN,
  4256. + .active_low = 0,
  4257. + }, {
  4258. + /* Not really for controlling the LED,
  4259. + when set low the LED blinks uncontrollable */
  4260. + .name = "nbg460n:green:wan",
  4261. + .gpio = NBG460N_GPIO_LED_WAN,
  4262. + .active_low = 0,
  4263. + }
  4264. +};
  4265. +
  4266. +static struct gpio_button nbg460n_gpio_buttons[] __initdata = {
  4267. + {
  4268. + .desc = "reset",
  4269. + .type = EV_KEY,
  4270. + .code = KEY_RESTART,
  4271. + .threshold = 3,
  4272. + .gpio = NBG460N_GPIO_BTN_RESET,
  4273. + .active_low = 1,
  4274. + }, {
  4275. + .desc = "wps",
  4276. + .type = EV_KEY,
  4277. + .code = KEY_WPS_BUTTON,
  4278. + .threshold = 3,
  4279. + .gpio = NBG460N_GPIO_BTN_WPS,
  4280. + .active_low = 1,
  4281. + }
  4282. +};
  4283. +
  4284. +static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
  4285. + .sda_pin = NBG460N_GPIO_PCF8563_SDA,
  4286. + .scl_pin = NBG460N_GPIO_PCF8563_SCK,
  4287. + .udelay = 10,
  4288. +};
  4289. +
  4290. +static struct platform_device nbg460n_i2c_device = {
  4291. + .name = "i2c-gpio",
  4292. + .id = -1,
  4293. + .num_resources = 0,
  4294. + .resource = NULL,
  4295. + .dev = {
  4296. + .platform_data = &nbg460n_i2c_device_platdata,
  4297. + },
  4298. +};
  4299. +
  4300. +static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
  4301. + {
  4302. + I2C_BOARD_INFO("pcf8563", 0x51),
  4303. + },
  4304. +};
  4305. +
  4306. +static void __devinit nbg460n_i2c_init(void)
  4307. +{
  4308. + /* The gpio interface */
  4309. + platform_device_register(&nbg460n_i2c_device);
  4310. + /* I2C devices */
  4311. + i2c_register_board_info(0, nbg460n_i2c_devs,
  4312. + ARRAY_SIZE(nbg460n_i2c_devs));
  4313. +}
  4314. +
  4315. +
  4316. +static struct rtl8366s_platform_data nbg460n_rtl8366s_data = {
  4317. + .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
  4318. + .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
  4319. +};
  4320. +
  4321. +static struct platform_device nbg460n_rtl8366s_device = {
  4322. + .name = RTL8366S_DRIVER_NAME,
  4323. + .id = -1,
  4324. + .dev = {
  4325. + .platform_data = &nbg460n_rtl8366s_data,
  4326. + }
  4327. +};
  4328. +
  4329. +static void __init nbg460n_setup(void)
  4330. +{
  4331. + /* end of bootloader sector contains mac address*/
  4332. + u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
  4333. + /* last sector contains wlan calib data */
  4334. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  4335. +
  4336. + ar71xx_set_mac_base(mac);
  4337. +
  4338. + /* LAN Port */
  4339. + ar71xx_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  4340. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4341. + ar71xx_eth0_data.speed = SPEED_1000;
  4342. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4343. +
  4344. + /* WAN Port */
  4345. + ar71xx_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  4346. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4347. + ar71xx_eth1_data.phy_mask = 0x10;
  4348. +
  4349. + ar71xx_add_device_eth(0);
  4350. + ar71xx_add_device_eth(1);
  4351. +
  4352. + /* register the switch phy */
  4353. + platform_device_register(&nbg460n_rtl8366s_device);
  4354. +
  4355. + /* register flash */
  4356. + ar71xx_add_device_m25p80(&nbg460n_flash_data);
  4357. +
  4358. + ar913x_add_device_wmac(eeprom, mac);
  4359. +
  4360. + /* register RTC chip */
  4361. + nbg460n_i2c_init();
  4362. +
  4363. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
  4364. + nbg460n_leds_gpio);
  4365. +
  4366. + ar71xx_add_device_gpio_buttons(-1, NBG460N_BUTTONS_POLL_INTERVAL,
  4367. + ARRAY_SIZE(nbg460n_gpio_buttons),
  4368. + nbg460n_gpio_buttons);
  4369. +}
  4370. +
  4371. +MIPS_MACHINE(AR71XX_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH", nbg460n_setup);
  4372. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-pb42.c linux-2.6.34/arch/mips/ar71xx/mach-pb42.c
  4373. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-pb42.c 1970-01-01 01:00:00.000000000 +0100
  4374. +++ linux-2.6.34/arch/mips/ar71xx/mach-pb42.c 2010-05-25 18:46:05.763464059 +0200
  4375. @@ -0,0 +1,71 @@
  4376. +/*
  4377. + * Atheros PB42 board support
  4378. + *
  4379. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4380. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4381. + *
  4382. + * This program is free software; you can redistribute it and/or modify it
  4383. + * under the terms of the GNU General Public License version 2 as published
  4384. + * by the Free Software Foundation.
  4385. + */
  4386. +
  4387. +#include <asm/mach-ar71xx/ar71xx.h>
  4388. +
  4389. +#include "machtype.h"
  4390. +#include "devices.h"
  4391. +#include "dev-m25p80.h"
  4392. +#include "dev-gpio-buttons.h"
  4393. +#include "dev-pb42-pci.h"
  4394. +#include "dev-usb.h"
  4395. +
  4396. +#define PB42_BUTTONS_POLL_INTERVAL 20
  4397. +
  4398. +#define PB42_GPIO_BTN_SW4 8
  4399. +#define PB42_GPIO_BTN_SW5 3
  4400. +
  4401. +static struct gpio_button pb42_gpio_buttons[] __initdata = {
  4402. + {
  4403. + .desc = "sw4",
  4404. + .type = EV_KEY,
  4405. + .code = BTN_0,
  4406. + .threshold = 3,
  4407. + .gpio = PB42_GPIO_BTN_SW4,
  4408. + .active_low = 1,
  4409. + } , {
  4410. + .desc = "sw5",
  4411. + .type = EV_KEY,
  4412. + .code = BTN_1,
  4413. + .threshold = 3,
  4414. + .gpio = PB42_GPIO_BTN_SW5,
  4415. + .active_low = 1,
  4416. + }
  4417. +};
  4418. +
  4419. +#define PB42_WAN_PHYMASK BIT(20)
  4420. +#define PB42_LAN_PHYMASK (BIT(16) | BIT(17) | BIT(18) | BIT(19))
  4421. +#define PB42_MDIO_PHYMASK (PB42_LAN_PHYMASK | PB42_WAN_PHYMASK)
  4422. +
  4423. +static void __init pb42_init(void)
  4424. +{
  4425. + ar71xx_add_device_m25p80(NULL);
  4426. +
  4427. + ar71xx_add_device_mdio(~PB42_MDIO_PHYMASK);
  4428. +
  4429. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4430. + ar71xx_eth0_data.phy_mask = PB42_WAN_PHYMASK;
  4431. +
  4432. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4433. + ar71xx_eth1_data.speed = SPEED_100;
  4434. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4435. +
  4436. + ar71xx_add_device_eth(0);
  4437. + ar71xx_add_device_eth(1);
  4438. +
  4439. + ar71xx_add_device_gpio_buttons(-1, PB42_BUTTONS_POLL_INTERVAL,
  4440. + ARRAY_SIZE(pb42_gpio_buttons),
  4441. + pb42_gpio_buttons);
  4442. +
  4443. + pb42_pci_init();
  4444. +}
  4445. +
  4446. +MIPS_MACHINE(AR71XX_MACH_PB42, "PB42", "Atheros PB42", pb42_init);
  4447. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-pb44.c linux-2.6.34/arch/mips/ar71xx/mach-pb44.c
  4448. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-pb44.c 1970-01-01 01:00:00.000000000 +0100
  4449. +++ linux-2.6.34/arch/mips/ar71xx/mach-pb44.c 2010-05-25 18:46:05.802223137 +0200
  4450. @@ -0,0 +1,207 @@
  4451. +/*
  4452. + * Atheros PB44 board support
  4453. + *
  4454. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  4455. + *
  4456. + * This program is free software; you can redistribute it and/or modify it
  4457. + * under the terms of the GNU General Public License version 2 as published
  4458. + * by the Free Software Foundation.
  4459. + */
  4460. +
  4461. +#include <linux/init.h>
  4462. +#include <linux/bitops.h>
  4463. +#include <linux/delay.h>
  4464. +#include <linux/platform_device.h>
  4465. +#include <linux/spi/spi.h>
  4466. +#include <linux/spi/flash.h>
  4467. +#include <linux/spi/vsc7385.h>
  4468. +#include <linux/i2c.h>
  4469. +#include <linux/i2c-gpio.h>
  4470. +#include <linux/i2c/pcf857x.h>
  4471. +
  4472. +#include <asm/mach-ar71xx/ar71xx.h>
  4473. +
  4474. +#include "machtype.h"
  4475. +#include "devices.h"
  4476. +#include "dev-pb42-pci.h"
  4477. +#include "dev-gpio-buttons.h"
  4478. +#include "dev-leds-gpio.h"
  4479. +#include "dev-usb.h"
  4480. +
  4481. +#define PB44_PCF8757_VSC7395_CS 0
  4482. +#define PB44_PCF8757_STEREO_CS 1
  4483. +#define PB44_PCF8757_SLIC_CS0 2
  4484. +#define PB44_PCF8757_SLIC_TEST 3
  4485. +#define PB44_PCF8757_SLIC_INT0 4
  4486. +#define PB44_PCF8757_SLIC_INT1 5
  4487. +#define PB44_PCF8757_SW_RESET 6
  4488. +#define PB44_PCF8757_SW_JUMP 8
  4489. +#define PB44_PCF8757_LED_JUMP1 9
  4490. +#define PB44_PCF8757_LED_JUMP2 10
  4491. +#define PB44_PCF8757_TP24 11
  4492. +#define PB44_PCF8757_TP25 12
  4493. +#define PB44_PCF8757_TP26 13
  4494. +#define PB44_PCF8757_TP27 14
  4495. +#define PB44_PCF8757_TP28 15
  4496. +
  4497. +#define PB44_GPIO_I2C_SCL 0
  4498. +#define PB44_GPIO_I2C_SDA 1
  4499. +
  4500. +#define PB44_GPIO_EXP_BASE 16
  4501. +#define PB44_GPIO_VSC7395_CS (PB44_GPIO_EXP_BASE + PB44_PCF8757_VSC7395_CS)
  4502. +#define PB44_GPIO_SW_RESET (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_RESET)
  4503. +#define PB44_GPIO_SW_JUMP (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_JUMP)
  4504. +#define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP1)
  4505. +#define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP2)
  4506. +
  4507. +static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
  4508. + .sda_pin = PB44_GPIO_I2C_SDA,
  4509. + .scl_pin = PB44_GPIO_I2C_SCL,
  4510. +};
  4511. +
  4512. +static struct platform_device pb44_i2c_gpio_device = {
  4513. + .name = "i2c-gpio",
  4514. + .id = 0,
  4515. + .dev = {
  4516. + .platform_data = &pb44_i2c_gpio_data,
  4517. + }
  4518. +};
  4519. +
  4520. +static struct pcf857x_platform_data pb44_pcf857x_data = {
  4521. + .gpio_base = PB44_GPIO_EXP_BASE,
  4522. +};
  4523. +
  4524. +static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
  4525. + {
  4526. + I2C_BOARD_INFO("pcf8575", 0x20),
  4527. + .platform_data = &pb44_pcf857x_data,
  4528. + },
  4529. +};
  4530. +
  4531. +static struct gpio_led pb44_leds_gpio[] __initdata = {
  4532. + {
  4533. + .name = "pb44:amber:jump1",
  4534. + .gpio = PB44_GPIO_LED_JUMP1,
  4535. + .active_low = 1,
  4536. + }, {
  4537. + .name = "pb44:green:jump2",
  4538. + .gpio = PB44_GPIO_LED_JUMP2,
  4539. + .active_low = 1,
  4540. + },
  4541. +};
  4542. +
  4543. +static struct gpio_button pb44_gpio_buttons[] __initdata = {
  4544. + {
  4545. + .desc = "soft_reset",
  4546. + .type = EV_KEY,
  4547. + .code = KEY_RESTART,
  4548. + .threshold = 3,
  4549. + .gpio = PB44_GPIO_SW_RESET,
  4550. + .active_low = 1,
  4551. + } , {
  4552. + .desc = "jumpstart",
  4553. + .type = EV_KEY,
  4554. + .code = KEY_WPS_BUTTON,
  4555. + .threshold = 3,
  4556. + .gpio = PB44_GPIO_SW_JUMP,
  4557. + .active_low = 1,
  4558. + }
  4559. +};
  4560. +
  4561. +static void pb44_vsc7395_reset(void)
  4562. +{
  4563. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  4564. + udelay(10);
  4565. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  4566. + mdelay(50);
  4567. +}
  4568. +
  4569. +static struct vsc7385_platform_data pb44_vsc7395_data = {
  4570. + .reset = pb44_vsc7395_reset,
  4571. + .ucode_name = "vsc7395_ucode_pb44.bin",
  4572. + .mac_cfg = {
  4573. + .tx_ipg = 6,
  4574. + .bit2 = 1,
  4575. + .clk_sel = 0,
  4576. + },
  4577. +};
  4578. +
  4579. +static struct spi_board_info pb44_spi_info[] = {
  4580. + {
  4581. + .bus_num = 0,
  4582. + .chip_select = 0,
  4583. + .max_speed_hz = 25000000,
  4584. + .modalias = "m25p80",
  4585. + }, {
  4586. + .bus_num = 0,
  4587. + .chip_select = 1,
  4588. + .max_speed_hz = 25000000,
  4589. + .modalias = "spi-vsc7385",
  4590. + .platform_data = &pb44_vsc7395_data,
  4591. + .controller_data = (void *) PB44_GPIO_VSC7395_CS,
  4592. + },
  4593. +};
  4594. +
  4595. +static struct resource pb44_spi_resources[] = {
  4596. + [0] = {
  4597. + .start = AR71XX_SPI_BASE,
  4598. + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  4599. + .flags = IORESOURCE_MEM,
  4600. + },
  4601. +};
  4602. +
  4603. +static struct ar71xx_spi_platform_data pb44_spi_data = {
  4604. + .bus_num = 0,
  4605. + .num_chipselect = 2,
  4606. +};
  4607. +
  4608. +static struct platform_device pb44_spi_device = {
  4609. + .name = "pb44-spi",
  4610. + .id = -1,
  4611. + .resource = pb44_spi_resources,
  4612. + .num_resources = ARRAY_SIZE(pb44_spi_resources),
  4613. + .dev = {
  4614. + .platform_data = &pb44_spi_data,
  4615. + },
  4616. +};
  4617. +
  4618. +#define PB44_WAN_PHYMASK BIT(0)
  4619. +#define PB44_LAN_PHYMASK 0
  4620. +#define PB44_MDIO_PHYMASK (PB44_LAN_PHYMASK | PB44_WAN_PHYMASK)
  4621. +
  4622. +static void __init pb44_init(void)
  4623. +{
  4624. + ar71xx_add_device_mdio(~PB44_MDIO_PHYMASK);
  4625. +
  4626. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4627. + ar71xx_eth0_data.phy_mask = PB44_WAN_PHYMASK;
  4628. +
  4629. + ar71xx_add_device_eth(0);
  4630. +
  4631. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  4632. + ar71xx_eth1_data.speed = SPEED_1000;
  4633. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4634. + ar71xx_eth1_pll_data.pll_1000 = 0x110000;
  4635. +
  4636. + ar71xx_add_device_eth(1);
  4637. +
  4638. + ar71xx_add_device_usb();
  4639. +
  4640. + pb42_pci_init();
  4641. +
  4642. + i2c_register_board_info(0, pb44_i2c_board_info,
  4643. + ARRAY_SIZE(pb44_i2c_board_info));
  4644. +
  4645. + platform_device_register(&pb44_i2c_gpio_device);
  4646. +
  4647. + spi_register_board_info(pb44_spi_info, ARRAY_SIZE(pb44_spi_info));
  4648. + platform_device_register(&pb44_spi_device);
  4649. +
  4650. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
  4651. + pb44_leds_gpio);
  4652. +
  4653. + ar71xx_add_device_gpio_buttons(-1, 20, ARRAY_SIZE(pb44_gpio_buttons),
  4654. + pb44_gpio_buttons);
  4655. +}
  4656. +
  4657. +MIPS_MACHINE(AR71XX_MACH_PB44, "PB44", "Atheros PB44", pb44_init);
  4658. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-pb92.c linux-2.6.34/arch/mips/ar71xx/mach-pb92.c
  4659. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-pb92.c 1970-01-01 01:00:00.000000000 +0100
  4660. +++ linux-2.6.34/arch/mips/ar71xx/mach-pb92.c 2010-05-25 18:46:05.830967287 +0200
  4661. @@ -0,0 +1,109 @@
  4662. +/*
  4663. + * Atheros PB92 board support
  4664. + *
  4665. + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  4666. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  4667. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4668. + *
  4669. + * This program is free software; you can redistribute it and/or modify it
  4670. + * under the terms of the GNU General Public License version 2 as published
  4671. + * by the Free Software Foundation.
  4672. + */
  4673. +
  4674. +#include <linux/mtd/mtd.h>
  4675. +#include <linux/mtd/partitions.h>
  4676. +#include <asm/mach-ar71xx/ar71xx.h>
  4677. +
  4678. +#include "machtype.h"
  4679. +#include "devices.h"
  4680. +#include "dev-m25p80.h"
  4681. +#include "dev-gpio-buttons.h"
  4682. +#include "dev-pb9x-pci.h"
  4683. +#include "dev-usb.h"
  4684. +
  4685. +#ifdef CONFIG_MTD_PARTITIONS
  4686. +static struct mtd_partition pb92_partitions[] = {
  4687. + {
  4688. + .name = "u-boot",
  4689. + .offset = 0,
  4690. + .size = 0x040000,
  4691. + .mask_flags = MTD_WRITEABLE,
  4692. + } , {
  4693. + .name = "u-boot-env",
  4694. + .offset = 0x040000,
  4695. + .size = 0x010000,
  4696. + } , {
  4697. + .name = "rootfs",
  4698. + .offset = 0x050000,
  4699. + .size = 0x2b0000,
  4700. + } , {
  4701. + .name = "uImage",
  4702. + .offset = 0x300000,
  4703. + .size = 0x0e0000,
  4704. + } , {
  4705. + .name = "ART",
  4706. + .offset = 0x3e0000,
  4707. + .size = 0x020000,
  4708. + .mask_flags = MTD_WRITEABLE,
  4709. + }
  4710. +};
  4711. +#endif /* CONFIG_MTD_PARTITIONS */
  4712. +
  4713. +static struct flash_platform_data pb92_flash_data = {
  4714. +#ifdef CONFIG_MTD_PARTITIONS
  4715. + .parts = pb92_partitions,
  4716. + .nr_parts = ARRAY_SIZE(pb92_partitions),
  4717. +#endif
  4718. +};
  4719. +
  4720. +
  4721. +#define PB92_BUTTONS_POLL_INTERVAL 20
  4722. +
  4723. +#define PB92_GPIO_BTN_SW4 8
  4724. +#define PB92_GPIO_BTN_SW5 3
  4725. +
  4726. +static struct gpio_button pb92_gpio_buttons[] __initdata = {
  4727. + {
  4728. + .desc = "sw4",
  4729. + .type = EV_KEY,
  4730. + .code = BTN_0,
  4731. + .threshold = 3,
  4732. + .gpio = PB92_GPIO_BTN_SW4,
  4733. + .active_low = 1,
  4734. + } , {
  4735. + .desc = "sw5",
  4736. + .type = EV_KEY,
  4737. + .code = BTN_1,
  4738. + .threshold = 3,
  4739. + .gpio = PB92_GPIO_BTN_SW5,
  4740. + .active_low = 1,
  4741. + }
  4742. +};
  4743. +
  4744. +static void __init pb92_init(void)
  4745. +{
  4746. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  4747. +
  4748. + ar71xx_set_mac_base(mac);
  4749. + ar71xx_add_device_m25p80(&pb92_flash_data);
  4750. +
  4751. + ar71xx_add_device_mdio(~0);
  4752. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4753. + ar71xx_eth0_data.speed = SPEED_1000;
  4754. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4755. +
  4756. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4757. + ar71xx_eth1_data.speed = SPEED_1000;
  4758. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  4759. +
  4760. + ar71xx_add_device_eth(0);
  4761. + ar71xx_add_device_eth(1);
  4762. +
  4763. + ar71xx_add_device_gpio_buttons(-1, PB92_BUTTONS_POLL_INTERVAL,
  4764. + ARRAY_SIZE(pb92_gpio_buttons),
  4765. + pb92_gpio_buttons);
  4766. +
  4767. + pb9x_pci_init();
  4768. +}
  4769. +
  4770. +MIPS_MACHINE(AR71XX_MACH_PB92, "PB92", "Atheros PB92", pb92_init);
  4771. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-rb4xx.c linux-2.6.34/arch/mips/ar71xx/mach-rb4xx.c
  4772. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-rb4xx.c 1970-01-01 01:00:00.000000000 +0100
  4773. +++ linux-2.6.34/arch/mips/ar71xx/mach-rb4xx.c 2010-05-25 18:46:05.873464062 +0200
  4774. @@ -0,0 +1,290 @@
  4775. +/*
  4776. + * MikroTik RouterBOARD 4xx series support
  4777. + *
  4778. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  4779. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  4780. + *
  4781. + * This program is free software; you can redistribute it and/or modify it
  4782. + * under the terms of the GNU General Public License version 2 as published
  4783. + * by the Free Software Foundation.
  4784. + */
  4785. +
  4786. +#include <linux/platform_device.h>
  4787. +#include <linux/irq.h>
  4788. +#include <linux/mmc/host.h>
  4789. +#include <linux/spi/spi.h>
  4790. +#include <linux/spi/flash.h>
  4791. +#include <linux/spi/mmc_spi.h>
  4792. +
  4793. +#include <asm/mach-ar71xx/ar71xx.h>
  4794. +#include <asm/mach-ar71xx/pci.h>
  4795. +
  4796. +#include "machtype.h"
  4797. +#include "devices.h"
  4798. +#include "dev-gpio-buttons.h"
  4799. +#include "dev-leds-gpio.h"
  4800. +#include "dev-usb.h"
  4801. +
  4802. +#define RB4XX_GPIO_USER_LED 4
  4803. +#define RB4XX_GPIO_RESET_SWITCH 7
  4804. +
  4805. +#define RB4XX_BUTTONS_POLL_INTERVAL 20
  4806. +
  4807. +static struct gpio_led rb4xx_leds_gpio[] __initdata = {
  4808. + {
  4809. + .name = "rb4xx:yellow:user",
  4810. + .gpio = RB4XX_GPIO_USER_LED,
  4811. + .active_low = 0,
  4812. + },
  4813. +};
  4814. +
  4815. +static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
  4816. + {
  4817. + .desc = "reset_switch",
  4818. + .type = EV_KEY,
  4819. + .code = KEY_RESTART,
  4820. + .threshold = 3,
  4821. + .gpio = RB4XX_GPIO_RESET_SWITCH,
  4822. + .active_low = 1,
  4823. + }
  4824. +};
  4825. +
  4826. +static struct platform_device rb4xx_nand_device = {
  4827. + .name = "rb4xx-nand",
  4828. + .id = -1,
  4829. +};
  4830. +
  4831. +static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
  4832. + {
  4833. + .slot = 0,
  4834. + .pin = 1,
  4835. + .irq = AR71XX_PCI_IRQ_DEV2,
  4836. + }, {
  4837. + .slot = 1,
  4838. + .pin = 1,
  4839. + .irq = AR71XX_PCI_IRQ_DEV0,
  4840. + }, {
  4841. + .slot = 1,
  4842. + .pin = 2,
  4843. + .irq = AR71XX_PCI_IRQ_DEV1,
  4844. + }, {
  4845. + .slot = 2,
  4846. + .pin = 1,
  4847. + .irq = AR71XX_PCI_IRQ_DEV1,
  4848. + }, {
  4849. + .slot = 3,
  4850. + .pin = 1,
  4851. + .irq = AR71XX_PCI_IRQ_DEV2,
  4852. + }
  4853. +};
  4854. +
  4855. +#if 0
  4856. +/*
  4857. + * SPI device support is experimental
  4858. + */
  4859. +static struct flash_platform_data rb4xx_flash_data = {
  4860. + .type = "pm25lv512",
  4861. +};
  4862. +
  4863. +static struct spi_board_info rb4xx_spi_info[] = {
  4864. + {
  4865. + .bus_num = 0,
  4866. + .chip_select = 0,
  4867. + .max_speed_hz = 25000000,
  4868. + .modalias = "m25p80",
  4869. + .platform_data = &rb4xx_flash_data,
  4870. + }
  4871. +};
  4872. +
  4873. +static struct mmc_spi_platform_data rb433_mmc_data = {
  4874. + .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  4875. +};
  4876. +
  4877. +static struct spi_board_info rb433_spi_info[] = {
  4878. + {
  4879. + .bus_num = 0,
  4880. + .chip_select = 0,
  4881. + .max_speed_hz = 25000000,
  4882. + .modalias = "m25p80",
  4883. + .platform_data = &rb433_flash_data,
  4884. + }, {
  4885. + .bus_num = 0,
  4886. + .chip_select = 2,
  4887. + .max_speed_hz = 25000000,
  4888. + .modalias = "mmc_spi",
  4889. + .platform_data = &rb433_mmc_data,
  4890. + }
  4891. +};
  4892. +
  4893. +static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
  4894. +{
  4895. + u32 ret;
  4896. +
  4897. + if (is_on == AR71XX_SPI_CS_INACTIVE) {
  4898. + ret = SPI_IOC_CS0 | SPI_IOC_CS1;
  4899. + } else {
  4900. + if (cs_high) {
  4901. + ret = SPI_IOC_CS0 | SPI_IOC_CS1;
  4902. + } else {
  4903. + if ((chip_select ^ 2) == 0)
  4904. + ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
  4905. + else
  4906. + ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
  4907. + }
  4908. + }
  4909. +
  4910. + return ret;
  4911. +}
  4912. +
  4913. +struct ar71xx_spi_platform_data rb433_spi_data = {
  4914. + .bus_num = 0,
  4915. + .num_chipselect = 3,
  4916. + .get_ioc_base = rb433_spi_get_ioc_base,
  4917. +};
  4918. +
  4919. +static void rb4xx_add_device_spi(void)
  4920. +{
  4921. + ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
  4922. +}
  4923. +
  4924. +static void rb433_add_device_spi(void)
  4925. +{
  4926. + ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
  4927. + ARRAY_SIZE(rb433_spi_info));
  4928. +}
  4929. +#else
  4930. +static inline void rb4xx_add_device_spi(void) {}
  4931. +static inline void rb433_add_device_spi(void) {}
  4932. +#endif
  4933. +
  4934. +static void __init rb4xx_generic_setup(void)
  4935. +{
  4936. + ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  4937. + AR71XX_GPIO_FUNC_SPI_CS2_EN);
  4938. +
  4939. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
  4940. + rb4xx_leds_gpio);
  4941. +
  4942. + ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
  4943. + ARRAY_SIZE(rb4xx_gpio_buttons),
  4944. + rb4xx_gpio_buttons);
  4945. +
  4946. + platform_device_register(&rb4xx_nand_device);
  4947. +}
  4948. +
  4949. +static void __init rb411_setup(void)
  4950. +{
  4951. + rb4xx_generic_setup();
  4952. + rb4xx_add_device_spi();
  4953. +
  4954. + ar71xx_add_device_mdio(0xfffffffc);
  4955. +
  4956. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4957. + ar71xx_eth0_data.phy_mask = 0x00000003;
  4958. +
  4959. + ar71xx_add_device_eth(0);
  4960. +
  4961. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  4962. +}
  4963. +
  4964. +MIPS_MACHINE(AR71XX_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
  4965. + rb411_setup);
  4966. +
  4967. +static void __init rb411u_setup(void)
  4968. +{
  4969. + rb411_setup();
  4970. + ar71xx_add_device_usb();
  4971. +}
  4972. +
  4973. +MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
  4974. + rb411u_setup);
  4975. +
  4976. +static void __init rb433_setup(void)
  4977. +{
  4978. + rb4xx_generic_setup();
  4979. + rb433_add_device_spi();
  4980. +
  4981. + ar71xx_add_device_mdio(0xffffffe9);
  4982. +
  4983. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  4984. + ar71xx_eth0_data.speed = SPEED_100;
  4985. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  4986. +
  4987. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  4988. + ar71xx_eth1_data.phy_mask = 0x00000010;
  4989. +
  4990. + ar71xx_add_device_eth(1);
  4991. + ar71xx_add_device_eth(0);
  4992. +
  4993. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  4994. +}
  4995. +
  4996. +MIPS_MACHINE(AR71XX_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
  4997. + rb433_setup);
  4998. +
  4999. +static void __init rb433u_setup(void)
  5000. +{
  5001. + rb433_setup();
  5002. + ar71xx_add_device_usb();
  5003. +}
  5004. +
  5005. +MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
  5006. + rb433u_setup);
  5007. +
  5008. +static void __init rb450_generic_setup(int gige)
  5009. +{
  5010. + rb4xx_generic_setup();
  5011. + rb4xx_add_device_spi();
  5012. +
  5013. + ar71xx_add_device_mdio(0xffffffe0);
  5014. +
  5015. + ar71xx_eth0_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
  5016. + ar71xx_eth0_data.phy_mask = (gige) ? (1 << 0) : 0;
  5017. + ar71xx_eth0_data.speed = (gige) ? SPEED_1000 : SPEED_100;
  5018. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5019. +
  5020. + ar71xx_eth1_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
  5021. + ar71xx_eth1_data.phy_mask = 0x00000010;
  5022. +
  5023. + ar71xx_add_device_eth(1);
  5024. + ar71xx_add_device_eth(0);
  5025. +}
  5026. +
  5027. +static void __init rb450_setup(void)
  5028. +{
  5029. + rb450_generic_setup(0);
  5030. +}
  5031. +
  5032. +MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
  5033. + rb450_setup);
  5034. +
  5035. +static void __init rb450g_setup(void)
  5036. +{
  5037. + rb450_generic_setup(1);
  5038. +}
  5039. +
  5040. +MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
  5041. + rb450g_setup);
  5042. +
  5043. +static void __init rb493_setup(void)
  5044. +{
  5045. + rb4xx_generic_setup();
  5046. + rb4xx_add_device_spi();
  5047. +
  5048. + ar71xx_add_device_mdio(0x3fffff00);
  5049. +
  5050. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  5051. + ar71xx_eth0_data.speed = SPEED_100;
  5052. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5053. +
  5054. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5055. + ar71xx_eth1_data.phy_mask = 0x00000001;
  5056. +
  5057. + ar71xx_add_device_eth(0);
  5058. + ar71xx_add_device_eth(1);
  5059. +
  5060. + ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  5061. +}
  5062. +
  5063. +MIPS_MACHINE(AR71XX_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",
  5064. + rb493_setup);
  5065. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-rb750.c linux-2.6.34/arch/mips/ar71xx/mach-rb750.c
  5066. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-rb750.c 1970-01-01 01:00:00.000000000 +0100
  5067. +++ linux-2.6.34/arch/mips/ar71xx/mach-rb750.c 2010-05-25 18:46:05.912223101 +0200
  5068. @@ -0,0 +1,133 @@
  5069. +/*
  5070. + * MikroTik RouterBOARD 750 support
  5071. + *
  5072. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  5073. + *
  5074. + * This program is free software; you can redistribute it and/or modify it
  5075. + * under the terms of the GNU General Public License version 2 as published
  5076. + * by the Free Software Foundation.
  5077. + */
  5078. +
  5079. +#include <linux/platform_device.h>
  5080. +#include <asm/mach-ar71xx/ar71xx.h>
  5081. +#include <asm/mach-ar71xx/mach-rb750.h>
  5082. +
  5083. +#include "machtype.h"
  5084. +#include "dev-ap91-eth.h"
  5085. +
  5086. +static struct rb750_led_data rb750_leds[] = {
  5087. + {
  5088. + .name = "rb750:green:act",
  5089. + .mask = RB750_LED_ACT,
  5090. + .active_low = 1,
  5091. + }, {
  5092. + .name = "rb750:green:port1",
  5093. + .mask = RB750_LED_PORT5,
  5094. + .active_low = 1,
  5095. + }, {
  5096. + .name = "rb750:green:port2",
  5097. + .mask = RB750_LED_PORT4,
  5098. + .active_low = 1,
  5099. + }, {
  5100. + .name = "rb750:green:port3",
  5101. + .mask = RB750_LED_PORT3,
  5102. + .active_low = 1,
  5103. + }, {
  5104. + .name = "rb750:green:port4",
  5105. + .mask = RB750_LED_PORT2,
  5106. + .active_low = 1,
  5107. + }, {
  5108. + .name = "rb750:green:port5",
  5109. + .mask = RB750_LED_PORT1,
  5110. + .active_low = 1,
  5111. + }
  5112. +};
  5113. +
  5114. +static struct rb750_led_platform_data rb750_leds_data = {
  5115. + .num_leds = ARRAY_SIZE(rb750_leds),
  5116. + .leds = rb750_leds,
  5117. +};
  5118. +
  5119. +static struct platform_device rb750_leds_device = {
  5120. + .name = "leds-rb750",
  5121. + .dev = {
  5122. + .platform_data = &rb750_leds_data,
  5123. + }
  5124. +};
  5125. +
  5126. +static const char *rb750_port_names[AP91_ETH_NUM_PORT_NAMES] __initdata = {
  5127. + "port5",
  5128. + "port4",
  5129. + "port3",
  5130. + "port2",
  5131. +};
  5132. +
  5133. +static struct platform_device rb750_nand_device = {
  5134. + .name = "rb750-nand",
  5135. + .id = -1,
  5136. +};
  5137. +
  5138. +int rb750_latch_change(u32 mask_clr, u32 mask_set)
  5139. +{
  5140. + static DEFINE_SPINLOCK(lock);
  5141. + static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
  5142. + static u32 latch_oe;
  5143. + static u32 latch_clr;
  5144. + unsigned long flags;
  5145. + u32 t;
  5146. + int ret = 0;
  5147. +
  5148. + spin_lock_irqsave(&lock, flags);
  5149. +
  5150. + if ((mask_clr & BIT(31)) != 0 &&
  5151. + (latch_set & RB750_LVC573_LE) == 0) {
  5152. + goto unlock;
  5153. + }
  5154. +
  5155. + latch_set = (latch_set | mask_set) & ~mask_clr;
  5156. + latch_clr = (latch_clr | mask_clr) & ~mask_set;
  5157. +
  5158. + if (latch_oe == 0)
  5159. + latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
  5160. +
  5161. + if (likely(latch_set & RB750_LVC573_LE)) {
  5162. + void __iomem *base = ar71xx_gpio_base;
  5163. +
  5164. + t = __raw_readl(base + GPIO_REG_OE);
  5165. + t |= mask_clr | latch_oe | mask_set;
  5166. +
  5167. + __raw_writel(t, base + GPIO_REG_OE);
  5168. + __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
  5169. + __raw_writel(latch_set, base + GPIO_REG_SET);
  5170. + } else if (mask_clr & RB750_LVC573_LE) {
  5171. + void __iomem *base = ar71xx_gpio_base;
  5172. +
  5173. + latch_oe = __raw_readl(base + GPIO_REG_OE);
  5174. + __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
  5175. + /* flush write */
  5176. + __raw_readl(base + GPIO_REG_CLEAR);
  5177. + }
  5178. +
  5179. + ret = 1;
  5180. +
  5181. + unlock:
  5182. + spin_unlock_irqrestore(&lock, flags);
  5183. + return ret;
  5184. +}
  5185. +EXPORT_SYMBOL_GPL(rb750_latch_change);
  5186. +
  5187. +static void __init rb750_setup(void)
  5188. +{
  5189. + ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  5190. + AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  5191. + AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  5192. + AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  5193. + AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  5194. +
  5195. + ap91_eth_init(NULL, rb750_port_names);
  5196. + platform_device_register(&rb750_leds_device);
  5197. + platform_device_register(&rb750_nand_device);
  5198. +}
  5199. +
  5200. +MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
  5201. + rb750_setup);
  5202. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-tew-632brp.c linux-2.6.34/arch/mips/ar71xx/mach-tew-632brp.c
  5203. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-tew-632brp.c 1970-01-01 01:00:00.000000000 +0100
  5204. +++ linux-2.6.34/arch/mips/ar71xx/mach-tew-632brp.c 2010-05-25 18:46:05.952223131 +0200
  5205. @@ -0,0 +1,149 @@
  5206. +/*
  5207. + * TrendNET TEW-632BRP board support
  5208. + *
  5209. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5210. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5211. + *
  5212. + * This program is free software; you can redistribute it and/or modify it
  5213. + * under the terms of the GNU General Public License version 2 as published
  5214. + * by the Free Software Foundation.
  5215. + */
  5216. +
  5217. +#include <linux/mtd/mtd.h>
  5218. +#include <linux/mtd/partitions.h>
  5219. +
  5220. +#include <asm/mach-ar71xx/ar71xx.h>
  5221. +
  5222. +#include "machtype.h"
  5223. +#include "devices.h"
  5224. +#include "dev-m25p80.h"
  5225. +#include "dev-ar913x-wmac.h"
  5226. +#include "dev-gpio-buttons.h"
  5227. +#include "dev-leds-gpio.h"
  5228. +#include "nvram.h"
  5229. +
  5230. +#define TEW_632BRP_GPIO_LED_STATUS 1
  5231. +#define TEW_632BRP_GPIO_LED_WPS 3
  5232. +#define TEW_632BRP_GPIO_LED_WLAN 6
  5233. +#define TEW_632BRP_GPIO_BTN_WPS 12
  5234. +#define TEW_632BRP_GPIO_BTN_RESET 21
  5235. +
  5236. +#define TEW_632BRP_BUTTONS_POLL_INTERVAL 20
  5237. +
  5238. +#define TEW_632BRP_CONFIG_ADDR 0x1f020000
  5239. +#define TEW_632BRP_CONFIG_SIZE 0x10000
  5240. +
  5241. +#ifdef CONFIG_MTD_PARTITIONS
  5242. +static struct mtd_partition tew_632brp_partitions[] = {
  5243. + {
  5244. + .name = "u-boot",
  5245. + .offset = 0,
  5246. + .size = 0x020000,
  5247. + .mask_flags = MTD_WRITEABLE,
  5248. + } , {
  5249. + .name = "config",
  5250. + .offset = 0x020000,
  5251. + .size = 0x010000,
  5252. + } , {
  5253. + .name = "kernel",
  5254. + .offset = 0x030000,
  5255. + .size = 0x0d0000,
  5256. + } , {
  5257. + .name = "rootfs",
  5258. + .offset = 0x100000,
  5259. + .size = 0x2f0000,
  5260. + } , {
  5261. + .name = "art",
  5262. + .offset = 0x3f0000,
  5263. + .size = 0x010000,
  5264. + .mask_flags = MTD_WRITEABLE,
  5265. + } , {
  5266. + .name = "firmware",
  5267. + .offset = 0x030000,
  5268. + .size = 0x3c0000,
  5269. + }
  5270. +};
  5271. +#endif /* CONFIG_MTD_PARTITIONS */
  5272. +
  5273. +static struct flash_platform_data tew_632brp_flash_data = {
  5274. +#ifdef CONFIG_MTD_PARTITIONS
  5275. + .parts = tew_632brp_partitions,
  5276. + .nr_parts = ARRAY_SIZE(tew_632brp_partitions),
  5277. +#endif
  5278. +};
  5279. +
  5280. +static struct gpio_led tew_632brp_leds_gpio[] __initdata = {
  5281. + {
  5282. + .name = "tew-632brp:green:status",
  5283. + .gpio = TEW_632BRP_GPIO_LED_STATUS,
  5284. + .active_low = 1,
  5285. + }, {
  5286. + .name = "tew-632brp:blue:wps",
  5287. + .gpio = TEW_632BRP_GPIO_LED_WPS,
  5288. + .active_low = 1,
  5289. + }, {
  5290. + .name = "tew-632brp:green:wlan",
  5291. + .gpio = TEW_632BRP_GPIO_LED_WLAN,
  5292. + .active_low = 1,
  5293. + }
  5294. +};
  5295. +
  5296. +static struct gpio_button tew_632brp_gpio_buttons[] __initdata = {
  5297. + {
  5298. + .desc = "reset",
  5299. + .type = EV_KEY,
  5300. + .code = KEY_RESTART,
  5301. + .threshold = 3,
  5302. + .gpio = TEW_632BRP_GPIO_BTN_RESET,
  5303. + }, {
  5304. + .desc = "wps",
  5305. + .type = EV_KEY,
  5306. + .code = KEY_WPS_BUTTON,
  5307. + .threshold = 3,
  5308. + .gpio = TEW_632BRP_GPIO_BTN_WPS,
  5309. + }
  5310. +};
  5311. +
  5312. +#define TEW_632BRP_LAN_PHYMASK BIT(0)
  5313. +#define TEW_632BRP_WAN_PHYMASK BIT(4)
  5314. +#define TEW_632BRP_MDIO_MASK (~(TEW_632BRP_LAN_PHYMASK | \
  5315. + TEW_632BRP_WAN_PHYMASK))
  5316. +
  5317. +static void __init tew_632brp_setup(void)
  5318. +{
  5319. + const char *config = (char *) KSEG1ADDR(TEW_632BRP_CONFIG_ADDR);
  5320. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5321. + u8 mac[6];
  5322. + u8 *wlan_mac = NULL;
  5323. +
  5324. + if (nvram_parse_mac_addr(config, TEW_632BRP_CONFIG_SIZE,
  5325. + "lan_mac=", mac) == 0) {
  5326. + ar71xx_set_mac_base(mac);
  5327. + wlan_mac = mac;
  5328. + }
  5329. +
  5330. + ar71xx_add_device_mdio(TEW_632BRP_MDIO_MASK);
  5331. +
  5332. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5333. + ar71xx_eth0_data.phy_mask = TEW_632BRP_LAN_PHYMASK;
  5334. +
  5335. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5336. + ar71xx_eth1_data.phy_mask = TEW_632BRP_WAN_PHYMASK;
  5337. +
  5338. + ar71xx_add_device_eth(0);
  5339. + ar71xx_add_device_eth(1);
  5340. +
  5341. + ar71xx_add_device_m25p80(&tew_632brp_flash_data);
  5342. +
  5343. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew_632brp_leds_gpio),
  5344. + tew_632brp_leds_gpio);
  5345. +
  5346. + ar71xx_add_device_gpio_buttons(-1, TEW_632BRP_BUTTONS_POLL_INTERVAL,
  5347. + ARRAY_SIZE(tew_632brp_gpio_buttons),
  5348. + tew_632brp_gpio_buttons);
  5349. +
  5350. + ar913x_add_device_wmac(eeprom, wlan_mac);
  5351. +}
  5352. +
  5353. +MIPS_MACHINE(AR71XX_MACH_TEW_632BRP, "TEW-632BRP", "TRENDnet TEW-632BRP",
  5354. + tew_632brp_setup);
  5355. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c linux-2.6.34/arch/mips/ar71xx/mach-tl-wr1043nd.c
  5356. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr1043nd.c 1970-01-01 01:00:00.000000000 +0100
  5357. +++ linux-2.6.34/arch/mips/ar71xx/mach-tl-wr1043nd.c 2010-05-25 18:46:05.990964132 +0200
  5358. @@ -0,0 +1,156 @@
  5359. +/*
  5360. + * TP-LINK TL-WR1043ND board support
  5361. + *
  5362. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5363. + *
  5364. + * This program is free software; you can redistribute it and/or modify it
  5365. + * under the terms of the GNU General Public License version 2 as published
  5366. + * by the Free Software Foundation.
  5367. + */
  5368. +
  5369. +#include <linux/mtd/mtd.h>
  5370. +#include <linux/mtd/partitions.h>
  5371. +#include <linux/platform_device.h>
  5372. +#include <linux/rtl8366rb.h>
  5373. +#include <asm/mach-ar71xx/ar71xx.h>
  5374. +
  5375. +#include "machtype.h"
  5376. +#include "devices.h"
  5377. +#include "dev-m25p80.h"
  5378. +#include "dev-ar913x-wmac.h"
  5379. +#include "dev-gpio-buttons.h"
  5380. +#include "dev-leds-gpio.h"
  5381. +#include "dev-usb.h"
  5382. +
  5383. +#define TL_WR1043ND_GPIO_LED_USB 1
  5384. +#define TL_WR1043ND_GPIO_LED_SYSTEM 2
  5385. +#define TL_WR1043ND_GPIO_LED_QSS 5
  5386. +#define TL_WR1043ND_GPIO_LED_WLAN 9
  5387. +
  5388. +#define TL_WR1043ND_GPIO_BTN_RESET 3
  5389. +#define TL_WR1043ND_GPIO_BTN_QSS 7
  5390. +
  5391. +#define TL_WR1043ND_GPIO_RTL8366_SDA 18
  5392. +#define TL_WR1043ND_GPIO_RTL8366_SCK 19
  5393. +
  5394. +#define TL_WR1043ND_BUTTONS_POLL_INTERVAL 20
  5395. +
  5396. +#ifdef CONFIG_MTD_PARTITIONS
  5397. +static struct mtd_partition tl_wr1043nd_partitions[] = {
  5398. + {
  5399. + .name = "u-boot",
  5400. + .offset = 0,
  5401. + .size = 0x020000,
  5402. + .mask_flags = MTD_WRITEABLE,
  5403. + } , {
  5404. + .name = "kernel",
  5405. + .offset = 0x020000,
  5406. + .size = 0x140000,
  5407. + } , {
  5408. + .name = "rootfs",
  5409. + .offset = 0x160000,
  5410. + .size = 0x690000,
  5411. + } , {
  5412. + .name = "art",
  5413. + .offset = 0x7f0000,
  5414. + .size = 0x010000,
  5415. + .mask_flags = MTD_WRITEABLE,
  5416. + } , {
  5417. + .name = "firmware",
  5418. + .offset = 0x020000,
  5419. + .size = 0x7d0000,
  5420. + }
  5421. +};
  5422. +#endif /* CONFIG_MTD_PARTITIONS */
  5423. +
  5424. +static struct flash_platform_data tl_wr1043nd_flash_data = {
  5425. +#ifdef CONFIG_MTD_PARTITIONS
  5426. + .parts = tl_wr1043nd_partitions,
  5427. + .nr_parts = ARRAY_SIZE(tl_wr1043nd_partitions),
  5428. +#endif
  5429. +};
  5430. +
  5431. +static struct gpio_led tl_wr1043nd_leds_gpio[] __initdata = {
  5432. + {
  5433. + .name = "tl-wr1043nd:green:usb",
  5434. + .gpio = TL_WR1043ND_GPIO_LED_USB,
  5435. + .active_low = 1,
  5436. + }, {
  5437. + .name = "tl-wr1043nd:green:system",
  5438. + .gpio = TL_WR1043ND_GPIO_LED_SYSTEM,
  5439. + .active_low = 1,
  5440. + }, {
  5441. + .name = "tl-wr1043nd:green:qss",
  5442. + .gpio = TL_WR1043ND_GPIO_LED_QSS,
  5443. + .active_low = 0,
  5444. + }, {
  5445. + .name = "tl-wr1043nd:green:wlan",
  5446. + .gpio = TL_WR1043ND_GPIO_LED_WLAN,
  5447. + .active_low = 1,
  5448. + }
  5449. +};
  5450. +
  5451. +static struct gpio_button tl_wr1043nd_gpio_buttons[] __initdata = {
  5452. + {
  5453. + .desc = "reset",
  5454. + .type = EV_KEY,
  5455. + .code = KEY_RESTART,
  5456. + .threshold = 3,
  5457. + .gpio = TL_WR1043ND_GPIO_BTN_RESET,
  5458. + .active_low = 1,
  5459. + }, {
  5460. + .desc = "qss",
  5461. + .type = EV_KEY,
  5462. + .code = KEY_WPS_BUTTON,
  5463. + .threshold = 3,
  5464. + .gpio = TL_WR1043ND_GPIO_BTN_QSS,
  5465. + .active_low = 1,
  5466. + }
  5467. +};
  5468. +
  5469. +static struct rtl8366rb_platform_data tl_wr1043nd_rtl8366rb_data = {
  5470. + .gpio_sda = TL_WR1043ND_GPIO_RTL8366_SDA,
  5471. + .gpio_sck = TL_WR1043ND_GPIO_RTL8366_SCK,
  5472. +};
  5473. +
  5474. +static struct platform_device tl_wr1043nd_rtl8366rb_device = {
  5475. + .name = RTL8366RB_DRIVER_NAME,
  5476. + .id = -1,
  5477. + .dev = {
  5478. + .platform_data = &tl_wr1043nd_rtl8366rb_data,
  5479. + }
  5480. +};
  5481. +
  5482. +static void __init tl_wr1043nd_setup(void)
  5483. +{
  5484. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5485. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5486. +
  5487. + ar71xx_set_mac_base(mac);
  5488. +
  5489. + ar71xx_eth0_data.mii_bus_dev = &tl_wr1043nd_rtl8366rb_device.dev;
  5490. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  5491. + ar71xx_eth0_data.speed = SPEED_1000;
  5492. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5493. + ar71xx_eth0_pll_data.pll_1000 = 0x1a000000;
  5494. +
  5495. + ar71xx_add_device_eth(0);
  5496. +
  5497. + ar71xx_add_device_usb();
  5498. +
  5499. + ar71xx_add_device_m25p80(&tl_wr1043nd_flash_data);
  5500. +
  5501. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_leds_gpio),
  5502. + tl_wr1043nd_leds_gpio);
  5503. +
  5504. + platform_device_register(&tl_wr1043nd_rtl8366rb_device);
  5505. +
  5506. + ar71xx_add_device_gpio_buttons(-1, TL_WR1043ND_BUTTONS_POLL_INTERVAL,
  5507. + ARRAY_SIZE(tl_wr1043nd_gpio_buttons),
  5508. + tl_wr1043nd_gpio_buttons);
  5509. +
  5510. + ar913x_add_device_wmac(eeprom, mac);
  5511. +}
  5512. +
  5513. +MIPS_MACHINE(AR71XX_MACH_TL_WR1043ND, "TL-WR1043ND", "TP-LINK TL-WR1043ND",
  5514. + tl_wr1043nd_setup);
  5515. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr741nd.c linux-2.6.34/arch/mips/ar71xx/mach-tl-wr741nd.c
  5516. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr741nd.c 1970-01-01 01:00:00.000000000 +0100
  5517. +++ linux-2.6.34/arch/mips/ar71xx/mach-tl-wr741nd.c 2010-05-25 18:46:06.033464057 +0200
  5518. @@ -0,0 +1,115 @@
  5519. +/*
  5520. + * TP-LINK TL-WR741ND board support
  5521. + *
  5522. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  5523. + *
  5524. + * This program is free software; you can redistribute it and/or modify it
  5525. + * under the terms of the GNU General Public License version 2 as published
  5526. + * by the Free Software Foundation.
  5527. + */
  5528. +
  5529. +#include <linux/mtd/mtd.h>
  5530. +#include <linux/mtd/partitions.h>
  5531. +
  5532. +#include <asm/mach-ar71xx/ar71xx.h>
  5533. +
  5534. +#include "machtype.h"
  5535. +#include "devices.h"
  5536. +#include "dev-m25p80.h"
  5537. +#include "dev-ap91-eth.h"
  5538. +#include "dev-ap91-pci.h"
  5539. +#include "dev-gpio-buttons.h"
  5540. +#include "dev-leds-gpio.h"
  5541. +
  5542. +#define TL_WR741ND_GPIO_LED_QSS 0
  5543. +#define TL_WR741ND_GPIO_LED_SYSTEM 1
  5544. +
  5545. +#define TL_WR741ND_GPIO_BTN_RESET 11
  5546. +#define TL_WR741ND_GPIO_BTN_QSS 12
  5547. +
  5548. +#define TL_WR741ND_BUTTONS_POLL_INTERVAL 20
  5549. +
  5550. +#ifdef CONFIG_MTD_PARTITIONS
  5551. +static struct mtd_partition tl_wr741nd_partitions[] = {
  5552. + {
  5553. + .name = "u-boot",
  5554. + .offset = 0,
  5555. + .size = 0x020000,
  5556. + .mask_flags = MTD_WRITEABLE,
  5557. + } , {
  5558. + .name = "kernel",
  5559. + .offset = 0x020000,
  5560. + .size = 0x140000,
  5561. + } , {
  5562. + .name = "rootfs",
  5563. + .offset = 0x160000,
  5564. + .size = 0x290000,
  5565. + } , {
  5566. + .name = "art",
  5567. + .offset = 0x3f0000,
  5568. + .size = 0x010000,
  5569. + .mask_flags = MTD_WRITEABLE,
  5570. + } , {
  5571. + .name = "firmware",
  5572. + .offset = 0x020000,
  5573. + .size = 0x3d0000,
  5574. + }
  5575. +};
  5576. +#endif /* CONFIG_MTD_PARTITIONS */
  5577. +
  5578. +static struct flash_platform_data tl_wr741nd_flash_data = {
  5579. +#ifdef CONFIG_MTD_PARTITIONS
  5580. + .parts = tl_wr741nd_partitions,
  5581. + .nr_parts = ARRAY_SIZE(tl_wr741nd_partitions),
  5582. +#endif
  5583. +};
  5584. +
  5585. +static struct gpio_led tl_wr741nd_leds_gpio[] __initdata = {
  5586. + {
  5587. + .name = "tl-wr741nd:green:system",
  5588. + .gpio = TL_WR741ND_GPIO_LED_SYSTEM,
  5589. + .active_low = 1,
  5590. + }, {
  5591. + .name = "tl-wr741nd:green:qss",
  5592. + .gpio = TL_WR741ND_GPIO_LED_QSS,
  5593. + .active_low = 1,
  5594. + }
  5595. +};
  5596. +
  5597. +static struct gpio_button tl_wr741nd_gpio_buttons[] __initdata = {
  5598. + {
  5599. + .desc = "reset",
  5600. + .type = EV_KEY,
  5601. + .code = KEY_RESTART,
  5602. + .threshold = 3,
  5603. + .gpio = TL_WR741ND_GPIO_BTN_RESET,
  5604. + .active_low = 1,
  5605. + }, {
  5606. + .desc = "qss",
  5607. + .type = EV_KEY,
  5608. + .code = KEY_WPS_BUTTON,
  5609. + .threshold = 3,
  5610. + .gpio = TL_WR741ND_GPIO_BTN_QSS,
  5611. + .active_low = 1,
  5612. + }
  5613. +};
  5614. +
  5615. +static void __init tl_wr741nd_setup(void)
  5616. +{
  5617. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5618. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  5619. +
  5620. + ar71xx_add_device_m25p80(&tl_wr741nd_flash_data);
  5621. +
  5622. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr741nd_leds_gpio),
  5623. + tl_wr741nd_leds_gpio);
  5624. +
  5625. + ar71xx_add_device_gpio_buttons(-1, TL_WR741ND_BUTTONS_POLL_INTERVAL,
  5626. + ARRAY_SIZE(tl_wr741nd_gpio_buttons),
  5627. + tl_wr741nd_gpio_buttons);
  5628. +
  5629. + ap91_eth_init(mac, NULL);
  5630. + ap91_pci_init(ee, mac);
  5631. +}
  5632. +MIPS_MACHINE(AR71XX_MACH_TL_WR741ND, "TL-WR741ND", "TP-LINK TL-WR741ND",
  5633. + tl_wr741nd_setup);
  5634. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr841n.c linux-2.6.34/arch/mips/ar71xx/mach-tl-wr841n.c
  5635. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr841n.c 1970-01-01 01:00:00.000000000 +0100
  5636. +++ linux-2.6.34/arch/mips/ar71xx/mach-tl-wr841n.c 2010-05-25 18:46:06.091873727 +0200
  5637. @@ -0,0 +1,143 @@
  5638. +/*
  5639. + * TP-LINK TL-WR841N board support
  5640. + *
  5641. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5642. + *
  5643. + * This program is free software; you can redistribute it and/or modify it
  5644. + * under the terms of the GNU General Public License version 2 as published
  5645. + * by the Free Software Foundation.
  5646. + */
  5647. +
  5648. +#include <linux/mtd/mtd.h>
  5649. +#include <linux/mtd/partitions.h>
  5650. +
  5651. +#include <asm/mach-ar71xx/ar71xx.h>
  5652. +
  5653. +#include "machtype.h"
  5654. +#include "devices.h"
  5655. +#include "dev-dsa.h"
  5656. +#include "dev-m25p80.h"
  5657. +#include "dev-gpio-buttons.h"
  5658. +#include "dev-pb42-pci.h"
  5659. +#include "dev-leds-gpio.h"
  5660. +
  5661. +#define TL_WR841ND_V1_GPIO_LED_SYSTEM 2
  5662. +#define TL_WR841ND_V1_GPIO_LED_QSS_GREEN 4
  5663. +#define TL_WR841ND_V1_GPIO_LED_QSS_RED 5
  5664. +
  5665. +#define TL_WR841ND_V1_GPIO_BTN_RESET 3
  5666. +#define TL_WR841ND_V1_GPIO_BTN_QSS 7
  5667. +
  5668. +#define TL_WR841ND_V1_BUTTONS_POLL_INTERVAL 20
  5669. +
  5670. +#ifdef CONFIG_MTD_PARTITIONS
  5671. +static struct mtd_partition tl_wr841n_v1_partitions[] = {
  5672. + {
  5673. + .name = "redboot",
  5674. + .offset = 0,
  5675. + .size = 0x020000,
  5676. + .mask_flags = MTD_WRITEABLE,
  5677. + } , {
  5678. + .name = "kernel",
  5679. + .offset = 0x020000,
  5680. + .size = 0x140000,
  5681. + } , {
  5682. + .name = "rootfs",
  5683. + .offset = 0x160000,
  5684. + .size = 0x280000,
  5685. + } , {
  5686. + .name = "config",
  5687. + .offset = 0x3e0000,
  5688. + .size = 0x020000,
  5689. + .mask_flags = MTD_WRITEABLE,
  5690. + } , {
  5691. + .name = "firmware",
  5692. + .offset = 0x020000,
  5693. + .size = 0x3c0000,
  5694. + }
  5695. +};
  5696. +#endif /* CONFIG_MTD_PARTITIONS */
  5697. +
  5698. +static struct flash_platform_data tl_wr841n_v1_flash_data = {
  5699. +#ifdef CONFIG_MTD_PARTITIONS
  5700. + .parts = tl_wr841n_v1_partitions,
  5701. + .nr_parts = ARRAY_SIZE(tl_wr841n_v1_partitions),
  5702. +#endif
  5703. +};
  5704. +
  5705. +static struct gpio_led tl_wr841n_v1_leds_gpio[] __initdata = {
  5706. + {
  5707. + .name = "tl-wr841n:green:system",
  5708. + .gpio = TL_WR841ND_V1_GPIO_LED_SYSTEM,
  5709. + .active_low = 1,
  5710. + }, {
  5711. + .name = "tl-wr841n:red:qss",
  5712. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_RED,
  5713. + }, {
  5714. + .name = "tl-wr841n:green:qss",
  5715. + .gpio = TL_WR841ND_V1_GPIO_LED_QSS_GREEN,
  5716. + }
  5717. +};
  5718. +
  5719. +static struct gpio_button tl_wr841n_v1_gpio_buttons[] __initdata = {
  5720. + {
  5721. + .desc = "reset",
  5722. + .type = EV_KEY,
  5723. + .code = KEY_RESTART,
  5724. + .threshold = 3,
  5725. + .gpio = TL_WR841ND_V1_GPIO_BTN_RESET,
  5726. + .active_low = 1,
  5727. + }, {
  5728. + .desc = "qss",
  5729. + .type = EV_KEY,
  5730. + .code = KEY_WPS_BUTTON,
  5731. + .threshold = 3,
  5732. + .gpio = TL_WR841ND_V1_GPIO_BTN_QSS,
  5733. + .active_low = 1,
  5734. + }
  5735. +};
  5736. +
  5737. +static struct dsa_chip_data tl_wr841n_v1_dsa_chip = {
  5738. + .port_names[0] = "wan",
  5739. + .port_names[1] = "lan1",
  5740. + .port_names[2] = "lan2",
  5741. + .port_names[3] = "lan3",
  5742. + .port_names[4] = "lan4",
  5743. + .port_names[5] = "cpu",
  5744. +};
  5745. +
  5746. +static struct dsa_platform_data tl_wr841n_v1_dsa_data = {
  5747. + .nr_chips = 1,
  5748. + .chip = &tl_wr841n_v1_dsa_chip,
  5749. +};
  5750. +
  5751. +static void __init tl_wr841n_v1_setup(void)
  5752. +{
  5753. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5754. +
  5755. + ar71xx_set_mac_base(mac);
  5756. +
  5757. + ar71xx_add_device_mdio(0x0);
  5758. +
  5759. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5760. + ar71xx_eth0_data.speed = SPEED_100;
  5761. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5762. +
  5763. + ar71xx_add_device_eth(0);
  5764. +
  5765. + ar71xx_add_device_dsa(0, &tl_wr841n_v1_dsa_data);
  5766. +
  5767. + ar71xx_add_device_m25p80(&tl_wr841n_v1_flash_data);
  5768. +
  5769. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v1_leds_gpio),
  5770. + tl_wr841n_v1_leds_gpio);
  5771. +
  5772. + ar71xx_add_device_gpio_buttons(-1, TL_WR841ND_V1_BUTTONS_POLL_INTERVAL,
  5773. + ARRAY_SIZE(tl_wr841n_v1_gpio_buttons),
  5774. + tl_wr841n_v1_gpio_buttons);
  5775. +
  5776. + pb42_pci_init();
  5777. +}
  5778. +
  5779. +MIPS_MACHINE(AR71XX_MACH_TL_WR841N_V1, "TL-WR841N-v1.5", "TP-LINK TL-WR841N v1",
  5780. + tl_wr841n_v1_setup);
  5781. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr941nd.c linux-2.6.34/arch/mips/ar71xx/mach-tl-wr941nd.c
  5782. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-tl-wr941nd.c 1970-01-01 01:00:00.000000000 +0100
  5783. +++ linux-2.6.34/arch/mips/ar71xx/mach-tl-wr941nd.c 2010-05-25 18:46:06.132223001 +0200
  5784. @@ -0,0 +1,142 @@
  5785. +/*
  5786. + * TP-LINK TL-WR941ND board support
  5787. + *
  5788. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  5789. + *
  5790. + * This program is free software; you can redistribute it and/or modify it
  5791. + * under the terms of the GNU General Public License version 2 as published
  5792. + * by the Free Software Foundation.
  5793. + */
  5794. +
  5795. +#include <linux/mtd/mtd.h>
  5796. +#include <linux/mtd/partitions.h>
  5797. +
  5798. +#include <asm/mach-ar71xx/ar71xx.h>
  5799. +
  5800. +#include "machtype.h"
  5801. +#include "devices.h"
  5802. +#include "dev-dsa.h"
  5803. +#include "dev-m25p80.h"
  5804. +#include "dev-ar913x-wmac.h"
  5805. +#include "dev-gpio-buttons.h"
  5806. +#include "dev-leds-gpio.h"
  5807. +
  5808. +#define TL_WR941ND_GPIO_LED_SYSTEM 2
  5809. +#define TL_WR941ND_GPIO_LED_QSS_RED 4
  5810. +#define TL_WR941ND_GPIO_LED_QSS_GREEN 5
  5811. +
  5812. +#define TL_WR941ND_GPIO_BTN_RESET 3
  5813. +#define TL_WR941ND_GPIO_BTN_QSS 7
  5814. +
  5815. +#define TL_WR941ND_BUTTONS_POLL_INTERVAL 20
  5816. +
  5817. +#ifdef CONFIG_MTD_PARTITIONS
  5818. +static struct mtd_partition tl_wr941nd_partitions[] = {
  5819. + {
  5820. + .name = "u-boot",
  5821. + .offset = 0,
  5822. + .size = 0x020000,
  5823. + .mask_flags = MTD_WRITEABLE,
  5824. + } , {
  5825. + .name = "kernel",
  5826. + .offset = 0x020000,
  5827. + .size = 0x140000,
  5828. + } , {
  5829. + .name = "rootfs",
  5830. + .offset = 0x160000,
  5831. + .size = 0x290000,
  5832. + } , {
  5833. + .name = "art",
  5834. + .offset = 0x3f0000,
  5835. + .size = 0x010000,
  5836. + .mask_flags = MTD_WRITEABLE,
  5837. + } , {
  5838. + .name = "firmware",
  5839. + .offset = 0x020000,
  5840. + .size = 0x3d0000,
  5841. + }
  5842. +};
  5843. +#endif /* CONFIG_MTD_PARTITIONS */
  5844. +
  5845. +static struct flash_platform_data tl_wr941nd_flash_data = {
  5846. +#ifdef CONFIG_MTD_PARTITIONS
  5847. + .parts = tl_wr941nd_partitions,
  5848. + .nr_parts = ARRAY_SIZE(tl_wr941nd_partitions),
  5849. +#endif
  5850. +};
  5851. +
  5852. +static struct gpio_led tl_wr941nd_leds_gpio[] __initdata = {
  5853. + {
  5854. + .name = "tl-wr941nd:green:system",
  5855. + .gpio = TL_WR941ND_GPIO_LED_SYSTEM,
  5856. + .active_low = 1,
  5857. + }, {
  5858. + .name = "tl-wr941nd:red:qss",
  5859. + .gpio = TL_WR941ND_GPIO_LED_QSS_RED,
  5860. + }, {
  5861. + .name = "tl-wr941nd:green:qss",
  5862. + .gpio = TL_WR941ND_GPIO_LED_QSS_GREEN,
  5863. + }
  5864. +};
  5865. +
  5866. +static struct gpio_button tl_wr941nd_gpio_buttons[] __initdata = {
  5867. + {
  5868. + .desc = "reset",
  5869. + .type = EV_KEY,
  5870. + .code = KEY_RESTART,
  5871. + .threshold = 3,
  5872. + .gpio = TL_WR941ND_GPIO_BTN_RESET,
  5873. + .active_low = 1,
  5874. + }, {
  5875. + .desc = "qss",
  5876. + .type = EV_KEY,
  5877. + .code = KEY_WPS_BUTTON,
  5878. + .threshold = 3,
  5879. + .gpio = TL_WR941ND_GPIO_BTN_QSS,
  5880. + .active_low = 1,
  5881. + }
  5882. +};
  5883. +
  5884. +static struct dsa_chip_data tl_wr941nd_dsa_chip = {
  5885. + .port_names[0] = "wan",
  5886. + .port_names[1] = "lan1",
  5887. + .port_names[2] = "lan2",
  5888. + .port_names[3] = "lan3",
  5889. + .port_names[4] = "lan4",
  5890. + .port_names[5] = "cpu",
  5891. +};
  5892. +
  5893. +static struct dsa_platform_data tl_wr941nd_dsa_data = {
  5894. + .nr_chips = 1,
  5895. + .chip = &tl_wr941nd_dsa_chip,
  5896. +};
  5897. +
  5898. +static void __init tl_wr941nd_setup(void)
  5899. +{
  5900. + u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  5901. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  5902. +
  5903. + ar71xx_set_mac_base(mac);
  5904. +
  5905. + ar71xx_add_device_mdio(0x0);
  5906. +
  5907. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  5908. + ar71xx_eth0_data.speed = SPEED_100;
  5909. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  5910. +
  5911. + ar71xx_add_device_eth(0);
  5912. + ar71xx_add_device_dsa(0, &tl_wr941nd_dsa_data);
  5913. +
  5914. + ar71xx_add_device_m25p80(&tl_wr941nd_flash_data);
  5915. +
  5916. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_wr941nd_leds_gpio),
  5917. + tl_wr941nd_leds_gpio);
  5918. +
  5919. + ar71xx_add_device_gpio_buttons(-1, TL_WR941ND_BUTTONS_POLL_INTERVAL,
  5920. + ARRAY_SIZE(tl_wr941nd_gpio_buttons),
  5921. + tl_wr941nd_gpio_buttons);
  5922. + ar913x_add_device_wmac(eeprom, mac);
  5923. +}
  5924. +
  5925. +MIPS_MACHINE(AR71XX_MACH_TL_WR941ND, "TL-WR941ND", "TP-LINK TL-WR941ND",
  5926. + tl_wr941nd_setup);
  5927. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/machtype.h linux-2.6.34/arch/mips/ar71xx/machtype.h
  5928. --- linux-2.6.34.orig/arch/mips/ar71xx/machtype.h 1970-01-01 01:00:00.000000000 +0100
  5929. +++ linux-2.6.34/arch/mips/ar71xx/machtype.h 2010-05-25 18:46:06.170978587 +0200
  5930. @@ -0,0 +1,60 @@
  5931. +/*
  5932. + * Atheros AR71xx machine type definitions
  5933. + *
  5934. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  5935. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  5936. + *
  5937. + * This program is free software; you can redistribute it and/or modify it
  5938. + * under the terms of the GNU General Public License version 2 as published
  5939. + * by the Free Software Foundation.
  5940. + */
  5941. +
  5942. +#ifndef _AR71XX_MACHTYPE_H
  5943. +#define _AR71XX_MACHTYPE_H
  5944. +
  5945. +#include <asm/mips_machine.h>
  5946. +
  5947. +enum ar71xx_mach_type {
  5948. + AR71XX_MACH_GENERIC = 0,
  5949. + AR71XX_MACH_AP81, /* Atheros AP81 */
  5950. + AR71XX_MACH_AP83, /* Atheros AP83 */
  5951. + AR71XX_MACH_AW_NR580, /* AzureWave AW-NR580 */
  5952. + AR71XX_MACH_DIR_600_A1, /* D-Link DIR-600 rev. A1 */
  5953. + AR71XX_MACH_DIR_615_C1, /* D-Link DIR-615 rev. C1 */
  5954. + AR71XX_MACH_DIR_825_B1, /* D-Link DIR-825 rev. B1 */
  5955. + AR71XX_MACH_RB_411, /* MikroTik RouterBOARD 411/411A/411AH */
  5956. + AR71XX_MACH_RB_411U, /* MikroTik RouterBOARD 411U */
  5957. + AR71XX_MACH_RB_433, /* MikroTik RouterBOARD 433/433AH */
  5958. + AR71XX_MACH_RB_433U, /* MikroTik RouterBOARD 433UAH */
  5959. + AR71XX_MACH_RB_450, /* MikroTik RouterBOARD 450 */
  5960. + AR71XX_MACH_RB_450G, /* MikroTik RouterBOARD 450G */
  5961. + AR71XX_MACH_RB_493, /* Mikrotik RouterBOARD 493/493AH */
  5962. + AR71XX_MACH_RB_750, /* MikroTik RouterBOARD 750 */
  5963. + AR71XX_MACH_PB42, /* Atheros PB42 */
  5964. + AR71XX_MACH_PB44, /* Atheros PB44 */
  5965. + AR71XX_MACH_PB92, /* Atheros PB92 */
  5966. + AR71XX_MACH_MZK_W04NU, /* Planex MZK-W04NU */
  5967. + AR71XX_MACH_MZK_W300NH, /* Planex MZK-W300NH */
  5968. + AR71XX_MACH_NBG460N, /* Zyxel NBG460N/550N/550NH */
  5969. + AR71XX_MACH_TEW_632BRP, /* TRENDnet TEW-632BRP */
  5970. + AR71XX_MACH_TL_WR741ND, /* TP-LINK TL-WR741ND */
  5971. + AR71XX_MACH_TL_WR841N_V1, /* TP-LINK TL-WR841N v1 */
  5972. + AR71XX_MACH_TL_WR941ND, /* TP-LINK TL-WR941ND */
  5973. + AR71XX_MACH_TL_WR1043ND, /* TP-LINK TL-WR1041ND */
  5974. + AR71XX_MACH_UBNT_LSSR71, /* Ubiquiti LS-SR71 */
  5975. + AR71XX_MACH_UBNT_LSX, /* Ubiquiti LSX */
  5976. + AR71XX_MACH_UBNT_RS, /* Ubiquiti RouterStation */
  5977. + AR71XX_MACH_UBNT_AR71XX, /* Ubiquiti AR71xx-based board */
  5978. + AR71XX_MACH_UBNT_RSPRO, /* Ubiquiti RouterStation Pro */
  5979. + AR71XX_MACH_UBNT_BULLET_M, /* Ubiquiti Bullet M */
  5980. + AR71XX_MACH_UBNT_ROCKET_M, /* Ubiquiti Rocket M */
  5981. + AR71XX_MACH_UBNT_NANO_M, /* Ubiquiti NanoStation M */
  5982. + AR71XX_MACH_WNDR3700, /* NETGEAR WNDR3700 */
  5983. + AR71XX_MACH_WNR2000, /* NETGEAR WNR2000 */
  5984. + AR71XX_MACH_WP543, /* Compex WP543 */
  5985. + AR71XX_MACH_WRT160NL, /* Linksys WRT160NL */
  5986. + AR71XX_MACH_WRT400N, /* Linksys WRT400N */
  5987. + AR71XX_MACH_WZR_HP_G300NH, /* Buffalo WZR-HP-G300NH */
  5988. +};
  5989. +
  5990. +#endif /* _AR71XX_MACHTYPE_H */
  5991. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-ubnt.c linux-2.6.34/arch/mips/ar71xx/mach-ubnt.c
  5992. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-ubnt.c 1970-01-01 01:00:00.000000000 +0100
  5993. +++ linux-2.6.34/arch/mips/ar71xx/mach-ubnt.c 2010-05-25 18:46:06.210978842 +0200
  5994. @@ -0,0 +1,281 @@
  5995. +/*
  5996. + * Ubiquiti RouterStation support
  5997. + *
  5998. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  5999. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6000. + * Copyright (C) 2008 Ubiquiti <support@ubnt.com>
  6001. + *
  6002. + * This program is free software; you can redistribute it and/or modify it
  6003. + * under the terms of the GNU General Public License version 2 as published
  6004. + * by the Free Software Foundation.
  6005. + */
  6006. +
  6007. +#include <asm/mach-ar71xx/ar71xx.h>
  6008. +
  6009. +#include "machtype.h"
  6010. +#include "devices.h"
  6011. +#include "dev-m25p80.h"
  6012. +#include "dev-ap91-pci.h"
  6013. +#include "dev-gpio-buttons.h"
  6014. +#include "dev-pb42-pci.h"
  6015. +#include "dev-leds-gpio.h"
  6016. +#include "dev-usb.h"
  6017. +
  6018. +#define UBNT_RS_GPIO_LED_RF 2
  6019. +#define UBNT_RS_GPIO_SW4 8
  6020. +
  6021. +#define UBNT_LS_SR71_GPIO_LED_D25 0
  6022. +#define UBNT_LS_SR71_GPIO_LED_D26 1
  6023. +#define UBNT_LS_SR71_GPIO_LED_D24 2
  6024. +#define UBNT_LS_SR71_GPIO_LED_D23 4
  6025. +#define UBNT_LS_SR71_GPIO_LED_D22 5
  6026. +#define UBNT_LS_SR71_GPIO_LED_D27 6
  6027. +#define UBNT_LS_SR71_GPIO_LED_D28 7
  6028. +
  6029. +#define UBNT_M_GPIO_LED_L1 0
  6030. +#define UBNT_M_GPIO_LED_L2 1
  6031. +#define UBNT_M_GPIO_LED_L3 11
  6032. +#define UBNT_M_GPIO_LED_L4 7
  6033. +#define UBNT_M_GPIO_BTN_RESET 12
  6034. +
  6035. +#define UBNT_BUTTONS_POLL_INTERVAL 20
  6036. +
  6037. +static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
  6038. + {
  6039. + .name = "ubnt:green:rf",
  6040. + .gpio = UBNT_RS_GPIO_LED_RF,
  6041. + .active_low = 0,
  6042. + }
  6043. +};
  6044. +
  6045. +static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
  6046. + {
  6047. + .name = "ubnt:green:d22",
  6048. + .gpio = UBNT_LS_SR71_GPIO_LED_D22,
  6049. + .active_low = 0,
  6050. + }, {
  6051. + .name = "ubnt:green:d23",
  6052. + .gpio = UBNT_LS_SR71_GPIO_LED_D23,
  6053. + .active_low = 0,
  6054. + }, {
  6055. + .name = "ubnt:green:d24",
  6056. + .gpio = UBNT_LS_SR71_GPIO_LED_D24,
  6057. + .active_low = 0,
  6058. + }, {
  6059. + .name = "ubnt:red:d25",
  6060. + .gpio = UBNT_LS_SR71_GPIO_LED_D25,
  6061. + .active_low = 0,
  6062. + }, {
  6063. + .name = "ubnt:red:d26",
  6064. + .gpio = UBNT_LS_SR71_GPIO_LED_D26,
  6065. + .active_low = 0,
  6066. + }, {
  6067. + .name = "ubnt:green:d27",
  6068. + .gpio = UBNT_LS_SR71_GPIO_LED_D27,
  6069. + .active_low = 0,
  6070. + }, {
  6071. + .name = "ubnt:green:d28",
  6072. + .gpio = UBNT_LS_SR71_GPIO_LED_D28,
  6073. + .active_low = 0,
  6074. + }
  6075. +};
  6076. +
  6077. +static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
  6078. + {
  6079. + .name = "ubnt:red:link1",
  6080. + .gpio = UBNT_M_GPIO_LED_L1,
  6081. + .active_low = 0,
  6082. + }, {
  6083. + .name = "ubnt:orange:link2",
  6084. + .gpio = UBNT_M_GPIO_LED_L2,
  6085. + .active_low = 0,
  6086. + }, {
  6087. + .name = "ubnt:green:link3",
  6088. + .gpio = UBNT_M_GPIO_LED_L3,
  6089. + .active_low = 0,
  6090. + }, {
  6091. + .name = "ubnt:green:link4",
  6092. + .gpio = UBNT_M_GPIO_LED_L4,
  6093. + .active_low = 0,
  6094. + }
  6095. +};
  6096. +
  6097. +static struct gpio_button ubnt_gpio_buttons[] __initdata = {
  6098. + {
  6099. + .desc = "sw4",
  6100. + .type = EV_KEY,
  6101. + .code = KEY_RESTART,
  6102. + .threshold = 3,
  6103. + .gpio = UBNT_RS_GPIO_SW4,
  6104. + .active_low = 1,
  6105. + }
  6106. +};
  6107. +
  6108. +static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
  6109. + {
  6110. + .desc = "reset",
  6111. + .type = EV_KEY,
  6112. + .code = KEY_RESTART,
  6113. + .threshold = 3,
  6114. + .gpio = UBNT_M_GPIO_BTN_RESET,
  6115. + .active_low = 1,
  6116. + }
  6117. +};
  6118. +
  6119. +static void __init ubnt_generic_setup(void)
  6120. +{
  6121. + ar71xx_add_device_m25p80(NULL);
  6122. +
  6123. + ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
  6124. + ARRAY_SIZE(ubnt_gpio_buttons),
  6125. + ubnt_gpio_buttons);
  6126. +
  6127. + pb42_pci_init();
  6128. +}
  6129. +
  6130. +#define UBNT_RS_WAN_PHYMASK (1 << 20)
  6131. +#define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
  6132. +
  6133. +static void __init ubnt_rs_setup(void)
  6134. +{
  6135. + ubnt_generic_setup();
  6136. +
  6137. + ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
  6138. +
  6139. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6140. + ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
  6141. +
  6142. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6143. + ar71xx_eth1_data.speed = SPEED_100;
  6144. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6145. +
  6146. + ar71xx_add_device_eth(0);
  6147. + ar71xx_add_device_eth(1);
  6148. +
  6149. + ar71xx_add_device_usb();
  6150. +
  6151. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  6152. + ubnt_rs_leds_gpio);
  6153. +}
  6154. +
  6155. +MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
  6156. + ubnt_rs_setup);
  6157. +
  6158. +MIPS_MACHINE(AR71XX_MACH_UBNT_AR71XX, "Ubiquiti AR71xx-based board",
  6159. + "Ubiquiti RouterStation", ubnt_rs_setup);
  6160. +
  6161. +#define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
  6162. +#define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
  6163. +
  6164. +static void __init ubnt_rspro_setup(void)
  6165. +{
  6166. + ubnt_generic_setup();
  6167. +
  6168. + ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
  6169. +
  6170. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6171. + ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
  6172. +
  6173. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6174. + ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
  6175. + ar71xx_eth1_data.speed = SPEED_1000;
  6176. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6177. +
  6178. + ar71xx_add_device_eth(0);
  6179. + ar71xx_add_device_eth(1);
  6180. +
  6181. + ar71xx_add_device_usb();
  6182. +
  6183. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  6184. + ubnt_rs_leds_gpio);
  6185. +}
  6186. +
  6187. +MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
  6188. + ubnt_rspro_setup);
  6189. +
  6190. +static void __init ubnt_lsx_setup(void)
  6191. +{
  6192. + ubnt_generic_setup();
  6193. +}
  6194. +
  6195. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
  6196. +
  6197. +#define UBNT_LSSR71_PHY_MASK (1 << 1)
  6198. +
  6199. +static void __init ubnt_lssr71_setup(void)
  6200. +{
  6201. + ubnt_generic_setup();
  6202. +
  6203. + ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
  6204. +
  6205. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6206. + ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
  6207. +
  6208. + ar71xx_add_device_eth(0);
  6209. +
  6210. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
  6211. + ubnt_ls_sr71_leds_gpio);
  6212. +}
  6213. +
  6214. +MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
  6215. + ubnt_lssr71_setup);
  6216. +
  6217. +static void __init ubnt_m_setup(void)
  6218. +{
  6219. + u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  6220. + u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  6221. +
  6222. + ar71xx_set_mac_base(mac);
  6223. +
  6224. + ar71xx_add_device_m25p80(NULL);
  6225. +
  6226. + ar71xx_add_device_mdio(~0);
  6227. +
  6228. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6229. + ar71xx_eth0_data.speed = SPEED_100;
  6230. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6231. + ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
  6232. + ar71xx_eth0_data.fifo_cfg2 = 0x015500aa;
  6233. + ar71xx_eth0_data.fifo_cfg3 = 0x01f00140;
  6234. +
  6235. + ar71xx_add_device_eth(0);
  6236. +
  6237. + ap91_pci_init(ee, NULL);
  6238. +
  6239. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
  6240. + ubnt_m_leds_gpio);
  6241. +
  6242. + ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
  6243. + ARRAY_SIZE(ubnt_m_gpio_buttons),
  6244. + ubnt_m_gpio_buttons);
  6245. +}
  6246. +
  6247. +static void __init ubnt_rocket_m_setup(void)
  6248. +{
  6249. + ubnt_m_setup();
  6250. + ar71xx_add_device_usb();
  6251. +}
  6252. +
  6253. +MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
  6254. + ubnt_m_setup);
  6255. +MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
  6256. + ubnt_rocket_m_setup);
  6257. +
  6258. +/* TODO detect the second ethernet port and use one
  6259. + init function for all Ubiquiti MIMO series products */
  6260. +static void __init ubnt_nano_m_setup(void)
  6261. +{
  6262. + ubnt_m_setup();
  6263. +
  6264. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6265. + ar71xx_eth1_data.speed = SPEED_1000;
  6266. + ar71xx_eth1_data.duplex = DUPLEX_FULL;
  6267. + ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
  6268. + ar71xx_eth1_data.fifo_cfg2 = 0x015500aa;
  6269. + ar71xx_eth1_data.fifo_cfg3 = 0x01f00140;
  6270. +
  6271. + ar71xx_add_device_eth(1);
  6272. +}
  6273. +
  6274. +MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
  6275. + ubnt_nano_m_setup);
  6276. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wndr3700.c linux-2.6.34/arch/mips/ar71xx/mach-wndr3700.c
  6277. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wndr3700.c 1970-01-01 01:00:00.000000000 +0100
  6278. +++ linux-2.6.34/arch/mips/ar71xx/mach-wndr3700.c 2010-05-25 18:46:06.250979126 +0200
  6279. @@ -0,0 +1,209 @@
  6280. +/*
  6281. + * Netgear WNDR3700 board support
  6282. + *
  6283. + * Copyright (C) 2009 Marco Porsch
  6284. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  6285. + *
  6286. + * This program is free software; you can redistribute it and/or modify it
  6287. + * under the terms of the GNU General Public License version 2 as published
  6288. + * by the Free Software Foundation.
  6289. + */
  6290. +
  6291. +#include <linux/platform_device.h>
  6292. +#include <linux/mtd/mtd.h>
  6293. +#include <linux/mtd/partitions.h>
  6294. +#include <linux/delay.h>
  6295. +#include <linux/rtl8366s.h>
  6296. +
  6297. +#include <asm/mach-ar71xx/ar71xx.h>
  6298. +
  6299. +#include "machtype.h"
  6300. +#include "devices.h"
  6301. +#include "dev-m25p80.h"
  6302. +#include "dev-ap94-pci.h"
  6303. +#include "dev-gpio-buttons.h"
  6304. +#include "dev-leds-gpio.h"
  6305. +#include "dev-usb.h"
  6306. +
  6307. +#define WNDR3700_GPIO_LED_WPS_ORANGE 0
  6308. +#define WNDR3700_GPIO_LED_POWER_ORANGE 1
  6309. +#define WNDR3700_GPIO_LED_POWER_GREEN 2
  6310. +#define WNDR3700_GPIO_LED_WPS_GREEN 4
  6311. +#define WNDR3700_GPIO_LED_WAN_GREEN 6
  6312. +
  6313. +#define WNDR3700_GPIO_BTN_WPS 3
  6314. +#define WNDR3700_GPIO_BTN_RESET 8
  6315. +#define WNDR3700_GPIO_BTN_WIFI 11
  6316. +
  6317. +#define WNDR3700_GPIO_RTL8366_SDA 5
  6318. +#define WNDR3700_GPIO_RTL8366_SCK 7
  6319. +
  6320. +#define WNDR3700_BUTTONS_POLL_INTERVAL 20
  6321. +
  6322. +#define WNDR3700_WMAC0_MAC_OFFSET 0
  6323. +#define WNDR3700_WMAC1_MAC_OFFSET 0xc
  6324. +#define WNDR3700_CALDATA0_OFFSET 0x1000
  6325. +#define WNDR3700_CALDATA1_OFFSET 0x5000
  6326. +
  6327. +#ifdef CONFIG_MTD_PARTITIONS
  6328. +static struct mtd_partition wndr3700_partitions[] = {
  6329. + {
  6330. + .name = "uboot",
  6331. + .offset = 0,
  6332. + .size = 0x050000,
  6333. + .mask_flags = MTD_WRITEABLE,
  6334. + } , {
  6335. + .name = "env",
  6336. + .offset = 0x050000,
  6337. + .size = 0x020000,
  6338. + .mask_flags = MTD_WRITEABLE,
  6339. + } , {
  6340. + .name = "rootfs",
  6341. + .offset = 0x070000,
  6342. + .size = 0x720000,
  6343. + } , {
  6344. + .name = "config",
  6345. + .offset = 0x790000,
  6346. + .size = 0x010000,
  6347. + .mask_flags = MTD_WRITEABLE,
  6348. + } , {
  6349. + .name = "config_bak",
  6350. + .offset = 0x7a0000,
  6351. + .size = 0x010000,
  6352. + .mask_flags = MTD_WRITEABLE,
  6353. + } , {
  6354. + .name = "pot",
  6355. + .offset = 0x7b0000,
  6356. + .size = 0x010000,
  6357. + .mask_flags = MTD_WRITEABLE,
  6358. + } , {
  6359. + .name = "traffic_meter",
  6360. + .offset = 0x7c0000,
  6361. + .size = 0x010000,
  6362. + .mask_flags = MTD_WRITEABLE,
  6363. + } , {
  6364. + .name = "language",
  6365. + .offset = 0x7d0000,
  6366. + .size = 0x020000,
  6367. + .mask_flags = MTD_WRITEABLE,
  6368. + } , {
  6369. + .name = "caldata",
  6370. + .offset = 0x7f0000,
  6371. + .size = 0x010000,
  6372. + .mask_flags = MTD_WRITEABLE,
  6373. + }
  6374. +};
  6375. +#endif /* CONFIG_MTD_PARTITIONS */
  6376. +
  6377. +static struct flash_platform_data wndr3700_flash_data = {
  6378. +#ifdef CONFIG_MTD_PARTITIONS
  6379. + .parts = wndr3700_partitions,
  6380. + .nr_parts = ARRAY_SIZE(wndr3700_partitions),
  6381. +#endif
  6382. +};
  6383. +
  6384. +static struct gpio_led wndr3700_leds_gpio[] __initdata = {
  6385. + {
  6386. + .name = "wndr3700:green:power",
  6387. + .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
  6388. + .active_low = 1,
  6389. + }, {
  6390. + .name = "wndr3700:orange:power",
  6391. + .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
  6392. + .active_low = 1,
  6393. + }, {
  6394. + .name = "wndr3700:green:wps",
  6395. + .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
  6396. + .active_low = 1,
  6397. + }, {
  6398. + .name = "wndr3700:orange:wps",
  6399. + .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
  6400. + .active_low = 1,
  6401. + }, {
  6402. + .name = "wndr3700:green:wan",
  6403. + .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
  6404. + .active_low = 1,
  6405. + }
  6406. +};
  6407. +
  6408. +static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
  6409. + {
  6410. + .desc = "reset",
  6411. + .type = EV_KEY,
  6412. + .code = KEY_RESTART,
  6413. + .threshold = 3,
  6414. + .gpio = WNDR3700_GPIO_BTN_RESET,
  6415. + .active_low = 1,
  6416. + }, {
  6417. + .desc = "wps",
  6418. + .type = EV_KEY,
  6419. + .code = KEY_WPS_BUTTON,
  6420. + .threshold = 3,
  6421. + .gpio = WNDR3700_GPIO_BTN_WPS,
  6422. + .active_low = 1,
  6423. + } , {
  6424. + .desc = "wifi",
  6425. + .type = EV_KEY,
  6426. + .code = BTN_2,
  6427. + .threshold = 3,
  6428. + .gpio = WNDR3700_GPIO_BTN_WIFI,
  6429. + .active_low = 1,
  6430. + }
  6431. +};
  6432. +
  6433. +static struct rtl8366s_platform_data wndr3700_rtl8366s_data = {
  6434. + .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
  6435. + .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
  6436. +};
  6437. +
  6438. +static struct platform_device wndr3700_rtl8366s_device = {
  6439. + .name = RTL8366S_DRIVER_NAME,
  6440. + .id = -1,
  6441. + .dev = {
  6442. + .platform_data = &wndr3700_rtl8366s_data,
  6443. + }
  6444. +};
  6445. +
  6446. +static void __init wndr3700_setup(void)
  6447. +{
  6448. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  6449. +
  6450. + ar71xx_set_mac_base(art);
  6451. +
  6452. + ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
  6453. + ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  6454. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6455. + ar71xx_eth0_data.speed = SPEED_1000;
  6456. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6457. +
  6458. + ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
  6459. + ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
  6460. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  6461. + ar71xx_eth1_data.phy_mask = 0x10;
  6462. +
  6463. + ar71xx_add_device_eth(0);
  6464. + ar71xx_add_device_eth(1);
  6465. +
  6466. + ar71xx_add_device_usb();
  6467. +
  6468. + ar71xx_add_device_m25p80(&wndr3700_flash_data);
  6469. +
  6470. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
  6471. + wndr3700_leds_gpio);
  6472. +
  6473. + ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
  6474. + ARRAY_SIZE(wndr3700_gpio_buttons),
  6475. + wndr3700_gpio_buttons);
  6476. +
  6477. + platform_device_register(&wndr3700_rtl8366s_device);
  6478. + platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
  6479. +
  6480. + ap94_pci_enable_quirk_wndr3700();
  6481. + ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
  6482. + art + WNDR3700_WMAC0_MAC_OFFSET,
  6483. + art + WNDR3700_CALDATA1_OFFSET,
  6484. + art + WNDR3700_WMAC1_MAC_OFFSET);
  6485. +}
  6486. +
  6487. +MIPS_MACHINE(AR71XX_MACH_WNDR3700, "WNDR3700", "NETGEAR WNDR3700",
  6488. + wndr3700_setup);
  6489. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wnr2000.c linux-2.6.34/arch/mips/ar71xx/mach-wnr2000.c
  6490. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wnr2000.c 1970-01-01 01:00:00.000000000 +0100
  6491. +++ linux-2.6.34/arch/mips/ar71xx/mach-wnr2000.c 2010-05-25 18:46:06.290978653 +0200
  6492. @@ -0,0 +1,148 @@
  6493. +/*
  6494. + * NETGEAR WNR2000 board support
  6495. + *
  6496. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6497. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6498. + * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
  6499. + *
  6500. + * This program is free software; you can redistribute it and/or modify it
  6501. + * under the terms of the GNU General Public License version 2 as published
  6502. + * by the Free Software Foundation.
  6503. + */
  6504. +
  6505. +#include <linux/mtd/mtd.h>
  6506. +#include <linux/mtd/partitions.h>
  6507. +
  6508. +#include <asm/mach-ar71xx/ar71xx.h>
  6509. +
  6510. +#include "machtype.h"
  6511. +#include "devices.h"
  6512. +#include "dev-m25p80.h"
  6513. +#include "dev-ar913x-wmac.h"
  6514. +#include "dev-gpio-buttons.h"
  6515. +#include "dev-leds-gpio.h"
  6516. +
  6517. +#define WNR2000_GPIO_LED_PWR_GREEN 14
  6518. +#define WNR2000_GPIO_LED_PWR_AMBER 7
  6519. +#define WNR2000_GPIO_LED_WPS 4
  6520. +#define WNR2000_GPIO_LED_WLAN 6
  6521. +#define WNR2000_GPIO_BTN_RESET 21
  6522. +#define WNR2000_GPIO_BTN_WPS 8
  6523. +
  6524. +#define WNR2000_BUTTONS_POLL_INTERVAL 20
  6525. +
  6526. +#ifdef CONFIG_MTD_PARTITIONS
  6527. +static struct mtd_partition wnr2000_partitions[] = {
  6528. + {
  6529. + .name = "u-boot",
  6530. + .offset = 0,
  6531. + .size = 0x040000,
  6532. + .mask_flags = MTD_WRITEABLE,
  6533. + } , {
  6534. + .name = "u-boot-env",
  6535. + .offset = 0x040000,
  6536. + .size = 0x010000,
  6537. + } , {
  6538. + .name = "rootfs",
  6539. + .offset = 0x050000,
  6540. + .size = 0x240000,
  6541. + } , {
  6542. + .name = "user-config",
  6543. + .offset = 0x290000,
  6544. + .size = 0x010000,
  6545. + } , {
  6546. + .name = "uImage",
  6547. + .offset = 0x2a0000,
  6548. + .size = 0x120000,
  6549. + } , {
  6550. + .name = "language_table",
  6551. + .offset = 0x3c0000,
  6552. + .size = 0x020000,
  6553. + } , {
  6554. + .name = "rootfs_checksum",
  6555. + .offset = 0x3e0000,
  6556. + .size = 0x010000,
  6557. + } , {
  6558. + .name = "art",
  6559. + .offset = 0x3f0000,
  6560. + .size = 0x010000,
  6561. + .mask_flags = MTD_WRITEABLE,
  6562. + }
  6563. +};
  6564. +#endif /* CONFIG_MTD_PARTITIONS */
  6565. +
  6566. +static struct flash_platform_data wnr2000_flash_data = {
  6567. +#ifdef CONFIG_MTD_PARTITIONS
  6568. + .parts = wnr2000_partitions,
  6569. + .nr_parts = ARRAY_SIZE(wnr2000_partitions),
  6570. +#endif
  6571. +};
  6572. +
  6573. +static struct gpio_led wnr2000_leds_gpio[] __initdata = {
  6574. + {
  6575. + .name = "wnr2000:green:power",
  6576. + .gpio = WNR2000_GPIO_LED_PWR_GREEN,
  6577. + .active_low = 1,
  6578. + }, {
  6579. + .name = "wnr2000:amber:power",
  6580. + .gpio = WNR2000_GPIO_LED_PWR_AMBER,
  6581. + .active_low = 1,
  6582. + }, {
  6583. + .name = "wnr2000:green:wps",
  6584. + .gpio = WNR2000_GPIO_LED_WPS,
  6585. + .active_low = 1,
  6586. + }, {
  6587. + .name = "wnr2000:blue:wlan",
  6588. + .gpio = WNR2000_GPIO_LED_WLAN,
  6589. + .active_low = 1,
  6590. + }
  6591. +};
  6592. +
  6593. +static struct gpio_button wnr2000_gpio_buttons[] __initdata = {
  6594. + {
  6595. + .desc = "reset",
  6596. + .type = EV_KEY,
  6597. + .code = KEY_RESTART,
  6598. + .threshold = 3,
  6599. + .gpio = WNR2000_GPIO_BTN_RESET,
  6600. + }, {
  6601. + .desc = "wps",
  6602. + .type = EV_KEY,
  6603. + .code = KEY_WPS_BUTTON,
  6604. + .threshold = 3,
  6605. + .gpio = WNR2000_GPIO_BTN_WPS,
  6606. + }
  6607. +};
  6608. +
  6609. +static void __init wnr2000_setup(void)
  6610. +{
  6611. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  6612. +
  6613. + ar71xx_set_mac_base(eeprom);
  6614. + ar71xx_add_device_mdio(0x0);
  6615. +
  6616. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6617. + ar71xx_eth0_data.speed = SPEED_100;
  6618. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  6619. + ar71xx_eth0_data.has_ar8216 = 1;
  6620. +
  6621. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6622. + ar71xx_eth1_data.phy_mask = 0x10;
  6623. +
  6624. + ar71xx_add_device_eth(0);
  6625. + ar71xx_add_device_eth(1);
  6626. +
  6627. + ar71xx_add_device_m25p80(&wnr2000_flash_data);
  6628. +
  6629. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wnr2000_leds_gpio),
  6630. + wnr2000_leds_gpio);
  6631. +
  6632. + ar71xx_add_device_gpio_buttons(-1, WNR2000_BUTTONS_POLL_INTERVAL,
  6633. + ARRAY_SIZE(wnr2000_gpio_buttons),
  6634. + wnr2000_gpio_buttons);
  6635. +
  6636. +
  6637. + ar913x_add_device_wmac(eeprom, NULL);
  6638. +}
  6639. +
  6640. +MIPS_MACHINE(AR71XX_MACH_WNR2000, "WNR2000", "NETGEAR WNR2000", wnr2000_setup);
  6641. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wp543.c linux-2.6.34/arch/mips/ar71xx/mach-wp543.c
  6642. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wp543.c 1970-01-01 01:00:00.000000000 +0100
  6643. +++ linux-2.6.34/arch/mips/ar71xx/mach-wp543.c 2010-05-25 18:46:06.340979863 +0200
  6644. @@ -0,0 +1,99 @@
  6645. +/*
  6646. + * Compex WP543/WPJ543 board support
  6647. + *
  6648. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  6649. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6650. + *
  6651. + * This program is free software; you can redistribute it and/or modify it
  6652. + * under the terms of the GNU General Public License version 2 as published
  6653. + * by the Free Software Foundation.
  6654. + */
  6655. +
  6656. +#include <linux/mtd/mtd.h>
  6657. +#include <linux/mtd/partitions.h>
  6658. +
  6659. +#include <asm/mach-ar71xx/ar71xx.h>
  6660. +
  6661. +#include "machtype.h"
  6662. +#include "devices.h"
  6663. +#include "dev-m25p80.h"
  6664. +#include "dev-pb42-pci.h"
  6665. +#include "dev-gpio-buttons.h"
  6666. +#include "dev-leds-gpio.h"
  6667. +#include "dev-usb.h"
  6668. +
  6669. +#define WP543_GPIO_SW6 2
  6670. +#define WP543_GPIO_LED_1 3
  6671. +#define WP543_GPIO_LED_2 4
  6672. +#define WP543_GPIO_LED_WLAN 5
  6673. +#define WP543_GPIO_LED_CONN 6
  6674. +#define WP543_GPIO_LED_DIAG 7
  6675. +#define WP543_GPIO_SW4 8
  6676. +
  6677. +#define WP543_BUTTONS_POLL_INTERVAL 20
  6678. +
  6679. +static struct gpio_led wp543_leds_gpio[] __initdata = {
  6680. + {
  6681. + .name = "wp543:green:led1",
  6682. + .gpio = WP543_GPIO_LED_1,
  6683. + .active_low = 1,
  6684. + }, {
  6685. + .name = "wp543:green:led2",
  6686. + .gpio = WP543_GPIO_LED_2,
  6687. + .active_low = 1,
  6688. + }, {
  6689. + .name = "wp543:green:wlan",
  6690. + .gpio = WP543_GPIO_LED_WLAN,
  6691. + .active_low = 1,
  6692. + }, {
  6693. + .name = "wp543:green:conn",
  6694. + .gpio = WP543_GPIO_LED_CONN,
  6695. + .active_low = 1,
  6696. + }, {
  6697. + .name = "wp543:green:diag",
  6698. + .gpio = WP543_GPIO_LED_DIAG,
  6699. + .active_low = 1,
  6700. + }
  6701. +};
  6702. +
  6703. +static struct gpio_button wp543_gpio_buttons[] __initdata = {
  6704. + {
  6705. + .desc = "sw6",
  6706. + .type = EV_KEY,
  6707. + .code = BTN_0,
  6708. + .threshold = 3,
  6709. + .gpio = WP543_GPIO_SW6,
  6710. + }, {
  6711. + .desc = "sw4",
  6712. + .type = EV_KEY,
  6713. + .code = BTN_1,
  6714. + .threshold = 3,
  6715. + .gpio = WP543_GPIO_SW4,
  6716. + }
  6717. +};
  6718. +
  6719. +static void __init wp543_setup(void)
  6720. +{
  6721. + ar71xx_add_device_m25p80(NULL);
  6722. +
  6723. + ar71xx_add_device_mdio(0xfffffff7);
  6724. +
  6725. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  6726. + ar71xx_eth0_data.phy_mask = 0x08;
  6727. + ar71xx_eth0_data.reset_bit = RESET_MODULE_GE0_MAC |
  6728. + RESET_MODULE_GE0_PHY;
  6729. + ar71xx_add_device_eth(0);
  6730. +
  6731. + ar71xx_add_device_usb();
  6732. +
  6733. + pb42_pci_init();
  6734. +
  6735. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wp543_leds_gpio),
  6736. + wp543_leds_gpio);
  6737. +
  6738. + ar71xx_add_device_gpio_buttons(-1, WP543_BUTTONS_POLL_INTERVAL,
  6739. + ARRAY_SIZE(wp543_gpio_buttons),
  6740. + wp543_gpio_buttons);
  6741. +}
  6742. +
  6743. +MIPS_MACHINE(AR71XX_MACH_WP543, "WP543", "Compex WP543", wp543_setup);
  6744. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wrt160nl.c linux-2.6.34/arch/mips/ar71xx/mach-wrt160nl.c
  6745. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wrt160nl.c 1970-01-01 01:00:00.000000000 +0100
  6746. +++ linux-2.6.34/arch/mips/ar71xx/mach-wrt160nl.c 2010-05-25 18:46:06.390978782 +0200
  6747. @@ -0,0 +1,158 @@
  6748. +/*
  6749. + * Linksys WRT160NL board support
  6750. + *
  6751. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  6752. + *
  6753. + * This program is free software; you can redistribute it and/or modify it
  6754. + * under the terms of the GNU General Public License version 2 as published
  6755. + * by the Free Software Foundation.
  6756. + */
  6757. +
  6758. +#include <linux/mtd/mtd.h>
  6759. +#include <linux/mtd/partitions.h>
  6760. +
  6761. +#include <asm/mach-ar71xx/ar71xx.h>
  6762. +
  6763. +#include "machtype.h"
  6764. +#include "devices.h"
  6765. +#include "dev-m25p80.h"
  6766. +#include "dev-ar913x-wmac.h"
  6767. +#include "dev-gpio-buttons.h"
  6768. +#include "dev-leds-gpio.h"
  6769. +#include "dev-usb.h"
  6770. +#include "nvram.h"
  6771. +
  6772. +#define WRT160NL_GPIO_LED_POWER 14
  6773. +#define WRT160NL_GPIO_LED_WPS_AMBER 9
  6774. +#define WRT160NL_GPIO_LED_WPS_BLUE 8
  6775. +#define WRT160NL_GPIO_LED_WLAN 6
  6776. +
  6777. +#define WRT160NL_GPIO_BTN_WPS 7
  6778. +#define WRT160NL_GPIO_BTN_RESET 21
  6779. +
  6780. +#define WRT160NL_BUTTONS_POLL_INTERVAL 20
  6781. +
  6782. +#define WRT160NL_NVRAM_ADDR 0x1f7e0000
  6783. +#define WRT160NL_NVRAM_SIZE 0x10000
  6784. +
  6785. +#ifdef CONFIG_MTD_PARTITIONS
  6786. +static struct mtd_partition wrt160nl_partitions[] = {
  6787. + {
  6788. + .name = "u-boot",
  6789. + .offset = 0,
  6790. + .size = 0x040000,
  6791. + .mask_flags = MTD_WRITEABLE,
  6792. + } , {
  6793. + .name = "kernel",
  6794. + .offset = 0x040000,
  6795. + .size = 0x0e0000,
  6796. + } , {
  6797. + .name = "filesytem",
  6798. + .offset = 0x120000,
  6799. + .size = 0x6c0000,
  6800. + } , {
  6801. + .name = "nvram",
  6802. + .offset = 0x7e0000,
  6803. + .size = 0x010000,
  6804. + .mask_flags = MTD_WRITEABLE,
  6805. + } , {
  6806. + .name = "ART",
  6807. + .offset = 0x7f0000,
  6808. + .size = 0x010000,
  6809. + .mask_flags = MTD_WRITEABLE,
  6810. + } , {
  6811. + .name = "firmware",
  6812. + .offset = 0x040000,
  6813. + .size = 0x7a0000,
  6814. + }
  6815. +};
  6816. +#endif /* CONFIG_MTD_PARTITIONS */
  6817. +
  6818. +static struct flash_platform_data wrt160nl_flash_data = {
  6819. +#ifdef CONFIG_MTD_PARTITIONS
  6820. + .parts = wrt160nl_partitions,
  6821. + .nr_parts = ARRAY_SIZE(wrt160nl_partitions),
  6822. +#endif
  6823. +};
  6824. +
  6825. +static struct gpio_led wrt160nl_leds_gpio[] __initdata = {
  6826. + {
  6827. + .name = "wrt160nl:blue:power",
  6828. + .gpio = WRT160NL_GPIO_LED_POWER,
  6829. + .active_low = 1,
  6830. + .default_trigger = "default-on",
  6831. + }, {
  6832. + .name = "wrt160nl:amber:wps",
  6833. + .gpio = WRT160NL_GPIO_LED_WPS_AMBER,
  6834. + .active_low = 1,
  6835. + }, {
  6836. + .name = "wrt160nl:blue:wps",
  6837. + .gpio = WRT160NL_GPIO_LED_WPS_BLUE,
  6838. + .active_low = 1,
  6839. + }, {
  6840. + .name = "wrt160nl:blue:wlan",
  6841. + .gpio = WRT160NL_GPIO_LED_WLAN,
  6842. + .active_low = 1,
  6843. + }
  6844. +};
  6845. +
  6846. +static struct gpio_button wrt160nl_gpio_buttons[] __initdata = {
  6847. + {
  6848. + .desc = "reset",
  6849. + .type = EV_KEY,
  6850. + .code = KEY_RESTART,
  6851. + .threshold = 3,
  6852. + .gpio = WRT160NL_GPIO_BTN_RESET,
  6853. + .active_low = 1,
  6854. + }, {
  6855. + .desc = "wps",
  6856. + .type = EV_KEY,
  6857. + .code = KEY_WPS_BUTTON,
  6858. + .threshold = 3,
  6859. + .gpio = WRT160NL_GPIO_BTN_WPS,
  6860. + .active_low = 1,
  6861. + }
  6862. +};
  6863. +
  6864. +static void __init wrt160nl_setup(void)
  6865. +{
  6866. + const char *nvram = (char *) KSEG1ADDR(WRT160NL_NVRAM_ADDR);
  6867. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  6868. + u8 mac[6];
  6869. +
  6870. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  6871. + "lan_hwaddr=", mac) == 0)
  6872. + ar71xx_set_mac_base(mac);
  6873. +
  6874. + ar71xx_add_device_mdio(0x0);
  6875. +
  6876. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6877. + ar71xx_eth0_data.phy_mask = 0x01;
  6878. +
  6879. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  6880. + ar71xx_eth1_data.phy_mask = 0x10;
  6881. +
  6882. + ar71xx_add_device_eth(0);
  6883. + ar71xx_add_device_eth(1);
  6884. +
  6885. + ar71xx_add_device_m25p80(&wrt160nl_flash_data);
  6886. +
  6887. + ar71xx_add_device_usb();
  6888. +
  6889. + if (nvram_parse_mac_addr(nvram, WRT160NL_NVRAM_SIZE,
  6890. + "wl0_hwaddr=", mac) == 0)
  6891. + ar913x_add_device_wmac(eeprom, mac);
  6892. + else
  6893. + ar913x_add_device_wmac(eeprom, NULL);
  6894. +
  6895. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt160nl_leds_gpio),
  6896. + wrt160nl_leds_gpio);
  6897. +
  6898. + ar71xx_add_device_gpio_buttons(-1, WRT160NL_BUTTONS_POLL_INTERVAL,
  6899. + ARRAY_SIZE(wrt160nl_gpio_buttons),
  6900. + wrt160nl_gpio_buttons);
  6901. +
  6902. +}
  6903. +
  6904. +MIPS_MACHINE(AR71XX_MACH_WRT160NL, "WRT160NL", "Linksys WRT160NL",
  6905. + wrt160nl_setup);
  6906. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wrt400n.c linux-2.6.34/arch/mips/ar71xx/mach-wrt400n.c
  6907. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wrt400n.c 1970-01-01 01:00:00.000000000 +0100
  6908. +++ linux-2.6.34/arch/mips/ar71xx/mach-wrt400n.c 2010-05-25 18:46:06.432223100 +0200
  6909. @@ -0,0 +1,168 @@
  6910. +/*
  6911. + * Linksys WRT400N board support
  6912. + *
  6913. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  6914. + * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
  6915. + *
  6916. + * This program is free software; you can redistribute it and/or modify it
  6917. + * under the terms of the GNU General Public License version 2 as published
  6918. + * by the Free Software Foundation.
  6919. + */
  6920. +
  6921. +#include <linux/mtd/mtd.h>
  6922. +#include <linux/mtd/partitions.h>
  6923. +
  6924. +#include <asm/mach-ar71xx/ar71xx.h>
  6925. +
  6926. +#include "machtype.h"
  6927. +#include "devices.h"
  6928. +#include "dev-ap94-pci.h"
  6929. +#include "dev-m25p80.h"
  6930. +#include "dev-gpio-buttons.h"
  6931. +#include "dev-leds-gpio.h"
  6932. +
  6933. +#define WRT400N_GPIO_LED_ORANGE 5
  6934. +#define WRT400N_GPIO_LED_GREEN 4
  6935. +#define WRT400N_GPIO_LED_POWER 1
  6936. +#define WRT400N_GPIO_LED_WLAN 0
  6937. +
  6938. +#define WRT400N_GPIO_BTN_RESET 8
  6939. +#define WRT400N_GPIO_BTN_WLSEC 3
  6940. +
  6941. +#define WRT400N_BUTTONS_POLL_INTERVAL 20
  6942. +
  6943. +#define WRT400N_MAC_ADDR_OFFSET 0x120c
  6944. +#define WRT400N_CALDATA0_OFFSET 0x1000
  6945. +#define WRT400N_CALDATA1_OFFSET 0x5000
  6946. +
  6947. +#ifdef CONFIG_MTD_PARTITIONS
  6948. +static struct mtd_partition wrt400n_partitions[] = {
  6949. + {
  6950. + .name = "uboot",
  6951. + .offset = 0,
  6952. + .size = 0x030000,
  6953. + .mask_flags = MTD_WRITEABLE,
  6954. + } , {
  6955. + .name = "env",
  6956. + .offset = 0x030000,
  6957. + .size = 0x010000,
  6958. + .mask_flags = MTD_WRITEABLE,
  6959. + } , {
  6960. + .name = "linux",
  6961. + .offset = 0x040000,
  6962. + .size = 0x140000,
  6963. + } , {
  6964. + .name = "rootfs",
  6965. + .offset = 0x180000,
  6966. + .size = 0x630000,
  6967. + } , {
  6968. + .name = "nvram",
  6969. + .offset = 0x7b0000,
  6970. + .size = 0x010000,
  6971. + .mask_flags = MTD_WRITEABLE,
  6972. + } , {
  6973. + .name = "factory",
  6974. + .offset = 0x7c0000,
  6975. + .size = 0x010000,
  6976. + .mask_flags = MTD_WRITEABLE,
  6977. + } , {
  6978. + .name = "language",
  6979. + .offset = 0x7d0000,
  6980. + .size = 0x020000,
  6981. + .mask_flags = MTD_WRITEABLE,
  6982. + } , {
  6983. + .name = "caldata",
  6984. + .offset = 0x7f0000,
  6985. + .size = 0x010000,
  6986. + .mask_flags = MTD_WRITEABLE,
  6987. + } , {
  6988. + .name = "firmware",
  6989. + .offset = 0x040000,
  6990. + .size = 0x770000,
  6991. + }
  6992. +};
  6993. +#endif /* CONFIG_MTD_PARTITIONS */
  6994. +
  6995. +static struct flash_platform_data wrt400n_flash_data = {
  6996. +#ifdef CONFIG_MTD_PARTITIONS
  6997. + .parts = wrt400n_partitions,
  6998. + .nr_parts = ARRAY_SIZE(wrt400n_partitions),
  6999. +#endif
  7000. +};
  7001. +
  7002. +static struct gpio_led wrt400n_leds_gpio[] __initdata = {
  7003. + {
  7004. + .name = "wrt400n:green:status",
  7005. + .gpio = WRT400N_GPIO_LED_GREEN,
  7006. + .active_low = 1,
  7007. + }, {
  7008. + .name = "wrt400n:amber:aoss",
  7009. + .gpio = WRT400N_GPIO_LED_ORANGE,
  7010. + .active_low = 1,
  7011. + }, {
  7012. + .name = "wrt400n:green:wlan",
  7013. + .gpio = WRT400N_GPIO_LED_WLAN,
  7014. + .active_low = 1,
  7015. + }, {
  7016. + .name = "wrt400n:green:power",
  7017. + .gpio = WRT400N_GPIO_LED_POWER,
  7018. + .active_low = 1,
  7019. + }
  7020. +};
  7021. +
  7022. +static struct gpio_button wrt400n_gpio_buttons[] __initdata = {
  7023. + {
  7024. + .desc = "reset",
  7025. + .type = EV_KEY,
  7026. + .code = KEY_RESTART,
  7027. + .threshold = 3,
  7028. + .gpio = WRT400N_GPIO_BTN_RESET,
  7029. + .active_low = 1,
  7030. + } , {
  7031. + .desc = "wlsec",
  7032. + .type = EV_KEY,
  7033. + .code = KEY_WPS_BUTTON,
  7034. + .threshold = 3,
  7035. + .gpio = WRT400N_GPIO_BTN_WLSEC,
  7036. + .active_low = 1,
  7037. + }
  7038. +};
  7039. +
  7040. +static void __init wrt400n_setup(void)
  7041. +{
  7042. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  7043. + u8 mac[6];
  7044. + int i;
  7045. +
  7046. + memcpy(mac, art + WRT400N_MAC_ADDR_OFFSET, 6);
  7047. + for (i = 5; i >= 3; i--)
  7048. + if (++mac[i] != 0x00) break;
  7049. +
  7050. + ar71xx_set_mac_base(mac);
  7051. +
  7052. + ar71xx_add_device_mdio(0x0);
  7053. +
  7054. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7055. + ar71xx_eth0_data.speed = SPEED_100;
  7056. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7057. +
  7058. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  7059. + ar71xx_eth1_data.phy_mask = 0x10;
  7060. +
  7061. + ar71xx_add_device_eth(0);
  7062. + ar71xx_add_device_eth(1);
  7063. +
  7064. + ar71xx_add_device_m25p80(&wrt400n_flash_data);
  7065. +
  7066. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt400n_leds_gpio),
  7067. + wrt400n_leds_gpio);
  7068. +
  7069. + ar71xx_add_device_gpio_buttons(-1, WRT400N_BUTTONS_POLL_INTERVAL,
  7070. + ARRAY_SIZE(wrt400n_gpio_buttons),
  7071. + wrt400n_gpio_buttons);
  7072. +
  7073. + ap94_pci_init(art + WRT400N_CALDATA0_OFFSET, NULL,
  7074. + art + WRT400N_CALDATA1_OFFSET, NULL);
  7075. +}
  7076. +
  7077. +MIPS_MACHINE(AR71XX_MACH_WRT400N, "WRT400N", "Linksys WRT400N", wrt400n_setup);
  7078. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c linux-2.6.34/arch/mips/ar71xx/mach-wzr-hp-g300nh.c
  7079. --- linux-2.6.34.orig/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 1970-01-01 01:00:00.000000000 +0100
  7080. +++ linux-2.6.34/arch/mips/ar71xx/mach-wzr-hp-g300nh.c 2010-05-25 18:46:06.480978988 +0200
  7081. @@ -0,0 +1,265 @@
  7082. +/*
  7083. + * Buffalo WZR-HP-G300NH board support
  7084. + *
  7085. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  7086. + *
  7087. + * This program is free software; you can redistribute it and/or modify it
  7088. + * under the terms of the GNU General Public License version 2 as published
  7089. + * by the Free Software Foundation.
  7090. + */
  7091. +
  7092. +#include <linux/platform_device.h>
  7093. +#include <linux/mtd/mtd.h>
  7094. +#include <linux/mtd/partitions.h>
  7095. +#include <linux/nxp_74hc153.h>
  7096. +#include <linux/rtl8366s.h>
  7097. +
  7098. +#include <asm/mips_machine.h>
  7099. +#include <asm/mach-ar71xx/ar71xx.h>
  7100. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  7101. +
  7102. +#include "machtype.h"
  7103. +#include "devices.h"
  7104. +#include "dev-ar913x-wmac.h"
  7105. +#include "dev-gpio-buttons.h"
  7106. +#include "dev-leds-gpio.h"
  7107. +#include "dev-usb.h"
  7108. +
  7109. +#define WZRHPG300NH_GPIO_LED_USB 0
  7110. +#define WZRHPG300NH_GPIO_LED_DIAG 1
  7111. +#define WZRHPG300NH_GPIO_LED_WIRELESS 6
  7112. +#define WZRHPG300NH_GPIO_LED_SECURITY 17
  7113. +#define WZRHPG300NH_GPIO_LED_ROUTER 18
  7114. +
  7115. +#define WZRHPG300NH_GPIO_RTL8366_SDA 19
  7116. +#define WZRHPG300NH_GPIO_RTL8366_SCK 20
  7117. +
  7118. +#define WZRHPG300NH_GPIO_74HC153_S0 9
  7119. +#define WZRHPG300NH_GPIO_74HC153_S1 11
  7120. +#define WZRHPG300NH_GPIO_74HC153_1Y 12
  7121. +#define WZRHPG300NH_GPIO_74HC153_2Y 14
  7122. +
  7123. +#define WZRHPG300NH_GPIO_EXP_BASE 32
  7124. +#define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
  7125. +#define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
  7126. +#define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
  7127. +#define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
  7128. +#define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
  7129. +#define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
  7130. +#define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
  7131. +
  7132. +#define WZRHPG300NH_BUTTONS_POLL_INTERVAL 20
  7133. +
  7134. +#define WZRHPG300NH_MAC_OFFSET 0x20c
  7135. +
  7136. +#ifdef CONFIG_MTD_PARTITIONS
  7137. +static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
  7138. + {
  7139. + .name = "u-boot",
  7140. + .offset = 0,
  7141. + .size = 0x0040000,
  7142. + .mask_flags = MTD_WRITEABLE,
  7143. + }, {
  7144. + .name = "u-boot-env",
  7145. + .offset = 0x0040000,
  7146. + .size = 0x0020000,
  7147. + .mask_flags = MTD_WRITEABLE,
  7148. + }, {
  7149. + .name = "kernel",
  7150. + .offset = 0x0060000,
  7151. + .size = 0x0100000,
  7152. + }, {
  7153. + .name = "rootfs",
  7154. + .offset = 0x0160000,
  7155. + .size = 0x1e60000,
  7156. + }, {
  7157. + .name = "user_property",
  7158. + .offset = 0x1fc0000,
  7159. + .size = 0x0020000,
  7160. + .mask_flags = MTD_WRITEABLE,
  7161. + }, {
  7162. + .name = "art",
  7163. + .offset = 0x1fe0000,
  7164. + .size = 0x0020000,
  7165. + .mask_flags = MTD_WRITEABLE,
  7166. + }, {
  7167. + .name = "firmware",
  7168. + .offset = 0x0060000,
  7169. + .size = 0x1f60000,
  7170. + }
  7171. +};
  7172. +#endif /* CONFIG_MTD_PARTITIONS */
  7173. +
  7174. +static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
  7175. + .width = 2,
  7176. +#ifdef CONFIG_MTD_PARTITIONS
  7177. + .parts = wzrhpg300nh_flash_partitions,
  7178. + .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
  7179. +#endif
  7180. +};
  7181. +
  7182. +#define WZRHPG300NH_FLASH_BASE 0x1e000000
  7183. +#define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
  7184. +
  7185. +static struct resource wzrhpg300nh_flash_resources[] = {
  7186. + [0] = {
  7187. + .start = WZRHPG300NH_FLASH_BASE,
  7188. + .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
  7189. + .flags = IORESOURCE_MEM,
  7190. + },
  7191. +};
  7192. +
  7193. +static struct platform_device wzrhpg300nh_flash_device = {
  7194. + .name = "ar91xx-flash",
  7195. + .id = -1,
  7196. + .resource = wzrhpg300nh_flash_resources,
  7197. + .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
  7198. + .dev = {
  7199. + .platform_data = &wzrhpg300nh_flash_data,
  7200. + }
  7201. +};
  7202. +
  7203. +static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
  7204. + {
  7205. + .name = "wzr-hp-g300nh:orange:security",
  7206. + .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
  7207. + .active_low = 1,
  7208. + }, {
  7209. + .name = "wzr-hp-g300nh:green:wireless",
  7210. + .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
  7211. + .active_low = 1,
  7212. + }, {
  7213. + .name = "wzr-hp-g300nh:green:router",
  7214. + .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
  7215. + .active_low = 1,
  7216. + }, {
  7217. + .name = "wzr-hp-g300nh:red:diag",
  7218. + .gpio = WZRHPG300NH_GPIO_LED_DIAG,
  7219. + .active_low = 1,
  7220. + }, {
  7221. + .name = "wzr-hp-g300nh:blue:usb",
  7222. + .gpio = WZRHPG300NH_GPIO_LED_USB,
  7223. + .active_low = 1,
  7224. + }
  7225. +};
  7226. +
  7227. +static struct gpio_button wzrhpg300nh_gpio_buttons[] __initdata = {
  7228. + {
  7229. + .desc = "reset",
  7230. + .type = EV_KEY,
  7231. + .code = KEY_RESTART,
  7232. + .threshold = 3,
  7233. + .gpio = WZRHPG300NH_GPIO_BTN_RESET,
  7234. + .active_low = 1,
  7235. + }, {
  7236. + .desc = "aoss",
  7237. + .type = EV_KEY,
  7238. + .code = KEY_WPS_BUTTON,
  7239. + .threshold = 3,
  7240. + .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
  7241. + .active_low = 1,
  7242. + }, {
  7243. + .desc = "usb",
  7244. + .type = EV_KEY,
  7245. + .code = BTN_2,
  7246. + .threshold = 3,
  7247. + .gpio = WZRHPG300NH_GPIO_BTN_USB,
  7248. + .active_low = 1,
  7249. + }, {
  7250. + .desc = "qos_on",
  7251. + .type = EV_KEY,
  7252. + .code = BTN_3,
  7253. + .threshold = 3,
  7254. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
  7255. + .active_low = 0,
  7256. + }, {
  7257. + .desc = "qos_off",
  7258. + .type = EV_KEY,
  7259. + .code = BTN_4,
  7260. + .threshold = 3,
  7261. + .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
  7262. + .active_low = 0,
  7263. + }, {
  7264. + .desc = "router_on",
  7265. + .type = EV_KEY,
  7266. + .code = BTN_5,
  7267. + .threshold = 3,
  7268. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
  7269. + .active_low = 0,
  7270. + }, {
  7271. + .desc = "router_auto",
  7272. + .type = EV_KEY,
  7273. + .code = BTN_6,
  7274. + .threshold = 3,
  7275. + .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
  7276. + .active_low = 0,
  7277. + }
  7278. +};
  7279. +
  7280. +static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
  7281. + .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
  7282. + .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
  7283. + .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
  7284. + .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
  7285. + .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
  7286. +};
  7287. +
  7288. +static struct platform_device wzrhpg300nh_74hc153_device = {
  7289. + .name = NXP_74HC153_DRIVER_NAME,
  7290. + .id = -1,
  7291. + .dev = {
  7292. + .platform_data = &wzrhpg300nh_74hc153_data,
  7293. + }
  7294. +};
  7295. +
  7296. +static struct rtl8366s_platform_data wzrhpg300nh_rtl8366s_data = {
  7297. + .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
  7298. + .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
  7299. +};
  7300. +
  7301. +static struct platform_device wzrhpg300nh_rtl8366s_device = {
  7302. + .name = RTL8366S_DRIVER_NAME,
  7303. + .id = -1,
  7304. + .dev = {
  7305. + .platform_data = &wzrhpg300nh_rtl8366s_data,
  7306. + }
  7307. +};
  7308. +
  7309. +static void __init wzrhpg300nh_setup(void)
  7310. +{
  7311. + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  7312. +
  7313. + ar71xx_set_mac_base(eeprom + WZRHPG300NH_MAC_OFFSET);
  7314. +
  7315. + ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
  7316. + ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  7317. + ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  7318. + ar71xx_eth0_data.speed = SPEED_1000;
  7319. + ar71xx_eth0_data.duplex = DUPLEX_FULL;
  7320. +
  7321. + ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
  7322. + ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  7323. + ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  7324. + ar71xx_eth1_data.phy_mask = 0x10;
  7325. +
  7326. + ar71xx_add_device_eth(0);
  7327. + ar71xx_add_device_eth(1);
  7328. +
  7329. + ar71xx_add_device_usb();
  7330. + ar913x_add_device_wmac(eeprom, NULL);
  7331. +
  7332. + platform_device_register(&wzrhpg300nh_74hc153_device);
  7333. + platform_device_register(&wzrhpg300nh_flash_device);
  7334. + platform_device_register(&wzrhpg300nh_rtl8366s_device);
  7335. +
  7336. + ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
  7337. + wzrhpg300nh_leds_gpio);
  7338. +
  7339. + ar71xx_add_device_gpio_buttons(-1, WZRHPG300NH_BUTTONS_POLL_INTERVAL,
  7340. + ARRAY_SIZE(wzrhpg300nh_gpio_buttons),
  7341. + wzrhpg300nh_gpio_buttons);
  7342. +
  7343. +}
  7344. +
  7345. +MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
  7346. + "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);
  7347. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/Makefile linux-2.6.34/arch/mips/ar71xx/Makefile
  7348. --- linux-2.6.34.orig/arch/mips/ar71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  7349. +++ linux-2.6.34/arch/mips/ar71xx/Makefile 2010-05-25 18:46:06.523464007 +0200
  7350. @@ -0,0 +1,54 @@
  7351. +#
  7352. +# Makefile for the Atheros AR71xx SoC specific parts of the kernel
  7353. +#
  7354. +# Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7355. +# Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7356. +#
  7357. +# This program is free software; you can redistribute it and/or modify it
  7358. +# under the terms of the GNU General Public License version 2 as published
  7359. +# by the Free Software Foundation.
  7360. +
  7361. +obj-y := prom.o irq.o setup.o devices.o gpio.o ar71xx.o
  7362. +
  7363. +obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  7364. +obj-$(CONFIG_PCI) += pci.o
  7365. +
  7366. +obj-$(CONFIG_AR71XX_DEV_AP91_ETH) += dev-ap91-eth.o
  7367. +obj-$(CONFIG_AR71XX_DEV_AP91_PCI) += dev-ap91-pci.o
  7368. +obj-$(CONFIG_AR71XX_DEV_AP94_PCI) += dev-ap94-pci.o
  7369. +obj-$(CONFIG_AR71XX_DEV_AR913X_WMAC) += dev-ar913x-wmac.o
  7370. +obj-$(CONFIG_AR71XX_DEV_DSA) += dev-dsa.o
  7371. +obj-$(CONFIG_AR71XX_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o
  7372. +obj-$(CONFIG_AR71XX_DEV_LEDS_GPIO) += dev-leds-gpio.o
  7373. +obj-$(CONFIG_AR71XX_DEV_M25P80) += dev-m25p80.o
  7374. +obj-$(CONFIG_AR71XX_DEV_PB42_PCI) += dev-pb42-pci.o
  7375. +obj-$(CONFIG_AR71XX_DEV_PB9X_PCI) += dev-pb9x-pci.o
  7376. +obj-$(CONFIG_AR71XX_DEV_USB) += dev-usb.o
  7377. +
  7378. +obj-$(CONFIG_AR71XX_NVRAM) += nvram.o
  7379. +
  7380. +obj-$(CONFIG_AR71XX_MACH_AP81) += mach-ap81.o
  7381. +obj-$(CONFIG_AR71XX_MACH_AP83) += mach-ap83.o
  7382. +obj-$(CONFIG_AR71XX_MACH_AW_NR580) += mach-aw-nr580.o
  7383. +obj-$(CONFIG_AR71XX_MACH_DIR_600_A1) += mach-dir-600-a1.o
  7384. +obj-$(CONFIG_AR71XX_MACH_DIR_615_C1) += mach-dir-615-c1.o
  7385. +obj-$(CONFIG_AR71XX_MACH_DIR_825_B1) += mach-dir-825-b1.o
  7386. +obj-$(CONFIG_AR71XX_MACH_MZK_W04NU) += mach-mzk-w04nu.o
  7387. +obj-$(CONFIG_AR71XX_MACH_MZK_W300NH) += mach-mzk-w300nh.o
  7388. +obj-$(CONFIG_AR71XX_MACH_NBG460N) += mach-nbg460n.o
  7389. +obj-$(CONFIG_AR71XX_MACH_PB42) += mach-pb42.o
  7390. +obj-$(CONFIG_AR71XX_MACH_PB44) += mach-pb44.o
  7391. +obj-$(CONFIG_AR71XX_MACH_PB92) += mach-pb92.o
  7392. +obj-$(CONFIG_AR71XX_MACH_RB4XX) += mach-rb4xx.o
  7393. +obj-$(CONFIG_AR71XX_MACH_RB750) += mach-rb750.o
  7394. +obj-$(CONFIG_AR71XX_MACH_TEW_632BRP) += mach-tew-632brp.o
  7395. +obj-$(CONFIG_AR71XX_MACH_TL_WR741ND) += mach-tl-wr741nd.o
  7396. +obj-$(CONFIG_AR71XX_MACH_TL_WR841N_V1) += mach-tl-wr841n.o
  7397. +obj-$(CONFIG_AR71XX_MACH_TL_WR941ND) += mach-tl-wr941nd.o
  7398. +obj-$(CONFIG_AR71XX_MACH_TL_WR1043ND) += mach-tl-wr1043nd.o
  7399. +obj-$(CONFIG_AR71XX_MACH_UBNT) += mach-ubnt.o
  7400. +obj-$(CONFIG_AR71XX_MACH_WNDR3700) += mach-wndr3700.o
  7401. +obj-$(CONFIG_AR71XX_MACH_WNR2000) += mach-wnr2000.o
  7402. +obj-$(CONFIG_AR71XX_MACH_WP543) += mach-wp543.o
  7403. +obj-$(CONFIG_AR71XX_MACH_WRT160NL) += mach-wrt160nl.o
  7404. +obj-$(CONFIG_AR71XX_MACH_WRT400N) += mach-wrt400n.o
  7405. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/nvram.c linux-2.6.34/arch/mips/ar71xx/nvram.c
  7406. --- linux-2.6.34.orig/arch/mips/ar71xx/nvram.c 1970-01-01 01:00:00.000000000 +0100
  7407. +++ linux-2.6.34/arch/mips/ar71xx/nvram.c 2010-05-25 18:46:06.563464058 +0200
  7408. @@ -0,0 +1,75 @@
  7409. +/*
  7410. + * Atheros AR71xx minimal nvram support
  7411. + *
  7412. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7413. + *
  7414. + * This program is free software; you can redistribute it and/or modify it
  7415. + * under the terms of the GNU General Public License version 2 as published
  7416. + * by the Free Software Foundation.
  7417. + */
  7418. +
  7419. +#include <linux/kernel.h>
  7420. +#include <linux/vmalloc.h>
  7421. +#include <linux/errno.h>
  7422. +#include <linux/init.h>
  7423. +#include <linux/string.h>
  7424. +
  7425. +#include "nvram.h"
  7426. +
  7427. +char *nvram_find_var(const char *name, const char *buf, unsigned buf_len)
  7428. +{
  7429. + unsigned len = strlen(name);
  7430. + char *cur, *last;
  7431. +
  7432. + if (buf_len == 0 || len == 0)
  7433. + return NULL;
  7434. +
  7435. + if (buf_len < len)
  7436. + return NULL;
  7437. +
  7438. + if (len == 1)
  7439. + return memchr(buf, (int) *name, buf_len);
  7440. +
  7441. + last = (char *) buf + buf_len - len;
  7442. + for (cur = (char *) buf; cur <= last; cur++)
  7443. + if (cur[0] == name[0] && memcmp(cur, name, len) == 0)
  7444. + return cur + len;
  7445. +
  7446. + return NULL;
  7447. +}
  7448. +
  7449. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  7450. + const char *name, char *mac)
  7451. +{
  7452. + char *buf;
  7453. + char *mac_str;
  7454. + int ret;
  7455. + int t;
  7456. +
  7457. + buf = vmalloc(nvram_len);
  7458. + if (!buf)
  7459. + return -ENOMEM;
  7460. +
  7461. + memcpy(buf, nvram, nvram_len);
  7462. + buf[nvram_len - 1] = '\0';
  7463. +
  7464. + mac_str = nvram_find_var(name, buf, nvram_len);
  7465. + if (!mac_str) {
  7466. + ret = -EINVAL;
  7467. + goto free;
  7468. + }
  7469. +
  7470. + t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
  7471. + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
  7472. +
  7473. + if (t != 6) {
  7474. + ret = -EINVAL;
  7475. + goto free;
  7476. + }
  7477. +
  7478. + ret = 0;
  7479. +
  7480. + free:
  7481. + vfree(buf);
  7482. + return ret;
  7483. +}
  7484. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/nvram.h linux-2.6.34/arch/mips/ar71xx/nvram.h
  7485. --- linux-2.6.34.orig/arch/mips/ar71xx/nvram.h 1970-01-01 01:00:00.000000000 +0100
  7486. +++ linux-2.6.34/arch/mips/ar71xx/nvram.h 2010-05-25 18:46:06.602223088 +0200
  7487. @@ -0,0 +1,19 @@
  7488. +/*
  7489. + * Atheros AR71xx minimal nvram support
  7490. + *
  7491. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  7492. + *
  7493. + * This program is free software; you can redistribute it and/or modify it
  7494. + * under the terms of the GNU General Public License version 2 as published
  7495. + * by the Free Software Foundation.
  7496. + */
  7497. +
  7498. +#ifndef _AR71XX_NVRAM_H
  7499. +#define _AR71XX_NVRAM_H
  7500. +
  7501. +char *nvram_find_var(const char *name, const char *buf,
  7502. + unsigned buf_len) __init;
  7503. +int nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
  7504. + const char *name, char *mac) __init;
  7505. +
  7506. +#endif /* _AR71XX_NVRAM_H */
  7507. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/pci.c linux-2.6.34/arch/mips/ar71xx/pci.c
  7508. --- linux-2.6.34.orig/arch/mips/ar71xx/pci.c 1970-01-01 01:00:00.000000000 +0100
  7509. +++ linux-2.6.34/arch/mips/ar71xx/pci.c 2010-05-25 18:46:06.641506945 +0200
  7510. @@ -0,0 +1,93 @@
  7511. +/*
  7512. + * Atheros AR71xx PCI setup code
  7513. + *
  7514. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7515. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7516. + *
  7517. + * Parts of this file are based on Atheros' 2.6.15 BSP
  7518. + *
  7519. + * This program is free software; you can redistribute it and/or modify it
  7520. + * under the terms of the GNU General Public License version 2 as published
  7521. + * by the Free Software Foundation.
  7522. + */
  7523. +
  7524. +#include <linux/kernel.h>
  7525. +
  7526. +#include <asm/traps.h>
  7527. +
  7528. +#include <asm/mach-ar71xx/ar71xx.h>
  7529. +#include <asm/mach-ar71xx/pci.h>
  7530. +
  7531. +unsigned ar71xx_pci_nr_irqs __initdata;
  7532. +struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  7533. +
  7534. +int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  7535. +
  7536. +static int ar71xx_be_handler(struct pt_regs *regs, int is_fixup)
  7537. +{
  7538. + int err = 0;
  7539. +
  7540. + err = ar71xx_pci_be_handler(is_fixup);
  7541. +
  7542. + return (is_fixup && !err) ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
  7543. +}
  7544. +
  7545. +int pcibios_plat_dev_init(struct pci_dev *dev)
  7546. +{
  7547. + if (ar71xx_pci_plat_dev_init)
  7548. + return ar71xx_pci_plat_dev_init(dev);
  7549. +
  7550. + return 0;
  7551. +}
  7552. +
  7553. +int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  7554. +{
  7555. + int ret = 0;
  7556. +
  7557. + switch (ar71xx_soc) {
  7558. + case AR71XX_SOC_AR7130:
  7559. + case AR71XX_SOC_AR7141:
  7560. + case AR71XX_SOC_AR7161:
  7561. + ret = ar71xx_pcibios_map_irq(dev, slot, pin);
  7562. + break;
  7563. +
  7564. + case AR71XX_SOC_AR7240:
  7565. + case AR71XX_SOC_AR7241:
  7566. + case AR71XX_SOC_AR7242:
  7567. + ret = ar724x_pcibios_map_irq(dev, slot, pin);
  7568. + break;
  7569. +
  7570. + default:
  7571. + break;
  7572. + }
  7573. +
  7574. + return ret;
  7575. +}
  7576. +
  7577. +int __init ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map)
  7578. +{
  7579. + int ret = 0;
  7580. +
  7581. + switch (ar71xx_soc) {
  7582. + case AR71XX_SOC_AR7130:
  7583. + case AR71XX_SOC_AR7141:
  7584. + case AR71XX_SOC_AR7161:
  7585. + board_be_handler = ar71xx_be_handler;
  7586. + ret = ar71xx_pcibios_init();
  7587. + break;
  7588. +
  7589. + case AR71XX_SOC_AR7240:
  7590. + case AR71XX_SOC_AR7241:
  7591. + case AR71XX_SOC_AR7242:
  7592. + ret = ar724x_pcibios_init();
  7593. + break;
  7594. +
  7595. + default:
  7596. + return 0;
  7597. + }
  7598. +
  7599. + ar71xx_pci_nr_irqs = nr_irqs;
  7600. + ar71xx_pci_irq_map = map;
  7601. +
  7602. + return ret;
  7603. +}
  7604. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/prom.c linux-2.6.34/arch/mips/ar71xx/prom.c
  7605. --- linux-2.6.34.orig/arch/mips/ar71xx/prom.c 1970-01-01 01:00:00.000000000 +0100
  7606. +++ linux-2.6.34/arch/mips/ar71xx/prom.c 2010-05-25 18:46:06.682223087 +0200
  7607. @@ -0,0 +1,105 @@
  7608. +/*
  7609. + * Atheros AR71xx SoC specific prom routines
  7610. + *
  7611. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7612. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7613. + *
  7614. + * This program is free software; you can redistribute it and/or modify it
  7615. + * under the terms of the GNU General Public License version 2 as published
  7616. + * by the Free Software Foundation.
  7617. + */
  7618. +
  7619. +#include <linux/kernel.h>
  7620. +#include <linux/init.h>
  7621. +#include <linux/io.h>
  7622. +#include <linux/string.h>
  7623. +
  7624. +#include <asm/bootinfo.h>
  7625. +#include <asm/addrspace.h>
  7626. +
  7627. +#include <asm/mach-ar71xx/ar71xx.h>
  7628. +
  7629. +static inline int is_valid_ram_addr(void *addr)
  7630. +{
  7631. + if (((u32) addr > KSEG0) &&
  7632. + ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
  7633. + return 1;
  7634. +
  7635. + if (((u32) addr > KSEG1) &&
  7636. + ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
  7637. + return 1;
  7638. +
  7639. + return 0;
  7640. +}
  7641. +
  7642. +static void __init ar71xx_prom_append_cmdline(const char *name,
  7643. + const char *value)
  7644. +{
  7645. + char buf[COMMAND_LINE_SIZE];
  7646. +
  7647. + snprintf(buf, sizeof(buf), " %s=%s", name, value);
  7648. + strlcat(arcs_cmdline, buf, sizeof(arcs_cmdline));
  7649. +}
  7650. +
  7651. +static void __init ar71xx_prom_find_env(char **envp, const char *name)
  7652. +{
  7653. + int len = strlen(name);
  7654. + char **p;
  7655. +
  7656. + if (!is_valid_ram_addr(envp))
  7657. + return;
  7658. +
  7659. + for (p = envp; is_valid_ram_addr(*p); p++) {
  7660. + if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') {
  7661. + ar71xx_prom_append_cmdline(name, *p + len + 1);
  7662. + break;
  7663. + }
  7664. +
  7665. + /* RedBoot env comes in pointer pairs - key, value */
  7666. + if (strncmp(name, *p, len) == 0 && (*p)[len] == 0)
  7667. + if (is_valid_ram_addr(*(++p))) {
  7668. + ar71xx_prom_append_cmdline(name, *p);
  7669. + break;
  7670. + }
  7671. + }
  7672. +}
  7673. +
  7674. +static int inline ar71xx_use__image_cmdline(void) { return 0; }
  7675. +
  7676. +static __init void ar71xx_prom_init_cmdline(int argc, char **argv)
  7677. +{
  7678. + int i;
  7679. +
  7680. + if (ar71xx_use__image_cmdline())
  7681. + return;
  7682. +
  7683. + if (!is_valid_ram_addr(argv))
  7684. + return;
  7685. +
  7686. + for (i = 0; i < argc; i++)
  7687. + if (is_valid_ram_addr(argv[i])) {
  7688. + strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
  7689. + strlcat(arcs_cmdline, argv[i], sizeof(arcs_cmdline));
  7690. + }
  7691. +}
  7692. +
  7693. +void __init prom_init(void)
  7694. +{
  7695. + char **envp;
  7696. +
  7697. + printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
  7698. + "fw_arg2=%08x, fw_arg3=%08x\n",
  7699. + (unsigned int)fw_arg0, (unsigned int)fw_arg1,
  7700. + (unsigned int)fw_arg2, (unsigned int)fw_arg3);
  7701. +
  7702. +
  7703. + ar71xx_prom_init_cmdline(fw_arg0, (char **)fw_arg1);
  7704. +
  7705. + envp = (char **)fw_arg2;
  7706. + ar71xx_prom_find_env(envp, "board");
  7707. +}
  7708. +
  7709. +void __init prom_free_prom_memory(void)
  7710. +{
  7711. + /* We do not have to prom memory to free */
  7712. +}
  7713. diff -Nur linux-2.6.34.orig/arch/mips/ar71xx/setup.c linux-2.6.34/arch/mips/ar71xx/setup.c
  7714. --- linux-2.6.34.orig/arch/mips/ar71xx/setup.c 1970-01-01 01:00:00.000000000 +0100
  7715. +++ linux-2.6.34/arch/mips/ar71xx/setup.c 2010-05-25 18:46:06.747917885 +0200
  7716. @@ -0,0 +1,310 @@
  7717. +/*
  7718. + * Atheros AR71xx SoC specific setup
  7719. + *
  7720. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  7721. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7722. + *
  7723. + * Parts of this file are based on Atheros' 2.6.15 BSP
  7724. + *
  7725. + * This program is free software; you can redistribute it and/or modify it
  7726. + * under the terms of the GNU General Public License version 2 as published
  7727. + * by the Free Software Foundation.
  7728. + */
  7729. +
  7730. +#include <linux/kernel.h>
  7731. +#include <linux/init.h>
  7732. +#include <linux/bootmem.h>
  7733. +
  7734. +#include <asm/bootinfo.h>
  7735. +#include <asm/time.h> /* for mips_hpt_frequency */
  7736. +#include <asm/reboot.h> /* for _machine_{restart,halt} */
  7737. +#include <asm/mips_machine.h>
  7738. +
  7739. +#include <asm/mach-ar71xx/ar71xx.h>
  7740. +
  7741. +#include "machtype.h"
  7742. +#include "devices.h"
  7743. +
  7744. +#define AR71XX_SYS_TYPE_LEN 64
  7745. +#define AR71XX_BASE_FREQ 40000000
  7746. +#define AR91XX_BASE_FREQ 5000000
  7747. +#define AR724X_BASE_FREQ 5000000
  7748. +
  7749. +u32 ar71xx_cpu_freq;
  7750. +EXPORT_SYMBOL_GPL(ar71xx_cpu_freq);
  7751. +
  7752. +u32 ar71xx_ahb_freq;
  7753. +EXPORT_SYMBOL_GPL(ar71xx_ahb_freq);
  7754. +
  7755. +u32 ar71xx_ddr_freq;
  7756. +EXPORT_SYMBOL_GPL(ar71xx_ddr_freq);
  7757. +
  7758. +enum ar71xx_soc_type ar71xx_soc;
  7759. +EXPORT_SYMBOL_GPL(ar71xx_soc);
  7760. +
  7761. +static char ar71xx_sys_type[AR71XX_SYS_TYPE_LEN];
  7762. +
  7763. +static void ar71xx_restart(char *command)
  7764. +{
  7765. + ar71xx_device_stop(RESET_MODULE_FULL_CHIP);
  7766. + for (;;)
  7767. + if (cpu_wait)
  7768. + cpu_wait();
  7769. +}
  7770. +
  7771. +static void ar71xx_halt(void)
  7772. +{
  7773. + while (1)
  7774. + cpu_wait();
  7775. +}
  7776. +
  7777. +static void __init ar71xx_detect_mem_size(void)
  7778. +{
  7779. + unsigned long size;
  7780. +
  7781. + for (size = AR71XX_MEM_SIZE_MIN; size < AR71XX_MEM_SIZE_MAX;
  7782. + size <<= 1 ) {
  7783. + if (!memcmp(ar71xx_detect_mem_size,
  7784. + ar71xx_detect_mem_size + size, 1024))
  7785. + break;
  7786. + }
  7787. +
  7788. + add_memory_region(0, size, BOOT_MEM_RAM);
  7789. +}
  7790. +
  7791. +static void __init ar71xx_detect_sys_type(void)
  7792. +{
  7793. + char *chip = "????";
  7794. + u32 id;
  7795. + u32 major;
  7796. + u32 minor;
  7797. + u32 rev = 0;
  7798. +
  7799. + id = ar71xx_reset_rr(AR71XX_RESET_REG_REV_ID);
  7800. + major = id & REV_ID_MAJOR_MASK;
  7801. +
  7802. + switch (major) {
  7803. + case REV_ID_MAJOR_AR71XX:
  7804. + minor = id & AR71XX_REV_ID_MINOR_MASK;
  7805. + rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  7806. + rev &= AR71XX_REV_ID_REVISION_MASK;
  7807. + switch (minor) {
  7808. + case AR71XX_REV_ID_MINOR_AR7130:
  7809. + ar71xx_soc = AR71XX_SOC_AR7130;
  7810. + chip = "7130";
  7811. + break;
  7812. +
  7813. + case AR71XX_REV_ID_MINOR_AR7141:
  7814. + ar71xx_soc = AR71XX_SOC_AR7141;
  7815. + chip = "7141";
  7816. + break;
  7817. +
  7818. + case AR71XX_REV_ID_MINOR_AR7161:
  7819. + ar71xx_soc = AR71XX_SOC_AR7161;
  7820. + chip = "7161";
  7821. + break;
  7822. + }
  7823. + break;
  7824. +
  7825. + case REV_ID_MAJOR_AR7240:
  7826. + ar71xx_soc = AR71XX_SOC_AR7240;
  7827. + chip = "7240";
  7828. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7829. + break;
  7830. +
  7831. + case REV_ID_MAJOR_AR7241:
  7832. + ar71xx_soc = AR71XX_SOC_AR7241;
  7833. + chip = "7241";
  7834. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7835. + break;
  7836. +
  7837. + case REV_ID_MAJOR_AR7242:
  7838. + ar71xx_soc = AR71XX_SOC_AR7242;
  7839. + chip = "7242";
  7840. + rev = (id & AR724X_REV_ID_REVISION_MASK);
  7841. + break;
  7842. +
  7843. + case REV_ID_MAJOR_AR913X:
  7844. + minor = id & AR91XX_REV_ID_MINOR_MASK;
  7845. + rev = id >> AR91XX_REV_ID_REVISION_SHIFT;
  7846. + rev &= AR91XX_REV_ID_REVISION_MASK;
  7847. + switch (minor) {
  7848. + case AR91XX_REV_ID_MINOR_AR9130:
  7849. + ar71xx_soc = AR71XX_SOC_AR9130;
  7850. + chip = "9130";
  7851. + break;
  7852. +
  7853. + case AR91XX_REV_ID_MINOR_AR9132:
  7854. + ar71xx_soc = AR71XX_SOC_AR9132;
  7855. + chip = "9132";
  7856. + break;
  7857. + }
  7858. + break;
  7859. +
  7860. + default:
  7861. + panic("ar71xx: unknown chip id:0x%08x\n", id);
  7862. + }
  7863. +
  7864. + sprintf(ar71xx_sys_type, "Atheros AR%s rev %u", chip, rev);
  7865. +}
  7866. +
  7867. +static void __init ar91xx_detect_sys_frequency(void)
  7868. +{
  7869. + u32 pll;
  7870. + u32 freq;
  7871. + u32 div;
  7872. +
  7873. + pll = ar71xx_pll_rr(AR91XX_PLL_REG_CPU_CONFIG);
  7874. +
  7875. + div = ((pll >> AR91XX_PLL_DIV_SHIFT) & AR91XX_PLL_DIV_MASK);
  7876. + freq = div * AR91XX_BASE_FREQ;
  7877. +
  7878. + ar71xx_cpu_freq = freq;
  7879. +
  7880. + div = ((pll >> AR91XX_DDR_DIV_SHIFT) & AR91XX_DDR_DIV_MASK) + 1;
  7881. + ar71xx_ddr_freq = freq / div;
  7882. +
  7883. + div = (((pll >> AR91XX_AHB_DIV_SHIFT) & AR91XX_AHB_DIV_MASK) + 1) * 2;
  7884. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7885. +}
  7886. +
  7887. +static void __init ar71xx_detect_sys_frequency(void)
  7888. +{
  7889. + u32 pll;
  7890. + u32 freq;
  7891. + u32 div;
  7892. +
  7893. + pll = ar71xx_pll_rr(AR71XX_PLL_REG_CPU_CONFIG);
  7894. +
  7895. + div = ((pll >> AR71XX_PLL_DIV_SHIFT) & AR71XX_PLL_DIV_MASK) + 1;
  7896. + freq = div * AR71XX_BASE_FREQ;
  7897. +
  7898. + div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1;
  7899. + ar71xx_cpu_freq = freq / div;
  7900. +
  7901. + div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1;
  7902. + ar71xx_ddr_freq = freq / div;
  7903. +
  7904. + div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  7905. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7906. +}
  7907. +
  7908. +static void __init ar724x_detect_sys_frequency(void)
  7909. +{
  7910. + u32 pll;
  7911. + u32 freq;
  7912. + u32 div;
  7913. +
  7914. + pll = ar71xx_pll_rr(AR724X_PLL_REG_CPU_CONFIG);
  7915. +
  7916. + div = ((pll >> AR724X_PLL_DIV_SHIFT) & AR724X_PLL_DIV_MASK);
  7917. + freq = div * AR724X_BASE_FREQ;
  7918. +
  7919. + div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK);
  7920. + freq *= div;
  7921. +
  7922. + ar71xx_cpu_freq = freq;
  7923. +
  7924. + div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  7925. + ar71xx_ddr_freq = freq / div;
  7926. +
  7927. + div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  7928. + ar71xx_ahb_freq = ar71xx_cpu_freq / div;
  7929. +}
  7930. +
  7931. +static void __init detect_sys_frequency(void)
  7932. +{
  7933. + switch (ar71xx_soc) {
  7934. + case AR71XX_SOC_AR7130:
  7935. + case AR71XX_SOC_AR7141:
  7936. + case AR71XX_SOC_AR7161:
  7937. + ar71xx_detect_sys_frequency();
  7938. + break;
  7939. +
  7940. + case AR71XX_SOC_AR7240:
  7941. + case AR71XX_SOC_AR7241:
  7942. + case AR71XX_SOC_AR7242:
  7943. + ar724x_detect_sys_frequency();
  7944. + break;
  7945. +
  7946. + case AR71XX_SOC_AR9130:
  7947. + case AR71XX_SOC_AR9132:
  7948. + ar91xx_detect_sys_frequency();
  7949. + break;
  7950. +
  7951. + default:
  7952. + BUG();
  7953. + }
  7954. +}
  7955. +
  7956. +const char *get_system_type(void)
  7957. +{
  7958. + return ar71xx_sys_type;
  7959. +}
  7960. +
  7961. +unsigned int __cpuinit get_c0_compare_irq(void)
  7962. +{
  7963. + return CP0_LEGACY_COMPARE_IRQ;
  7964. +}
  7965. +
  7966. +void __init plat_mem_setup(void)
  7967. +{
  7968. + set_io_port_base(KSEG1);
  7969. +
  7970. + ar71xx_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  7971. + AR71XX_DDR_CTRL_SIZE);
  7972. +
  7973. + ar71xx_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  7974. + AR71XX_PLL_SIZE);
  7975. +
  7976. + ar71xx_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  7977. + AR71XX_RESET_SIZE);
  7978. +
  7979. + ar71xx_gpio_base = ioremap_nocache(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
  7980. +
  7981. + ar71xx_usb_ctrl_base = ioremap_nocache(AR71XX_USB_CTRL_BASE,
  7982. + AR71XX_USB_CTRL_SIZE);
  7983. +
  7984. + ar71xx_detect_mem_size();
  7985. + ar71xx_detect_sys_type();
  7986. + detect_sys_frequency();
  7987. +
  7988. + printk(KERN_INFO
  7989. + "%s, CPU:%u.%03u MHz, AHB:%u.%03u MHz, DDR:%u.%03u MHz\n",
  7990. + ar71xx_sys_type,
  7991. + ar71xx_cpu_freq / 1000000, (ar71xx_cpu_freq / 1000) % 1000,
  7992. + ar71xx_ahb_freq / 1000000, (ar71xx_ahb_freq / 1000) % 1000,
  7993. + ar71xx_ddr_freq / 1000000, (ar71xx_ddr_freq / 1000) % 1000);
  7994. +
  7995. + _machine_restart = ar71xx_restart;
  7996. + _machine_halt = ar71xx_halt;
  7997. + pm_power_off = ar71xx_halt;
  7998. +}
  7999. +
  8000. +void __init plat_time_init(void)
  8001. +{
  8002. + mips_hpt_frequency = ar71xx_cpu_freq / 2;
  8003. +}
  8004. +
  8005. +__setup("board=", mips_machtype_setup);
  8006. +
  8007. +static int __init ar71xx_machine_setup(void)
  8008. +{
  8009. + ar71xx_gpio_init();
  8010. +
  8011. + ar71xx_add_device_uart();
  8012. + ar71xx_add_device_wdt();
  8013. +
  8014. + mips_machine_setup();
  8015. + return 0;
  8016. +}
  8017. +
  8018. +arch_initcall(ar71xx_machine_setup);
  8019. +
  8020. +static void __init ar71xx_generic_init(void)
  8021. +{
  8022. + /* Nothing to do */
  8023. +}
  8024. +
  8025. +MIPS_MACHINE(AR71XX_MACH_GENERIC, "Generic", "Generic AR71xx board",
  8026. + ar71xx_generic_init);
  8027. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/ar71xx.h
  8028. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/ar71xx.h 1970-01-01 01:00:00.000000000 +0100
  8029. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/ar71xx.h 2010-05-25 18:46:06.783464047 +0200
  8030. @@ -0,0 +1,514 @@
  8031. +/*
  8032. + * Atheros AR71xx SoC specific definitions
  8033. + *
  8034. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8035. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8036. + *
  8037. + * Parts of this file are based on Atheros' 2.6.15 BSP
  8038. + *
  8039. + * This program is free software; you can redistribute it and/or modify it
  8040. + * under the terms of the GNU General Public License version 2 as published
  8041. + * by the Free Software Foundation.
  8042. + */
  8043. +
  8044. +#ifndef __ASM_MACH_AR71XX_H
  8045. +#define __ASM_MACH_AR71XX_H
  8046. +
  8047. +#include <linux/types.h>
  8048. +#include <linux/init.h>
  8049. +#include <linux/io.h>
  8050. +#include <linux/bitops.h>
  8051. +
  8052. +#ifndef __ASSEMBLER__
  8053. +
  8054. +#define AR71XX_PCI_MEM_BASE 0x10000000
  8055. +#define AR71XX_PCI_MEM_SIZE 0x08000000
  8056. +#define AR71XX_APB_BASE 0x18000000
  8057. +#define AR71XX_GE0_BASE 0x19000000
  8058. +#define AR71XX_GE0_SIZE 0x01000000
  8059. +#define AR71XX_GE1_BASE 0x1a000000
  8060. +#define AR71XX_GE1_SIZE 0x01000000
  8061. +#define AR71XX_EHCI_BASE 0x1b000000
  8062. +#define AR71XX_EHCI_SIZE 0x01000000
  8063. +#define AR71XX_OHCI_BASE 0x1c000000
  8064. +#define AR71XX_OHCI_SIZE 0x01000000
  8065. +#define AR7240_OHCI_BASE 0x1b000000
  8066. +#define AR7240_OHCI_SIZE 0x01000000
  8067. +#define AR71XX_SPI_BASE 0x1f000000
  8068. +#define AR71XX_SPI_SIZE 0x01000000
  8069. +
  8070. +#define AR71XX_DDR_CTRL_BASE (AR71XX_APB_BASE + 0x00000000)
  8071. +#define AR71XX_DDR_CTRL_SIZE 0x10000
  8072. +#define AR71XX_CPU_BASE (AR71XX_APB_BASE + 0x00010000)
  8073. +#define AR71XX_UART_BASE (AR71XX_APB_BASE + 0x00020000)
  8074. +#define AR71XX_UART_SIZE 0x10000
  8075. +#define AR71XX_USB_CTRL_BASE (AR71XX_APB_BASE + 0x00030000)
  8076. +#define AR71XX_USB_CTRL_SIZE 0x10000
  8077. +#define AR71XX_GPIO_BASE (AR71XX_APB_BASE + 0x00040000)
  8078. +#define AR71XX_GPIO_SIZE 0x10000
  8079. +#define AR71XX_PLL_BASE (AR71XX_APB_BASE + 0x00050000)
  8080. +#define AR71XX_PLL_SIZE 0x10000
  8081. +#define AR71XX_RESET_BASE (AR71XX_APB_BASE + 0x00060000)
  8082. +#define AR71XX_RESET_SIZE 0x10000
  8083. +#define AR71XX_MII_BASE (AR71XX_APB_BASE + 0x00070000)
  8084. +#define AR71XX_MII_SIZE 0x10000
  8085. +#define AR71XX_SLIC_BASE (AR71XX_APB_BASE + 0x00090000)
  8086. +#define AR71XX_SLIC_SIZE 0x10000
  8087. +#define AR71XX_DMA_BASE (AR71XX_APB_BASE + 0x000A0000)
  8088. +#define AR71XX_DMA_SIZE 0x10000
  8089. +#define AR71XX_STEREO_BASE (AR71XX_APB_BASE + 0x000B0000)
  8090. +#define AR71XX_STEREO_SIZE 0x10000
  8091. +
  8092. +#define AR724X_PCI_CRP_BASE (AR71XX_APB_BASE + 0x000C0000)
  8093. +#define AR724X_PCI_CRP_SIZE 0x100
  8094. +
  8095. +#define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000F0000)
  8096. +#define AR724X_PCI_CTRL_SIZE 0x100
  8097. +
  8098. +#define AR91XX_WMAC_BASE (AR71XX_APB_BASE + 0x000C0000)
  8099. +#define AR91XX_WMAC_SIZE 0x30000
  8100. +
  8101. +#define AR71XX_MEM_SIZE_MIN 0x0200000
  8102. +#define AR71XX_MEM_SIZE_MAX 0x10000000
  8103. +
  8104. +#define AR71XX_CPU_IRQ_BASE 0
  8105. +#define AR71XX_MISC_IRQ_BASE 8
  8106. +#define AR71XX_MISC_IRQ_COUNT 8
  8107. +#define AR71XX_GPIO_IRQ_BASE 16
  8108. +#define AR71XX_GPIO_IRQ_COUNT 32
  8109. +#define AR71XX_PCI_IRQ_BASE 48
  8110. +#define AR71XX_PCI_IRQ_COUNT 8
  8111. +
  8112. +#define AR71XX_CPU_IRQ_IP2 (AR71XX_CPU_IRQ_BASE + 2)
  8113. +#define AR71XX_CPU_IRQ_USB (AR71XX_CPU_IRQ_BASE + 3)
  8114. +#define AR71XX_CPU_IRQ_GE0 (AR71XX_CPU_IRQ_BASE + 4)
  8115. +#define AR71XX_CPU_IRQ_GE1 (AR71XX_CPU_IRQ_BASE + 5)
  8116. +#define AR71XX_CPU_IRQ_MISC (AR71XX_CPU_IRQ_BASE + 6)
  8117. +#define AR71XX_CPU_IRQ_TIMER (AR71XX_CPU_IRQ_BASE + 7)
  8118. +
  8119. +#define AR71XX_MISC_IRQ_TIMER (AR71XX_MISC_IRQ_BASE + 0)
  8120. +#define AR71XX_MISC_IRQ_ERROR (AR71XX_MISC_IRQ_BASE + 1)
  8121. +#define AR71XX_MISC_IRQ_GPIO (AR71XX_MISC_IRQ_BASE + 2)
  8122. +#define AR71XX_MISC_IRQ_UART (AR71XX_MISC_IRQ_BASE + 3)
  8123. +#define AR71XX_MISC_IRQ_WDOG (AR71XX_MISC_IRQ_BASE + 4)
  8124. +#define AR71XX_MISC_IRQ_PERFC (AR71XX_MISC_IRQ_BASE + 5)
  8125. +#define AR71XX_MISC_IRQ_OHCI (AR71XX_MISC_IRQ_BASE + 6)
  8126. +#define AR71XX_MISC_IRQ_DMA (AR71XX_MISC_IRQ_BASE + 7)
  8127. +
  8128. +#define AR71XX_GPIO_IRQ(_x) (AR71XX_GPIO_IRQ_BASE + (_x))
  8129. +
  8130. +#define AR71XX_PCI_IRQ_DEV0 (AR71XX_PCI_IRQ_BASE + 0)
  8131. +#define AR71XX_PCI_IRQ_DEV1 (AR71XX_PCI_IRQ_BASE + 1)
  8132. +#define AR71XX_PCI_IRQ_DEV2 (AR71XX_PCI_IRQ_BASE + 2)
  8133. +#define AR71XX_PCI_IRQ_CORE (AR71XX_PCI_IRQ_BASE + 4)
  8134. +
  8135. +extern u32 ar71xx_ahb_freq;
  8136. +extern u32 ar71xx_cpu_freq;
  8137. +extern u32 ar71xx_ddr_freq;
  8138. +
  8139. +enum ar71xx_soc_type {
  8140. + AR71XX_SOC_UNKNOWN,
  8141. + AR71XX_SOC_AR7130,
  8142. + AR71XX_SOC_AR7141,
  8143. + AR71XX_SOC_AR7161,
  8144. + AR71XX_SOC_AR7240,
  8145. + AR71XX_SOC_AR7241,
  8146. + AR71XX_SOC_AR7242,
  8147. + AR71XX_SOC_AR9130,
  8148. + AR71XX_SOC_AR9132
  8149. +};
  8150. +
  8151. +extern enum ar71xx_soc_type ar71xx_soc;
  8152. +
  8153. +/*
  8154. + * PLL block
  8155. + */
  8156. +#define AR71XX_PLL_REG_CPU_CONFIG 0x00
  8157. +#define AR71XX_PLL_REG_SEC_CONFIG 0x04
  8158. +#define AR71XX_PLL_REG_ETH0_INT_CLOCK 0x10
  8159. +#define AR71XX_PLL_REG_ETH1_INT_CLOCK 0x14
  8160. +
  8161. +#define AR71XX_PLL_DIV_SHIFT 3
  8162. +#define AR71XX_PLL_DIV_MASK 0x1f
  8163. +#define AR71XX_CPU_DIV_SHIFT 16
  8164. +#define AR71XX_CPU_DIV_MASK 0x3
  8165. +#define AR71XX_DDR_DIV_SHIFT 18
  8166. +#define AR71XX_DDR_DIV_MASK 0x3
  8167. +#define AR71XX_AHB_DIV_SHIFT 20
  8168. +#define AR71XX_AHB_DIV_MASK 0x7
  8169. +
  8170. +#define AR71XX_ETH0_PLL_SHIFT 17
  8171. +#define AR71XX_ETH1_PLL_SHIFT 19
  8172. +
  8173. +#define AR724X_PLL_REG_CPU_CONFIG 0x00
  8174. +#define AR724X_PLL_REG_PCIE_CONFIG 0x18
  8175. +
  8176. +#define AR724X_PLL_DIV_SHIFT 0
  8177. +#define AR724X_PLL_DIV_MASK 0x3ff
  8178. +#define AR724X_PLL_REF_DIV_SHIFT 10
  8179. +#define AR724X_PLL_REF_DIV_MASK 0xf
  8180. +#define AR724X_AHB_DIV_SHIFT 19
  8181. +#define AR724X_AHB_DIV_MASK 0x1
  8182. +#define AR724X_DDR_DIV_SHIFT 22
  8183. +#define AR724X_DDR_DIV_MASK 0x3
  8184. +
  8185. +#define AR91XX_PLL_REG_CPU_CONFIG 0x00
  8186. +#define AR91XX_PLL_REG_ETH_CONFIG 0x04
  8187. +#define AR91XX_PLL_REG_ETH0_INT_CLOCK 0x14
  8188. +#define AR91XX_PLL_REG_ETH1_INT_CLOCK 0x18
  8189. +
  8190. +#define AR91XX_PLL_DIV_SHIFT 0
  8191. +#define AR91XX_PLL_DIV_MASK 0x3ff
  8192. +#define AR91XX_DDR_DIV_SHIFT 22
  8193. +#define AR91XX_DDR_DIV_MASK 0x3
  8194. +#define AR91XX_AHB_DIV_SHIFT 19
  8195. +#define AR91XX_AHB_DIV_MASK 0x1
  8196. +
  8197. +#define AR91XX_ETH0_PLL_SHIFT 20
  8198. +#define AR91XX_ETH1_PLL_SHIFT 22
  8199. +
  8200. +extern void __iomem *ar71xx_pll_base;
  8201. +
  8202. +static inline void ar71xx_pll_wr(unsigned reg, u32 val)
  8203. +{
  8204. + __raw_writel(val, ar71xx_pll_base + reg);
  8205. +}
  8206. +
  8207. +static inline u32 ar71xx_pll_rr(unsigned reg)
  8208. +{
  8209. + return __raw_readl(ar71xx_pll_base + reg);
  8210. +}
  8211. +
  8212. +/*
  8213. + * USB_CONFIG block
  8214. + */
  8215. +#define USB_CTRL_REG_FLADJ 0x00
  8216. +#define USB_CTRL_REG_CONFIG 0x04
  8217. +
  8218. +extern void __iomem *ar71xx_usb_ctrl_base;
  8219. +
  8220. +static inline void ar71xx_usb_ctrl_wr(unsigned reg, u32 val)
  8221. +{
  8222. + __raw_writel(val, ar71xx_usb_ctrl_base + reg);
  8223. +}
  8224. +
  8225. +static inline u32 ar71xx_usb_ctrl_rr(unsigned reg)
  8226. +{
  8227. + return __raw_readl(ar71xx_usb_ctrl_base + reg);
  8228. +}
  8229. +
  8230. +/*
  8231. + * GPIO block
  8232. + */
  8233. +#define GPIO_REG_OE 0x00
  8234. +#define GPIO_REG_IN 0x04
  8235. +#define GPIO_REG_OUT 0x08
  8236. +#define GPIO_REG_SET 0x0c
  8237. +#define GPIO_REG_CLEAR 0x10
  8238. +#define GPIO_REG_INT_MODE 0x14
  8239. +#define GPIO_REG_INT_TYPE 0x18
  8240. +#define GPIO_REG_INT_POLARITY 0x1c
  8241. +#define GPIO_REG_INT_PENDING 0x20
  8242. +#define GPIO_REG_INT_ENABLE 0x24
  8243. +#define GPIO_REG_FUNC 0x28
  8244. +
  8245. +#define AR71XX_GPIO_FUNC_STEREO_EN BIT(17)
  8246. +#define AR71XX_GPIO_FUNC_SLIC_EN BIT(16)
  8247. +#define AR71XX_GPIO_FUNC_SPI_CS2_EN BIT(13)
  8248. +#define AR71XX_GPIO_FUNC_SPI_CS1_EN BIT(12)
  8249. +#define AR71XX_GPIO_FUNC_UART_EN BIT(8)
  8250. +#define AR71XX_GPIO_FUNC_USB_OC_EN BIT(4)
  8251. +#define AR71XX_GPIO_FUNC_USB_CLK_EN BIT(0)
  8252. +
  8253. +#define AR71XX_GPIO_COUNT 16
  8254. +
  8255. +#define AR724X_GPIO_FUNC_GE0_MII_CLK_EN BIT(19)
  8256. +#define AR724X_GPIO_FUNC_SPI_EN BIT(18)
  8257. +#define AR724X_GPIO_FUNC_SPI_CS_EN2 BIT(14)
  8258. +#define AR724X_GPIO_FUNC_SPI_CS_EN1 BIT(13)
  8259. +#define AR724X_GPIO_FUNC_CLK_OBS5_EN BIT(12)
  8260. +#define AR724X_GPIO_FUNC_CLK_OBS4_EN BIT(11)
  8261. +#define AR724X_GPIO_FUNC_CLK_OBS3_EN BIT(10)
  8262. +#define AR724X_GPIO_FUNC_CLK_OBS2_EN BIT(9)
  8263. +#define AR724X_GPIO_FUNC_CLK_OBS1_EN BIT(8)
  8264. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN BIT(7)
  8265. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN BIT(6)
  8266. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN BIT(5)
  8267. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN BIT(4)
  8268. +#define AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN BIT(3)
  8269. +#define AR724X_GPIO_FUNC_UART_RTS_CTS_EN BIT(2)
  8270. +#define AR724X_GPIO_FUNC_UART_EN BIT(1)
  8271. +#define AR724X_GPIO_FUNC_JTAG_DISABLE BIT(0)
  8272. +
  8273. +#define AR724X_GPIO_COUNT 18
  8274. +
  8275. +#define AR91XX_GPIO_FUNC_WMAC_LED_EN BIT(22)
  8276. +#define AR91XX_GPIO_FUNC_EXP_PORT_CS_EN BIT(21)
  8277. +#define AR91XX_GPIO_FUNC_I2S_REFCLKEN BIT(20)
  8278. +#define AR91XX_GPIO_FUNC_I2S_MCKEN BIT(19)
  8279. +#define AR91XX_GPIO_FUNC_I2S1_EN BIT(18)
  8280. +#define AR91XX_GPIO_FUNC_I2S0_EN BIT(17)
  8281. +#define AR91XX_GPIO_FUNC_SLIC_EN BIT(16)
  8282. +#define AR91XX_GPIO_FUNC_UART_RTSCTS_EN BIT(9)
  8283. +#define AR91XX_GPIO_FUNC_UART_EN BIT(8)
  8284. +#define AR91XX_GPIO_FUNC_USB_CLK_EN BIT(4)
  8285. +
  8286. +#define AR91XX_GPIO_COUNT 22
  8287. +
  8288. +extern void __iomem *ar71xx_gpio_base;
  8289. +
  8290. +static inline void ar71xx_gpio_wr(unsigned reg, u32 value)
  8291. +{
  8292. + __raw_writel(value, ar71xx_gpio_base + reg);
  8293. +}
  8294. +
  8295. +static inline u32 ar71xx_gpio_rr(unsigned reg)
  8296. +{
  8297. + return __raw_readl(ar71xx_gpio_base + reg);
  8298. +}
  8299. +
  8300. +void ar71xx_gpio_init(void) __init;
  8301. +void ar71xx_gpio_function_enable(u32 mask);
  8302. +void ar71xx_gpio_function_disable(u32 mask);
  8303. +void ar71xx_gpio_function_setup(u32 set, u32 clear);
  8304. +
  8305. +/*
  8306. + * DDR_CTRL block
  8307. + */
  8308. +#define AR71XX_DDR_REG_PCI_WIN0 0x7c
  8309. +#define AR71XX_DDR_REG_PCI_WIN1 0x80
  8310. +#define AR71XX_DDR_REG_PCI_WIN2 0x84
  8311. +#define AR71XX_DDR_REG_PCI_WIN3 0x88
  8312. +#define AR71XX_DDR_REG_PCI_WIN4 0x8c
  8313. +#define AR71XX_DDR_REG_PCI_WIN5 0x90
  8314. +#define AR71XX_DDR_REG_PCI_WIN6 0x94
  8315. +#define AR71XX_DDR_REG_PCI_WIN7 0x98
  8316. +#define AR71XX_DDR_REG_FLUSH_GE0 0x9c
  8317. +#define AR71XX_DDR_REG_FLUSH_GE1 0xa0
  8318. +#define AR71XX_DDR_REG_FLUSH_USB 0xa4
  8319. +#define AR71XX_DDR_REG_FLUSH_PCI 0xa8
  8320. +
  8321. +#define AR724X_DDR_REG_FLUSH_GE0 0x7c
  8322. +#define AR724X_DDR_REG_FLUSH_GE1 0x80
  8323. +#define AR724X_DDR_REG_FLUSH_USB 0x84
  8324. +#define AR724X_DDR_REG_FLUSH_PCIE 0x88
  8325. +
  8326. +#define AR91XX_DDR_REG_FLUSH_GE0 0x7c
  8327. +#define AR91XX_DDR_REG_FLUSH_GE1 0x80
  8328. +#define AR91XX_DDR_REG_FLUSH_USB 0x84
  8329. +#define AR91XX_DDR_REG_FLUSH_WMAC 0x88
  8330. +
  8331. +#define PCI_WIN0_OFFS 0x10000000
  8332. +#define PCI_WIN1_OFFS 0x11000000
  8333. +#define PCI_WIN2_OFFS 0x12000000
  8334. +#define PCI_WIN3_OFFS 0x13000000
  8335. +#define PCI_WIN4_OFFS 0x14000000
  8336. +#define PCI_WIN5_OFFS 0x15000000
  8337. +#define PCI_WIN6_OFFS 0x16000000
  8338. +#define PCI_WIN7_OFFS 0x07000000
  8339. +
  8340. +extern void __iomem *ar71xx_ddr_base;
  8341. +
  8342. +static inline void ar71xx_ddr_wr(unsigned reg, u32 val)
  8343. +{
  8344. + __raw_writel(val, ar71xx_ddr_base + reg);
  8345. +}
  8346. +
  8347. +static inline u32 ar71xx_ddr_rr(unsigned reg)
  8348. +{
  8349. + return __raw_readl(ar71xx_ddr_base + reg);
  8350. +}
  8351. +
  8352. +void ar71xx_ddr_flush(u32 reg);
  8353. +
  8354. +/*
  8355. + * PCI block
  8356. + */
  8357. +#define AR71XX_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + PCI_WIN7_OFFS + 0x10000)
  8358. +#define AR71XX_PCI_CFG_SIZE 0x100
  8359. +
  8360. +#define PCI_REG_CRP_AD_CBE 0x00
  8361. +#define PCI_REG_CRP_WRDATA 0x04
  8362. +#define PCI_REG_CRP_RDDATA 0x08
  8363. +#define PCI_REG_CFG_AD 0x0c
  8364. +#define PCI_REG_CFG_CBE 0x10
  8365. +#define PCI_REG_CFG_WRDATA 0x14
  8366. +#define PCI_REG_CFG_RDDATA 0x18
  8367. +#define PCI_REG_PCI_ERR 0x1c
  8368. +#define PCI_REG_PCI_ERR_ADDR 0x20
  8369. +#define PCI_REG_AHB_ERR 0x24
  8370. +#define PCI_REG_AHB_ERR_ADDR 0x28
  8371. +
  8372. +#define PCI_CRP_CMD_WRITE 0x00010000
  8373. +#define PCI_CRP_CMD_READ 0x00000000
  8374. +#define PCI_CFG_CMD_READ 0x0000000a
  8375. +#define PCI_CFG_CMD_WRITE 0x0000000b
  8376. +
  8377. +#define PCI_IDSEL_ADL_START 17
  8378. +
  8379. +#define AR724X_PCI_CFG_BASE (AR71XX_PCI_MEM_BASE + 0x4000000)
  8380. +#define AR724X_PCI_CFG_SIZE 0x1000
  8381. +
  8382. +#define AR724X_PCI_REG_APP 0x00
  8383. +#define AR724X_PCI_REG_RESET 0x18
  8384. +#define AR724X_PCI_REG_INT_STATUS 0x4c
  8385. +#define AR724X_PCI_REG_INT_MASK 0x50
  8386. +
  8387. +#define AR724X_PCI_APP_LTSSM_ENABLE BIT(0)
  8388. +#define AR724X_PCI_RESET_LINK_UP BIT(0)
  8389. +
  8390. +#define AR724X_PCI_INT_DEV0 BIT(14)
  8391. +
  8392. +/*
  8393. + * RESET block
  8394. + */
  8395. +#define AR71XX_RESET_REG_TIMER 0x00
  8396. +#define AR71XX_RESET_REG_TIMER_RELOAD 0x04
  8397. +#define AR71XX_RESET_REG_WDOG_CTRL 0x08
  8398. +#define AR71XX_RESET_REG_WDOG 0x0c
  8399. +#define AR71XX_RESET_REG_MISC_INT_STATUS 0x10
  8400. +#define AR71XX_RESET_REG_MISC_INT_ENABLE 0x14
  8401. +#define AR71XX_RESET_REG_PCI_INT_STATUS 0x18
  8402. +#define AR71XX_RESET_REG_PCI_INT_ENABLE 0x1c
  8403. +#define AR71XX_RESET_REG_GLOBAL_INT_STATUS 0x20
  8404. +#define AR71XX_RESET_REG_RESET_MODULE 0x24
  8405. +#define AR71XX_RESET_REG_PERFC_CTRL 0x2c
  8406. +#define AR71XX_RESET_REG_PERFC0 0x30
  8407. +#define AR71XX_RESET_REG_PERFC1 0x34
  8408. +#define AR71XX_RESET_REG_REV_ID 0x90
  8409. +
  8410. +#define AR91XX_RESET_REG_GLOBAL_INT_STATUS 0x18
  8411. +#define AR91XX_RESET_REG_RESET_MODULE 0x1c
  8412. +#define AR91XX_RESET_REG_PERF_CTRL 0x20
  8413. +#define AR91XX_RESET_REG_PERFC0 0x24
  8414. +#define AR91XX_RESET_REG_PERFC1 0x28
  8415. +
  8416. +#define AR724X_RESET_REG_RESET_MODULE 0x1c
  8417. +
  8418. +#define WDOG_CTRL_LAST_RESET BIT(31)
  8419. +#define WDOG_CTRL_ACTION_MASK 3
  8420. +#define WDOG_CTRL_ACTION_NONE 0 /* no action */
  8421. +#define WDOG_CTRL_ACTION_GPI 1 /* general purpose interrupt */
  8422. +#define WDOG_CTRL_ACTION_NMI 2 /* NMI */
  8423. +#define WDOG_CTRL_ACTION_FCR 3 /* full chip reset */
  8424. +
  8425. +#define MISC_INT_DMA BIT(7)
  8426. +#define MISC_INT_OHCI BIT(6)
  8427. +#define MISC_INT_PERFC BIT(5)
  8428. +#define MISC_INT_WDOG BIT(4)
  8429. +#define MISC_INT_UART BIT(3)
  8430. +#define MISC_INT_GPIO BIT(2)
  8431. +#define MISC_INT_ERROR BIT(1)
  8432. +#define MISC_INT_TIMER BIT(0)
  8433. +
  8434. +#define PCI_INT_CORE BIT(4)
  8435. +#define PCI_INT_DEV2 BIT(2)
  8436. +#define PCI_INT_DEV1 BIT(1)
  8437. +#define PCI_INT_DEV0 BIT(0)
  8438. +
  8439. +#define RESET_MODULE_EXTERNAL BIT(28)
  8440. +#define RESET_MODULE_FULL_CHIP BIT(24)
  8441. +#define RESET_MODULE_AMBA2WMAC BIT(22)
  8442. +#define RESET_MODULE_CPU_NMI BIT(21)
  8443. +#define RESET_MODULE_CPU_COLD BIT(20)
  8444. +#define RESET_MODULE_DMA BIT(19)
  8445. +#define RESET_MODULE_SLIC BIT(18)
  8446. +#define RESET_MODULE_STEREO BIT(17)
  8447. +#define RESET_MODULE_DDR BIT(16)
  8448. +#define RESET_MODULE_GE1_MAC BIT(13)
  8449. +#define RESET_MODULE_GE1_PHY BIT(12)
  8450. +#define RESET_MODULE_USBSUS_OVERRIDE BIT(10)
  8451. +#define RESET_MODULE_GE0_MAC BIT(9)
  8452. +#define RESET_MODULE_GE0_PHY BIT(8)
  8453. +#define RESET_MODULE_USB_OHCI_DLL BIT(6)
  8454. +#define RESET_MODULE_USB_HOST BIT(5)
  8455. +#define RESET_MODULE_USB_PHY BIT(4)
  8456. +#define RESET_MODULE_USB_OHCI_DLL_7240 BIT(3)
  8457. +#define RESET_MODULE_PCI_BUS BIT(1)
  8458. +#define RESET_MODULE_PCI_CORE BIT(0)
  8459. +
  8460. +#define AR724X_RESET_GE1_MDIO BIT(23)
  8461. +#define AR724X_RESET_GE0_MDIO BIT(22)
  8462. +#define AR724X_RESET_PCIE_PHY_SERIAL BIT(10)
  8463. +#define AR724X_RESET_PCIE_PHY BIT(7)
  8464. +#define AR724X_RESET_PCIE BIT(6)
  8465. +
  8466. +#define REV_ID_MAJOR_MASK 0xfff0
  8467. +#define REV_ID_MAJOR_AR71XX 0x00a0
  8468. +#define REV_ID_MAJOR_AR913X 0x00b0
  8469. +#define REV_ID_MAJOR_AR7240 0x00c0
  8470. +#define REV_ID_MAJOR_AR7241 0x0100
  8471. +#define REV_ID_MAJOR_AR7242 0x1100
  8472. +
  8473. +#define AR71XX_REV_ID_MINOR_MASK 0x3
  8474. +#define AR71XX_REV_ID_MINOR_AR7130 0x0
  8475. +#define AR71XX_REV_ID_MINOR_AR7141 0x1
  8476. +#define AR71XX_REV_ID_MINOR_AR7161 0x2
  8477. +#define AR71XX_REV_ID_REVISION_MASK 0x3
  8478. +#define AR71XX_REV_ID_REVISION_SHIFT 2
  8479. +
  8480. +#define AR91XX_REV_ID_MINOR_MASK 0x3
  8481. +#define AR91XX_REV_ID_MINOR_AR9130 0x0
  8482. +#define AR91XX_REV_ID_MINOR_AR9132 0x1
  8483. +#define AR91XX_REV_ID_REVISION_MASK 0x3
  8484. +#define AR91XX_REV_ID_REVISION_SHIFT 2
  8485. +
  8486. +#define AR724X_REV_ID_REVISION_MASK 0x3
  8487. +
  8488. +extern void __iomem *ar71xx_reset_base;
  8489. +
  8490. +static inline void ar71xx_reset_wr(unsigned reg, u32 val)
  8491. +{
  8492. + __raw_writel(val, ar71xx_reset_base + reg);
  8493. +}
  8494. +
  8495. +static inline u32 ar71xx_reset_rr(unsigned reg)
  8496. +{
  8497. + return __raw_readl(ar71xx_reset_base + reg);
  8498. +}
  8499. +
  8500. +void ar71xx_device_stop(u32 mask);
  8501. +void ar71xx_device_start(u32 mask);
  8502. +int ar71xx_device_stopped(u32 mask);
  8503. +
  8504. +/*
  8505. + * SPI block
  8506. + */
  8507. +#define SPI_REG_FS 0x00 /* Function Select */
  8508. +#define SPI_REG_CTRL 0x04 /* SPI Control */
  8509. +#define SPI_REG_IOC 0x08 /* SPI I/O Control */
  8510. +#define SPI_REG_RDS 0x0c /* Read Data Shift */
  8511. +
  8512. +#define SPI_FS_GPIO BIT(0) /* Enable GPIO mode */
  8513. +
  8514. +#define SPI_CTRL_RD BIT(6) /* Remap Disable */
  8515. +#define SPI_CTRL_DIV_MASK 0x3f
  8516. +
  8517. +#define SPI_IOC_DO BIT(0) /* Data Out pin */
  8518. +#define SPI_IOC_CLK BIT(8) /* CLK pin */
  8519. +#define SPI_IOC_CS(n) BIT(16 + (n))
  8520. +#define SPI_IOC_CS0 SPI_IOC_CS(0)
  8521. +#define SPI_IOC_CS1 SPI_IOC_CS(1)
  8522. +#define SPI_IOC_CS2 SPI_IOC_CS(2)
  8523. +#define SPI_IOC_CS_ALL (SPI_IOC_CS0 | SPI_IOC_CS1 | SPI_IOC_CS2)
  8524. +
  8525. +void ar71xx_flash_acquire(void);
  8526. +void ar71xx_flash_release(void);
  8527. +
  8528. +/*
  8529. + * MII_CTRL block
  8530. + */
  8531. +#define MII_REG_MII0_CTRL 0x00
  8532. +#define MII_REG_MII1_CTRL 0x04
  8533. +
  8534. +#define MII0_CTRL_IF_GMII 0
  8535. +#define MII0_CTRL_IF_MII 1
  8536. +#define MII0_CTRL_IF_RGMII 2
  8537. +#define MII0_CTRL_IF_RMII 3
  8538. +
  8539. +#define MII1_CTRL_IF_RGMII 0
  8540. +#define MII1_CTRL_IF_RMII 1
  8541. +
  8542. +#endif /* __ASSEMBLER__ */
  8543. +
  8544. +#endif /* __ASM_MACH_AR71XX_H */
  8545. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h
  8546. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 1970-01-01 01:00:00.000000000 +0100
  8547. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/ar91xx_flash.h 2010-05-25 18:46:06.842223171 +0200
  8548. @@ -0,0 +1,26 @@
  8549. +/*
  8550. + * AR91xx parallel flash driver platform data definitions
  8551. + *
  8552. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8553. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8554. + *
  8555. + * This program is free software; you can redistribute it and/or modify it
  8556. + * under the terms of the GNU General Public License version 2 as published
  8557. + * by the Free Software Foundation.
  8558. + */
  8559. +
  8560. +#ifndef __AR91XX_FLASH_H
  8561. +#define __AR91XX_FLASH_H
  8562. +
  8563. +struct mtd_partition;
  8564. +
  8565. +struct ar91xx_flash_platform_data {
  8566. + unsigned int width;
  8567. + u8 is_shared:1;
  8568. +#ifdef CONFIG_MTD_PARTITIONS
  8569. + unsigned int nr_parts;
  8570. + struct mtd_partition *parts;
  8571. +#endif
  8572. +};
  8573. +
  8574. +#endif /* __AR91XX_FLASH_H */
  8575. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h
  8576. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 1970-01-01 01:00:00.000000000 +0100
  8577. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/cpu-feature-overrides.h 2010-05-25 18:46:06.883464235 +0200
  8578. @@ -0,0 +1,56 @@
  8579. +/*
  8580. + * Atheros AR71xx specific CPU feature overrides
  8581. + *
  8582. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8583. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8584. + *
  8585. + * This file was derived from: include/asm-mips/cpu-features.h
  8586. + * Copyright (C) 2003, 2004 Ralf Baechle
  8587. + * Copyright (C) 2004 Maciej W. Rozycki
  8588. + *
  8589. + * This program is free software; you can redistribute it and/or modify it
  8590. + * under the terms of the GNU General Public License version 2 as published
  8591. + * by the Free Software Foundation.
  8592. + *
  8593. + */
  8594. +#ifndef __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  8595. +#define __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H
  8596. +
  8597. +#define cpu_has_tlb 1
  8598. +#define cpu_has_4kex 1
  8599. +#define cpu_has_3k_cache 0
  8600. +#define cpu_has_4k_cache 1
  8601. +#define cpu_has_tx39_cache 0
  8602. +#define cpu_has_sb1_cache 0
  8603. +#define cpu_has_fpu 0
  8604. +#define cpu_has_32fpr 0
  8605. +#define cpu_has_counter 1
  8606. +#define cpu_has_watch 1
  8607. +#define cpu_has_divec 1
  8608. +
  8609. +#define cpu_has_prefetch 1
  8610. +#define cpu_has_ejtag 1
  8611. +#define cpu_has_llsc 1
  8612. +
  8613. +#define cpu_has_mips16 1
  8614. +#define cpu_has_mdmx 0
  8615. +#define cpu_has_mips3d 0
  8616. +#define cpu_has_smartmips 0
  8617. +
  8618. +#define cpu_has_mips32r1 1
  8619. +#define cpu_has_mips32r2 1
  8620. +#define cpu_has_mips64r1 0
  8621. +#define cpu_has_mips64r2 0
  8622. +
  8623. +#define cpu_has_dsp 0
  8624. +#define cpu_has_mipsmt 0
  8625. +
  8626. +#define cpu_has_64bits 0
  8627. +#define cpu_has_64bit_zero_reg 0
  8628. +#define cpu_has_64bit_gp_regs 0
  8629. +#define cpu_has_64bit_addresses 0
  8630. +
  8631. +#define cpu_dcache_line_size() 32
  8632. +#define cpu_icache_line_size() 32
  8633. +
  8634. +#endif /* __ASM_MACH_AR71XX_CPU_FEATURE_OVERRIDES_H */
  8635. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/gpio.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/gpio.h
  8636. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/gpio.h 1970-01-01 01:00:00.000000000 +0100
  8637. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/gpio.h 2010-05-25 18:46:06.922223109 +0200
  8638. @@ -0,0 +1,53 @@
  8639. +/*
  8640. + * Atheros AR71xx GPIO API definitions
  8641. + *
  8642. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8643. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8644. + *
  8645. + * This program is free software; you can redistribute it and/or modify it
  8646. + * under the terms of the GNU General Public License version 2 as published
  8647. + * by the Free Software Foundation.
  8648. + *
  8649. + */
  8650. +
  8651. +#ifndef __ASM_MACH_AR71XX_GPIO_H
  8652. +#define __ASM_MACH_AR71XX_GPIO_H
  8653. +
  8654. +#define ARCH_NR_GPIOS 64
  8655. +#include <asm-generic/gpio.h>
  8656. +
  8657. +#include <asm/mach-ar71xx/ar71xx.h>
  8658. +
  8659. +extern unsigned long ar71xx_gpio_count;
  8660. +extern void __ar71xx_gpio_set_value(unsigned gpio, int value);
  8661. +extern int __ar71xx_gpio_get_value(unsigned gpio);
  8662. +
  8663. +static inline int gpio_to_irq(unsigned gpio)
  8664. +{
  8665. + return AR71XX_GPIO_IRQ(gpio);
  8666. +}
  8667. +
  8668. +static inline int irq_to_gpio(unsigned irq)
  8669. +{
  8670. + return irq - AR71XX_GPIO_IRQ_BASE;
  8671. +}
  8672. +
  8673. +static inline int gpio_get_value(unsigned gpio)
  8674. +{
  8675. + if (gpio < ar71xx_gpio_count)
  8676. + return __ar71xx_gpio_get_value(gpio);
  8677. +
  8678. + return __gpio_get_value(gpio);
  8679. +}
  8680. +
  8681. +static inline void gpio_set_value(unsigned gpio, int value)
  8682. +{
  8683. + if (gpio < ar71xx_gpio_count)
  8684. + __ar71xx_gpio_set_value(gpio, value);
  8685. + else
  8686. + __gpio_set_value(gpio, value);
  8687. +}
  8688. +
  8689. +#define gpio_cansleep __gpio_cansleep
  8690. +
  8691. +#endif /* __ASM_MACH_AR71XX_GPIO_H */
  8692. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/irq.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/irq.h
  8693. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/irq.h 1970-01-01 01:00:00.000000000 +0100
  8694. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/irq.h 2010-05-25 18:46:06.961120355 +0200
  8695. @@ -0,0 +1,17 @@
  8696. +/*
  8697. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8698. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8699. + *
  8700. + * This program is free software; you can redistribute it and/or modify it
  8701. + * under the terms of the GNU General Public License version 2 as published
  8702. + * by the Free Software Foundation.
  8703. + */
  8704. +#ifndef __ASM_MACH_AR71XX_IRQ_H
  8705. +#define __ASM_MACH_AR71XX_IRQ_H
  8706. +
  8707. +#define MIPS_CPU_IRQ_BASE 0
  8708. +#define NR_IRQS 56
  8709. +
  8710. +#include_next <irq.h>
  8711. +
  8712. +#endif /* __ASM_MACH_AR71XX_IRQ_H */
  8713. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h
  8714. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 1970-01-01 01:00:00.000000000 +0100
  8715. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/kernel-entry-init.h 2010-05-25 18:46:07.003473055 +0200
  8716. @@ -0,0 +1,32 @@
  8717. +/*
  8718. + * Atheros AR71xx specific kernel entry setup
  8719. + *
  8720. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  8721. + *
  8722. + * This program is free software; you can redistribute it and/or modify it
  8723. + * under the terms of the GNU General Public License version 2 as published
  8724. + * by the Free Software Foundation.
  8725. + *
  8726. + */
  8727. +#ifndef __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  8728. +#define __ASM_MACH_AR71XX_KERNEL_ENTRY_H
  8729. +
  8730. + /*
  8731. + * Some bootloaders set the 'Kseg0 coherency algorithm' to
  8732. + * 'Cacheable, noncoherent, write-through, no write allocate'
  8733. + * and this cause performance issues. Let's go and change it to
  8734. + * 'Cacheable, noncoherent, write-back, write allocate'
  8735. + */
  8736. + .macro kernel_entry_setup
  8737. + mfc0 t0, CP0_CONFIG
  8738. + li t1, ~CONF_CM_CMASK
  8739. + and t0, t1
  8740. + ori t0, CONF_CM_CACHABLE_NONCOHERENT
  8741. + mtc0 t0, CP0_CONFIG
  8742. + nop
  8743. + .endm
  8744. +
  8745. + .macro smp_slave_setup
  8746. + .endm
  8747. +
  8748. +#endif /* __ASM_MACH_AR71XX_KERNEL_ENTRY_H */
  8749. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/mach-rb750.h
  8750. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 1970-01-01 01:00:00.000000000 +0100
  8751. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/mach-rb750.h 2010-05-25 18:46:07.040970889 +0200
  8752. @@ -0,0 +1,66 @@
  8753. +/*
  8754. + * MikroTik RouterBOARD 750 definitions
  8755. + *
  8756. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  8757. + *
  8758. + * This program is free software; you can redistribute it and/or modify it
  8759. + * under the terms of the GNU General Public License version 2 as published
  8760. + * by the Free Software Foundation.
  8761. + */
  8762. +#ifndef _MACH_RB750_H
  8763. +#define _MACH_RB750_H
  8764. +
  8765. +#include <linux/bitops.h>
  8766. +
  8767. +#define RB750_GPIO_LVC573_LE 0 /* Latch enable on LVC573 */
  8768. +#define RB750_GPIO_NAND_IO0 1 /* NAND I/O 0 */
  8769. +#define RB750_GPIO_NAND_IO1 2 /* NAND I/O 1 */
  8770. +#define RB750_GPIO_NAND_IO2 3 /* NAND I/O 2 */
  8771. +#define RB750_GPIO_NAND_IO3 4 /* NAND I/O 3 */
  8772. +#define RB750_GPIO_NAND_IO4 5 /* NAND I/O 4 */
  8773. +#define RB750_GPIO_NAND_IO5 6 /* NAND I/O 5 */
  8774. +#define RB750_GPIO_NAND_IO6 7 /* NAND I/O 6 */
  8775. +#define RB750_GPIO_NAND_IO7 8 /* NAND I/O 7 */
  8776. +#define RB750_GPIO_NAND_NCE 11 /* NAND Chip Enable (active low) */
  8777. +#define RB750_GPIO_NAND_RDY 12 /* NAND Ready */
  8778. +#define RB750_GPIO_NAND_CLE 14 /* NAND Command Latch Enable */
  8779. +#define RB750_GPIO_NAND_ALE 15 /* NAND Address Latch Enable */
  8780. +#define RB750_GPIO_NAND_NRE 16 /* NAND Read Enable (active low) */
  8781. +#define RB750_GPIO_NAND_NWE 17 /* NAND Write Enable (active low) */
  8782. +
  8783. +#define RB750_GPIO_BTN_RESET 1
  8784. +#define RB750_GPIO_SPI_CS0 2
  8785. +#define RB750_GPIO_LED_ACT 12
  8786. +#define RB750_GPIO_LED_PORT1 13
  8787. +#define RB750_GPIO_LED_PORT2 14
  8788. +#define RB750_GPIO_LED_PORT3 15
  8789. +#define RB750_GPIO_LED_PORT4 16
  8790. +#define RB750_GPIO_LED_PORT5 17
  8791. +
  8792. +#define RB750_LED_ACT BIT(RB750_GPIO_LED_ACT)
  8793. +#define RB750_LED_PORT1 BIT(RB750_GPIO_LED_PORT1)
  8794. +#define RB750_LED_PORT2 BIT(RB750_GPIO_LED_PORT2)
  8795. +#define RB750_LED_PORT3 BIT(RB750_GPIO_LED_PORT3)
  8796. +#define RB750_LED_PORT4 BIT(RB750_GPIO_LED_PORT4)
  8797. +#define RB750_LED_PORT5 BIT(RB750_GPIO_LED_PORT5)
  8798. +
  8799. +#define RB750_LVC573_LE BIT(RB750_GPIO_LVC573_LE)
  8800. +
  8801. +#define RB750_LED_BITS (RB750_LED_PORT1 | RB750_LED_PORT2 | RB750_LED_PORT3 | \
  8802. + RB750_LED_PORT4 | RB750_LED_PORT5 | RB750_LED_ACT)
  8803. +
  8804. +struct rb750_led_data {
  8805. + char *name;
  8806. + char *default_trigger;
  8807. + u32 mask;
  8808. + int active_low;
  8809. +};
  8810. +
  8811. +struct rb750_led_platform_data {
  8812. + int num_leds;
  8813. + struct rb750_led_data *leds;
  8814. +};
  8815. +
  8816. +int rb750_latch_change(u32 mask_clr, u32 mask_set);
  8817. +
  8818. +#endif /* _MACH_RB750_H */
  8819. \ No newline at end of file
  8820. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/mangle-port.h
  8821. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/mangle-port.h 1970-01-01 01:00:00.000000000 +0100
  8822. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/mangle-port.h 2010-05-25 18:46:07.080975596 +0200
  8823. @@ -0,0 +1,45 @@
  8824. +/*
  8825. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  8826. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8827. + *
  8828. + * This file was derived from: inlude/asm-mips/mach-generic/mangle-port.h
  8829. + * Copyright (C) 2003, 2004 Ralf Baechle
  8830. + *
  8831. + * This program is free software; you can redistribute it and/or modify it
  8832. + * under the terms of the GNU General Public License version 2 as published
  8833. + * by the Free Software Foundation.
  8834. + */
  8835. +
  8836. +#ifndef __ASM_MACH_AR71XX_MANGLE_PORT_H
  8837. +#define __ASM_MACH_AR71XX_MANGLE_PORT_H
  8838. +
  8839. +#define __swizzle_addr_b(port) ((port) ^ 3)
  8840. +#define __swizzle_addr_w(port) ((port) ^ 2)
  8841. +#define __swizzle_addr_l(port) (port)
  8842. +#define __swizzle_addr_q(port) (port)
  8843. +
  8844. +#if defined(CONFIG_SWAP_IO_SPACE)
  8845. +
  8846. +# define ioswabb(a, x) (x)
  8847. +# define __mem_ioswabb(a, x) (x)
  8848. +# define ioswabw(a, x) le16_to_cpu(x)
  8849. +# define __mem_ioswabw(a, x) (x)
  8850. +# define ioswabl(a, x) le32_to_cpu(x)
  8851. +# define __mem_ioswabl(a, x) (x)
  8852. +# define ioswabq(a, x) le64_to_cpu(x)
  8853. +# define __mem_ioswabq(a, x) (x)
  8854. +
  8855. +#else
  8856. +
  8857. +# define ioswabb(a, x) (x)
  8858. +# define __mem_ioswabb(a, x) (x)
  8859. +# define ioswabw(a, x) (x)
  8860. +# define __mem_ioswabw(a, x) cpu_to_le16(x)
  8861. +# define ioswabl(a, x) (x)
  8862. +# define __mem_ioswabl(a, x) cpu_to_le32(x)
  8863. +# define ioswabq(a, x) (x)
  8864. +# define __mem_ioswabq(a, x) cpu_to_le64(x)
  8865. +
  8866. +#endif
  8867. +
  8868. +#endif /* __ASM_MACH_AR71XX_MANGLE_PORT_H */
  8869. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/pci.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/pci.h
  8870. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/pci.h 1970-01-01 01:00:00.000000000 +0100
  8871. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/pci.h 2010-05-25 18:46:07.122223041 +0200
  8872. @@ -0,0 +1,39 @@
  8873. +/*
  8874. + * Atheros AR71xx SoC specific PCI definitions
  8875. + *
  8876. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8877. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8878. + *
  8879. + * This program is free software; you can redistribute it and/or modify it
  8880. + * under the terms of the GNU General Public License version 2 as published
  8881. + * by the Free Software Foundation.
  8882. + */
  8883. +
  8884. +#ifndef __ASM_MACH_AR71XX_PCI_H
  8885. +#define __ASM_MACH_AR71XX_PCI_H
  8886. +
  8887. +struct pci_dev;
  8888. +
  8889. +struct ar71xx_pci_irq {
  8890. + int irq;
  8891. + u8 slot;
  8892. + u8 pin;
  8893. +};
  8894. +
  8895. +extern int (*ar71xx_pci_plat_dev_init)(struct pci_dev *dev);
  8896. +extern unsigned ar71xx_pci_nr_irqs __initdata;
  8897. +extern struct ar71xx_pci_irq *ar71xx_pci_irq_map __initdata;
  8898. +
  8899. +int ar71xx_pcibios_map_irq(const struct pci_dev *dev,
  8900. + uint8_t slot, uint8_t pin) __init;
  8901. +int ar71xx_pcibios_init(void) __init;
  8902. +
  8903. +int ar71xx_pci_be_handler(int is_fixup);
  8904. +
  8905. +int ar724x_pcibios_map_irq(const struct pci_dev *dev,
  8906. + uint8_t slot, uint8_t pin) __init;
  8907. +int ar724x_pcibios_init(void) __init;
  8908. +
  8909. +int ar71xx_pci_init(unsigned nr_irqs, struct ar71xx_pci_irq *map) __init;
  8910. +
  8911. +#endif /* __ASM_MACH_AR71XX_PCI_H */
  8912. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/platform.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/platform.h
  8913. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/platform.h 1970-01-01 01:00:00.000000000 +0100
  8914. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/platform.h 2010-05-25 18:46:07.171468638 +0200
  8915. @@ -0,0 +1,61 @@
  8916. +/*
  8917. + * Atheros AR71xx SoC specific platform data definitions
  8918. + *
  8919. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8920. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8921. + *
  8922. + * This program is free software; you can redistribute it and/or modify it
  8923. + * under the terms of the GNU General Public License version 2 as published
  8924. + * by the Free Software Foundation.
  8925. + */
  8926. +
  8927. +#ifndef __ASM_MACH_AR71XX_PLATFORM_H
  8928. +#define __ASM_MACH_AR71XX_PLATFORM_H
  8929. +
  8930. +#include <linux/if_ether.h>
  8931. +#include <linux/skbuff.h>
  8932. +#include <linux/phy.h>
  8933. +#include <linux/spi/spi.h>
  8934. +
  8935. +struct ag71xx_platform_data {
  8936. + phy_interface_t phy_if_mode;
  8937. + u32 phy_mask;
  8938. + int speed;
  8939. + int duplex;
  8940. + u32 reset_bit;
  8941. + u32 mii_if;
  8942. + u8 mac_addr[ETH_ALEN];
  8943. + struct device *mii_bus_dev;
  8944. +
  8945. + u8 has_gbit:1;
  8946. + u8 is_ar91xx:1;
  8947. + u8 is_ar724x:1;
  8948. + u8 has_ar8216:1;
  8949. +
  8950. + void (* ddr_flush)(void);
  8951. + void (* set_pll)(int speed);
  8952. +
  8953. + u32 fifo_cfg1;
  8954. + u32 fifo_cfg2;
  8955. + u32 fifo_cfg3;
  8956. +};
  8957. +
  8958. +struct ag71xx_mdio_platform_data {
  8959. + u32 phy_mask;
  8960. + int is_ar7240;
  8961. +};
  8962. +
  8963. +struct ar71xx_ehci_platform_data {
  8964. + u8 is_ar91xx;
  8965. +};
  8966. +
  8967. +struct ar71xx_spi_platform_data {
  8968. + unsigned bus_num;
  8969. + unsigned num_chipselect;
  8970. + u32 (*get_ioc_base)(u8 chip_select, int cs_high, int is_on);
  8971. +};
  8972. +
  8973. +#define AR71XX_SPI_CS_INACTIVE 0
  8974. +#define AR71XX_SPI_CS_ACTIVE 1
  8975. +
  8976. +#endif /* __ASM_MACH_AR71XX_PLATFORM_H */
  8977. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/war.h linux-2.6.34/arch/mips/include/asm/mach-ar71xx/war.h
  8978. --- linux-2.6.34.orig/arch/mips/include/asm/mach-ar71xx/war.h 1970-01-01 01:00:00.000000000 +0100
  8979. +++ linux-2.6.34/arch/mips/include/asm/mach-ar71xx/war.h 2010-05-25 18:46:07.220978398 +0200
  8980. @@ -0,0 +1,25 @@
  8981. +/*
  8982. + * This file is subject to the terms and conditions of the GNU General Public
  8983. + * License. See the file "COPYING" in the main directory of this archive
  8984. + * for more details.
  8985. + *
  8986. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  8987. + */
  8988. +#ifndef __ASM_MACH_AR71XX_WAR_H
  8989. +#define __ASM_MACH_AR71XX_WAR_H
  8990. +
  8991. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  8992. +#define R4600_V1_HIT_CACHEOP_WAR 0
  8993. +#define R4600_V2_HIT_CACHEOP_WAR 0
  8994. +#define R5432_CP0_INTERRUPT_WAR 0
  8995. +#define BCM1250_M3_WAR 0
  8996. +#define SIBYTE_1956_WAR 0
  8997. +#define MIPS4K_ICACHE_REFILL_WAR 0
  8998. +#define MIPS_CACHE_SYNC_WAR 0
  8999. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  9000. +#define RM9000_CDEX_SMP_WAR 0
  9001. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  9002. +#define R10000_LLSC_WAR 0
  9003. +#define MIPS34K_MISSED_ITLB_WAR 0
  9004. +
  9005. +#endif /* __ASM_MACH_AR71XX_WAR_H */
  9006. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mips_machine.h linux-2.6.34/arch/mips/include/asm/mips_machine.h
  9007. --- linux-2.6.34.orig/arch/mips/include/asm/mips_machine.h 1970-01-01 01:00:00.000000000 +0100
  9008. +++ linux-2.6.34/arch/mips/include/asm/mips_machine.h 2010-05-25 18:46:07.270971848 +0200
  9009. @@ -0,0 +1,54 @@
  9010. +/*
  9011. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  9012. + *
  9013. + * This program is free software; you can redistribute it and/or modify it
  9014. + * under the terms of the GNU General Public License version 2 as published
  9015. + * by the Free Software Foundation.
  9016. + *
  9017. + */
  9018. +
  9019. +#ifndef __ASM_MIPS_MACHINE_H
  9020. +#define __ASM_MIPS_MACHINE_H
  9021. +
  9022. +#include <linux/init.h>
  9023. +#include <linux/list.h>
  9024. +
  9025. +#include <asm/bootinfo.h>
  9026. +
  9027. +struct mips_machine {
  9028. + unsigned long mach_type;
  9029. + char *mach_id;
  9030. + char *mach_name;
  9031. + void (*mach_setup)(void);
  9032. + struct list_head list;
  9033. +};
  9034. +
  9035. +void mips_machine_register(struct mips_machine *) __init;
  9036. +void mips_machine_setup(void) __init;
  9037. +int mips_machtype_setup(char *id) __init;
  9038. +void mips_machine_set_name(char *name) __init;
  9039. +
  9040. +extern char *mips_machine_name;
  9041. +
  9042. +#define MIPS_MACHINE(_type, _id, _name, _setup) \
  9043. +static const char machine_name_##_type[] __initconst \
  9044. + __aligned(1) = _name; \
  9045. +static const char machine_id_##_type[] __initconst \
  9046. + __aligned(1) = _id; \
  9047. +static struct mips_machine machine_##_type __initdata = \
  9048. +{ \
  9049. + .mach_type = _type, \
  9050. + .mach_id = (char *) machine_id_##_type, \
  9051. + .mach_name = (char *) machine_name_##_type, \
  9052. + .mach_setup = _setup, \
  9053. +}; \
  9054. + \
  9055. +static int __init register_machine_##_type(void) \
  9056. +{ \
  9057. + mips_machine_register(&machine_##_type); \
  9058. + return 0; \
  9059. +} \
  9060. + \
  9061. +pure_initcall(register_machine_##_type)
  9062. +
  9063. +#endif /* __ASM_MIPS_MACHINE_H */
  9064. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/time.h linux-2.6.34/arch/mips/include/asm/time.h
  9065. --- linux-2.6.34.orig/arch/mips/include/asm/time.h 2010-05-16 23:17:36.000000000 +0200
  9066. +++ linux-2.6.34/arch/mips/include/asm/time.h 2010-05-25 18:46:07.320975755 +0200
  9067. @@ -52,6 +52,7 @@
  9068. */
  9069. #ifdef CONFIG_CEVT_R4K_LIB
  9070. extern unsigned int __weak get_c0_compare_int(void);
  9071. +extern unsigned int __weak get_c0_compare_irq(void);
  9072. extern int r4k_clockevent_init(void);
  9073. #endif
  9074. diff -Nur linux-2.6.34.orig/arch/mips/Kconfig linux-2.6.34/arch/mips/Kconfig
  9075. --- linux-2.6.34.orig/arch/mips/Kconfig 2010-05-16 23:17:36.000000000 +0200
  9076. +++ linux-2.6.34/arch/mips/Kconfig 2010-05-25 18:46:07.382337624 +0200
  9077. @@ -48,6 +48,23 @@
  9078. Support for the Texas Instruments AR7 System-on-a-Chip
  9079. family: TNETD7100, 7200 and 7300.
  9080. +config ATHEROS_AR71XX
  9081. + bool "Atheros AR71xx based boards"
  9082. + select CEVT_R4K
  9083. + select CSRC_R4K
  9084. + select DMA_NONCOHERENT
  9085. + select HW_HAS_PCI
  9086. + select IRQ_CPU
  9087. + select ARCH_REQUIRE_GPIOLIB
  9088. + select SYS_HAS_CPU_MIPS32_R1
  9089. + select SYS_HAS_CPU_MIPS32_R2
  9090. + select SYS_SUPPORTS_32BIT_KERNEL
  9091. + select SYS_SUPPORTS_BIG_ENDIAN
  9092. + select SYS_HAS_EARLY_PRINTK
  9093. + select MIPS_MACHINE
  9094. + help
  9095. + Support for Atheros AR71xx based boards.
  9096. +
  9097. config BCM47XX
  9098. bool "Broadcom BCM47XX based boards"
  9099. select CEVT_R4K
  9100. @@ -684,6 +701,7 @@
  9101. endchoice
  9102. source "arch/mips/alchemy/Kconfig"
  9103. +source "arch/mips/ar71xx/Kconfig"
  9104. source "arch/mips/bcm63xx/Kconfig"
  9105. source "arch/mips/jazz/Kconfig"
  9106. source "arch/mips/lasat/Kconfig"
  9107. @@ -850,9 +868,15 @@
  9108. config MIPS_DISABLE_OBSOLETE_IDE
  9109. bool
  9110. +config MYLOADER
  9111. + bool
  9112. +
  9113. config SYNC_R4K
  9114. bool
  9115. +config MIPS_MACHINE
  9116. + def_bool n
  9117. +
  9118. config NO_IOPORT
  9119. def_bool n
  9120. diff -Nur linux-2.6.34.orig/arch/mips/kernel/Makefile linux-2.6.34/arch/mips/kernel/Makefile
  9121. --- linux-2.6.34.orig/arch/mips/kernel/Makefile 2010-05-16 23:17:36.000000000 +0200
  9122. +++ linux-2.6.34/arch/mips/kernel/Makefile 2010-05-25 19:00:48.342223057 +0200
  9123. @@ -93,6 +93,7 @@
  9124. obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
  9125. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  9126. +obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o
  9127. obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o
  9128. 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)
  9129. diff -Nur linux-2.6.34.orig/arch/mips/kernel/mips_machine.c linux-2.6.34/arch/mips/kernel/mips_machine.c
  9130. --- linux-2.6.34.orig/arch/mips/kernel/mips_machine.c 1970-01-01 01:00:00.000000000 +0100
  9131. +++ linux-2.6.34/arch/mips/kernel/mips_machine.c 2010-05-25 19:08:53.143473119 +0200
  9132. @@ -0,0 +1,121 @@
  9133. +/*
  9134. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  9135. + *
  9136. + * This program is free software; you can redistribute it and/or modify it
  9137. + * under the terms of the GNU General Public License version 2 as published
  9138. + * by the Free Software Foundation.
  9139. + *
  9140. + */
  9141. +#include <linux/mm.h>
  9142. +#include <linux/slab.h>
  9143. +#include <linux/string.h>
  9144. +
  9145. +#include <asm/mips_machine.h>
  9146. +
  9147. +static struct list_head mips_machines __initdata =
  9148. + LIST_HEAD_INIT(mips_machines);
  9149. +static char *mips_machid __initdata;
  9150. +
  9151. +char *mips_machine_name = "Unknown";
  9152. +
  9153. +static struct mips_machine * __init mips_machine_find(unsigned long machtype)
  9154. +{
  9155. + struct list_head *this;
  9156. +
  9157. + list_for_each(this, &mips_machines) {
  9158. + struct mips_machine *mach;
  9159. +
  9160. + mach = list_entry(this, struct mips_machine, list);
  9161. + if (mach->mach_type == machtype)
  9162. + return mach;
  9163. + }
  9164. +
  9165. + return NULL;
  9166. +}
  9167. +
  9168. +void __init mips_machine_register(struct mips_machine *mach)
  9169. +{
  9170. + list_add_tail(&mach->list, &mips_machines);
  9171. +}
  9172. +
  9173. +void __init mips_machine_set_name(char *name)
  9174. +{
  9175. + unsigned int len;
  9176. + char *p;
  9177. +
  9178. + if (name == NULL)
  9179. + return;
  9180. +
  9181. + len = strlen(name);
  9182. + p = kmalloc(len + 1, GFP_KERNEL);
  9183. + if (p) {
  9184. + strncpy(p, name, len);
  9185. + p[len] = '\0';
  9186. + mips_machine_name = p;
  9187. + } else {
  9188. + printk(KERN_WARNING "MIPS: no memory for machine_name\n");
  9189. + }
  9190. +}
  9191. +
  9192. +void __init mips_machine_setup(void)
  9193. +{
  9194. + struct mips_machine *mach;
  9195. +
  9196. + mach = mips_machine_find(mips_machtype);
  9197. + if (!mach) {
  9198. + printk(KERN_WARNING "MIPS: no machine registered for "
  9199. + "machtype %lu\n", mips_machtype);
  9200. + return;
  9201. + }
  9202. +
  9203. + mips_machine_set_name(mach->mach_name);
  9204. + printk(KERN_NOTICE "MIPS: machine is %s\n", mips_machine_name);
  9205. +
  9206. + if (mach->mach_setup)
  9207. + mach->mach_setup();
  9208. +}
  9209. +
  9210. +int __init mips_machtype_setup(char *id)
  9211. +{
  9212. + if (mips_machid == NULL)
  9213. + mips_machid = id;
  9214. +
  9215. + return 1;
  9216. +}
  9217. +
  9218. +__setup("machtype=", mips_machtype_setup);
  9219. +
  9220. +static int __init mips_machtype_init(void)
  9221. +{
  9222. + struct list_head *this;
  9223. + struct mips_machine *mach;
  9224. +
  9225. + if (mips_machid == NULL)
  9226. + return 0;
  9227. +
  9228. + list_for_each(this, &mips_machines) {
  9229. + mach = list_entry(this, struct mips_machine, list);
  9230. + if (mach->mach_id == NULL)
  9231. + continue;
  9232. +
  9233. + if (strcmp(mach->mach_id, mips_machid) == 0) {
  9234. + mips_machtype = mach->mach_type;
  9235. + return 0;
  9236. + }
  9237. + }
  9238. +
  9239. + printk(KERN_WARNING
  9240. + "MIPS: no machine found for id: '%s', registered machines:\n",
  9241. + mips_machid);
  9242. + printk(KERN_WARNING "%32s %s\n", "id", "name");
  9243. +
  9244. + list_for_each(this, &mips_machines) {
  9245. + mach = list_entry(this, struct mips_machine, list);
  9246. + printk(KERN_WARNING "%32s %s\n",
  9247. + mach->mach_id ? mach->mach_id : "", mach->mach_name);
  9248. + }
  9249. +
  9250. + return 0;
  9251. +}
  9252. +
  9253. +core_initcall(mips_machtype_init);
  9254. diff -Nur linux-2.6.34.orig/arch/mips/kernel/proc.c linux-2.6.34/arch/mips/kernel/proc.c
  9255. --- linux-2.6.34.orig/arch/mips/kernel/proc.c 2010-05-16 23:17:36.000000000 +0200
  9256. +++ linux-2.6.34/arch/mips/kernel/proc.c 2010-05-25 18:46:08.072223162 +0200
  9257. @@ -12,6 +12,7 @@
  9258. #include <asm/cpu-features.h>
  9259. #include <asm/mipsregs.h>
  9260. #include <asm/processor.h>
  9261. +#include <asm/mips_machine.h>
  9262. unsigned int vced_count, vcei_count;
  9263. @@ -31,8 +32,12 @@
  9264. /*
  9265. * For the first processor also print the system type
  9266. */
  9267. - if (n == 0)
  9268. + if (n == 0) {
  9269. seq_printf(m, "system type\t\t: %s\n", get_system_type());
  9270. +#ifdef CONFIG_MIPS_MACHINE
  9271. + seq_printf(m, "machine\t\t\t: %s\n", mips_machine_name);
  9272. +#endif
  9273. + }
  9274. seq_printf(m, "processor\t\t: %ld\n", n);
  9275. sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n",
  9276. diff -Nur linux-2.6.34.orig/arch/mips/kernel/traps.c linux-2.6.34/arch/mips/kernel/traps.c
  9277. --- linux-2.6.34.orig/arch/mips/kernel/traps.c 2010-05-16 23:17:36.000000000 +0200
  9278. +++ linux-2.6.34/arch/mips/kernel/traps.c 2010-05-25 19:01:23.272222993 +0200
  9279. @@ -50,6 +50,7 @@
  9280. #include <asm/types.h>
  9281. #include <asm/stacktrace.h>
  9282. #include <asm/irq.h>
  9283. +#include <asm/time.h>
  9284. #include <asm/uasm.h>
  9285. extern void check_wait(void);
  9286. @@ -1506,6 +1507,8 @@
  9287. if (cpu_has_mips_r2) {
  9288. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  9289. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  9290. + if (get_c0_compare_irq)
  9291. + cp0_compare_irq = get_c0_compare_irq();
  9292. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  9293. if (cp0_perfcount_irq == cp0_compare_irq)
  9294. cp0_perfcount_irq = -1;
  9295. diff -Nur linux-2.6.34.orig/arch/mips/Makefile linux-2.6.34/arch/mips/Makefile
  9296. --- linux-2.6.34.orig/arch/mips/Makefile 2010-05-16 23:17:36.000000000 +0200
  9297. +++ linux-2.6.34/arch/mips/Makefile 2010-05-25 18:46:08.530007292 +0200
  9298. @@ -179,6 +179,13 @@
  9299. cflags-$(CONFIG_CPU_CAVIUM_OCTEON) += -Wa,-march=octeon
  9300. endif
  9301. +#
  9302. +# Atheros AR71xx
  9303. +#
  9304. +core-$(CONFIG_ATHEROS_AR71XX) += arch/mips/ar71xx/
  9305. +cflags-$(CONFIG_ATHEROS_AR71XX) += -I$(srctree)/arch/mips/include/asm/mach-ar71xx
  9306. +load-$(CONFIG_ATHEROS_AR71XX) += 0xffffffff80060000
  9307. +
  9308. cflags-$(CONFIG_CPU_R4000_WORKAROUNDS) += $(call cc-option,-mfix-r4000,)
  9309. cflags-$(CONFIG_CPU_R4400_WORKAROUNDS) += $(call cc-option,-mfix-r4400,)
  9310. cflags-$(CONFIG_CPU_DADDI_WORKAROUNDS) += $(call cc-option,-mno-daddi,)
  9311. diff -Nur linux-2.6.34.orig/arch/mips/pci/Makefile linux-2.6.34/arch/mips/pci/Makefile
  9312. --- linux-2.6.34.orig/arch/mips/pci/Makefile 2010-05-16 23:17:36.000000000 +0200
  9313. +++ linux-2.6.34/arch/mips/pci/Makefile 2010-05-25 18:46:08.712416500 +0200
  9314. @@ -18,6 +18,7 @@
  9315. obj-$(CONFIG_BCM47XX) += pci-bcm47xx.o
  9316. obj-$(CONFIG_BCM63XX) += pci-bcm63xx.o fixup-bcm63xx.o \
  9317. ops-bcm63xx.o
  9318. +obj-$(CONFIG_ATHEROS_AR71XX) += pci-ar71xx.o pci-ar724x.o
  9319. #
  9320. # These are still pretty much in the old state, watch, go blind.
  9321. diff -Nur linux-2.6.34.orig/arch/mips/pci/pci-ar71xx.c linux-2.6.34/arch/mips/pci/pci-ar71xx.c
  9322. --- linux-2.6.34.orig/arch/mips/pci/pci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  9323. +++ linux-2.6.34/arch/mips/pci/pci-ar71xx.c 2010-05-25 18:46:08.752223161 +0200
  9324. @@ -0,0 +1,409 @@
  9325. +/*
  9326. + * Atheros AR71xx PCI host controller driver
  9327. + *
  9328. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  9329. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  9330. + *
  9331. + * Parts of this file are based on Atheros' 2.6.15 BSP
  9332. + *
  9333. + * This program is free software; you can redistribute it and/or modify it
  9334. + * under the terms of the GNU General Public License version 2 as published
  9335. + * by the Free Software Foundation.
  9336. + */
  9337. +
  9338. +#include <linux/resource.h>
  9339. +#include <linux/types.h>
  9340. +#include <linux/delay.h>
  9341. +#include <linux/bitops.h>
  9342. +#include <linux/pci.h>
  9343. +#include <linux/pci_regs.h>
  9344. +#include <linux/interrupt.h>
  9345. +
  9346. +#include <asm/mach-ar71xx/ar71xx.h>
  9347. +#include <asm/mach-ar71xx/pci.h>
  9348. +
  9349. +#undef DEBUG
  9350. +#ifdef DEBUG
  9351. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  9352. +#else
  9353. +#define DBG(fmt, args...)
  9354. +#endif
  9355. +
  9356. +#define AR71XX_PCI_DELAY 100 /* msecs */
  9357. +
  9358. +#if 0
  9359. +#define PCI_IDSEL_BASE PCI_IDSEL_ADL_START
  9360. +#else
  9361. +#define PCI_IDSEL_BASE 0
  9362. +#endif
  9363. +
  9364. +static void __iomem *ar71xx_pcicfg_base;
  9365. +static DEFINE_SPINLOCK(ar71xx_pci_lock);
  9366. +static int ar71xx_pci_fixup_enable;
  9367. +
  9368. +static inline void ar71xx_pci_delay(void)
  9369. +{
  9370. + mdelay(AR71XX_PCI_DELAY);
  9371. +}
  9372. +
  9373. +/* Byte lane enable bits */
  9374. +static u8 ble_table[4][4] = {
  9375. + {0x0, 0xf, 0xf, 0xf},
  9376. + {0xe, 0xd, 0xb, 0x7},
  9377. + {0xc, 0xf, 0x3, 0xf},
  9378. + {0xf, 0xf, 0xf, 0xf},
  9379. +};
  9380. +
  9381. +static inline u32 ar71xx_pci_get_ble(int where, int size, int local)
  9382. +{
  9383. + u32 t;
  9384. +
  9385. + t = ble_table[size & 3][where & 3];
  9386. + BUG_ON(t == 0xf);
  9387. + t <<= (local) ? 20 : 4;
  9388. + return t;
  9389. +}
  9390. +
  9391. +static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
  9392. + int where)
  9393. +{
  9394. + u32 ret;
  9395. +
  9396. + if (!bus->number) {
  9397. + /* type 0 */
  9398. + ret = (1 << (PCI_IDSEL_BASE + PCI_SLOT(devfn)))
  9399. + | (PCI_FUNC(devfn) << 8) | (where & ~3);
  9400. + } else {
  9401. + /* type 1 */
  9402. + ret = (bus->number << 16) | (PCI_SLOT(devfn) << 11)
  9403. + | (PCI_FUNC(devfn) << 8) | (where & ~3) | 1;
  9404. + }
  9405. +
  9406. + return ret;
  9407. +}
  9408. +
  9409. +int ar71xx_pci_be_handler(int is_fixup)
  9410. +{
  9411. + void __iomem *base = ar71xx_pcicfg_base;
  9412. + u32 pci_err;
  9413. + u32 ahb_err;
  9414. +
  9415. + pci_err = __raw_readl(base + PCI_REG_PCI_ERR) & 3;
  9416. + if (pci_err) {
  9417. + if (!is_fixup)
  9418. + printk(KERN_ALERT "PCI error %d at PCI addr 0x%x\n",
  9419. + pci_err,
  9420. + __raw_readl(base + PCI_REG_PCI_ERR_ADDR));
  9421. +
  9422. + __raw_writel(pci_err, base + PCI_REG_PCI_ERR);
  9423. + }
  9424. +
  9425. + ahb_err = __raw_readl(base + PCI_REG_AHB_ERR) & 1;
  9426. + if (ahb_err) {
  9427. + if (!is_fixup)
  9428. + printk(KERN_ALERT "AHB error at AHB address 0x%x\n",
  9429. + __raw_readl(base + PCI_REG_AHB_ERR_ADDR));
  9430. +
  9431. + __raw_writel(ahb_err, base + PCI_REG_AHB_ERR);
  9432. + }
  9433. +
  9434. + return ((ahb_err | pci_err) ? 1 : 0);
  9435. +}
  9436. +
  9437. +static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
  9438. + unsigned int devfn, int where, int size, u32 cmd)
  9439. +{
  9440. + void __iomem *base = ar71xx_pcicfg_base;
  9441. + u32 addr;
  9442. +
  9443. + addr = ar71xx_pci_bus_addr(bus, devfn, where);
  9444. +
  9445. + DBG("PCI: set cfgaddr: %02x:%02x.%01x/%02x:%01d, addr=%08x\n",
  9446. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9447. + where, size, addr);
  9448. +
  9449. + __raw_writel(addr, base + PCI_REG_CFG_AD);
  9450. + __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0),
  9451. + base + PCI_REG_CFG_CBE);
  9452. +
  9453. + return ar71xx_pci_be_handler(1);
  9454. +}
  9455. +
  9456. +static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  9457. + int where, int size, u32 *value)
  9458. +{
  9459. + void __iomem *base = ar71xx_pcicfg_base;
  9460. + static u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
  9461. + unsigned long flags;
  9462. + u32 data;
  9463. + int ret;
  9464. +
  9465. + ret = PCIBIOS_SUCCESSFUL;
  9466. +
  9467. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d\n", bus->number,
  9468. + PCI_SLOT(devfn), PCI_FUNC(devfn), where, size);
  9469. +
  9470. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  9471. +
  9472. + if (bus->number == 0 && devfn == 0) {
  9473. + u32 t;
  9474. +
  9475. + t = PCI_CRP_CMD_READ | (where & ~3);
  9476. +
  9477. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  9478. + data = __raw_readl(base + PCI_REG_CRP_RDDATA);
  9479. +
  9480. + DBG("PCI: rd local cfg, ad_cbe:%08x, data:%08x\n", t, data);
  9481. +
  9482. + } else {
  9483. + int err;
  9484. +
  9485. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  9486. + PCI_CFG_CMD_READ);
  9487. +
  9488. + if (err == 0) {
  9489. + data = __raw_readl(base + PCI_REG_CFG_RDDATA);
  9490. + } else {
  9491. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  9492. + data = ~0;
  9493. + }
  9494. + }
  9495. +
  9496. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  9497. +
  9498. + DBG("PCI: read config: data=%08x raw=%08x\n",
  9499. + (data >> (8 * (where & 3))) & mask[size & 7], data);
  9500. +
  9501. + *value = (data >> (8 * (where & 3))) & mask[size & 7];
  9502. +
  9503. + return ret;
  9504. +}
  9505. +
  9506. +static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  9507. + int where, int size, u32 value)
  9508. +{
  9509. + void __iomem *base = ar71xx_pcicfg_base;
  9510. + unsigned long flags;
  9511. + int ret;
  9512. +
  9513. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d value=%08x\n",
  9514. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9515. + where, size, value);
  9516. +
  9517. + value = value << (8 * (where & 3));
  9518. + ret = PCIBIOS_SUCCESSFUL;
  9519. +
  9520. + spin_lock_irqsave(&ar71xx_pci_lock, flags);
  9521. + if (bus->number == 0 && devfn == 0) {
  9522. + u32 t;
  9523. +
  9524. + t = PCI_CRP_CMD_WRITE | (where & ~3);
  9525. + t |= ar71xx_pci_get_ble(where, size, 1);
  9526. +
  9527. + DBG("PCI: wr local cfg, ad_cbe:%08x, value:%08x\n", t, value);
  9528. +
  9529. + __raw_writel(t, base + PCI_REG_CRP_AD_CBE);
  9530. + __raw_writel(value, base + PCI_REG_CRP_WRDATA);
  9531. + } else {
  9532. + int err;
  9533. +
  9534. + err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
  9535. + PCI_CFG_CMD_WRITE);
  9536. +
  9537. + if (err == 0)
  9538. + __raw_writel(value, base + PCI_REG_CFG_WRDATA);
  9539. + else
  9540. + ret = PCIBIOS_DEVICE_NOT_FOUND;
  9541. + }
  9542. + spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
  9543. +
  9544. + return ret;
  9545. +}
  9546. +
  9547. +static void ar71xx_pci_fixup(struct pci_dev *dev)
  9548. +{
  9549. + u32 t;
  9550. +
  9551. + if (!ar71xx_pci_fixup_enable)
  9552. + return;
  9553. +
  9554. + if (dev->bus->number != 0 || dev->devfn != 0)
  9555. + return;
  9556. +
  9557. + DBG("PCI: fixup host controller %s (%04x:%04x)\n", pci_name(dev),
  9558. + dev->vendor, dev->device);
  9559. +
  9560. + /* setup COMMAND register */
  9561. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
  9562. + | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
  9563. +
  9564. + pci_write_config_word(dev, PCI_COMMAND, t);
  9565. +}
  9566. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar71xx_pci_fixup);
  9567. +
  9568. +int __init ar71xx_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  9569. + uint8_t pin)
  9570. +{
  9571. + int irq = -1;
  9572. + int i;
  9573. +
  9574. + slot -= PCI_IDSEL_ADL_START - PCI_IDSEL_BASE;
  9575. +
  9576. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  9577. + struct ar71xx_pci_irq *entry;
  9578. +
  9579. + entry = &ar71xx_pci_irq_map[i];
  9580. + if (entry->slot == slot && entry->pin == pin) {
  9581. + irq = entry->irq;
  9582. + break;
  9583. + }
  9584. + }
  9585. +
  9586. + if (irq < 0) {
  9587. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  9588. + pin, pci_name((struct pci_dev *)dev));
  9589. + } else {
  9590. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  9591. + irq, pin, pci_name((struct pci_dev *)dev));
  9592. + }
  9593. +
  9594. + return irq;
  9595. +}
  9596. +
  9597. +static struct pci_ops ar71xx_pci_ops = {
  9598. + .read = ar71xx_pci_read_config,
  9599. + .write = ar71xx_pci_write_config,
  9600. +};
  9601. +
  9602. +static struct resource ar71xx_pci_io_resource = {
  9603. + .name = "PCI IO space",
  9604. + .start = 0,
  9605. + .end = 0,
  9606. + .flags = IORESOURCE_IO,
  9607. +};
  9608. +
  9609. +static struct resource ar71xx_pci_mem_resource = {
  9610. + .name = "PCI memory space",
  9611. + .start = AR71XX_PCI_MEM_BASE,
  9612. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  9613. + .flags = IORESOURCE_MEM
  9614. +};
  9615. +
  9616. +static struct pci_controller ar71xx_pci_controller = {
  9617. + .pci_ops = &ar71xx_pci_ops,
  9618. + .mem_resource = &ar71xx_pci_mem_resource,
  9619. + .io_resource = &ar71xx_pci_io_resource,
  9620. +};
  9621. +
  9622. +static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  9623. +{
  9624. + void __iomem *base = ar71xx_reset_base;
  9625. + u32 pending;
  9626. +
  9627. + pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
  9628. + __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9629. +
  9630. + if (pending & PCI_INT_DEV0)
  9631. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  9632. +
  9633. + else if (pending & PCI_INT_DEV1)
  9634. + generic_handle_irq(AR71XX_PCI_IRQ_DEV1);
  9635. +
  9636. + else if (pending & PCI_INT_DEV2)
  9637. + generic_handle_irq(AR71XX_PCI_IRQ_DEV2);
  9638. +
  9639. + else if (pending & PCI_INT_CORE)
  9640. + generic_handle_irq(AR71XX_PCI_IRQ_CORE);
  9641. +
  9642. + else
  9643. + spurious_interrupt();
  9644. +}
  9645. +
  9646. +static void ar71xx_pci_irq_unmask(unsigned int irq)
  9647. +{
  9648. + void __iomem *base = ar71xx_reset_base;
  9649. + u32 t;
  9650. +
  9651. + irq -= AR71XX_PCI_IRQ_BASE;
  9652. +
  9653. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9654. + __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9655. +
  9656. + /* flush write */
  9657. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9658. +}
  9659. +
  9660. +static void ar71xx_pci_irq_mask(unsigned int irq)
  9661. +{
  9662. + void __iomem *base = ar71xx_reset_base;
  9663. + u32 t;
  9664. +
  9665. + irq -= AR71XX_PCI_IRQ_BASE;
  9666. +
  9667. + t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9668. + __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9669. +
  9670. + /* flush write */
  9671. + (void) __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9672. +}
  9673. +
  9674. +static struct irq_chip ar71xx_pci_irq_chip = {
  9675. + .name = "AR71XX PCI ",
  9676. + .mask = ar71xx_pci_irq_mask,
  9677. + .unmask = ar71xx_pci_irq_unmask,
  9678. + .mask_ack = ar71xx_pci_irq_mask,
  9679. +};
  9680. +
  9681. +static void __init ar71xx_pci_irq_init(void)
  9682. +{
  9683. + void __iomem *base = ar71xx_reset_base;
  9684. + int i;
  9685. +
  9686. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  9687. + __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_STATUS);
  9688. +
  9689. + for (i = AR71XX_PCI_IRQ_BASE;
  9690. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) {
  9691. + irq_desc[i].status = IRQ_DISABLED;
  9692. + set_irq_chip_and_handler(i, &ar71xx_pci_irq_chip,
  9693. + handle_level_irq);
  9694. + }
  9695. +
  9696. + set_irq_chained_handler(AR71XX_CPU_IRQ_IP2, ar71xx_pci_irq_handler);
  9697. +}
  9698. +
  9699. +int __init ar71xx_pcibios_init(void)
  9700. +{
  9701. + void __iomem *ddr_base = ar71xx_ddr_base;
  9702. +
  9703. + ar71xx_device_stop(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  9704. + ar71xx_pci_delay();
  9705. +
  9706. + ar71xx_device_start(RESET_MODULE_PCI_BUS | RESET_MODULE_PCI_CORE);
  9707. + ar71xx_pci_delay();
  9708. +
  9709. + ar71xx_pcicfg_base = ioremap_nocache(AR71XX_PCI_CFG_BASE,
  9710. + AR71XX_PCI_CFG_SIZE);
  9711. + if (ar71xx_pcicfg_base == NULL)
  9712. + return -ENOMEM;
  9713. +
  9714. + __raw_writel(PCI_WIN0_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN0);
  9715. + __raw_writel(PCI_WIN1_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN1);
  9716. + __raw_writel(PCI_WIN2_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN2);
  9717. + __raw_writel(PCI_WIN3_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN3);
  9718. + __raw_writel(PCI_WIN4_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN4);
  9719. + __raw_writel(PCI_WIN5_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN5);
  9720. + __raw_writel(PCI_WIN6_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN6);
  9721. + __raw_writel(PCI_WIN7_OFFS, ddr_base + AR71XX_DDR_REG_PCI_WIN7);
  9722. +
  9723. + ar71xx_pci_delay();
  9724. +
  9725. + /* clear bus errors */
  9726. + (void)ar71xx_pci_be_handler(1);
  9727. +
  9728. + ar71xx_pci_fixup_enable = 1;
  9729. + ar71xx_pci_irq_init();
  9730. + register_pci_controller(&ar71xx_pci_controller);
  9731. +
  9732. + return 0;
  9733. +}
  9734. diff -Nur linux-2.6.34.orig/arch/mips/pci/pci-ar724x.c linux-2.6.34/arch/mips/pci/pci-ar724x.c
  9735. --- linux-2.6.34.orig/arch/mips/pci/pci-ar724x.c 1970-01-01 01:00:00.000000000 +0100
  9736. +++ linux-2.6.34/arch/mips/pci/pci-ar724x.c 2010-05-25 18:46:08.793464075 +0200
  9737. @@ -0,0 +1,395 @@
  9738. +/*
  9739. + * Atheros AR724x PCI host controller driver
  9740. + *
  9741. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  9742. + *
  9743. + * Parts of this file are based on Atheros' 2.6.15 BSP
  9744. + *
  9745. + * This program is free software; you can redistribute it and/or modify it
  9746. + * under the terms of the GNU General Public License version 2 as published
  9747. + * by the Free Software Foundation.
  9748. + */
  9749. +
  9750. +#include <linux/resource.h>
  9751. +#include <linux/types.h>
  9752. +#include <linux/delay.h>
  9753. +#include <linux/bitops.h>
  9754. +#include <linux/pci.h>
  9755. +#include <linux/pci_regs.h>
  9756. +#include <linux/interrupt.h>
  9757. +
  9758. +#include <asm/mach-ar71xx/ar71xx.h>
  9759. +#include <asm/mach-ar71xx/pci.h>
  9760. +
  9761. +#undef DEBUG
  9762. +#ifdef DEBUG
  9763. +#define DBG(fmt, args...) printk(KERN_INFO fmt, ## args)
  9764. +#else
  9765. +#define DBG(fmt, args...)
  9766. +#endif
  9767. +
  9768. +static void __iomem *ar724x_pci_localcfg_base;
  9769. +static void __iomem *ar724x_pci_devcfg_base;
  9770. +static void __iomem *ar724x_pci_ctrl_base;
  9771. +static int ar724x_pci_fixup_enable;
  9772. +
  9773. +static DEFINE_SPINLOCK(ar724x_pci_lock);
  9774. +
  9775. +static void ar724x_pci_read(void __iomem *base, int where, int size, u32 *value)
  9776. +{
  9777. + unsigned long flags;
  9778. + u32 data;
  9779. +
  9780. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  9781. + data = __raw_readl(base + (where & ~3));
  9782. +
  9783. + switch (size) {
  9784. + case 1:
  9785. + if (where & 1)
  9786. + data >>= 8;
  9787. + if (where & 2)
  9788. + data >>= 16;
  9789. + data &= 0xFF;
  9790. + break;
  9791. + case 2:
  9792. + if (where & 2)
  9793. + data >>= 16;
  9794. + data &= 0xFFFF;
  9795. + break;
  9796. + }
  9797. +
  9798. + *value = data;
  9799. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  9800. +}
  9801. +
  9802. +static void ar724x_pci_write(void __iomem *base, int where, int size, u32 value)
  9803. +{
  9804. + unsigned long flags;
  9805. + u32 data;
  9806. + int s;
  9807. +
  9808. + spin_lock_irqsave(&ar724x_pci_lock, flags);
  9809. + data = __raw_readl(base + (where & ~3));
  9810. +
  9811. + switch (size) {
  9812. + case 1:
  9813. + s = ((where & 3) << 3);
  9814. + data &= ~(0xFF << s);
  9815. + data |= ((value & 0xFF) << s);
  9816. + break;
  9817. + case 2:
  9818. + s = ((where & 2) << 3);
  9819. + data &= ~(0xFFFF << s);
  9820. + data |= ((value & 0xFFFF) << s);
  9821. + break;
  9822. + case 4:
  9823. + data = value;
  9824. + break;
  9825. + }
  9826. +
  9827. + __raw_writel(data, base + (where & ~3));
  9828. + /* flush write */
  9829. + (void)__raw_readl(base + (where & ~3));
  9830. + spin_unlock_irqrestore(&ar724x_pci_lock, flags);
  9831. +}
  9832. +
  9833. +static int ar724x_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  9834. + int where, int size, u32 *value)
  9835. +{
  9836. +
  9837. + if (bus->number != 0 || devfn != 0)
  9838. + return PCIBIOS_DEVICE_NOT_FOUND;
  9839. +
  9840. + ar724x_pci_read(ar724x_pci_devcfg_base, where, size, value);
  9841. +
  9842. + DBG("PCI: read config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  9843. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9844. + where, size, *value);
  9845. +
  9846. + /*
  9847. + * WAR for BAR issue - We are unable to access the PCI device space
  9848. + * if we set the BAR with proper base address
  9849. + */
  9850. + if ((where == 0x10) && (size == 4)) {
  9851. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  9852. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, 0xffff);
  9853. + else
  9854. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, 0x1000ffff);
  9855. + }
  9856. +
  9857. + return PCIBIOS_SUCCESSFUL;
  9858. +}
  9859. +
  9860. +static int ar724x_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  9861. + int where, int size, u32 value)
  9862. +{
  9863. + if (bus->number != 0 || devfn != 0)
  9864. + return PCIBIOS_DEVICE_NOT_FOUND;
  9865. +
  9866. + DBG("PCI: write config: %02x:%02x.%01x/%02x:%01d, value=%08x\n",
  9867. + bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
  9868. + where, size, value);
  9869. +
  9870. + ar724x_pci_write(ar724x_pci_devcfg_base, where, size, value);
  9871. +
  9872. + return PCIBIOS_SUCCESSFUL;
  9873. +}
  9874. +
  9875. +static void ar724x_pci_fixup(struct pci_dev *dev)
  9876. +{
  9877. + u16 cmd;
  9878. +
  9879. + if (!ar724x_pci_fixup_enable)
  9880. + return;
  9881. +
  9882. + if (dev->bus->number != 0 || dev->devfn != 0)
  9883. + return;
  9884. +
  9885. + /* setup COMMAND register */
  9886. + pci_read_config_word(dev, PCI_COMMAND, &cmd);
  9887. + cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  9888. + PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY | PCI_COMMAND_SERR |
  9889. + PCI_COMMAND_FAST_BACK;
  9890. +
  9891. + pci_write_config_word(dev, PCI_COMMAND, cmd);
  9892. +}
  9893. +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ar724x_pci_fixup);
  9894. +
  9895. +int __init ar724x_pcibios_map_irq(const struct pci_dev *dev, uint8_t slot,
  9896. + uint8_t pin)
  9897. +{
  9898. + int irq = -1;
  9899. + int i;
  9900. +
  9901. + for (i = 0; i < ar71xx_pci_nr_irqs; i++) {
  9902. + struct ar71xx_pci_irq *entry;
  9903. + entry = &ar71xx_pci_irq_map[i];
  9904. +
  9905. + if (entry->slot == slot && entry->pin == pin) {
  9906. + irq = entry->irq;
  9907. + break;
  9908. + }
  9909. + }
  9910. +
  9911. + if (irq < 0)
  9912. + printk(KERN_ALERT "PCI: no irq found for pin%u@%s\n",
  9913. + pin, pci_name((struct pci_dev *)dev));
  9914. + else
  9915. + printk(KERN_INFO "PCI: mapping irq %d to pin%u@%s\n",
  9916. + irq, pin, pci_name((struct pci_dev *)dev));
  9917. +
  9918. + return irq;
  9919. +}
  9920. +
  9921. +static struct pci_ops ar724x_pci_ops = {
  9922. + .read = ar724x_pci_read_config,
  9923. + .write = ar724x_pci_write_config,
  9924. +};
  9925. +
  9926. +static struct resource ar724x_pci_io_resource = {
  9927. + .name = "PCI IO space",
  9928. + .start = 0,
  9929. + .end = 0,
  9930. + .flags = IORESOURCE_IO,
  9931. +};
  9932. +
  9933. +static struct resource ar724x_pci_mem_resource = {
  9934. + .name = "PCI memory space",
  9935. + .start = AR71XX_PCI_MEM_BASE,
  9936. + .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
  9937. + .flags = IORESOURCE_MEM
  9938. +};
  9939. +
  9940. +static struct pci_controller ar724x_pci_controller = {
  9941. + .pci_ops = &ar724x_pci_ops,
  9942. + .mem_resource = &ar724x_pci_mem_resource,
  9943. + .io_resource = &ar724x_pci_io_resource,
  9944. +};
  9945. +
  9946. +static void __init ar724x_pci_reset(void)
  9947. +{
  9948. + ar71xx_device_stop(AR724X_RESET_PCIE);
  9949. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY);
  9950. + ar71xx_device_stop(AR724X_RESET_PCIE_PHY_SERIAL);
  9951. + udelay(100);
  9952. +
  9953. + ar71xx_device_start(AR724X_RESET_PCIE_PHY_SERIAL);
  9954. + udelay(100);
  9955. + ar71xx_device_start(AR724X_RESET_PCIE_PHY);
  9956. + ar71xx_device_start(AR724X_RESET_PCIE);
  9957. +}
  9958. +
  9959. +static int __init ar724x_pci_setup(void)
  9960. +{
  9961. + void __iomem *base = ar724x_pci_ctrl_base;
  9962. + u32 t;
  9963. +
  9964. + /* setup COMMAND register */
  9965. + t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE |
  9966. + PCI_COMMAND_PARITY|PCI_COMMAND_SERR|PCI_COMMAND_FAST_BACK;
  9967. +
  9968. + ar724x_pci_write(ar724x_pci_localcfg_base, PCI_COMMAND, 4, t);
  9969. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x20, 4, 0x1ff01000);
  9970. + ar724x_pci_write(ar724x_pci_localcfg_base, 0x24, 4, 0x1ff01000);
  9971. +
  9972. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  9973. + if (t != 0x7) {
  9974. + udelay(100000);
  9975. + __raw_writel(0, base + AR724X_PCI_REG_RESET);
  9976. + udelay(100);
  9977. + __raw_writel(4, base + AR724X_PCI_REG_RESET);
  9978. + udelay(100000);
  9979. + }
  9980. +
  9981. + if (ar71xx_soc == AR71XX_SOC_AR7240)
  9982. + t = AR724X_PCI_APP_LTSSM_ENABLE;
  9983. + else
  9984. + t = 0x1ffc1;
  9985. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  9986. + /* flush write */
  9987. + (void) __raw_readl(base + AR724X_PCI_REG_APP);
  9988. + udelay(1000);
  9989. +
  9990. + t = __raw_readl(base + AR724X_PCI_REG_RESET);
  9991. + if ((t & AR724X_PCI_RESET_LINK_UP) == 0x0) {
  9992. + printk(KERN_WARNING "PCI: no PCIe module found\n");
  9993. + return -ENODEV;
  9994. + }
  9995. +
  9996. + if (ar71xx_soc == AR71XX_SOC_AR7241 || ar71xx_soc == AR71XX_SOC_AR7242) {
  9997. + t = __raw_readl(base + AR724X_PCI_REG_APP);
  9998. + t |= BIT(16);
  9999. + __raw_writel(t, base + AR724X_PCI_REG_APP);
  10000. + }
  10001. +
  10002. + return 0;
  10003. +}
  10004. +
  10005. +static void ar724x_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  10006. +{
  10007. + void __iomem *base = ar724x_pci_ctrl_base;
  10008. + u32 pending;
  10009. +
  10010. + pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
  10011. + __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10012. +
  10013. + if (pending & AR724X_PCI_INT_DEV0)
  10014. + generic_handle_irq(AR71XX_PCI_IRQ_DEV0);
  10015. +
  10016. + else
  10017. + spurious_interrupt();
  10018. +}
  10019. +
  10020. +static void ar724x_pci_irq_unmask(unsigned int irq)
  10021. +{
  10022. + void __iomem *base = ar724x_pci_ctrl_base;
  10023. + u32 t;
  10024. +
  10025. + switch (irq) {
  10026. + case AR71XX_PCI_IRQ_DEV0:
  10027. + irq -= AR71XX_PCI_IRQ_BASE;
  10028. +
  10029. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10030. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  10031. + base + AR724X_PCI_REG_INT_MASK);
  10032. + /* flush write */
  10033. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10034. + }
  10035. +}
  10036. +
  10037. +static void ar724x_pci_irq_mask(unsigned int irq)
  10038. +{
  10039. + void __iomem *base = ar724x_pci_ctrl_base;
  10040. + u32 t;
  10041. +
  10042. + switch (irq) {
  10043. + case AR71XX_PCI_IRQ_DEV0:
  10044. + irq -= AR71XX_PCI_IRQ_BASE;
  10045. +
  10046. + t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10047. + __raw_writel(t & ~AR724X_PCI_INT_DEV0,
  10048. + base + AR724X_PCI_REG_INT_MASK);
  10049. +
  10050. + /* flush write */
  10051. + (void) __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  10052. +
  10053. + t = __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  10054. + __raw_writel(t | AR724X_PCI_INT_DEV0,
  10055. + base + AR724X_PCI_REG_INT_STATUS);
  10056. +
  10057. + /* flush write */
  10058. + (void) __raw_readl(base + AR724X_PCI_REG_INT_STATUS);
  10059. + }
  10060. +}
  10061. +
  10062. +static struct irq_chip ar724x_pci_irq_chip = {
  10063. + .name = "AR724X PCI ",
  10064. + .mask = ar724x_pci_irq_mask,
  10065. + .unmask = ar724x_pci_irq_unmask,
  10066. + .mask_ack = ar724x_pci_irq_mask,
  10067. +};
  10068. +
  10069. +static void __init ar724x_pci_irq_init(void)
  10070. +{
  10071. + void __iomem *base = ar724x_pci_ctrl_base;
  10072. + u32 t;
  10073. + int i;
  10074. +
  10075. + t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
  10076. + if (t & (AR724X_RESET_PCIE | AR724X_RESET_PCIE_PHY |
  10077. + AR724X_RESET_PCIE_PHY_SERIAL)) {
  10078. + return;
  10079. + }
  10080. +
  10081. + __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
  10082. + __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
  10083. +
  10084. + for (i = AR71XX_PCI_IRQ_BASE;
  10085. + i < AR71XX_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) {
  10086. + irq_desc[i].status = IRQ_DISABLED;
  10087. + set_irq_chip_and_handler(i, &ar724x_pci_irq_chip,
  10088. + handle_level_irq);
  10089. + }
  10090. +
  10091. + set_irq_chained_handler(AR71XX_CPU_IRQ_IP2, ar724x_pci_irq_handler);
  10092. +}
  10093. +
  10094. +int __init ar724x_pcibios_init(void)
  10095. +{
  10096. + int ret = -ENOMEM;
  10097. +
  10098. + ar724x_pci_localcfg_base = ioremap_nocache(AR724X_PCI_CRP_BASE,
  10099. + AR724X_PCI_CRP_SIZE);
  10100. + if (ar724x_pci_localcfg_base == NULL)
  10101. + goto err;
  10102. +
  10103. + ar724x_pci_devcfg_base = ioremap_nocache(AR724X_PCI_CFG_BASE,
  10104. + AR724X_PCI_CFG_SIZE);
  10105. + if (ar724x_pci_devcfg_base == NULL)
  10106. + goto err_unmap_localcfg;
  10107. +
  10108. + ar724x_pci_ctrl_base = ioremap_nocache(AR724X_PCI_CTRL_BASE,
  10109. + AR724X_PCI_CTRL_SIZE);
  10110. + if (ar724x_pci_ctrl_base == NULL)
  10111. + goto err_unmap_devcfg;
  10112. +
  10113. + ar724x_pci_reset();
  10114. + ret = ar724x_pci_setup();
  10115. + if (ret)
  10116. + goto err_unmap_ctrl;
  10117. +
  10118. + ar724x_pci_fixup_enable = 1;
  10119. + ar724x_pci_irq_init();
  10120. + register_pci_controller(&ar724x_pci_controller);
  10121. +
  10122. + return 0;
  10123. +
  10124. + err_unmap_ctrl:
  10125. + iounmap(ar724x_pci_ctrl_base);
  10126. + err_unmap_devcfg:
  10127. + iounmap(ar724x_pci_devcfg_base);
  10128. + err_unmap_localcfg:
  10129. + iounmap(ar724x_pci_localcfg_base);
  10130. + err:
  10131. + return ret;
  10132. +}
  10133. diff -Nur linux-2.6.34.orig/drivers/char/Kconfig linux-2.6.34/drivers/char/Kconfig
  10134. --- linux-2.6.34.orig/drivers/char/Kconfig 2010-05-16 23:17:36.000000000 +0200
  10135. +++ linux-2.6.34/drivers/char/Kconfig 2010-05-25 18:46:08.833464040 +0200
  10136. @@ -1024,6 +1024,14 @@
  10137. If compiled as a module, it will be called cs5535_gpio.
  10138. +config GPIO_DEVICE
  10139. + tristate "GPIO device support"
  10140. + depends on GENERIC_GPIO
  10141. + help
  10142. + Say Y to enable Linux GPIO device support. This allows control of
  10143. + GPIO pins using a character device
  10144. +
  10145. +
  10146. config RAW_DRIVER
  10147. tristate "RAW driver (/dev/raw/rawN)"
  10148. depends on BLOCK
  10149. diff -Nur linux-2.6.34.orig/drivers/char/Makefile linux-2.6.34/drivers/char/Makefile
  10150. --- linux-2.6.34.orig/drivers/char/Makefile 2010-05-16 23:17:36.000000000 +0200
  10151. +++ linux-2.6.34/drivers/char/Makefile 2010-05-25 18:46:08.873463967 +0200
  10152. @@ -95,6 +95,7 @@
  10153. obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
  10154. obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
  10155. obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
  10156. +obj-$(CONFIG_GPIO_DEVICE) += gpio_dev.o
  10157. obj-$(CONFIG_GPIO_TB0219) += tb0219.o
  10158. obj-$(CONFIG_TELCLOCK) += tlclk.o
  10159. diff -Nur linux-2.6.34.orig/drivers/gpio/nxp_74hc153.c linux-2.6.34/drivers/gpio/nxp_74hc153.c
  10160. --- linux-2.6.34.orig/drivers/gpio/nxp_74hc153.c 1970-01-01 01:00:00.000000000 +0100
  10161. +++ linux-2.6.34/drivers/gpio/nxp_74hc153.c 2010-05-25 18:46:08.913464115 +0200
  10162. @@ -0,0 +1,246 @@
  10163. +/*
  10164. + * NXP 74HC153 - Dual 4-input multiplexer GPIO driver
  10165. + *
  10166. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  10167. + *
  10168. + * This program is free software; you can redistribute it and/or modify
  10169. + * it under the terms of the GNU General Public License version 2 as
  10170. + * published by the Free Software Foundation.
  10171. + */
  10172. +
  10173. +#include <linux/module.h>
  10174. +#include <linux/init.h>
  10175. +#include <linux/gpio.h>
  10176. +#include <linux/platform_device.h>
  10177. +#include <linux/nxp_74hc153.h>
  10178. +
  10179. +#define NXP_74HC153_NUM_GPIOS 8
  10180. +#define NXP_74HC153_S0_MASK 0x1
  10181. +#define NXP_74HC153_S1_MASK 0x2
  10182. +#define NXP_74HC153_BANK_MASK 0x4
  10183. +
  10184. +struct nxp_74hc153_chip {
  10185. + struct device *parent;
  10186. + struct gpio_chip gpio_chip;
  10187. + struct mutex lock;
  10188. +};
  10189. +
  10190. +static struct nxp_74hc153_chip *gpio_to_nxp(struct gpio_chip *gc)
  10191. +{
  10192. + return container_of(gc, struct nxp_74hc153_chip, gpio_chip);
  10193. +}
  10194. +
  10195. +static int nxp_74hc153_direction_input(struct gpio_chip *gc, unsigned offset)
  10196. +{
  10197. + return 0;
  10198. +}
  10199. +
  10200. +static int nxp_74hc153_direction_output(struct gpio_chip *gc,
  10201. + unsigned offset, int val)
  10202. +{
  10203. + return -EINVAL;
  10204. +}
  10205. +
  10206. +static int nxp_74hc153_get_value(struct gpio_chip *gc, unsigned offset)
  10207. +{
  10208. + struct nxp_74hc153_chip *nxp;
  10209. + struct nxp_74hc153_platform_data *pdata;
  10210. + unsigned s0;
  10211. + unsigned s1;
  10212. + unsigned pin;
  10213. + int ret;
  10214. +
  10215. + nxp = gpio_to_nxp(gc);
  10216. + pdata = nxp->parent->platform_data;
  10217. +
  10218. + s0 = !!(offset & NXP_74HC153_S0_MASK);
  10219. + s1 = !!(offset & NXP_74HC153_S1_MASK);
  10220. + pin = (offset & NXP_74HC153_BANK_MASK) ? pdata->gpio_pin_2y
  10221. + : pdata->gpio_pin_1y;
  10222. +
  10223. + mutex_lock(&nxp->lock);
  10224. + gpio_set_value(pdata->gpio_pin_s0, s0);
  10225. + gpio_set_value(pdata->gpio_pin_s1, s1);
  10226. + ret = gpio_get_value(pin);
  10227. + mutex_unlock(&nxp->lock);
  10228. +
  10229. + return ret;
  10230. +}
  10231. +
  10232. +static void nxp_74hc153_set_value(struct gpio_chip *gc,
  10233. + unsigned offset, int val)
  10234. +{
  10235. + /* not supported */
  10236. +}
  10237. +
  10238. +static int __devinit nxp_74hc153_probe(struct platform_device *pdev)
  10239. +{
  10240. + struct nxp_74hc153_platform_data *pdata;
  10241. + struct nxp_74hc153_chip *nxp;
  10242. + struct gpio_chip *gc;
  10243. + int err;
  10244. +
  10245. + pdata = pdev->dev.platform_data;
  10246. + if (pdata == NULL) {
  10247. + dev_dbg(&pdev->dev, "no platform data specified\n");
  10248. + return -EINVAL;
  10249. + }
  10250. +
  10251. + nxp = kzalloc(sizeof(struct nxp_74hc153_chip), GFP_KERNEL);
  10252. + if (nxp == NULL) {
  10253. + dev_err(&pdev->dev, "no memory for private data\n");
  10254. + return -ENOMEM;
  10255. + }
  10256. +
  10257. + err = gpio_request(pdata->gpio_pin_s0, dev_name(&pdev->dev));
  10258. + if (err) {
  10259. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10260. + pdata->gpio_pin_s0, err);
  10261. + goto err_free_nxp;
  10262. + }
  10263. +
  10264. + err = gpio_request(pdata->gpio_pin_s1, dev_name(&pdev->dev));
  10265. + if (err) {
  10266. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10267. + pdata->gpio_pin_s1, err);
  10268. + goto err_free_s0;
  10269. + }
  10270. +
  10271. + err = gpio_request(pdata->gpio_pin_1y, dev_name(&pdev->dev));
  10272. + if (err) {
  10273. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10274. + pdata->gpio_pin_1y, err);
  10275. + goto err_free_s1;
  10276. + }
  10277. +
  10278. + err = gpio_request(pdata->gpio_pin_2y, dev_name(&pdev->dev));
  10279. + if (err) {
  10280. + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
  10281. + pdata->gpio_pin_2y, err);
  10282. + goto err_free_1y;
  10283. + }
  10284. +
  10285. + err = gpio_direction_output(pdata->gpio_pin_s0, 0);
  10286. + if (err) {
  10287. + dev_err(&pdev->dev,
  10288. + "unable to set direction of gpio %u, err=%d\n",
  10289. + pdata->gpio_pin_s0, err);
  10290. + goto err_free_2y;
  10291. + }
  10292. +
  10293. + err = gpio_direction_output(pdata->gpio_pin_s1, 0);
  10294. + if (err) {
  10295. + dev_err(&pdev->dev,
  10296. + "unable to set direction of gpio %u, err=%d\n",
  10297. + pdata->gpio_pin_s1, err);
  10298. + goto err_free_2y;
  10299. + }
  10300. +
  10301. + err = gpio_direction_input(pdata->gpio_pin_1y);
  10302. + if (err) {
  10303. + dev_err(&pdev->dev,
  10304. + "unable to set direction of gpio %u, err=%d\n",
  10305. + pdata->gpio_pin_1y, err);
  10306. + goto err_free_2y;
  10307. + }
  10308. +
  10309. + err = gpio_direction_input(pdata->gpio_pin_2y);
  10310. + if (err) {
  10311. + dev_err(&pdev->dev,
  10312. + "unable to set direction of gpio %u, err=%d\n",
  10313. + pdata->gpio_pin_2y, err);
  10314. + goto err_free_2y;
  10315. + }
  10316. +
  10317. + nxp->parent = &pdev->dev;
  10318. + mutex_init(&nxp->lock);
  10319. +
  10320. + gc = &nxp->gpio_chip;
  10321. +
  10322. + gc->direction_input = nxp_74hc153_direction_input;
  10323. + gc->direction_output = nxp_74hc153_direction_output;
  10324. + gc->get = nxp_74hc153_get_value;
  10325. + gc->set = nxp_74hc153_set_value;
  10326. + gc->can_sleep = 1;
  10327. +
  10328. + gc->base = pdata->gpio_base;
  10329. + gc->ngpio = NXP_74HC153_NUM_GPIOS;
  10330. + gc->label = dev_name(nxp->parent);
  10331. + gc->dev = nxp->parent;
  10332. + gc->owner = THIS_MODULE;
  10333. +
  10334. + err = gpiochip_add(&nxp->gpio_chip);
  10335. + if (err) {
  10336. + dev_err(&pdev->dev, "unable to add gpio chip, err=%d\n", err);
  10337. + goto err_free_2y;
  10338. + }
  10339. +
  10340. + platform_set_drvdata(pdev, nxp);
  10341. + return 0;
  10342. +
  10343. + err_free_2y:
  10344. + gpio_free(pdata->gpio_pin_2y);
  10345. + err_free_1y:
  10346. + gpio_free(pdata->gpio_pin_1y);
  10347. + err_free_s1:
  10348. + gpio_free(pdata->gpio_pin_s1);
  10349. + err_free_s0:
  10350. + gpio_free(pdata->gpio_pin_s0);
  10351. + err_free_nxp:
  10352. + kfree(nxp);
  10353. + return err;
  10354. +}
  10355. +
  10356. +static int nxp_74hc153_remove(struct platform_device *pdev)
  10357. +{
  10358. + struct nxp_74hc153_chip *nxp = platform_get_drvdata(pdev);
  10359. + struct nxp_74hc153_platform_data *pdata = pdev->dev.platform_data;
  10360. +
  10361. + if (nxp) {
  10362. + int err;
  10363. +
  10364. + err = gpiochip_remove(&nxp->gpio_chip);
  10365. + if (err) {
  10366. + dev_err(&pdev->dev,
  10367. + "unable to remove gpio chip, err=%d\n",
  10368. + err);
  10369. + return err;
  10370. + }
  10371. +
  10372. + gpio_free(pdata->gpio_pin_2y);
  10373. + gpio_free(pdata->gpio_pin_1y);
  10374. + gpio_free(pdata->gpio_pin_s1);
  10375. + gpio_free(pdata->gpio_pin_s0);
  10376. +
  10377. + kfree(nxp);
  10378. + platform_set_drvdata(pdev, NULL);
  10379. + }
  10380. +
  10381. + return 0;
  10382. +}
  10383. +
  10384. +static struct platform_driver nxp_74hc153_driver = {
  10385. + .probe = nxp_74hc153_probe,
  10386. + .remove = __devexit_p(nxp_74hc153_remove),
  10387. + .driver = {
  10388. + .name = NXP_74HC153_DRIVER_NAME,
  10389. + .owner = THIS_MODULE,
  10390. + },
  10391. +};
  10392. +
  10393. +static int __init nxp_74hc153_init(void)
  10394. +{
  10395. + return platform_driver_register(&nxp_74hc153_driver);
  10396. +}
  10397. +subsys_initcall(nxp_74hc153_init);
  10398. +
  10399. +static void __exit nxp_74hc153_exit(void)
  10400. +{
  10401. + platform_driver_unregister(&nxp_74hc153_driver);
  10402. +}
  10403. +module_exit(nxp_74hc153_exit);
  10404. +
  10405. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10406. +MODULE_DESCRIPTION("GPIO expander driver for NXP 74HC153");
  10407. +MODULE_LICENSE("GPL v2");
  10408. +MODULE_ALIAS("platform:" NXP_74HC153_DRIVER_NAME);
  10409. diff -Nur linux-2.6.34.orig/drivers/input/misc/gpio_buttons.c linux-2.6.34/drivers/input/misc/gpio_buttons.c
  10410. --- linux-2.6.34.orig/drivers/input/misc/gpio_buttons.c 1970-01-01 01:00:00.000000000 +0100
  10411. +++ linux-2.6.34/drivers/input/misc/gpio_buttons.c 2010-05-25 18:46:08.953464216 +0200
  10412. @@ -0,0 +1,216 @@
  10413. +/*
  10414. + * Driver for buttons on GPIO lines not capable of generating interrupts
  10415. + *
  10416. + * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
  10417. + * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
  10418. + *
  10419. + * This file was based on: /drivers/input/misc/cobalt_btns.c
  10420. + * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  10421. + *
  10422. + * also was based on: /drivers/input/keyboard/gpio_keys.c
  10423. + * Copyright 2005 Phil Blundell
  10424. + *
  10425. + * This program is free software; you can redistribute it and/or modify
  10426. + * it under the terms of the GNU General Public License version 2 as
  10427. + * published by the Free Software Foundation.
  10428. + *
  10429. + */
  10430. +
  10431. +#include <linux/kernel.h>
  10432. +#include <linux/module.h>
  10433. +#include <linux/init.h>
  10434. +#include <linux/slab.h>
  10435. +
  10436. +#include <linux/input.h>
  10437. +#include <linux/input-polldev.h>
  10438. +#include <linux/ioport.h>
  10439. +#include <linux/platform_device.h>
  10440. +
  10441. +#include <linux/gpio_buttons.h>
  10442. +
  10443. +#include <asm/gpio.h>
  10444. +
  10445. +#define DRV_NAME "gpio-buttons"
  10446. +#define DRV_VERSION "0.1.2"
  10447. +#define PFX DRV_NAME ": "
  10448. +
  10449. +struct gpio_button_data {
  10450. + int last_state;
  10451. + int count;
  10452. +};
  10453. +
  10454. +struct gpio_buttons_dev {
  10455. + struct input_polled_dev *poll_dev;
  10456. + struct gpio_buttons_platform_data *pdata;
  10457. + struct gpio_button_data *data;
  10458. +};
  10459. +
  10460. +static void gpio_buttons_poll(struct input_polled_dev *dev)
  10461. +{
  10462. + struct gpio_buttons_dev *bdev = dev->private;
  10463. + struct gpio_buttons_platform_data *pdata = bdev->pdata;
  10464. + struct input_dev *input = dev->input;
  10465. + int i;
  10466. +
  10467. + for (i = 0; i < bdev->pdata->nbuttons; i++) {
  10468. + struct gpio_button *button = &pdata->buttons[i];
  10469. + unsigned int type = button->type ?: EV_KEY;
  10470. + int state;
  10471. +
  10472. + if (bdev->data[i].count < button->threshold) {
  10473. + bdev->data[i].count++;
  10474. + continue;
  10475. + }
  10476. +
  10477. + state = gpio_get_value(button->gpio) ? 1 : 0;
  10478. + if (state != bdev->data[i].last_state) {
  10479. + input_event(input, type, button->code,
  10480. + !!(state ^ button->active_low));
  10481. + input_sync(input);
  10482. + bdev->data[i].count = 0;
  10483. + bdev->data[i].last_state = state;
  10484. + }
  10485. + }
  10486. +}
  10487. +
  10488. +static int __devinit gpio_buttons_probe(struct platform_device *pdev)
  10489. +{
  10490. + struct gpio_buttons_platform_data *pdata = pdev->dev.platform_data;
  10491. + struct gpio_buttons_dev *bdev;
  10492. + struct input_polled_dev *poll_dev;
  10493. + struct input_dev *input;
  10494. + int error, i;
  10495. +
  10496. + if (!pdata)
  10497. + return -ENXIO;
  10498. +
  10499. + bdev = kzalloc(sizeof(struct gpio_buttons_dev) +
  10500. + sizeof(struct gpio_button_data) * pdata->nbuttons,
  10501. + GFP_KERNEL);
  10502. + if (!bdev) {
  10503. + printk(KERN_ERR DRV_NAME "no memory for device\n");
  10504. + return -ENOMEM;
  10505. + }
  10506. +
  10507. + bdev->data = (struct gpio_button_data *) &bdev[1];
  10508. +
  10509. + poll_dev = input_allocate_polled_device();
  10510. + if (!poll_dev) {
  10511. + printk(KERN_ERR DRV_NAME "no memory for polled device\n");
  10512. + error = -ENOMEM;
  10513. + goto err_free_bdev;
  10514. + }
  10515. +
  10516. + poll_dev->private = bdev;
  10517. + poll_dev->poll = gpio_buttons_poll;
  10518. + poll_dev->poll_interval = pdata->poll_interval;
  10519. +
  10520. + input = poll_dev->input;
  10521. +
  10522. + input->evbit[0] = BIT(EV_KEY);
  10523. + input->name = pdev->name;
  10524. + input->phys = "gpio-buttons/input0";
  10525. + input->dev.parent = &pdev->dev;
  10526. +
  10527. + input->id.bustype = BUS_HOST;
  10528. + input->id.vendor = 0x0001;
  10529. + input->id.product = 0x0001;
  10530. + input->id.version = 0x0100;
  10531. +
  10532. + for (i = 0; i < pdata->nbuttons; i++) {
  10533. + struct gpio_button *button = &pdata->buttons[i];
  10534. + unsigned int gpio = button->gpio;
  10535. + unsigned int type = button->type ?: EV_KEY;
  10536. +
  10537. + error = gpio_request(gpio, button->desc ?
  10538. + button->desc : DRV_NAME);
  10539. + if (error) {
  10540. + printk(KERN_ERR PFX "unable to claim gpio %u, "
  10541. + "error %d\n", gpio, error);
  10542. + goto err_free_gpio;
  10543. + }
  10544. +
  10545. + error = gpio_direction_input(gpio);
  10546. + if (error) {
  10547. + printk(KERN_ERR PFX "unable to set direction on "
  10548. + "gpio %u, error %d\n", gpio, error);
  10549. + goto err_free_gpio;
  10550. + }
  10551. +
  10552. + input_set_capability(input, type, button->code);
  10553. + bdev->data[i].last_state = gpio_get_value(button->gpio) ? 1 : 0;
  10554. + }
  10555. +
  10556. + bdev->poll_dev = poll_dev;
  10557. + bdev->pdata = pdata;
  10558. + platform_set_drvdata(pdev, bdev);
  10559. +
  10560. + error = input_register_polled_device(poll_dev);
  10561. + if (error) {
  10562. + printk(KERN_ERR PFX "unable to register polled device, "
  10563. + "error %d\n", error);
  10564. + goto err_free_gpio;
  10565. + }
  10566. +
  10567. + return 0;
  10568. +
  10569. +err_free_gpio:
  10570. + for (i = i - 1; i >= 0; i--)
  10571. + gpio_free(pdata->buttons[i].gpio);
  10572. +
  10573. + input_free_polled_device(poll_dev);
  10574. +
  10575. +err_free_bdev:
  10576. + kfree(bdev);
  10577. +
  10578. + platform_set_drvdata(pdev, NULL);
  10579. + return error;
  10580. +}
  10581. +
  10582. +static int __devexit gpio_buttons_remove(struct platform_device *pdev)
  10583. +{
  10584. + struct gpio_buttons_dev *bdev = platform_get_drvdata(pdev);
  10585. + struct gpio_buttons_platform_data *pdata = bdev->pdata;
  10586. + int i;
  10587. +
  10588. + input_unregister_polled_device(bdev->poll_dev);
  10589. +
  10590. + for (i = 0; i < pdata->nbuttons; i++)
  10591. + gpio_free(pdata->buttons[i].gpio);
  10592. +
  10593. + input_free_polled_device(bdev->poll_dev);
  10594. +
  10595. + kfree(bdev);
  10596. + platform_set_drvdata(pdev, NULL);
  10597. +
  10598. + return 0;
  10599. +}
  10600. +
  10601. +static struct platform_driver gpio_buttons_driver = {
  10602. + .probe = gpio_buttons_probe,
  10603. + .remove = __devexit_p(gpio_buttons_remove),
  10604. + .driver = {
  10605. + .name = DRV_NAME,
  10606. + .owner = THIS_MODULE,
  10607. + },
  10608. +};
  10609. +
  10610. +static int __init gpio_buttons_init(void)
  10611. +{
  10612. + printk(KERN_INFO DRV_NAME " driver version " DRV_VERSION "\n");
  10613. + return platform_driver_register(&gpio_buttons_driver);
  10614. +}
  10615. +
  10616. +static void __exit gpio_buttons_exit(void)
  10617. +{
  10618. + platform_driver_unregister(&gpio_buttons_driver);
  10619. +}
  10620. +
  10621. +module_init(gpio_buttons_init);
  10622. +module_exit(gpio_buttons_exit);
  10623. +
  10624. +MODULE_LICENSE("GPL");
  10625. +MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
  10626. +MODULE_VERSION(DRV_VERSION);
  10627. +MODULE_DESCRIPTION("Polled buttons driver for CPU GPIOs");
  10628. +
  10629. diff -Nur linux-2.6.34.orig/drivers/input/misc/Kconfig linux-2.6.34/drivers/input/misc/Kconfig
  10630. --- linux-2.6.34.orig/drivers/input/misc/Kconfig 2010-05-16 23:17:36.000000000 +0200
  10631. +++ linux-2.6.34/drivers/input/misc/Kconfig 2010-05-25 18:46:08.990963497 +0200
  10632. @@ -340,4 +340,20 @@
  10633. To compile this driver as a module, choose M here: the
  10634. module will be called pcap_keys.
  10635. +config INPUT_GPIO_BUTTONS
  10636. + tristate "Polled GPIO buttons interface"
  10637. + depends on GENERIC_GPIO
  10638. + select INPUT_POLLDEV
  10639. + help
  10640. + This driver implements support for buttons connected
  10641. + to GPIO pins of various CPUs (and some other chips).
  10642. +
  10643. + Say Y here if your device has buttons connected
  10644. + directly to such GPIO pins. Your board-specific
  10645. + setup logic must also provide a platform device,
  10646. + with configuration data saying which GPIOs are used.
  10647. +
  10648. + To compile this driver as a module, choose M here: the
  10649. + module will be called gpio-buttons.
  10650. +
  10651. endif
  10652. diff -Nur linux-2.6.34.orig/drivers/input/misc/Makefile linux-2.6.34/drivers/input/misc/Makefile
  10653. --- linux-2.6.34.orig/drivers/input/misc/Makefile 2010-05-16 23:17:36.000000000 +0200
  10654. +++ linux-2.6.34/drivers/input/misc/Makefile 2010-05-25 18:46:09.023464096 +0200
  10655. @@ -32,4 +32,5 @@
  10656. obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
  10657. obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
  10658. obj-$(CONFIG_INPUT_YEALINK) += yealink.o
  10659. +obj-$(CONFIG_INPUT_GPIO_BUTTONS) += gpio_buttons.o
  10660. diff -Nur linux-2.6.34.orig/drivers/leds/leds-rb750.c linux-2.6.34/drivers/leds/leds-rb750.c
  10661. --- linux-2.6.34.orig/drivers/leds/leds-rb750.c 1970-01-01 01:00:00.000000000 +0100
  10662. +++ linux-2.6.34/drivers/leds/leds-rb750.c 2010-05-25 18:46:09.073472968 +0200
  10663. @@ -0,0 +1,140 @@
  10664. +/*
  10665. + * LED driver for the RouterBOARD 750
  10666. + *
  10667. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  10668. + *
  10669. + * This program is free software; you can redistribute it and/or modify
  10670. + * it under the terms of the GNU General Public License version 2 as
  10671. + * published by the Free Software Foundation.
  10672. + *
  10673. + */
  10674. +#include <linux/kernel.h>
  10675. +#include <linux/init.h>
  10676. +#include <linux/platform_device.h>
  10677. +#include <linux/leds.h>
  10678. +
  10679. +#include <asm/mach-ar71xx/mach-rb750.h>
  10680. +
  10681. +#define DRV_NAME "leds-rb750"
  10682. +
  10683. +struct rb750_led_dev {
  10684. + struct led_classdev cdev;
  10685. + u32 mask;
  10686. + int active_low;
  10687. +};
  10688. +
  10689. +struct rb750_led_drvdata {
  10690. + struct rb750_led_dev *led_devs;
  10691. + int num_leds;
  10692. +};
  10693. +
  10694. +static inline struct rb750_led_dev *to_rbled(struct led_classdev *led_cdev)
  10695. +{
  10696. + return (struct rb750_led_dev *)container_of(led_cdev,
  10697. + struct rb750_led_dev, cdev);
  10698. +}
  10699. +
  10700. +static void rb750_led_brightness_set(struct led_classdev *led_cdev,
  10701. + enum led_brightness value)
  10702. +{
  10703. + struct rb750_led_dev *rbled = to_rbled(led_cdev);
  10704. + int level;
  10705. +
  10706. + level = (value == LED_OFF) ? 0 : 1;
  10707. + level ^= rbled->active_low;
  10708. +
  10709. + if (level)
  10710. + rb750_latch_change(0, rbled->mask);
  10711. + else
  10712. + rb750_latch_change(rbled->mask, 0);
  10713. +}
  10714. +
  10715. +static int __devinit rb750_led_probe(struct platform_device *pdev)
  10716. +{
  10717. + struct rb750_led_platform_data *pdata;
  10718. + struct rb750_led_drvdata *drvdata;
  10719. + int ret = 0;
  10720. + int i;
  10721. +
  10722. + pdata = pdev->dev.platform_data;
  10723. + if (!pdata)
  10724. + return -EINVAL;
  10725. +
  10726. + drvdata = kzalloc(sizeof(struct rb750_led_drvdata) +
  10727. + sizeof(struct rb750_led_dev) * pdata->num_leds,
  10728. + GFP_KERNEL);
  10729. + if (!drvdata)
  10730. + return -ENOMEM;
  10731. +
  10732. + drvdata->num_leds = pdata->num_leds;
  10733. + drvdata->led_devs = (struct rb750_led_dev *) &drvdata[1];
  10734. +
  10735. + for (i = 0; i < drvdata->num_leds; i++) {
  10736. + struct rb750_led_dev *rbled = &drvdata->led_devs[i];
  10737. + struct rb750_led_data *led_data = &pdata->leds[i];
  10738. +
  10739. + rbled->cdev.name = led_data->name;
  10740. + rbled->cdev.default_trigger = led_data->default_trigger;
  10741. + rbled->cdev.brightness_set = rb750_led_brightness_set;
  10742. + rbled->cdev.brightness = LED_OFF;
  10743. +
  10744. + rbled->mask = led_data->mask;
  10745. + rbled->active_low = !!led_data->active_low;
  10746. +
  10747. + ret = led_classdev_register(&pdev->dev, &rbled->cdev);
  10748. + if (ret)
  10749. + goto err;
  10750. + }
  10751. +
  10752. + platform_set_drvdata(pdev, drvdata);
  10753. + return 0;
  10754. +
  10755. + err:
  10756. + for (i = i - 1; i >= 0; i--)
  10757. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  10758. +
  10759. + kfree(drvdata);
  10760. + return ret;
  10761. +}
  10762. +
  10763. +static int __devexit rb750_led_remove(struct platform_device *pdev)
  10764. +{
  10765. + struct rb750_led_drvdata *drvdata;
  10766. + int i;
  10767. +
  10768. + drvdata = platform_get_drvdata(pdev);
  10769. + for (i = 0; i < drvdata->num_leds; i++)
  10770. + led_classdev_unregister(&drvdata->led_devs[i].cdev);
  10771. +
  10772. + kfree(drvdata);
  10773. + return 0;
  10774. +}
  10775. +
  10776. +static struct platform_driver rb750_led_driver = {
  10777. + .probe = rb750_led_probe,
  10778. + .remove = __devexit_p(rb750_led_remove),
  10779. + .driver = {
  10780. + .name = DRV_NAME,
  10781. + .owner = THIS_MODULE,
  10782. + },
  10783. +};
  10784. +
  10785. +MODULE_ALIAS("platform:leds-rb750");
  10786. +
  10787. +static int __init rb750_led_init(void)
  10788. +{
  10789. + return platform_driver_register(&rb750_led_driver);
  10790. +}
  10791. +
  10792. +static void __exit rb750_led_exit(void)
  10793. +{
  10794. + platform_driver_unregister(&rb750_led_driver);
  10795. +}
  10796. +
  10797. +module_init(rb750_led_init);
  10798. +module_exit(rb750_led_exit);
  10799. +
  10800. +MODULE_DESCRIPTION(DRV_NAME);
  10801. +MODULE_DESCRIPTION("LED driver for the RouterBOARD 750");
  10802. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10803. +MODULE_LICENSE("GPL v2");
  10804. diff -Nur linux-2.6.34.orig/drivers/leds/leds-wndr3700-usb.c linux-2.6.34/drivers/leds/leds-wndr3700-usb.c
  10805. --- linux-2.6.34.orig/drivers/leds/leds-wndr3700-usb.c 1970-01-01 01:00:00.000000000 +0100
  10806. +++ linux-2.6.34/drivers/leds/leds-wndr3700-usb.c 2010-05-25 18:46:09.111217247 +0200
  10807. @@ -0,0 +1,75 @@
  10808. +/*
  10809. + * USB LED driver for the NETGEAR WNDR3700
  10810. + *
  10811. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10812. + *
  10813. + * This program is free software; you can redistribute it and/or modify it
  10814. + * under the terms of the GNU General Public License version 2 as published
  10815. + * by the Free Software Foundation.
  10816. + */
  10817. +
  10818. +#include <linux/leds.h>
  10819. +#include <linux/module.h>
  10820. +#include <linux/platform_device.h>
  10821. +
  10822. +#include <asm/mach-ar71xx/ar71xx.h>
  10823. +
  10824. +#define DRIVER_NAME "wndr3700-led-usb"
  10825. +
  10826. +static void wndr3700_usb_led_set(struct led_classdev *cdev,
  10827. + enum led_brightness brightness)
  10828. +{
  10829. + if (brightness)
  10830. + ar71xx_device_start(RESET_MODULE_GE1_PHY);
  10831. + else
  10832. + ar71xx_device_stop(RESET_MODULE_GE1_PHY);
  10833. +}
  10834. +
  10835. +static enum led_brightness wndr3700_usb_led_get(struct led_classdev *cdev)
  10836. +{
  10837. + return ar71xx_device_stopped(RESET_MODULE_GE1_PHY) ? LED_OFF : LED_FULL;
  10838. +}
  10839. +
  10840. +static struct led_classdev wndr3700_usb_led = {
  10841. + .name = "wndr3700:green:usb",
  10842. + .brightness_set = wndr3700_usb_led_set,
  10843. + .brightness_get = wndr3700_usb_led_get,
  10844. +};
  10845. +
  10846. +static int __devinit wndr3700_usb_led_probe(struct platform_device *pdev)
  10847. +{
  10848. + return led_classdev_register(&pdev->dev, &wndr3700_usb_led);
  10849. +}
  10850. +
  10851. +static int __devexit wndr3700_usb_led_remove(struct platform_device *pdev)
  10852. +{
  10853. + led_classdev_unregister(&wndr3700_usb_led);
  10854. + return 0;
  10855. +}
  10856. +
  10857. +static struct platform_driver wndr3700_usb_led_driver = {
  10858. + .probe = wndr3700_usb_led_probe,
  10859. + .remove = __devexit_p(wndr3700_usb_led_remove),
  10860. + .driver = {
  10861. + .name = DRIVER_NAME,
  10862. + .owner = THIS_MODULE,
  10863. + },
  10864. +};
  10865. +
  10866. +static int __init wndr3700_usb_led_init(void)
  10867. +{
  10868. + return platform_driver_register(&wndr3700_usb_led_driver);
  10869. +}
  10870. +
  10871. +static void __exit wndr3700_usb_led_exit(void)
  10872. +{
  10873. + platform_driver_unregister(&wndr3700_usb_led_driver);
  10874. +}
  10875. +
  10876. +module_init(wndr3700_usb_led_init);
  10877. +module_exit(wndr3700_usb_led_exit);
  10878. +
  10879. +MODULE_DESCRIPTION("USB LED driver for the NETGEAR WNDR3700");
  10880. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  10881. +MODULE_LICENSE("GPL v2");
  10882. +MODULE_ALIAS("platform:" DRIVER_NAME);
  10883. diff -Nur linux-2.6.34.orig/drivers/mtd/maps/ar91xx_flash.c linux-2.6.34/drivers/mtd/maps/ar91xx_flash.c
  10884. --- linux-2.6.34.orig/drivers/mtd/maps/ar91xx_flash.c 1970-01-01 01:00:00.000000000 +0100
  10885. +++ linux-2.6.34/drivers/mtd/maps/ar91xx_flash.c 2010-05-25 18:46:09.152223170 +0200
  10886. @@ -0,0 +1,310 @@
  10887. +/*
  10888. + * Parallel flash driver for the Atheros AR91xx SoC
  10889. + *
  10890. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  10891. + *
  10892. + * This program is free software; you can redistribute it and/or modify
  10893. + * it under the terms of the GNU General Public License version 2 as
  10894. + * published by the Free Software Foundation.
  10895. + *
  10896. + */
  10897. +
  10898. +#include <linux/module.h>
  10899. +#include <linux/types.h>
  10900. +#include <linux/kernel.h>
  10901. +#include <linux/init.h>
  10902. +#include <linux/slab.h>
  10903. +#include <linux/device.h>
  10904. +#include <linux/platform_device.h>
  10905. +#include <linux/mtd/mtd.h>
  10906. +#include <linux/mtd/map.h>
  10907. +#include <linux/mtd/partitions.h>
  10908. +#include <linux/io.h>
  10909. +
  10910. +#include <asm/mach-ar71xx/ar71xx.h>
  10911. +#include <asm/mach-ar71xx/ar91xx_flash.h>
  10912. +
  10913. +#define DRV_NAME "ar91xx-flash"
  10914. +
  10915. +struct ar91xx_flash_info {
  10916. + struct mtd_info *mtd;
  10917. + struct map_info map;
  10918. +#ifdef CONFIG_MTD_PARTITIONS
  10919. + int nr_parts;
  10920. + struct mtd_partition *parts;
  10921. +#endif
  10922. +};
  10923. +
  10924. +static map_word ar91xx_flash_read(struct map_info *map, unsigned long ofs)
  10925. +{
  10926. + map_word val;
  10927. +
  10928. + if (map_bankwidth_is_1(map))
  10929. + val.x[0] = __raw_readb(map->virt + (ofs ^ 3));
  10930. + else if (map_bankwidth_is_2(map))
  10931. + val.x[0] = __raw_readw(map->virt + (ofs ^ 2));
  10932. + else
  10933. + val = map_word_ff(map);
  10934. +
  10935. + return val;
  10936. +}
  10937. +
  10938. +static void ar91xx_flash_write(struct map_info *map, map_word d,
  10939. + unsigned long ofs)
  10940. +{
  10941. + if (map_bankwidth_is_1(map))
  10942. + __raw_writeb(d.x[0], map->virt + (ofs ^ 3));
  10943. + else if (map_bankwidth_is_2(map))
  10944. + __raw_writew(d.x[0], map->virt + (ofs ^ 2));
  10945. +
  10946. + mb();
  10947. +}
  10948. +
  10949. +static map_word ar91xx_flash_read_lock(struct map_info *map, unsigned long ofs)
  10950. +{
  10951. + map_word ret;
  10952. +
  10953. + ar71xx_flash_acquire();
  10954. + ret = ar91xx_flash_read(map, ofs);
  10955. + ar71xx_flash_release();
  10956. +
  10957. + return ret;
  10958. +}
  10959. +
  10960. +static void ar91xx_flash_write_lock(struct map_info *map, map_word d,
  10961. + unsigned long ofs)
  10962. +{
  10963. + ar71xx_flash_acquire();
  10964. + ar91xx_flash_write(map, d, ofs);
  10965. + ar71xx_flash_release();
  10966. +}
  10967. +
  10968. +static void ar91xx_flash_copy_from_lock(struct map_info *map, void *to,
  10969. + unsigned long from, ssize_t len)
  10970. +{
  10971. + ar71xx_flash_acquire();
  10972. + inline_map_copy_from(map, to, from, len);
  10973. + ar71xx_flash_release();
  10974. +}
  10975. +
  10976. +static void ar91xx_flash_copy_to_lock(struct map_info *map, unsigned long to,
  10977. + const void *from, ssize_t len)
  10978. +{
  10979. + ar71xx_flash_acquire();
  10980. + inline_map_copy_to(map, to, from, len);
  10981. + ar71xx_flash_release();
  10982. +}
  10983. +
  10984. +static int ar91xx_flash_remove(struct platform_device *pdev)
  10985. +{
  10986. + struct ar91xx_flash_platform_data *pdata;
  10987. + struct ar91xx_flash_info *info;
  10988. +
  10989. + info = platform_get_drvdata(pdev);
  10990. + if (info == NULL)
  10991. + return 0;
  10992. +
  10993. + platform_set_drvdata(pdev, NULL);
  10994. +
  10995. + if (info->mtd == NULL)
  10996. + return 0;
  10997. +
  10998. + pdata = pdev->dev.platform_data;
  10999. +#ifdef CONFIG_MTD_PARTITIONS
  11000. + if (info->nr_parts) {
  11001. + del_mtd_partitions(info->mtd);
  11002. + kfree(info->parts);
  11003. + } else if (pdata->nr_parts) {
  11004. + del_mtd_partitions(info->mtd);
  11005. + } else {
  11006. + del_mtd_device(info->mtd);
  11007. + }
  11008. +#else
  11009. + del_mtd_device(info->mtd);
  11010. +#endif
  11011. + map_destroy(info->mtd);
  11012. +
  11013. + return 0;
  11014. +}
  11015. +
  11016. +static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
  11017. +#ifdef CONFIG_MTD_PARTITIONS
  11018. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  11019. +#endif
  11020. +
  11021. +static int ar91xx_flash_probe(struct platform_device *pdev)
  11022. +{
  11023. + struct ar91xx_flash_platform_data *pdata;
  11024. + struct ar91xx_flash_info *info;
  11025. + struct resource *res;
  11026. + struct resource *region;
  11027. + const char **probe_type;
  11028. + int err = 0;
  11029. +
  11030. + pdata = pdev->dev.platform_data;
  11031. + if (pdata == NULL)
  11032. + return -EINVAL;
  11033. +
  11034. + info = devm_kzalloc(&pdev->dev, sizeof(struct ar91xx_flash_info),
  11035. + GFP_KERNEL);
  11036. + if (info == NULL) {
  11037. + err = -ENOMEM;
  11038. + goto err_out;
  11039. + }
  11040. +
  11041. + platform_set_drvdata(pdev, info);
  11042. +
  11043. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11044. + if (res == NULL) {
  11045. + err = -ENOENT;
  11046. + goto err_out;
  11047. + }
  11048. +
  11049. + dev_info(&pdev->dev, "%.8llx at %.8llx\n",
  11050. + (unsigned long long)(res->end - res->start + 1),
  11051. + (unsigned long long)res->start);
  11052. +
  11053. + region = devm_request_mem_region(&pdev->dev,
  11054. + res->start, res->end - res->start + 1,
  11055. + dev_name(&pdev->dev));
  11056. + if (region == NULL) {
  11057. + dev_err(&pdev->dev, "could not reserve memory region\n");
  11058. + err = -ENOMEM;
  11059. + goto err_out;
  11060. + }
  11061. +
  11062. + info->map.name = dev_name(&pdev->dev);
  11063. + info->map.phys = res->start;
  11064. + info->map.size = res->end - res->start + 1;
  11065. + info->map.bankwidth = pdata->width;
  11066. +
  11067. + info->map.virt = devm_ioremap(&pdev->dev, info->map.phys,
  11068. + info->map.size);
  11069. + if (info->map.virt == NULL) {
  11070. + dev_err(&pdev->dev, "failed to ioremap flash region\n");
  11071. + err = -EIO;
  11072. + goto err_out;
  11073. + }
  11074. +
  11075. + simple_map_init(&info->map);
  11076. + if (pdata->is_shared) {
  11077. + info->map.read = ar91xx_flash_read_lock;
  11078. + info->map.write = ar91xx_flash_write_lock;
  11079. + info->map.copy_from = ar91xx_flash_copy_from_lock;
  11080. + info->map.copy_to = ar91xx_flash_copy_to_lock;
  11081. + } else {
  11082. + info->map.read = ar91xx_flash_read;
  11083. + info->map.write = ar91xx_flash_write;
  11084. + }
  11085. +
  11086. + probe_type = rom_probe_types;
  11087. + for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
  11088. + info->mtd = do_map_probe(*probe_type, &info->map);
  11089. +
  11090. + if (info->mtd == NULL) {
  11091. + dev_err(&pdev->dev, "map_probe failed\n");
  11092. + err = -ENXIO;
  11093. + goto err_out;
  11094. + }
  11095. +
  11096. + info->mtd->owner = THIS_MODULE;
  11097. +
  11098. +#ifdef CONFIG_MTD_PARTITIONS
  11099. + if (pdata->nr_parts) {
  11100. + dev_info(&pdev->dev, "using static partition mapping\n");
  11101. + add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
  11102. + return 0;
  11103. + }
  11104. +
  11105. + err = parse_mtd_partitions(info->mtd, part_probe_types,
  11106. + &info->parts, 0);
  11107. + if (err > 0) {
  11108. + add_mtd_partitions(info->mtd, info->parts, err);
  11109. + return 0;
  11110. + }
  11111. +#endif
  11112. +
  11113. + add_mtd_device(info->mtd);
  11114. + return 0;
  11115. +
  11116. + err_out:
  11117. + ar91xx_flash_remove(pdev);
  11118. + return err;
  11119. +}
  11120. +
  11121. +#ifdef CONFIG_PM
  11122. +static int ar91xx_flash_suspend(struct platform_device *dev, pm_message_t state)
  11123. +{
  11124. + struct ar91xx_flash_info *info = platform_get_drvdata(dev);
  11125. + int ret = 0;
  11126. +
  11127. + if (info->mtd->suspend)
  11128. + ret = info->mtd->suspend(info->mtd);
  11129. +
  11130. + if (ret)
  11131. + goto fail;
  11132. +
  11133. + return 0;
  11134. +
  11135. + fail:
  11136. + if (info->mtd->suspend) {
  11137. + BUG_ON(!info->mtd->resume);
  11138. + info->mtd->resume(info->mtd);
  11139. + }
  11140. +
  11141. + return ret;
  11142. +}
  11143. +
  11144. +static int ar91xx_flash_resume(struct platform_device *pdev)
  11145. +{
  11146. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  11147. +
  11148. + if (info->mtd->resume)
  11149. + info->mtd->resume(info->mtd);
  11150. +
  11151. + return 0;
  11152. +}
  11153. +
  11154. +static void ar91xx_flash_shutdown(struct platform_device *pdev)
  11155. +{
  11156. + struct ar91xx_flash_info *info = platform_get_drvdata(pdev);
  11157. +
  11158. + if (info->mtd->suspend && info->mtd->resume)
  11159. + if (info->mtd->suspend(info->mtd) == 0)
  11160. + info->mtd->resume(info->mtd);
  11161. +}
  11162. +#else
  11163. +#define ar91xx_flash_suspend NULL
  11164. +#define ar91xx_flash_resume NULL
  11165. +#define ar91xx_flash_shutdown NULL
  11166. +#endif
  11167. +
  11168. +static struct platform_driver ar91xx_flash_driver = {
  11169. + .probe = ar91xx_flash_probe,
  11170. + .remove = ar91xx_flash_remove,
  11171. + .suspend = ar91xx_flash_suspend,
  11172. + .resume = ar91xx_flash_resume,
  11173. + .shutdown = ar91xx_flash_shutdown,
  11174. + .driver = {
  11175. + .name = DRV_NAME,
  11176. + .owner = THIS_MODULE,
  11177. + },
  11178. +};
  11179. +
  11180. +static int __init ar91xx_flash_init(void)
  11181. +{
  11182. + return platform_driver_register(&ar91xx_flash_driver);
  11183. +}
  11184. +
  11185. +static void __exit ar91xx_flash_exit(void)
  11186. +{
  11187. + platform_driver_unregister(&ar91xx_flash_driver);
  11188. +}
  11189. +
  11190. +module_init(ar91xx_flash_init);
  11191. +module_exit(ar91xx_flash_exit);
  11192. +
  11193. +MODULE_LICENSE("GPL v2");
  11194. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  11195. +MODULE_DESCRIPTION("Parallel flash driver for the Atheros AR91xx SoC");
  11196. +MODULE_ALIAS("platform:" DRV_NAME);
  11197. diff -Nur linux-2.6.34.orig/drivers/mtd/maps/Kconfig linux-2.6.34/drivers/mtd/maps/Kconfig
  11198. --- linux-2.6.34.orig/drivers/mtd/maps/Kconfig 2010-05-16 23:17:36.000000000 +0200
  11199. +++ linux-2.6.34/drivers/mtd/maps/Kconfig 2010-05-25 18:46:09.183472999 +0200
  11200. @@ -251,6 +251,13 @@
  11201. help
  11202. Support for flash chips on NETtel/SecureEdge/SnapGear boards.
  11203. +config MTD_AR91XX_FLASH
  11204. + tristate "Atheros AR91xx parallel flash support"
  11205. + depends on ATHEROS_AR71XX
  11206. + select MTD_COMPLEX_MAPPINGS
  11207. + help
  11208. + Parallel flash driver for the Atheros AR91xx based boards.
  11209. +
  11210. config MTD_DILNETPC
  11211. tristate "CFI Flash device mapped on DIL/Net PC"
  11212. depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
  11213. diff -Nur linux-2.6.34.orig/drivers/mtd/maps/Makefile linux-2.6.34/drivers/mtd/maps/Makefile
  11214. --- linux-2.6.34.orig/drivers/mtd/maps/Makefile 2010-05-16 23:17:36.000000000 +0200
  11215. +++ linux-2.6.34/drivers/mtd/maps/Makefile 2010-05-25 19:02:05.812223036 +0200
  11216. @@ -7,6 +7,7 @@
  11217. endif
  11218. # Chip mappings
  11219. +obj-$(CONFIG_MTD_AR91XX_FLASH) += ar91xx_flash.o
  11220. obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
  11221. obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
  11222. obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
  11223. diff -Nur linux-2.6.34.orig/drivers/mtd/nand/Kconfig linux-2.6.34/drivers/mtd/nand/Kconfig
  11224. --- linux-2.6.34.orig/drivers/mtd/nand/Kconfig 2010-05-16 23:17:36.000000000 +0200
  11225. +++ linux-2.6.34/drivers/mtd/nand/Kconfig 2010-05-25 18:46:09.253473064 +0200
  11226. @@ -488,4 +488,8 @@
  11227. This enables the driver for the NAND Flash on evaluation board based
  11228. on w90p910.
  11229. +config MTD_NAND_RB4XX
  11230. + tristate "NAND flash driver for RouterBoard 4xx series"
  11231. + depends on MTD_NAND && AR71XX_MACH_RB4XX
  11232. +
  11233. endif # MTD_NAND
  11234. diff -Nur linux-2.6.34.orig/drivers/mtd/nand/Makefile linux-2.6.34/drivers/mtd/nand/Makefile
  11235. --- linux-2.6.34.orig/drivers/mtd/nand/Makefile 2010-05-16 23:17:36.000000000 +0200
  11236. +++ linux-2.6.34/drivers/mtd/nand/Makefile 2010-05-25 18:46:09.291161582 +0200
  11237. @@ -30,6 +30,7 @@
  11238. obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
  11239. obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o
  11240. obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
  11241. +obj-$(CONFIG_MTD_NAND_RB4XX) += rb4xx_nand.o
  11242. obj-$(CONFIG_MTD_ALAUDA) += alauda.o
  11243. obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
  11244. obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
  11245. diff -Nur linux-2.6.34.orig/drivers/mtd/nand/rb4xx_nand.c linux-2.6.34/drivers/mtd/nand/rb4xx_nand.c
  11246. --- linux-2.6.34.orig/drivers/mtd/nand/rb4xx_nand.c 1970-01-01 01:00:00.000000000 +0100
  11247. +++ linux-2.6.34/drivers/mtd/nand/rb4xx_nand.c 2010-05-25 19:20:29.870979934 +0200
  11248. @@ -0,0 +1,513 @@
  11249. +/*
  11250. + * NAND flash driver for the MikroTik RouterBoard 4xx series
  11251. + *
  11252. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  11253. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  11254. + *
  11255. + * This file was based on the driver for Linux 2.6.22 published by
  11256. + * MikroTik for their RouterBoard 4xx series devices.
  11257. + *
  11258. + * This program is free software; you can redistribute it and/or modify it
  11259. + * under the terms of the GNU General Public License version 2 as published
  11260. + * by the Free Software Foundation.
  11261. + */
  11262. +
  11263. +#include <linux/init.h>
  11264. +#include <linux/mtd/nand.h>
  11265. +#include <linux/mtd/mtd.h>
  11266. +#include <linux/mtd/partitions.h>
  11267. +#include <linux/platform_device.h>
  11268. +#include <linux/delay.h>
  11269. +#include <linux/io.h>
  11270. +#include <linux/gpio.h>
  11271. +#include <linux/slab.h>
  11272. +
  11273. +#include <asm/mach-ar71xx/ar71xx.h>
  11274. +
  11275. +#define DRV_NAME "rb4xx-nand"
  11276. +#define DRV_VERSION "0.1.10"
  11277. +#define DRV_DESC "NAND flash driver for RouterBoard 4xx series"
  11278. +
  11279. +#define USE_FAST_READ 1
  11280. +#define USE_FAST_WRITE 1
  11281. +#undef RB4XX_NAND_DEBUG
  11282. +
  11283. +#ifdef RB4XX_NAND_DEBUG
  11284. +#define DBG(fmt, arg...) printk(KERN_DEBUG DRV_NAME ": " fmt, ## arg)
  11285. +#else
  11286. +#define DBG(fmt, arg...) do {} while (0)
  11287. +#endif
  11288. +
  11289. +#define RB4XX_NAND_GPIO_RDY 5
  11290. +#define RB4XX_FLASH_HZ 33333334
  11291. +#define RB4XX_NAND_HZ 33333334
  11292. +
  11293. +#define SPI_CTRL_FASTEST 0x40
  11294. +#define SPI_CTRL_SAFE 0x43 /* 25 MHz for AHB 200 MHz */
  11295. +#define SBIT_IOC_BASE SPI_IOC_CS1
  11296. +#define SBIT_IOC_DO_SHIFT 0
  11297. +#define SBIT_IOC_DO (1u << SBIT_IOC_DO_SHIFT)
  11298. +#define SBIT_IOC_DO2_SHIFT 18
  11299. +#define SBIT_IOC_DO2 (1u << SBIT_IOC_DO2_SHIFT)
  11300. +
  11301. +#define CPLD_CMD_WRITE_MULT 0x08 /* send cmd, n x send data, read data */
  11302. +#define CPLD_CMD_WRITE_CFG 0x09 /* send cmd, n x send cfg */
  11303. +#define CPLD_CMD_READ_MULT 0x0a /* send cmd, send idle, n x read data */
  11304. +#define CPLD_CMD_READ_FAST 0x0b /* send cmd, 4 x idle, n x read data */
  11305. +
  11306. +#define CFG_BIT_nCE 0x80
  11307. +#define CFG_BIT_CLE 0x40
  11308. +#define CFG_BIT_ALE 0x20
  11309. +#define CFG_BIT_FAN 0x10
  11310. +#define CFG_BIT_nLED4 0x08
  11311. +#define CFG_BIT_nLED3 0x04
  11312. +#define CFG_BIT_nLED2 0x02
  11313. +#define CFG_BIT_nLED1 0x01
  11314. +
  11315. +#define CFG_BIT_nLEDS \
  11316. + (CFG_BIT_nLED1 | CFG_BIT_nLED2 | CFG_BIT_nLED3 | CFG_BIT_nLED4)
  11317. +
  11318. +struct rb4xx_nand_info {
  11319. + struct nand_chip chip;
  11320. + struct mtd_info mtd;
  11321. +};
  11322. +
  11323. +/*
  11324. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  11325. + * will not be able to find the kernel that we load.
  11326. + */
  11327. +static struct nand_ecclayout rb4xx_nand_ecclayout = {
  11328. + .eccbytes = 6,
  11329. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  11330. + .oobavail = 9,
  11331. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  11332. +};
  11333. +
  11334. +static struct mtd_partition rb4xx_nand_partitions[] = {
  11335. + {
  11336. + .name = "booter",
  11337. + .offset = 0,
  11338. + .size = (256 * 1024),
  11339. + .mask_flags = MTD_WRITEABLE,
  11340. + },
  11341. + {
  11342. + .name = "kernel",
  11343. + .offset = (256 * 1024),
  11344. + .size = (4 * 1024 * 1024) - (256 * 1024),
  11345. + },
  11346. + {
  11347. + .name = "rootfs",
  11348. + .offset = MTDPART_OFS_NXTBLK,
  11349. + .size = (1024*1024*64) - (1024*256) - (4 * 1024 * 1024)
  11350. + },
  11351. + {
  11352. + .name = "cfgfs",
  11353. + .offset = (1024*1024*64) - (1024*256),
  11354. + .size = (1024*256),
  11355. + },
  11356. +};
  11357. +
  11358. +#if USE_FAST_READ
  11359. +#define SPI_NDATA_BASE 0x00800000
  11360. +static unsigned spi_ctrl_fread = SPI_CTRL_SAFE;
  11361. +static unsigned spi_ctrl_flash = SPI_CTRL_SAFE;
  11362. +extern unsigned mips_hpt_frequency;
  11363. +#endif
  11364. +
  11365. +static inline unsigned rb4xx_spi_rreg(unsigned r)
  11366. +{
  11367. + return __raw_readl((void * __iomem)(KSEG1ADDR(AR71XX_SPI_BASE) + r));
  11368. +}
  11369. +
  11370. +static inline void rb4xx_spi_wreg(unsigned r, unsigned v)
  11371. +{
  11372. + __raw_writel(v, (void * __iomem)(KSEG1ADDR(AR71XX_SPI_BASE) + r));
  11373. +}
  11374. +
  11375. +static inline void do_spi_clk(int bit)
  11376. +{
  11377. + unsigned bval = SBIT_IOC_BASE | (bit & 1);
  11378. +
  11379. + rb4xx_spi_wreg(SPI_REG_IOC, bval);
  11380. + rb4xx_spi_wreg(SPI_REG_IOC, bval | SPI_IOC_CLK);
  11381. +}
  11382. +
  11383. +static void do_spi_byte(uint8_t byte)
  11384. +{
  11385. + do_spi_clk(byte >> 7);
  11386. + do_spi_clk(byte >> 6);
  11387. + do_spi_clk(byte >> 5);
  11388. + do_spi_clk(byte >> 4);
  11389. + do_spi_clk(byte >> 3);
  11390. + do_spi_clk(byte >> 2);
  11391. + do_spi_clk(byte >> 1);
  11392. + do_spi_clk(byte);
  11393. +
  11394. + DBG("spi_byte sent 0x%02x got 0x%x\n",
  11395. + byte, rb4xx_spi_rreg(SPI_REG_RDS));
  11396. +}
  11397. +
  11398. +#if USE_FAST_WRITE
  11399. +static inline void do_spi_clk_fast(int bit1, int bit2)
  11400. +{
  11401. + unsigned bval = (SBIT_IOC_BASE |
  11402. + ((bit1 << SBIT_IOC_DO_SHIFT) & SBIT_IOC_DO) |
  11403. + ((bit2 << SBIT_IOC_DO2_SHIFT) & SBIT_IOC_DO2));
  11404. +
  11405. + rb4xx_spi_wreg(SPI_REG_IOC, bval);
  11406. + rb4xx_spi_wreg(SPI_REG_IOC, bval | SPI_IOC_CLK);
  11407. +}
  11408. +
  11409. +static inline void do_spi_byte_fast(uint8_t byte)
  11410. +{
  11411. + do_spi_clk_fast(byte >> 7, byte >> 6);
  11412. + do_spi_clk_fast(byte >> 5, byte >> 4);
  11413. + do_spi_clk_fast(byte >> 3, byte >> 2);
  11414. + do_spi_clk_fast(byte >> 1, byte >> 0);
  11415. +
  11416. + DBG("spi_byte_fast sent 0x%02x got 0x%x\n",
  11417. + byte, rb4xx_spi_rreg(SPI_REG_RDS));
  11418. +}
  11419. +#else
  11420. +static inline void do_spi_byte_fast(uint8_t byte)
  11421. +{
  11422. + do_spi_byte(byte);
  11423. +}
  11424. +#endif /* USE_FAST_WRITE */
  11425. +
  11426. +static int do_spi_cmd(unsigned cmd, unsigned sendCnt, const uint8_t *sendData,
  11427. + unsigned recvCnt, uint8_t *recvData,
  11428. + const uint8_t *verifyData, int fastWrite)
  11429. +{
  11430. + unsigned i;
  11431. +
  11432. + DBG("SPI cmd 0x%x send %u recv %u\n", cmd, sendCnt, recvCnt);
  11433. +
  11434. + rb4xx_spi_wreg(SPI_REG_FS, SPI_FS_GPIO);
  11435. + rb4xx_spi_wreg(SPI_REG_CTRL, SPI_CTRL_FASTEST);
  11436. +
  11437. + do_spi_byte(cmd);
  11438. +#if 0
  11439. + if (cmd == CPLD_CMD_READ_FAST) {
  11440. + do_spi_byte(0x80);
  11441. + do_spi_byte(0);
  11442. + do_spi_byte(0);
  11443. + }
  11444. +#endif
  11445. + for (i = 0; i < sendCnt; ++i) {
  11446. + if (fastWrite)
  11447. + do_spi_byte_fast(sendData[i]);
  11448. + else
  11449. + do_spi_byte(sendData[i]);
  11450. + }
  11451. +
  11452. + for (i = 0; i < recvCnt; ++i) {
  11453. + if (fastWrite)
  11454. + do_spi_byte_fast(0);
  11455. + else
  11456. + do_spi_byte(0);
  11457. +
  11458. + if (recvData) {
  11459. + recvData[i] = rb4xx_spi_rreg(SPI_REG_RDS) & 0xff;
  11460. + } else if (verifyData) {
  11461. + if (verifyData[i] != (rb4xx_spi_rreg(SPI_REG_RDS)
  11462. + & 0xff))
  11463. + break;
  11464. + }
  11465. + }
  11466. +
  11467. + rb4xx_spi_wreg(SPI_REG_IOC, SBIT_IOC_BASE | SPI_IOC_CS0);
  11468. + rb4xx_spi_wreg(SPI_REG_CTRL, spi_ctrl_flash);
  11469. + rb4xx_spi_wreg(SPI_REG_FS, 0);
  11470. +
  11471. + return i == recvCnt;
  11472. +}
  11473. +
  11474. +static int got_write = 1;
  11475. +
  11476. +static void rb4xx_nand_write_data(const uint8_t *byte, unsigned cnt)
  11477. +{
  11478. + do_spi_cmd(CPLD_CMD_WRITE_MULT, cnt, byte, 1, NULL, NULL, 1);
  11479. + got_write = 1;
  11480. +}
  11481. +
  11482. +static void rb4xx_nand_write_byte(uint8_t byte)
  11483. +{
  11484. + rb4xx_nand_write_data(&byte, 1);
  11485. +}
  11486. +
  11487. +#if USE_FAST_READ
  11488. +static uint8_t *rb4xx_nand_read_getaddr(unsigned cnt)
  11489. +{
  11490. + static unsigned nboffset = 0x100000;
  11491. + unsigned addr;
  11492. +
  11493. + if (got_write) {
  11494. + nboffset = (nboffset + 31) & ~31;
  11495. + if (nboffset >= 0x100000) /* 1MB */
  11496. + nboffset = 0;
  11497. +
  11498. + got_write = 0;
  11499. + rb4xx_spi_wreg(SPI_REG_FS, SPI_FS_GPIO);
  11500. + rb4xx_spi_wreg(SPI_REG_CTRL, spi_ctrl_fread);
  11501. + rb4xx_spi_wreg(SPI_REG_FS, 0);
  11502. + }
  11503. +
  11504. + addr = KSEG1ADDR(AR71XX_SPI_BASE + SPI_NDATA_BASE) + nboffset;
  11505. + DBG("rb4xx_nand_read_getaddr 0x%x cnt 0x%x\n", addr, cnt);
  11506. +
  11507. + nboffset += cnt;
  11508. + return (uint8_t *)addr;
  11509. +}
  11510. +
  11511. +static void rb4xx_nand_read_data(uint8_t *buf, unsigned cnt)
  11512. +{
  11513. + unsigned size32 = cnt & ~31;
  11514. + unsigned remain = cnt & 31;
  11515. +
  11516. + if (size32) {
  11517. + uint8_t *addr = rb4xx_nand_read_getaddr(size32);
  11518. + memcpy(buf, (void *)addr, size32);
  11519. + }
  11520. +
  11521. + if (remain) {
  11522. + do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, remain,
  11523. + buf + size32, NULL, 0);
  11524. + }
  11525. +}
  11526. +
  11527. +static int rb4xx_nand_verify_data(const uint8_t *buf, unsigned cnt)
  11528. +{
  11529. + unsigned size32 = cnt & ~31;
  11530. + unsigned remain = cnt & 31;
  11531. +
  11532. + if (size32) {
  11533. + uint8_t *addr = rb4xx_nand_read_getaddr(size32);
  11534. + if (memcmp(buf, (void *)addr, size32) != 0)
  11535. + return 0;
  11536. + }
  11537. +
  11538. + if (remain) {
  11539. + return do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, remain,
  11540. + NULL, buf + size32, 0);
  11541. + }
  11542. + return 1;
  11543. +}
  11544. +#else /* USE_FAST_READ */
  11545. +static void rb4xx_nand_read_data(uint8_t *buf, unsigned cnt)
  11546. +{
  11547. + do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, cnt, buf, NULL, 0);
  11548. +}
  11549. +
  11550. +static int rb4xx_nand_verify_data(const uint8_t *buf, unsigned cnt)
  11551. +{
  11552. + return do_spi_cmd(CPLD_CMD_READ_MULT, 1, buf, cnt, NULL, buf, 0);
  11553. +}
  11554. +#endif /* USE_FAST_READ */
  11555. +
  11556. +static void rb4xx_nand_write_cfg(uint8_t byte)
  11557. +{
  11558. + do_spi_cmd(CPLD_CMD_WRITE_CFG, 1, &byte, 0, NULL, NULL, 0);
  11559. + got_write = 1;
  11560. +}
  11561. +
  11562. +static int rb4xx_nand_dev_ready(struct mtd_info *mtd)
  11563. +{
  11564. + return gpio_get_value(RB4XX_NAND_GPIO_RDY);
  11565. +}
  11566. +
  11567. +static void rb4xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  11568. + unsigned int ctrl)
  11569. +{
  11570. + if (ctrl & NAND_CTRL_CHANGE) {
  11571. + uint8_t cfg = CFG_BIT_nLEDS;
  11572. +
  11573. + cfg |= (ctrl & NAND_CLE) ? CFG_BIT_CLE : 0;
  11574. + cfg |= (ctrl & NAND_ALE) ? CFG_BIT_ALE : 0;
  11575. + cfg |= (ctrl & NAND_NCE) ? 0 : CFG_BIT_nCE;
  11576. +
  11577. + rb4xx_nand_write_cfg(cfg);
  11578. + }
  11579. +
  11580. + if (cmd != NAND_CMD_NONE)
  11581. + rb4xx_nand_write_byte(cmd);
  11582. +}
  11583. +
  11584. +static uint8_t rb4xx_nand_read_byte(struct mtd_info *mtd)
  11585. +{
  11586. + uint8_t byte = 0;
  11587. +
  11588. + rb4xx_nand_read_data(&byte, 1);
  11589. + return byte;
  11590. +}
  11591. +
  11592. +static void rb4xx_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf,
  11593. + int len)
  11594. +{
  11595. + rb4xx_nand_write_data(buf, len);
  11596. +}
  11597. +
  11598. +static void rb4xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf,
  11599. + int len)
  11600. +{
  11601. + rb4xx_nand_read_data(buf, len);
  11602. +}
  11603. +
  11604. +static int rb4xx_nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf,
  11605. + int len)
  11606. +{
  11607. + if (!rb4xx_nand_verify_data(buf, len))
  11608. + return -EFAULT;
  11609. +
  11610. + return 0;
  11611. +}
  11612. +
  11613. +static unsigned get_spi_ctrl(unsigned hz_max, const char *name)
  11614. +{
  11615. + unsigned div;
  11616. +
  11617. + div = (ar71xx_ahb_freq - 1) / (2 * hz_max);
  11618. + /*
  11619. + * CPU has a bug at (div == 0) - first bit read is random
  11620. + */
  11621. + if (div == 0)
  11622. + ++div;
  11623. +
  11624. + if (name) {
  11625. + unsigned ahb_khz = (ar71xx_ahb_freq + 500) / 1000;
  11626. + unsigned div_real = 2 * (div + 1);
  11627. + printk(KERN_INFO "%s SPI clock %u kHz (AHB %u kHz / %u)\n",
  11628. + name,
  11629. + ahb_khz / div_real,
  11630. + ahb_khz, div_real);
  11631. + }
  11632. +
  11633. + return SPI_CTRL_FASTEST + div;
  11634. +}
  11635. +
  11636. +static int __init rb4xx_nand_probe(struct platform_device *pdev)
  11637. +{
  11638. + struct rb4xx_nand_info *info;
  11639. + int ret;
  11640. +
  11641. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  11642. +
  11643. + ret = gpio_request(RB4XX_NAND_GPIO_RDY, "NAND RDY");
  11644. + if (ret) {
  11645. + printk(KERN_ERR "rb4xx-nand: gpio request failed\n");
  11646. + return ret;
  11647. + }
  11648. +
  11649. + ret = gpio_direction_input(RB4XX_NAND_GPIO_RDY);
  11650. + if (ret) {
  11651. + printk(KERN_ERR "rb4xx-nand: unable to set input mode "
  11652. + "on gpio%d\n", RB4XX_NAND_GPIO_RDY);
  11653. + goto err_free_gpio;
  11654. + }
  11655. +
  11656. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  11657. + if (!info) {
  11658. + printk(KERN_ERR "rb4xx-nand: no memory for private data\n");
  11659. + ret = -ENOMEM;
  11660. + goto err_free_gpio;
  11661. + }
  11662. +
  11663. +#if USE_FAST_READ
  11664. + spi_ctrl_fread = get_spi_ctrl(RB4XX_NAND_HZ, "NAND");
  11665. +#endif
  11666. + spi_ctrl_flash = get_spi_ctrl(RB4XX_FLASH_HZ, "FLASH");
  11667. +
  11668. + rb4xx_nand_write_cfg(CFG_BIT_nLEDS | CFG_BIT_nCE);
  11669. +
  11670. + info->chip.priv = &info;
  11671. + info->mtd.priv = &info->chip;
  11672. + info->mtd.owner = THIS_MODULE;
  11673. +
  11674. + info->chip.cmd_ctrl = rb4xx_nand_cmd_ctrl;
  11675. + info->chip.dev_ready = rb4xx_nand_dev_ready;
  11676. + info->chip.read_byte = rb4xx_nand_read_byte;
  11677. + info->chip.write_buf = rb4xx_nand_write_buf;
  11678. + info->chip.read_buf = rb4xx_nand_read_buf;
  11679. + info->chip.verify_buf = rb4xx_nand_verify_buf;
  11680. +
  11681. + info->chip.chip_delay = 25;
  11682. + info->chip.ecc.mode = NAND_ECC_SOFT;
  11683. + info->chip.options |= NAND_NO_AUTOINCR;
  11684. +
  11685. + platform_set_drvdata(pdev, info);
  11686. +
  11687. + ret = nand_scan_ident(&info->mtd, 1);
  11688. + if (ret) {
  11689. + ret = -ENXIO;
  11690. + goto err_free_info;
  11691. + }
  11692. +
  11693. + if (info->mtd.writesize == 512)
  11694. + info->chip.ecc.layout = &rb4xx_nand_ecclayout;
  11695. +
  11696. + ret = nand_scan_tail(&info->mtd);
  11697. + if (ret) {
  11698. + return -ENXIO;
  11699. + goto err_set_drvdata;
  11700. + }
  11701. +
  11702. +#ifdef CONFIG_MTD_PARTITIONS
  11703. + ret = add_mtd_partitions(&info->mtd, rb4xx_nand_partitions,
  11704. + ARRAY_SIZE(rb4xx_nand_partitions));
  11705. +#else
  11706. + ret = add_mtd_device(&info->mtd);
  11707. +#endif
  11708. + if (ret)
  11709. + goto err_release_nand;
  11710. +
  11711. + return 0;
  11712. +
  11713. +err_release_nand:
  11714. + nand_release(&info->mtd);
  11715. +err_set_drvdata:
  11716. + platform_set_drvdata(pdev, NULL);
  11717. +err_free_info:
  11718. + kfree(info);
  11719. +err_free_gpio:
  11720. + gpio_free(RB4XX_NAND_GPIO_RDY);
  11721. + return ret;
  11722. +}
  11723. +
  11724. +static int __devexit rb4xx_nand_remove(struct platform_device *pdev)
  11725. +{
  11726. + struct rb4xx_nand_info *info = platform_get_drvdata(pdev);
  11727. +
  11728. + nand_release(&info->mtd);
  11729. + platform_set_drvdata(pdev, NULL);
  11730. + kfree(info);
  11731. +
  11732. + return 0;
  11733. +}
  11734. +
  11735. +static struct platform_driver rb4xx_nand_driver = {
  11736. + .probe = rb4xx_nand_probe,
  11737. + .remove = __devexit_p(rb4xx_nand_remove),
  11738. + .driver = {
  11739. + .name = DRV_NAME,
  11740. + .owner = THIS_MODULE,
  11741. + },
  11742. +};
  11743. +
  11744. +static int __init rb4xx_nand_init(void)
  11745. +{
  11746. + return platform_driver_register(&rb4xx_nand_driver);
  11747. +}
  11748. +
  11749. +static void __exit rb4xx_nand_exit(void)
  11750. +{
  11751. + platform_driver_unregister(&rb4xx_nand_driver);
  11752. +}
  11753. +
  11754. +module_init(rb4xx_nand_init);
  11755. +module_exit(rb4xx_nand_exit);
  11756. +
  11757. +MODULE_DESCRIPTION(DRV_DESC);
  11758. +MODULE_VERSION(DRV_VERSION);
  11759. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  11760. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  11761. +MODULE_LICENSE("GPL v2");
  11762. diff -Nur linux-2.6.34.orig/drivers/mtd/nand/rb750_nand.c linux-2.6.34/drivers/mtd/nand/rb750_nand.c
  11763. --- linux-2.6.34.orig/drivers/mtd/nand/rb750_nand.c 1970-01-01 01:00:00.000000000 +0100
  11764. +++ linux-2.6.34/drivers/mtd/nand/rb750_nand.c 2010-05-25 18:46:09.381633487 +0200
  11765. @@ -0,0 +1,360 @@
  11766. +/*
  11767. + * NAND flash driver for the MikroTik RouterBOARD 750
  11768. + *
  11769. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  11770. + *
  11771. + * This program is free software; you can redistribute it and/or modify it
  11772. + * under the terms of the GNU General Public License version 2 as published
  11773. + * by the Free Software Foundation.
  11774. + */
  11775. +
  11776. +#include <linux/init.h>
  11777. +#include <linux/mtd/nand.h>
  11778. +#include <linux/mtd/mtd.h>
  11779. +#include <linux/mtd/partitions.h>
  11780. +#include <linux/platform_device.h>
  11781. +#include <linux/io.h>
  11782. +
  11783. +#include <asm/mach-ar71xx/ar71xx.h>
  11784. +#include <asm/mach-ar71xx/mach-rb750.h>
  11785. +
  11786. +#define DRV_NAME "rb750-nand"
  11787. +#define DRV_VERSION "0.1.0"
  11788. +#define DRV_DESC "NAND flash driver for the RouterBOARD 750"
  11789. +
  11790. +#define RB750_NAND_IO0 BIT(RB750_GPIO_NAND_IO0)
  11791. +#define RB750_NAND_ALE BIT(RB750_GPIO_NAND_ALE)
  11792. +#define RB750_NAND_CLE BIT(RB750_GPIO_NAND_CLE)
  11793. +#define RB750_NAND_NRE BIT(RB750_GPIO_NAND_NRE)
  11794. +#define RB750_NAND_NWE BIT(RB750_GPIO_NAND_NWE)
  11795. +#define RB750_NAND_RDY BIT(RB750_GPIO_NAND_RDY)
  11796. +#define RB750_NAND_NCE BIT(RB750_GPIO_NAND_NCE)
  11797. +
  11798. +#define RB750_NAND_DATA_SHIFT 1
  11799. +#define RB750_NAND_DATA_BITS (0xff << RB750_NAND_DATA_SHIFT)
  11800. +#define RB750_NAND_INPUT_BITS (RB750_NAND_DATA_BITS | RB750_NAND_RDY)
  11801. +#define RB750_NAND_OUTPUT_BITS (RB750_NAND_ALE | RB750_NAND_CLE | \
  11802. + RB750_NAND_NRE | RB750_NAND_NWE | \
  11803. + RB750_NAND_NCE)
  11804. +
  11805. +struct rb750_nand_info {
  11806. + struct nand_chip chip;
  11807. + struct mtd_info mtd;
  11808. +};
  11809. +
  11810. +/*
  11811. + * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
  11812. + * will not be able to find the kernel that we load.
  11813. + */
  11814. +static struct nand_ecclayout rb750_nand_ecclayout = {
  11815. + .eccbytes = 6,
  11816. + .eccpos = { 8, 9, 10, 13, 14, 15 },
  11817. + .oobavail = 9,
  11818. + .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  11819. +};
  11820. +
  11821. +static struct mtd_partition rb750_nand_partitions[] = {
  11822. + {
  11823. + .name = "booter",
  11824. + .offset = 0,
  11825. + .size = (256 * 1024),
  11826. + .mask_flags = MTD_WRITEABLE,
  11827. + }, {
  11828. + .name = "kernel",
  11829. + .offset = (256 * 1024),
  11830. + .size = (4 * 1024 * 1024) - (256 * 1024),
  11831. + }, {
  11832. + .name = "rootfs",
  11833. + .offset = MTDPART_OFS_NXTBLK,
  11834. + .size = MTDPART_SIZ_FULL,
  11835. + },
  11836. +};
  11837. +
  11838. +static void rb750_nand_write(const u8 *buf, unsigned len)
  11839. +{
  11840. + void __iomem *base = ar71xx_gpio_base;
  11841. + u32 out;
  11842. + unsigned i;
  11843. +
  11844. + /* set data lines to output mode */
  11845. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_DATA_BITS,
  11846. + base + GPIO_REG_OE);
  11847. +
  11848. + out = __raw_readl(base + GPIO_REG_OUT);
  11849. + out &= ~(RB750_NAND_DATA_BITS | RB750_NAND_NWE);
  11850. + for (i = 0; i != len; i++) {
  11851. + u32 data;
  11852. +
  11853. + data = buf[i];
  11854. + data <<= RB750_NAND_DATA_SHIFT;
  11855. + data |= out;
  11856. + __raw_writel(data, base + GPIO_REG_OUT);
  11857. +
  11858. + __raw_writel(data | RB750_NAND_NWE, base + GPIO_REG_OUT);
  11859. + /* flush write */
  11860. + __raw_readl(base + GPIO_REG_OUT);
  11861. + }
  11862. +
  11863. + /* set data lines to input mode */
  11864. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~RB750_NAND_DATA_BITS,
  11865. + base + GPIO_REG_OE);
  11866. + /* flush write */
  11867. + __raw_readl(base + GPIO_REG_OE);
  11868. +}
  11869. +
  11870. +static int rb750_nand_read_verify(u8 *read_buf, unsigned len,
  11871. + const u8 *verify_buf)
  11872. +{
  11873. + void __iomem *base = ar71xx_gpio_base;
  11874. + unsigned i;
  11875. +
  11876. + for (i = 0; i < len; i++) {
  11877. + u8 data;
  11878. +
  11879. + /* activate RE line */
  11880. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_CLEAR);
  11881. + /* flush write */
  11882. + __raw_readl(base + GPIO_REG_CLEAR);
  11883. +
  11884. + /* read input lines */
  11885. + data = __raw_readl(base + GPIO_REG_IN) >> RB750_NAND_DATA_SHIFT;
  11886. +
  11887. + /* deactivate RE line */
  11888. + __raw_writel(RB750_NAND_NRE, base + GPIO_REG_SET);
  11889. +
  11890. + if (read_buf)
  11891. + read_buf[i] = data;
  11892. + else if (verify_buf && verify_buf[i] != data)
  11893. + return -EFAULT;
  11894. + }
  11895. +
  11896. + return 0;
  11897. +}
  11898. +
  11899. +static void rb750_nand_select_chip(struct mtd_info *mtd, int chip)
  11900. +{
  11901. + void __iomem *base = ar71xx_gpio_base;
  11902. + u32 func;
  11903. +
  11904. + func = __raw_readl(base + GPIO_REG_FUNC);
  11905. + if (chip >= 0) {
  11906. + /* disable latch */
  11907. + rb750_latch_change(RB750_LVC573_LE, 0);
  11908. +
  11909. + /* disable alternate functions */
  11910. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  11911. + AR724X_GPIO_FUNC_SPI_EN);
  11912. +
  11913. + /* set input mode for data lines */
  11914. + __raw_writel(__raw_readl(base + GPIO_REG_OE) &
  11915. + ~RB750_NAND_INPUT_BITS,
  11916. + base + GPIO_REG_OE);
  11917. +
  11918. + /* deactivate RE and WE lines */
  11919. + __raw_writel(RB750_NAND_NRE | RB750_NAND_NWE,
  11920. + base + GPIO_REG_SET);
  11921. + /* flush write */
  11922. + (void) __raw_readl(base + GPIO_REG_SET);
  11923. +
  11924. + /* activate CE line */
  11925. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_CLEAR);
  11926. + } else {
  11927. + /* deactivate CE line */
  11928. + __raw_writel(RB750_NAND_NCE, base + GPIO_REG_SET);
  11929. + /* flush write */
  11930. + (void) __raw_readl(base + GPIO_REG_SET);
  11931. +
  11932. + __raw_writel(__raw_readl(base + GPIO_REG_OE) |
  11933. + RB750_NAND_IO0 | RB750_NAND_RDY,
  11934. + base + GPIO_REG_OE);
  11935. +
  11936. + /* restore alternate functions */
  11937. + ar71xx_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
  11938. + AR724X_GPIO_FUNC_JTAG_DISABLE);
  11939. +
  11940. + /* enable latch */
  11941. + rb750_latch_change(0, RB750_LVC573_LE);
  11942. + }
  11943. +}
  11944. +
  11945. +static int rb750_nand_dev_ready(struct mtd_info *mtd)
  11946. +{
  11947. + void __iomem *base = ar71xx_gpio_base;
  11948. +
  11949. + return !!(__raw_readl(base + GPIO_REG_IN) & RB750_NAND_RDY);
  11950. +}
  11951. +
  11952. +static void rb750_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  11953. + unsigned int ctrl)
  11954. +{
  11955. + if (ctrl & NAND_CTRL_CHANGE) {
  11956. + void __iomem *base = ar71xx_gpio_base;
  11957. + u32 t;
  11958. +
  11959. + t = __raw_readl(base + GPIO_REG_OUT);
  11960. +
  11961. + t &= ~(RB750_NAND_CLE | RB750_NAND_ALE);
  11962. + t |= (ctrl & NAND_CLE) ? RB750_NAND_CLE : 0;
  11963. + t |= (ctrl & NAND_ALE) ? RB750_NAND_ALE : 0;
  11964. +
  11965. + __raw_writel(t, base + GPIO_REG_OUT);
  11966. + /* flush write */
  11967. + __raw_readl(base + GPIO_REG_OUT);
  11968. + }
  11969. +
  11970. + if (cmd != NAND_CMD_NONE) {
  11971. + u8 t = cmd;
  11972. + rb750_nand_write(&t, 1);
  11973. + }
  11974. +}
  11975. +
  11976. +static u8 rb750_nand_read_byte(struct mtd_info *mtd)
  11977. +{
  11978. + u8 data = 0;
  11979. + rb750_nand_read_verify(&data, 1, NULL);
  11980. + return data;
  11981. +}
  11982. +
  11983. +static void rb750_nand_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  11984. +{
  11985. + rb750_nand_read_verify(buf, len, NULL);
  11986. +}
  11987. +
  11988. +static void rb750_nand_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  11989. +{
  11990. + rb750_nand_write(buf, len);
  11991. +}
  11992. +
  11993. +static int rb750_nand_verify_buf(struct mtd_info *mtd, const u8 *buf, int len)
  11994. +{
  11995. + return rb750_nand_read_verify(NULL, len, buf);
  11996. +}
  11997. +
  11998. +static void __init rb750_nand_gpio_init(void)
  11999. +{
  12000. + void __iomem *base = ar71xx_gpio_base;
  12001. + u32 out;
  12002. +
  12003. + out = __raw_readl(base + GPIO_REG_OUT);
  12004. +
  12005. + /* setup output levels */
  12006. + __raw_writel(RB750_NAND_NCE | RB750_NAND_NRE | RB750_NAND_NWE,
  12007. + base + GPIO_REG_SET);
  12008. +
  12009. + __raw_writel(RB750_NAND_ALE | RB750_NAND_CLE,
  12010. + base + GPIO_REG_CLEAR);
  12011. +
  12012. + /* setup input lines */
  12013. + __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(RB750_NAND_INPUT_BITS),
  12014. + base + GPIO_REG_OE);
  12015. +
  12016. + /* setup output lines */
  12017. + __raw_writel(__raw_readl(base + GPIO_REG_OE) | RB750_NAND_OUTPUT_BITS,
  12018. + base + GPIO_REG_OE);
  12019. +
  12020. + rb750_latch_change(~out & RB750_NAND_IO0, out & RB750_NAND_IO0);
  12021. +}
  12022. +
  12023. +static int __init rb750_nand_probe(struct platform_device *pdev)
  12024. +{
  12025. + struct rb750_nand_info *info;
  12026. + int ret;
  12027. +
  12028. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  12029. +
  12030. + rb750_nand_gpio_init();
  12031. +
  12032. + info = kzalloc(sizeof(*info), GFP_KERNEL);
  12033. + if (!info)
  12034. + return -ENOMEM;
  12035. +
  12036. + info->chip.priv = &info;
  12037. + info->mtd.priv = &info->chip;
  12038. + info->mtd.owner = THIS_MODULE;
  12039. +
  12040. + info->chip.select_chip = rb750_nand_select_chip;
  12041. + info->chip.cmd_ctrl = rb750_nand_cmd_ctrl;
  12042. + info->chip.dev_ready = rb750_nand_dev_ready;
  12043. + info->chip.read_byte = rb750_nand_read_byte;
  12044. + info->chip.write_buf = rb750_nand_write_buf;
  12045. + info->chip.read_buf = rb750_nand_read_buf;
  12046. + info->chip.verify_buf = rb750_nand_verify_buf;
  12047. +
  12048. + info->chip.chip_delay = 25;
  12049. + info->chip.ecc.mode = NAND_ECC_SOFT;
  12050. + info->chip.options |= NAND_NO_AUTOINCR;
  12051. +
  12052. + platform_set_drvdata(pdev, info);
  12053. +
  12054. + ret = nand_scan_ident(&info->mtd, 1);
  12055. + if (ret) {
  12056. + ret = -ENXIO;
  12057. + goto err_free_info;
  12058. + }
  12059. +
  12060. + if (info->mtd.writesize == 512)
  12061. + info->chip.ecc.layout = &rb750_nand_ecclayout;
  12062. +
  12063. + ret = nand_scan_tail(&info->mtd);
  12064. + if (ret) {
  12065. + return -ENXIO;
  12066. + goto err_set_drvdata;
  12067. + }
  12068. +
  12069. +#ifdef CONFIG_MTD_PARTITIONS
  12070. + ret = add_mtd_partitions(&info->mtd, rb750_nand_partitions,
  12071. + ARRAY_SIZE(rb750_nand_partitions));
  12072. +#else
  12073. + ret = add_mtd_device(&info->mtd);
  12074. +#endif
  12075. + if (ret)
  12076. + goto err_release_nand;
  12077. +
  12078. + return 0;
  12079. +
  12080. + err_release_nand:
  12081. + nand_release(&info->mtd);
  12082. + err_set_drvdata:
  12083. + platform_set_drvdata(pdev, NULL);
  12084. + err_free_info:
  12085. + kfree(info);
  12086. + return ret;
  12087. +}
  12088. +
  12089. +static int __devexit rb750_nand_remove(struct platform_device *pdev)
  12090. +{
  12091. + struct rb750_nand_info *info = platform_get_drvdata(pdev);
  12092. +
  12093. + nand_release(&info->mtd);
  12094. + platform_set_drvdata(pdev, NULL);
  12095. + kfree(info);
  12096. +
  12097. + return 0;
  12098. +}
  12099. +
  12100. +static struct platform_driver rb750_nand_driver = {
  12101. + .probe = rb750_nand_probe,
  12102. + .remove = __devexit_p(rb750_nand_remove),
  12103. + .driver = {
  12104. + .name = DRV_NAME,
  12105. + .owner = THIS_MODULE,
  12106. + },
  12107. +};
  12108. +
  12109. +static int __init rb750_nand_init(void)
  12110. +{
  12111. + return platform_driver_register(&rb750_nand_driver);
  12112. +}
  12113. +
  12114. +static void __exit rb750_nand_exit(void)
  12115. +{
  12116. + platform_driver_unregister(&rb750_nand_driver);
  12117. +}
  12118. +
  12119. +module_init(rb750_nand_init);
  12120. +module_exit(rb750_nand_exit);
  12121. +
  12122. +MODULE_DESCRIPTION(DRV_DESC);
  12123. +MODULE_VERSION(DRV_VERSION);
  12124. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  12125. +MODULE_LICENSE("GPL v2");
  12126. diff -Nur linux-2.6.34.orig/drivers/mtd/wrt160nl_part.c linux-2.6.34/drivers/mtd/wrt160nl_part.c
  12127. --- linux-2.6.34.orig/drivers/mtd/wrt160nl_part.c 1970-01-01 01:00:00.000000000 +0100
  12128. +++ linux-2.6.34/drivers/mtd/wrt160nl_part.c 2010-05-25 18:46:09.413464327 +0200
  12129. @@ -0,0 +1,181 @@
  12130. +/*
  12131. + * Copyright (C) 2009 Christian Daniel <cd@maintech.de>
  12132. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  12133. + *
  12134. + * This program is free software; you can redistribute it and/or modify
  12135. + * it under the terms of the GNU General Public License as published by
  12136. + * the Free Software Foundation; either version 2 of the License, or
  12137. + * (at your option) any later version.
  12138. + *
  12139. + * This program is distributed in the hope that it will be useful,
  12140. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12141. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12142. + * GNU General Public License for more details.
  12143. + *
  12144. + * You should have received a copy of the GNU General Public License
  12145. + * along with this program; if not, write to the Free Software
  12146. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  12147. + *
  12148. + * TRX flash partition table.
  12149. + * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
  12150. + *
  12151. + */
  12152. +
  12153. +#include <linux/kernel.h>
  12154. +#include <linux/slab.h>
  12155. +#include <linux/vmalloc.h>
  12156. +
  12157. +#include <linux/mtd/mtd.h>
  12158. +#include <linux/mtd/partitions.h>
  12159. +
  12160. +struct cybertan_header {
  12161. + char magic[4];
  12162. + u8 res1[4];
  12163. + char fw_date[3];
  12164. + char fw_ver[3];
  12165. + char id[4];
  12166. + char hw_ver;
  12167. + char unused;
  12168. + u8 flags[2];
  12169. + u8 res2[10];
  12170. +};
  12171. +
  12172. +#define TRX_PARTS 6
  12173. +#define TRX_MAGIC 0x30524448
  12174. +#define TRX_MAX_OFFSET 3
  12175. +
  12176. +struct trx_header {
  12177. + uint32_t magic; /* "HDR0" */
  12178. + uint32_t len; /* Length of file including header */
  12179. + uint32_t crc32; /* 32-bit CRC from flag_version to end of file */
  12180. + uint32_t flag_version; /* 0:15 flags, 16:31 version */
  12181. + uint32_t offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */
  12182. +};
  12183. +
  12184. +#define IH_MAGIC 0x27051956 /* Image Magic Number */
  12185. +#define IH_NMLEN 32 /* Image Name Length */
  12186. +
  12187. +struct uimage_header {
  12188. + uint32_t ih_magic; /* Image Header Magic Number */
  12189. + uint32_t ih_hcrc; /* Image Header CRC Checksum */
  12190. + uint32_t ih_time; /* Image Creation Timestamp */
  12191. + uint32_t ih_size; /* Image Data Size */
  12192. + uint32_t ih_load; /* Data» Load Address */
  12193. + uint32_t ih_ep; /* Entry Point Address */
  12194. + uint32_t ih_dcrc; /* Image Data CRC Checksum */
  12195. + uint8_t ih_os; /* Operating System */
  12196. + uint8_t ih_arch; /* CPU architecture */
  12197. + uint8_t ih_type; /* Image Type */
  12198. + uint8_t ih_comp; /* Compression Type */
  12199. + uint8_t ih_name[IH_NMLEN]; /* Image Name */
  12200. +};
  12201. +
  12202. +struct wrt160nl_header {
  12203. + struct cybertan_header cybertan;
  12204. + struct trx_header trx;
  12205. + struct uimage_header uimage;
  12206. +} __attribute__ ((packed));
  12207. +
  12208. +static struct mtd_partition trx_parts[TRX_PARTS];
  12209. +
  12210. +static int wrt160nl_parse_partitions(struct mtd_info *master,
  12211. + struct mtd_partition **pparts,
  12212. + unsigned long origin)
  12213. +{
  12214. + struct wrt160nl_header *header;
  12215. + struct trx_header *theader;
  12216. + struct uimage_header *uheader;
  12217. + size_t retlen;
  12218. + unsigned int kernel_len;
  12219. + int ret;
  12220. +
  12221. + header = vmalloc(sizeof(*header));
  12222. + if (!header) {
  12223. + return -ENOMEM;
  12224. + goto out;
  12225. + }
  12226. +
  12227. + ret = master->read(master, 4 * master->erasesize, sizeof(*header),
  12228. + &retlen, (void *) header);
  12229. + if (ret)
  12230. + goto free_hdr;
  12231. +
  12232. + if (retlen != sizeof(*header)) {
  12233. + ret = -EIO;
  12234. + goto free_hdr;
  12235. + }
  12236. +
  12237. + if (strncmp(header->cybertan.magic, "NL16", 4) != 0) {
  12238. + printk(KERN_NOTICE "%s: no WRT160NL signature found\n",
  12239. + master->name);
  12240. + goto free_hdr;
  12241. + }
  12242. +
  12243. + theader = &header->trx;
  12244. + if (le32_to_cpu(theader->magic) != TRX_MAGIC) {
  12245. + printk(KERN_NOTICE "%s: no TRX header found\n", master->name);
  12246. + goto free_hdr;
  12247. + }
  12248. +
  12249. + uheader = &header->uimage;
  12250. + if (uheader->ih_magic != IH_MAGIC) {
  12251. + printk(KERN_NOTICE "%s: no uImage found\n", master->name);
  12252. + goto free_hdr;
  12253. + }
  12254. +
  12255. + kernel_len = le32_to_cpu(theader->offsets[1]) + sizeof(struct cybertan_header);
  12256. +
  12257. + trx_parts[0].name = "u-boot";
  12258. + trx_parts[0].offset = 0;
  12259. + trx_parts[0].size = 4 * master->erasesize;
  12260. + trx_parts[0].mask_flags = MTD_WRITEABLE;
  12261. +
  12262. + trx_parts[1].name = "kernel";
  12263. + trx_parts[1].offset = trx_parts[0].offset + trx_parts[0].size;
  12264. + trx_parts[1].size = kernel_len;
  12265. + trx_parts[1].mask_flags = 0;
  12266. +
  12267. + trx_parts[2].name = "rootfs";
  12268. + trx_parts[2].offset = trx_parts[1].offset + trx_parts[1].size;
  12269. + trx_parts[2].size = master->size - 6 * master->erasesize - trx_parts[1].size;
  12270. + trx_parts[2].mask_flags = 0;
  12271. +
  12272. + trx_parts[3].name = "nvram";
  12273. + trx_parts[3].offset = master->size - 2 * master->erasesize;
  12274. + trx_parts[3].size = master->erasesize;
  12275. + trx_parts[3].mask_flags = MTD_WRITEABLE;
  12276. +
  12277. + trx_parts[4].name = "art";
  12278. + trx_parts[4].offset = master->size - master->erasesize;
  12279. + trx_parts[4].size = master->erasesize;
  12280. + trx_parts[4].mask_flags = MTD_WRITEABLE;
  12281. +
  12282. + trx_parts[5].name = "firmware";
  12283. + trx_parts[5].offset = 4 * master->erasesize;
  12284. + trx_parts[5].size = master->size - 6 * master->erasesize;
  12285. + trx_parts[5].mask_flags = 0;
  12286. +
  12287. + *pparts = trx_parts;
  12288. + ret = TRX_PARTS;
  12289. +
  12290. + free_hdr:
  12291. + vfree(header);
  12292. + out:
  12293. + return ret;
  12294. +}
  12295. +
  12296. +static struct mtd_part_parser wrt160nl_parser = {
  12297. + .owner = THIS_MODULE,
  12298. + .parse_fn = wrt160nl_parse_partitions,
  12299. + .name = "wrt160nl",
  12300. +};
  12301. +
  12302. +static int __init wrt160nl_parser_init(void)
  12303. +{
  12304. + return register_mtd_parser(&wrt160nl_parser);
  12305. +}
  12306. +
  12307. +module_init(wrt160nl_parser_init);
  12308. +
  12309. +MODULE_LICENSE("GPL");
  12310. +MODULE_AUTHOR("Christian Daniel <cd@maintech.de>");
  12311. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_ar8216.c linux-2.6.34/drivers/net/ag71xx/ag71xx_ar8216.c
  12312. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_ar8216.c 1970-01-01 01:00:00.000000000 +0100
  12313. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_ar8216.c 2010-05-25 18:46:09.453464158 +0200
  12314. @@ -0,0 +1,44 @@
  12315. +/*
  12316. + * Atheros AR71xx built-in ethernet mac driver
  12317. + * Special support for the Atheros ar8216 switch chip
  12318. + *
  12319. + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  12320. + *
  12321. + * Based on Atheros' AG7100 driver
  12322. + *
  12323. + * This program is free software; you can redistribute it and/or modify it
  12324. + * under the terms of the GNU General Public License version 2 as published
  12325. + * by the Free Software Foundation.
  12326. + */
  12327. +
  12328. +#include "ag71xx.h"
  12329. +
  12330. +#define AR8216_PACKET_TYPE_MASK 0xf
  12331. +#define AR8216_PACKET_TYPE_NORMAL 0
  12332. +
  12333. +#define AR8216_HEADER_LEN 2
  12334. +
  12335. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb)
  12336. +{
  12337. + skb_push(skb, AR8216_HEADER_LEN);
  12338. + skb->data[0] = 0x10;
  12339. + skb->data[1] = 0x80;
  12340. +}
  12341. +
  12342. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  12343. + int pktlen)
  12344. +{
  12345. + u8 type;
  12346. +
  12347. + type = skb->data[1] & AR8216_PACKET_TYPE_MASK;
  12348. + switch (type) {
  12349. + case AR8216_PACKET_TYPE_NORMAL:
  12350. + break;
  12351. +
  12352. + default:
  12353. + return -EINVAL;
  12354. + }
  12355. +
  12356. + skb_pull(skb, AR8216_HEADER_LEN);
  12357. + return 0;
  12358. +}
  12359. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_debugfs.c linux-2.6.34/drivers/net/ag71xx/ag71xx_debugfs.c
  12360. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  12361. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_debugfs.c 2010-05-25 18:46:09.493464124 +0200
  12362. @@ -0,0 +1,197 @@
  12363. +/*
  12364. + * Atheros AR71xx built-in ethernet mac driver
  12365. + *
  12366. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12367. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12368. + *
  12369. + * Based on Atheros' AG7100 driver
  12370. + *
  12371. + * This program is free software; you can redistribute it and/or modify it
  12372. + * under the terms of the GNU General Public License version 2 as published
  12373. + * by the Free Software Foundation.
  12374. + */
  12375. +
  12376. +#include <linux/debugfs.h>
  12377. +
  12378. +#include "ag71xx.h"
  12379. +
  12380. +static struct dentry *ag71xx_debugfs_root;
  12381. +
  12382. +static int ag71xx_debugfs_generic_open(struct inode *inode, struct file *file)
  12383. +{
  12384. + file->private_data = inode->i_private;
  12385. + return 0;
  12386. +}
  12387. +
  12388. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status)
  12389. +{
  12390. + if (status)
  12391. + ag->debug.int_stats.total++;
  12392. + if (status & AG71XX_INT_TX_PS)
  12393. + ag->debug.int_stats.tx_ps++;
  12394. + if (status & AG71XX_INT_TX_UR)
  12395. + ag->debug.int_stats.tx_ur++;
  12396. + if (status & AG71XX_INT_TX_BE)
  12397. + ag->debug.int_stats.tx_be++;
  12398. + if (status & AG71XX_INT_RX_PR)
  12399. + ag->debug.int_stats.rx_pr++;
  12400. + if (status & AG71XX_INT_RX_OF)
  12401. + ag->debug.int_stats.rx_of++;
  12402. + if (status & AG71XX_INT_RX_BE)
  12403. + ag->debug.int_stats.rx_be++;
  12404. +}
  12405. +
  12406. +static ssize_t read_file_int_stats(struct file *file, char __user *user_buf,
  12407. + size_t count, loff_t *ppos)
  12408. +{
  12409. +#define PR_INT_STAT(_label, _field) \
  12410. + len += snprintf(buf + len, sizeof(buf) - len, \
  12411. + "%20s: %10lu\n", _label, ag->debug.int_stats._field);
  12412. +
  12413. + struct ag71xx *ag = file->private_data;
  12414. + char buf[256];
  12415. + unsigned int len = 0;
  12416. +
  12417. + PR_INT_STAT("TX Packet Sent", tx_ps);
  12418. + PR_INT_STAT("TX Underrun", tx_ur);
  12419. + PR_INT_STAT("TX Bus Error", tx_be);
  12420. + PR_INT_STAT("RX Packet Received", rx_pr);
  12421. + PR_INT_STAT("RX Overflow", rx_of);
  12422. + PR_INT_STAT("RX Bus Error", rx_be);
  12423. + len += snprintf(buf + len, sizeof(buf) - len, "\n");
  12424. + PR_INT_STAT("Total", total);
  12425. +
  12426. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  12427. +#undef PR_INT_STAT
  12428. +}
  12429. +
  12430. +static const struct file_operations ag71xx_fops_int_stats = {
  12431. + .open = ag71xx_debugfs_generic_open,
  12432. + .read = read_file_int_stats,
  12433. + .owner = THIS_MODULE
  12434. +};
  12435. +
  12436. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx)
  12437. +{
  12438. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  12439. +
  12440. + if (rx) {
  12441. + stats->rx_count++;
  12442. + stats->rx_packets += rx;
  12443. + if (rx <= AG71XX_NAPI_WEIGHT)
  12444. + stats->rx[rx]++;
  12445. + if (rx > stats->rx_packets_max)
  12446. + stats->rx_packets_max = rx;
  12447. + }
  12448. +
  12449. + if (tx) {
  12450. + stats->tx_count++;
  12451. + stats->tx_packets += tx;
  12452. + if (tx <= AG71XX_NAPI_WEIGHT)
  12453. + stats->tx[tx]++;
  12454. + if (tx > stats->tx_packets_max)
  12455. + stats->tx_packets_max = tx;
  12456. + }
  12457. +}
  12458. +
  12459. +static ssize_t read_file_napi_stats(struct file *file, char __user *user_buf,
  12460. + size_t count, loff_t *ppos)
  12461. +{
  12462. + struct ag71xx *ag = file->private_data;
  12463. + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats;
  12464. + char buf[2048];
  12465. + unsigned int len = 0;
  12466. + unsigned long rx_avg = 0;
  12467. + unsigned long tx_avg = 0;
  12468. + int i;
  12469. +
  12470. + if (stats->rx_count)
  12471. + rx_avg = stats->rx_packets / stats->rx_count;
  12472. +
  12473. + if (stats->tx_count)
  12474. + tx_avg = stats->tx_packets / stats->tx_count;
  12475. +
  12476. + len += snprintf(buf + len, sizeof(buf) - len, "%3s %10s %10s\n",
  12477. + "len", "rx", "tx");
  12478. +
  12479. + for (i = 1; i <= AG71XX_NAPI_WEIGHT; i++)
  12480. + len += snprintf(buf + len, sizeof(buf) - len,
  12481. + "%3d: %10lu %10lu\n",
  12482. + i, stats->rx[i], stats->tx[i]);
  12483. +
  12484. + len += snprintf(buf + len, sizeof(buf) - len, "\n");
  12485. +
  12486. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12487. + "sum", stats->rx_count, stats->tx_count);
  12488. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12489. + "avg", rx_avg, tx_avg);
  12490. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12491. + "max", stats->rx_packets_max, stats->tx_packets_max);
  12492. + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n",
  12493. + "pkt", stats->rx_packets, stats->tx_packets);
  12494. +
  12495. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  12496. +}
  12497. +
  12498. +static const struct file_operations ag71xx_fops_napi_stats = {
  12499. + .open = ag71xx_debugfs_generic_open,
  12500. + .read = read_file_napi_stats,
  12501. + .owner = THIS_MODULE
  12502. +};
  12503. +
  12504. +void ag71xx_debugfs_exit(struct ag71xx *ag)
  12505. +{
  12506. + debugfs_remove(ag->debug.debugfs_napi_stats);
  12507. + debugfs_remove(ag->debug.debugfs_int_stats);
  12508. + debugfs_remove(ag->debug.debugfs_dir);
  12509. +}
  12510. +
  12511. +int ag71xx_debugfs_init(struct ag71xx *ag)
  12512. +{
  12513. + ag->debug.debugfs_dir = debugfs_create_dir(ag->dev->name,
  12514. + ag71xx_debugfs_root);
  12515. + if (!ag->debug.debugfs_dir)
  12516. + goto err;
  12517. +
  12518. + ag->debug.debugfs_int_stats =
  12519. + debugfs_create_file("int_stats",
  12520. + S_IRUGO,
  12521. + ag->debug.debugfs_dir,
  12522. + ag,
  12523. + &ag71xx_fops_int_stats);
  12524. + if (!ag->debug.debugfs_int_stats)
  12525. + goto err;
  12526. +
  12527. + ag->debug.debugfs_napi_stats =
  12528. + debugfs_create_file("napi_stats",
  12529. + S_IRUGO,
  12530. + ag->debug.debugfs_dir,
  12531. + ag,
  12532. + &ag71xx_fops_napi_stats);
  12533. + if (!ag->debug.debugfs_napi_stats)
  12534. + goto err;
  12535. +
  12536. + return 0;
  12537. +
  12538. + err:
  12539. + ag71xx_debugfs_exit(ag);
  12540. + return -ENOMEM;
  12541. +}
  12542. +
  12543. +int ag71xx_debugfs_root_init(void)
  12544. +{
  12545. + if (ag71xx_debugfs_root)
  12546. + return -EBUSY;
  12547. +
  12548. + ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  12549. + if (!ag71xx_debugfs_root)
  12550. + return -ENOENT;
  12551. +
  12552. + return 0;
  12553. +}
  12554. +
  12555. +void ag71xx_debugfs_root_exit(void)
  12556. +{
  12557. + debugfs_remove(ag71xx_debugfs_root);
  12558. + ag71xx_debugfs_root = NULL;
  12559. +}
  12560. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_ethtool.c linux-2.6.34/drivers/net/ag71xx/ag71xx_ethtool.c
  12561. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_ethtool.c 1970-01-01 01:00:00.000000000 +0100
  12562. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_ethtool.c 2010-05-25 18:46:09.523473138 +0200
  12563. @@ -0,0 +1,71 @@
  12564. +/*
  12565. + * Atheros AR71xx built-in ethernet mac driver
  12566. + *
  12567. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12568. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12569. + *
  12570. + * Based on Atheros' AG7100 driver
  12571. + *
  12572. + * This program is free software; you can redistribute it and/or modify it
  12573. + * under the terms of the GNU General Public License version 2 as published
  12574. + * by the Free Software Foundation.
  12575. + */
  12576. +
  12577. +#include "ag71xx.h"
  12578. +
  12579. +static int ag71xx_ethtool_get_settings(struct net_device *dev,
  12580. + struct ethtool_cmd *cmd)
  12581. +{
  12582. + struct ag71xx *ag = netdev_priv(dev);
  12583. + struct phy_device *phydev = ag->phy_dev;
  12584. +
  12585. + if (!phydev)
  12586. + return -ENODEV;
  12587. +
  12588. + return phy_ethtool_gset(phydev, cmd);
  12589. +}
  12590. +
  12591. +static int ag71xx_ethtool_set_settings(struct net_device *dev,
  12592. + struct ethtool_cmd *cmd)
  12593. +{
  12594. + struct ag71xx *ag = netdev_priv(dev);
  12595. + struct phy_device *phydev = ag->phy_dev;
  12596. +
  12597. + if (!phydev)
  12598. + return -ENODEV;
  12599. +
  12600. + return phy_ethtool_sset(phydev, cmd);
  12601. +}
  12602. +
  12603. +static void ag71xx_ethtool_get_drvinfo(struct net_device *dev,
  12604. + struct ethtool_drvinfo *info)
  12605. +{
  12606. + struct ag71xx *ag = netdev_priv(dev);
  12607. +
  12608. + strcpy(info->driver, ag->pdev->dev.driver->name);
  12609. + strcpy(info->version, AG71XX_DRV_VERSION);
  12610. + strcpy(info->bus_info, dev_name(&ag->pdev->dev));
  12611. +}
  12612. +
  12613. +static u32 ag71xx_ethtool_get_msglevel(struct net_device *dev)
  12614. +{
  12615. + struct ag71xx *ag = netdev_priv(dev);
  12616. +
  12617. + return ag->msg_enable;
  12618. +}
  12619. +
  12620. +static void ag71xx_ethtool_set_msglevel(struct net_device *dev, u32 msg_level)
  12621. +{
  12622. + struct ag71xx *ag = netdev_priv(dev);
  12623. +
  12624. + ag->msg_enable = msg_level;
  12625. +}
  12626. +
  12627. +struct ethtool_ops ag71xx_ethtool_ops = {
  12628. + .set_settings = ag71xx_ethtool_set_settings,
  12629. + .get_settings = ag71xx_ethtool_get_settings,
  12630. + .get_drvinfo = ag71xx_ethtool_get_drvinfo,
  12631. + .get_msglevel = ag71xx_ethtool_get_msglevel,
  12632. + .set_msglevel = ag71xx_ethtool_set_msglevel,
  12633. + .get_link = ethtool_op_get_link,
  12634. +};
  12635. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx.h linux-2.6.34/drivers/net/ag71xx/ag71xx.h
  12636. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx.h 1970-01-01 01:00:00.000000000 +0100
  12637. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx.h 2010-05-25 18:46:09.553473141 +0200
  12638. @@ -0,0 +1,500 @@
  12639. +/*
  12640. + * Atheros AR71xx built-in ethernet mac driver
  12641. + *
  12642. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  12643. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  12644. + *
  12645. + * Based on Atheros' AG7100 driver
  12646. + *
  12647. + * This program is free software; you can redistribute it and/or modify it
  12648. + * under the terms of the GNU General Public License version 2 as published
  12649. + * by the Free Software Foundation.
  12650. + */
  12651. +
  12652. +#ifndef __AG71XX_H
  12653. +#define __AG71XX_H
  12654. +
  12655. +#include <linux/kernel.h>
  12656. +#include <linux/version.h>
  12657. +#include <linux/module.h>
  12658. +#include <linux/init.h>
  12659. +#include <linux/types.h>
  12660. +#include <linux/random.h>
  12661. +#include <linux/spinlock.h>
  12662. +#include <linux/interrupt.h>
  12663. +#include <linux/platform_device.h>
  12664. +#include <linux/ethtool.h>
  12665. +#include <linux/etherdevice.h>
  12666. +#include <linux/phy.h>
  12667. +#include <linux/skbuff.h>
  12668. +#include <linux/dma-mapping.h>
  12669. +#include <linux/workqueue.h>
  12670. +
  12671. +#include <linux/bitops.h>
  12672. +
  12673. +#include <asm/mach-ar71xx/ar71xx.h>
  12674. +#include <asm/mach-ar71xx/platform.h>
  12675. +
  12676. +#define ETH_FCS_LEN 4
  12677. +
  12678. +#define AG71XX_DRV_NAME "ag71xx"
  12679. +#define AG71XX_DRV_VERSION "0.5.35"
  12680. +
  12681. +#define AG71XX_NAPI_WEIGHT 64
  12682. +#define AG71XX_OOM_REFILL (1 + HZ/10)
  12683. +
  12684. +#define AG71XX_INT_ERR (AG71XX_INT_RX_BE | AG71XX_INT_TX_BE)
  12685. +#define AG71XX_INT_TX (AG71XX_INT_TX_PS)
  12686. +#define AG71XX_INT_RX (AG71XX_INT_RX_PR | AG71XX_INT_RX_OF)
  12687. +
  12688. +#define AG71XX_INT_POLL (AG71XX_INT_RX | AG71XX_INT_TX)
  12689. +#define AG71XX_INT_INIT (AG71XX_INT_ERR | AG71XX_INT_POLL)
  12690. +
  12691. +#define AG71XX_TX_FIFO_LEN 2048
  12692. +#define AG71XX_TX_MTU_LEN 1536
  12693. +#define AG71XX_RX_PKT_RESERVE 64
  12694. +#define AG71XX_RX_PKT_SIZE \
  12695. + (AG71XX_RX_PKT_RESERVE + ETH_HLEN + ETH_FRAME_LEN + ETH_FCS_LEN)
  12696. +
  12697. +#define AG71XX_TX_RING_SIZE 64
  12698. +#define AG71XX_TX_THRES_STOP (AG71XX_TX_RING_SIZE - 4)
  12699. +#define AG71XX_TX_THRES_WAKEUP \
  12700. + (AG71XX_TX_RING_SIZE - (AG71XX_TX_RING_SIZE / 4))
  12701. +
  12702. +#define AG71XX_RX_RING_SIZE 128
  12703. +
  12704. +#ifdef CONFIG_AG71XX_DEBUG
  12705. +#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
  12706. +#else
  12707. +#define DBG(fmt, args...) do {} while (0)
  12708. +#endif
  12709. +
  12710. +#define ag71xx_assert(_cond) \
  12711. +do { \
  12712. + if (_cond) \
  12713. + break; \
  12714. + printk("%s,%d: assertion failed\n", __FILE__, __LINE__); \
  12715. + BUG(); \
  12716. +} while (0)
  12717. +
  12718. +struct ag71xx_desc {
  12719. + u32 data;
  12720. + u32 ctrl;
  12721. +#define DESC_EMPTY BIT(31)
  12722. +#define DESC_MORE BIT(24)
  12723. +#define DESC_PKTLEN_M 0xfff
  12724. + u32 next;
  12725. + u32 pad;
  12726. +} __attribute__((aligned(4)));
  12727. +
  12728. +struct ag71xx_buf {
  12729. + struct sk_buff *skb;
  12730. + struct ag71xx_desc *desc;
  12731. + dma_addr_t dma_addr;
  12732. + u32 pad;
  12733. +};
  12734. +
  12735. +struct ag71xx_ring {
  12736. + struct ag71xx_buf *buf;
  12737. + u8 *descs_cpu;
  12738. + dma_addr_t descs_dma;
  12739. + unsigned int desc_size;
  12740. + unsigned int curr;
  12741. + unsigned int dirty;
  12742. + unsigned int size;
  12743. +};
  12744. +
  12745. +struct ag71xx_mdio {
  12746. + struct mii_bus *mii_bus;
  12747. + int mii_irq[PHY_MAX_ADDR];
  12748. + void __iomem *mdio_base;
  12749. + struct ag71xx_mdio_platform_data *pdata;
  12750. +};
  12751. +
  12752. +struct ag71xx_int_stats {
  12753. + unsigned long rx_pr;
  12754. + unsigned long rx_be;
  12755. + unsigned long rx_of;
  12756. + unsigned long tx_ps;
  12757. + unsigned long tx_be;
  12758. + unsigned long tx_ur;
  12759. + unsigned long total;
  12760. +};
  12761. +
  12762. +struct ag71xx_napi_stats {
  12763. + unsigned long napi_calls;
  12764. + unsigned long rx_count;
  12765. + unsigned long rx_packets;
  12766. + unsigned long rx_packets_max;
  12767. + unsigned long tx_count;
  12768. + unsigned long tx_packets;
  12769. + unsigned long tx_packets_max;
  12770. +
  12771. + unsigned long rx[AG71XX_NAPI_WEIGHT + 1];
  12772. + unsigned long tx[AG71XX_NAPI_WEIGHT + 1];
  12773. +};
  12774. +
  12775. +struct ag71xx_debug {
  12776. + struct dentry *debugfs_dir;
  12777. + struct dentry *debugfs_int_stats;
  12778. + struct dentry *debugfs_napi_stats;
  12779. +
  12780. + struct ag71xx_int_stats int_stats;
  12781. + struct ag71xx_napi_stats napi_stats;
  12782. +};
  12783. +
  12784. +struct ag71xx {
  12785. + void __iomem *mac_base;
  12786. + void __iomem *mii_ctrl;
  12787. +
  12788. + spinlock_t lock;
  12789. + struct platform_device *pdev;
  12790. + struct net_device *dev;
  12791. + struct napi_struct napi;
  12792. + u32 msg_enable;
  12793. +
  12794. + struct ag71xx_ring rx_ring;
  12795. + struct ag71xx_ring tx_ring;
  12796. +
  12797. + struct mii_bus *mii_bus;
  12798. + struct phy_device *phy_dev;
  12799. +
  12800. + unsigned int link;
  12801. + unsigned int speed;
  12802. + int duplex;
  12803. +
  12804. + struct work_struct restart_work;
  12805. + struct timer_list oom_timer;
  12806. +
  12807. +#ifdef CONFIG_AG71XX_DEBUG_FS
  12808. + struct ag71xx_debug debug;
  12809. +#endif
  12810. +};
  12811. +
  12812. +extern struct ethtool_ops ag71xx_ethtool_ops;
  12813. +void ag71xx_link_adjust(struct ag71xx *ag);
  12814. +
  12815. +int ag71xx_mdio_driver_init(void) __init;
  12816. +void ag71xx_mdio_driver_exit(void);
  12817. +
  12818. +int ag71xx_phy_connect(struct ag71xx *ag);
  12819. +void ag71xx_phy_disconnect(struct ag71xx *ag);
  12820. +void ag71xx_phy_start(struct ag71xx *ag);
  12821. +void ag71xx_phy_stop(struct ag71xx *ag);
  12822. +
  12823. +static inline struct ag71xx_platform_data *ag71xx_get_pdata(struct ag71xx *ag)
  12824. +{
  12825. + return ag->pdev->dev.platform_data;
  12826. +}
  12827. +
  12828. +static inline int ag71xx_desc_empty(struct ag71xx_desc *desc)
  12829. +{
  12830. + return ((desc->ctrl & DESC_EMPTY) != 0);
  12831. +}
  12832. +
  12833. +static inline int ag71xx_desc_pktlen(struct ag71xx_desc *desc)
  12834. +{
  12835. + return (desc->ctrl & DESC_PKTLEN_M);
  12836. +}
  12837. +
  12838. +/* Register offsets */
  12839. +#define AG71XX_REG_MAC_CFG1 0x0000
  12840. +#define AG71XX_REG_MAC_CFG2 0x0004
  12841. +#define AG71XX_REG_MAC_IPG 0x0008
  12842. +#define AG71XX_REG_MAC_HDX 0x000c
  12843. +#define AG71XX_REG_MAC_MFL 0x0010
  12844. +#define AG71XX_REG_MII_CFG 0x0020
  12845. +#define AG71XX_REG_MII_CMD 0x0024
  12846. +#define AG71XX_REG_MII_ADDR 0x0028
  12847. +#define AG71XX_REG_MII_CTRL 0x002c
  12848. +#define AG71XX_REG_MII_STATUS 0x0030
  12849. +#define AG71XX_REG_MII_IND 0x0034
  12850. +#define AG71XX_REG_MAC_IFCTL 0x0038
  12851. +#define AG71XX_REG_MAC_ADDR1 0x0040
  12852. +#define AG71XX_REG_MAC_ADDR2 0x0044
  12853. +#define AG71XX_REG_FIFO_CFG0 0x0048
  12854. +#define AG71XX_REG_FIFO_CFG1 0x004c
  12855. +#define AG71XX_REG_FIFO_CFG2 0x0050
  12856. +#define AG71XX_REG_FIFO_CFG3 0x0054
  12857. +#define AG71XX_REG_FIFO_CFG4 0x0058
  12858. +#define AG71XX_REG_FIFO_CFG5 0x005c
  12859. +#define AG71XX_REG_FIFO_RAM0 0x0060
  12860. +#define AG71XX_REG_FIFO_RAM1 0x0064
  12861. +#define AG71XX_REG_FIFO_RAM2 0x0068
  12862. +#define AG71XX_REG_FIFO_RAM3 0x006c
  12863. +#define AG71XX_REG_FIFO_RAM4 0x0070
  12864. +#define AG71XX_REG_FIFO_RAM5 0x0074
  12865. +#define AG71XX_REG_FIFO_RAM6 0x0078
  12866. +#define AG71XX_REG_FIFO_RAM7 0x007c
  12867. +
  12868. +#define AG71XX_REG_TX_CTRL 0x0180
  12869. +#define AG71XX_REG_TX_DESC 0x0184
  12870. +#define AG71XX_REG_TX_STATUS 0x0188
  12871. +#define AG71XX_REG_RX_CTRL 0x018c
  12872. +#define AG71XX_REG_RX_DESC 0x0190
  12873. +#define AG71XX_REG_RX_STATUS 0x0194
  12874. +#define AG71XX_REG_INT_ENABLE 0x0198
  12875. +#define AG71XX_REG_INT_STATUS 0x019c
  12876. +
  12877. +#define MAC_CFG1_TXE BIT(0) /* Tx Enable */
  12878. +#define MAC_CFG1_STX BIT(1) /* Synchronize Tx Enable */
  12879. +#define MAC_CFG1_RXE BIT(2) /* Rx Enable */
  12880. +#define MAC_CFG1_SRX BIT(3) /* Synchronize Rx Enable */
  12881. +#define MAC_CFG1_TFC BIT(4) /* Tx Flow Control Enable */
  12882. +#define MAC_CFG1_RFC BIT(5) /* Rx Flow Control Enable */
  12883. +#define MAC_CFG1_LB BIT(8) /* Loopback mode */
  12884. +#define MAC_CFG1_SR BIT(31) /* Soft Reset */
  12885. +
  12886. +#define MAC_CFG2_FDX BIT(0)
  12887. +#define MAC_CFG2_CRC_EN BIT(1)
  12888. +#define MAC_CFG2_PAD_CRC_EN BIT(2)
  12889. +#define MAC_CFG2_LEN_CHECK BIT(4)
  12890. +#define MAC_CFG2_HUGE_FRAME_EN BIT(5)
  12891. +#define MAC_CFG2_IF_1000 BIT(9)
  12892. +#define MAC_CFG2_IF_10_100 BIT(8)
  12893. +
  12894. +#define FIFO_CFG0_WTM BIT(0) /* Watermark Module */
  12895. +#define FIFO_CFG0_RXS BIT(1) /* Rx System Module */
  12896. +#define FIFO_CFG0_RXF BIT(2) /* Rx Fabric Module */
  12897. +#define FIFO_CFG0_TXS BIT(3) /* Tx System Module */
  12898. +#define FIFO_CFG0_TXF BIT(4) /* Tx Fabric Module */
  12899. +#define FIFO_CFG0_ALL (FIFO_CFG0_WTM | FIFO_CFG0_RXS | FIFO_CFG0_RXF \
  12900. + | FIFO_CFG0_TXS | FIFO_CFG0_TXF)
  12901. +
  12902. +#define FIFO_CFG0_ENABLE_SHIFT 8
  12903. +
  12904. +#define FIFO_CFG4_DE BIT(0) /* Drop Event */
  12905. +#define FIFO_CFG4_DV BIT(1) /* RX_DV Event */
  12906. +#define FIFO_CFG4_FC BIT(2) /* False Carrier */
  12907. +#define FIFO_CFG4_CE BIT(3) /* Code Error */
  12908. +#define FIFO_CFG4_CR BIT(4) /* CRC error */
  12909. +#define FIFO_CFG4_LM BIT(5) /* Length Mismatch */
  12910. +#define FIFO_CFG4_LO BIT(6) /* Length out of range */
  12911. +#define FIFO_CFG4_OK BIT(7) /* Packet is OK */
  12912. +#define FIFO_CFG4_MC BIT(8) /* Multicast Packet */
  12913. +#define FIFO_CFG4_BC BIT(9) /* Broadcast Packet */
  12914. +#define FIFO_CFG4_DR BIT(10) /* Dribble */
  12915. +#define FIFO_CFG4_LE BIT(11) /* Long Event */
  12916. +#define FIFO_CFG4_CF BIT(12) /* Control Frame */
  12917. +#define FIFO_CFG4_PF BIT(13) /* Pause Frame */
  12918. +#define FIFO_CFG4_UO BIT(14) /* Unsupported Opcode */
  12919. +#define FIFO_CFG4_VT BIT(15) /* VLAN tag detected */
  12920. +#define FIFO_CFG4_FT BIT(16) /* Frame Truncated */
  12921. +#define FIFO_CFG4_UC BIT(17) /* Unicast Packet */
  12922. +
  12923. +#define FIFO_CFG5_DE BIT(0) /* Drop Event */
  12924. +#define FIFO_CFG5_DV BIT(1) /* RX_DV Event */
  12925. +#define FIFO_CFG5_FC BIT(2) /* False Carrier */
  12926. +#define FIFO_CFG5_CE BIT(3) /* Code Error */
  12927. +#define FIFO_CFG5_LM BIT(4) /* Length Mismatch */
  12928. +#define FIFO_CFG5_LO BIT(5) /* Length Out of Range */
  12929. +#define FIFO_CFG5_OK BIT(6) /* Packet is OK */
  12930. +#define FIFO_CFG5_MC BIT(7) /* Multicast Packet */
  12931. +#define FIFO_CFG5_BC BIT(8) /* Broadcast Packet */
  12932. +#define FIFO_CFG5_DR BIT(9) /* Dribble */
  12933. +#define FIFO_CFG5_CF BIT(10) /* Control Frame */
  12934. +#define FIFO_CFG5_PF BIT(11) /* Pause Frame */
  12935. +#define FIFO_CFG5_UO BIT(12) /* Unsupported Opcode */
  12936. +#define FIFO_CFG5_VT BIT(13) /* VLAN tag detected */
  12937. +#define FIFO_CFG5_LE BIT(14) /* Long Event */
  12938. +#define FIFO_CFG5_FT BIT(15) /* Frame Truncated */
  12939. +#define FIFO_CFG5_16 BIT(16) /* unknown */
  12940. +#define FIFO_CFG5_17 BIT(17) /* unknown */
  12941. +#define FIFO_CFG5_SF BIT(18) /* Short Frame */
  12942. +#define FIFO_CFG5_BM BIT(19) /* Byte Mode */
  12943. +
  12944. +#define AG71XX_INT_TX_PS BIT(0)
  12945. +#define AG71XX_INT_TX_UR BIT(1)
  12946. +#define AG71XX_INT_TX_BE BIT(3)
  12947. +#define AG71XX_INT_RX_PR BIT(4)
  12948. +#define AG71XX_INT_RX_OF BIT(6)
  12949. +#define AG71XX_INT_RX_BE BIT(7)
  12950. +
  12951. +#define MAC_IFCTL_SPEED BIT(16)
  12952. +
  12953. +#define MII_CFG_CLK_DIV_4 0
  12954. +#define MII_CFG_CLK_DIV_6 2
  12955. +#define MII_CFG_CLK_DIV_8 3
  12956. +#define MII_CFG_CLK_DIV_10 4
  12957. +#define MII_CFG_CLK_DIV_14 5
  12958. +#define MII_CFG_CLK_DIV_20 6
  12959. +#define MII_CFG_CLK_DIV_28 7
  12960. +#define MII_CFG_RESET BIT(31)
  12961. +
  12962. +#define MII_CMD_WRITE 0x0
  12963. +#define MII_CMD_READ 0x1
  12964. +#define MII_ADDR_SHIFT 8
  12965. +#define MII_IND_BUSY BIT(0)
  12966. +#define MII_IND_INVALID BIT(2)
  12967. +
  12968. +#define TX_CTRL_TXE BIT(0) /* Tx Enable */
  12969. +
  12970. +#define TX_STATUS_PS BIT(0) /* Packet Sent */
  12971. +#define TX_STATUS_UR BIT(1) /* Tx Underrun */
  12972. +#define TX_STATUS_BE BIT(3) /* Bus Error */
  12973. +
  12974. +#define RX_CTRL_RXE BIT(0) /* Rx Enable */
  12975. +
  12976. +#define RX_STATUS_PR BIT(0) /* Packet Received */
  12977. +#define RX_STATUS_OF BIT(2) /* Rx Overflow */
  12978. +#define RX_STATUS_BE BIT(3) /* Bus Error */
  12979. +
  12980. +#define MII_CTRL_IF_MASK 3
  12981. +#define MII_CTRL_SPEED_SHIFT 4
  12982. +#define MII_CTRL_SPEED_MASK 3
  12983. +#define MII_CTRL_SPEED_10 0
  12984. +#define MII_CTRL_SPEED_100 1
  12985. +#define MII_CTRL_SPEED_1000 2
  12986. +
  12987. +static inline void ag71xx_check_reg_offset(struct ag71xx *ag, unsigned reg)
  12988. +{
  12989. + switch (reg) {
  12990. + case AG71XX_REG_MAC_CFG1 ... AG71XX_REG_MAC_MFL:
  12991. + case AG71XX_REG_MAC_IFCTL ... AG71XX_REG_INT_STATUS:
  12992. + break;
  12993. +
  12994. + default:
  12995. + BUG();
  12996. + }
  12997. +}
  12998. +
  12999. +static inline void ag71xx_wr(struct ag71xx *ag, unsigned reg, u32 value)
  13000. +{
  13001. + ag71xx_check_reg_offset(ag, reg);
  13002. +
  13003. + __raw_writel(value, ag->mac_base + reg);
  13004. + /* flush write */
  13005. + (void) __raw_readl(ag->mac_base + reg);
  13006. +}
  13007. +
  13008. +static inline u32 ag71xx_rr(struct ag71xx *ag, unsigned reg)
  13009. +{
  13010. + ag71xx_check_reg_offset(ag, reg);
  13011. +
  13012. + return __raw_readl(ag->mac_base + reg);
  13013. +}
  13014. +
  13015. +static inline void ag71xx_sb(struct ag71xx *ag, unsigned reg, u32 mask)
  13016. +{
  13017. + void __iomem *r;
  13018. +
  13019. + ag71xx_check_reg_offset(ag, reg);
  13020. +
  13021. + r = ag->mac_base + reg;
  13022. + __raw_writel(__raw_readl(r) | mask, r);
  13023. + /* flush write */
  13024. + (void)__raw_readl(r);
  13025. +}
  13026. +
  13027. +static inline void ag71xx_cb(struct ag71xx *ag, unsigned reg, u32 mask)
  13028. +{
  13029. + void __iomem *r;
  13030. +
  13031. + ag71xx_check_reg_offset(ag, reg);
  13032. +
  13033. + r = ag->mac_base + reg;
  13034. + __raw_writel(__raw_readl(r) & ~mask, r);
  13035. + /* flush write */
  13036. + (void) __raw_readl(r);
  13037. +}
  13038. +
  13039. +static inline void ag71xx_int_enable(struct ag71xx *ag, u32 ints)
  13040. +{
  13041. + ag71xx_sb(ag, AG71XX_REG_INT_ENABLE, ints);
  13042. +}
  13043. +
  13044. +static inline void ag71xx_int_disable(struct ag71xx *ag, u32 ints)
  13045. +{
  13046. + ag71xx_cb(ag, AG71XX_REG_INT_ENABLE, ints);
  13047. +}
  13048. +
  13049. +static inline void ag71xx_mii_ctrl_wr(struct ag71xx *ag, u32 value)
  13050. +{
  13051. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13052. +
  13053. + if (pdata->is_ar724x)
  13054. + return;
  13055. +
  13056. + __raw_writel(value, ag->mii_ctrl);
  13057. +
  13058. + /* flush write */
  13059. + __raw_readl(ag->mii_ctrl);
  13060. +}
  13061. +
  13062. +static inline u32 ag71xx_mii_ctrl_rr(struct ag71xx *ag)
  13063. +{
  13064. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13065. +
  13066. + if (pdata->is_ar724x)
  13067. + return 0xffffffff;
  13068. +
  13069. + return __raw_readl(ag->mii_ctrl);
  13070. +}
  13071. +
  13072. +static void inline ag71xx_mii_ctrl_set_if(struct ag71xx *ag,
  13073. + unsigned int mii_if)
  13074. +{
  13075. + u32 t;
  13076. +
  13077. + t = ag71xx_mii_ctrl_rr(ag);
  13078. + t &= ~(MII_CTRL_IF_MASK);
  13079. + t |= (mii_if & MII_CTRL_IF_MASK);
  13080. + ag71xx_mii_ctrl_wr(ag, t);
  13081. +}
  13082. +
  13083. +static void inline ag71xx_mii_ctrl_set_speed(struct ag71xx *ag,
  13084. + unsigned int speed)
  13085. +{
  13086. + u32 t;
  13087. +
  13088. + t = ag71xx_mii_ctrl_rr(ag);
  13089. + t &= ~(MII_CTRL_SPEED_MASK << MII_CTRL_SPEED_SHIFT);
  13090. + t |= (speed & MII_CTRL_SPEED_MASK) << MII_CTRL_SPEED_SHIFT;
  13091. + ag71xx_mii_ctrl_wr(ag, t);
  13092. +}
  13093. +
  13094. +#ifdef CONFIG_AG71XX_AR8216_SUPPORT
  13095. +void ag71xx_add_ar8216_header(struct ag71xx *ag, struct sk_buff *skb);
  13096. +int ag71xx_remove_ar8216_header(struct ag71xx *ag, struct sk_buff *skb,
  13097. + int pktlen);
  13098. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  13099. +{
  13100. + return ag71xx_get_pdata(ag)->has_ar8216;
  13101. +}
  13102. +#else
  13103. +static inline void ag71xx_add_ar8216_header(struct ag71xx *ag,
  13104. + struct sk_buff *skb)
  13105. +{
  13106. +}
  13107. +
  13108. +static inline int ag71xx_remove_ar8216_header(struct ag71xx *ag,
  13109. + struct sk_buff *skb,
  13110. + int pktlen)
  13111. +{
  13112. + return 0;
  13113. +}
  13114. +static inline int ag71xx_has_ar8216(struct ag71xx *ag)
  13115. +{
  13116. + return 0;
  13117. +}
  13118. +#endif
  13119. +
  13120. +#ifdef CONFIG_AG71XX_DEBUG_FS
  13121. +int ag71xx_debugfs_root_init(void);
  13122. +void ag71xx_debugfs_root_exit(void);
  13123. +int ag71xx_debugfs_init(struct ag71xx *ag);
  13124. +void ag71xx_debugfs_exit(struct ag71xx *ag);
  13125. +void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status);
  13126. +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx);
  13127. +#else
  13128. +static inline int ag71xx_debugfs_root_init(void) { return 0; }
  13129. +static inline void ag71xx_debugfs_root_exit(void) {}
  13130. +static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; }
  13131. +static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {}
  13132. +static inline void ag71xx_debugfs_update_int_stats(struct ag71xx *ag,
  13133. + u32 status) {}
  13134. +static inline void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag,
  13135. + int rx, int tx) {}
  13136. +#endif /* CONFIG_AG71XX_DEBUG_FS */
  13137. +
  13138. +#endif /* _AG71XX_H */
  13139. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_main.c linux-2.6.34/drivers/net/ag71xx/ag71xx_main.c
  13140. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_main.c 1970-01-01 01:00:00.000000000 +0100
  13141. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_main.c 2010-05-25 18:46:09.593464126 +0200
  13142. @@ -0,0 +1,1184 @@
  13143. +/*
  13144. + * Atheros AR71xx built-in ethernet mac driver
  13145. + *
  13146. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  13147. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  13148. + *
  13149. + * Based on Atheros' AG7100 driver
  13150. + *
  13151. + * This program is free software; you can redistribute it and/or modify it
  13152. + * under the terms of the GNU General Public License version 2 as published
  13153. + * by the Free Software Foundation.
  13154. + */
  13155. +
  13156. +#include "ag71xx.h"
  13157. +
  13158. +#define AG71XX_DEFAULT_MSG_ENABLE \
  13159. + ( NETIF_MSG_DRV \
  13160. + | NETIF_MSG_PROBE \
  13161. + | NETIF_MSG_LINK \
  13162. + | NETIF_MSG_TIMER \
  13163. + | NETIF_MSG_IFDOWN \
  13164. + | NETIF_MSG_IFUP \
  13165. + | NETIF_MSG_RX_ERR \
  13166. + | NETIF_MSG_TX_ERR )
  13167. +
  13168. +static int ag71xx_msg_level = -1;
  13169. +
  13170. +module_param_named(msg_level, ag71xx_msg_level, int, 0);
  13171. +MODULE_PARM_DESC(msg_level, "Message level (-1=defaults,0=none,...,16=all)");
  13172. +
  13173. +static void ag71xx_dump_dma_regs(struct ag71xx *ag)
  13174. +{
  13175. + DBG("%s: dma_tx_ctrl=%08x, dma_tx_desc=%08x, dma_tx_status=%08x\n",
  13176. + ag->dev->name,
  13177. + ag71xx_rr(ag, AG71XX_REG_TX_CTRL),
  13178. + ag71xx_rr(ag, AG71XX_REG_TX_DESC),
  13179. + ag71xx_rr(ag, AG71XX_REG_TX_STATUS));
  13180. +
  13181. + DBG("%s: dma_rx_ctrl=%08x, dma_rx_desc=%08x, dma_rx_status=%08x\n",
  13182. + ag->dev->name,
  13183. + ag71xx_rr(ag, AG71XX_REG_RX_CTRL),
  13184. + ag71xx_rr(ag, AG71XX_REG_RX_DESC),
  13185. + ag71xx_rr(ag, AG71XX_REG_RX_STATUS));
  13186. +}
  13187. +
  13188. +static void ag71xx_dump_regs(struct ag71xx *ag)
  13189. +{
  13190. + DBG("%s: mac_cfg1=%08x, mac_cfg2=%08x, ipg=%08x, hdx=%08x, mfl=%08x\n",
  13191. + ag->dev->name,
  13192. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG1),
  13193. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  13194. + ag71xx_rr(ag, AG71XX_REG_MAC_IPG),
  13195. + ag71xx_rr(ag, AG71XX_REG_MAC_HDX),
  13196. + ag71xx_rr(ag, AG71XX_REG_MAC_MFL));
  13197. + DBG("%s: mac_ifctl=%08x, mac_addr1=%08x, mac_addr2=%08x\n",
  13198. + ag->dev->name,
  13199. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  13200. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR1),
  13201. + ag71xx_rr(ag, AG71XX_REG_MAC_ADDR2));
  13202. + DBG("%s: fifo_cfg0=%08x, fifo_cfg1=%08x, fifo_cfg2=%08x\n",
  13203. + ag->dev->name,
  13204. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  13205. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  13206. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  13207. + DBG("%s: fifo_cfg3=%08x, fifo_cfg4=%08x, fifo_cfg5=%08x\n",
  13208. + ag->dev->name,
  13209. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  13210. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  13211. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  13212. +}
  13213. +
  13214. +static inline void ag71xx_dump_intr(struct ag71xx *ag, char *label, u32 intr)
  13215. +{
  13216. + DBG("%s: %s intr=%08x %s%s%s%s%s%s\n",
  13217. + ag->dev->name, label, intr,
  13218. + (intr & AG71XX_INT_TX_PS) ? "TXPS " : "",
  13219. + (intr & AG71XX_INT_TX_UR) ? "TXUR " : "",
  13220. + (intr & AG71XX_INT_TX_BE) ? "TXBE " : "",
  13221. + (intr & AG71XX_INT_RX_PR) ? "RXPR " : "",
  13222. + (intr & AG71XX_INT_RX_OF) ? "RXOF " : "",
  13223. + (intr & AG71XX_INT_RX_BE) ? "RXBE " : "");
  13224. +}
  13225. +
  13226. +static void ag71xx_ring_free(struct ag71xx_ring *ring)
  13227. +{
  13228. + kfree(ring->buf);
  13229. +
  13230. + if (ring->descs_cpu)
  13231. + dma_free_coherent(NULL, ring->size * ring->desc_size,
  13232. + ring->descs_cpu, ring->descs_dma);
  13233. +}
  13234. +
  13235. +static int ag71xx_ring_alloc(struct ag71xx_ring *ring, unsigned int size)
  13236. +{
  13237. + int err;
  13238. + int i;
  13239. +
  13240. + ring->desc_size = sizeof(struct ag71xx_desc);
  13241. + if (ring->desc_size % cache_line_size()) {
  13242. + DBG("ag71xx: ring %p, desc size %u rounded to %u\n",
  13243. + ring, ring->desc_size,
  13244. + roundup(ring->desc_size, cache_line_size()));
  13245. + ring->desc_size = roundup(ring->desc_size, cache_line_size());
  13246. + }
  13247. +
  13248. + ring->descs_cpu = dma_alloc_coherent(NULL, size * ring->desc_size,
  13249. + &ring->descs_dma, GFP_ATOMIC);
  13250. + if (!ring->descs_cpu) {
  13251. + err = -ENOMEM;
  13252. + goto err;
  13253. + }
  13254. +
  13255. + ring->size = size;
  13256. +
  13257. + ring->buf = kzalloc(size * sizeof(*ring->buf), GFP_KERNEL);
  13258. + if (!ring->buf) {
  13259. + err = -ENOMEM;
  13260. + goto err;
  13261. + }
  13262. +
  13263. + for (i = 0; i < size; i++) {
  13264. + ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[i * ring->desc_size];
  13265. + DBG("ag71xx: ring %p, desc %d at %p\n",
  13266. + ring, i, ring->buf[i].desc);
  13267. + }
  13268. +
  13269. + return 0;
  13270. +
  13271. + err:
  13272. + return err;
  13273. +}
  13274. +
  13275. +static void ag71xx_ring_tx_clean(struct ag71xx *ag)
  13276. +{
  13277. + struct ag71xx_ring *ring = &ag->tx_ring;
  13278. + struct net_device *dev = ag->dev;
  13279. +
  13280. + while (ring->curr != ring->dirty) {
  13281. + u32 i = ring->dirty % AG71XX_TX_RING_SIZE;
  13282. +
  13283. + if (!ag71xx_desc_empty(ring->buf[i].desc)) {
  13284. + ring->buf[i].desc->ctrl = 0;
  13285. + dev->stats.tx_errors++;
  13286. + }
  13287. +
  13288. + if (ring->buf[i].skb)
  13289. + dev_kfree_skb_any(ring->buf[i].skb);
  13290. +
  13291. + ring->buf[i].skb = NULL;
  13292. +
  13293. + ring->dirty++;
  13294. + }
  13295. +
  13296. + /* flush descriptors */
  13297. + wmb();
  13298. +
  13299. +}
  13300. +
  13301. +static void ag71xx_ring_tx_init(struct ag71xx *ag)
  13302. +{
  13303. + struct ag71xx_ring *ring = &ag->tx_ring;
  13304. + int i;
  13305. +
  13306. + for (i = 0; i < AG71XX_TX_RING_SIZE; i++) {
  13307. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  13308. + ring->desc_size * ((i + 1) % AG71XX_TX_RING_SIZE));
  13309. +
  13310. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13311. + ring->buf[i].skb = NULL;
  13312. + }
  13313. +
  13314. + /* flush descriptors */
  13315. + wmb();
  13316. +
  13317. + ring->curr = 0;
  13318. + ring->dirty = 0;
  13319. +}
  13320. +
  13321. +static void ag71xx_ring_rx_clean(struct ag71xx *ag)
  13322. +{
  13323. + struct ag71xx_ring *ring = &ag->rx_ring;
  13324. + int i;
  13325. +
  13326. + if (!ring->buf)
  13327. + return;
  13328. +
  13329. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++)
  13330. + if (ring->buf[i].skb) {
  13331. + dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
  13332. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  13333. + kfree_skb(ring->buf[i].skb);
  13334. + }
  13335. +}
  13336. +
  13337. +static int ag71xx_rx_reserve(struct ag71xx *ag)
  13338. +{
  13339. + int reserve = 0;
  13340. +
  13341. + if (ag71xx_get_pdata(ag)->is_ar724x) {
  13342. + if (!ag71xx_has_ar8216(ag))
  13343. + reserve = 2;
  13344. +
  13345. + if (ag->phy_dev)
  13346. + reserve += 4 - (ag->phy_dev->pkt_align % 4);
  13347. +
  13348. + reserve %= 4;
  13349. + }
  13350. +
  13351. + return reserve + AG71XX_RX_PKT_RESERVE;
  13352. +}
  13353. +
  13354. +
  13355. +static int ag71xx_ring_rx_init(struct ag71xx *ag)
  13356. +{
  13357. + struct ag71xx_ring *ring = &ag->rx_ring;
  13358. + unsigned int reserve = ag71xx_rx_reserve(ag);
  13359. + unsigned int i;
  13360. + int ret;
  13361. +
  13362. + ret = 0;
  13363. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++) {
  13364. + ring->buf[i].desc->next = (u32) (ring->descs_dma +
  13365. + ring->desc_size * ((i + 1) % AG71XX_RX_RING_SIZE));
  13366. +
  13367. + DBG("ag71xx: RX desc at %p, next is %08x\n",
  13368. + ring->buf[i].desc,
  13369. + ring->buf[i].desc->next);
  13370. + }
  13371. +
  13372. + for (i = 0; i < AG71XX_RX_RING_SIZE; i++) {
  13373. + struct sk_buff *skb;
  13374. + dma_addr_t dma_addr;
  13375. +
  13376. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  13377. + if (!skb) {
  13378. + ret = -ENOMEM;
  13379. + break;
  13380. + }
  13381. +
  13382. + skb->dev = ag->dev;
  13383. + skb_reserve(skb, reserve);
  13384. +
  13385. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  13386. + AG71XX_RX_PKT_SIZE,
  13387. + DMA_FROM_DEVICE);
  13388. + ring->buf[i].skb = skb;
  13389. + ring->buf[i].dma_addr = dma_addr;
  13390. + ring->buf[i].desc->data = (u32) dma_addr;
  13391. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13392. + }
  13393. +
  13394. + /* flush descriptors */
  13395. + wmb();
  13396. +
  13397. + ring->curr = 0;
  13398. + ring->dirty = 0;
  13399. +
  13400. + return ret;
  13401. +}
  13402. +
  13403. +static int ag71xx_ring_rx_refill(struct ag71xx *ag)
  13404. +{
  13405. + struct ag71xx_ring *ring = &ag->rx_ring;
  13406. + unsigned int reserve = ag71xx_rx_reserve(ag);
  13407. + unsigned int count;
  13408. +
  13409. + count = 0;
  13410. + for (; ring->curr - ring->dirty > 0; ring->dirty++) {
  13411. + unsigned int i;
  13412. +
  13413. + i = ring->dirty % AG71XX_RX_RING_SIZE;
  13414. +
  13415. + if (ring->buf[i].skb == NULL) {
  13416. + dma_addr_t dma_addr;
  13417. + struct sk_buff *skb;
  13418. +
  13419. + skb = dev_alloc_skb(AG71XX_RX_PKT_SIZE + reserve);
  13420. + if (skb == NULL)
  13421. + break;
  13422. +
  13423. + skb_reserve(skb, reserve);
  13424. + skb->dev = ag->dev;
  13425. +
  13426. + dma_addr = dma_map_single(&ag->dev->dev, skb->data,
  13427. + AG71XX_RX_PKT_SIZE,
  13428. + DMA_FROM_DEVICE);
  13429. +
  13430. + ring->buf[i].skb = skb;
  13431. + ring->buf[i].dma_addr = dma_addr;
  13432. + ring->buf[i].desc->data = (u32) dma_addr;
  13433. + }
  13434. +
  13435. + ring->buf[i].desc->ctrl = DESC_EMPTY;
  13436. + count++;
  13437. + }
  13438. +
  13439. + /* flush descriptors */
  13440. + wmb();
  13441. +
  13442. + DBG("%s: %u rx descriptors refilled\n", ag->dev->name, count);
  13443. +
  13444. + return count;
  13445. +}
  13446. +
  13447. +static int ag71xx_rings_init(struct ag71xx *ag)
  13448. +{
  13449. + int ret;
  13450. +
  13451. + ret = ag71xx_ring_alloc(&ag->tx_ring, AG71XX_TX_RING_SIZE);
  13452. + if (ret)
  13453. + return ret;
  13454. +
  13455. + ag71xx_ring_tx_init(ag);
  13456. +
  13457. + ret = ag71xx_ring_alloc(&ag->rx_ring, AG71XX_RX_RING_SIZE);
  13458. + if (ret)
  13459. + return ret;
  13460. +
  13461. + ret = ag71xx_ring_rx_init(ag);
  13462. + return ret;
  13463. +}
  13464. +
  13465. +static void ag71xx_rings_cleanup(struct ag71xx *ag)
  13466. +{
  13467. + ag71xx_ring_rx_clean(ag);
  13468. + ag71xx_ring_free(&ag->rx_ring);
  13469. +
  13470. + ag71xx_ring_tx_clean(ag);
  13471. + ag71xx_ring_free(&ag->tx_ring);
  13472. +}
  13473. +
  13474. +static unsigned char *ag71xx_speed_str(struct ag71xx *ag)
  13475. +{
  13476. + switch (ag->speed) {
  13477. + case SPEED_1000:
  13478. + return "1000";
  13479. + case SPEED_100:
  13480. + return "100";
  13481. + case SPEED_10:
  13482. + return "10";
  13483. + }
  13484. +
  13485. + return "?";
  13486. +}
  13487. +
  13488. +void ag71xx_link_adjust(struct ag71xx *ag)
  13489. +{
  13490. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13491. + u32 cfg2;
  13492. + u32 ifctl;
  13493. + u32 fifo5;
  13494. + u32 mii_speed;
  13495. +
  13496. + if (!ag->link) {
  13497. + netif_carrier_off(ag->dev);
  13498. + if (netif_msg_link(ag))
  13499. + printk(KERN_INFO "%s: link down\n", ag->dev->name);
  13500. + return;
  13501. + }
  13502. +
  13503. + cfg2 = ag71xx_rr(ag, AG71XX_REG_MAC_CFG2);
  13504. + cfg2 &= ~(MAC_CFG2_IF_1000 | MAC_CFG2_IF_10_100 | MAC_CFG2_FDX);
  13505. + cfg2 |= (ag->duplex) ? MAC_CFG2_FDX : 0;
  13506. +
  13507. + ifctl = ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL);
  13508. + ifctl &= ~(MAC_IFCTL_SPEED);
  13509. +
  13510. + fifo5 = ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5);
  13511. + fifo5 &= ~FIFO_CFG5_BM;
  13512. +
  13513. + switch (ag->speed) {
  13514. + case SPEED_1000:
  13515. + mii_speed = MII_CTRL_SPEED_1000;
  13516. + cfg2 |= MAC_CFG2_IF_1000;
  13517. + fifo5 |= FIFO_CFG5_BM;
  13518. + break;
  13519. + case SPEED_100:
  13520. + mii_speed = MII_CTRL_SPEED_100;
  13521. + cfg2 |= MAC_CFG2_IF_10_100;
  13522. + ifctl |= MAC_IFCTL_SPEED;
  13523. + break;
  13524. + case SPEED_10:
  13525. + mii_speed = MII_CTRL_SPEED_10;
  13526. + cfg2 |= MAC_CFG2_IF_10_100;
  13527. + break;
  13528. + default:
  13529. + BUG();
  13530. + return;
  13531. + }
  13532. +
  13533. + if (pdata->is_ar91xx)
  13534. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x00780fff);
  13535. + else if (pdata->is_ar724x)
  13536. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, pdata->fifo_cfg3);
  13537. + else
  13538. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG3, 0x008001ff);
  13539. +
  13540. + if (pdata->set_pll)
  13541. + pdata->set_pll(ag->speed);
  13542. +
  13543. + ag71xx_mii_ctrl_set_speed(ag, mii_speed);
  13544. +
  13545. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG2, cfg2);
  13546. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, fifo5);
  13547. + ag71xx_wr(ag, AG71XX_REG_MAC_IFCTL, ifctl);
  13548. +
  13549. + netif_carrier_on(ag->dev);
  13550. + if (netif_msg_link(ag))
  13551. + printk(KERN_INFO "%s: link up (%sMbps/%s duplex)\n",
  13552. + ag->dev->name,
  13553. + ag71xx_speed_str(ag),
  13554. + (DUPLEX_FULL == ag->duplex) ? "Full" : "Half");
  13555. +
  13556. + DBG("%s: fifo_cfg0=%#x, fifo_cfg1=%#x, fifo_cfg2=%#x\n",
  13557. + ag->dev->name,
  13558. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG0),
  13559. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG1),
  13560. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG2));
  13561. +
  13562. + DBG("%s: fifo_cfg3=%#x, fifo_cfg4=%#x, fifo_cfg5=%#x\n",
  13563. + ag->dev->name,
  13564. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG3),
  13565. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG4),
  13566. + ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5));
  13567. +
  13568. + DBG("%s: mac_cfg2=%#x, mac_ifctl=%#x, mii_ctrl=%#x\n",
  13569. + ag->dev->name,
  13570. + ag71xx_rr(ag, AG71XX_REG_MAC_CFG2),
  13571. + ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL),
  13572. + ag71xx_mii_ctrl_rr(ag));
  13573. +}
  13574. +
  13575. +static void ag71xx_hw_set_macaddr(struct ag71xx *ag, unsigned char *mac)
  13576. +{
  13577. + u32 t;
  13578. +
  13579. + t = (((u32) mac[5]) << 24) | (((u32) mac[4]) << 16)
  13580. + | (((u32) mac[3]) << 8) | ((u32) mac[2]);
  13581. +
  13582. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR1, t);
  13583. +
  13584. + t = (((u32) mac[1]) << 24) | (((u32) mac[0]) << 16);
  13585. + ag71xx_wr(ag, AG71XX_REG_MAC_ADDR2, t);
  13586. +}
  13587. +
  13588. +static void ag71xx_dma_reset(struct ag71xx *ag)
  13589. +{
  13590. + u32 val;
  13591. + int i;
  13592. +
  13593. + ag71xx_dump_dma_regs(ag);
  13594. +
  13595. + /* stop RX and TX */
  13596. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, 0);
  13597. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, 0);
  13598. +
  13599. + /* clear descriptor addresses */
  13600. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, 0);
  13601. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, 0);
  13602. +
  13603. + /* clear pending RX/TX interrupts */
  13604. + for (i = 0; i < 256; i++) {
  13605. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  13606. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  13607. + }
  13608. +
  13609. + /* clear pending errors */
  13610. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE | RX_STATUS_OF);
  13611. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE | TX_STATUS_UR);
  13612. +
  13613. + val = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  13614. + if (val)
  13615. + printk(KERN_ALERT "%s: unable to clear DMA Rx status: %08x\n",
  13616. + ag->dev->name, val);
  13617. +
  13618. + val = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  13619. +
  13620. + /* mask out reserved bits */
  13621. + val &= ~0xff000000;
  13622. +
  13623. + if (val)
  13624. + printk(KERN_ALERT "%s: unable to clear DMA Tx status: %08x\n",
  13625. + ag->dev->name, val);
  13626. +
  13627. + ag71xx_dump_dma_regs(ag);
  13628. +}
  13629. +
  13630. +#define MAC_CFG1_INIT (MAC_CFG1_RXE | MAC_CFG1_TXE | \
  13631. + MAC_CFG1_SRX | MAC_CFG1_STX)
  13632. +
  13633. +#define FIFO_CFG0_INIT (FIFO_CFG0_ALL << FIFO_CFG0_ENABLE_SHIFT)
  13634. +
  13635. +#define FIFO_CFG4_INIT (FIFO_CFG4_DE | FIFO_CFG4_DV | FIFO_CFG4_FC | \
  13636. + FIFO_CFG4_CE | FIFO_CFG4_CR | FIFO_CFG4_LM | \
  13637. + FIFO_CFG4_LO | FIFO_CFG4_OK | FIFO_CFG4_MC | \
  13638. + FIFO_CFG4_BC | FIFO_CFG4_DR | FIFO_CFG4_LE | \
  13639. + FIFO_CFG4_CF | FIFO_CFG4_PF | FIFO_CFG4_UO | \
  13640. + FIFO_CFG4_VT)
  13641. +
  13642. +#define FIFO_CFG5_INIT (FIFO_CFG5_DE | FIFO_CFG5_DV | FIFO_CFG5_FC | \
  13643. + FIFO_CFG5_CE | FIFO_CFG5_LO | FIFO_CFG5_OK | \
  13644. + FIFO_CFG5_MC | FIFO_CFG5_BC | FIFO_CFG5_DR | \
  13645. + FIFO_CFG5_CF | FIFO_CFG5_PF | FIFO_CFG5_VT | \
  13646. + FIFO_CFG5_LE | FIFO_CFG5_FT | FIFO_CFG5_16 | \
  13647. + FIFO_CFG5_17 | FIFO_CFG5_SF)
  13648. +
  13649. +static void ag71xx_hw_init(struct ag71xx *ag)
  13650. +{
  13651. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13652. +
  13653. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_SR);
  13654. + udelay(20);
  13655. +
  13656. + ar71xx_device_stop(pdata->reset_bit);
  13657. + mdelay(100);
  13658. + ar71xx_device_start(pdata->reset_bit);
  13659. + mdelay(100);
  13660. +
  13661. + /* setup MAC configuration registers */
  13662. + if (pdata->is_ar724x)
  13663. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG1,
  13664. + MAC_CFG1_INIT | MAC_CFG1_TFC | MAC_CFG1_RFC);
  13665. + else
  13666. + ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, MAC_CFG1_INIT);
  13667. +
  13668. + ag71xx_sb(ag, AG71XX_REG_MAC_CFG2,
  13669. + MAC_CFG2_PAD_CRC_EN | MAC_CFG2_LEN_CHECK);
  13670. +
  13671. + /* setup max frame length */
  13672. + ag71xx_wr(ag, AG71XX_REG_MAC_MFL, AG71XX_TX_MTU_LEN);
  13673. +
  13674. + /* setup MII interface type */
  13675. + ag71xx_mii_ctrl_set_if(ag, pdata->mii_if);
  13676. +
  13677. + /* setup FIFO configuration registers */
  13678. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG0, FIFO_CFG0_INIT);
  13679. + if (pdata->is_ar724x) {
  13680. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, pdata->fifo_cfg1);
  13681. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, pdata->fifo_cfg2);
  13682. + } else {
  13683. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG1, 0x0fff0000);
  13684. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG2, 0x00001fff);
  13685. + }
  13686. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG4, FIFO_CFG4_INIT);
  13687. + ag71xx_wr(ag, AG71XX_REG_FIFO_CFG5, FIFO_CFG5_INIT);
  13688. +
  13689. + ag71xx_dma_reset(ag);
  13690. +}
  13691. +
  13692. +static void ag71xx_hw_start(struct ag71xx *ag)
  13693. +{
  13694. + /* start RX engine */
  13695. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  13696. +
  13697. + /* enable interrupts */
  13698. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, AG71XX_INT_INIT);
  13699. +}
  13700. +
  13701. +static void ag71xx_hw_stop(struct ag71xx *ag)
  13702. +{
  13703. + /* disable all interrupts */
  13704. + ag71xx_wr(ag, AG71XX_REG_INT_ENABLE, 0);
  13705. +
  13706. + ag71xx_dma_reset(ag);
  13707. +}
  13708. +
  13709. +static int ag71xx_open(struct net_device *dev)
  13710. +{
  13711. + struct ag71xx *ag = netdev_priv(dev);
  13712. + int ret;
  13713. +
  13714. + ret = ag71xx_rings_init(ag);
  13715. + if (ret)
  13716. + goto err;
  13717. +
  13718. + napi_enable(&ag->napi);
  13719. +
  13720. + netif_carrier_off(dev);
  13721. + ag71xx_phy_start(ag);
  13722. +
  13723. + ag71xx_wr(ag, AG71XX_REG_TX_DESC, ag->tx_ring.descs_dma);
  13724. + ag71xx_wr(ag, AG71XX_REG_RX_DESC, ag->rx_ring.descs_dma);
  13725. +
  13726. + ag71xx_hw_set_macaddr(ag, dev->dev_addr);
  13727. +
  13728. + ag71xx_hw_start(ag);
  13729. +
  13730. + netif_start_queue(dev);
  13731. +
  13732. + return 0;
  13733. +
  13734. + err:
  13735. + ag71xx_rings_cleanup(ag);
  13736. + return ret;
  13737. +}
  13738. +
  13739. +static int ag71xx_stop(struct net_device *dev)
  13740. +{
  13741. + struct ag71xx *ag = netdev_priv(dev);
  13742. + unsigned long flags;
  13743. +
  13744. + netif_carrier_off(dev);
  13745. + ag71xx_phy_stop(ag);
  13746. +
  13747. + spin_lock_irqsave(&ag->lock, flags);
  13748. +
  13749. + netif_stop_queue(dev);
  13750. +
  13751. + ag71xx_hw_stop(ag);
  13752. +
  13753. + napi_disable(&ag->napi);
  13754. + del_timer_sync(&ag->oom_timer);
  13755. +
  13756. + spin_unlock_irqrestore(&ag->lock, flags);
  13757. +
  13758. + ag71xx_rings_cleanup(ag);
  13759. +
  13760. + return 0;
  13761. +}
  13762. +
  13763. +static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
  13764. + struct net_device *dev)
  13765. +{
  13766. + struct ag71xx *ag = netdev_priv(dev);
  13767. + struct ag71xx_ring *ring = &ag->tx_ring;
  13768. + struct ag71xx_desc *desc;
  13769. + dma_addr_t dma_addr;
  13770. + int i;
  13771. +
  13772. + i = ring->curr % AG71XX_TX_RING_SIZE;
  13773. + desc = ring->buf[i].desc;
  13774. +
  13775. + if (!ag71xx_desc_empty(desc))
  13776. + goto err_drop;
  13777. +
  13778. + if (ag71xx_has_ar8216(ag))
  13779. + ag71xx_add_ar8216_header(ag, skb);
  13780. +
  13781. + if (skb->len <= 0) {
  13782. + DBG("%s: packet len is too small\n", ag->dev->name);
  13783. + goto err_drop;
  13784. + }
  13785. +
  13786. + dma_addr = dma_map_single(&dev->dev, skb->data, skb->len,
  13787. + DMA_TO_DEVICE);
  13788. +
  13789. + ring->buf[i].skb = skb;
  13790. +
  13791. + /* setup descriptor fields */
  13792. + desc->data = (u32) dma_addr;
  13793. + desc->ctrl = (skb->len & DESC_PKTLEN_M);
  13794. +
  13795. + /* flush descriptor */
  13796. + wmb();
  13797. +
  13798. + ring->curr++;
  13799. + if (ring->curr == (ring->dirty + AG71XX_TX_THRES_STOP)) {
  13800. + DBG("%s: tx queue full\n", ag->dev->name);
  13801. + netif_stop_queue(dev);
  13802. + }
  13803. +
  13804. + DBG("%s: packet injected into TX queue\n", ag->dev->name);
  13805. +
  13806. + /* enable TX engine */
  13807. + ag71xx_wr(ag, AG71XX_REG_TX_CTRL, TX_CTRL_TXE);
  13808. +
  13809. + return NETDEV_TX_OK;
  13810. +
  13811. + err_drop:
  13812. + dev->stats.tx_dropped++;
  13813. +
  13814. + dev_kfree_skb(skb);
  13815. + return NETDEV_TX_OK;
  13816. +}
  13817. +
  13818. +static int ag71xx_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  13819. +{
  13820. + struct mii_ioctl_data *data = (struct mii_ioctl_data *) &ifr->ifr_data;
  13821. + struct ag71xx *ag = netdev_priv(dev);
  13822. + int ret;
  13823. +
  13824. + switch (cmd) {
  13825. + case SIOCETHTOOL:
  13826. + if (ag->phy_dev == NULL)
  13827. + break;
  13828. +
  13829. + spin_lock_irq(&ag->lock);
  13830. + ret = phy_ethtool_ioctl(ag->phy_dev, (void *) ifr->ifr_data);
  13831. + spin_unlock_irq(&ag->lock);
  13832. + return ret;
  13833. +
  13834. + case SIOCSIFHWADDR:
  13835. + if (copy_from_user
  13836. + (dev->dev_addr, ifr->ifr_data, sizeof(dev->dev_addr)))
  13837. + return -EFAULT;
  13838. + return 0;
  13839. +
  13840. + case SIOCGIFHWADDR:
  13841. + if (copy_to_user
  13842. + (ifr->ifr_data, dev->dev_addr, sizeof(dev->dev_addr)))
  13843. + return -EFAULT;
  13844. + return 0;
  13845. +
  13846. + case SIOCGMIIPHY:
  13847. + case SIOCGMIIREG:
  13848. + case SIOCSMIIREG:
  13849. + if (ag->phy_dev == NULL)
  13850. + break;
  13851. +
  13852. + return phy_mii_ioctl(ag->phy_dev, data, cmd);
  13853. +
  13854. + default:
  13855. + break;
  13856. + }
  13857. +
  13858. + return -EOPNOTSUPP;
  13859. +}
  13860. +
  13861. +static void ag71xx_oom_timer_handler(unsigned long data)
  13862. +{
  13863. + struct net_device *dev = (struct net_device *) data;
  13864. + struct ag71xx *ag = netdev_priv(dev);
  13865. +
  13866. + napi_schedule(&ag->napi);
  13867. +}
  13868. +
  13869. +static void ag71xx_tx_timeout(struct net_device *dev)
  13870. +{
  13871. + struct ag71xx *ag = netdev_priv(dev);
  13872. +
  13873. + if (netif_msg_tx_err(ag))
  13874. + printk(KERN_DEBUG "%s: tx timeout\n", ag->dev->name);
  13875. +
  13876. + schedule_work(&ag->restart_work);
  13877. +}
  13878. +
  13879. +static void ag71xx_restart_work_func(struct work_struct *work)
  13880. +{
  13881. + struct ag71xx *ag = container_of(work, struct ag71xx, restart_work);
  13882. +
  13883. + ag71xx_stop(ag->dev);
  13884. + ag71xx_open(ag->dev);
  13885. +}
  13886. +
  13887. +static int ag71xx_tx_packets(struct ag71xx *ag)
  13888. +{
  13889. + struct ag71xx_ring *ring = &ag->tx_ring;
  13890. + int sent;
  13891. +
  13892. + DBG("%s: processing TX ring\n", ag->dev->name);
  13893. +
  13894. + sent = 0;
  13895. + while (ring->dirty != ring->curr) {
  13896. + unsigned int i = ring->dirty % AG71XX_TX_RING_SIZE;
  13897. + struct ag71xx_desc *desc = ring->buf[i].desc;
  13898. + struct sk_buff *skb = ring->buf[i].skb;
  13899. +
  13900. + if (!ag71xx_desc_empty(desc))
  13901. + break;
  13902. +
  13903. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_PS);
  13904. +
  13905. + ag->dev->stats.tx_bytes += skb->len;
  13906. + ag->dev->stats.tx_packets++;
  13907. +
  13908. + dev_kfree_skb_any(skb);
  13909. + ring->buf[i].skb = NULL;
  13910. +
  13911. + ring->dirty++;
  13912. + sent++;
  13913. + }
  13914. +
  13915. + DBG("%s: %d packets sent out\n", ag->dev->name, sent);
  13916. +
  13917. + if ((ring->curr - ring->dirty) < AG71XX_TX_THRES_WAKEUP)
  13918. + netif_wake_queue(ag->dev);
  13919. +
  13920. + return sent;
  13921. +}
  13922. +
  13923. +static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
  13924. +{
  13925. + struct net_device *dev = ag->dev;
  13926. + struct ag71xx_ring *ring = &ag->rx_ring;
  13927. + int done = 0;
  13928. +
  13929. + DBG("%s: rx packets, limit=%d, curr=%u, dirty=%u\n",
  13930. + dev->name, limit, ring->curr, ring->dirty);
  13931. +
  13932. + while (done < limit) {
  13933. + unsigned int i = ring->curr % AG71XX_RX_RING_SIZE;
  13934. + struct ag71xx_desc *desc = ring->buf[i].desc;
  13935. + struct sk_buff *skb;
  13936. + int pktlen;
  13937. + int err = 0;
  13938. +
  13939. + if (ag71xx_desc_empty(desc))
  13940. + break;
  13941. +
  13942. + if ((ring->dirty + AG71XX_RX_RING_SIZE) == ring->curr) {
  13943. + ag71xx_assert(0);
  13944. + break;
  13945. + }
  13946. +
  13947. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_PR);
  13948. +
  13949. + skb = ring->buf[i].skb;
  13950. + pktlen = ag71xx_desc_pktlen(desc);
  13951. + pktlen -= ETH_FCS_LEN;
  13952. +
  13953. + dma_unmap_single(&dev->dev, ring->buf[i].dma_addr,
  13954. + AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
  13955. +
  13956. + dev->last_rx = jiffies;
  13957. + dev->stats.rx_packets++;
  13958. + dev->stats.rx_bytes += pktlen;
  13959. +
  13960. + skb_put(skb, pktlen);
  13961. + if (ag71xx_has_ar8216(ag))
  13962. + err = ag71xx_remove_ar8216_header(ag, skb, pktlen);
  13963. +
  13964. + if (err) {
  13965. + dev->stats.rx_dropped++;
  13966. + kfree_skb(skb);
  13967. + } else {
  13968. + skb->dev = dev;
  13969. + skb->ip_summed = CHECKSUM_NONE;
  13970. + if (ag->phy_dev) {
  13971. + ag->phy_dev->netif_receive_skb(skb);
  13972. + } else {
  13973. + skb->protocol = eth_type_trans(skb, dev);
  13974. + netif_receive_skb(skb);
  13975. + }
  13976. + }
  13977. +
  13978. + ring->buf[i].skb = NULL;
  13979. + done++;
  13980. +
  13981. + ring->curr++;
  13982. + }
  13983. +
  13984. + ag71xx_ring_rx_refill(ag);
  13985. +
  13986. + DBG("%s: rx finish, curr=%u, dirty=%u, done=%d\n",
  13987. + dev->name, ring->curr, ring->dirty, done);
  13988. +
  13989. + return done;
  13990. +}
  13991. +
  13992. +static int ag71xx_poll(struct napi_struct *napi, int limit)
  13993. +{
  13994. + struct ag71xx *ag = container_of(napi, struct ag71xx, napi);
  13995. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  13996. + struct net_device *dev = ag->dev;
  13997. + struct ag71xx_ring *rx_ring;
  13998. + unsigned long flags;
  13999. + u32 status;
  14000. + int tx_done;
  14001. + int rx_done;
  14002. +
  14003. + pdata->ddr_flush();
  14004. + tx_done = ag71xx_tx_packets(ag);
  14005. +
  14006. + DBG("%s: processing RX ring\n", dev->name);
  14007. + rx_done = ag71xx_rx_packets(ag, limit);
  14008. +
  14009. + ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done);
  14010. +
  14011. + rx_ring = &ag->rx_ring;
  14012. + if (rx_ring->buf[rx_ring->dirty % AG71XX_RX_RING_SIZE].skb == NULL)
  14013. + goto oom;
  14014. +
  14015. + status = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
  14016. + if (unlikely(status & RX_STATUS_OF)) {
  14017. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_OF);
  14018. + dev->stats.rx_fifo_errors++;
  14019. +
  14020. + /* restart RX */
  14021. + ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE);
  14022. + }
  14023. +
  14024. + if (rx_done < limit) {
  14025. + if (status & RX_STATUS_PR)
  14026. + goto more;
  14027. +
  14028. + status = ag71xx_rr(ag, AG71XX_REG_TX_STATUS);
  14029. + if (status & TX_STATUS_PS)
  14030. + goto more;
  14031. +
  14032. + DBG("%s: disable polling mode, rx=%d, tx=%d,limit=%d\n",
  14033. + dev->name, rx_done, tx_done, limit);
  14034. +
  14035. + napi_complete(napi);
  14036. +
  14037. + /* enable interrupts */
  14038. + spin_lock_irqsave(&ag->lock, flags);
  14039. + ag71xx_int_enable(ag, AG71XX_INT_POLL);
  14040. + spin_unlock_irqrestore(&ag->lock, flags);
  14041. + return rx_done;
  14042. + }
  14043. +
  14044. + more:
  14045. + DBG("%s: stay in polling mode, rx=%d, tx=%d, limit=%d\n",
  14046. + dev->name, rx_done, tx_done, limit);
  14047. + return rx_done;
  14048. +
  14049. + oom:
  14050. + if (netif_msg_rx_err(ag))
  14051. + printk(KERN_DEBUG "%s: out of memory\n", dev->name);
  14052. +
  14053. + mod_timer(&ag->oom_timer, jiffies + AG71XX_OOM_REFILL);
  14054. + napi_complete(napi);
  14055. + return 0;
  14056. +}
  14057. +
  14058. +static irqreturn_t ag71xx_interrupt(int irq, void *dev_id)
  14059. +{
  14060. + struct net_device *dev = dev_id;
  14061. + struct ag71xx *ag = netdev_priv(dev);
  14062. + u32 status;
  14063. +
  14064. + status = ag71xx_rr(ag, AG71XX_REG_INT_STATUS);
  14065. + ag71xx_dump_intr(ag, "raw", status);
  14066. +
  14067. + if (unlikely(!status))
  14068. + return IRQ_NONE;
  14069. +
  14070. + if (unlikely(status & AG71XX_INT_ERR)) {
  14071. + if (status & AG71XX_INT_TX_BE) {
  14072. + ag71xx_wr(ag, AG71XX_REG_TX_STATUS, TX_STATUS_BE);
  14073. + dev_err(&dev->dev, "TX BUS error\n");
  14074. + }
  14075. + if (status & AG71XX_INT_RX_BE) {
  14076. + ag71xx_wr(ag, AG71XX_REG_RX_STATUS, RX_STATUS_BE);
  14077. + dev_err(&dev->dev, "RX BUS error\n");
  14078. + }
  14079. + }
  14080. +
  14081. + if (likely(status & AG71XX_INT_POLL)) {
  14082. + ag71xx_int_disable(ag, AG71XX_INT_POLL);
  14083. + DBG("%s: enable polling mode\n", dev->name);
  14084. + napi_schedule(&ag->napi);
  14085. + }
  14086. +
  14087. + ag71xx_debugfs_update_int_stats(ag, status);
  14088. +
  14089. + return IRQ_HANDLED;
  14090. +}
  14091. +
  14092. +static void ag71xx_set_multicast_list(struct net_device *dev)
  14093. +{
  14094. + /* TODO */
  14095. +}
  14096. +
  14097. +#ifdef CONFIG_NET_POLL_CONTROLLER
  14098. +/*
  14099. + * Polling 'interrupt' - used by things like netconsole to send skbs
  14100. + * without having to re-enable interrupts. It's not called while
  14101. + * the interrupt routine is executing.
  14102. + */
  14103. +static void ag71xx_netpoll(struct net_device *dev)
  14104. +{
  14105. + disable_irq(dev->irq);
  14106. + ag71xx_interrupt(dev->irq, dev);
  14107. + enable_irq(dev->irq);
  14108. +}
  14109. +#endif
  14110. +
  14111. +static const struct net_device_ops ag71xx_netdev_ops = {
  14112. + .ndo_open = ag71xx_open,
  14113. + .ndo_stop = ag71xx_stop,
  14114. + .ndo_start_xmit = ag71xx_hard_start_xmit,
  14115. + .ndo_set_multicast_list = ag71xx_set_multicast_list,
  14116. + .ndo_do_ioctl = ag71xx_do_ioctl,
  14117. + .ndo_tx_timeout = ag71xx_tx_timeout,
  14118. + .ndo_change_mtu = eth_change_mtu,
  14119. + .ndo_set_mac_address = eth_mac_addr,
  14120. + .ndo_validate_addr = eth_validate_addr,
  14121. +#ifdef CONFIG_NET_POLL_CONTROLLER
  14122. + .ndo_poll_controller = ag71xx_netpoll,
  14123. +#endif
  14124. +};
  14125. +
  14126. +static int __init ag71xx_probe(struct platform_device *pdev)
  14127. +{
  14128. + struct net_device *dev;
  14129. + struct resource *res;
  14130. + struct ag71xx *ag;
  14131. + struct ag71xx_platform_data *pdata;
  14132. + int err;
  14133. +
  14134. + pdata = pdev->dev.platform_data;
  14135. + if (!pdata) {
  14136. + dev_err(&pdev->dev, "no platform data specified\n");
  14137. + err = -ENXIO;
  14138. + goto err_out;
  14139. + }
  14140. +
  14141. + if (pdata->mii_bus_dev == NULL) {
  14142. + dev_err(&pdev->dev, "no MII bus device specified\n");
  14143. + err = -EINVAL;
  14144. + goto err_out;
  14145. + }
  14146. +
  14147. + dev = alloc_etherdev(sizeof(*ag));
  14148. + if (!dev) {
  14149. + dev_err(&pdev->dev, "alloc_etherdev failed\n");
  14150. + err = -ENOMEM;
  14151. + goto err_out;
  14152. + }
  14153. +
  14154. + SET_NETDEV_DEV(dev, &pdev->dev);
  14155. +
  14156. + ag = netdev_priv(dev);
  14157. + ag->pdev = pdev;
  14158. + ag->dev = dev;
  14159. + ag->msg_enable = netif_msg_init(ag71xx_msg_level,
  14160. + AG71XX_DEFAULT_MSG_ENABLE);
  14161. + spin_lock_init(&ag->lock);
  14162. +
  14163. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mac_base");
  14164. + if (!res) {
  14165. + dev_err(&pdev->dev, "no mac_base resource found\n");
  14166. + err = -ENXIO;
  14167. + goto err_out;
  14168. + }
  14169. +
  14170. + ag->mac_base = ioremap_nocache(res->start, res->end - res->start + 1);
  14171. + if (!ag->mac_base) {
  14172. + dev_err(&pdev->dev, "unable to ioremap mac_base\n");
  14173. + err = -ENOMEM;
  14174. + goto err_free_dev;
  14175. + }
  14176. +
  14177. + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mii_ctrl");
  14178. + if (!res) {
  14179. + dev_err(&pdev->dev, "no mii_ctrl resource found\n");
  14180. + err = -ENXIO;
  14181. + goto err_unmap_base;
  14182. + }
  14183. +
  14184. + ag->mii_ctrl = ioremap_nocache(res->start, res->end - res->start + 1);
  14185. + if (!ag->mii_ctrl) {
  14186. + dev_err(&pdev->dev, "unable to ioremap mii_ctrl\n");
  14187. + err = -ENOMEM;
  14188. + goto err_unmap_base;
  14189. + }
  14190. +
  14191. + dev->irq = platform_get_irq(pdev, 0);
  14192. + err = request_irq(dev->irq, ag71xx_interrupt,
  14193. + IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  14194. + dev->name, dev);
  14195. + if (err) {
  14196. + dev_err(&pdev->dev, "unable to request IRQ %d\n", dev->irq);
  14197. + goto err_unmap_mii_ctrl;
  14198. + }
  14199. +
  14200. + dev->base_addr = (unsigned long)ag->mac_base;
  14201. + dev->netdev_ops = &ag71xx_netdev_ops;
  14202. + dev->ethtool_ops = &ag71xx_ethtool_ops;
  14203. +
  14204. + INIT_WORK(&ag->restart_work, ag71xx_restart_work_func);
  14205. +
  14206. + init_timer(&ag->oom_timer);
  14207. + ag->oom_timer.data = (unsigned long) dev;
  14208. + ag->oom_timer.function = ag71xx_oom_timer_handler;
  14209. +
  14210. + memcpy(dev->dev_addr, pdata->mac_addr, ETH_ALEN);
  14211. +
  14212. + netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
  14213. +
  14214. + err = register_netdev(dev);
  14215. + if (err) {
  14216. + dev_err(&pdev->dev, "unable to register net device\n");
  14217. + goto err_free_irq;
  14218. + }
  14219. +
  14220. + printk(KERN_INFO "%s: Atheros AG71xx at 0x%08lx, irq %d\n",
  14221. + dev->name, dev->base_addr, dev->irq);
  14222. +
  14223. + ag71xx_dump_regs(ag);
  14224. +
  14225. + ag71xx_hw_init(ag);
  14226. +
  14227. + ag71xx_dump_regs(ag);
  14228. +
  14229. + err = ag71xx_phy_connect(ag);
  14230. + if (err)
  14231. + goto err_unregister_netdev;
  14232. +
  14233. + err = ag71xx_debugfs_init(ag);
  14234. + if (err)
  14235. + goto err_phy_disconnect;
  14236. +
  14237. + platform_set_drvdata(pdev, dev);
  14238. +
  14239. + return 0;
  14240. +
  14241. + err_phy_disconnect:
  14242. + ag71xx_phy_disconnect(ag);
  14243. + err_unregister_netdev:
  14244. + unregister_netdev(dev);
  14245. + err_free_irq:
  14246. + free_irq(dev->irq, dev);
  14247. + err_unmap_mii_ctrl:
  14248. + iounmap(ag->mii_ctrl);
  14249. + err_unmap_base:
  14250. + iounmap(ag->mac_base);
  14251. + err_free_dev:
  14252. + kfree(dev);
  14253. + err_out:
  14254. + platform_set_drvdata(pdev, NULL);
  14255. + return err;
  14256. +}
  14257. +
  14258. +static int __exit ag71xx_remove(struct platform_device *pdev)
  14259. +{
  14260. + struct net_device *dev = platform_get_drvdata(pdev);
  14261. +
  14262. + if (dev) {
  14263. + struct ag71xx *ag = netdev_priv(dev);
  14264. +
  14265. + ag71xx_debugfs_exit(ag);
  14266. + ag71xx_phy_disconnect(ag);
  14267. + unregister_netdev(dev);
  14268. + free_irq(dev->irq, dev);
  14269. + iounmap(ag->mii_ctrl);
  14270. + iounmap(ag->mac_base);
  14271. + kfree(dev);
  14272. + platform_set_drvdata(pdev, NULL);
  14273. + }
  14274. +
  14275. + return 0;
  14276. +}
  14277. +
  14278. +static struct platform_driver ag71xx_driver = {
  14279. + .probe = ag71xx_probe,
  14280. + .remove = __exit_p(ag71xx_remove),
  14281. + .driver = {
  14282. + .name = AG71XX_DRV_NAME,
  14283. + }
  14284. +};
  14285. +
  14286. +static int __init ag71xx_module_init(void)
  14287. +{
  14288. + int ret;
  14289. +
  14290. + ret = ag71xx_debugfs_root_init();
  14291. + if (ret)
  14292. + goto err_out;
  14293. +
  14294. + ret = ag71xx_mdio_driver_init();
  14295. + if (ret)
  14296. + goto err_debugfs_exit;
  14297. +
  14298. + ret = platform_driver_register(&ag71xx_driver);
  14299. + if (ret)
  14300. + goto err_mdio_exit;
  14301. +
  14302. + return 0;
  14303. +
  14304. + err_mdio_exit:
  14305. + ag71xx_mdio_driver_exit();
  14306. + err_debugfs_exit:
  14307. + ag71xx_debugfs_root_exit();
  14308. + err_out:
  14309. + return ret;
  14310. +}
  14311. +
  14312. +static void __exit ag71xx_module_exit(void)
  14313. +{
  14314. + platform_driver_unregister(&ag71xx_driver);
  14315. + ag71xx_mdio_driver_exit();
  14316. + ag71xx_debugfs_root_exit();
  14317. +}
  14318. +
  14319. +module_init(ag71xx_module_init);
  14320. +module_exit(ag71xx_module_exit);
  14321. +
  14322. +MODULE_VERSION(AG71XX_DRV_VERSION);
  14323. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  14324. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  14325. +MODULE_LICENSE("GPL v2");
  14326. +MODULE_ALIAS("platform:" AG71XX_DRV_NAME);
  14327. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_mdio.c linux-2.6.34/drivers/net/ag71xx/ag71xx_mdio.c
  14328. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_mdio.c 1970-01-01 01:00:00.000000000 +0100
  14329. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_mdio.c 2010-05-25 18:46:09.633464081 +0200
  14330. @@ -0,0 +1,243 @@
  14331. +/*
  14332. + * Atheros AR71xx built-in ethernet mac driver
  14333. + *
  14334. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  14335. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  14336. + *
  14337. + * Based on Atheros' AG7100 driver
  14338. + *
  14339. + * This program is free software; you can redistribute it and/or modify it
  14340. + * under the terms of the GNU General Public License version 2 as published
  14341. + * by the Free Software Foundation.
  14342. + */
  14343. +
  14344. +#include "ag71xx.h"
  14345. +
  14346. +#define AG71XX_MDIO_RETRY 1000
  14347. +#define AG71XX_MDIO_DELAY 5
  14348. +
  14349. +static inline void ag71xx_mdio_wr(struct ag71xx_mdio *am, unsigned reg,
  14350. + u32 value)
  14351. +{
  14352. + void __iomem *r;
  14353. +
  14354. + r = am->mdio_base + reg;
  14355. + __raw_writel(value, r);
  14356. +
  14357. + /* flush write */
  14358. + (void) __raw_readl(r);
  14359. +}
  14360. +
  14361. +static inline u32 ag71xx_mdio_rr(struct ag71xx_mdio *am, unsigned reg)
  14362. +{
  14363. + return __raw_readl(am->mdio_base + reg);
  14364. +}
  14365. +
  14366. +static void ag71xx_mdio_dump_regs(struct ag71xx_mdio *am)
  14367. +{
  14368. + DBG("%s: mii_cfg=%08x, mii_cmd=%08x, mii_addr=%08x\n",
  14369. + am->mii_bus->name,
  14370. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CFG),
  14371. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CMD),
  14372. + ag71xx_mdio_rr(am, AG71XX_REG_MII_ADDR));
  14373. + DBG("%s: mii_ctrl=%08x, mii_status=%08x, mii_ind=%08x\n",
  14374. + am->mii_bus->name,
  14375. + ag71xx_mdio_rr(am, AG71XX_REG_MII_CTRL),
  14376. + ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS),
  14377. + ag71xx_mdio_rr(am, AG71XX_REG_MII_IND));
  14378. +}
  14379. +
  14380. +static int ag71xx_mdio_mii_read(struct ag71xx_mdio *am, int addr, int reg)
  14381. +{
  14382. + int ret;
  14383. + int i;
  14384. +
  14385. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  14386. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  14387. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  14388. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_READ);
  14389. +
  14390. + i = AG71XX_MDIO_RETRY;
  14391. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  14392. + if (i-- == 0) {
  14393. + printk(KERN_ERR "%s: mii_read timed out\n",
  14394. + am->mii_bus->name);
  14395. + ret = 0xffff;
  14396. + goto out;
  14397. + }
  14398. + udelay(AG71XX_MDIO_DELAY);
  14399. + }
  14400. +
  14401. + ret = ag71xx_mdio_rr(am, AG71XX_REG_MII_STATUS) & 0xffff;
  14402. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CMD, MII_CMD_WRITE);
  14403. +
  14404. + DBG("mii_read: addr=%04x, reg=%04x, value=%04x\n", addr, reg, ret);
  14405. +
  14406. + out:
  14407. + return ret;
  14408. +}
  14409. +
  14410. +static void ag71xx_mdio_mii_write(struct ag71xx_mdio *am,
  14411. + int addr, int reg, u16 val)
  14412. +{
  14413. + int i;
  14414. +
  14415. + DBG("mii_write: addr=%04x, reg=%04x, value=%04x\n", addr, reg, val);
  14416. +
  14417. + ag71xx_mdio_wr(am, AG71XX_REG_MII_ADDR,
  14418. + ((addr & 0xff) << MII_ADDR_SHIFT) | (reg & 0xff));
  14419. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CTRL, val);
  14420. +
  14421. + i = AG71XX_MDIO_RETRY;
  14422. + while (ag71xx_mdio_rr(am, AG71XX_REG_MII_IND) & MII_IND_BUSY) {
  14423. + if (i-- == 0) {
  14424. + printk(KERN_ERR "%s: mii_write timed out\n",
  14425. + am->mii_bus->name);
  14426. + break;
  14427. + }
  14428. + udelay(AG71XX_MDIO_DELAY);
  14429. + }
  14430. +}
  14431. +
  14432. +static int ag71xx_mdio_reset(struct mii_bus *bus)
  14433. +{
  14434. + struct ag71xx_mdio *am = bus->priv;
  14435. + u32 t;
  14436. +
  14437. + if (am->pdata->is_ar7240)
  14438. + t = MII_CFG_CLK_DIV_6;
  14439. + else
  14440. + t = MII_CFG_CLK_DIV_28;
  14441. +
  14442. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t | MII_CFG_RESET);
  14443. + udelay(100);
  14444. +
  14445. + ag71xx_mdio_wr(am, AG71XX_REG_MII_CFG, t);
  14446. + udelay(100);
  14447. +
  14448. + return 0;
  14449. +}
  14450. +
  14451. +static int ag71xx_mdio_read(struct mii_bus *bus, int addr, int reg)
  14452. +{
  14453. + struct ag71xx_mdio *am = bus->priv;
  14454. +
  14455. + return ag71xx_mdio_mii_read(am, addr, reg);
  14456. +}
  14457. +
  14458. +static int ag71xx_mdio_write(struct mii_bus *bus, int addr, int reg, u16 val)
  14459. +{
  14460. + struct ag71xx_mdio *am = bus->priv;
  14461. +
  14462. + ag71xx_mdio_mii_write(am, addr, reg, val);
  14463. + return 0;
  14464. +}
  14465. +
  14466. +static int __init ag71xx_mdio_probe(struct platform_device *pdev)
  14467. +{
  14468. + struct ag71xx_mdio_platform_data *pdata;
  14469. + struct ag71xx_mdio *am;
  14470. + struct resource *res;
  14471. + int i;
  14472. + int err;
  14473. +
  14474. + pdata = pdev->dev.platform_data;
  14475. + if (!pdata) {
  14476. + dev_err(&pdev->dev, "no platform data specified\n");
  14477. + return -EINVAL;
  14478. + }
  14479. +
  14480. + am = kzalloc(sizeof(*am), GFP_KERNEL);
  14481. + if (!am) {
  14482. + err = -ENOMEM;
  14483. + goto err_out;
  14484. + }
  14485. +
  14486. + am->pdata = pdata;
  14487. +
  14488. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  14489. + if (!res) {
  14490. + dev_err(&pdev->dev, "no iomem resource found\n");
  14491. + err = -ENXIO;
  14492. + goto err_out;
  14493. + }
  14494. +
  14495. + am->mdio_base = ioremap_nocache(res->start, res->end - res->start + 1);
  14496. + if (!am->mdio_base) {
  14497. + dev_err(&pdev->dev, "unable to ioremap registers\n");
  14498. + err = -ENOMEM;
  14499. + goto err_free_mdio;
  14500. + }
  14501. +
  14502. + am->mii_bus = mdiobus_alloc();
  14503. + if (am->mii_bus == NULL) {
  14504. + err = -ENOMEM;
  14505. + goto err_iounmap;
  14506. + }
  14507. +
  14508. + am->mii_bus->name = "ag71xx_mdio";
  14509. + am->mii_bus->read = ag71xx_mdio_read;
  14510. + am->mii_bus->write = ag71xx_mdio_write;
  14511. + am->mii_bus->reset = ag71xx_mdio_reset;
  14512. + am->mii_bus->irq = am->mii_irq;
  14513. + am->mii_bus->priv = am;
  14514. + am->mii_bus->parent = &pdev->dev;
  14515. + snprintf(am->mii_bus->id, MII_BUS_ID_SIZE, "%s", dev_name(&pdev->dev));
  14516. + am->mii_bus->phy_mask = pdata->phy_mask;
  14517. +
  14518. + for (i = 0; i < PHY_MAX_ADDR; i++)
  14519. + am->mii_irq[i] = PHY_POLL;
  14520. +
  14521. + ag71xx_mdio_wr(am, AG71XX_REG_MAC_CFG1, 0);
  14522. +
  14523. + err = mdiobus_register(am->mii_bus);
  14524. + if (err)
  14525. + goto err_free_bus;
  14526. +
  14527. + ag71xx_mdio_dump_regs(am);
  14528. +
  14529. + platform_set_drvdata(pdev, am);
  14530. + return 0;
  14531. +
  14532. + err_free_bus:
  14533. + mdiobus_free(am->mii_bus);
  14534. + err_iounmap:
  14535. + iounmap(am->mdio_base);
  14536. + err_free_mdio:
  14537. + kfree(am);
  14538. + err_out:
  14539. + return err;
  14540. +}
  14541. +
  14542. +static int __exit ag71xx_mdio_remove(struct platform_device *pdev)
  14543. +{
  14544. + struct ag71xx_mdio *am = platform_get_drvdata(pdev);
  14545. +
  14546. + if (am) {
  14547. + mdiobus_unregister(am->mii_bus);
  14548. + mdiobus_free(am->mii_bus);
  14549. + iounmap(am->mdio_base);
  14550. + kfree(am);
  14551. + platform_set_drvdata(pdev, NULL);
  14552. + }
  14553. +
  14554. + return 0;
  14555. +}
  14556. +
  14557. +static struct platform_driver ag71xx_mdio_driver = {
  14558. + .probe = ag71xx_mdio_probe,
  14559. + .remove = __exit_p(ag71xx_mdio_remove),
  14560. + .driver = {
  14561. + .name = "ag71xx-mdio",
  14562. + }
  14563. +};
  14564. +
  14565. +int ag71xx_mdio_driver_init(void)
  14566. +{
  14567. + return platform_driver_register(&ag71xx_mdio_driver);
  14568. +}
  14569. +
  14570. +void ag71xx_mdio_driver_exit(void)
  14571. +{
  14572. + platform_driver_unregister(&ag71xx_mdio_driver);
  14573. +}
  14574. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_phy.c linux-2.6.34/drivers/net/ag71xx/ag71xx_phy.c
  14575. --- linux-2.6.34.orig/drivers/net/ag71xx/ag71xx_phy.c 1970-01-01 01:00:00.000000000 +0100
  14576. +++ linux-2.6.34/drivers/net/ag71xx/ag71xx_phy.c 2010-05-25 18:46:09.663473144 +0200
  14577. @@ -0,0 +1,213 @@
  14578. +/*
  14579. + * Atheros AR71xx built-in ethernet mac driver
  14580. + *
  14581. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  14582. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  14583. + *
  14584. + * Based on Atheros' AG7100 driver
  14585. + *
  14586. + * This program is free software; you can redistribute it and/or modify it
  14587. + * under the terms of the GNU General Public License version 2 as published
  14588. + * by the Free Software Foundation.
  14589. + */
  14590. +
  14591. +#include "ag71xx.h"
  14592. +
  14593. +static void ag71xx_phy_link_adjust(struct net_device *dev)
  14594. +{
  14595. + struct ag71xx *ag = netdev_priv(dev);
  14596. + struct phy_device *phydev = ag->phy_dev;
  14597. + unsigned long flags;
  14598. + int status_change = 0;
  14599. +
  14600. + spin_lock_irqsave(&ag->lock, flags);
  14601. +
  14602. + if (phydev->link) {
  14603. + if (ag->duplex != phydev->duplex
  14604. + || ag->speed != phydev->speed) {
  14605. + status_change = 1;
  14606. + }
  14607. + }
  14608. +
  14609. + if (phydev->link != ag->link)
  14610. + status_change = 1;
  14611. +
  14612. + ag->link = phydev->link;
  14613. + ag->duplex = phydev->duplex;
  14614. + ag->speed = phydev->speed;
  14615. +
  14616. + if (status_change)
  14617. + ag71xx_link_adjust(ag);
  14618. +
  14619. + spin_unlock_irqrestore(&ag->lock, flags);
  14620. +}
  14621. +
  14622. +void ag71xx_phy_start(struct ag71xx *ag)
  14623. +{
  14624. + if (ag->phy_dev) {
  14625. + phy_start(ag->phy_dev);
  14626. + } else {
  14627. + ag->link = 1;
  14628. + ag71xx_link_adjust(ag);
  14629. + }
  14630. +}
  14631. +
  14632. +void ag71xx_phy_stop(struct ag71xx *ag)
  14633. +{
  14634. + if (ag->phy_dev) {
  14635. + phy_stop(ag->phy_dev);
  14636. + } else {
  14637. + ag->link = 0;
  14638. + ag71xx_link_adjust(ag);
  14639. + }
  14640. +}
  14641. +
  14642. +static int ag71xx_phy_connect_fixed(struct ag71xx *ag)
  14643. +{
  14644. + struct net_device *dev = ag->dev;
  14645. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14646. + int ret = 0;
  14647. +
  14648. + /* use fixed settings */
  14649. + switch (pdata->speed) {
  14650. + case SPEED_10:
  14651. + case SPEED_100:
  14652. + case SPEED_1000:
  14653. + break;
  14654. + default:
  14655. + printk(KERN_ERR "%s: invalid speed specified\n", dev->name);
  14656. + ret = -EINVAL;
  14657. + break;
  14658. + }
  14659. +
  14660. + printk(KERN_DEBUG "%s: using fixed link parameters\n", dev->name);
  14661. +
  14662. + ag->duplex = pdata->duplex;
  14663. + ag->speed = pdata->speed;
  14664. +
  14665. + return ret;
  14666. +}
  14667. +
  14668. +static int ag71xx_phy_connect_multi(struct ag71xx *ag)
  14669. +{
  14670. + struct net_device *dev = ag->dev;
  14671. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14672. + struct phy_device *phydev = NULL;
  14673. + int phy_addr;
  14674. + int ret = 0;
  14675. +
  14676. + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
  14677. + if (!(pdata->phy_mask & (1 << phy_addr)))
  14678. + continue;
  14679. +
  14680. + if (ag->mii_bus->phy_map[phy_addr] == NULL)
  14681. + continue;
  14682. +
  14683. + DBG("%s: PHY found at %s, uid=%08x\n",
  14684. + dev->name,
  14685. + dev_name(&ag->mii_bus->phy_map[phy_addr]->dev),
  14686. + ag->mii_bus->phy_map[phy_addr]->phy_id);
  14687. +
  14688. + if (phydev == NULL)
  14689. + phydev = ag->mii_bus->phy_map[phy_addr];
  14690. + }
  14691. +
  14692. + if (!phydev) {
  14693. + printk(KERN_ERR "%s: no PHY found with phy_mask=%08x\n",
  14694. + dev->name, pdata->phy_mask);
  14695. + return -ENODEV;
  14696. + }
  14697. +
  14698. + ag->phy_dev = phy_connect(dev, dev_name(&phydev->dev),
  14699. + &ag71xx_phy_link_adjust, 0,
  14700. + pdata->phy_if_mode);
  14701. +
  14702. + if (IS_ERR(ag->phy_dev)) {
  14703. + printk(KERN_ERR "%s: could not connect to PHY at %s\n",
  14704. + dev->name, dev_name(&phydev->dev));
  14705. + return PTR_ERR(ag->phy_dev);
  14706. + }
  14707. +
  14708. + /* mask with MAC supported features */
  14709. + if (pdata->has_gbit)
  14710. + phydev->supported &= PHY_GBIT_FEATURES;
  14711. + else
  14712. + phydev->supported &= PHY_BASIC_FEATURES;
  14713. +
  14714. + phydev->advertising = phydev->supported;
  14715. +
  14716. + printk(KERN_DEBUG "%s: connected to PHY at %s [uid=%08x, driver=%s]\n",
  14717. + dev->name, dev_name(&phydev->dev),
  14718. + phydev->phy_id, phydev->drv->name);
  14719. +
  14720. + ag->link = 0;
  14721. + ag->speed = 0;
  14722. + ag->duplex = -1;
  14723. +
  14724. + return ret;
  14725. +}
  14726. +
  14727. +static int dev_is_class(struct device *dev, void *class)
  14728. +{
  14729. + if (dev->class != NULL && !strcmp(dev->class->name, class))
  14730. + return 1;
  14731. +
  14732. + return 0;
  14733. +}
  14734. +
  14735. +static struct device *dev_find_class(struct device *parent, char *class)
  14736. +{
  14737. + if (dev_is_class(parent, class)) {
  14738. + get_device(parent);
  14739. + return parent;
  14740. + }
  14741. +
  14742. + return device_find_child(parent, class, dev_is_class);
  14743. +}
  14744. +
  14745. +static struct mii_bus *dev_to_mii_bus(struct device *dev)
  14746. +{
  14747. + struct device *d;
  14748. +
  14749. + d = dev_find_class(dev, "mdio_bus");
  14750. + if (d != NULL) {
  14751. + struct mii_bus *bus;
  14752. +
  14753. + bus = to_mii_bus(d);
  14754. + put_device(d);
  14755. +
  14756. + return bus;
  14757. + }
  14758. +
  14759. + return NULL;
  14760. +}
  14761. +
  14762. +int ag71xx_phy_connect(struct ag71xx *ag)
  14763. +{
  14764. + struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
  14765. +
  14766. + ag->mii_bus = dev_to_mii_bus(pdata->mii_bus_dev);
  14767. + if (ag->mii_bus == NULL) {
  14768. + printk(KERN_ERR "%s: unable to find MII bus on device '%s'\n",
  14769. + ag->dev->name, dev_name(pdata->mii_bus_dev));
  14770. + return -ENODEV;
  14771. + }
  14772. +
  14773. + /* Reset the mdio bus explicitly */
  14774. + if (ag->mii_bus->reset) {
  14775. + mutex_lock(&ag->mii_bus->mdio_lock);
  14776. + ag->mii_bus->reset(ag->mii_bus);
  14777. + mutex_unlock(&ag->mii_bus->mdio_lock);
  14778. + }
  14779. +
  14780. + if (pdata->phy_mask)
  14781. + return ag71xx_phy_connect_multi(ag);
  14782. +
  14783. + return ag71xx_phy_connect_fixed(ag);
  14784. +}
  14785. +
  14786. +void ag71xx_phy_disconnect(struct ag71xx *ag)
  14787. +{
  14788. + if (ag->phy_dev)
  14789. + phy_disconnect(ag->phy_dev);
  14790. +}
  14791. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/Kconfig linux-2.6.34/drivers/net/ag71xx/Kconfig
  14792. --- linux-2.6.34.orig/drivers/net/ag71xx/Kconfig 1970-01-01 01:00:00.000000000 +0100
  14793. +++ linux-2.6.34/drivers/net/ag71xx/Kconfig 2010-05-25 18:46:09.693473072 +0200
  14794. @@ -0,0 +1,33 @@
  14795. +config AG71XX
  14796. + tristate "Atheros AR71xx built-in ethernet mac support"
  14797. + depends on ATHEROS_AR71XX
  14798. + select PHYLIB
  14799. + help
  14800. + If you wish to compile a kernel for AR71xx/91xx and enable
  14801. + ethernet support, then you should always answer Y to this.
  14802. +
  14803. +if AG71XX
  14804. +
  14805. +config AG71XX_DEBUG
  14806. + bool "Atheros AR71xx built-in ethernet driver debugging"
  14807. + default n
  14808. + help
  14809. + Atheros AR71xx built-in ethernet driver debugging messages.
  14810. +
  14811. +config AG71XX_DEBUG_FS
  14812. + bool "Atheros AR71xx built-in ethernet driver debugfs support"
  14813. + depends on DEBUG_FS
  14814. + default n
  14815. + help
  14816. + Say Y, if you need access to various statistics provided by
  14817. + the ag71xx driver.
  14818. +
  14819. +config AG71XX_AR8216_SUPPORT
  14820. + bool "special support for the Atheros AR8216 switch"
  14821. + default n
  14822. + default y if AR71XX_MACH_WNR2000 || AR71XX_MACH_MZK_W04NU
  14823. + help
  14824. + Say 'y' here if you want to enable special support for the
  14825. + Atheros AR8216 switch found on some boards.
  14826. +
  14827. +endif
  14828. diff -Nur linux-2.6.34.orig/drivers/net/ag71xx/Makefile linux-2.6.34/drivers/net/ag71xx/Makefile
  14829. --- linux-2.6.34.orig/drivers/net/ag71xx/Makefile 1970-01-01 01:00:00.000000000 +0100
  14830. +++ linux-2.6.34/drivers/net/ag71xx/Makefile 2010-05-25 18:46:09.733464200 +0200
  14831. @@ -0,0 +1,14 @@
  14832. +#
  14833. +# Makefile for the Atheros AR71xx built-in ethernet macs
  14834. +#
  14835. +
  14836. +ag71xx-y += ag71xx_main.o
  14837. +ag71xx-y += ag71xx_ethtool.o
  14838. +ag71xx-y += ag71xx_phy.o
  14839. +ag71xx-y += ag71xx_mdio.o
  14840. +
  14841. +ag71xx-$(CONFIG_AG71XX_DEBUG_FS) += ag71xx_debugfs.o
  14842. +ag71xx-$(CONFIG_AG71XX_AR8216_SUPPORT) += ag71xx_ar8216.o
  14843. +
  14844. +obj-$(CONFIG_AG71XX) += ag71xx.o
  14845. +
  14846. diff -Nur linux-2.6.34.orig/drivers/net/Kconfig linux-2.6.34/drivers/net/Kconfig
  14847. --- linux-2.6.34.orig/drivers/net/Kconfig 2010-05-16 23:17:36.000000000 +0200
  14848. +++ linux-2.6.34/drivers/net/Kconfig 2010-05-25 18:46:09.773464179 +0200
  14849. @@ -2038,6 +2038,8 @@
  14850. The safe and default value for this is N.
  14851. +source drivers/net/ag71xx/Kconfig
  14852. +
  14853. config DL2K
  14854. tristate "DL2000/TC902x-based Gigabit Ethernet support"
  14855. depends on PCI
  14856. diff -Nur linux-2.6.34.orig/drivers/net/Makefile linux-2.6.34/drivers/net/Makefile
  14857. --- linux-2.6.34.orig/drivers/net/Makefile 2010-05-16 23:17:36.000000000 +0200
  14858. +++ linux-2.6.34/drivers/net/Makefile 2010-05-25 18:46:09.813473236 +0200
  14859. @@ -109,6 +109,7 @@
  14860. # end link order section
  14861. #
  14862. +obj-$(CONFIG_AG71XX) += ag71xx/
  14863. obj-$(CONFIG_SUNDANCE) += sundance.o
  14864. obj-$(CONFIG_HAMACHI) += hamachi.o
  14865. obj-$(CONFIG_NET) += Space.o loopback.o
  14866. diff -Nur linux-2.6.34.orig/drivers/net/phy/Kconfig linux-2.6.34/drivers/net/phy/Kconfig
  14867. --- linux-2.6.34.orig/drivers/net/phy/Kconfig 2010-05-16 23:17:36.000000000 +0200
  14868. +++ linux-2.6.34/drivers/net/phy/Kconfig 2010-05-25 18:46:09.863473083 +0200
  14869. @@ -93,6 +93,10 @@
  14870. ---help---
  14871. Supports the KSZ9021, VSC8201, KS8001 PHYs.
  14872. +config IP175C_PHY
  14873. + tristate "Driver for IC+ IP175C/IP178C switches"
  14874. + select SWCONFIG
  14875. +
  14876. config FIXED_PHY
  14877. bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
  14878. depends on PHYLIB=y
  14879. diff -Nur linux-2.6.34.orig/drivers/net/phy/phy.c linux-2.6.34/drivers/net/phy/phy.c
  14880. --- linux-2.6.34.orig/drivers/net/phy/phy.c 2010-05-16 23:17:36.000000000 +0200
  14881. +++ linux-2.6.34/drivers/net/phy/phy.c 2010-05-25 18:46:12.573473234 +0200
  14882. @@ -298,6 +298,50 @@
  14883. }
  14884. EXPORT_SYMBOL(phy_ethtool_gset);
  14885. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
  14886. +{
  14887. + u32 cmd;
  14888. + int tmp;
  14889. + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  14890. + struct ethtool_value edata = { ETHTOOL_GLINK };
  14891. +
  14892. + if (get_user(cmd, (u32 *) useraddr))
  14893. + return -EFAULT;
  14894. +
  14895. + switch (cmd) {
  14896. + case ETHTOOL_GSET:
  14897. + phy_ethtool_gset(phydev, &ecmd);
  14898. + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  14899. + return -EFAULT;
  14900. + return 0;
  14901. +
  14902. + case ETHTOOL_SSET:
  14903. + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  14904. + return -EFAULT;
  14905. + return phy_ethtool_sset(phydev, &ecmd);
  14906. +
  14907. + case ETHTOOL_NWAY_RST:
  14908. + /* if autoneg is off, it's an error */
  14909. + tmp = phy_read(phydev, MII_BMCR);
  14910. + if (tmp & BMCR_ANENABLE) {
  14911. + tmp |= (BMCR_ANRESTART);
  14912. + phy_write(phydev, MII_BMCR, tmp);
  14913. + return 0;
  14914. + }
  14915. + return -EINVAL;
  14916. +
  14917. + case ETHTOOL_GLINK:
  14918. + edata.data = (phy_read(phydev,
  14919. + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
  14920. + if (copy_to_user(useraddr, &edata, sizeof(edata)))
  14921. + return -EFAULT;
  14922. + return 0;
  14923. + }
  14924. +
  14925. + return -EOPNOTSUPP;
  14926. +}
  14927. +EXPORT_SYMBOL(phy_ethtool_ioctl);
  14928. +
  14929. /**
  14930. * phy_mii_ioctl - generic PHY MII ioctl interface
  14931. * @phydev: the phy_device struct
  14932. @@ -351,7 +395,7 @@
  14933. }
  14934. phy_write(phydev, mii_data->reg_num, val);
  14935. -
  14936. +
  14937. if (mii_data->reg_num == MII_BMCR &&
  14938. val & BMCR_RESET &&
  14939. phydev->drv->config_init) {
  14940. @@ -465,7 +509,7 @@
  14941. int idx;
  14942. idx = phy_find_setting(phydev->speed, phydev->duplex);
  14943. -
  14944. +
  14945. idx++;
  14946. idx = phy_find_valid(idx, phydev->supported);
  14947. diff -Nur linux-2.6.34.orig/drivers/net/phy/phy_device.c linux-2.6.34/drivers/net/phy/phy_device.c
  14948. --- linux-2.6.34.orig/drivers/net/phy/phy_device.c 2010-05-16 23:17:36.000000000 +0200
  14949. +++ linux-2.6.34/drivers/net/phy/phy_device.c 2010-05-25 18:46:12.660978620 +0200
  14950. @@ -146,6 +146,18 @@
  14951. }
  14952. EXPORT_SYMBOL(phy_scan_fixups);
  14953. +static int generic_receive_skb(struct sk_buff *skb)
  14954. +{
  14955. + skb->protocol = eth_type_trans(skb, skb->dev);
  14956. + return netif_receive_skb(skb);
  14957. +}
  14958. +
  14959. +static int generic_rx(struct sk_buff *skb)
  14960. +{
  14961. + skb->protocol = eth_type_trans(skb, skb->dev);
  14962. + return netif_rx(skb);
  14963. +}
  14964. +
  14965. struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
  14966. {
  14967. struct phy_device *dev;
  14968. @@ -175,6 +187,8 @@
  14969. dev_set_name(&dev->dev, PHY_ID_FMT, bus->id, addr);
  14970. dev->state = PHY_DOWN;
  14971. + dev->netif_receive_skb = &generic_receive_skb;
  14972. + dev->netif_rx = &generic_rx;
  14973. mutex_init(&dev->lock);
  14974. INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
  14975. diff -Nur linux-2.6.34.orig/drivers/spi/ap83_spi.c linux-2.6.34/drivers/spi/ap83_spi.c
  14976. --- linux-2.6.34.orig/drivers/spi/ap83_spi.c 1970-01-01 01:00:00.000000000 +0100
  14977. +++ linux-2.6.34/drivers/spi/ap83_spi.c 2010-05-25 18:46:12.703464112 +0200
  14978. @@ -0,0 +1,282 @@
  14979. +/*
  14980. + * Atheros AP83 board specific SPI Controller driver
  14981. + *
  14982. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  14983. + *
  14984. + * This program is free software; you can redistribute it and/or modify
  14985. + * it under the terms of the GNU General Public License version 2 as
  14986. + * published by the Free Software Foundation.
  14987. + *
  14988. + */
  14989. +
  14990. +#include <linux/kernel.h>
  14991. +#include <linux/init.h>
  14992. +#include <linux/delay.h>
  14993. +#include <linux/spinlock.h>
  14994. +#include <linux/workqueue.h>
  14995. +#include <linux/platform_device.h>
  14996. +#include <linux/io.h>
  14997. +#include <linux/spi/spi.h>
  14998. +#include <linux/spi/spi_bitbang.h>
  14999. +#include <linux/bitops.h>
  15000. +#include <linux/gpio.h>
  15001. +
  15002. +#include <asm/mach-ar71xx/ar71xx.h>
  15003. +#include <asm/mach-ar71xx/platform.h>
  15004. +
  15005. +#define DRV_DESC "Atheros AP83 board SPI Controller driver"
  15006. +#define DRV_VERSION "0.1.0"
  15007. +#define DRV_NAME "ap83-spi"
  15008. +
  15009. +#define AP83_SPI_CLK_HIGH (1 << 23)
  15010. +#define AP83_SPI_CLK_LOW 0
  15011. +#define AP83_SPI_MOSI_HIGH (1 << 22)
  15012. +#define AP83_SPI_MOSI_LOW 0
  15013. +
  15014. +#define AP83_SPI_GPIO_CS 1
  15015. +#define AP83_SPI_GPIO_MISO 3
  15016. +
  15017. +struct ap83_spi {
  15018. + struct spi_bitbang bitbang;
  15019. + void __iomem *base;
  15020. + u32 addr;
  15021. +
  15022. + struct platform_device *pdev;
  15023. +};
  15024. +
  15025. +static inline u32 ap83_spi_rr(struct ap83_spi *sp, u32 reg)
  15026. +{
  15027. + return __raw_readl(sp->base + reg);
  15028. +}
  15029. +
  15030. +static inline struct ap83_spi *spidev_to_sp(struct spi_device *spi)
  15031. +{
  15032. + return spi_master_get_devdata(spi->master);
  15033. +}
  15034. +
  15035. +static inline void setsck(struct spi_device *spi, int val)
  15036. +{
  15037. + struct ap83_spi *sp = spidev_to_sp(spi);
  15038. +
  15039. + if (val)
  15040. + sp->addr |= AP83_SPI_CLK_HIGH;
  15041. + else
  15042. + sp->addr &= ~AP83_SPI_CLK_HIGH;
  15043. +
  15044. + dev_dbg(&spi->dev, "addr=%08x, SCK set to %s\n",
  15045. + sp->addr, (val) ? "HIGH" : "LOW");
  15046. +
  15047. + ap83_spi_rr(sp, sp->addr);
  15048. +}
  15049. +
  15050. +static inline void setmosi(struct spi_device *spi, int val)
  15051. +{
  15052. + struct ap83_spi *sp = spidev_to_sp(spi);
  15053. +
  15054. + if (val)
  15055. + sp->addr |= AP83_SPI_MOSI_HIGH;
  15056. + else
  15057. + sp->addr &= ~AP83_SPI_MOSI_HIGH;
  15058. +
  15059. + dev_dbg(&spi->dev, "addr=%08x, MOSI set to %s\n",
  15060. + sp->addr, (val) ? "HIGH" : "LOW");
  15061. +
  15062. + ap83_spi_rr(sp, sp->addr);
  15063. +}
  15064. +
  15065. +static inline u32 getmiso(struct spi_device *spi)
  15066. +{
  15067. + u32 ret;
  15068. +
  15069. + ret = gpio_get_value(AP83_SPI_GPIO_MISO) ? 1 : 0;
  15070. + dev_dbg(&spi->dev, "get MISO: %d\n", ret);
  15071. +
  15072. + return ret;
  15073. +}
  15074. +
  15075. +static inline void do_spidelay(struct spi_device *spi, unsigned nsecs)
  15076. +{
  15077. + ndelay(nsecs);
  15078. +}
  15079. +
  15080. +static void ap83_spi_chipselect(struct spi_device *spi, int on)
  15081. +{
  15082. + struct ap83_spi *sp = spidev_to_sp(spi);
  15083. +
  15084. + dev_dbg(&spi->dev, "set CS to %d\n", (on) ? 0 : 1);
  15085. +
  15086. + if (on) {
  15087. + ar71xx_flash_acquire();
  15088. +
  15089. + sp->addr = 0;
  15090. + ap83_spi_rr(sp, sp->addr);
  15091. +
  15092. + gpio_set_value(AP83_SPI_GPIO_CS, 0);
  15093. + } else {
  15094. + gpio_set_value(AP83_SPI_GPIO_CS, 1);
  15095. + ar71xx_flash_release();
  15096. + }
  15097. +}
  15098. +
  15099. +#define spidelay(nsecs) \
  15100. + do { \
  15101. + /* Steal the spi_device pointer from our caller. \
  15102. + * The bitbang-API should probably get fixed here... */ \
  15103. + do_spidelay(spi, nsecs); \
  15104. + } while (0)
  15105. +
  15106. +#define EXPAND_BITBANG_TXRX
  15107. +#include <linux/spi/spi_bitbang.h>
  15108. +
  15109. +static u32 ap83_spi_txrx_mode0(struct spi_device *spi,
  15110. + unsigned nsecs, u32 word, u8 bits)
  15111. +{
  15112. + dev_dbg(&spi->dev, "TXRX0 word=%08x, bits=%u\n", word, bits);
  15113. + return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  15114. +}
  15115. +
  15116. +static u32 ap83_spi_txrx_mode1(struct spi_device *spi,
  15117. + unsigned nsecs, u32 word, u8 bits)
  15118. +{
  15119. + dev_dbg(&spi->dev, "TXRX1 word=%08x, bits=%u\n", word, bits);
  15120. + return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
  15121. +}
  15122. +
  15123. +static u32 ap83_spi_txrx_mode2(struct spi_device *spi,
  15124. + unsigned nsecs, u32 word, u8 bits)
  15125. +{
  15126. + dev_dbg(&spi->dev, "TXRX2 word=%08x, bits=%u\n", word, bits);
  15127. + return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
  15128. +}
  15129. +
  15130. +static u32 ap83_spi_txrx_mode3(struct spi_device *spi,
  15131. + unsigned nsecs, u32 word, u8 bits)
  15132. +{
  15133. + dev_dbg(&spi->dev, "TXRX3 word=%08x, bits=%u\n", word, bits);
  15134. + return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
  15135. +}
  15136. +
  15137. +static int ap83_spi_probe(struct platform_device *pdev)
  15138. +{
  15139. + struct spi_master *master;
  15140. + struct ap83_spi *sp;
  15141. + struct ap83_spi_platform_data *pdata;
  15142. + struct resource *r;
  15143. + int ret;
  15144. +
  15145. + ret = gpio_request(AP83_SPI_GPIO_MISO, "spi-miso");
  15146. + if (ret) {
  15147. + dev_err(&pdev->dev, "gpio request failed for MISO\n");
  15148. + return ret;
  15149. + }
  15150. +
  15151. + ret = gpio_request(AP83_SPI_GPIO_CS, "spi-cs");
  15152. + if (ret) {
  15153. + dev_err(&pdev->dev, "gpio request failed for CS\n");
  15154. + goto err_free_miso;
  15155. + }
  15156. +
  15157. + ret = gpio_direction_input(AP83_SPI_GPIO_MISO);
  15158. + if (ret) {
  15159. + dev_err(&pdev->dev, "unable to set direction of MISO\n");
  15160. + goto err_free_cs;
  15161. + }
  15162. +
  15163. + ret = gpio_direction_output(AP83_SPI_GPIO_CS, 0);
  15164. + if (ret) {
  15165. + dev_err(&pdev->dev, "unable to set direction of CS\n");
  15166. + goto err_free_cs;
  15167. + }
  15168. +
  15169. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15170. + if (master == NULL) {
  15171. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15172. + return -ENOMEM;
  15173. + }
  15174. +
  15175. + sp = spi_master_get_devdata(master);
  15176. + platform_set_drvdata(pdev, sp);
  15177. +
  15178. + pdata = pdev->dev.platform_data;
  15179. +
  15180. + sp->bitbang.master = spi_master_get(master);
  15181. + sp->bitbang.chipselect = ap83_spi_chipselect;
  15182. + sp->bitbang.txrx_word[SPI_MODE_0] = ap83_spi_txrx_mode0;
  15183. + sp->bitbang.txrx_word[SPI_MODE_1] = ap83_spi_txrx_mode1;
  15184. + sp->bitbang.txrx_word[SPI_MODE_2] = ap83_spi_txrx_mode2;
  15185. + sp->bitbang.txrx_word[SPI_MODE_3] = ap83_spi_txrx_mode3;
  15186. +
  15187. + sp->bitbang.master->bus_num = pdev->id;
  15188. + sp->bitbang.master->num_chipselect = 1;
  15189. +
  15190. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15191. + if (r == NULL) {
  15192. + ret = -ENOENT;
  15193. + goto err_spi_put;
  15194. + }
  15195. +
  15196. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15197. + if (!sp->base) {
  15198. + ret = -ENXIO;
  15199. + goto err_spi_put;
  15200. + }
  15201. +
  15202. + ret = spi_bitbang_start(&sp->bitbang);
  15203. + if (!ret)
  15204. + goto err_unmap;
  15205. +
  15206. + dev_info(&pdev->dev, "AP83 SPI adapter at %08x\n", r->start);
  15207. +
  15208. + return 0;
  15209. +
  15210. + err_unmap:
  15211. + iounmap(sp->base);
  15212. + err_spi_put:
  15213. + platform_set_drvdata(pdev, NULL);
  15214. + spi_master_put(sp->bitbang.master);
  15215. +
  15216. + err_free_cs:
  15217. + gpio_free(AP83_SPI_GPIO_CS);
  15218. + err_free_miso:
  15219. + gpio_free(AP83_SPI_GPIO_MISO);
  15220. + return ret;
  15221. +}
  15222. +
  15223. +static int ap83_spi_remove(struct platform_device *pdev)
  15224. +{
  15225. + struct ap83_spi *sp = platform_get_drvdata(pdev);
  15226. +
  15227. + spi_bitbang_stop(&sp->bitbang);
  15228. + iounmap(sp->base);
  15229. + platform_set_drvdata(pdev, NULL);
  15230. + spi_master_put(sp->bitbang.master);
  15231. +
  15232. + return 0;
  15233. +}
  15234. +
  15235. +static struct platform_driver ap83_spi_drv = {
  15236. + .probe = ap83_spi_probe,
  15237. + .remove = ap83_spi_remove,
  15238. + .driver = {
  15239. + .name = DRV_NAME,
  15240. + .owner = THIS_MODULE,
  15241. + },
  15242. +};
  15243. +
  15244. +static int __init ap83_spi_init(void)
  15245. +{
  15246. + return platform_driver_register(&ap83_spi_drv);
  15247. +}
  15248. +module_init(ap83_spi_init);
  15249. +
  15250. +static void __exit ap83_spi_exit(void)
  15251. +{
  15252. + platform_driver_unregister(&ap83_spi_drv);
  15253. +}
  15254. +module_exit(ap83_spi_exit);
  15255. +
  15256. +MODULE_ALIAS("platform:" DRV_NAME);
  15257. +MODULE_DESCRIPTION(DRV_DESC);
  15258. +MODULE_VERSION(DRV_VERSION);
  15259. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15260. +MODULE_LICENSE("GPL v2");
  15261. diff -Nur linux-2.6.34.orig/drivers/spi/ar71xx_spi.c linux-2.6.34/drivers/spi/ar71xx_spi.c
  15262. --- linux-2.6.34.orig/drivers/spi/ar71xx_spi.c 1970-01-01 01:00:00.000000000 +0100
  15263. +++ linux-2.6.34/drivers/spi/ar71xx_spi.c 2010-05-25 18:46:12.743464042 +0200
  15264. @@ -0,0 +1,283 @@
  15265. +/*
  15266. + * Atheros AR71xx SPI Controller driver
  15267. + *
  15268. + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  15269. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  15270. + *
  15271. + * This program is free software; you can redistribute it and/or modify
  15272. + * it under the terms of the GNU General Public License version 2 as
  15273. + * published by the Free Software Foundation.
  15274. + *
  15275. + */
  15276. +
  15277. +#include <linux/kernel.h>
  15278. +#include <linux/init.h>
  15279. +#include <linux/delay.h>
  15280. +#include <linux/spinlock.h>
  15281. +#include <linux/workqueue.h>
  15282. +#include <linux/platform_device.h>
  15283. +#include <linux/io.h>
  15284. +#include <linux/spi/spi.h>
  15285. +#include <linux/spi/spi_bitbang.h>
  15286. +#include <linux/bitops.h>
  15287. +
  15288. +#include <asm/mach-ar71xx/ar71xx.h>
  15289. +#include <asm/mach-ar71xx/platform.h>
  15290. +
  15291. +#define DRV_DESC "Atheros AR71xx SPI Controller driver"
  15292. +#define DRV_VERSION "0.2.4"
  15293. +#define DRV_NAME "ar71xx-spi"
  15294. +
  15295. +#undef PER_BIT_READ
  15296. +
  15297. +struct ar71xx_spi {
  15298. + struct spi_bitbang bitbang;
  15299. + u32 ioc_base;
  15300. + u32 reg_ctrl;
  15301. +
  15302. + void __iomem *base;
  15303. +
  15304. + struct platform_device *pdev;
  15305. + u32 (*get_ioc_base)(u8 chip_select, int cs_high,
  15306. + int is_on);
  15307. +};
  15308. +
  15309. +static inline u32 ar71xx_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  15310. +{
  15311. + return __raw_readl(sp->base + reg);
  15312. +}
  15313. +
  15314. +static inline void ar71xx_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  15315. +{
  15316. + __raw_writel(val, sp->base + reg);
  15317. +}
  15318. +
  15319. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  15320. +{
  15321. + return spi_master_get_devdata(spi->master);
  15322. +}
  15323. +
  15324. +static u32 ar71xx_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
  15325. +{
  15326. + u32 ret;
  15327. +
  15328. + if (is_on == AR71XX_SPI_CS_INACTIVE)
  15329. + ret = SPI_IOC_CS_ALL;
  15330. + else
  15331. + ret = SPI_IOC_CS_ALL & ~SPI_IOC_CS(chip_select);
  15332. +
  15333. + return ret;
  15334. +}
  15335. +
  15336. +static void ar71xx_spi_chipselect(struct spi_device *spi, int value)
  15337. +{
  15338. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15339. + void __iomem *base = sp->base;
  15340. + u32 ioc_base;
  15341. +
  15342. + switch (value) {
  15343. + case BITBANG_CS_INACTIVE:
  15344. + ioc_base = sp->get_ioc_base(spi->chip_select,
  15345. + (spi->mode & SPI_CS_HIGH) != 0,
  15346. + AR71XX_SPI_CS_INACTIVE);
  15347. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  15348. + break;
  15349. +
  15350. + case BITBANG_CS_ACTIVE:
  15351. + ioc_base = sp->get_ioc_base(spi->chip_select,
  15352. + (spi->mode & SPI_CS_HIGH) != 0,
  15353. + AR71XX_SPI_CS_ACTIVE);
  15354. +
  15355. + __raw_writel(ioc_base, base + SPI_REG_IOC);
  15356. + sp->ioc_base = ioc_base;
  15357. + break;
  15358. + }
  15359. +}
  15360. +
  15361. +static void ar71xx_spi_setup_regs(struct spi_device *spi)
  15362. +{
  15363. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15364. +
  15365. + /* enable GPIO mode */
  15366. + ar71xx_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  15367. +
  15368. + /* save CTRL register */
  15369. + sp->reg_ctrl = ar71xx_spi_rr(sp, SPI_REG_CTRL);
  15370. +
  15371. + /* TODO: setup speed? */
  15372. + ar71xx_spi_wr(sp, SPI_REG_CTRL, 0x43);
  15373. +}
  15374. +
  15375. +static void ar71xx_spi_restore_regs(struct spi_device *spi)
  15376. +{
  15377. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15378. +
  15379. + /* restore CTRL register */
  15380. + ar71xx_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  15381. + /* disable GPIO mode */
  15382. + ar71xx_spi_wr(sp, SPI_REG_FS, 0);
  15383. +}
  15384. +
  15385. +static int ar71xx_spi_setup(struct spi_device *spi)
  15386. +{
  15387. + int status;
  15388. +
  15389. + if (spi->bits_per_word > 32)
  15390. + return -EINVAL;
  15391. +
  15392. + if (!spi->controller_state)
  15393. + ar71xx_spi_setup_regs(spi);
  15394. +
  15395. + status = spi_bitbang_setup(spi);
  15396. + if (status && !spi->controller_state)
  15397. + ar71xx_spi_restore_regs(spi);
  15398. +
  15399. + return status;
  15400. +}
  15401. +
  15402. +static void ar71xx_spi_cleanup(struct spi_device *spi)
  15403. +{
  15404. + ar71xx_spi_restore_regs(spi);
  15405. + spi_bitbang_cleanup(spi);
  15406. +}
  15407. +
  15408. +static u32 ar71xx_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  15409. + u32 word, u8 bits)
  15410. +{
  15411. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15412. + void __iomem *base = sp->base;
  15413. + u32 ioc = sp->ioc_base;
  15414. + u32 ret;
  15415. +
  15416. + /* clock starts at inactive polarity */
  15417. + for (word <<= (32 - bits); likely(bits); bits--) {
  15418. + u32 out;
  15419. +
  15420. + if (word & (1 << 31))
  15421. + out = ioc | SPI_IOC_DO;
  15422. + else
  15423. + out = ioc & ~SPI_IOC_DO;
  15424. +
  15425. + /* setup MSB (to slave) on trailing edge */
  15426. + __raw_writel(out, base + SPI_REG_IOC);
  15427. +
  15428. + __raw_writel(out | SPI_IOC_CLK, base + SPI_REG_IOC);
  15429. +
  15430. + word <<= 1;
  15431. +
  15432. +#ifdef PER_BIT_READ
  15433. + /* sample MSB (from slave) on leading edge */
  15434. + ret = __raw_readl(base + SPI_REG_RDS);
  15435. + __raw_writel(out, base + SPI_REG_IOC);
  15436. +#endif
  15437. +
  15438. + }
  15439. +
  15440. +#ifndef PER_BIT_READ
  15441. + ret = __raw_readl(base + SPI_REG_RDS);
  15442. +#endif
  15443. + return ret;
  15444. +}
  15445. +
  15446. +static int ar71xx_spi_probe(struct platform_device *pdev)
  15447. +{
  15448. + struct spi_master *master;
  15449. + struct ar71xx_spi *sp;
  15450. + struct ar71xx_spi_platform_data *pdata;
  15451. + struct resource *r;
  15452. + int ret;
  15453. +
  15454. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15455. + if (master == NULL) {
  15456. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15457. + return -ENOMEM;
  15458. + }
  15459. +
  15460. + sp = spi_master_get_devdata(master);
  15461. + platform_set_drvdata(pdev, sp);
  15462. +
  15463. + pdata = pdev->dev.platform_data;
  15464. +
  15465. + master->setup = ar71xx_spi_setup;
  15466. + master->cleanup = ar71xx_spi_cleanup;
  15467. +
  15468. + sp->bitbang.master = spi_master_get(master);
  15469. + sp->bitbang.chipselect = ar71xx_spi_chipselect;
  15470. + sp->bitbang.txrx_word[SPI_MODE_0] = ar71xx_spi_txrx_mode0;
  15471. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  15472. +
  15473. + sp->get_ioc_base = ar71xx_spi_get_ioc_base;
  15474. + if (pdata) {
  15475. + sp->bitbang.master->bus_num = pdata->bus_num;
  15476. + sp->bitbang.master->num_chipselect = pdata->num_chipselect;
  15477. + if (pdata->get_ioc_base)
  15478. + sp->get_ioc_base = pdata->get_ioc_base;
  15479. + } else {
  15480. + sp->bitbang.master->bus_num = 0;
  15481. + sp->bitbang.master->num_chipselect = 3;
  15482. + }
  15483. +
  15484. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15485. + if (r == NULL) {
  15486. + ret = -ENOENT;
  15487. + goto err1;
  15488. + }
  15489. +
  15490. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15491. + if (!sp->base) {
  15492. + ret = -ENXIO;
  15493. + goto err1;
  15494. + }
  15495. +
  15496. + ret = spi_bitbang_start(&sp->bitbang);
  15497. + if (!ret)
  15498. + return 0;
  15499. +
  15500. + iounmap(sp->base);
  15501. + err1:
  15502. + platform_set_drvdata(pdev, NULL);
  15503. + spi_master_put(sp->bitbang.master);
  15504. +
  15505. + return ret;
  15506. +}
  15507. +
  15508. +static int ar71xx_spi_remove(struct platform_device *pdev)
  15509. +{
  15510. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  15511. +
  15512. + spi_bitbang_stop(&sp->bitbang);
  15513. + iounmap(sp->base);
  15514. + platform_set_drvdata(pdev, NULL);
  15515. + spi_master_put(sp->bitbang.master);
  15516. +
  15517. + return 0;
  15518. +}
  15519. +
  15520. +static struct platform_driver ar71xx_spi_drv = {
  15521. + .probe = ar71xx_spi_probe,
  15522. + .remove = ar71xx_spi_remove,
  15523. + .driver = {
  15524. + .name = DRV_NAME,
  15525. + .owner = THIS_MODULE,
  15526. + },
  15527. +};
  15528. +
  15529. +static int __init ar71xx_spi_init(void)
  15530. +{
  15531. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  15532. + return platform_driver_register(&ar71xx_spi_drv);
  15533. +}
  15534. +module_init(ar71xx_spi_init);
  15535. +
  15536. +static void __exit ar71xx_spi_exit(void)
  15537. +{
  15538. + platform_driver_unregister(&ar71xx_spi_drv);
  15539. +}
  15540. +module_exit(ar71xx_spi_exit);
  15541. +
  15542. +MODULE_ALIAS("platform:" DRV_NAME);
  15543. +MODULE_DESCRIPTION(DRV_DESC);
  15544. +MODULE_VERSION(DRV_VERSION);
  15545. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15546. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
  15547. +MODULE_LICENSE("GPL v2");
  15548. diff -Nur linux-2.6.34.orig/drivers/spi/Kconfig linux-2.6.34/drivers/spi/Kconfig
  15549. --- linux-2.6.34.orig/drivers/spi/Kconfig 2010-05-16 23:17:36.000000000 +0200
  15550. +++ linux-2.6.34/drivers/spi/Kconfig 2010-05-25 18:46:12.800978217 +0200
  15551. @@ -53,6 +53,13 @@
  15552. comment "SPI Master Controller Drivers"
  15553. +config SPI_AR71XX
  15554. + tristate "Atheros AR71xx SPI Controller"
  15555. + depends on SPI_MASTER && ATHEROS_AR71XX
  15556. + select SPI_BITBANG
  15557. + help
  15558. + This is the SPI contoller driver for Atheros AR71xx.
  15559. +
  15560. config SPI_ATMEL
  15561. tristate "Atmel SPI Controller"
  15562. depends on (ARCH_AT91 || AVR32)
  15563. diff -Nur linux-2.6.34.orig/drivers/spi/Makefile linux-2.6.34/drivers/spi/Makefile
  15564. --- linux-2.6.34.orig/drivers/spi/Makefile 2010-05-16 23:17:36.000000000 +0200
  15565. +++ linux-2.6.34/drivers/spi/Makefile 2010-05-25 18:46:12.843464070 +0200
  15566. @@ -11,6 +11,7 @@
  15567. obj-$(CONFIG_SPI_MASTER) += spi.o
  15568. # SPI master controller drivers (bus)
  15569. +obj-$(CONFIG_SPI_AR71XX) += ar71xx_spi.o
  15570. obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o
  15571. obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
  15572. obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
  15573. diff -Nur linux-2.6.34.orig/drivers/spi/pb44_spi.c linux-2.6.34/drivers/spi/pb44_spi.c
  15574. --- linux-2.6.34.orig/drivers/spi/pb44_spi.c 1970-01-01 01:00:00.000000000 +0100
  15575. +++ linux-2.6.34/drivers/spi/pb44_spi.c 2010-05-25 18:46:12.882113964 +0200
  15576. @@ -0,0 +1,299 @@
  15577. +/*
  15578. + * Atheros PB44 board SPI controller driver
  15579. + *
  15580. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  15581. + *
  15582. + * This program is free software; you can redistribute it and/or modify
  15583. + * it under the terms of the GNU General Public License version 2 as
  15584. + * published by the Free Software Foundation.
  15585. + *
  15586. + */
  15587. +
  15588. +#include <linux/kernel.h>
  15589. +#include <linux/init.h>
  15590. +#include <linux/delay.h>
  15591. +#include <linux/spinlock.h>
  15592. +#include <linux/workqueue.h>
  15593. +#include <linux/platform_device.h>
  15594. +#include <linux/io.h>
  15595. +#include <linux/spi/spi.h>
  15596. +#include <linux/spi/spi_bitbang.h>
  15597. +#include <linux/bitops.h>
  15598. +#include <linux/gpio.h>
  15599. +
  15600. +#include <asm/mach-ar71xx/ar71xx.h>
  15601. +#include <asm/mach-ar71xx/platform.h>
  15602. +
  15603. +#define DRV_DESC "Atheros PB44 SPI Controller driver"
  15604. +#define DRV_VERSION "0.1.0"
  15605. +#define DRV_NAME "pb44-spi"
  15606. +
  15607. +#undef PER_BIT_READ
  15608. +
  15609. +struct ar71xx_spi {
  15610. + struct spi_bitbang bitbang;
  15611. + u32 ioc_base;
  15612. + u32 reg_ctrl;
  15613. +
  15614. + void __iomem *base;
  15615. +
  15616. + struct platform_device *pdev;
  15617. +};
  15618. +
  15619. +static inline u32 pb44_spi_rr(struct ar71xx_spi *sp, unsigned reg)
  15620. +{
  15621. + return __raw_readl(sp->base + reg);
  15622. +}
  15623. +
  15624. +static inline void pb44_spi_wr(struct ar71xx_spi *sp, unsigned reg, u32 val)
  15625. +{
  15626. + __raw_writel(val, sp->base + reg);
  15627. +}
  15628. +
  15629. +static inline struct ar71xx_spi *spidev_to_sp(struct spi_device *spi)
  15630. +{
  15631. + return spi_master_get_devdata(spi->master);
  15632. +}
  15633. +
  15634. +static void pb44_spi_chipselect(struct spi_device *spi, int is_active)
  15635. +{
  15636. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15637. + int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
  15638. +
  15639. + if (is_active) {
  15640. + /* set initial clock polarity */
  15641. + if (spi->mode & SPI_CPOL)
  15642. + sp->ioc_base |= SPI_IOC_CLK;
  15643. + else
  15644. + sp->ioc_base &= ~SPI_IOC_CLK;
  15645. +
  15646. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15647. + }
  15648. +
  15649. + if (spi->chip_select) {
  15650. + unsigned long gpio = (unsigned long) spi->controller_data;
  15651. +
  15652. + /* SPI is normally active-low */
  15653. + gpio_set_value(gpio, cs_high);
  15654. + } else {
  15655. + if (cs_high)
  15656. + sp->ioc_base |= SPI_IOC_CS0;
  15657. + else
  15658. + sp->ioc_base &= ~SPI_IOC_CS0;
  15659. +
  15660. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15661. + }
  15662. +
  15663. +}
  15664. +
  15665. +static int pb44_spi_setup_cs(struct spi_device *spi)
  15666. +{
  15667. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15668. +
  15669. + /* enable GPIO mode */
  15670. + pb44_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
  15671. +
  15672. + /* save CTRL register */
  15673. + sp->reg_ctrl = pb44_spi_rr(sp, SPI_REG_CTRL);
  15674. + sp->ioc_base = pb44_spi_rr(sp, SPI_REG_IOC);
  15675. +
  15676. + /* TODO: setup speed? */
  15677. + pb44_spi_wr(sp, SPI_REG_CTRL, 0x43);
  15678. +
  15679. + if (spi->chip_select) {
  15680. + unsigned long gpio = (unsigned long) spi->controller_data;
  15681. + int status = 0;
  15682. +
  15683. + status = gpio_request(gpio, dev_name(&spi->dev));
  15684. + if (status)
  15685. + return status;
  15686. +
  15687. + status = gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH);
  15688. + if (status) {
  15689. + gpio_free(gpio);
  15690. + return status;
  15691. + }
  15692. + } else {
  15693. + if (spi->mode & SPI_CS_HIGH)
  15694. + sp->ioc_base |= SPI_IOC_CS0;
  15695. + else
  15696. + sp->ioc_base &= ~SPI_IOC_CS0;
  15697. + pb44_spi_wr(sp, SPI_REG_IOC, sp->ioc_base);
  15698. + }
  15699. +
  15700. + return 0;
  15701. +}
  15702. +
  15703. +static void pb44_spi_cleanup_cs(struct spi_device *spi)
  15704. +{
  15705. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15706. +
  15707. + if (spi->chip_select) {
  15708. + unsigned long gpio = (unsigned long) spi->controller_data;
  15709. + gpio_free(gpio);
  15710. + }
  15711. +
  15712. + /* restore CTRL register */
  15713. + pb44_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
  15714. + /* disable GPIO mode */
  15715. + pb44_spi_wr(sp, SPI_REG_FS, 0);
  15716. +}
  15717. +
  15718. +static int pb44_spi_setup(struct spi_device *spi)
  15719. +{
  15720. + int status = 0;
  15721. +
  15722. + if (spi->bits_per_word > 32)
  15723. + return -EINVAL;
  15724. +
  15725. + if (!spi->controller_state) {
  15726. + status = pb44_spi_setup_cs(spi);
  15727. + if (status)
  15728. + return status;
  15729. + }
  15730. +
  15731. + status = spi_bitbang_setup(spi);
  15732. + if (status && !spi->controller_state)
  15733. + pb44_spi_cleanup_cs(spi);
  15734. +
  15735. + return status;
  15736. +}
  15737. +
  15738. +static void pb44_spi_cleanup(struct spi_device *spi)
  15739. +{
  15740. + pb44_spi_cleanup_cs(spi);
  15741. + spi_bitbang_cleanup(spi);
  15742. +}
  15743. +
  15744. +static u32 pb44_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
  15745. + u32 word, u8 bits)
  15746. +{
  15747. + struct ar71xx_spi *sp = spidev_to_sp(spi);
  15748. + u32 ioc = sp->ioc_base;
  15749. + u32 ret;
  15750. +
  15751. + /* clock starts at inactive polarity */
  15752. + for (word <<= (32 - bits); likely(bits); bits--) {
  15753. + u32 out;
  15754. +
  15755. + if (word & (1 << 31))
  15756. + out = ioc | SPI_IOC_DO;
  15757. + else
  15758. + out = ioc & ~SPI_IOC_DO;
  15759. +
  15760. + /* setup MSB (to slave) on trailing edge */
  15761. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  15762. + pb44_spi_wr(sp, SPI_REG_IOC, out | SPI_IOC_CLK);
  15763. +
  15764. + word <<= 1;
  15765. +
  15766. +#ifdef PER_BIT_READ
  15767. + /* sample MSB (from slave) on leading edge */
  15768. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  15769. + pb44_spi_wr(sp, SPI_REG_IOC, out);
  15770. +#endif
  15771. + }
  15772. +
  15773. +#ifndef PER_BIT_READ
  15774. + ret = pb44_spi_rr(sp, SPI_REG_RDS);
  15775. +#endif
  15776. + return ret;
  15777. +}
  15778. +
  15779. +static int pb44_spi_probe(struct platform_device *pdev)
  15780. +{
  15781. + struct spi_master *master;
  15782. + struct ar71xx_spi *sp;
  15783. + struct ar71xx_spi_platform_data *pdata;
  15784. + struct resource *r;
  15785. + int ret;
  15786. +
  15787. + master = spi_alloc_master(&pdev->dev, sizeof(*sp));
  15788. + if (master == NULL) {
  15789. + dev_err(&pdev->dev, "failed to allocate spi master\n");
  15790. + return -ENOMEM;
  15791. + }
  15792. +
  15793. + sp = spi_master_get_devdata(master);
  15794. + platform_set_drvdata(pdev, sp);
  15795. +
  15796. + pdata = pdev->dev.platform_data;
  15797. +
  15798. + master->setup = pb44_spi_setup;
  15799. + master->cleanup = pb44_spi_cleanup;
  15800. + if (pdata) {
  15801. + master->bus_num = pdata->bus_num;
  15802. + master->num_chipselect = pdata->num_chipselect;
  15803. + } else {
  15804. + master->bus_num = 0;
  15805. + master->num_chipselect = 1;
  15806. + }
  15807. +
  15808. + sp->bitbang.master = spi_master_get(master);
  15809. + sp->bitbang.chipselect = pb44_spi_chipselect;
  15810. + sp->bitbang.txrx_word[SPI_MODE_0] = pb44_spi_txrx_mode0;
  15811. + sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
  15812. + sp->bitbang.flags = SPI_CS_HIGH;
  15813. +
  15814. + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  15815. + if (r == NULL) {
  15816. + ret = -ENOENT;
  15817. + goto err1;
  15818. + }
  15819. +
  15820. + sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
  15821. + if (!sp->base) {
  15822. + ret = -ENXIO;
  15823. + goto err1;
  15824. + }
  15825. +
  15826. + ret = spi_bitbang_start(&sp->bitbang);
  15827. + if (!ret)
  15828. + return 0;
  15829. +
  15830. + iounmap(sp->base);
  15831. + err1:
  15832. + platform_set_drvdata(pdev, NULL);
  15833. + spi_master_put(sp->bitbang.master);
  15834. +
  15835. + return ret;
  15836. +}
  15837. +
  15838. +static int pb44_spi_remove(struct platform_device *pdev)
  15839. +{
  15840. + struct ar71xx_spi *sp = platform_get_drvdata(pdev);
  15841. +
  15842. + spi_bitbang_stop(&sp->bitbang);
  15843. + iounmap(sp->base);
  15844. + platform_set_drvdata(pdev, NULL);
  15845. + spi_master_put(sp->bitbang.master);
  15846. +
  15847. + return 0;
  15848. +}
  15849. +
  15850. +static struct platform_driver pb44_spi_drv = {
  15851. + .probe = pb44_spi_probe,
  15852. + .remove = pb44_spi_remove,
  15853. + .driver = {
  15854. + .name = DRV_NAME,
  15855. + .owner = THIS_MODULE,
  15856. + },
  15857. +};
  15858. +
  15859. +static int __init pb44_spi_init(void)
  15860. +{
  15861. + return platform_driver_register(&pb44_spi_drv);
  15862. +}
  15863. +module_init(pb44_spi_init);
  15864. +
  15865. +static void __exit pb44_spi_exit(void)
  15866. +{
  15867. + platform_driver_unregister(&pb44_spi_drv);
  15868. +}
  15869. +module_exit(pb44_spi_exit);
  15870. +
  15871. +MODULE_ALIAS("platform:" DRV_NAME);
  15872. +MODULE_DESCRIPTION(DRV_DESC);
  15873. +MODULE_VERSION(DRV_VERSION);
  15874. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  15875. +MODULE_LICENSE("GPL v2");
  15876. diff -Nur linux-2.6.34.orig/drivers/spi/spi_vsc7385.c linux-2.6.34/drivers/spi/spi_vsc7385.c
  15877. --- linux-2.6.34.orig/drivers/spi/spi_vsc7385.c 1970-01-01 01:00:00.000000000 +0100
  15878. +++ linux-2.6.34/drivers/spi/spi_vsc7385.c 2010-05-25 18:46:12.923471407 +0200
  15879. @@ -0,0 +1,620 @@
  15880. +/*
  15881. + * SPI driver for the Vitesse VSC7385 ethernet switch
  15882. + *
  15883. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  15884. + *
  15885. + * Parts of this file are based on Atheros' 2.6.15 BSP
  15886. + *
  15887. + * This program is free software; you can redistribute it and/or modify it
  15888. + * under the terms of the GNU General Public License version 2 as published
  15889. + * by the Free Software Foundation.
  15890. + */
  15891. +
  15892. +#include <linux/types.h>
  15893. +#include <linux/kernel.h>
  15894. +#include <linux/init.h>
  15895. +#include <linux/module.h>
  15896. +#include <linux/delay.h>
  15897. +#include <linux/device.h>
  15898. +#include <linux/bitops.h>
  15899. +#include <linux/firmware.h>
  15900. +#include <linux/spi/spi.h>
  15901. +#include <linux/spi/vsc7385.h>
  15902. +
  15903. +#define DRV_NAME "spi-vsc7385"
  15904. +#define DRV_DESC "Vitesse VSC7385 Gbit ethernet switch driver"
  15905. +#define DRV_VERSION "0.1.0"
  15906. +
  15907. +#define VSC73XX_BLOCK_MAC 0x1
  15908. +#define VSC73XX_BLOCK_2 0x2
  15909. +#define VSC73XX_BLOCK_MII 0x3
  15910. +#define VSC73XX_BLOCK_4 0x4
  15911. +#define VSC73XX_BLOCK_5 0x5
  15912. +#define VSC73XX_BLOCK_SYSTEM 0x7
  15913. +
  15914. +#define VSC73XX_SUBBLOCK_PORT_0 0
  15915. +#define VSC73XX_SUBBLOCK_PORT_1 1
  15916. +#define VSC73XX_SUBBLOCK_PORT_2 2
  15917. +#define VSC73XX_SUBBLOCK_PORT_3 3
  15918. +#define VSC73XX_SUBBLOCK_PORT_4 4
  15919. +#define VSC73XX_SUBBLOCK_PORT_MAC 6
  15920. +
  15921. +/* MAC Block registers */
  15922. +#define VSC73XX_MAC_CFG 0x0
  15923. +#define VSC73XX_ADVPORTM 0x19
  15924. +#define VSC73XX_RXOCT 0x50
  15925. +#define VSC73XX_TXOCT 0x51
  15926. +#define VSC73XX_C_RX0 0x52
  15927. +#define VSC73XX_C_RX1 0x53
  15928. +#define VSC73XX_C_RX2 0x54
  15929. +#define VSC73XX_C_TX0 0x55
  15930. +#define VSC73XX_C_TX1 0x56
  15931. +#define VSC73XX_C_TX2 0x57
  15932. +#define VSC73XX_C_CFG 0x58
  15933. +
  15934. +/* MAC_CFG register bits */
  15935. +#define VSC73XX_MAC_CFG_WEXC_DIS (1 << 31)
  15936. +#define VSC73XX_MAC_CFG_PORT_RST (1 << 29)
  15937. +#define VSC73XX_MAC_CFG_TX_EN (1 << 28)
  15938. +#define VSC73XX_MAC_CFG_SEED_LOAD (1 << 27)
  15939. +#define VSC73XX_MAC_CFG_FDX (1 << 18)
  15940. +#define VSC73XX_MAC_CFG_GIGE (1 << 17)
  15941. +#define VSC73XX_MAC_CFG_RX_EN (1 << 16)
  15942. +#define VSC73XX_MAC_CFG_VLAN_DBLAWR (1 << 15)
  15943. +#define VSC73XX_MAC_CFG_VLAN_AWR (1 << 14)
  15944. +#define VSC73XX_MAC_CFG_100_BASE_T (1 << 13)
  15945. +#define VSC73XX_MAC_CFG_TX_IPG(x) (((x) & 0x1f) << 6)
  15946. +#define VSC73XX_MAC_CFG_MAC_RX_RST (1 << 5)
  15947. +#define VSC73XX_MAC_CFG_MAC_TX_RST (1 << 4)
  15948. +#define VSC73XX_MAC_CFG_BIT2 (1 << 2)
  15949. +#define VSC73XX_MAC_CFG_CLK_SEL(x) ((x) & 0x3)
  15950. +
  15951. +/* ADVPORTM register bits */
  15952. +#define VSC73XX_ADVPORTM_IFG_PPM (1 << 7)
  15953. +#define VSC73XX_ADVPORTM_EXC_COL_CONT (1 << 6)
  15954. +#define VSC73XX_ADVPORTM_EXT_PORT (1 << 5)
  15955. +#define VSC73XX_ADVPORTM_INV_GTX (1 << 4)
  15956. +#define VSC73XX_ADVPORTM_ENA_GTX (1 << 3)
  15957. +#define VSC73XX_ADVPORTM_DDR_MODE (1 << 2)
  15958. +#define VSC73XX_ADVPORTM_IO_LOOPBACK (1 << 1)
  15959. +#define VSC73XX_ADVPORTM_HOST_LOOPBACK (1 << 0)
  15960. +
  15961. +/* MII Block registers */
  15962. +#define VSC73XX_MII_STAT 0x0
  15963. +#define VSC73XX_MII_CMD 0x1
  15964. +#define VSC73XX_MII_DATA 0x2
  15965. +
  15966. +/* System Block registers */
  15967. +#define VSC73XX_ICPU_SIPAD 0x01
  15968. +#define VSC73XX_ICPU_CLOCK_DELAY 0x05
  15969. +#define VSC73XX_ICPU_CTRL 0x10
  15970. +#define VSC73XX_ICPU_ADDR 0x11
  15971. +#define VSC73XX_ICPU_SRAM 0x12
  15972. +#define VSC73XX_ICPU_MBOX_VAL 0x15
  15973. +#define VSC73XX_ICPU_MBOX_SET 0x16
  15974. +#define VSC73XX_ICPU_MBOX_CLR 0x17
  15975. +#define VSC73XX_ICPU_CHIPID 0x18
  15976. +#define VSC73XX_ICPU_GPIO 0x34
  15977. +
  15978. +#define VSC73XX_ICPU_CTRL_CLK_DIV (1 << 8)
  15979. +#define VSC73XX_ICPU_CTRL_SRST_HOLD (1 << 7)
  15980. +#define VSC73XX_ICPU_CTRL_BOOT_EN (1 << 3)
  15981. +#define VSC73XX_ICPU_CTRL_EXT_ACC_EN (1 << 2)
  15982. +#define VSC73XX_ICPU_CTRL_CLK_EN (1 << 1)
  15983. +#define VSC73XX_ICPU_CTRL_SRST (1 << 0)
  15984. +
  15985. +#define VSC73XX_ICPU_CHIPID_ID_SHIFT 12
  15986. +#define VSC73XX_ICPU_CHIPID_ID_MASK 0xffff
  15987. +#define VSC73XX_ICPU_CHIPID_REV_SHIFT 28
  15988. +#define VSC73XX_ICPU_CHIPID_REV_MASK 0xf
  15989. +#define VSC73XX_ICPU_CHIPID_ID_7385 0x7385
  15990. +#define VSC73XX_ICPU_CHIPID_ID_7395 0x7395
  15991. +
  15992. +#define VSC73XX_CMD_MODE_READ 0
  15993. +#define VSC73XX_CMD_MODE_WRITE 1
  15994. +#define VSC73XX_CMD_MODE_SHIFT 4
  15995. +#define VSC73XX_CMD_BLOCK_SHIFT 5
  15996. +#define VSC73XX_CMD_BLOCK_MASK 0x7
  15997. +#define VSC73XX_CMD_SUBBLOCK_MASK 0xf
  15998. +
  15999. +#define VSC7385_CLOCK_DELAY ((3 << 4) | 3)
  16000. +#define VSC7385_CLOCK_DELAY_MASK ((3 << 4) | 3)
  16001. +
  16002. +#define VSC73XX_ICPU_CTRL_STOP (VSC73XX_ICPU_CTRL_SRST_HOLD | \
  16003. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  16004. + VSC73XX_ICPU_CTRL_EXT_ACC_EN)
  16005. +
  16006. +#define VSC73XX_ICPU_CTRL_START (VSC73XX_ICPU_CTRL_CLK_DIV | \
  16007. + VSC73XX_ICPU_CTRL_BOOT_EN | \
  16008. + VSC73XX_ICPU_CTRL_CLK_EN | \
  16009. + VSC73XX_ICPU_CTRL_SRST)
  16010. +
  16011. +#define VSC7385_ADVPORTM_MASK (VSC73XX_ADVPORTM_IFG_PPM | \
  16012. + VSC73XX_ADVPORTM_EXC_COL_CONT | \
  16013. + VSC73XX_ADVPORTM_EXT_PORT | \
  16014. + VSC73XX_ADVPORTM_INV_GTX | \
  16015. + VSC73XX_ADVPORTM_ENA_GTX | \
  16016. + VSC73XX_ADVPORTM_DDR_MODE | \
  16017. + VSC73XX_ADVPORTM_IO_LOOPBACK | \
  16018. + VSC73XX_ADVPORTM_HOST_LOOPBACK)
  16019. +
  16020. +#define VSC7385_ADVPORTM_INIT (VSC73XX_ADVPORTM_EXT_PORT | \
  16021. + VSC73XX_ADVPORTM_ENA_GTX | \
  16022. + VSC73XX_ADVPORTM_DDR_MODE)
  16023. +
  16024. +#define VSC7385_MAC_CFG_RESET (VSC73XX_MAC_CFG_PORT_RST | \
  16025. + VSC73XX_MAC_CFG_MAC_RX_RST | \
  16026. + VSC73XX_MAC_CFG_MAC_TX_RST)
  16027. +
  16028. +#define VSC73XX_MAC_CFG_INIT (VSC73XX_MAC_CFG_TX_EN | \
  16029. + VSC73XX_MAC_CFG_FDX | \
  16030. + VSC73XX_MAC_CFG_GIGE | \
  16031. + VSC73XX_MAC_CFG_RX_EN)
  16032. +
  16033. +#define VSC73XX_RESET_DELAY 100
  16034. +
  16035. +struct vsc7385 {
  16036. + struct spi_device *spi;
  16037. + struct mutex lock;
  16038. + struct vsc7385_platform_data *pdata;
  16039. +};
  16040. +
  16041. +static int vsc7385_is_addr_valid(u8 block, u8 subblock)
  16042. +{
  16043. + switch (block) {
  16044. + case VSC73XX_BLOCK_MAC:
  16045. + switch (subblock) {
  16046. + case 0 ... 4:
  16047. + case 6:
  16048. + return 1;
  16049. + }
  16050. + break;
  16051. +
  16052. + case VSC73XX_BLOCK_2:
  16053. + case VSC73XX_BLOCK_SYSTEM:
  16054. + switch (subblock) {
  16055. + case 0:
  16056. + return 1;
  16057. + }
  16058. + break;
  16059. +
  16060. + case VSC73XX_BLOCK_MII:
  16061. + case VSC73XX_BLOCK_4:
  16062. + case VSC73XX_BLOCK_5:
  16063. + switch (subblock) {
  16064. + case 0 ... 1:
  16065. + return 1;
  16066. + }
  16067. + break;
  16068. + }
  16069. +
  16070. + return 0;
  16071. +}
  16072. +
  16073. +static inline u8 vsc7385_make_addr(u8 mode, u8 block, u8 subblock)
  16074. +{
  16075. + u8 ret;
  16076. +
  16077. + ret = (block & VSC73XX_CMD_BLOCK_MASK) << VSC73XX_CMD_BLOCK_SHIFT;
  16078. + ret |= (mode & 1) << VSC73XX_CMD_MODE_SHIFT;
  16079. + ret |= subblock & VSC73XX_CMD_SUBBLOCK_MASK;
  16080. +
  16081. + return ret;
  16082. +}
  16083. +
  16084. +static int vsc7385_read(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  16085. + u32 *value)
  16086. +{
  16087. + u8 cmd[4];
  16088. + u8 buf[4];
  16089. + struct spi_transfer t[2];
  16090. + struct spi_message m;
  16091. + int err;
  16092. +
  16093. + if (!vsc7385_is_addr_valid(block, subblock))
  16094. + return -EINVAL;
  16095. +
  16096. + spi_message_init(&m);
  16097. +
  16098. + memset(&t, 0, sizeof(t));
  16099. +
  16100. + t[0].tx_buf = cmd;
  16101. + t[0].len = sizeof(cmd);
  16102. + spi_message_add_tail(&t[0], &m);
  16103. +
  16104. + t[1].rx_buf = buf;
  16105. + t[1].len = sizeof(buf);
  16106. + spi_message_add_tail(&t[1], &m);
  16107. +
  16108. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_READ, block, subblock);
  16109. + cmd[1] = reg;
  16110. + cmd[2] = 0;
  16111. + cmd[3] = 0;
  16112. +
  16113. + mutex_lock(&vsc->lock);
  16114. + err = spi_sync(vsc->spi, &m);
  16115. + mutex_unlock(&vsc->lock);
  16116. +
  16117. + if (err)
  16118. + return err;
  16119. +
  16120. + *value = (((u32) buf[0]) << 24) | (((u32) buf[1]) << 16) |
  16121. + (((u32) buf[2]) << 8) | ((u32) buf[3]);
  16122. +
  16123. + return 0;
  16124. +}
  16125. +
  16126. +
  16127. +static int vsc7385_write(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  16128. + u32 value)
  16129. +{
  16130. + u8 cmd[2];
  16131. + u8 buf[4];
  16132. + struct spi_transfer t[2];
  16133. + struct spi_message m;
  16134. + int err;
  16135. +
  16136. + if (!vsc7385_is_addr_valid(block, subblock))
  16137. + return -EINVAL;
  16138. +
  16139. + spi_message_init(&m);
  16140. +
  16141. + memset(&t, 0, sizeof(t));
  16142. +
  16143. + t[0].tx_buf = cmd;
  16144. + t[0].len = sizeof(cmd);
  16145. + spi_message_add_tail(&t[0], &m);
  16146. +
  16147. + t[1].tx_buf = buf;
  16148. + t[1].len = sizeof(buf);
  16149. + spi_message_add_tail(&t[1], &m);
  16150. +
  16151. + cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_WRITE, block, subblock);
  16152. + cmd[1] = reg;
  16153. +
  16154. + buf[0] = (value >> 24) & 0xff;
  16155. + buf[1] = (value >> 16) & 0xff;
  16156. + buf[2] = (value >> 8) & 0xff;
  16157. + buf[3] = value & 0xff;
  16158. +
  16159. + mutex_lock(&vsc->lock);
  16160. + err = spi_sync(vsc->spi, &m);
  16161. + mutex_unlock(&vsc->lock);
  16162. +
  16163. + return err;
  16164. +}
  16165. +
  16166. +static inline int vsc7385_write_verify(struct vsc7385 *vsc, u8 block,
  16167. + u8 subblock, u8 reg, u32 value,
  16168. + u32 read_mask, u32 read_val)
  16169. +{
  16170. + struct spi_device *spi = vsc->spi;
  16171. + u32 t;
  16172. + int err;
  16173. +
  16174. + err = vsc7385_write(vsc, block, subblock, reg, value);
  16175. + if (err)
  16176. + return err;
  16177. +
  16178. + err = vsc7385_read(vsc, block, subblock, reg, &t);
  16179. + if (err)
  16180. + return err;
  16181. +
  16182. + if ((t & read_mask) != read_val) {
  16183. + dev_err(&spi->dev, "register write error\n");
  16184. + return -EIO;
  16185. + }
  16186. +
  16187. + return 0;
  16188. +}
  16189. +
  16190. +static inline int vsc7385_set_clock_delay(struct vsc7385 *vsc, u32 val)
  16191. +{
  16192. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16193. + VSC73XX_ICPU_CLOCK_DELAY, val);
  16194. +}
  16195. +
  16196. +static inline int vsc7385_get_clock_delay(struct vsc7385 *vsc, u32 *val)
  16197. +{
  16198. + return vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16199. + VSC73XX_ICPU_CLOCK_DELAY, val);
  16200. +}
  16201. +
  16202. +static inline int vsc7385_icpu_stop(struct vsc7385 *vsc)
  16203. +{
  16204. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  16205. + VSC73XX_ICPU_CTRL_STOP);
  16206. +}
  16207. +
  16208. +static inline int vsc7385_icpu_start(struct vsc7385 *vsc)
  16209. +{
  16210. + return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  16211. + VSC73XX_ICPU_CTRL_START);
  16212. +}
  16213. +
  16214. +static inline int vsc7385_icpu_reset(struct vsc7385 *vsc)
  16215. +{
  16216. + int rc;
  16217. +
  16218. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_ADDR,
  16219. + 0x0000);
  16220. + if (rc)
  16221. + dev_err(&vsc->spi->dev,
  16222. + "could not reset microcode, err=%d\n", rc);
  16223. +
  16224. + return rc;
  16225. +}
  16226. +
  16227. +static int vsc7385_upload_ucode(struct vsc7385 *vsc)
  16228. +{
  16229. + struct spi_device *spi = vsc->spi;
  16230. + const struct firmware *firmware;
  16231. + char *ucode_name;
  16232. + unsigned char *dp;
  16233. + unsigned int curVal;
  16234. + int i;
  16235. + int diffs;
  16236. + int rc;
  16237. +
  16238. + ucode_name = (vsc->pdata->ucode_name) ? vsc->pdata->ucode_name
  16239. + : "vsc7385_ucode.bin";
  16240. + rc = request_firmware(&firmware, ucode_name, &spi->dev);
  16241. + if (rc) {
  16242. + dev_err(&spi->dev, "request_firmware failed, err=%d\n",
  16243. + rc);
  16244. + return rc;
  16245. + }
  16246. +
  16247. + rc = vsc7385_icpu_stop(vsc);
  16248. + if (rc)
  16249. + goto out;
  16250. +
  16251. + rc = vsc7385_icpu_reset(vsc);
  16252. + if (rc)
  16253. + goto out;
  16254. +
  16255. + dev_info(&spi->dev, "uploading microcode...\n");
  16256. +
  16257. + dp = (unsigned char *) firmware->data;
  16258. + for (i = 0; i < firmware->size; i++) {
  16259. + rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16260. + VSC73XX_ICPU_SRAM, *dp++);
  16261. + if (rc) {
  16262. + dev_err(&spi->dev, "could not load microcode, err=%d\n",
  16263. + rc);
  16264. + goto out;
  16265. + }
  16266. + }
  16267. +
  16268. + rc = vsc7385_icpu_reset(vsc);
  16269. + if (rc)
  16270. + goto out;
  16271. +
  16272. + dev_info(&spi->dev, "verifying microcode...\n");
  16273. +
  16274. + dp = (unsigned char *) firmware->data;
  16275. + diffs = 0;
  16276. + for (i = 0; i < firmware->size; i++) {
  16277. + rc = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16278. + VSC73XX_ICPU_SRAM, &curVal);
  16279. + if (rc) {
  16280. + dev_err(&spi->dev, "could not read microcode %d\n",rc);
  16281. + goto out;
  16282. + }
  16283. +
  16284. + if (curVal > 0xff) {
  16285. + dev_err(&spi->dev, "bad val read: %04x : %02x %02x\n",
  16286. + i, *dp, curVal);
  16287. + rc = -EIO;
  16288. + goto out;
  16289. + }
  16290. +
  16291. + if ((curVal & 0xff) != *dp) {
  16292. + diffs++;
  16293. + dev_err(&spi->dev, "verify error: %04x : %02x %02x\n",
  16294. + i, *dp, curVal);
  16295. +
  16296. + if (diffs > 4)
  16297. + break;
  16298. + }
  16299. + dp++;
  16300. + }
  16301. +
  16302. + if (diffs) {
  16303. + dev_err(&spi->dev, "microcode verification failed\n");
  16304. + rc = -EIO;
  16305. + goto out;
  16306. + }
  16307. +
  16308. + dev_info(&spi->dev, "microcode uploaded\n");
  16309. +
  16310. + rc = vsc7385_icpu_start(vsc);
  16311. +
  16312. + out:
  16313. + release_firmware(firmware);
  16314. + return rc;
  16315. +}
  16316. +
  16317. +static int vsc7385_setup(struct vsc7385 *vsc)
  16318. +{
  16319. + struct vsc7385_platform_data *pdata = vsc->pdata;
  16320. + u32 t;
  16321. + int err;
  16322. +
  16323. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16324. + VSC73XX_ICPU_CLOCK_DELAY,
  16325. + VSC7385_CLOCK_DELAY,
  16326. + VSC7385_CLOCK_DELAY_MASK,
  16327. + VSC7385_CLOCK_DELAY);
  16328. + if (err)
  16329. + goto err;
  16330. +
  16331. + err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_MAC,
  16332. + VSC73XX_SUBBLOCK_PORT_MAC, VSC73XX_ADVPORTM,
  16333. + VSC7385_ADVPORTM_INIT,
  16334. + VSC7385_ADVPORTM_MASK,
  16335. + VSC7385_ADVPORTM_INIT);
  16336. + if (err)
  16337. + goto err;
  16338. +
  16339. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  16340. + VSC73XX_MAC_CFG, VSC7385_MAC_CFG_RESET);
  16341. + if (err)
  16342. + goto err;
  16343. +
  16344. + t = VSC73XX_MAC_CFG_INIT;
  16345. + t |= VSC73XX_MAC_CFG_TX_IPG(pdata->mac_cfg.tx_ipg);
  16346. + t |= VSC73XX_MAC_CFG_CLK_SEL(pdata->mac_cfg.clk_sel);
  16347. + if (pdata->mac_cfg.bit2)
  16348. + t |= VSC73XX_MAC_CFG_BIT2;
  16349. +
  16350. + err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  16351. + VSC73XX_MAC_CFG, t);
  16352. + if (err)
  16353. + goto err;
  16354. +
  16355. + return 0;
  16356. +
  16357. + err:
  16358. + return err;
  16359. +}
  16360. +
  16361. +static int vsc7385_detect(struct vsc7385 *vsc)
  16362. +{
  16363. + struct spi_device *spi = vsc->spi;
  16364. + u32 t;
  16365. + u32 id;
  16366. + u32 rev;
  16367. + int err;
  16368. +
  16369. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16370. + VSC73XX_ICPU_MBOX_VAL, &t);
  16371. + if (err) {
  16372. + dev_err(&spi->dev, "unable to read mailbox, err=%d\n", err);
  16373. + return err;
  16374. + }
  16375. +
  16376. + if (t == 0xffffffff) {
  16377. + dev_dbg(&spi->dev, "assert chip reset\n");
  16378. + if (vsc->pdata->reset)
  16379. + vsc->pdata->reset();
  16380. +
  16381. + }
  16382. +
  16383. + err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  16384. + VSC73XX_ICPU_CHIPID, &t);
  16385. + if (err) {
  16386. + dev_err(&spi->dev, "unable to read chip id, err=%d\n", err);
  16387. + return err;
  16388. + }
  16389. +
  16390. + id = (t >> VSC73XX_ICPU_CHIPID_ID_SHIFT) & VSC73XX_ICPU_CHIPID_ID_MASK;
  16391. + switch (id) {
  16392. + case VSC73XX_ICPU_CHIPID_ID_7385:
  16393. + case VSC73XX_ICPU_CHIPID_ID_7395:
  16394. + break;
  16395. + default:
  16396. + dev_err(&spi->dev, "unsupported chip, id=%04x\n", id);
  16397. + return -ENODEV;
  16398. + }
  16399. +
  16400. + rev = (t >> VSC73XX_ICPU_CHIPID_REV_SHIFT) &
  16401. + VSC73XX_ICPU_CHIPID_REV_MASK;
  16402. + dev_info(&spi->dev, "VSC%04X (rev. %d) switch found \n", id, rev);
  16403. +
  16404. + return 0;
  16405. +}
  16406. +
  16407. +static int __devinit vsc7385_probe(struct spi_device *spi)
  16408. +{
  16409. + struct vsc7385 *vsc;
  16410. + struct vsc7385_platform_data *pdata;
  16411. + int err;
  16412. +
  16413. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION"\n");
  16414. +
  16415. + pdata = spi->dev.platform_data;
  16416. + if (!pdata) {
  16417. + dev_err(&spi->dev, "no platform data specified\n");
  16418. + return-ENODEV;
  16419. + }
  16420. +
  16421. + vsc = kzalloc(sizeof(*vsc), GFP_KERNEL);
  16422. + if (!vsc) {
  16423. + dev_err(&spi->dev, "no memory for private data\n");
  16424. + return-ENOMEM;
  16425. + }
  16426. +
  16427. + mutex_init(&vsc->lock);
  16428. + vsc->pdata = pdata;
  16429. + vsc->spi = spi_dev_get(spi);
  16430. + dev_set_drvdata(&spi->dev, vsc);
  16431. +
  16432. + spi->mode = SPI_MODE_0;
  16433. + spi->bits_per_word = 8;
  16434. + err = spi_setup(spi);
  16435. + if (err) {
  16436. + dev_err(&spi->dev, "spi_setup failed, err=%d \n", err);
  16437. + goto err_drvdata;
  16438. + }
  16439. +
  16440. + err = vsc7385_detect(vsc);
  16441. + if (err) {
  16442. + dev_err(&spi->dev, "no chip found, err=%d \n", err);
  16443. + goto err_drvdata;
  16444. + }
  16445. +
  16446. + err = vsc7385_upload_ucode(vsc);
  16447. + if (err)
  16448. + goto err_drvdata;
  16449. +
  16450. + err = vsc7385_setup(vsc);
  16451. + if (err)
  16452. + goto err_drvdata;
  16453. +
  16454. + return 0;
  16455. +
  16456. + err_drvdata:
  16457. + dev_set_drvdata(&spi->dev, NULL);
  16458. + kfree(vsc);
  16459. + return err;
  16460. +}
  16461. +
  16462. +static int __devexit vsc7385_remove(struct spi_device *spi)
  16463. +{
  16464. + struct vsc7385_data *vsc;
  16465. +
  16466. + vsc = dev_get_drvdata(&spi->dev);
  16467. + dev_set_drvdata(&spi->dev, NULL);
  16468. + kfree(vsc);
  16469. +
  16470. + return 0;
  16471. +}
  16472. +
  16473. +static struct spi_driver vsc7385_driver = {
  16474. + .driver = {
  16475. + .name = DRV_NAME,
  16476. + .bus = &spi_bus_type,
  16477. + .owner = THIS_MODULE,
  16478. + },
  16479. + .probe = vsc7385_probe,
  16480. + .remove = __devexit_p(vsc7385_remove),
  16481. +};
  16482. +
  16483. +static int __init vsc7385_init(void)
  16484. +{
  16485. + return spi_register_driver(&vsc7385_driver);
  16486. +}
  16487. +module_init(vsc7385_init);
  16488. +
  16489. +static void __exit vsc7385_exit(void)
  16490. +{
  16491. + spi_unregister_driver(&vsc7385_driver);
  16492. +}
  16493. +module_exit(vsc7385_exit);
  16494. +
  16495. +MODULE_DESCRIPTION(DRV_DESC);
  16496. +MODULE_VERSION(DRV_VERSION);
  16497. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  16498. +MODULE_LICENSE("GPL v2");
  16499. +
  16500. diff -Nur linux-2.6.34.orig/drivers/usb/host/ehci-ar71xx.c linux-2.6.34/drivers/usb/host/ehci-ar71xx.c
  16501. --- linux-2.6.34.orig/drivers/usb/host/ehci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  16502. +++ linux-2.6.34/drivers/usb/host/ehci-ar71xx.c 2010-05-25 18:46:12.962223093 +0200
  16503. @@ -0,0 +1,242 @@
  16504. +/*
  16505. + * Bus Glue for Atheros AR71xx built-in EHCI controller.
  16506. + *
  16507. + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  16508. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16509. + *
  16510. + * Parts of this file are based on Atheros' 2.6.15 BSP
  16511. + * Copyright (C) 2007 Atheros Communications, Inc.
  16512. + *
  16513. + * This program is free software; you can redistribute it and/or modify it
  16514. + * under the terms of the GNU General Public License version 2 as published
  16515. + * by the Free Software Foundation.
  16516. + */
  16517. +
  16518. +#include <linux/platform_device.h>
  16519. +#include <linux/delay.h>
  16520. +
  16521. +#include <asm/mach-ar71xx/platform.h>
  16522. +
  16523. +extern int usb_disabled(void);
  16524. +
  16525. +static int ehci_ar71xx_init(struct usb_hcd *hcd)
  16526. +{
  16527. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  16528. + int ret;
  16529. +
  16530. + ehci->caps = hcd->regs;
  16531. + ehci->regs = hcd->regs +
  16532. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  16533. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  16534. +
  16535. + ehci->sbrn = 0x20;
  16536. + ehci->has_synopsys_hc_bug = 1;
  16537. +
  16538. + ehci_reset(ehci);
  16539. +
  16540. + ret = ehci_init(hcd);
  16541. + if (ret)
  16542. + return ret;
  16543. +
  16544. + ehci_port_power(ehci, 0);
  16545. +
  16546. + return 0;
  16547. +}
  16548. +
  16549. +static int ehci_ar91xx_init(struct usb_hcd *hcd)
  16550. +{
  16551. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  16552. + int ret;
  16553. +
  16554. + ehci->caps = hcd->regs + 0x100;
  16555. + ehci->regs = hcd->regs + 0x100 +
  16556. + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  16557. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  16558. +
  16559. + hcd->has_tt = 1;
  16560. + ehci->sbrn = 0x20;
  16561. +
  16562. + ehci_reset(ehci);
  16563. +
  16564. + ret = ehci_init(hcd);
  16565. + if (ret)
  16566. + return ret;
  16567. +
  16568. + ehci_port_power(ehci, 0);
  16569. +
  16570. + return 0;
  16571. +}
  16572. +
  16573. +static int ehci_ar71xx_probe(const struct hc_driver *driver,
  16574. + struct usb_hcd **hcd_out,
  16575. + struct platform_device *pdev)
  16576. +{
  16577. + struct usb_hcd *hcd;
  16578. + struct resource *res;
  16579. + int irq;
  16580. + int ret;
  16581. +
  16582. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  16583. + if (!res) {
  16584. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  16585. + dev_name(&pdev->dev));
  16586. + return -ENODEV;
  16587. + }
  16588. + irq = res->start;
  16589. +
  16590. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  16591. + if (!res) {
  16592. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  16593. + dev_name(&pdev->dev));
  16594. + return -ENODEV;
  16595. + }
  16596. +
  16597. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  16598. + if (!hcd)
  16599. + return -ENOMEM;
  16600. +
  16601. + hcd->rsrc_start = res->start;
  16602. + hcd->rsrc_len = res->end - res->start + 1;
  16603. +
  16604. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  16605. + dev_dbg(&pdev->dev, "controller already in use\n");
  16606. + ret = -EBUSY;
  16607. + goto err_put_hcd;
  16608. + }
  16609. +
  16610. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  16611. + if (!hcd->regs) {
  16612. + dev_dbg(&pdev->dev, "error mapping memory\n");
  16613. + ret = -EFAULT;
  16614. + goto err_release_region;
  16615. + }
  16616. +
  16617. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  16618. + if (ret)
  16619. + goto err_iounmap;
  16620. +
  16621. + return 0;
  16622. +
  16623. + err_iounmap:
  16624. + iounmap(hcd->regs);
  16625. +
  16626. + err_release_region:
  16627. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16628. + err_put_hcd:
  16629. + usb_put_hcd(hcd);
  16630. + return ret;
  16631. +}
  16632. +
  16633. +static void ehci_ar71xx_remove(struct usb_hcd *hcd,
  16634. + struct platform_device *pdev)
  16635. +{
  16636. + usb_remove_hcd(hcd);
  16637. + iounmap(hcd->regs);
  16638. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16639. + usb_put_hcd(hcd);
  16640. +}
  16641. +
  16642. +static const struct hc_driver ehci_ar71xx_hc_driver = {
  16643. + .description = hcd_name,
  16644. + .product_desc = "Atheros AR71xx built-in EHCI controller",
  16645. + .hcd_priv_size = sizeof(struct ehci_hcd),
  16646. +
  16647. + .irq = ehci_irq,
  16648. + .flags = HCD_MEMORY | HCD_USB2,
  16649. +
  16650. + .reset = ehci_ar71xx_init,
  16651. + .start = ehci_run,
  16652. + .stop = ehci_stop,
  16653. + .shutdown = ehci_shutdown,
  16654. +
  16655. + .urb_enqueue = ehci_urb_enqueue,
  16656. + .urb_dequeue = ehci_urb_dequeue,
  16657. + .endpoint_disable = ehci_endpoint_disable,
  16658. + .endpoint_reset = ehci_endpoint_reset,
  16659. +
  16660. + .get_frame_number = ehci_get_frame,
  16661. +
  16662. + .hub_status_data = ehci_hub_status_data,
  16663. + .hub_control = ehci_hub_control,
  16664. +#ifdef CONFIG_PM
  16665. + .hub_suspend = ehci_hub_suspend,
  16666. + .hub_resume = ehci_hub_resume,
  16667. +#endif
  16668. + .relinquish_port = ehci_relinquish_port,
  16669. + .port_handed_over = ehci_port_handed_over,
  16670. +
  16671. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  16672. +};
  16673. +
  16674. +static const struct hc_driver ehci_ar91xx_hc_driver = {
  16675. + .description = hcd_name,
  16676. + .product_desc = "Atheros AR91xx built-in EHCI controller",
  16677. + .hcd_priv_size = sizeof(struct ehci_hcd),
  16678. + .irq = ehci_irq,
  16679. + .flags = HCD_MEMORY | HCD_USB2,
  16680. +
  16681. + .reset = ehci_ar91xx_init,
  16682. + .start = ehci_run,
  16683. + .stop = ehci_stop,
  16684. + .shutdown = ehci_shutdown,
  16685. +
  16686. + .urb_enqueue = ehci_urb_enqueue,
  16687. + .urb_dequeue = ehci_urb_dequeue,
  16688. + .endpoint_disable = ehci_endpoint_disable,
  16689. + .endpoint_reset = ehci_endpoint_reset,
  16690. +
  16691. + .get_frame_number = ehci_get_frame,
  16692. +
  16693. + .hub_status_data = ehci_hub_status_data,
  16694. + .hub_control = ehci_hub_control,
  16695. +#ifdef CONFIG_PM
  16696. + .hub_suspend = ehci_hub_suspend,
  16697. + .hub_resume = ehci_hub_resume,
  16698. +#endif
  16699. + .relinquish_port = ehci_relinquish_port,
  16700. + .port_handed_over = ehci_port_handed_over,
  16701. +
  16702. + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  16703. +};
  16704. +
  16705. +static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
  16706. +{
  16707. + struct ar71xx_ehci_platform_data *pdata;
  16708. + struct usb_hcd *hcd = NULL;
  16709. + int ret;
  16710. +
  16711. + if (usb_disabled())
  16712. + return -ENODEV;
  16713. +
  16714. + pdata = pdev->dev.platform_data;
  16715. + if (!pdata) {
  16716. + dev_err(&pdev->dev, "no platform data specified for %s\n",
  16717. + dev_name(&pdev->dev));
  16718. + return -ENODEV;
  16719. + }
  16720. +
  16721. + if (pdata->is_ar91xx)
  16722. + ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
  16723. + else
  16724. + ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
  16725. +
  16726. + return ret;
  16727. +}
  16728. +
  16729. +static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
  16730. +{
  16731. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  16732. +
  16733. + ehci_ar71xx_remove(hcd, pdev);
  16734. + return 0;
  16735. +}
  16736. +
  16737. +MODULE_ALIAS("platform:ar71xx-ehci");
  16738. +
  16739. +static struct platform_driver ehci_ar71xx_driver = {
  16740. + .probe = ehci_ar71xx_driver_probe,
  16741. + .remove = ehci_ar71xx_driver_remove,
  16742. + .driver = {
  16743. + .name = "ar71xx-ehci",
  16744. + }
  16745. +};
  16746. diff -Nur linux-2.6.34.orig/drivers/usb/host/ehci-hcd.c linux-2.6.34/drivers/usb/host/ehci-hcd.c
  16747. --- linux-2.6.34.orig/drivers/usb/host/ehci-hcd.c 2010-05-16 23:17:36.000000000 +0200
  16748. +++ linux-2.6.34/drivers/usb/host/ehci-hcd.c 2010-05-25 18:46:13.003464099 +0200
  16749. @@ -1159,6 +1159,11 @@
  16750. #define PLATFORM_DRIVER ehci_atmel_driver
  16751. #endif
  16752. +#ifdef CONFIG_USB_EHCI_AR71XX
  16753. +#include "ehci-ar71xx.c"
  16754. +#define PLATFORM_DRIVER ehci_ar71xx_driver
  16755. +#endif
  16756. +
  16757. #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
  16758. !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
  16759. #error "missing bus glue for ehci-hcd"
  16760. diff -Nur linux-2.6.34.orig/drivers/usb/host/Kconfig linux-2.6.34/drivers/usb/host/Kconfig
  16761. --- linux-2.6.34.orig/drivers/usb/host/Kconfig 2010-05-16 23:17:36.000000000 +0200
  16762. +++ linux-2.6.34/drivers/usb/host/Kconfig 2010-05-25 18:46:13.040970869 +0200
  16763. @@ -109,6 +109,13 @@
  16764. support both high speed and full speed devices, or high speed
  16765. devices only.
  16766. +config USB_EHCI_AR71XX
  16767. + bool "USB EHCI support for AR71xx"
  16768. + depends on USB_EHCI_HCD && ATHEROS_AR71XX
  16769. + default y
  16770. + help
  16771. + Support for Atheros AR71xx built-in EHCI controller
  16772. +
  16773. config USB_EHCI_FSL
  16774. bool "Support for Freescale on-chip EHCI USB controller"
  16775. depends on USB_EHCI_HCD && FSL_SOC
  16776. @@ -207,6 +214,13 @@
  16777. To compile this driver as a module, choose M here: the
  16778. module will be called ohci-hcd.
  16779. +config USB_OHCI_AR71XX
  16780. + bool "USB OHCI support for Atheros AR71xx"
  16781. + depends on USB_OHCI_HCD && ATHEROS_AR71XX
  16782. + default y
  16783. + help
  16784. + Support for Atheros AR71xx built-in OHCI controller
  16785. +
  16786. config USB_OHCI_HCD_PPC_SOC
  16787. bool "OHCI support for on-chip PPC USB controller"
  16788. depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx)
  16789. diff -Nur linux-2.6.34.orig/drivers/usb/host/ohci-ar71xx.c linux-2.6.34/drivers/usb/host/ohci-ar71xx.c
  16790. --- linux-2.6.34.orig/drivers/usb/host/ohci-ar71xx.c 1970-01-01 01:00:00.000000000 +0100
  16791. +++ linux-2.6.34/drivers/usb/host/ohci-ar71xx.c 2010-05-25 18:46:13.093473080 +0200
  16792. @@ -0,0 +1,165 @@
  16793. +/*
  16794. + * OHCI HCD (Host Controller Driver) for USB.
  16795. + *
  16796. + * Bus Glue for Atheros AR71xx built-in OHCI controller.
  16797. + *
  16798. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  16799. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16800. + *
  16801. + * Parts of this file are based on Atheros' 2.6.15 BSP
  16802. + * Copyright (C) 2007 Atheros Communications, Inc.
  16803. + *
  16804. + * This program is free software; you can redistribute it and/or modify it
  16805. + * under the terms of the GNU General Public License version 2 as published
  16806. + * by the Free Software Foundation.
  16807. + */
  16808. +
  16809. +#include <linux/platform_device.h>
  16810. +#include <linux/delay.h>
  16811. +
  16812. +extern int usb_disabled(void);
  16813. +
  16814. +static int usb_hcd_ar71xx_probe(const struct hc_driver *driver,
  16815. + struct platform_device *pdev)
  16816. +{
  16817. + struct usb_hcd *hcd;
  16818. + struct resource *res;
  16819. + int irq;
  16820. + int ret;
  16821. +
  16822. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  16823. + if (!res) {
  16824. + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
  16825. + dev_name(&pdev->dev));
  16826. + return -ENODEV;
  16827. + }
  16828. + irq = res->start;
  16829. +
  16830. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  16831. + if (!hcd)
  16832. + return -ENOMEM;
  16833. +
  16834. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  16835. + if (!res) {
  16836. + dev_dbg(&pdev->dev, "no base address specified for %s\n",
  16837. + dev_name(&pdev->dev));
  16838. + ret = -ENODEV;
  16839. + goto err_put_hcd;
  16840. + }
  16841. + hcd->rsrc_start = res->start;
  16842. + hcd->rsrc_len = res->end - res->start + 1;
  16843. +
  16844. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  16845. + dev_dbg(&pdev->dev, "controller already in use\n");
  16846. + ret = -EBUSY;
  16847. + goto err_put_hcd;
  16848. + }
  16849. +
  16850. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  16851. + if (!hcd->regs) {
  16852. + dev_dbg(&pdev->dev, "error mapping memory\n");
  16853. + ret = -EFAULT;
  16854. + goto err_release_region;
  16855. + }
  16856. +
  16857. + ohci_hcd_init(hcd_to_ohci(hcd));
  16858. +
  16859. + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  16860. + if (ret)
  16861. + goto err_stop_hcd;
  16862. +
  16863. + return 0;
  16864. +
  16865. + err_stop_hcd:
  16866. + iounmap(hcd->regs);
  16867. + err_release_region:
  16868. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16869. + err_put_hcd:
  16870. + usb_put_hcd(hcd);
  16871. + return ret;
  16872. +}
  16873. +
  16874. +void usb_hcd_ar71xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  16875. +{
  16876. + usb_remove_hcd(hcd);
  16877. + iounmap(hcd->regs);
  16878. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  16879. + usb_put_hcd(hcd);
  16880. +}
  16881. +
  16882. +static int __devinit ohci_ar71xx_start(struct usb_hcd *hcd)
  16883. +{
  16884. + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  16885. + int ret;
  16886. +
  16887. + ret = ohci_init(ohci);
  16888. + if (ret < 0)
  16889. + return ret;
  16890. +
  16891. + ret = ohci_run(ohci);
  16892. + if (ret < 0)
  16893. + goto err;
  16894. +
  16895. + return 0;
  16896. +
  16897. + err:
  16898. + ohci_stop(hcd);
  16899. + return ret;
  16900. +}
  16901. +
  16902. +static const struct hc_driver ohci_ar71xx_hc_driver = {
  16903. + .description = hcd_name,
  16904. + .product_desc = "Atheros AR71xx built-in OHCI controller",
  16905. + .hcd_priv_size = sizeof(struct ohci_hcd),
  16906. +
  16907. + .irq = ohci_irq,
  16908. + .flags = HCD_USB11 | HCD_MEMORY,
  16909. +
  16910. + .start = ohci_ar71xx_start,
  16911. + .stop = ohci_stop,
  16912. + .shutdown = ohci_shutdown,
  16913. +
  16914. + .urb_enqueue = ohci_urb_enqueue,
  16915. + .urb_dequeue = ohci_urb_dequeue,
  16916. + .endpoint_disable = ohci_endpoint_disable,
  16917. +
  16918. + /*
  16919. + * scheduling support
  16920. + */
  16921. + .get_frame_number = ohci_get_frame,
  16922. +
  16923. + /*
  16924. + * root hub support
  16925. + */
  16926. + .hub_status_data = ohci_hub_status_data,
  16927. + .hub_control = ohci_hub_control,
  16928. + .start_port_reset = ohci_start_port_reset,
  16929. +};
  16930. +
  16931. +static int ohci_hcd_ar71xx_drv_probe(struct platform_device *pdev)
  16932. +{
  16933. + if (usb_disabled())
  16934. + return -ENODEV;
  16935. +
  16936. + return usb_hcd_ar71xx_probe(&ohci_ar71xx_hc_driver, pdev);
  16937. +}
  16938. +
  16939. +static int ohci_hcd_ar71xx_drv_remove(struct platform_device *pdev)
  16940. +{
  16941. + struct usb_hcd *hcd = platform_get_drvdata(pdev);
  16942. +
  16943. + usb_hcd_ar71xx_remove(hcd, pdev);
  16944. + return 0;
  16945. +}
  16946. +
  16947. +MODULE_ALIAS("platform:ar71xx-ohci");
  16948. +
  16949. +static struct platform_driver ohci_hcd_ar71xx_driver = {
  16950. + .probe = ohci_hcd_ar71xx_drv_probe,
  16951. + .remove = ohci_hcd_ar71xx_drv_remove,
  16952. + .shutdown = usb_hcd_platform_shutdown,
  16953. + .driver = {
  16954. + .name = "ar71xx-ohci",
  16955. + .owner = THIS_MODULE,
  16956. + },
  16957. +};
  16958. diff -Nur linux-2.6.34.orig/drivers/usb/host/ohci-hcd.c linux-2.6.34/drivers/usb/host/ohci-hcd.c
  16959. --- linux-2.6.34.orig/drivers/usb/host/ohci-hcd.c 2010-05-16 23:17:36.000000000 +0200
  16960. +++ linux-2.6.34/drivers/usb/host/ohci-hcd.c 2010-05-25 18:46:13.132223090 +0200
  16961. @@ -1090,6 +1090,11 @@
  16962. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  16963. #endif
  16964. +#ifdef CONFIG_USB_OHCI_AR71XX
  16965. +#include "ohci-ar71xx.c"
  16966. +#define PLATFORM_DRIVER ohci_hcd_ar71xx_driver
  16967. +#endif
  16968. +
  16969. #if !defined(PCI_DRIVER) && \
  16970. !defined(PLATFORM_DRIVER) && \
  16971. !defined(OF_PLATFORM_DRIVER) && \
  16972. diff -Nur linux-2.6.34.orig/drivers/watchdog/ar71xx_wdt.c linux-2.6.34/drivers/watchdog/ar71xx_wdt.c
  16973. --- linux-2.6.34.orig/drivers/watchdog/ar71xx_wdt.c 1970-01-01 01:00:00.000000000 +0100
  16974. +++ linux-2.6.34/drivers/watchdog/ar71xx_wdt.c 2010-05-25 18:46:13.163473025 +0200
  16975. @@ -0,0 +1,270 @@
  16976. +/*
  16977. + * Driver for the Atheros AR71xx SoC's built-in hardware watchdog timer.
  16978. + *
  16979. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  16980. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  16981. + *
  16982. + * This driver was based on: drivers/watchdog/ixp4xx_wdt.c
  16983. + * Author: Deepak Saxena <dsaxena@plexity.net>
  16984. + * Copyright 2004 (c) MontaVista, Software, Inc.
  16985. + *
  16986. + * which again was based on sa1100 driver,
  16987. + * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
  16988. + *
  16989. + * This program is free software; you can redistribute it and/or modify it
  16990. + * under the terms of the GNU General Public License version 2 as published
  16991. + * by the Free Software Foundation.
  16992. + *
  16993. + */
  16994. +
  16995. +#include <linux/bitops.h>
  16996. +#include <linux/errno.h>
  16997. +#include <linux/fs.h>
  16998. +#include <linux/init.h>
  16999. +#include <linux/kernel.h>
  17000. +#include <linux/miscdevice.h>
  17001. +#include <linux/module.h>
  17002. +#include <linux/moduleparam.h>
  17003. +#include <linux/platform_device.h>
  17004. +#include <linux/types.h>
  17005. +#include <linux/watchdog.h>
  17006. +
  17007. +#include <asm/mach-ar71xx/ar71xx.h>
  17008. +
  17009. +#define DRV_NAME "ar71xx-wdt"
  17010. +#define DRV_DESC "Atheros AR71xx hardware watchdog driver"
  17011. +#define DRV_VERSION "0.1.0"
  17012. +
  17013. +#define WDT_TIMEOUT 15 /* seconds */
  17014. +
  17015. +static int nowayout = WATCHDOG_NOWAYOUT;
  17016. +
  17017. +#ifdef CONFIG_WATCHDOG_NOWAYOUT
  17018. +module_param(nowayout, int, 0);
  17019. +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
  17020. + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  17021. +#endif
  17022. +
  17023. +static unsigned long wdt_flags;
  17024. +
  17025. +#define WDT_FLAGS_BUSY 0
  17026. +#define WDT_FLAGS_EXPECT_CLOSE 1
  17027. +
  17028. +static int wdt_timeout = WDT_TIMEOUT;
  17029. +static int boot_status;
  17030. +static int max_timeout;
  17031. +
  17032. +static void inline ar71xx_wdt_keepalive(void)
  17033. +{
  17034. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG, ar71xx_ahb_freq * wdt_timeout);
  17035. +}
  17036. +
  17037. +static void inline ar71xx_wdt_enable(void)
  17038. +{
  17039. + printk(KERN_DEBUG DRV_NAME ": enabling watchdog timer\n");
  17040. + ar71xx_wdt_keepalive();
  17041. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_FCR);
  17042. +}
  17043. +
  17044. +static void inline ar71xx_wdt_disable(void)
  17045. +{
  17046. + printk(KERN_DEBUG DRV_NAME ": disabling watchdog timer\n");
  17047. + ar71xx_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_NONE);
  17048. +}
  17049. +
  17050. +static int ar71xx_wdt_set_timeout(int val)
  17051. +{
  17052. + if (val < 1 || val > max_timeout)
  17053. + return -EINVAL;
  17054. +
  17055. + wdt_timeout = val;
  17056. + ar71xx_wdt_keepalive();
  17057. +
  17058. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs\n", wdt_timeout);
  17059. +
  17060. + return 0;
  17061. +}
  17062. +
  17063. +static int ar71xx_wdt_open(struct inode *inode, struct file *file)
  17064. +{
  17065. + if (test_and_set_bit(WDT_FLAGS_BUSY, &wdt_flags))
  17066. + return -EBUSY;
  17067. +
  17068. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17069. +
  17070. + ar71xx_wdt_enable();
  17071. +
  17072. + return nonseekable_open(inode, file);
  17073. +}
  17074. +
  17075. +static int ar71xx_wdt_release(struct inode *inode, struct file *file)
  17076. +{
  17077. + if (test_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags)) {
  17078. + ar71xx_wdt_disable();
  17079. + } else {
  17080. + printk(KERN_CRIT DRV_NAME ": device closed unexpectedly, "
  17081. + "watchdog timer will not stop!\n");
  17082. + }
  17083. +
  17084. + clear_bit(WDT_FLAGS_BUSY, &wdt_flags);
  17085. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17086. +
  17087. + return 0;
  17088. +}
  17089. +
  17090. +static ssize_t ar71xx_wdt_write(struct file *file, const char *data,
  17091. + size_t len, loff_t *ppos)
  17092. +{
  17093. + if (len) {
  17094. + if (!nowayout) {
  17095. + size_t i;
  17096. +
  17097. + clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
  17098. +
  17099. + for (i = 0; i != len; i++) {
  17100. + char c;
  17101. +
  17102. + if (get_user(c, data + i))
  17103. + return -EFAULT;
  17104. +
  17105. + if (c == 'V')
  17106. + set_bit(WDT_FLAGS_EXPECT_CLOSE,
  17107. + &wdt_flags);
  17108. + }
  17109. + }
  17110. +
  17111. + ar71xx_wdt_keepalive();
  17112. + }
  17113. +
  17114. + return len;
  17115. +}
  17116. +
  17117. +static struct watchdog_info ar71xx_wdt_info = {
  17118. + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
  17119. + WDIOF_MAGICCLOSE | WDIOF_CARDRESET,
  17120. + .firmware_version = 0,
  17121. + .identity = "AR71XX watchdog",
  17122. +};
  17123. +
  17124. +static int ar71xx_wdt_ioctl(struct inode *inode, struct file *file,
  17125. + unsigned int cmd, unsigned long arg)
  17126. +{
  17127. + int t;
  17128. + int ret;
  17129. +
  17130. + switch (cmd) {
  17131. + case WDIOC_GETSUPPORT:
  17132. + ret = copy_to_user((struct watchdog_info *)arg,
  17133. + &ar71xx_wdt_info,
  17134. + sizeof(&ar71xx_wdt_info)) ? -EFAULT : 0;
  17135. + break;
  17136. +
  17137. + case WDIOC_GETSTATUS:
  17138. + ret = put_user(0, (int *)arg) ? -EFAULT : 0;
  17139. + break;
  17140. +
  17141. + case WDIOC_GETBOOTSTATUS:
  17142. + ret = put_user(boot_status, (int *)arg) ? -EFAULT : 0;
  17143. + break;
  17144. +
  17145. + case WDIOC_KEEPALIVE:
  17146. + ar71xx_wdt_keepalive();
  17147. + ret = 0;
  17148. + break;
  17149. +
  17150. + case WDIOC_SETTIMEOUT:
  17151. + ret = get_user(t, (int *)arg) ? -EFAULT : 0;
  17152. + if (ret)
  17153. + break;
  17154. +
  17155. + ret = ar71xx_wdt_set_timeout(t);
  17156. + if (ret)
  17157. + break;
  17158. +
  17159. + /* fallthrough */
  17160. + case WDIOC_GETTIMEOUT:
  17161. + ret = put_user(wdt_timeout, (int *)arg) ? -EFAULT : 0;
  17162. + break;
  17163. +
  17164. + default:
  17165. + ret = -ENOTTY;
  17166. + break;
  17167. + }
  17168. +
  17169. + return ret;
  17170. +}
  17171. +
  17172. +static const struct file_operations ar71xx_wdt_fops = {
  17173. + .owner = THIS_MODULE,
  17174. + .write = ar71xx_wdt_write,
  17175. + .ioctl = ar71xx_wdt_ioctl,
  17176. + .open = ar71xx_wdt_open,
  17177. + .release = ar71xx_wdt_release,
  17178. +};
  17179. +
  17180. +static struct miscdevice ar71xx_wdt_miscdev = {
  17181. + .minor = WATCHDOG_MINOR,
  17182. + .name = "watchdog",
  17183. + .fops = &ar71xx_wdt_fops,
  17184. +};
  17185. +
  17186. +static int __devinit ar71xx_wdt_probe(struct platform_device *pdev)
  17187. +{
  17188. + int ret;
  17189. +
  17190. + max_timeout = (0xfffffffful / ar71xx_ahb_freq);
  17191. + wdt_timeout = (max_timeout < WDT_TIMEOUT) ? max_timeout : WDT_TIMEOUT;
  17192. +
  17193. + boot_status =
  17194. + (ar71xx_reset_rr(AR71XX_RESET_REG_WDOG_CTRL) & WDOG_CTRL_LAST_RESET) ?
  17195. + WDIOF_CARDRESET : 0;
  17196. +
  17197. + ret = misc_register(&ar71xx_wdt_miscdev);
  17198. + if (ret)
  17199. + goto err_out;
  17200. +
  17201. + printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
  17202. +
  17203. + printk(KERN_DEBUG DRV_NAME ": timeout=%d secs (max=%d)\n",
  17204. + wdt_timeout, max_timeout);
  17205. +
  17206. + return 0;
  17207. +
  17208. +err_out:
  17209. + return ret;
  17210. +}
  17211. +
  17212. +static int __devexit ar71xx_wdt_remove(struct platform_device *pdev)
  17213. +{
  17214. + misc_deregister(&ar71xx_wdt_miscdev);
  17215. + return 0;
  17216. +}
  17217. +
  17218. +static struct platform_driver ar71xx_wdt_driver = {
  17219. + .probe = ar71xx_wdt_probe,
  17220. + .remove = __devexit_p(ar71xx_wdt_remove),
  17221. + .driver = {
  17222. + .name = DRV_NAME,
  17223. + .owner = THIS_MODULE,
  17224. + },
  17225. +};
  17226. +
  17227. +static int __init ar71xx_wdt_init(void)
  17228. +{
  17229. + return platform_driver_register(&ar71xx_wdt_driver);
  17230. +}
  17231. +module_init(ar71xx_wdt_init);
  17232. +
  17233. +static void __exit ar71xx_wdt_exit(void)
  17234. +{
  17235. + platform_driver_unregister(&ar71xx_wdt_driver);
  17236. +}
  17237. +module_exit(ar71xx_wdt_exit);
  17238. +
  17239. +MODULE_DESCRIPTION(DRV_DESC);
  17240. +MODULE_VERSION(DRV_VERSION);
  17241. +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
  17242. +MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
  17243. +MODULE_LICENSE("GPL v2");
  17244. +MODULE_ALIAS("platform:" DRV_NAME);
  17245. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  17246. diff -Nur linux-2.6.34.orig/drivers/watchdog/Kconfig linux-2.6.34/drivers/watchdog/Kconfig
  17247. --- linux-2.6.34.orig/drivers/watchdog/Kconfig 2010-05-16 23:17:36.000000000 +0200
  17248. +++ linux-2.6.34/drivers/watchdog/Kconfig 2010-05-25 18:46:13.203464018 +0200
  17249. @@ -857,6 +857,13 @@
  17250. help
  17251. Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
  17252. +config AR71XX_WDT
  17253. + tristate "Atheros AR71xx Watchdog Timer"
  17254. + depends on ATHEROS_AR71XX
  17255. + help
  17256. + Hardware driver for the built-in watchdog timer on the Atheros
  17257. + AR71xx SoCs.
  17258. +
  17259. # PARISC Architecture
  17260. # POWERPC Architecture
  17261. diff -Nur linux-2.6.34.orig/drivers/watchdog/Makefile linux-2.6.34/drivers/watchdog/Makefile
  17262. --- linux-2.6.34.orig/drivers/watchdog/Makefile 2010-05-16 23:17:36.000000000 +0200
  17263. +++ linux-2.6.34/drivers/watchdog/Makefile 2010-05-25 18:46:13.242223206 +0200
  17264. @@ -113,6 +113,7 @@
  17265. obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
  17266. obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
  17267. obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
  17268. +obj-$(CONFIG_AR71XX_WDT) += ar71xx_wdt.o
  17269. # PARISC Architecture
  17270. diff -Nur linux-2.6.34.orig/include/linux/ath9k_platform.h linux-2.6.34/include/linux/ath9k_platform.h
  17271. --- linux-2.6.34.orig/include/linux/ath9k_platform.h 2010-05-16 23:17:36.000000000 +0200
  17272. +++ linux-2.6.34/include/linux/ath9k_platform.h 2010-05-25 18:46:13.283473018 +0200
  17273. @@ -1,19 +1,11 @@
  17274. /*
  17275. - * Copyright (c) 2008 Atheros Communications Inc.
  17276. - * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  17277. - * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
  17278. + * ath9k platform data defines
  17279. *
  17280. - * Permission to use, copy, modify, and/or distribute this software for any
  17281. - * purpose with or without fee is hereby granted, provided that the above
  17282. - * copyright notice and this permission notice appear in all copies.
  17283. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  17284. *
  17285. - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  17286. - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  17287. - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  17288. - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17289. - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17290. - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17291. - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17292. + * This program is free software; you can redistribute it and/or modify it
  17293. + * under the terms of the GNU General Public License version 2 as published
  17294. + * by the Free Software Foundation.
  17295. */
  17296. #ifndef _LINUX_ATH9K_PLATFORM_H
  17297. @@ -23,6 +15,9 @@
  17298. struct ath9k_platform_data {
  17299. u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
  17300. + u8 *macaddr;
  17301. +
  17302. + unsigned long quirk_wndr3700:1;
  17303. };
  17304. #endif /* _LINUX_ATH9K_PLATFORM_H */
  17305. diff -Nur linux-2.6.34.orig/include/linux/gpio_buttons.h linux-2.6.34/include/linux/gpio_buttons.h
  17306. --- linux-2.6.34.orig/include/linux/gpio_buttons.h 1970-01-01 01:00:00.000000000 +0100
  17307. +++ linux-2.6.34/include/linux/gpio_buttons.h 2010-05-25 18:46:13.322223192 +0200
  17308. @@ -0,0 +1,33 @@
  17309. +/*
  17310. + * Definitions for the GPIO buttons interface driver
  17311. + *
  17312. + * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
  17313. + *
  17314. + * This file was based on: /include/linux/gpio_keys.h
  17315. + * The original gpio_keys.h seems not to have a license.
  17316. + *
  17317. + * This program is free software; you can redistribute it and/or modify
  17318. + * it under the terms of the GNU General Public License version 2 as
  17319. + * published by the Free Software Foundation.
  17320. + *
  17321. + */
  17322. +
  17323. +#ifndef _GPIO_BUTTONS_H_
  17324. +#define _GPIO_BUTTONS_H_
  17325. +
  17326. +struct gpio_button {
  17327. + int gpio; /* GPIO line number */
  17328. + int active_low;
  17329. + char *desc; /* button description */
  17330. + int type; /* input event type (EV_KEY, EV_SW) */
  17331. + int code; /* input event code (KEY_*, SW_*) */
  17332. + int threshold; /* count threshold */
  17333. +};
  17334. +
  17335. +struct gpio_buttons_platform_data {
  17336. + struct gpio_button *buttons;
  17337. + int nbuttons; /* number of buttons */
  17338. + int poll_interval; /* polling interval */
  17339. +};
  17340. +
  17341. +#endif /* _GPIO_BUTTONS_H_ */
  17342. diff -Nur linux-2.6.34.orig/include/linux/gpio_dev.h linux-2.6.34/include/linux/gpio_dev.h
  17343. --- linux-2.6.34.orig/include/linux/gpio_dev.h 1970-01-01 01:00:00.000000000 +0100
  17344. +++ linux-2.6.34/include/linux/gpio_dev.h 2010-05-25 18:46:13.380969951 +0200
  17345. @@ -0,0 +1,11 @@
  17346. +#ifndef _GPIODEV_H__
  17347. +#define _GPIODEV_H__
  17348. +
  17349. +#define IOC_GPIODEV_MAGIC 'B'
  17350. +#define GPIO_GET _IO(IOC_GPIODEV_MAGIC, 10)
  17351. +#define GPIO_SET _IO(IOC_GPIODEV_MAGIC, 11)
  17352. +#define GPIO_CLEAR _IO(IOC_GPIODEV_MAGIC, 12)
  17353. +#define GPIO_DIR_IN _IO(IOC_GPIODEV_MAGIC, 13)
  17354. +#define GPIO_DIR_OUT _IO(IOC_GPIODEV_MAGIC, 14)
  17355. +
  17356. +#endif
  17357. diff -Nur linux-2.6.34.orig/include/linux/netdevice.h linux-2.6.34/include/linux/netdevice.h
  17358. --- linux-2.6.34.orig/include/linux/netdevice.h 2010-05-16 23:17:36.000000000 +0200
  17359. +++ linux-2.6.34/include/linux/netdevice.h 2010-05-25 18:46:13.412222988 +0200
  17360. @@ -863,6 +863,7 @@
  17361. void *ax25_ptr; /* AX.25 specific data */
  17362. struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
  17363. assign before registering */
  17364. + void *phy_ptr; /* PHY device specific data */
  17365. /*
  17366. * Cache line mostly used on receive path (including eth_type_trans())
  17367. diff -Nur linux-2.6.34.orig/include/linux/nxp_74hc153.h linux-2.6.34/include/linux/nxp_74hc153.h
  17368. --- linux-2.6.34.orig/include/linux/nxp_74hc153.h 1970-01-01 01:00:00.000000000 +0100
  17369. +++ linux-2.6.34/include/linux/nxp_74hc153.h 2010-05-25 18:46:13.463473072 +0200
  17370. @@ -0,0 +1,24 @@
  17371. +/*
  17372. + * NXP 74HC153 - Dual 4-input multiplexer defines
  17373. + *
  17374. + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
  17375. + *
  17376. + * This program is free software; you can redistribute it and/or modify
  17377. + * it under the terms of the GNU General Public License version 2 as
  17378. + * published by the Free Software Foundation.
  17379. + */
  17380. +
  17381. +#ifndef _NXP_74HC153_H
  17382. +#define _NXP_74HC153_H
  17383. +
  17384. +#define NXP_74HC153_DRIVER_NAME "nxp-74hc153"
  17385. +
  17386. +struct nxp_74hc153_platform_data {
  17387. + unsigned gpio_base;
  17388. + unsigned gpio_pin_s0;
  17389. + unsigned gpio_pin_s1;
  17390. + unsigned gpio_pin_1y;
  17391. + unsigned gpio_pin_2y;
  17392. +};
  17393. +
  17394. +#endif /* _NXP_74HC153_H */
  17395. diff -Nur linux-2.6.34.orig/include/linux/phy.h linux-2.6.34/include/linux/phy.h
  17396. --- linux-2.6.34.orig/include/linux/phy.h 2010-05-16 23:17:36.000000000 +0200
  17397. +++ linux-2.6.34/include/linux/phy.h 2010-05-25 18:46:13.503473452 +0200
  17398. @@ -325,6 +325,20 @@
  17399. void (*adjust_link)(struct net_device *dev);
  17400. void (*adjust_state)(struct net_device *dev);
  17401. +
  17402. + /*
  17403. + * By default these point to the original functions
  17404. + * with the same name. adding them to the phy_device
  17405. + * allows the phy driver to override them for packet
  17406. + * mangling if the ethernet driver supports it
  17407. + * This is required to support some really horrible
  17408. + * switches such as the Marvell 88E6060
  17409. + */
  17410. + int (*netif_receive_skb)(struct sk_buff *skb);
  17411. + int (*netif_rx)(struct sk_buff *skb);
  17412. +
  17413. + /* alignment offset for packets */
  17414. + int pkt_align;
  17415. };
  17416. #define to_phy_device(d) container_of(d, struct phy_device, dev)
  17417. @@ -492,6 +506,7 @@
  17418. void phy_stop_machine(struct phy_device *phydev);
  17419. int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  17420. int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  17421. +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
  17422. int phy_mii_ioctl(struct phy_device *phydev,
  17423. struct mii_ioctl_data *mii_data, int cmd);
  17424. int phy_start_interrupts(struct phy_device *phydev);
  17425. diff -Nur linux-2.6.34.orig/include/linux/spi/vsc7385.h linux-2.6.34/include/linux/spi/vsc7385.h
  17426. --- linux-2.6.34.orig/include/linux/spi/vsc7385.h 1970-01-01 01:00:00.000000000 +0100
  17427. +++ linux-2.6.34/include/linux/spi/vsc7385.h 2010-05-25 18:46:13.540971583 +0200
  17428. @@ -0,0 +1,19 @@
  17429. +/*
  17430. + * Platform data definition for the Vitesse VSC7385 ethernet switch driver
  17431. + *
  17432. + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  17433. + *
  17434. + * This program is free software; you can redistribute it and/or modify it
  17435. + * under the terms of the GNU General Public License version 2 as published
  17436. + * by the Free Software Foundation.
  17437. + */
  17438. +
  17439. +struct vsc7385_platform_data {
  17440. + void (* reset)(void);
  17441. + char *ucode_name;
  17442. + struct {
  17443. + u32 tx_ipg:5;
  17444. + u32 bit2:1;
  17445. + u32 clk_sel:3;
  17446. + } mac_cfg;
  17447. +};
  17448. diff -Nur linux-2.6.34.orig/net/dsa/ar7240.c linux-2.6.34/net/dsa/ar7240.c
  17449. --- linux-2.6.34.orig/net/dsa/ar7240.c 1970-01-01 01:00:00.000000000 +0100
  17450. +++ linux-2.6.34/net/dsa/ar7240.c 2010-05-25 18:46:13.583464107 +0200
  17451. @@ -0,0 +1,736 @@
  17452. +/*
  17453. + * DSA driver for the built-in ethernet switch of the Atheros AR7240 SoC
  17454. + * Copyright (c) 2010 Gabor Juhos <juhosg@openwrt.org>
  17455. + *
  17456. + * This file was based on:
  17457. + * net/dsa/mv88e6060.c - Driver for Marvell 88e6060 switch chips
  17458. + * Copyright (c) 2008 Marvell Semiconductor
  17459. + *
  17460. + * This program is free software; you can redistribute it and/or modify it
  17461. + * under the terms of the GNU General Public License version 2 as published
  17462. + * by the Free Software Foundation.
  17463. + *
  17464. + */
  17465. +
  17466. +#include <linux/etherdevice.h>
  17467. +#include <linux/list.h>
  17468. +#include <linux/netdevice.h>
  17469. +#include <linux/phy.h>
  17470. +#include <linux/mii.h>
  17471. +#include <linux/bitops.h>
  17472. +
  17473. +#include "dsa_priv.h"
  17474. +
  17475. +#define BITM(_count) (BIT(_count) - 1)
  17476. +
  17477. +#define AR7240_REG_MASK_CTRL 0x00
  17478. +#define AR7240_MASK_CTRL_REVISION_M BITM(8)
  17479. +#define AR7240_MASK_CTRL_VERSION_M BITM(8)
  17480. +#define AR7240_MASK_CTRL_VERSION_S 8
  17481. +#define AR7240_MASK_CTRL_SOFT_RESET BIT(31)
  17482. +
  17483. +#define AR7240_REG_MAC_ADDR0 0x20
  17484. +#define AR7240_REG_MAC_ADDR1 0x24
  17485. +
  17486. +#define AR7240_REG_FLOOD_MASK 0x2c
  17487. +#define AR7240_FLOOD_MASK_BROAD_TO_CPU BIT(26)
  17488. +
  17489. +#define AR7240_REG_GLOBAL_CTRL 0x30
  17490. +#define AR7240_GLOBAL_CTRL_MTU_M BITM(12)
  17491. +
  17492. +#define AR7240_REG_AT_CTRL 0x5c
  17493. +#define AR7240_AT_CTRL_ARP_EN BIT(20)
  17494. +
  17495. +#define AR7240_REG_TAG_PRIORITY 0x70
  17496. +
  17497. +#define AR7240_REG_SERVICE_TAG 0x74
  17498. +#define AR7240_SERVICE_TAG_M BITM(16)
  17499. +
  17500. +#define AR7240_REG_CPU_PORT 0x78
  17501. +#define AR7240_MIRROR_PORT_S 4
  17502. +#define AR7240_CPU_PORT_EN BIT(8)
  17503. +
  17504. +#define AR7240_REG_MIB_FUNCTION0 0x80
  17505. +#define AR7240_MIB_TIMER_M BITM(16)
  17506. +#define AR7240_MIB_AT_HALF_EN BIT(16)
  17507. +#define AR7240_MIB_BUSY BIT(17)
  17508. +#define AR7240_MIB_FUNC_S 24
  17509. +#define AR7240_MIB_FUNC_NO_OP 0x0
  17510. +#define AR7240_MIB_FUNC_FLUSH 0x1
  17511. +#define AR7240_MIB_FUNC_CAPTURE 0x3
  17512. +
  17513. +#define AR7240_REG_MDIO_CTRL 0x98
  17514. +#define AR7240_MDIO_CTRL_DATA_M BITM(16)
  17515. +#define AR7240_MDIO_CTRL_REG_ADDR_S 16
  17516. +#define AR7240_MDIO_CTRL_PHY_ADDR_S 21
  17517. +#define AR7240_MDIO_CTRL_CMD_WRITE 0
  17518. +#define AR7240_MDIO_CTRL_CMD_READ BIT(27)
  17519. +#define AR7240_MDIO_CTRL_MASTER_EN BIT(30)
  17520. +#define AR7240_MDIO_CTRL_BUSY BIT(31)
  17521. +
  17522. +#define AR7240_REG_PORT_BASE(_port) (0x100 + (_port) * 0x100)
  17523. +
  17524. +#define AR7240_REG_PORT_STATUS(_port) (AR7240_REG_PORT_BASE((_port)) + 0x00)
  17525. +#define AR7240_PORT_STATUS_SPEED_M BITM(2)
  17526. +#define AR7240_PORT_STATUS_SPEED_10 0
  17527. +#define AR7240_PORT_STATUS_SPEED_100 1
  17528. +#define AR7240_PORT_STATUS_SPEED_1000 2
  17529. +#define AR7240_PORT_STATUS_TXMAC BIT(2)
  17530. +#define AR7240_PORT_STATUS_RXMAC BIT(3)
  17531. +#define AR7240_PORT_STATUS_TXFLOW BIT(4)
  17532. +#define AR7240_PORT_STATUS_RXFLOW BIT(5)
  17533. +#define AR7240_PORT_STATUS_DUPLEX BIT(6)
  17534. +#define AR7240_PORT_STATUS_LINK_UP BIT(8)
  17535. +#define AR7240_PORT_STATUS_LINK_AUTO BIT(9)
  17536. +#define AR7240_PORT_STATUS_LINK_PAUSE BIT(10)
  17537. +
  17538. +#define AR7240_REG_PORT_CTRL(_port) (AR7240_REG_PORT_BASE((_port)) + 0x04)
  17539. +#define AR7240_PORT_CTRL_STATE_M BITM(3)
  17540. +#define AR7240_PORT_CTRL_STATE_DISABLED 0
  17541. +#define AR7240_PORT_CTRL_STATE_BLOCK 1
  17542. +#define AR7240_PORT_CTRL_STATE_LISTEN 2
  17543. +#define AR7240_PORT_CTRL_STATE_LEARN 3
  17544. +#define AR7240_PORT_CTRL_STATE_FORWARD 4
  17545. +#define AR7240_PORT_CTRL_LEARN_LOCK BIT(7)
  17546. +#define AR7240_PORT_CTRL_VLAN_MODE_S 8
  17547. +#define AR7240_PORT_CTRL_VLAN_MODE_KEEP 0
  17548. +#define AR7240_PORT_CTRL_VLAN_MODE_STRIP 1
  17549. +#define AR7240_PORT_CTRL_VLAN_MODE_ADD 2
  17550. +#define AR7240_PORT_CTRL_VLAN_MODE_DOUBLE_TAG 3
  17551. +#define AR7240_PORT_CTRL_IGMP_SNOOP BIT(10)
  17552. +#define AR7240_PORT_CTRL_HEADER BIT(11)
  17553. +#define AR7240_PORT_CTRL_MAC_LOOP BIT(12)
  17554. +#define AR7240_PORT_CTRL_SINGLE_VLAN BIT(13)
  17555. +#define AR7240_PORT_CTRL_LEARN BIT(14)
  17556. +#define AR7240_PORT_CTRL_DOUBLE_TAG BIT(15)
  17557. +#define AR7240_PORT_CTRL_MIRROR_TX BIT(16)
  17558. +#define AR7240_PORT_CTRL_MIRROR_RX BIT(17)
  17559. +
  17560. +#define AR7240_REG_PORT_VLAN(_port) (AR7240_REG_PORT_BASE((_port)) + 0x08)
  17561. +
  17562. +#define AR7240_PORT_VLAN_DEFAULT_ID_S 0
  17563. +#define AR7240_PORT_VLAN_DEST_PORTS_S 16
  17564. +
  17565. +#define AR7240_REG_STATS_BASE(_port) (0x20000 + (_port) * 0x100)
  17566. +
  17567. +#define AR7240_STATS_RXBROAD 0x00
  17568. +#define AR7240_STATS_RXPAUSE 0x04
  17569. +#define AR7240_STATS_RXMULTI 0x08
  17570. +#define AR7240_STATS_RXFCSERR 0x0c
  17571. +#define AR7240_STATS_RXALIGNERR 0x10
  17572. +#define AR7240_STATS_RXRUNT 0x14
  17573. +#define AR7240_STATS_RXFRAGMENT 0x18
  17574. +#define AR7240_STATS_RX64BYTE 0x1c
  17575. +#define AR7240_STATS_RX128BYTE 0x20
  17576. +#define AR7240_STATS_RX256BYTE 0x24
  17577. +#define AR7240_STATS_RX512BYTE 0x28
  17578. +#define AR7240_STATS_RX1024BYTE 0x2c
  17579. +#define AR7240_STATS_RX1518BYTE 0x30
  17580. +#define AR7240_STATS_RXMAXBYTE 0x34
  17581. +#define AR7240_STATS_RXTOOLONG 0x38
  17582. +#define AR7240_STATS_RXGOODBYTE 0x3c
  17583. +#define AR7240_STATS_RXBADBYTE 0x44
  17584. +#define AR7240_STATS_RXOVERFLOW 0x4c
  17585. +#define AR7240_STATS_FILTERED 0x50
  17586. +#define AR7240_STATS_TXBROAD 0x54
  17587. +#define AR7240_STATS_TXPAUSE 0x58
  17588. +#define AR7240_STATS_TXMULTI 0x5c
  17589. +#define AR7240_STATS_TXUNDERRUN 0x60
  17590. +#define AR7240_STATS_TX64BYTE 0x64
  17591. +#define AR7240_STATS_TX128BYTE 0x68
  17592. +#define AR7240_STATS_TX256BYTE 0x6c
  17593. +#define AR7240_STATS_TX512BYTE 0x70
  17594. +#define AR7240_STATS_TX1024BYTE 0x74
  17595. +#define AR7240_STATS_TX1518BYTE 0x78
  17596. +#define AR7240_STATS_TXMAXBYTE 0x7c
  17597. +#define AR7240_STATS_TXOVERSIZE 0x80
  17598. +#define AR7240_STATS_TXBYTE 0x84
  17599. +#define AR7240_STATS_TXCOLLISION 0x8c
  17600. +#define AR7240_STATS_TXABORTCOL 0x90
  17601. +#define AR7240_STATS_TXMULTICOL 0x94
  17602. +#define AR7240_STATS_TXSINGLECOL 0x98
  17603. +#define AR7240_STATS_TXEXCDEFER 0x9c
  17604. +#define AR7240_STATS_TXDEFER 0xa0
  17605. +#define AR7240_STATS_TXLATECOL 0xa4
  17606. +
  17607. +#define AR7240_PORT_CPU 0
  17608. +#define AR7240_NUM_PORTS 6
  17609. +#define AR7240_NUM_PHYS 5
  17610. +
  17611. +#define AR7240_PHY_ID1 0x004d
  17612. +#define AR7240_PHY_ID2 0xd041
  17613. +
  17614. +#define AR7240_PORT_MASK(_port) BIT((_port))
  17615. +#define AR7240_PORT_MASK_ALL BITM(AR7240_NUM_PORTS)
  17616. +#define AR7240_PORT_MASK_BUT(_port) (AR7240_PORT_MASK_ALL & ~BIT((_port)))
  17617. +
  17618. +struct ar7240sw {
  17619. + struct mii_bus *mii_bus;
  17620. + struct mutex reg_mutex;
  17621. + struct mutex stats_mutex;
  17622. +};
  17623. +
  17624. +struct ar7240sw_hw_stat {
  17625. + char string[ETH_GSTRING_LEN];
  17626. + int sizeof_stat;
  17627. + int reg;
  17628. +};
  17629. +
  17630. +static inline struct ar7240sw *dsa_to_ar7240sw(struct dsa_switch *ds)
  17631. +{
  17632. + return (struct ar7240sw *)(ds + 1);
  17633. +}
  17634. +
  17635. +static inline void ar7240sw_init(struct ar7240sw *as, struct mii_bus *mii)
  17636. +{
  17637. + as->mii_bus = mii;
  17638. + mutex_init(&as->reg_mutex);
  17639. + mutex_init(&as->stats_mutex);
  17640. +}
  17641. +
  17642. +static inline u16 mk_phy_addr(u32 reg)
  17643. +{
  17644. + return (0x17 & ((reg >> 4) | 0x10));
  17645. +}
  17646. +
  17647. +static inline u16 mk_phy_reg(u32 reg)
  17648. +{
  17649. + return ((reg << 1) & 0x1e);
  17650. +}
  17651. +
  17652. +static inline u16 mk_high_addr(u32 reg)
  17653. +{
  17654. + return ((reg >> 7) & 0x1ff);
  17655. +}
  17656. +
  17657. +static u32 __ar7240sw_reg_read(struct ar7240sw *as, u32 reg)
  17658. +{
  17659. + struct mii_bus *mii = as->mii_bus;
  17660. + u16 phy_addr;
  17661. + u16 phy_reg;
  17662. + u32 hi, lo;
  17663. +
  17664. + reg = (reg & 0xfffffffc) >> 2;
  17665. +
  17666. + mdiobus_write(mii, 0x1f, 0x10, mk_high_addr(reg));
  17667. +
  17668. + phy_addr = mk_phy_addr(reg);
  17669. + phy_reg = mk_phy_reg(reg);
  17670. +
  17671. + lo = (u32) mdiobus_read(mii, phy_addr, phy_reg);
  17672. + hi = (u32) mdiobus_read(mii, phy_addr, phy_reg + 1);
  17673. +
  17674. + return ((hi << 16) | lo);
  17675. +}
  17676. +
  17677. +static void __ar7240sw_reg_write(struct ar7240sw *as, u32 reg, u32 val)
  17678. +{
  17679. + struct mii_bus *mii = as->mii_bus;
  17680. + u16 phy_addr;
  17681. + u16 phy_reg;
  17682. +
  17683. + reg = (reg & 0xfffffffc) >> 2;
  17684. +
  17685. + mdiobus_write(mii, 0x1f, 0x10, mk_high_addr(reg));
  17686. +
  17687. + phy_addr = mk_phy_addr(reg);
  17688. + phy_reg = mk_phy_reg(reg);
  17689. +
  17690. + mdiobus_write(mii, phy_addr, phy_reg + 1, (val >> 16));
  17691. + mdiobus_write(mii, phy_addr, phy_reg, (val & 0xffff));
  17692. +}
  17693. +
  17694. +static u32 ar7240sw_reg_read(struct ar7240sw *as, u32 reg_addr)
  17695. +{
  17696. + u32 ret;
  17697. +
  17698. + mutex_lock(&as->reg_mutex);
  17699. + ret = __ar7240sw_reg_read(as, reg_addr);
  17700. + mutex_unlock(&as->reg_mutex);
  17701. +
  17702. + return ret;
  17703. +}
  17704. +
  17705. +static void ar7240sw_reg_write(struct ar7240sw *as, u32 reg_addr, u32 reg_val)
  17706. +{
  17707. + mutex_lock(&as->reg_mutex);
  17708. + __ar7240sw_reg_write(as, reg_addr, reg_val);
  17709. + mutex_unlock(&as->reg_mutex);
  17710. +}
  17711. +
  17712. +static u32 ar7240sw_reg_rmw(struct ar7240sw *as, u32 reg, u32 mask, u32 val)
  17713. +{
  17714. + u32 t;
  17715. +
  17716. + mutex_lock(&as->reg_mutex);
  17717. + t = __ar7240sw_reg_read(as, reg);
  17718. + t &= ~mask;
  17719. + t |= val;
  17720. + __ar7240sw_reg_write(as, reg, t);
  17721. + mutex_unlock(&as->reg_mutex);
  17722. +
  17723. + return t;
  17724. +}
  17725. +
  17726. +static void ar7240sw_reg_set(struct ar7240sw *as, u32 reg, u32 val)
  17727. +{
  17728. + u32 t;
  17729. +
  17730. + mutex_lock(&as->reg_mutex);
  17731. + t = __ar7240sw_reg_read(as, reg);
  17732. + t |= val;
  17733. + __ar7240sw_reg_write(as, reg, t);
  17734. + mutex_unlock(&as->reg_mutex);
  17735. +}
  17736. +
  17737. +static int ar7240sw_reg_wait(struct ar7240sw *as, u32 reg, u32 mask, u32 val,
  17738. + unsigned timeout)
  17739. +{
  17740. + int i;
  17741. +
  17742. + for (i = 0; i < timeout; i++) {
  17743. + u32 t;
  17744. +
  17745. + t = ar7240sw_reg_read(as, reg);
  17746. + if ((t & mask) == val)
  17747. + return 0;
  17748. +
  17749. + msleep(1);
  17750. + }
  17751. +
  17752. + return -ETIMEDOUT;
  17753. +}
  17754. +
  17755. +static u16 ar7240sw_phy_read(struct ar7240sw *as, unsigned phy_addr,
  17756. + unsigned reg_addr)
  17757. +{
  17758. + u32 t;
  17759. + int err;
  17760. +
  17761. + if (phy_addr >= AR7240_NUM_PHYS)
  17762. + return 0xffff;
  17763. +
  17764. + t = (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  17765. + (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  17766. + AR7240_MDIO_CTRL_MASTER_EN |
  17767. + AR7240_MDIO_CTRL_BUSY |
  17768. + AR7240_MDIO_CTRL_CMD_READ;
  17769. +
  17770. + ar7240sw_reg_write(as, AR7240_REG_MDIO_CTRL, t);
  17771. + err = ar7240sw_reg_wait(as, AR7240_REG_MDIO_CTRL,
  17772. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  17773. + if (err)
  17774. + return 0xffff;
  17775. +
  17776. + t = ar7240sw_reg_read(as, AR7240_REG_MDIO_CTRL);
  17777. + return (t & AR7240_MDIO_CTRL_DATA_M);
  17778. +}
  17779. +
  17780. +static int ar7240sw_phy_write(struct ar7240sw *as, unsigned phy_addr,
  17781. + unsigned reg_addr, u16 reg_val)
  17782. +{
  17783. + u32 t;
  17784. + int ret;
  17785. +
  17786. + if (phy_addr >= AR7240_NUM_PHYS)
  17787. + return -EINVAL;
  17788. +
  17789. + t = (phy_addr << AR7240_MDIO_CTRL_PHY_ADDR_S) |
  17790. + (reg_addr << AR7240_MDIO_CTRL_REG_ADDR_S) |
  17791. + AR7240_MDIO_CTRL_MASTER_EN |
  17792. + AR7240_MDIO_CTRL_BUSY |
  17793. + AR7240_MDIO_CTRL_CMD_WRITE |
  17794. + reg_val;
  17795. +
  17796. + ar7240sw_reg_write(as, AR7240_REG_MDIO_CTRL, t);
  17797. + ret = ar7240sw_reg_wait(as, AR7240_REG_MDIO_CTRL,
  17798. + AR7240_MDIO_CTRL_BUSY, 0, 5);
  17799. + return ret;
  17800. +}
  17801. +
  17802. +static int ar7240sw_capture_stats(struct ar7240sw *as)
  17803. +{
  17804. + int ret;
  17805. +
  17806. + /* Capture the hardware statistics for all ports */
  17807. + ar7240sw_reg_write(as, AR7240_REG_MIB_FUNCTION0,
  17808. + (AR7240_MIB_FUNC_CAPTURE << AR7240_MIB_FUNC_S));
  17809. +
  17810. + /* Wait for the capturing to complete. */
  17811. + ret = ar7240sw_reg_wait(as, AR7240_REG_MIB_FUNCTION0,
  17812. + AR7240_MIB_BUSY, 0, 10);
  17813. + return ret;
  17814. +}
  17815. +
  17816. +static void ar7240sw_disable_port(struct ar7240sw *as, unsigned port)
  17817. +{
  17818. + ar7240sw_reg_write(as, AR7240_REG_PORT_CTRL(port),
  17819. + AR7240_PORT_CTRL_STATE_DISABLED);
  17820. +}
  17821. +
  17822. +static int ar7240sw_reset(struct ar7240sw *as)
  17823. +{
  17824. + int ret;
  17825. + int i;
  17826. +
  17827. + /* Set all ports to disabled state. */
  17828. + for (i = 0; i < AR7240_NUM_PORTS; i++)
  17829. + ar7240sw_disable_port(as, i);
  17830. +
  17831. + /* Wait for transmit queues to drain. */
  17832. + msleep(2);
  17833. +
  17834. + /* Reset the switch. */
  17835. + ar7240sw_reg_write(as, AR7240_REG_MASK_CTRL,
  17836. + AR7240_MASK_CTRL_SOFT_RESET);
  17837. +
  17838. + ret = ar7240sw_reg_wait(as, AR7240_REG_MASK_CTRL,
  17839. + AR7240_MASK_CTRL_SOFT_RESET, 0, 1000);
  17840. + return ret;
  17841. +}
  17842. +
  17843. +static void ar7240sw_setup(struct ar7240sw *as)
  17844. +{
  17845. + /* Enable CPU port, and disable mirror port */
  17846. + ar7240sw_reg_write(as, AR7240_REG_CPU_PORT,
  17847. + AR7240_CPU_PORT_EN |
  17848. + (15 << AR7240_MIRROR_PORT_S));
  17849. +
  17850. + /* Setup TAG priority mapping */
  17851. + ar7240sw_reg_write(as, AR7240_REG_TAG_PRIORITY, 0xfa50);
  17852. +
  17853. + /* Enable ARP frame acknowledge */
  17854. + ar7240sw_reg_set(as, AR7240_REG_AT_CTRL, AR7240_AT_CTRL_ARP_EN);
  17855. +
  17856. + /* Enable Broadcast frames transmitted to the CPU */
  17857. + ar7240sw_reg_set(as, AR7240_REG_FLOOD_MASK,
  17858. + AR7240_FLOOD_MASK_BROAD_TO_CPU);
  17859. +
  17860. + /* setup MTU */
  17861. + ar7240sw_reg_rmw(as, AR7240_REG_GLOBAL_CTRL, AR7240_GLOBAL_CTRL_MTU_M,
  17862. + 1536);
  17863. +
  17864. + /* setup Service TAG */
  17865. + ar7240sw_reg_rmw(as, AR7240_REG_SERVICE_TAG, AR7240_SERVICE_TAG_M,
  17866. + ETH_P_QINQ);
  17867. +}
  17868. +
  17869. +static void ar7240sw_setup_port(struct ar7240sw *as, unsigned port)
  17870. +{
  17871. + u32 ctrl;
  17872. + u32 dest_ports;
  17873. + u32 vlan;
  17874. +
  17875. + ctrl = AR7240_PORT_CTRL_STATE_FORWARD;
  17876. +
  17877. + if (port == AR7240_PORT_CPU) {
  17878. + ar7240sw_reg_write(as, AR7240_REG_PORT_STATUS(port),
  17879. + AR7240_PORT_STATUS_SPEED_1000 |
  17880. + AR7240_PORT_STATUS_TXFLOW |
  17881. + AR7240_PORT_STATUS_RXFLOW |
  17882. + AR7240_PORT_STATUS_TXMAC |
  17883. + AR7240_PORT_STATUS_RXMAC |
  17884. + AR7240_PORT_STATUS_DUPLEX);
  17885. +
  17886. + /* allow the CPU port to talk to each of the 'real' ports */
  17887. + dest_ports = AR7240_PORT_MASK_BUT(port);
  17888. +
  17889. + /* remove service tag from ingress frames */
  17890. + ctrl |= AR7240_PORT_CTRL_DOUBLE_TAG;
  17891. + } else {
  17892. + ar7240sw_reg_write(as, AR7240_REG_PORT_STATUS(port),
  17893. + AR7240_PORT_STATUS_LINK_AUTO);
  17894. +
  17895. + /*
  17896. + * allow each of the 'real' ports to only talk to the CPU
  17897. + * port.
  17898. + */
  17899. + dest_ports = AR7240_PORT_MASK(port) |
  17900. + AR7240_PORT_MASK(AR7240_PORT_CPU);
  17901. +
  17902. + /* add service tag to egress frames */
  17903. + ctrl |= (AR7240_PORT_CTRL_VLAN_MODE_DOUBLE_TAG <<
  17904. + AR7240_PORT_CTRL_VLAN_MODE_S);
  17905. + }
  17906. +
  17907. + /* set default VID and and destination ports for this VLAN */
  17908. + vlan = port;
  17909. + vlan |= (dest_ports << AR7240_PORT_VLAN_DEST_PORTS_S);
  17910. +
  17911. + ar7240sw_reg_write(as, AR7240_REG_PORT_CTRL(port), ctrl);
  17912. + ar7240sw_reg_write(as, AR7240_REG_PORT_VLAN(port), vlan);
  17913. +}
  17914. +
  17915. +static char *ar7240_dsa_probe(struct mii_bus *mii, int sw_addr)
  17916. +{
  17917. + struct ar7240sw as;
  17918. + u32 ctrl;
  17919. + u16 phy_id1;
  17920. + u16 phy_id2;
  17921. + u8 ver;
  17922. +
  17923. + ar7240sw_init(&as, mii);
  17924. +
  17925. + ctrl = ar7240sw_reg_read(&as, AR7240_REG_MASK_CTRL);
  17926. +
  17927. + ver = (ctrl >> AR7240_MASK_CTRL_VERSION_S) & AR7240_MASK_CTRL_VERSION_M;
  17928. + if (ver != 1) {
  17929. + pr_err("ar7240_dsa: unsupported chip, ctrl=%08x\n", ctrl);
  17930. + return NULL;
  17931. + }
  17932. +
  17933. + phy_id1 = ar7240sw_phy_read(&as, 0, MII_PHYSID1);
  17934. + phy_id2 = ar7240sw_phy_read(&as, 0, MII_PHYSID2);
  17935. + if (phy_id1 != AR7240_PHY_ID1 || phy_id2 != AR7240_PHY_ID2) {
  17936. + pr_err("ar7240_dsa: unknown phy id '%04x:%04x'\n",
  17937. + phy_id1, phy_id2);
  17938. + return NULL;
  17939. + }
  17940. +
  17941. + return "Atheros AR7240 built-in";
  17942. +}
  17943. +
  17944. +static int ar7240_dsa_setup(struct dsa_switch *ds)
  17945. +{
  17946. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  17947. + int i;
  17948. + int ret;
  17949. +
  17950. + ar7240sw_init(as, ds->master_mii_bus);
  17951. +
  17952. + ret = ar7240sw_reset(as);
  17953. + if (ret)
  17954. + return ret;
  17955. +
  17956. + ar7240sw_setup(as);
  17957. +
  17958. + for (i = 0; i < AR7240_NUM_PORTS; i++) {
  17959. + if (dsa_is_cpu_port(ds, i) || (ds->phys_port_mask & (1 << i)))
  17960. + ar7240sw_setup_port(as, i);
  17961. + else
  17962. + ar7240sw_disable_port(as, i);
  17963. + }
  17964. +
  17965. + return 0;
  17966. +}
  17967. +
  17968. +static int ar7240_dsa_set_addr(struct dsa_switch *ds, u8 *addr)
  17969. +{
  17970. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  17971. + u32 t;
  17972. +
  17973. + t = (addr[4] << 8) | addr[5];
  17974. + ar7240sw_reg_write(as, AR7240_REG_MAC_ADDR0, t);
  17975. +
  17976. + t = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
  17977. + ar7240sw_reg_write(as, AR7240_REG_MAC_ADDR1, t);
  17978. +
  17979. + return 0;
  17980. +}
  17981. +
  17982. +static int ar7240_iort_to_phy_addr(int port)
  17983. +{
  17984. + if (port > 0 && port < AR7240_NUM_PORTS)
  17985. + return port - 1;
  17986. +
  17987. + return -EINVAL;
  17988. +}
  17989. +
  17990. +static int ar7240_dsa_phy_read(struct dsa_switch *ds, int port, int regnum)
  17991. +{
  17992. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  17993. + int phy_addr;
  17994. +
  17995. + phy_addr = ar7240_iort_to_phy_addr(port);
  17996. + if (phy_addr < 0)
  17997. + return 0xffff;
  17998. +
  17999. + return ar7240sw_phy_read(as, phy_addr, regnum);
  18000. +}
  18001. +
  18002. +static int ar7240_dsa_phy_write(struct dsa_switch *ds, int port, int regnum,
  18003. + u16 val)
  18004. +{
  18005. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18006. + int phy_addr;
  18007. +
  18008. + phy_addr = ar7240_iort_to_phy_addr(port);
  18009. + if (phy_addr < 0)
  18010. + return 0xffff;
  18011. +
  18012. + return ar7240sw_phy_write(as, phy_addr, regnum, val);
  18013. +}
  18014. +
  18015. +static const char *ar7240sw_speed_str(unsigned speed)
  18016. +{
  18017. + switch (speed) {
  18018. + case AR7240_PORT_STATUS_SPEED_10:
  18019. + return "10";
  18020. + case AR7240_PORT_STATUS_SPEED_100:
  18021. + return "100";
  18022. + case AR7240_PORT_STATUS_SPEED_1000:
  18023. + return "1000";
  18024. + }
  18025. +
  18026. + return "????";
  18027. +}
  18028. +
  18029. +static void ar7240_dsa_poll_link(struct dsa_switch *ds)
  18030. +{
  18031. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18032. + int i;
  18033. +
  18034. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  18035. + struct net_device *dev;
  18036. + u32 status;
  18037. + int link;
  18038. + unsigned speed;
  18039. + int duplex;
  18040. +
  18041. + dev = ds->ports[i];
  18042. + if (dev == NULL)
  18043. + continue;
  18044. +
  18045. + link = 0;
  18046. + if (dev->flags & IFF_UP) {
  18047. + status = ar7240sw_reg_read(as,
  18048. + AR7240_REG_PORT_STATUS(i));
  18049. + link = !!(status & AR7240_PORT_STATUS_LINK_UP);
  18050. + }
  18051. +
  18052. + if (!link) {
  18053. + if (netif_carrier_ok(dev)) {
  18054. + pr_info("%s: link down\n", dev->name);
  18055. + netif_carrier_off(dev);
  18056. + }
  18057. + continue;
  18058. + }
  18059. +
  18060. + speed = (status & AR7240_PORT_STATUS_SPEED_M);
  18061. + duplex = (status & AR7240_PORT_STATUS_DUPLEX) ? 1 : 0;
  18062. + if (!netif_carrier_ok(dev)) {
  18063. + pr_info("%s: link up, %sMb/s, %s duplex",
  18064. + dev->name,
  18065. + ar7240sw_speed_str(speed),
  18066. + duplex ? "full" : "half");
  18067. + netif_carrier_on(dev);
  18068. + }
  18069. + }
  18070. +}
  18071. +
  18072. +static const struct ar7240sw_hw_stat ar7240_hw_stats[] = {
  18073. + { "rx_broadcast" , 4, AR7240_STATS_RXBROAD, },
  18074. + { "rx_pause" , 4, AR7240_STATS_RXPAUSE, },
  18075. + { "rx_multicast" , 4, AR7240_STATS_RXMULTI, },
  18076. + { "rx_fcs_error" , 4, AR7240_STATS_RXFCSERR, },
  18077. + { "rx_align_error" , 4, AR7240_STATS_RXALIGNERR, },
  18078. + { "rx_undersize" , 4, AR7240_STATS_RXRUNT, },
  18079. + { "rx_fragments" , 4, AR7240_STATS_RXFRAGMENT, },
  18080. + { "rx_64bytes" , 4, AR7240_STATS_RX64BYTE, },
  18081. + { "rx_65_127bytes" , 4, AR7240_STATS_RX128BYTE, },
  18082. + { "rx_128_255bytes" , 4, AR7240_STATS_RX256BYTE, },
  18083. + { "rx_256_511bytes" , 4, AR7240_STATS_RX512BYTE, },
  18084. + { "rx_512_1023bytes" , 4, AR7240_STATS_RX1024BYTE, },
  18085. + { "rx_1024_1518bytes" , 4, AR7240_STATS_RX1518BYTE, },
  18086. + { "rx_1519_max_bytes" , 4, AR7240_STATS_RXMAXBYTE, },
  18087. + { "rx_oversize" , 4, AR7240_STATS_RXTOOLONG, },
  18088. + { "rx_good_bytes" , 8, AR7240_STATS_RXGOODBYTE, },
  18089. + { "rx_bad_bytes" , 8, AR7240_STATS_RXBADBYTE, },
  18090. + { "rx_overflow" , 4, AR7240_STATS_RXOVERFLOW, },
  18091. + { "filtered" , 4, AR7240_STATS_FILTERED, },
  18092. + { "tx_broadcast" , 4, AR7240_STATS_TXBROAD, },
  18093. + { "tx_pause" , 4, AR7240_STATS_TXPAUSE, },
  18094. + { "tx_multicast" , 4, AR7240_STATS_TXMULTI, },
  18095. + { "tx_underrun" , 4, AR7240_STATS_TXUNDERRUN, },
  18096. + { "tx_64bytes" , 4, AR7240_STATS_TX64BYTE, },
  18097. + { "tx_65_127bytes" , 4, AR7240_STATS_TX128BYTE, },
  18098. + { "tx_128_255bytes" , 4, AR7240_STATS_TX256BYTE, },
  18099. + { "tx_256_511bytes" , 4, AR7240_STATS_TX512BYTE, },
  18100. + { "tx_512_1023bytes" , 4, AR7240_STATS_TX1024BYTE, },
  18101. + { "tx_1024_1518bytes" , 4, AR7240_STATS_TX1518BYTE, },
  18102. + { "tx_1519_max_bytes" , 4, AR7240_STATS_TXMAXBYTE, },
  18103. + { "tx_oversize" , 4, AR7240_STATS_TXOVERSIZE, },
  18104. + { "tx_bytes" , 8, AR7240_STATS_TXBYTE, },
  18105. + { "tx_collisions" , 4, AR7240_STATS_TXCOLLISION, },
  18106. + { "tx_abort_collisions" , 4, AR7240_STATS_TXABORTCOL, },
  18107. + { "tx_multi_collisions" , 4, AR7240_STATS_TXMULTICOL, },
  18108. + { "tx_single_collisions", 4, AR7240_STATS_TXSINGLECOL, },
  18109. + { "tx_excessive_deferred", 4, AR7240_STATS_TXEXCDEFER, },
  18110. + { "tx_deferred" , 4, AR7240_STATS_TXDEFER, },
  18111. + { "tx_late_collisions" , 4, AR7240_STATS_TXLATECOL, },
  18112. +};
  18113. +
  18114. +static void ar7240_dsa_get_strings(struct dsa_switch *ds, int port,
  18115. + uint8_t *data)
  18116. +{
  18117. + int i;
  18118. +
  18119. + for (i = 0; i < ARRAY_SIZE(ar7240_hw_stats); i++) {
  18120. + memcpy(data + i * ETH_GSTRING_LEN,
  18121. + ar7240_hw_stats[i].string, ETH_GSTRING_LEN);
  18122. + }
  18123. +}
  18124. +
  18125. +static void ar7240_dsa_get_ethtool_stats(struct dsa_switch *ds, int port,
  18126. + uint64_t *data)
  18127. +{
  18128. + struct ar7240sw *as = dsa_to_ar7240sw(ds);
  18129. + int err;
  18130. + int i;
  18131. +
  18132. + mutex_lock(&as->stats_mutex);
  18133. +
  18134. + err = ar7240sw_capture_stats(as);
  18135. + if (err)
  18136. + goto unlock;
  18137. +
  18138. + for (i = 0; i < ARRAY_SIZE(ar7240_hw_stats); i++) {
  18139. + const struct ar7240sw_hw_stat *s = &ar7240_hw_stats[i];
  18140. + u32 reg = AR7240_REG_STATS_BASE(port);
  18141. + u32 low;
  18142. + u32 high;
  18143. +
  18144. + low = ar7240sw_reg_read(as, reg + s->reg);
  18145. + if (s->sizeof_stat == 8)
  18146. + high = ar7240sw_reg_read(as, reg + s->reg);
  18147. + else
  18148. + high = 0;
  18149. +
  18150. + data[i] = (((u64) high) << 32) | low;
  18151. + }
  18152. +
  18153. + unlock:
  18154. + mutex_unlock(&as->stats_mutex);
  18155. +}
  18156. +
  18157. +static int ar7240_dsa_get_sset_count(struct dsa_switch *ds)
  18158. +{
  18159. + return ARRAY_SIZE(ar7240_hw_stats);
  18160. +}
  18161. +
  18162. +static struct dsa_switch_driver ar7240_dsa_driver = {
  18163. + .tag_protocol = htons(ETH_P_QINQ),
  18164. + .priv_size = sizeof(struct ar7240sw),
  18165. + .probe = ar7240_dsa_probe,
  18166. + .setup = ar7240_dsa_setup,
  18167. + .set_addr = ar7240_dsa_set_addr,
  18168. + .phy_read = ar7240_dsa_phy_read,
  18169. + .phy_write = ar7240_dsa_phy_write,
  18170. + .poll_link = ar7240_dsa_poll_link,
  18171. + .get_strings = ar7240_dsa_get_strings,
  18172. + .get_ethtool_stats = ar7240_dsa_get_ethtool_stats,
  18173. + .get_sset_count = ar7240_dsa_get_sset_count,
  18174. +};
  18175. +
  18176. +int __init dsa_ar7240_init(void)
  18177. +{
  18178. + register_switch_driver(&ar7240_dsa_driver);
  18179. + return 0;
  18180. +}
  18181. +module_init(dsa_ar7240_init);
  18182. +
  18183. +void __exit dsa_ar7240_cleanup(void)
  18184. +{
  18185. + unregister_switch_driver(&ar7240_dsa_driver);
  18186. +}
  18187. +module_exit(dsa_ar7240_cleanup);
  18188. diff -Nur linux-2.6.34.orig/net/dsa/mv88e6063.c linux-2.6.34/net/dsa/mv88e6063.c
  18189. --- linux-2.6.34.orig/net/dsa/mv88e6063.c 1970-01-01 01:00:00.000000000 +0100
  18190. +++ linux-2.6.34/net/dsa/mv88e6063.c 2010-05-25 18:46:13.623464081 +0200
  18191. @@ -0,0 +1,294 @@
  18192. +/*
  18193. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6063 switch chips
  18194. + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
  18195. + *
  18196. + * This driver was base on: net/dsa/mv88e6060.c
  18197. + * net/dsa/mv88e6063.c - Driver for Marvell 88e6060 switch chips
  18198. + * Copyright (c) 2008-2009 Marvell Semiconductor
  18199. + *
  18200. + * This program is free software; you can redistribute it and/or modify
  18201. + * it under the terms of the GNU General Public License as published by
  18202. + * the Free Software Foundation; either version 2 of the License, or
  18203. + * (at your option) any later version.
  18204. + */
  18205. +
  18206. +#include <linux/list.h>
  18207. +#include <linux/netdevice.h>
  18208. +#include <linux/phy.h>
  18209. +#include "dsa_priv.h"
  18210. +
  18211. +#define REG_BASE 0x10
  18212. +#define REG_PHY(p) (REG_BASE + (p))
  18213. +#define REG_PORT(p) (REG_BASE + 8 + (p))
  18214. +#define REG_GLOBAL (REG_BASE + 0x0f)
  18215. +#define NUM_PORTS 7
  18216. +
  18217. +static int reg_read(struct dsa_switch *ds, int addr, int reg)
  18218. +{
  18219. + return mdiobus_read(ds->master_mii_bus, addr, reg);
  18220. +}
  18221. +
  18222. +#define REG_READ(addr, reg) \
  18223. + ({ \
  18224. + int __ret; \
  18225. + \
  18226. + __ret = reg_read(ds, addr, reg); \
  18227. + if (__ret < 0) \
  18228. + return __ret; \
  18229. + __ret; \
  18230. + })
  18231. +
  18232. +
  18233. +static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
  18234. +{
  18235. + return mdiobus_write(ds->master_mii_bus, addr, reg, val);
  18236. +}
  18237. +
  18238. +#define REG_WRITE(addr, reg, val) \
  18239. + ({ \
  18240. + int __ret; \
  18241. + \
  18242. + __ret = reg_write(ds, addr, reg, val); \
  18243. + if (__ret < 0) \
  18244. + return __ret; \
  18245. + })
  18246. +
  18247. +static char *mv88e6063_probe(struct mii_bus *bus, int sw_addr)
  18248. +{
  18249. + int ret;
  18250. +
  18251. + ret = mdiobus_read(bus, REG_PORT(0), 0x03);
  18252. + if (ret >= 0) {
  18253. + ret &= 0xfff0;
  18254. + if (ret == 0x1530)
  18255. + return "Marvell 88E6063";
  18256. + }
  18257. +
  18258. + return NULL;
  18259. +}
  18260. +
  18261. +static int mv88e6063_switch_reset(struct dsa_switch *ds)
  18262. +{
  18263. + int i;
  18264. + int ret;
  18265. +
  18266. + /*
  18267. + * Set all ports to the disabled state.
  18268. + */
  18269. + for (i = 0; i < NUM_PORTS; i++) {
  18270. + ret = REG_READ(REG_PORT(i), 0x04);
  18271. + REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  18272. + }
  18273. +
  18274. + /*
  18275. + * Wait for transmit queues to drain.
  18276. + */
  18277. + msleep(2);
  18278. +
  18279. + /*
  18280. + * Reset the switch.
  18281. + */
  18282. + REG_WRITE(REG_GLOBAL, 0x0a, 0xa130);
  18283. +
  18284. + /*
  18285. + * Wait up to one second for reset to complete.
  18286. + */
  18287. + for (i = 0; i < 1000; i++) {
  18288. + ret = REG_READ(REG_GLOBAL, 0x00);
  18289. + if ((ret & 0x8000) == 0x0000)
  18290. + break;
  18291. +
  18292. + msleep(1);
  18293. + }
  18294. + if (i == 1000)
  18295. + return -ETIMEDOUT;
  18296. +
  18297. + return 0;
  18298. +}
  18299. +
  18300. +static int mv88e6063_setup_global(struct dsa_switch *ds)
  18301. +{
  18302. + /*
  18303. + * Disable discarding of frames with excessive collisions,
  18304. + * set the maximum frame size to 1536 bytes, and mask all
  18305. + * interrupt sources.
  18306. + */
  18307. + REG_WRITE(REG_GLOBAL, 0x04, 0x0800);
  18308. +
  18309. + /*
  18310. + * Enable automatic address learning, set the address
  18311. + * database size to 1024 entries, and set the default aging
  18312. + * time to 5 minutes.
  18313. + */
  18314. + REG_WRITE(REG_GLOBAL, 0x0a, 0x2130);
  18315. +
  18316. + return 0;
  18317. +}
  18318. +
  18319. +static int mv88e6063_setup_port(struct dsa_switch *ds, int p)
  18320. +{
  18321. + int addr = REG_PORT(p);
  18322. +
  18323. + /*
  18324. + * Do not force flow control, disable Ingress and Egress
  18325. + * Header tagging, disable VLAN tunneling, and set the port
  18326. + * state to Forwarding. Additionally, if this is the CPU
  18327. + * port, enable Ingress and Egress Trailer tagging mode.
  18328. + */
  18329. + REG_WRITE(addr, 0x04, dsa_is_cpu_port(ds, p) ? 0x4103 : 0x0003);
  18330. +
  18331. + /*
  18332. + * Port based VLAN map: give each port its own address
  18333. + * database, allow the CPU port to talk to each of the 'real'
  18334. + * ports, and allow each of the 'real' ports to only talk to
  18335. + * the CPU port.
  18336. + */
  18337. + REG_WRITE(addr, 0x06,
  18338. + ((p & 0xf) << 12) |
  18339. + (dsa_is_cpu_port(ds, p) ?
  18340. + ds->phys_port_mask :
  18341. + (1 << ds->dst->cpu_port)));
  18342. +
  18343. + /*
  18344. + * Port Association Vector: when learning source addresses
  18345. + * of packets, add the address to the address database using
  18346. + * a port bitmap that has only the bit for this port set and
  18347. + * the other bits clear.
  18348. + */
  18349. + REG_WRITE(addr, 0x0b, 1 << p);
  18350. +
  18351. + return 0;
  18352. +}
  18353. +
  18354. +static int mv88e6063_setup(struct dsa_switch *ds)
  18355. +{
  18356. + int i;
  18357. + int ret;
  18358. +
  18359. + ret = mv88e6063_switch_reset(ds);
  18360. + if (ret < 0)
  18361. + return ret;
  18362. +
  18363. + /* @@@ initialise atu */
  18364. +
  18365. + ret = mv88e6063_setup_global(ds);
  18366. + if (ret < 0)
  18367. + return ret;
  18368. +
  18369. + for (i = 0; i < NUM_PORTS; i++) {
  18370. + ret = mv88e6063_setup_port(ds, i);
  18371. + if (ret < 0)
  18372. + return ret;
  18373. + }
  18374. +
  18375. + return 0;
  18376. +}
  18377. +
  18378. +static int mv88e6063_set_addr(struct dsa_switch *ds, u8 *addr)
  18379. +{
  18380. + REG_WRITE(REG_GLOBAL, 0x01, (addr[0] << 8) | addr[1]);
  18381. + REG_WRITE(REG_GLOBAL, 0x02, (addr[2] << 8) | addr[3]);
  18382. + REG_WRITE(REG_GLOBAL, 0x03, (addr[4] << 8) | addr[5]);
  18383. +
  18384. + return 0;
  18385. +}
  18386. +
  18387. +static int mv88e6063_port_to_phy_addr(int port)
  18388. +{
  18389. + if (port >= 0 && port <= NUM_PORTS)
  18390. + return REG_PHY(port);
  18391. + return -1;
  18392. +}
  18393. +
  18394. +static int mv88e6063_phy_read(struct dsa_switch *ds, int port, int regnum)
  18395. +{
  18396. + int addr;
  18397. +
  18398. + addr = mv88e6063_port_to_phy_addr(port);
  18399. + if (addr == -1)
  18400. + return 0xffff;
  18401. +
  18402. + return reg_read(ds, addr, regnum);
  18403. +}
  18404. +
  18405. +static int
  18406. +mv88e6063_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
  18407. +{
  18408. + int addr;
  18409. +
  18410. + addr = mv88e6063_port_to_phy_addr(port);
  18411. + if (addr == -1)
  18412. + return 0xffff;
  18413. +
  18414. + return reg_write(ds, addr, regnum, val);
  18415. +}
  18416. +
  18417. +static void mv88e6063_poll_link(struct dsa_switch *ds)
  18418. +{
  18419. + int i;
  18420. +
  18421. + for (i = 0; i < DSA_MAX_PORTS; i++) {
  18422. + struct net_device *dev;
  18423. + int uninitialized_var(port_status);
  18424. + int link;
  18425. + int speed;
  18426. + int duplex;
  18427. + int fc;
  18428. +
  18429. + dev = ds->ports[i];
  18430. + if (dev == NULL)
  18431. + continue;
  18432. +
  18433. + link = 0;
  18434. + if (dev->flags & IFF_UP) {
  18435. + port_status = reg_read(ds, REG_PORT(i), 0x00);
  18436. + if (port_status < 0)
  18437. + continue;
  18438. +
  18439. + link = !!(port_status & 0x1000);
  18440. + }
  18441. +
  18442. + if (!link) {
  18443. + if (netif_carrier_ok(dev)) {
  18444. + printk(KERN_INFO "%s: link down\n", dev->name);
  18445. + netif_carrier_off(dev);
  18446. + }
  18447. + continue;
  18448. + }
  18449. +
  18450. + speed = (port_status & 0x0100) ? 100 : 10;
  18451. + duplex = (port_status & 0x0200) ? 1 : 0;
  18452. + fc = ((port_status & 0xc000) == 0xc000) ? 1 : 0;
  18453. +
  18454. + if (!netif_carrier_ok(dev)) {
  18455. + printk(KERN_INFO "%s: link up, %d Mb/s, %s duplex, "
  18456. + "flow control %sabled\n", dev->name,
  18457. + speed, duplex ? "full" : "half",
  18458. + fc ? "en" : "dis");
  18459. + netif_carrier_on(dev);
  18460. + }
  18461. + }
  18462. +}
  18463. +
  18464. +static struct dsa_switch_driver mv88e6063_switch_driver = {
  18465. + .tag_protocol = htons(ETH_P_TRAILER),
  18466. + .probe = mv88e6063_probe,
  18467. + .setup = mv88e6063_setup,
  18468. + .set_addr = mv88e6063_set_addr,
  18469. + .phy_read = mv88e6063_phy_read,
  18470. + .phy_write = mv88e6063_phy_write,
  18471. + .poll_link = mv88e6063_poll_link,
  18472. +};
  18473. +
  18474. +static int __init mv88e6063_init(void)
  18475. +{
  18476. + register_switch_driver(&mv88e6063_switch_driver);
  18477. + return 0;
  18478. +}
  18479. +module_init(mv88e6063_init);
  18480. +
  18481. +static void __exit mv88e6063_cleanup(void)
  18482. +{
  18483. + unregister_switch_driver(&mv88e6063_switch_driver);
  18484. +}
  18485. +module_exit(mv88e6063_cleanup);
  18486. diff -Nur linux-2.6.34.orig/net/dsa/tag_qinq.c linux-2.6.34/net/dsa/tag_qinq.c
  18487. --- linux-2.6.34.orig/net/dsa/tag_qinq.c 1970-01-01 01:00:00.000000000 +0100
  18488. +++ linux-2.6.34/net/dsa/tag_qinq.c 2010-05-25 18:46:13.663473277 +0200
  18489. @@ -0,0 +1,127 @@
  18490. +/*
  18491. + * net/dsa/tag_qinq.c - QinQ tag format handling
  18492. + * Copyright (c) 2010 Gabor Juhos <juhosg@openwrt.org>
  18493. + *
  18494. + * This file was based on:
  18495. + * net/dsa/tag_edsa.c - Ethertype DSA tagging
  18496. + * Copyright (c) 2008-2009 Marvell Semiconductor
  18497. + *
  18498. + * This program is free software; you can redistribute it and/or modify
  18499. + * it under the terms of the GNU General Public License as published by
  18500. + * the Free Software Foundation; either version 2 of the License, or
  18501. + * (at your option) any later version.
  18502. + */
  18503. +
  18504. +#include <linux/etherdevice.h>
  18505. +#include <linux/list.h>
  18506. +#include <linux/netdevice.h>
  18507. +#include <linux/if_vlan.h>
  18508. +
  18509. +#include "dsa_priv.h"
  18510. +
  18511. +netdev_tx_t qinq_xmit(struct sk_buff *skb, struct net_device *dev)
  18512. +{
  18513. + struct dsa_slave_priv *p = netdev_priv(dev);
  18514. + struct vlan_ethhdr *veth;
  18515. + unsigned int len;
  18516. + int ret;
  18517. +
  18518. + if (skb_cow_head(skb, VLAN_HLEN) < 0)
  18519. + goto out_free_skb;
  18520. +
  18521. + veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
  18522. +
  18523. + /* Move the mac addresses to the beginning of the new header. */
  18524. + memmove(skb->data, skb->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);
  18525. + skb->mac_header -= VLAN_HLEN;
  18526. +
  18527. + /* setup VLAN header fields */
  18528. + veth->h_vlan_proto = htons(ETH_P_QINQ);
  18529. + veth->h_vlan_TCI = htons(p->port);
  18530. +
  18531. + len = skb->len;
  18532. + skb->protocol = htons(ETH_P_QINQ);
  18533. + skb->dev = p->parent->dst->master_netdev;
  18534. +
  18535. + ret = dev_queue_xmit(skb);
  18536. + if (unlikely(ret != NET_XMIT_SUCCESS))
  18537. + goto out_dropped;
  18538. +
  18539. + dev->stats.tx_packets++;
  18540. + dev->stats.tx_bytes += len;
  18541. +
  18542. + return NETDEV_TX_OK;
  18543. +
  18544. + out_free_skb:
  18545. + kfree_skb(skb);
  18546. + out_dropped:
  18547. + dev->stats.tx_dropped++;
  18548. + return NETDEV_TX_OK;
  18549. +}
  18550. +
  18551. +static int qinq_rcv(struct sk_buff *skb, struct net_device *dev,
  18552. + struct packet_type *pt, struct net_device *orig_dev)
  18553. +{
  18554. + struct dsa_switch_tree *dst;
  18555. + struct dsa_switch *ds;
  18556. + struct vlan_hdr *vhdr;
  18557. + int source_port;
  18558. +
  18559. + dst = dev->dsa_ptr;
  18560. + if (unlikely(dst == NULL))
  18561. + goto out_drop;
  18562. + ds = dst->ds[0];
  18563. +
  18564. + skb = skb_unshare(skb, GFP_ATOMIC);
  18565. + if (skb == NULL)
  18566. + goto out;
  18567. +
  18568. + if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
  18569. + goto out_drop;
  18570. +
  18571. + vhdr = (struct vlan_hdr *)skb->data;
  18572. + source_port = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  18573. + if (source_port >= DSA_MAX_PORTS || ds->ports[source_port] == NULL)
  18574. + goto out_drop;
  18575. +
  18576. + /* Remove the outermost VLAN tag and update checksum. */
  18577. + skb_pull_rcsum(skb, VLAN_HLEN);
  18578. + memmove(skb->data - ETH_HLEN,
  18579. + skb->data - ETH_HLEN - VLAN_HLEN,
  18580. + 2 * ETH_ALEN);
  18581. +
  18582. + skb->dev = ds->ports[source_port];
  18583. + skb_push(skb, ETH_HLEN);
  18584. + skb->pkt_type = PACKET_HOST;
  18585. + skb->protocol = eth_type_trans(skb, skb->dev);
  18586. +
  18587. + skb->dev->stats.rx_packets++;
  18588. + skb->dev->stats.rx_bytes += skb->len;
  18589. +
  18590. + netif_receive_skb(skb);
  18591. +
  18592. + return 0;
  18593. +
  18594. + out_drop:
  18595. + kfree_skb(skb);
  18596. + out:
  18597. + return 0;
  18598. +}
  18599. +
  18600. +static struct packet_type qinq_packet_type __read_mostly = {
  18601. + .type = cpu_to_be16(ETH_P_QINQ),
  18602. + .func = qinq_rcv,
  18603. +};
  18604. +
  18605. +static int __init qinq_init_module(void)
  18606. +{
  18607. + dev_add_pack(&qinq_packet_type);
  18608. + return 0;
  18609. +}
  18610. +module_init(qinq_init_module);
  18611. +
  18612. +static void __exit qinq_cleanup_module(void)
  18613. +{
  18614. + dev_remove_pack(&qinq_packet_type);
  18615. +}
  18616. +module_exit(qinq_cleanup_module);