ar7.patch 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087
  1. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/clock.c linux-2.6.29.1/arch/mips/ar7/clock.c
  2. --- linux-2.6.29.1.orig/arch/mips/ar7/clock.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.29.1/arch/mips/ar7/clock.c 2009-05-31 20:19:17.000000000 +0200
  4. @@ -0,0 +1,483 @@
  5. +/*
  6. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  7. + * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
  8. + *
  9. + * This program is free software; you can redistribute it and/or modify
  10. + * it under the terms of the GNU General Public License as published by
  11. + * the Free Software Foundation; either version 2 of the License, or
  12. + * (at your option) any later version.
  13. + *
  14. + * This program is distributed in the hope that it will be useful,
  15. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. + * GNU General Public License for more details.
  18. + *
  19. + * You should have received a copy of the GNU General Public License
  20. + * along with this program; if not, write to the Free Software
  21. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. + */
  23. +
  24. +#include <linux/init.h>
  25. +#include <linux/types.h>
  26. +#include <linux/module.h>
  27. +#include <linux/delay.h>
  28. +#include <asm/addrspace.h>
  29. +#include <asm/io.h>
  30. +#include <asm/mach-ar7/ar7.h>
  31. +
  32. +#define BOOT_PLL_SOURCE_MASK 0x3
  33. +#define CPU_PLL_SOURCE_SHIFT 16
  34. +#define BUS_PLL_SOURCE_SHIFT 14
  35. +#define USB_PLL_SOURCE_SHIFT 18
  36. +#define DSP_PLL_SOURCE_SHIFT 22
  37. +#define BOOT_PLL_SOURCE_AFE 0
  38. +#define BOOT_PLL_SOURCE_BUS 0
  39. +#define BOOT_PLL_SOURCE_REF 1
  40. +#define BOOT_PLL_SOURCE_XTAL 2
  41. +#define BOOT_PLL_SOURCE_CPU 3
  42. +#define BOOT_PLL_BYPASS 0x00000020
  43. +#define BOOT_PLL_ASYNC_MODE 0x02000000
  44. +#define BOOT_PLL_2TO1_MODE 0x00008000
  45. +
  46. +#define TNETD7200_CLOCK_ID_CPU 0
  47. +#define TNETD7200_CLOCK_ID_DSP 1
  48. +#define TNETD7200_CLOCK_ID_USB 2
  49. +
  50. +#define TNETD7200_DEF_CPU_CLK 211000000
  51. +#define TNETD7200_DEF_DSP_CLK 125000000
  52. +#define TNETD7200_DEF_USB_CLK 48000000
  53. +
  54. +struct tnetd7300_clock {
  55. + u32 ctrl;
  56. +#define PREDIV_MASK 0x001f0000
  57. +#define PREDIV_SHIFT 16
  58. +#define POSTDIV_MASK 0x0000001f
  59. + u32 unused1[3];
  60. + u32 pll;
  61. +#define MUL_MASK 0x0000f000
  62. +#define MUL_SHIFT 12
  63. +#define PLL_MODE_MASK 0x00000001
  64. +#define PLL_NDIV 0x00000800
  65. +#define PLL_DIV 0x00000002
  66. +#define PLL_STATUS 0x00000001
  67. + u32 unused2[3];
  68. +};
  69. +
  70. +struct tnetd7300_clocks {
  71. + struct tnetd7300_clock bus;
  72. + struct tnetd7300_clock cpu;
  73. + struct tnetd7300_clock usb;
  74. + struct tnetd7300_clock dsp;
  75. +};
  76. +
  77. +struct tnetd7200_clock {
  78. + u32 ctrl;
  79. + u32 unused1[3];
  80. +#define DIVISOR_ENABLE_MASK 0x00008000
  81. + u32 mul;
  82. + u32 prediv;
  83. + u32 postdiv;
  84. + u32 postdiv2;
  85. + u32 unused2[6];
  86. + u32 cmd;
  87. + u32 status;
  88. + u32 cmden;
  89. + u32 padding[15];
  90. +};
  91. +
  92. +struct tnetd7200_clocks {
  93. + struct tnetd7200_clock cpu;
  94. + struct tnetd7200_clock dsp;
  95. + struct tnetd7200_clock usb;
  96. +};
  97. +
  98. +int ar7_cpu_clock = 150000000;
  99. +EXPORT_SYMBOL(ar7_cpu_clock);
  100. +int ar7_bus_clock = 125000000;
  101. +EXPORT_SYMBOL(ar7_bus_clock);
  102. +int ar7_dsp_clock;
  103. +EXPORT_SYMBOL(ar7_dsp_clock);
  104. +
  105. +static int gcd(int a, int b)
  106. +{
  107. + int c;
  108. +
  109. + if (a < b) {
  110. + c = a;
  111. + a = b;
  112. + b = c;
  113. + }
  114. + while ((c = (a % b))) {
  115. + a = b;
  116. + b = c;
  117. + }
  118. + return b;
  119. +}
  120. +
  121. +static void approximate(int base, int target, int *prediv,
  122. + int *postdiv, int *mul)
  123. +{
  124. + int i, j, k, freq, res = target;
  125. + for (i = 1; i <= 16; i++)
  126. + for (j = 1; j <= 32; j++)
  127. + for (k = 1; k <= 32; k++) {
  128. + freq = abs(base / j * i / k - target);
  129. + if (freq < res) {
  130. + res = freq;
  131. + *mul = i;
  132. + *prediv = j;
  133. + *postdiv = k;
  134. + }
  135. + }
  136. +}
  137. +
  138. +static void calculate(int base, int target, int *prediv, int *postdiv,
  139. + int *mul)
  140. +{
  141. + int tmp_gcd, tmp_base, tmp_freq;
  142. +
  143. + for (*prediv = 1; *prediv <= 32; (*prediv)++) {
  144. + tmp_base = base / *prediv;
  145. + tmp_gcd = gcd(target, tmp_base);
  146. + *mul = target / tmp_gcd;
  147. + *postdiv = tmp_base / tmp_gcd;
  148. + if ((*mul < 1) || (*mul >= 16))
  149. + continue;
  150. + if ((*postdiv > 0) & (*postdiv <= 32))
  151. + break;
  152. + }
  153. +
  154. + if (base / (*prediv) * (*mul) / (*postdiv) != target) {
  155. + approximate(base, target, prediv, postdiv, mul);
  156. + tmp_freq = base / (*prediv) * (*mul) / (*postdiv);
  157. + printk(KERN_WARNING
  158. + "Adjusted requested frequency %d to %d\n",
  159. + target, tmp_freq);
  160. + }
  161. +
  162. + printk(KERN_DEBUG "Clocks: prediv: %d, postdiv: %d, mul: %d\n",
  163. + *prediv, *postdiv, *mul);
  164. +}
  165. +
  166. +static int tnetd7300_dsp_clock(void)
  167. +{
  168. + u32 didr1, didr2;
  169. + u8 rev = ar7_chip_rev();
  170. + didr1 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x18));
  171. + didr2 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x1c));
  172. + if (didr2 & (1 << 23))
  173. + return 0;
  174. + if ((rev >= 0x23) && (rev != 0x57))
  175. + return 250000000;
  176. + if ((((didr2 & 0x1fff) << 10) | ((didr1 & 0xffc00000) >> 22))
  177. + > 4208000)
  178. + return 250000000;
  179. + return 0;
  180. +}
  181. +
  182. +static int tnetd7300_get_clock(u32 shift, struct tnetd7300_clock *clock,
  183. + u32 *bootcr, u32 bus_clock)
  184. +{
  185. + int product;
  186. + int base_clock = AR7_REF_CLOCK;
  187. + u32 ctrl = readl(&clock->ctrl);
  188. + u32 pll = readl(&clock->pll);
  189. + int prediv = ((ctrl & PREDIV_MASK) >> PREDIV_SHIFT) + 1;
  190. + int postdiv = (ctrl & POSTDIV_MASK) + 1;
  191. + int divisor = prediv * postdiv;
  192. + int mul = ((pll & MUL_MASK) >> MUL_SHIFT) + 1;
  193. +
  194. + switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
  195. + case BOOT_PLL_SOURCE_BUS:
  196. + base_clock = bus_clock;
  197. + break;
  198. + case BOOT_PLL_SOURCE_REF:
  199. + base_clock = AR7_REF_CLOCK;
  200. + break;
  201. + case BOOT_PLL_SOURCE_XTAL:
  202. + base_clock = AR7_XTAL_CLOCK;
  203. + break;
  204. + case BOOT_PLL_SOURCE_CPU:
  205. + base_clock = ar7_cpu_clock;
  206. + break;
  207. + }
  208. +
  209. + if (*bootcr & BOOT_PLL_BYPASS)
  210. + return base_clock / divisor;
  211. +
  212. + if ((pll & PLL_MODE_MASK) == 0)
  213. + return (base_clock >> (mul / 16 + 1)) / divisor;
  214. +
  215. + if ((pll & (PLL_NDIV | PLL_DIV)) == (PLL_NDIV | PLL_DIV)) {
  216. + product = (mul & 1) ?
  217. + (base_clock * mul) >> 1 :
  218. + (base_clock * (mul - 1)) >> 2;
  219. + return product / divisor;
  220. + }
  221. +
  222. + if (mul == 16)
  223. + return base_clock / divisor;
  224. +
  225. + return base_clock * mul / divisor;
  226. +}
  227. +
  228. +static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
  229. + u32 *bootcr, u32 frequency)
  230. +{
  231. + int prediv, postdiv, mul;
  232. + int base_clock = ar7_bus_clock;
  233. +
  234. + switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
  235. + case BOOT_PLL_SOURCE_BUS:
  236. + base_clock = ar7_bus_clock;
  237. + break;
  238. + case BOOT_PLL_SOURCE_REF:
  239. + base_clock = AR7_REF_CLOCK;
  240. + break;
  241. + case BOOT_PLL_SOURCE_XTAL:
  242. + base_clock = AR7_XTAL_CLOCK;
  243. + break;
  244. + case BOOT_PLL_SOURCE_CPU:
  245. + base_clock = ar7_cpu_clock;
  246. + break;
  247. + }
  248. +
  249. + calculate(base_clock, frequency, &prediv, &postdiv, &mul);
  250. +
  251. + writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl);
  252. + mdelay(1);
  253. + writel(4, &clock->pll);
  254. + while (readl(&clock->pll) & PLL_STATUS);
  255. + writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll);
  256. + mdelay(75);
  257. +}
  258. +
  259. +static void __init tnetd7300_init_clocks(void)
  260. +{
  261. + u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
  262. + struct tnetd7300_clocks *clocks =
  263. + (struct tnetd7300_clocks *)
  264. + ioremap_nocache(AR7_REGS_POWER + 0x20,
  265. + sizeof(struct tnetd7300_clocks));
  266. +
  267. + ar7_bus_clock = tnetd7300_get_clock(BUS_PLL_SOURCE_SHIFT,
  268. + &clocks->bus, bootcr, AR7_AFE_CLOCK);
  269. +
  270. + if (*bootcr & BOOT_PLL_ASYNC_MODE)
  271. + ar7_cpu_clock = tnetd7300_get_clock(CPU_PLL_SOURCE_SHIFT,
  272. + &clocks->cpu, bootcr, AR7_AFE_CLOCK);
  273. + else
  274. + ar7_cpu_clock = ar7_bus_clock;
  275. +/*
  276. + tnetd7300_set_clock(USB_PLL_SOURCE_SHIFT, &clocks->usb,
  277. + bootcr, 48000000);
  278. +*/
  279. + if (ar7_dsp_clock == 250000000)
  280. + tnetd7300_set_clock(DSP_PLL_SOURCE_SHIFT, &clocks->dsp,
  281. + bootcr, ar7_dsp_clock);
  282. +
  283. + iounmap(clocks);
  284. + iounmap(bootcr);
  285. +}
  286. +
  287. +static int tnetd7200_get_clock(int base, struct tnetd7200_clock *clock,
  288. + u32 *bootcr, u32 bus_clock)
  289. +{
  290. + int divisor = ((readl(&clock->prediv) & 0x1f) + 1) *
  291. + ((readl(&clock->postdiv) & 0x1f) + 1);
  292. +
  293. + if (*bootcr & BOOT_PLL_BYPASS)
  294. + return base / divisor;
  295. +
  296. + return base * ((readl(&clock->mul) & 0xf) + 1) / divisor;
  297. +}
  298. +
  299. +
  300. +static void tnetd7200_set_clock(int base, struct tnetd7200_clock *clock,
  301. + int prediv, int postdiv, int postdiv2, int mul, u32 frequency)
  302. +{
  303. + printk(KERN_INFO
  304. + "Clocks: base = %d, frequency = %u, prediv = %d, "
  305. + "postdiv = %d, postdiv2 = %d, mul = %d\n",
  306. + base, frequency, prediv, postdiv, postdiv2, mul);
  307. +
  308. + writel(0, &clock->ctrl);
  309. + writel(DIVISOR_ENABLE_MASK | ((prediv - 1) & 0x1F), &clock->prediv);
  310. + writel((mul - 1) & 0xF, &clock->mul);
  311. +
  312. + for (mul = 0; mul < 2000; mul++) /* nop */;
  313. +
  314. + while (readl(&clock->status) & 0x1) /* nop */;
  315. +
  316. + writel(DIVISOR_ENABLE_MASK | ((postdiv - 1) & 0x1F), &clock->postdiv);
  317. +
  318. + writel(readl(&clock->cmden) | 1, &clock->cmden);
  319. + writel(readl(&clock->cmd) | 1, &clock->cmd);
  320. +
  321. + while (readl(&clock->status) & 0x1) /* nop */;
  322. +
  323. + writel(DIVISOR_ENABLE_MASK | ((postdiv2 - 1) & 0x1F), &clock->postdiv2);
  324. +
  325. + writel(readl(&clock->cmden) | 1, &clock->cmden);
  326. + writel(readl(&clock->cmd) | 1, &clock->cmd);
  327. +
  328. + while (readl(&clock->status) & 0x1) /* nop */;
  329. +
  330. + writel(readl(&clock->ctrl) | 1, &clock->ctrl);
  331. +}
  332. +
  333. +static int tnetd7200_get_clock_base(int clock_id, u32 *bootcr)
  334. +{
  335. + if (*bootcr & BOOT_PLL_ASYNC_MODE)
  336. + /* Async */
  337. + switch (clock_id) {
  338. + case TNETD7200_CLOCK_ID_DSP:
  339. + return AR7_REF_CLOCK;
  340. + default:
  341. + return AR7_AFE_CLOCK;
  342. + }
  343. + else
  344. + /* Sync */
  345. + if (*bootcr & BOOT_PLL_2TO1_MODE)
  346. + /* 2:1 */
  347. + switch (clock_id) {
  348. + case TNETD7200_CLOCK_ID_DSP:
  349. + return AR7_REF_CLOCK;
  350. + default:
  351. + return AR7_AFE_CLOCK;
  352. + }
  353. + else
  354. + /* 1:1 */
  355. + return AR7_REF_CLOCK;
  356. +}
  357. +
  358. +
  359. +static void __init tnetd7200_init_clocks(void)
  360. +{
  361. + u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
  362. + struct tnetd7200_clocks *clocks =
  363. + (struct tnetd7200_clocks *)
  364. + ioremap_nocache(AR7_REGS_POWER + 0x80,
  365. + sizeof(struct tnetd7200_clocks));
  366. + int cpu_base, cpu_mul, cpu_prediv, cpu_postdiv;
  367. + int dsp_base, dsp_mul, dsp_prediv, dsp_postdiv;
  368. + int usb_base, usb_mul, usb_prediv, usb_postdiv;
  369. +
  370. +/*
  371. + Log from Fritz!Box 7170 Annex B:
  372. +
  373. + CPU revision is: 00018448
  374. + Clocks: Async mode
  375. + Clocks: Setting DSP clock
  376. + Clocks: prediv: 1, postdiv: 1, mul: 5
  377. + Clocks: base = 25000000, frequency = 125000000, prediv = 1,
  378. + postdiv = 2, postdiv2 = 1, mul = 10
  379. + Clocks: Setting CPU clock
  380. + Adjusted requested frequency 211000000 to 211968000
  381. + Clocks: prediv: 1, postdiv: 1, mul: 6
  382. + Clocks: base = 35328000, frequency = 211968000, prediv = 1,
  383. + postdiv = 1, postdiv2 = -1, mul = 6
  384. + Clocks: Setting USB clock
  385. + Adjusted requested frequency 48000000 to 48076920
  386. + Clocks: prediv: 13, postdiv: 1, mul: 5
  387. + Clocks: base = 125000000, frequency = 48000000, prediv = 13,
  388. + postdiv = 1, postdiv2 = -1, mul = 5
  389. +
  390. + DSL didn't work if you didn't set the postdiv 2:1 postdiv2 combination,
  391. + driver hung on startup.
  392. + Haven't tested this on a synchronous board,
  393. + neither do i know what to do with ar7_dsp_clock
  394. +*/
  395. +
  396. + cpu_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_CPU, bootcr);
  397. + dsp_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_DSP, bootcr);
  398. +
  399. + if (*bootcr & BOOT_PLL_ASYNC_MODE) {
  400. + printk(KERN_INFO "Clocks: Async mode\n");
  401. +
  402. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  403. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK,
  404. + &dsp_prediv, &dsp_postdiv, &dsp_mul);
  405. + ar7_bus_clock =
  406. + ((dsp_base / dsp_prediv) * dsp_mul) / dsp_postdiv;
  407. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  408. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv, dsp_mul * 2,
  409. + ar7_bus_clock);
  410. +
  411. + printk(KERN_INFO "Clocks: Setting CPU clock\n");
  412. + calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
  413. + &cpu_postdiv, &cpu_mul);
  414. + ar7_cpu_clock =
  415. + ((cpu_base / cpu_prediv) * cpu_mul) / cpu_postdiv;
  416. + tnetd7200_set_clock(cpu_base, &clocks->cpu,
  417. + cpu_prediv, cpu_postdiv, -1, cpu_mul,
  418. + ar7_cpu_clock);
  419. +
  420. + } else
  421. + if (*bootcr & BOOT_PLL_2TO1_MODE) {
  422. + printk(KERN_INFO "Clocks: Sync 2:1 mode\n");
  423. +
  424. + printk(KERN_INFO "Clocks: Setting CPU clock\n");
  425. + calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
  426. + &cpu_postdiv, &cpu_mul);
  427. + ar7_cpu_clock = ((cpu_base / cpu_prediv) * cpu_mul)
  428. + / cpu_postdiv;
  429. + tnetd7200_set_clock(cpu_base, &clocks->cpu,
  430. + cpu_prediv, cpu_postdiv, -1, cpu_mul,
  431. + ar7_cpu_clock);
  432. +
  433. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  434. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
  435. + &dsp_postdiv, &dsp_mul);
  436. + ar7_bus_clock = ar7_cpu_clock / 2;
  437. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  438. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
  439. + dsp_mul * 2, ar7_bus_clock);
  440. + } else {
  441. + printk(KERN_INFO "Clocks: Sync 1:1 mode\n");
  442. +
  443. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  444. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
  445. + &dsp_postdiv, &dsp_mul);
  446. + ar7_bus_clock = ((dsp_base / dsp_prediv) * dsp_mul)
  447. + / dsp_postdiv;
  448. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  449. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
  450. + dsp_mul * 2, ar7_bus_clock);
  451. +
  452. + ar7_cpu_clock = ar7_bus_clock;
  453. + }
  454. +
  455. + printk(KERN_INFO "Clocks: Setting USB clock\n");
  456. + usb_base = ar7_bus_clock;
  457. + calculate(usb_base, TNETD7200_DEF_USB_CLK, &usb_prediv,
  458. + &usb_postdiv, &usb_mul);
  459. + tnetd7200_set_clock(usb_base, &clocks->usb,
  460. + usb_prediv, usb_postdiv, -1, usb_mul,
  461. + TNETD7200_DEF_USB_CLK);
  462. +
  463. + #warning FIXME
  464. + ar7_dsp_clock = ar7_cpu_clock;
  465. +
  466. + iounmap(clocks);
  467. + iounmap(bootcr);
  468. +}
  469. +
  470. +void __init ar7_init_clocks(void)
  471. +{
  472. + switch (ar7_chip_id()) {
  473. + case AR7_CHIP_7100:
  474. +#warning FIXME: Check if the new 7200 clock init works for 7100
  475. + tnetd7200_init_clocks();
  476. + break;
  477. + case AR7_CHIP_7200:
  478. + tnetd7200_init_clocks();
  479. + break;
  480. + case AR7_CHIP_7300:
  481. + ar7_dsp_clock = tnetd7300_dsp_clock();
  482. + tnetd7300_init_clocks();
  483. + break;
  484. + default:
  485. + break;
  486. + }
  487. +}
  488. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/gpio.c linux-2.6.29.1/arch/mips/ar7/gpio.c
  489. --- linux-2.6.29.1.orig/arch/mips/ar7/gpio.c 1970-01-01 01:00:00.000000000 +0100
  490. +++ linux-2.6.29.1/arch/mips/ar7/gpio.c 2009-05-31 20:19:27.000000000 +0200
  491. @@ -0,0 +1,49 @@
  492. +/*
  493. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  494. + * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
  495. + *
  496. + * This program is free software; you can redistribute it and/or modify
  497. + * it under the terms of the GNU General Public License as published by
  498. + * the Free Software Foundation; either version 2 of the License, or
  499. + * (at your option) any later version.
  500. + *
  501. + * This program is distributed in the hope that it will be useful,
  502. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  503. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  504. + * GNU General Public License for more details.
  505. + *
  506. + * You should have received a copy of the GNU General Public License
  507. + * along with this program; if not, write to the Free Software
  508. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  509. + */
  510. +
  511. +#include <linux/module.h>
  512. +
  513. +#include <asm/mach-ar7/gpio.h>
  514. +
  515. +static const char *ar7_gpio_list[AR7_GPIO_MAX];
  516. +
  517. +int gpio_request(unsigned gpio, const char *label)
  518. +{
  519. + if (gpio >= AR7_GPIO_MAX)
  520. + return -EINVAL;
  521. +
  522. + if (ar7_gpio_list[gpio])
  523. + return -EBUSY;
  524. +
  525. + if (label) {
  526. + ar7_gpio_list[gpio] = label;
  527. + } else {
  528. + ar7_gpio_list[gpio] = "busy";
  529. + }
  530. +
  531. + return 0;
  532. +}
  533. +EXPORT_SYMBOL(gpio_request);
  534. +
  535. +void gpio_free(unsigned gpio)
  536. +{
  537. + BUG_ON(!ar7_gpio_list[gpio]);
  538. + ar7_gpio_list[gpio] = NULL;
  539. +}
  540. +EXPORT_SYMBOL(gpio_free);
  541. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/irq.c linux-2.6.29.1/arch/mips/ar7/irq.c
  542. --- linux-2.6.29.1.orig/arch/mips/ar7/irq.c 1970-01-01 01:00:00.000000000 +0100
  543. +++ linux-2.6.29.1/arch/mips/ar7/irq.c 2009-05-31 20:19:35.000000000 +0200
  544. @@ -0,0 +1,183 @@
  545. +/*
  546. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  547. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  548. + *
  549. + * This program is free software; you can redistribute it and/or modify
  550. + * it under the terms of the GNU General Public License as published by
  551. + * the Free Software Foundation; either version 2 of the License, or
  552. + * (at your option) any later version.
  553. + *
  554. + * This program is distributed in the hope that it will be useful,
  555. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  556. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  557. + * GNU General Public License for more details.
  558. + *
  559. + * You should have received a copy of the GNU General Public License
  560. + * along with this program; if not, write to the Free Software
  561. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  562. + */
  563. +
  564. +#include <linux/interrupt.h>
  565. +#include <linux/io.h>
  566. +
  567. +#include <asm/irq_cpu.h>
  568. +#include <asm/mipsregs.h>
  569. +#include <asm/mach-ar7/ar7.h>
  570. +
  571. +#define EXCEPT_OFFSET 0x80
  572. +#define PACE_OFFSET 0xA0
  573. +#define CHNLS_OFFSET 0x200
  574. +
  575. +#define REG_OFFSET(irq, reg) ((irq) / 32 * 0x4 + reg * 0x10)
  576. +#define SEC_REG_OFFSET(reg) (EXCEPT_OFFSET + reg * 0x8)
  577. +#define SEC_SR_OFFSET (SEC_REG_OFFSET(0)) /* 0x80 */
  578. +#define CR_OFFSET(irq) (REG_OFFSET(irq, 1)) /* 0x10 */
  579. +#define SEC_CR_OFFSET (SEC_REG_OFFSET(1)) /* 0x88 */
  580. +#define ESR_OFFSET(irq) (REG_OFFSET(irq, 2)) /* 0x20 */
  581. +#define SEC_ESR_OFFSET (SEC_REG_OFFSET(2)) /* 0x90 */
  582. +#define ECR_OFFSET(irq) (REG_OFFSET(irq, 3)) /* 0x30 */
  583. +#define SEC_ECR_OFFSET (SEC_REG_OFFSET(3)) /* 0x98 */
  584. +#define PIR_OFFSET (0x40)
  585. +#define MSR_OFFSET (0x44)
  586. +#define PM_OFFSET(irq) (REG_OFFSET(irq, 5)) /* 0x50 */
  587. +#define TM_OFFSET(irq) (REG_OFFSET(irq, 6)) /* 0x60 */
  588. +
  589. +#define REG(addr) ((u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
  590. +
  591. +#define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
  592. +
  593. +static void ar7_unmask_irq(unsigned int irq_nr);
  594. +static void ar7_mask_irq(unsigned int irq_nr);
  595. +static void ar7_ack_irq(unsigned int irq_nr);
  596. +static void ar7_unmask_sec_irq(unsigned int irq_nr);
  597. +static void ar7_mask_sec_irq(unsigned int irq_nr);
  598. +static void ar7_ack_sec_irq(unsigned int irq_nr);
  599. +static void ar7_cascade(void);
  600. +static void ar7_irq_init(int base);
  601. +static int ar7_irq_base;
  602. +
  603. +static struct irq_chip ar7_irq_type = {
  604. + .name = "AR7",
  605. + .unmask = ar7_unmask_irq,
  606. + .mask = ar7_mask_irq,
  607. + .ack = ar7_ack_irq
  608. +};
  609. +
  610. +static struct irq_chip ar7_sec_irq_type = {
  611. + .name = "AR7",
  612. + .unmask = ar7_unmask_sec_irq,
  613. + .mask = ar7_mask_sec_irq,
  614. + .ack = ar7_ack_sec_irq,
  615. +};
  616. +
  617. +static struct irqaction ar7_cascade_action = {
  618. + .handler = no_action,
  619. + .name = "AR7 cascade interrupt"
  620. +};
  621. +
  622. +static void ar7_unmask_irq(unsigned int irq)
  623. +{
  624. + writel(1 << ((irq - ar7_irq_base) % 32),
  625. + REG(ESR_OFFSET(irq - ar7_irq_base)));
  626. +}
  627. +
  628. +static void ar7_mask_irq(unsigned int irq)
  629. +{
  630. + writel(1 << ((irq - ar7_irq_base) % 32),
  631. + REG(ECR_OFFSET(irq - ar7_irq_base)));
  632. +}
  633. +
  634. +static void ar7_ack_irq(unsigned int irq)
  635. +{
  636. + writel(1 << ((irq - ar7_irq_base) % 32),
  637. + REG(CR_OFFSET(irq - ar7_irq_base)));
  638. +}
  639. +
  640. +static void ar7_unmask_sec_irq(unsigned int irq)
  641. +{
  642. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ESR_OFFSET));
  643. +}
  644. +
  645. +static void ar7_mask_sec_irq(unsigned int irq)
  646. +{
  647. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ECR_OFFSET));
  648. +}
  649. +
  650. +static void ar7_ack_sec_irq(unsigned int irq)
  651. +{
  652. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_CR_OFFSET));
  653. +}
  654. +
  655. +void __init arch_init_irq(void) {
  656. + mips_cpu_irq_init();
  657. + ar7_irq_init(8);
  658. +}
  659. +
  660. +static void __init ar7_irq_init(int base)
  661. +{
  662. + int i;
  663. + /*
  664. + * Disable interrupts and clear pending
  665. + */
  666. + writel(0xffffffff, REG(ECR_OFFSET(0)));
  667. + writel(0xff, REG(ECR_OFFSET(32)));
  668. + writel(0xffffffff, REG(SEC_ECR_OFFSET));
  669. + writel(0xffffffff, REG(CR_OFFSET(0)));
  670. + writel(0xff, REG(CR_OFFSET(32)));
  671. + writel(0xffffffff, REG(SEC_CR_OFFSET));
  672. +
  673. + ar7_irq_base = base;
  674. +
  675. + for (i = 0; i < 40; i++) {
  676. + writel(i, REG(CHNL_OFFSET(i)));
  677. + /* Primary IRQ's */
  678. + set_irq_chip_and_handler(base + i, &ar7_irq_type,
  679. + handle_level_irq);
  680. + /* Secondary IRQ's */
  681. + if (i < 32)
  682. + set_irq_chip_and_handler(base + i + 40,
  683. + &ar7_sec_irq_type,
  684. + handle_level_irq);
  685. + }
  686. +
  687. + setup_irq(2, &ar7_cascade_action);
  688. + setup_irq(ar7_irq_base, &ar7_cascade_action);
  689. + set_c0_status(IE_IRQ0);
  690. +}
  691. +
  692. +static void ar7_cascade(void)
  693. +{
  694. + u32 status;
  695. + int i, irq;
  696. +
  697. + /* Primary IRQ's */
  698. + irq = readl(REG(PIR_OFFSET)) & 0x3f;
  699. + if (irq) {
  700. + do_IRQ(ar7_irq_base + irq);
  701. + return;
  702. + }
  703. +
  704. + /* Secondary IRQ's are cascaded through primary '0' */
  705. + writel(1, REG(CR_OFFSET(irq)));
  706. + status = readl(REG(SEC_SR_OFFSET));
  707. + for (i = 0; i < 32; i++) {
  708. + if (status & 1) {
  709. + do_IRQ(ar7_irq_base + i + 40);
  710. + return;
  711. + }
  712. + status >>= 1;
  713. + }
  714. +
  715. + spurious_interrupt();
  716. +}
  717. +
  718. +asmlinkage void plat_irq_dispatch(void)
  719. +{
  720. + unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  721. + if (pending & STATUSF_IP7) /* cpu timer */
  722. + do_IRQ(7);
  723. + else if (pending & STATUSF_IP2) /* int0 hardware line */
  724. + ar7_cascade();
  725. + else
  726. + spurious_interrupt();
  727. +}
  728. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/Makefile linux-2.6.29.1/arch/mips/ar7/Makefile
  729. --- linux-2.6.29.1.orig/arch/mips/ar7/Makefile 1970-01-01 01:00:00.000000000 +0100
  730. +++ linux-2.6.29.1/arch/mips/ar7/Makefile 2009-05-31 19:50:05.000000000 +0200
  731. @@ -0,0 +1,10 @@
  732. +
  733. +obj-y := \
  734. + prom.o \
  735. + setup.o \
  736. + memory.o \
  737. + irq.o \
  738. + time.o \
  739. + platform.o \
  740. + gpio.o \
  741. + clock.o
  742. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/memory.c linux-2.6.29.1/arch/mips/ar7/memory.c
  743. --- linux-2.6.29.1.orig/arch/mips/ar7/memory.c 1970-01-01 01:00:00.000000000 +0100
  744. +++ linux-2.6.29.1/arch/mips/ar7/memory.c 2009-05-31 19:50:05.000000000 +0200
  745. @@ -0,0 +1,74 @@
  746. +/*
  747. + * Based on arch/mips/mm/init.c
  748. + * Copyright (C) 1994 - 2000 Ralf Baechle
  749. + * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  750. + * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  751. + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  752. + *
  753. + * This program is free software; you can redistribute it and/or modify
  754. + * it under the terms of the GNU General Public License as published by
  755. + * the Free Software Foundation; either version 2 of the License, or
  756. + * (at your option) any later version.
  757. + *
  758. + * This program is distributed in the hope that it will be useful,
  759. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  760. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  761. + * GNU General Public License for more details.
  762. + *
  763. + * You should have received a copy of the GNU General Public License
  764. + * along with this program; if not, write to the Free Software
  765. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  766. + */
  767. +#include <linux/bootmem.h>
  768. +#include <linux/init.h>
  769. +#include <linux/mm.h>
  770. +#include <linux/module.h>
  771. +#include <linux/pfn.h>
  772. +#include <linux/proc_fs.h>
  773. +#include <linux/string.h>
  774. +#include <linux/swap.h>
  775. +
  776. +#include <asm/bootinfo.h>
  777. +#include <asm/page.h>
  778. +#include <asm/sections.h>
  779. +
  780. +#include <asm/mips-boards/prom.h>
  781. +
  782. +static int __init memsize(void)
  783. +{
  784. + u32 size = (64 << 20);
  785. + u32 *addr = (u32 *)KSEG1ADDR(0x14000000 + size - 4);
  786. + u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end));
  787. + u32 *tmpaddr = addr;
  788. +
  789. + while (tmpaddr > kernel_end) {
  790. + *tmpaddr = (u32)tmpaddr;
  791. + size >>= 1;
  792. + tmpaddr -= size >> 2;
  793. + }
  794. +
  795. + do {
  796. + tmpaddr += size >> 2;
  797. + if (*tmpaddr != (u32)tmpaddr)
  798. + break;
  799. + size <<= 1;
  800. + } while (size < (64 << 20));
  801. +
  802. + writel(tmpaddr, &addr);
  803. +
  804. + return size;
  805. +}
  806. +
  807. +void __init prom_meminit(void)
  808. +{
  809. + unsigned long pages;
  810. +
  811. + pages = memsize() >> PAGE_SHIFT;
  812. + add_memory_region(PHYS_OFFSET, pages << PAGE_SHIFT,
  813. + BOOT_MEM_RAM);
  814. +}
  815. +
  816. +void __init prom_free_prom_memory(void)
  817. +{
  818. + return;
  819. +}
  820. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/platform.c linux-2.6.29.1/arch/mips/ar7/platform.c
  821. --- linux-2.6.29.1.orig/arch/mips/ar7/platform.c 1970-01-01 01:00:00.000000000 +0100
  822. +++ linux-2.6.29.1/arch/mips/ar7/platform.c 2009-06-01 13:34:18.000000000 +0200
  823. @@ -0,0 +1,535 @@
  824. +/*
  825. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  826. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  827. + *
  828. + * This program is free software; you can redistribute it and/or modify
  829. + * it under the terms of the GNU General Public License as published by
  830. + * the Free Software Foundation; either version 2 of the License, or
  831. + * (at your option) any later version.
  832. + *
  833. + * This program is distributed in the hope that it will be useful,
  834. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  835. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  836. + * GNU General Public License for more details.
  837. + *
  838. + * You should have received a copy of the GNU General Public License
  839. + * along with this program; if not, write to the Free Software
  840. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  841. + */
  842. +
  843. +#include <linux/autoconf.h>
  844. +#include <linux/init.h>
  845. +#include <linux/types.h>
  846. +#include <linux/module.h>
  847. +#include <linux/delay.h>
  848. +#include <linux/dma-mapping.h>
  849. +#include <linux/platform_device.h>
  850. +#include <linux/mtd/physmap.h>
  851. +#include <linux/serial.h>
  852. +#include <linux/serial_8250.h>
  853. +#include <linux/ioport.h>
  854. +#include <linux/io.h>
  855. +#include <linux/version.h>
  856. +#include <linux/vlynq.h>
  857. +#include <linux/leds.h>
  858. +#include <linux/string.h>
  859. +
  860. +#include <asm/addrspace.h>
  861. +#include <asm/mach-ar7/ar7.h>
  862. +#include <asm/mach-ar7/gpio.h>
  863. +#include <asm/mach-ar7/prom.h>
  864. +
  865. +struct plat_vlynq_data {
  866. + struct plat_vlynq_ops ops;
  867. + int gpio_bit;
  868. + int reset_bit;
  869. +};
  870. +
  871. +
  872. +static int vlynq_on(struct vlynq_device *dev)
  873. +{
  874. + int result;
  875. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  876. +
  877. + if ((result = gpio_request(pdata->gpio_bit, "vlynq")))
  878. + goto out;
  879. +
  880. + ar7_device_reset(pdata->reset_bit);
  881. +
  882. + if ((result = ar7_gpio_disable(pdata->gpio_bit)))
  883. + goto out_enabled;
  884. +
  885. + if ((result = ar7_gpio_enable(pdata->gpio_bit)))
  886. + goto out_enabled;
  887. +
  888. + if ((result = gpio_direction_output(pdata->gpio_bit, 0)))
  889. + goto out_gpio_enabled;
  890. +
  891. + mdelay(50);
  892. +
  893. + gpio_set_value(pdata->gpio_bit, 1);
  894. + mdelay(50);
  895. +
  896. + return 0;
  897. +
  898. +out_gpio_enabled:
  899. + ar7_gpio_disable(pdata->gpio_bit);
  900. +out_enabled:
  901. + ar7_device_disable(pdata->reset_bit);
  902. + gpio_free(pdata->gpio_bit);
  903. +out:
  904. + return result;
  905. +}
  906. +
  907. +static void vlynq_off(struct vlynq_device *dev)
  908. +{
  909. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  910. + ar7_gpio_disable(pdata->gpio_bit);
  911. + gpio_free(pdata->gpio_bit);
  912. + ar7_device_disable(pdata->reset_bit);
  913. +}
  914. +
  915. +static struct resource physmap_flash_resource = {
  916. + .name = "mem",
  917. + .flags = IORESOURCE_MEM,
  918. + .start = 0x10000000,
  919. + .end = 0x107fffff,
  920. +};
  921. +
  922. +static struct resource cpmac_low_res[] = {
  923. + {
  924. + .name = "regs",
  925. + .flags = IORESOURCE_MEM,
  926. + .start = AR7_REGS_MAC0,
  927. + .end = AR7_REGS_MAC0 + 0x7ff,
  928. + },
  929. + {
  930. + .name = "irq",
  931. + .flags = IORESOURCE_IRQ,
  932. + .start = 27,
  933. + .end = 27,
  934. + },
  935. +};
  936. +
  937. +static struct resource cpmac_high_res[] = {
  938. + {
  939. + .name = "regs",
  940. + .flags = IORESOURCE_MEM,
  941. + .start = AR7_REGS_MAC1,
  942. + .end = AR7_REGS_MAC1 + 0x7ff,
  943. + },
  944. + {
  945. + .name = "irq",
  946. + .flags = IORESOURCE_IRQ,
  947. + .start = 41,
  948. + .end = 41,
  949. + },
  950. +};
  951. +
  952. +static struct resource vlynq_low_res[] = {
  953. + {
  954. + .name = "regs",
  955. + .flags = IORESOURCE_MEM,
  956. + .start = AR7_REGS_VLYNQ0,
  957. + .end = AR7_REGS_VLYNQ0 + 0xff,
  958. + },
  959. + {
  960. + .name = "irq",
  961. + .flags = IORESOURCE_IRQ,
  962. + .start = 29,
  963. + .end = 29,
  964. + },
  965. + {
  966. + .name = "mem",
  967. + .flags = IORESOURCE_MEM,
  968. + .start = 0x04000000,
  969. + .end = 0x04ffffff,
  970. + },
  971. + {
  972. + .name = "devirq",
  973. + .flags = IORESOURCE_IRQ,
  974. + .start = 80,
  975. + .end = 111,
  976. + },
  977. +};
  978. +
  979. +static struct resource vlynq_high_res[] = {
  980. + {
  981. + .name = "regs",
  982. + .flags = IORESOURCE_MEM,
  983. + .start = AR7_REGS_VLYNQ1,
  984. + .end = AR7_REGS_VLYNQ1 + 0xff,
  985. + },
  986. + {
  987. + .name = "irq",
  988. + .flags = IORESOURCE_IRQ,
  989. + .start = 33,
  990. + .end = 33,
  991. + },
  992. + {
  993. + .name = "mem",
  994. + .flags = IORESOURCE_MEM,
  995. + .start = 0x0c000000,
  996. + .end = 0x0cffffff,
  997. + },
  998. + {
  999. + .name = "devirq",
  1000. + .flags = IORESOURCE_IRQ,
  1001. + .start = 112,
  1002. + .end = 143,
  1003. + },
  1004. +};
  1005. +
  1006. +static struct resource usb_res[] = {
  1007. + {
  1008. + .name = "regs",
  1009. + .flags = IORESOURCE_MEM,
  1010. + .start = AR7_REGS_USB,
  1011. + .end = AR7_REGS_USB + 0xff,
  1012. + },
  1013. + {
  1014. + .name = "irq",
  1015. + .flags = IORESOURCE_IRQ,
  1016. + .start = 32,
  1017. + .end = 32,
  1018. + },
  1019. + {
  1020. + .name = "mem",
  1021. + .flags = IORESOURCE_MEM,
  1022. + .start = 0x03400000,
  1023. + .end = 0x034001fff,
  1024. + },
  1025. +};
  1026. +
  1027. +static struct physmap_flash_data physmap_flash_data = {
  1028. + .width = 2,
  1029. +};
  1030. +
  1031. +static struct plat_cpmac_data cpmac_low_data = {
  1032. + .reset_bit = 17,
  1033. + .power_bit = 20,
  1034. + .phy_mask = 0x80000000,
  1035. +};
  1036. +
  1037. +static struct plat_cpmac_data cpmac_high_data = {
  1038. + .reset_bit = 21,
  1039. + .power_bit = 22,
  1040. + .phy_mask = 0x7fffffff,
  1041. +};
  1042. +
  1043. +static struct plat_vlynq_data vlynq_low_data = {
  1044. + .ops.on = vlynq_on,
  1045. + .ops.off = vlynq_off,
  1046. + .reset_bit = 20,
  1047. + .gpio_bit = 18,
  1048. +};
  1049. +
  1050. +static struct plat_vlynq_data vlynq_high_data = {
  1051. + .ops.on = vlynq_on,
  1052. + .ops.off = vlynq_off,
  1053. + .reset_bit = 16,
  1054. + .gpio_bit = 19,
  1055. +};
  1056. +
  1057. +static struct platform_device physmap_flash = {
  1058. + .id = 0,
  1059. + .name = "physmap-flash",
  1060. + .dev.platform_data = &physmap_flash_data,
  1061. + .resource = &physmap_flash_resource,
  1062. + .num_resources = 1,
  1063. +};
  1064. +
  1065. +static u64 cpmac_dma_mask = DMA_32BIT_MASK;
  1066. +static struct platform_device cpmac_low = {
  1067. + .id = 0,
  1068. + .name = "cpmac",
  1069. + .dev = {
  1070. + .dma_mask = &cpmac_dma_mask,
  1071. + .coherent_dma_mask = DMA_32BIT_MASK,
  1072. + .platform_data = &cpmac_low_data,
  1073. + },
  1074. + .resource = cpmac_low_res,
  1075. + .num_resources = ARRAY_SIZE(cpmac_low_res),
  1076. +};
  1077. +
  1078. +static struct platform_device cpmac_high = {
  1079. + .id = 1,
  1080. + .name = "cpmac",
  1081. + .dev = {
  1082. + .dma_mask = &cpmac_dma_mask,
  1083. + .coherent_dma_mask = DMA_32BIT_MASK,
  1084. + .platform_data = &cpmac_high_data,
  1085. + },
  1086. + .resource = cpmac_high_res,
  1087. + .num_resources = ARRAY_SIZE(cpmac_high_res),
  1088. +};
  1089. +
  1090. +static struct platform_device vlynq_low = {
  1091. + .id = 0,
  1092. + .name = "vlynq",
  1093. + .dev.platform_data = &vlynq_low_data,
  1094. + .resource = vlynq_low_res,
  1095. + .num_resources = ARRAY_SIZE(vlynq_low_res),
  1096. +};
  1097. +
  1098. +static struct platform_device vlynq_high = {
  1099. + .id = 1,
  1100. + .name = "vlynq",
  1101. + .dev.platform_data = &vlynq_high_data,
  1102. + .resource = vlynq_high_res,
  1103. + .num_resources = ARRAY_SIZE(vlynq_high_res),
  1104. +};
  1105. +
  1106. +
  1107. +/* This is proper way to define uart ports, but they are then detected
  1108. + * as xscale and, obviously, don't work...
  1109. + */
  1110. +#if !defined(CONFIG_SERIAL_8250)
  1111. +
  1112. +static struct plat_serial8250_port uart0_data = {
  1113. + .mapbase = AR7_REGS_UART0,
  1114. + .irq = AR7_IRQ_UART0,
  1115. + .regshift = 2,
  1116. + .iotype = UPIO_MEM,
  1117. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1118. +};
  1119. +
  1120. +static struct plat_serial8250_port uart1_data = {
  1121. + .mapbase = UR8_REGS_UART1,
  1122. + .irq = AR7_IRQ_UART1,
  1123. + .regshift = 2,
  1124. + .iotype = UPIO_MEM,
  1125. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1126. +};
  1127. +
  1128. +static struct plat_serial8250_port uart_data[] = {
  1129. + uart0_data,
  1130. + uart1_data,
  1131. + { .flags = 0 }
  1132. +};
  1133. +
  1134. +static struct plat_serial8250_port uart_data_single[] = {
  1135. + uart0_data,
  1136. + { .flags = 0 }
  1137. +};
  1138. +
  1139. +static struct platform_device uart = {
  1140. + .id = 0,
  1141. + .name = "serial8250",
  1142. + .dev.platform_data = uart_data_single
  1143. +};
  1144. +#endif
  1145. +
  1146. +static struct gpio_led default_leds[] = {
  1147. + { .name = "status", .gpio = 8, .active_low = 1, },
  1148. +};
  1149. +
  1150. +static struct gpio_led dsl502t_leds[] = {
  1151. + { .name = "status", .gpio = 9, .active_low = 1, },
  1152. + { .name = "ethernet", .gpio = 7, .active_low = 1, },
  1153. + { .name = "usb", .gpio = 12, .active_low = 1, },
  1154. +};
  1155. +
  1156. +static struct gpio_led dg834g_leds[] = {
  1157. + { .name = "ppp", .gpio = 6, .active_low = 1, },
  1158. + { .name = "status", .gpio = 7, .active_low = 1, },
  1159. + { .name = "adsl", .gpio = 8, .active_low = 1, },
  1160. + { .name = "wifi", .gpio = 12, .active_low = 1, },
  1161. + { .name = "power", .gpio = 14, .active_low = 1, .default_trigger = "default-on", },
  1162. +};
  1163. +
  1164. +static struct gpio_led fb_sl_leds[] = {
  1165. + { .name = "1", .gpio = 7, },
  1166. + { .name = "2", .gpio = 13, .active_low = 1, },
  1167. + { .name = "3", .gpio = 10, .active_low = 1, },
  1168. + { .name = "4", .gpio = 12, .active_low = 1, },
  1169. + { .name = "5", .gpio = 9, .active_low = 1, },
  1170. +};
  1171. +
  1172. +static struct gpio_led fb_fon_leds[] = {
  1173. + { .name = "1", .gpio = 8, },
  1174. + { .name = "2", .gpio = 3, .active_low = 1, },
  1175. + { .name = "3", .gpio = 5, },
  1176. + { .name = "4", .gpio = 4, .active_low = 1, },
  1177. + { .name = "5", .gpio = 11, .active_low = 1, },
  1178. +};
  1179. +
  1180. +static struct gpio_led_platform_data ar7_led_data;
  1181. +
  1182. +static struct platform_device ar7_gpio_leds = {
  1183. + .name = "leds-gpio",
  1184. + .id = -1,
  1185. + .dev = {
  1186. + .platform_data = &ar7_led_data,
  1187. + }
  1188. +};
  1189. +
  1190. +static struct platform_device ar7_udc = {
  1191. + .id = -1,
  1192. + .name = "ar7_udc",
  1193. + .resource = usb_res,
  1194. + .num_resources = ARRAY_SIZE(usb_res),
  1195. +};
  1196. +
  1197. +static inline unsigned char char2hex(char h)
  1198. +{
  1199. + switch (h) {
  1200. + case '0': case '1': case '2': case '3': case '4':
  1201. + case '5': case '6': case '7': case '8': case '9':
  1202. + return h - '0';
  1203. + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  1204. + return h - 'A' + 10;
  1205. + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  1206. + return h - 'a' + 10;
  1207. + default:
  1208. + return 0;
  1209. + }
  1210. +}
  1211. +
  1212. +static void cpmac_get_mac(int instance, unsigned char *dev_addr)
  1213. +{
  1214. + int i;
  1215. + char name[5], default_mac[] = "00:00:00:12:34:56", *mac;
  1216. +
  1217. + mac = NULL;
  1218. + sprintf(name, "mac%c", 'a' + instance);
  1219. + mac = prom_getenv(name);
  1220. + if (!mac) {
  1221. + sprintf(name, "mac%c", 'a');
  1222. + mac = prom_getenv(name);
  1223. + }
  1224. + if (!mac)
  1225. + mac = default_mac;
  1226. + for (i = 0; i < 6; i++)
  1227. + dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
  1228. + char2hex(mac[i * 3 + 1]);
  1229. +}
  1230. +
  1231. +static void __init detect_leds(void)
  1232. +{
  1233. + char *prId, *usb_prod;
  1234. +
  1235. + /* Default LEDs */
  1236. + ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
  1237. + ar7_led_data.leds = default_leds;
  1238. +
  1239. + /* FIXME: the whole thing is unreliable */
  1240. + prId = prom_getenv("ProductID");
  1241. + usb_prod = prom_getenv("usb_prod");
  1242. +
  1243. + /* If we can't get the product id from PROM, use the default LEDs */
  1244. + if (!prId)
  1245. + return;
  1246. +
  1247. + if (strstr(prId, "Fritz_Box_FON")) {
  1248. + ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
  1249. + ar7_led_data.leds = fb_fon_leds;
  1250. + } else if (strstr(prId, "Fritz_Box_")) {
  1251. + ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
  1252. + ar7_led_data.leds = fb_sl_leds;
  1253. + } else if ((!strcmp(prId, "AR7RD") || !strcmp(prId, "AR7DB")) && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
  1254. + ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
  1255. + ar7_led_data.leds = dsl502t_leds;
  1256. + } else if (strstr(prId, "DG834")) {
  1257. + ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
  1258. + ar7_led_data.leds = dg834g_leds;
  1259. + }
  1260. +}
  1261. +
  1262. +static int __init ar7_register_devices(void)
  1263. +{
  1264. + int res;
  1265. +
  1266. +#ifdef CONFIG_SERIAL_8250
  1267. +
  1268. + static struct uart_port uart_port[2];
  1269. +
  1270. + memset(uart_port, 0, sizeof(struct uart_port) * 2);
  1271. +
  1272. + // use default type
  1273. + //uart_port[0].type = PORT_AR7;
  1274. + uart_port[0].line = 0;
  1275. + uart_port[0].irq = AR7_IRQ_UART0;
  1276. + uart_port[0].uartclk = ar7_bus_freq() / 2;
  1277. + uart_port[0].iotype = UPIO_MEM;
  1278. + uart_port[0].mapbase = AR7_REGS_UART0;
  1279. + uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
  1280. + uart_port[0].regshift = 2;
  1281. + res = early_serial_setup(&uart_port[0]);
  1282. + if (res)
  1283. + return res;
  1284. +
  1285. +
  1286. + /* Only TNETD73xx have a second serial port */
  1287. + if (ar7_has_second_uart()) {
  1288. + // use default type
  1289. + //uart_port[1].type = PORT_AR7;
  1290. + uart_port[1].line = 1;
  1291. + uart_port[1].irq = AR7_IRQ_UART1;
  1292. + uart_port[1].uartclk = ar7_bus_freq() / 2;
  1293. + uart_port[1].iotype = UPIO_MEM;
  1294. + uart_port[1].mapbase = UR8_REGS_UART1;
  1295. + uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
  1296. + uart_port[1].regshift = 2;
  1297. + res = early_serial_setup(&uart_port[1]);
  1298. + if (res)
  1299. + return res;
  1300. + }
  1301. +
  1302. +#else /* !CONFIG_SERIAL_8250 */
  1303. +
  1304. + uart_data[0].uartclk = ar7_bus_freq() / 2;
  1305. + uart_data[1].uartclk = uart_data[0].uartclk;
  1306. +
  1307. + /* Only TNETD73xx have a second serial port */
  1308. + if (ar7_has_second_uart())
  1309. + uart.dev.platform_data = uart_data;
  1310. +
  1311. + res = platform_device_register(&uart);
  1312. + if (res)
  1313. + return res;
  1314. +
  1315. +#endif /* CONFIG_SERIAL_8250 */
  1316. +
  1317. + res = platform_device_register(&physmap_flash);
  1318. + if (res)
  1319. + return res;
  1320. +
  1321. + ar7_device_disable(vlynq_low_data.reset_bit);
  1322. + res = platform_device_register(&vlynq_low);
  1323. + if (res)
  1324. + return res;
  1325. +
  1326. + if (ar7_has_high_vlynq()) {
  1327. + ar7_device_disable(vlynq_high_data.reset_bit);
  1328. + res = platform_device_register(&vlynq_high);
  1329. + if (res)
  1330. + return res;
  1331. + }
  1332. +
  1333. + if (ar7_has_high_cpmac()) {
  1334. + cpmac_get_mac(1, cpmac_high_data.dev_addr);
  1335. + res = platform_device_register(&cpmac_high);
  1336. + if (res)
  1337. + return res;
  1338. + } else {
  1339. + cpmac_low_data.phy_mask = 0xffffffff;
  1340. + }
  1341. +
  1342. + cpmac_get_mac(0, cpmac_low_data.dev_addr);
  1343. + res = platform_device_register(&cpmac_low);
  1344. + if (res)
  1345. + return res;
  1346. +
  1347. + detect_leds();
  1348. + res = platform_device_register(&ar7_gpio_leds);
  1349. + if (res)
  1350. + return res;
  1351. +
  1352. + res = platform_device_register(&ar7_udc);
  1353. +
  1354. + return res;
  1355. +}
  1356. +
  1357. +
  1358. +arch_initcall(ar7_register_devices);
  1359. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/prom.c linux-2.6.29.1/arch/mips/ar7/prom.c
  1360. --- linux-2.6.29.1.orig/arch/mips/ar7/prom.c 1970-01-01 01:00:00.000000000 +0100
  1361. +++ linux-2.6.29.1/arch/mips/ar7/prom.c 2009-05-31 20:18:44.000000000 +0200
  1362. @@ -0,0 +1,321 @@
  1363. +/*
  1364. + * Carsten Langgaard, carstenl@mips.com
  1365. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1366. + *
  1367. + * This program is free software; you can distribute it and/or modify it
  1368. + * under the terms of the GNU General Public License (Version 2) as
  1369. + * published by the Free Software Foundation.
  1370. + *
  1371. + * This program is distributed in the hope it will be useful, but WITHOUT
  1372. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1373. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1374. + * for more details.
  1375. + *
  1376. + * You should have received a copy of the GNU General Public License along
  1377. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1378. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1379. + *
  1380. + * Putting things on the screen/serial line using YAMONs facilities.
  1381. + */
  1382. +#include <linux/init.h>
  1383. +#include <linux/kernel.h>
  1384. +#include <linux/serial_reg.h>
  1385. +#include <linux/spinlock.h>
  1386. +#include <linux/module.h>
  1387. +#include <linux/string.h>
  1388. +#include <linux/io.h>
  1389. +#include <asm/bootinfo.h>
  1390. +
  1391. +#include <asm/mach-ar7/ar7.h>
  1392. +#include <asm/mach-ar7/prom.h>
  1393. +
  1394. +#define MAX_ENTRY 80
  1395. +
  1396. +struct env_var {
  1397. + char *name;
  1398. + char *value;
  1399. +};
  1400. +
  1401. +static struct env_var adam2_env[MAX_ENTRY] = { { 0, }, };
  1402. +
  1403. +char *prom_getenv(const char *name)
  1404. +{
  1405. + int i;
  1406. + for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
  1407. + if (!strcmp(name, adam2_env[i].name))
  1408. + return adam2_env[i].value;
  1409. +
  1410. + return NULL;
  1411. +}
  1412. +EXPORT_SYMBOL(prom_getenv);
  1413. +
  1414. +char * __init prom_getcmdline(void)
  1415. +{
  1416. + return &(arcs_cmdline[0]);
  1417. +}
  1418. +
  1419. +static void __init ar7_init_cmdline(int argc, char *argv[])
  1420. +{
  1421. + char *cp;
  1422. + int actr;
  1423. +
  1424. + actr = 1; /* Always ignore argv[0] */
  1425. +
  1426. + cp = &(arcs_cmdline[0]);
  1427. + while (actr < argc) {
  1428. + strcpy(cp, argv[actr]);
  1429. + cp += strlen(argv[actr]);
  1430. + *cp++ = ' ';
  1431. + actr++;
  1432. + }
  1433. + if (cp != &(arcs_cmdline[0])) {
  1434. + /* get rid of trailing space */
  1435. + --cp;
  1436. + *cp = '\0';
  1437. + }
  1438. +}
  1439. +
  1440. +struct psbl_rec {
  1441. + u32 psbl_size;
  1442. + u32 env_base;
  1443. + u32 env_size;
  1444. + u32 ffs_base;
  1445. + u32 ffs_size;
  1446. +};
  1447. +
  1448. +static __initdata char psp_env_version[] = "TIENV0.8";
  1449. +
  1450. +struct psp_env_chunk {
  1451. + u8 num;
  1452. + u8 ctrl;
  1453. + u16 csum;
  1454. + u8 len;
  1455. + char data[11];
  1456. +} __attribute__ ((packed));
  1457. +
  1458. +struct psp_var_map_entry {
  1459. + u8 num;
  1460. + char *value;
  1461. +};
  1462. +
  1463. +static struct psp_var_map_entry psp_var_map[] = {
  1464. + { 1, "cpufrequency" },
  1465. + { 2, "memsize" },
  1466. + { 3, "flashsize" },
  1467. + { 4, "modetty0" },
  1468. + { 5, "modetty1" },
  1469. + { 8, "maca" },
  1470. + { 9, "macb" },
  1471. + { 28, "sysfrequency" },
  1472. + { 38, "mipsfrequency" },
  1473. +};
  1474. +
  1475. +/*
  1476. +
  1477. +Well-known variable (num is looked up in table above for matching variable name)
  1478. +Example: cpufrequency=211968000
  1479. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1480. +| 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
  1481. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1482. +
  1483. +Name=Value pair in a single chunk
  1484. +Example: NAME=VALUE
  1485. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1486. +| 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
  1487. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1488. +
  1489. +Name=Value pair in 2 chunks (len is the number of chunks)
  1490. +Example: bootloaderVersion=1.3.7.15
  1491. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1492. +| 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
  1493. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1494. +| _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
  1495. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1496. +
  1497. +Data is padded with 0xFF
  1498. +
  1499. +*/
  1500. +
  1501. +#define PSP_ENV_SIZE 4096
  1502. +
  1503. +static char psp_env_data[PSP_ENV_SIZE] = { 0, };
  1504. +
  1505. +static char * __init lookup_psp_var_map(u8 num)
  1506. +{
  1507. + int i;
  1508. +
  1509. + for (i = 0; i < sizeof(psp_var_map); i++)
  1510. + if (psp_var_map[i].num == num)
  1511. + return psp_var_map[i].value;
  1512. +
  1513. + return NULL;
  1514. +}
  1515. +
  1516. +static void __init add_adam2_var(char *name, char *value)
  1517. +{
  1518. + int i;
  1519. + for (i = 0; i < MAX_ENTRY; i++) {
  1520. + if (!adam2_env[i].name) {
  1521. + adam2_env[i].name = name;
  1522. + adam2_env[i].value = value;
  1523. + return;
  1524. + } else if (!strcmp(adam2_env[i].name, name)) {
  1525. + adam2_env[i].value = value;
  1526. + return;
  1527. + }
  1528. + }
  1529. +}
  1530. +
  1531. +static int __init parse_psp_env(void *psp_env_base)
  1532. +{
  1533. + int i, n;
  1534. + char *name, *value;
  1535. + struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
  1536. +
  1537. + memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
  1538. +
  1539. + i = 1;
  1540. + n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
  1541. + while (i < n) {
  1542. + if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
  1543. + break;
  1544. + value = chunks[i].data;
  1545. + if (chunks[i].num) {
  1546. + name = lookup_psp_var_map(chunks[i].num);
  1547. + } else {
  1548. + name = value;
  1549. + value += strlen(name) + 1;
  1550. + }
  1551. + if (name)
  1552. + add_adam2_var(name, value);
  1553. + i += chunks[i].len;
  1554. + }
  1555. + return 0;
  1556. +}
  1557. +
  1558. +static void __init ar7_init_env(struct env_var *env)
  1559. +{
  1560. + int i;
  1561. + struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
  1562. + void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
  1563. +
  1564. + if (strcmp(psp_env, psp_env_version) == 0) {
  1565. + parse_psp_env(psp_env);
  1566. + } else {
  1567. + for (i = 0; i < MAX_ENTRY; i++, env++)
  1568. + if (env->name)
  1569. + add_adam2_var(env->name, env->value);
  1570. + }
  1571. +}
  1572. +
  1573. +static void __init console_config(void)
  1574. +{
  1575. +#ifdef CONFIG_SERIAL_8250_CONSOLE
  1576. + char console_string[40];
  1577. + int baud = 0;
  1578. + char parity = '\0', bits = '\0', flow = '\0';
  1579. + char *s, *p;
  1580. +
  1581. + if (strstr(prom_getcmdline(), "console="))
  1582. + return;
  1583. +
  1584. +#ifdef CONFIG_KGDB
  1585. + if (!strstr(prom_getcmdline(), "nokgdb")) {
  1586. + strcat(prom_getcmdline(), " console=kgdb");
  1587. + kgdb_enabled = 1;
  1588. + return;
  1589. + }
  1590. +#endif
  1591. +
  1592. + if ((s = prom_getenv("modetty0"))) {
  1593. + baud = simple_strtoul(s, &p, 10);
  1594. + s = p;
  1595. + if (*s == ',') s++;
  1596. + if (*s) parity = *s++;
  1597. + if (*s == ',') s++;
  1598. + if (*s) bits = *s++;
  1599. + if (*s == ',') s++;
  1600. + if (*s == 'h') flow = 'r';
  1601. + }
  1602. +
  1603. + if (baud == 0)
  1604. + baud = 38400;
  1605. + if (parity != 'n' && parity != 'o' && parity != 'e')
  1606. + parity = 'n';
  1607. + if (bits != '7' && bits != '8')
  1608. + bits = '8';
  1609. +
  1610. + if (flow == 'r')
  1611. + sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  1612. + parity, bits, flow);
  1613. + else
  1614. + sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
  1615. + bits);
  1616. + strcat(prom_getcmdline(), console_string);
  1617. +#endif
  1618. +}
  1619. +
  1620. +void __init prom_init(void)
  1621. +{
  1622. + ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
  1623. + ar7_init_env((struct env_var *)fw_arg2);
  1624. + console_config();
  1625. +}
  1626. +
  1627. +#define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
  1628. +static inline unsigned int serial_in(int offset)
  1629. +{
  1630. + return readb((void *)PORT(offset));
  1631. +}
  1632. +
  1633. +static inline void serial_out(int offset, int value)
  1634. +{
  1635. + writeb(value, (void *)PORT(offset));
  1636. +}
  1637. +
  1638. +char prom_getchar(void)
  1639. +{
  1640. + while (!(serial_in(UART_LSR) & UART_LSR_DR));
  1641. + return serial_in(UART_RX);
  1642. +}
  1643. +
  1644. +int prom_putchar(char c)
  1645. +{
  1646. + while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0);
  1647. + serial_out(UART_TX, c);
  1648. + return 1;
  1649. +}
  1650. +
  1651. +/* from adm5120/prom.c */
  1652. +void prom_printf(const char *fmt, ...)
  1653. +{
  1654. + va_list args;
  1655. + int l;
  1656. + char *p, *buf_end;
  1657. + char buf[1024];
  1658. +
  1659. + va_start(args, fmt);
  1660. + l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
  1661. + va_end(args);
  1662. +
  1663. + buf_end = buf + l;
  1664. +
  1665. + for (p = buf; p < buf_end; p++) {
  1666. + /* Crude cr/nl handling is better than none */
  1667. + if (*p == '\n')
  1668. + prom_putchar('\r');
  1669. + prom_putchar(*p);
  1670. + }
  1671. +}
  1672. +
  1673. +#ifdef CONFIG_KGDB
  1674. +int putDebugChar(char c)
  1675. +{
  1676. + return prom_putchar(c);
  1677. +}
  1678. +
  1679. +char getDebugChar(void)
  1680. +{
  1681. + return prom_getchar();
  1682. +}
  1683. +#endif
  1684. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/setup.c linux-2.6.29.1/arch/mips/ar7/setup.c
  1685. --- linux-2.6.29.1.orig/arch/mips/ar7/setup.c 1970-01-01 01:00:00.000000000 +0100
  1686. +++ linux-2.6.29.1/arch/mips/ar7/setup.c 2009-06-01 12:36:33.000000000 +0200
  1687. @@ -0,0 +1,105 @@
  1688. +/*
  1689. + * Carsten Langgaard, carstenl@mips.com
  1690. + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  1691. + *
  1692. + * This program is free software; you can distribute it and/or modify it
  1693. + * under the terms of the GNU General Public License (Version 2) as
  1694. + * published by the Free Software Foundation.
  1695. + *
  1696. + * This program is distributed in the hope it will be useful, but WITHOUT
  1697. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1698. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1699. + * for more details.
  1700. + *
  1701. + * You should have received a copy of the GNU General Public License along
  1702. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1703. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1704. + */
  1705. +#include <linux/version.h>
  1706. +#include <linux/init.h>
  1707. +#include <linux/ioport.h>
  1708. +#include <linux/pm.h>
  1709. +
  1710. +#include <asm/reboot.h>
  1711. +#include <asm/time.h>
  1712. +#include <asm/mach-ar7/ar7.h>
  1713. +#include <asm/mach-ar7/prom.h>
  1714. +
  1715. +static void ar7_machine_restart(char *command);
  1716. +static void ar7_machine_halt(void);
  1717. +static void ar7_machine_power_off(void);
  1718. +
  1719. +static void ar7_machine_restart(char *command)
  1720. +{
  1721. + u32 *softres_reg = (u32 *)ioremap(AR7_REGS_RESET +
  1722. + AR7_RESET_SOFTWARE, 1);
  1723. + writel(1, softres_reg);
  1724. +}
  1725. +
  1726. +static void ar7_machine_halt(void)
  1727. +{
  1728. + while (1);
  1729. +}
  1730. +
  1731. +static void ar7_machine_power_off(void)
  1732. +{
  1733. + u32 *power_reg = (u32 *)ioremap(AR7_REGS_POWER, 1);
  1734. + u32 power_state = readl(power_reg) | (3 << 30);
  1735. + writel(power_state, power_reg);
  1736. + ar7_machine_halt();
  1737. +}
  1738. +
  1739. +const char *get_system_type(void)
  1740. +{
  1741. + u16 chip_id = ar7_chip_id();
  1742. + switch (chip_id) {
  1743. + case AR7_CHIP_7300:
  1744. + return "TI AR7 (TNETD7300)";
  1745. + case AR7_CHIP_7100:
  1746. + return "TI AR7 (TNETD7100)";
  1747. + case AR7_CHIP_7200:
  1748. + return "TI AR7 (TNETD7200)";
  1749. + default:
  1750. + return "TI AR7 (Unknown)";
  1751. + }
  1752. +}
  1753. +
  1754. +static int __init ar7_init_console(void)
  1755. +{
  1756. + return 0;
  1757. +}
  1758. +
  1759. +/*
  1760. + * Initializes basic routines and structures pointers, memory size (as
  1761. + * given by the bios and saves the command line.
  1762. + */
  1763. +
  1764. +extern void ar7_init_clocks(void);
  1765. +
  1766. +void __init plat_mem_setup(void)
  1767. +{
  1768. + unsigned long io_base;
  1769. +
  1770. + _machine_restart = ar7_machine_restart;
  1771. + _machine_halt = ar7_machine_halt;
  1772. + pm_power_off = ar7_machine_power_off;
  1773. + panic_timeout = 3;
  1774. +
  1775. + io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
  1776. + if (!io_base) panic("Can't remap IO base!\n");
  1777. + set_io_port_base(io_base);
  1778. +
  1779. + prom_meminit();
  1780. + ar7_init_clocks();
  1781. +
  1782. + ioport_resource.start = 0;
  1783. + ioport_resource.end = ~0;
  1784. + iomem_resource.start = 0;
  1785. + iomem_resource.end = ~0;
  1786. +
  1787. + printk(KERN_INFO "%s, ID: 0x%04x, Revision: 0x%02x\n",
  1788. + get_system_type(),
  1789. + ar7_chip_id(), ar7_chip_rev());
  1790. +}
  1791. +
  1792. +console_initcall(ar7_init_console);
  1793. diff -Nur linux-2.6.29.1.orig/arch/mips/ar7/time.c linux-2.6.29.1/arch/mips/ar7/time.c
  1794. --- linux-2.6.29.1.orig/arch/mips/ar7/time.c 1970-01-01 01:00:00.000000000 +0100
  1795. +++ linux-2.6.29.1/arch/mips/ar7/time.c 2009-06-01 12:37:00.000000000 +0200
  1796. @@ -0,0 +1,28 @@
  1797. +/*
  1798. + * Carsten Langgaard, carstenl@mips.com
  1799. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1800. + *
  1801. + * This program is free software; you can distribute it and/or modify it
  1802. + * under the terms of the GNU General Public License (Version 2) as
  1803. + * published by the Free Software Foundation.
  1804. + *
  1805. + * This program is distributed in the hope it will be useful, but WITHOUT
  1806. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1807. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1808. + * for more details.
  1809. + *
  1810. + * You should have received a copy of the GNU General Public License along
  1811. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1812. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1813. + *
  1814. + * Setting up the clock on the MIPS boards.
  1815. + */
  1816. +
  1817. +#include <linux/version.h>
  1818. +#include <asm/time.h>
  1819. +#include <asm/mach-ar7/ar7.h>
  1820. +
  1821. +void __init plat_time_init(void)
  1822. +{
  1823. + mips_hpt_frequency = ar7_cpu_freq() / 2;
  1824. +}
  1825. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/ar7.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/ar7.h
  1826. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/ar7.h 1970-01-01 01:00:00.000000000 +0100
  1827. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/ar7.h 2009-05-31 19:50:04.000000000 +0200
  1828. @@ -0,0 +1,170 @@
  1829. +/*
  1830. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  1831. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  1832. + *
  1833. + * This program is free software; you can redistribute it and/or modify
  1834. + * it under the terms of the GNU General Public License as published by
  1835. + * the Free Software Foundation; either version 2 of the License, or
  1836. + * (at your option) any later version.
  1837. + *
  1838. + * This program is distributed in the hope that it will be useful,
  1839. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1840. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1841. + * GNU General Public License for more details.
  1842. + *
  1843. + * You should have received a copy of the GNU General Public License
  1844. + * along with this program; if not, write to the Free Software
  1845. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  1846. + */
  1847. +
  1848. +#ifndef __AR7_H__
  1849. +#define __AR7_H__
  1850. +
  1851. +#include <linux/delay.h>
  1852. +#include <asm/addrspace.h>
  1853. +#include <linux/io.h>
  1854. +
  1855. +#define AR7_REGS_BASE 0x08610000
  1856. +
  1857. +#define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  1858. +#define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  1859. +/* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  1860. +#define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  1861. +#define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  1862. +#define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  1863. +#define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  1864. +#define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  1865. +#define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  1866. +#define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  1867. +#define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  1868. +#define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  1869. +#define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  1870. +
  1871. +#define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  1872. +#define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  1873. +#define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  1874. +
  1875. +#define AR7_RESET_PEREPHERIAL 0x0
  1876. +#define AR7_RESET_SOFTWARE 0x4
  1877. +#define AR7_RESET_STATUS 0x8
  1878. +
  1879. +#define AR7_RESET_BIT_CPMAC_LO 17
  1880. +#define AR7_RESET_BIT_CPMAC_HI 21
  1881. +#define AR7_RESET_BIT_MDIO 22
  1882. +#define AR7_RESET_BIT_EPHY 26
  1883. +
  1884. +/* GPIO control registers */
  1885. +#define AR7_GPIO_INPUT 0x0
  1886. +#define AR7_GPIO_OUTPUT 0x4
  1887. +#define AR7_GPIO_DIR 0x8
  1888. +#define AR7_GPIO_ENABLE 0xc
  1889. +
  1890. +#define AR7_CHIP_7100 0x18
  1891. +#define AR7_CHIP_7200 0x2b
  1892. +#define AR7_CHIP_7300 0x05
  1893. +
  1894. +/* Interrupts */
  1895. +#define AR7_IRQ_UART0 15
  1896. +#define AR7_IRQ_UART1 16
  1897. +
  1898. +/* Clocks */
  1899. +#define AR7_AFE_CLOCK 35328000
  1900. +#define AR7_REF_CLOCK 25000000
  1901. +#define AR7_XTAL_CLOCK 24000000
  1902. +
  1903. +struct plat_cpmac_data {
  1904. + int reset_bit;
  1905. + int power_bit;
  1906. + u32 phy_mask;
  1907. + char dev_addr[6];
  1908. +};
  1909. +
  1910. +struct plat_dsl_data {
  1911. + int reset_bit_dsl;
  1912. + int reset_bit_sar;
  1913. +};
  1914. +
  1915. +extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
  1916. +
  1917. +static inline u16 ar7_chip_id(void)
  1918. +{
  1919. + return readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff;
  1920. +}
  1921. +
  1922. +static inline u8 ar7_chip_rev(void)
  1923. +{
  1924. + return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) >> 16) & 0xff;
  1925. +}
  1926. +
  1927. +static inline int ar7_cpu_freq(void)
  1928. +{
  1929. + return ar7_cpu_clock;
  1930. +}
  1931. +
  1932. +static inline int ar7_bus_freq(void)
  1933. +{
  1934. + return ar7_bus_clock;
  1935. +}
  1936. +
  1937. +static inline int ar7_vbus_freq(void)
  1938. +{
  1939. + return ar7_bus_clock / 2;
  1940. +}
  1941. +#define ar7_cpmac_freq ar7_vbus_freq
  1942. +
  1943. +static inline int ar7_dsp_freq(void)
  1944. +{
  1945. + return ar7_dsp_clock;
  1946. +}
  1947. +
  1948. +static inline int ar7_has_high_cpmac(void)
  1949. +{
  1950. + u16 chip_id = ar7_chip_id();
  1951. + switch (chip_id) {
  1952. + case AR7_CHIP_7100:
  1953. + case AR7_CHIP_7200:
  1954. + return 0;
  1955. + default:
  1956. + return 1;
  1957. + }
  1958. +}
  1959. +#define ar7_has_high_vlynq ar7_has_high_cpmac
  1960. +#define ar7_has_second_uart ar7_has_high_cpmac
  1961. +
  1962. +static inline void ar7_device_enable(u32 bit)
  1963. +{
  1964. + void *reset_reg =
  1965. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  1966. + writel(readl(reset_reg) | (1 << bit), reset_reg);
  1967. + mdelay(20);
  1968. +}
  1969. +
  1970. +static inline void ar7_device_disable(u32 bit)
  1971. +{
  1972. + void *reset_reg =
  1973. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  1974. + writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  1975. + mdelay(20);
  1976. +}
  1977. +
  1978. +static inline void ar7_device_reset(u32 bit)
  1979. +{
  1980. + ar7_device_disable(bit);
  1981. + ar7_device_enable(bit);
  1982. +}
  1983. +
  1984. +static inline void ar7_device_on(u32 bit)
  1985. +{
  1986. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  1987. + writel(readl(power_reg) | (1 << bit), power_reg);
  1988. + mdelay(20);
  1989. +}
  1990. +
  1991. +static inline void ar7_device_off(u32 bit)
  1992. +{
  1993. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  1994. + writel(readl(power_reg) & ~(1 << bit), power_reg);
  1995. + mdelay(20);
  1996. +}
  1997. +
  1998. +#endif /* __AR7_H__ */
  1999. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/gpio.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/gpio.h
  2000. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/gpio.h 1970-01-01 01:00:00.000000000 +0100
  2001. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/gpio.h 2009-05-31 20:26:23.000000000 +0200
  2002. @@ -0,0 +1,109 @@
  2003. +/*
  2004. + * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  2005. + *
  2006. + * This program is free software; you can redistribute it and/or modify
  2007. + * it under the terms of the GNU General Public License as published by
  2008. + * the Free Software Foundation; either version 2 of the License, or
  2009. + * (at your option) any later version.
  2010. + *
  2011. + * This program is distributed in the hope that it will be useful,
  2012. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2013. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2014. + * GNU General Public License for more details.
  2015. + *
  2016. + * You should have received a copy of the GNU General Public License
  2017. + * along with this program; if not, write to the Free Software
  2018. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2019. + */
  2020. +
  2021. +#ifndef __AR7_GPIO_H__
  2022. +#define __AR7_GPIO_H__
  2023. +#include <asm/mach-ar7/ar7.h>
  2024. +
  2025. +#define AR7_GPIO_MAX 32
  2026. +
  2027. +extern int gpio_request(unsigned gpio, const char *label);
  2028. +extern void gpio_free(unsigned gpio);
  2029. +
  2030. +/* Common GPIO layer */
  2031. +static inline int gpio_get_value(unsigned gpio)
  2032. +{
  2033. + void __iomem *gpio_in =
  2034. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
  2035. +
  2036. + return readl(gpio_in) & (1 << gpio);
  2037. +}
  2038. +
  2039. +static inline void gpio_set_value(unsigned gpio, int value)
  2040. +{
  2041. + void __iomem *gpio_out =
  2042. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
  2043. + unsigned tmp;
  2044. +
  2045. + tmp = readl(gpio_out) & ~(1 << gpio);
  2046. + if (value)
  2047. + tmp |= 1 << gpio;
  2048. + writel(tmp, gpio_out);
  2049. +}
  2050. +
  2051. +static inline int gpio_direction_input(unsigned gpio)
  2052. +{
  2053. + void __iomem *gpio_dir =
  2054. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2055. +
  2056. + if (gpio >= AR7_GPIO_MAX)
  2057. + return -EINVAL;
  2058. +
  2059. + writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
  2060. +
  2061. + return 0;
  2062. +}
  2063. +
  2064. +static inline int gpio_direction_output(unsigned gpio, int value)
  2065. +{
  2066. + void __iomem *gpio_dir =
  2067. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2068. +
  2069. + if (gpio >= AR7_GPIO_MAX)
  2070. + return -EINVAL;
  2071. +
  2072. + gpio_set_value(gpio, value);
  2073. + writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
  2074. +
  2075. + return 0;
  2076. +}
  2077. +
  2078. +static inline int gpio_to_irq(unsigned gpio)
  2079. +{
  2080. + return -EINVAL;
  2081. +}
  2082. +
  2083. +static inline int irq_to_gpio(unsigned irq)
  2084. +{
  2085. + return -EINVAL;
  2086. +}
  2087. +
  2088. +/* Board specific GPIO functions */
  2089. +static inline int ar7_gpio_enable(unsigned gpio)
  2090. +{
  2091. + void __iomem *gpio_en =
  2092. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2093. +
  2094. + writel(readl(gpio_en) | (1 << gpio), gpio_en);
  2095. +
  2096. + return 0;
  2097. +}
  2098. +
  2099. +static inline int ar7_gpio_disable(unsigned gpio)
  2100. +{
  2101. + void __iomem *gpio_en =
  2102. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2103. +
  2104. + writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
  2105. +
  2106. + return 0;
  2107. +}
  2108. +
  2109. +#include <asm-generic/gpio.h>
  2110. +
  2111. +#endif
  2112. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/irq.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/irq.h
  2113. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/irq.h 1970-01-01 01:00:00.000000000 +0100
  2114. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/irq.h 2009-05-31 19:50:04.000000000 +0200
  2115. @@ -0,0 +1,16 @@
  2116. +/*
  2117. + * This file is subject to the terms and conditions of the GNU General Public
  2118. + * License. See the file "COPYING" in the main directory of this archive
  2119. + * for more details.
  2120. + *
  2121. + * Shamelessly copied from asm-mips/mach-emma2rh/
  2122. + * Copyright (C) 2003 by Ralf Baechle
  2123. + */
  2124. +#ifndef __ASM_AR7_IRQ_H
  2125. +#define __ASM_AR7_IRQ_H
  2126. +
  2127. +#define NR_IRQS 256
  2128. +
  2129. +#include_next <irq.h>
  2130. +
  2131. +#endif /* __ASM_AR7_IRQ_H */
  2132. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/prom.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/prom.h
  2133. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/prom.h 1970-01-01 01:00:00.000000000 +0100
  2134. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/prom.h 2009-05-31 19:50:04.000000000 +0200
  2135. @@ -0,0 +1,26 @@
  2136. +/*
  2137. + * Copyright (C) 2006, 2007 Florian Fainelli <florian@openwrt.org>
  2138. + *
  2139. + * This program is free software; you can redistribute it and/or modify
  2140. + * it under the terms of the GNU General Public License as published by
  2141. + * the Free Software Foundation; either version 2 of the License, or
  2142. + * (at your option) any later version.
  2143. + *
  2144. + * This program is distributed in the hope that it will be useful,
  2145. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2146. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2147. + * GNU General Public License for more details.
  2148. + *
  2149. + * You should have received a copy of the GNU General Public License
  2150. + * along with this program; if not, write to the Free Software
  2151. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2152. + */
  2153. +
  2154. +#ifndef __PROM_H__
  2155. +#define __PROM_H__
  2156. +
  2157. +extern char *prom_getenv(const char *name);
  2158. +extern void prom_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
  2159. +extern void prom_meminit(void);
  2160. +
  2161. +#endif /* __PROM_H__ */
  2162. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/spaces.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/spaces.h
  2163. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/spaces.h 1970-01-01 01:00:00.000000000 +0100
  2164. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/spaces.h 2009-05-31 19:50:04.000000000 +0200
  2165. @@ -0,0 +1,32 @@
  2166. +/*
  2167. + * This file is subject to the terms and conditions of the GNU General Public
  2168. + * License. See the file "COPYING" in the main directory of this archive
  2169. + * for more details.
  2170. + *
  2171. + * Copyright (C) 1994 - 1999, 2000, 03, 04 Ralf Baechle
  2172. + * Copyright (C) 2000, 2002 Maciej W. Rozycki
  2173. + * Copyright (C) 1990, 1999, 2000 Silicon Graphics, Inc.
  2174. + */
  2175. +#ifndef _ASM_AR7_SPACES_H
  2176. +#define _ASM_AR7_SPACES_H
  2177. +
  2178. +#define CAC_BASE 0x80000000
  2179. +#define IO_BASE 0xa0000000
  2180. +#define UNCAC_BASE 0xa0000000
  2181. +#define MAP_BASE 0xc0000000
  2182. +
  2183. +/*
  2184. + * This handles the memory map.
  2185. + * We handle pages at KSEG0 for kernels with 32 bit address space.
  2186. + */
  2187. +#define PAGE_OFFSET 0x94000000UL
  2188. +#define PHYS_OFFSET 0x14000000UL
  2189. +
  2190. +/*
  2191. + * Memory above this physical address will be considered highmem.
  2192. + */
  2193. +#ifndef HIGHMEM_START
  2194. +#define HIGHMEM_START 0x40000000UL
  2195. +#endif
  2196. +
  2197. +#endif /* __ASM_AR7_SPACES_H */
  2198. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/war.h linux-2.6.29.1/arch/mips/include/asm/mach-ar7/war.h
  2199. --- linux-2.6.29.1.orig/arch/mips/include/asm/mach-ar7/war.h 1970-01-01 01:00:00.000000000 +0100
  2200. +++ linux-2.6.29.1/arch/mips/include/asm/mach-ar7/war.h 2009-05-31 19:50:04.000000000 +0200
  2201. @@ -0,0 +1,25 @@
  2202. +/*
  2203. + * This file is subject to the terms and conditions of the GNU General Public
  2204. + * License. See the file "COPYING" in the main directory of this archive
  2205. + * for more details.
  2206. + *
  2207. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  2208. + */
  2209. +#ifndef __ASM_MIPS_MACH_BCM947XX_WAR_H
  2210. +#define __ASM_MIPS_MACH_BCM947XX_WAR_H
  2211. +
  2212. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  2213. +#define R4600_V1_HIT_CACHEOP_WAR 0
  2214. +#define R4600_V2_HIT_CACHEOP_WAR 0
  2215. +#define R5432_CP0_INTERRUPT_WAR 0
  2216. +#define BCM1250_M3_WAR 0
  2217. +#define SIBYTE_1956_WAR 0
  2218. +#define MIPS4K_ICACHE_REFILL_WAR 0
  2219. +#define MIPS_CACHE_SYNC_WAR 0
  2220. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  2221. +#define RM9000_CDEX_SMP_WAR 0
  2222. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  2223. +#define R10000_LLSC_WAR 0
  2224. +#define MIPS34K_MISSED_ITLB_WAR 0
  2225. +
  2226. +#endif /* __ASM_MIPS_MACH_BCM947XX_WAR_H */
  2227. diff -Nur linux-2.6.29.1.orig/arch/mips/include/asm/page.h linux-2.6.29.1/arch/mips/include/asm/page.h
  2228. --- linux-2.6.29.1.orig/arch/mips/include/asm/page.h 2009-04-02 22:55:27.000000000 +0200
  2229. +++ linux-2.6.29.1/arch/mips/include/asm/page.h 2009-05-31 19:57:06.000000000 +0200
  2230. @@ -182,8 +182,11 @@
  2231. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  2232. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  2233. -#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
  2234. -#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
  2235. +#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
  2236. + PHYS_OFFSET)
  2237. +#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
  2238. + PHYS_OFFSET)
  2239. +
  2240. #include <asm-generic/memory_model.h>
  2241. #include <asm-generic/page.h>
  2242. diff -Nur linux-2.6.29.1.orig/arch/mips/Kconfig linux-2.6.29.1/arch/mips/Kconfig
  2243. --- linux-2.6.29.1.orig/arch/mips/Kconfig 2009-04-02 22:55:27.000000000 +0200
  2244. +++ linux-2.6.29.1/arch/mips/Kconfig 2009-05-31 19:55:40.000000000 +0200
  2245. @@ -19,6 +19,24 @@
  2246. prompt "System type"
  2247. default SGI_IP22
  2248. +config AR7
  2249. + bool "Texas Instruments AR7"
  2250. + select BOOT_ELF32
  2251. + select DMA_NONCOHERENT
  2252. + select CEVT_R4K
  2253. + select CSRC_R4K
  2254. + select IRQ_CPU
  2255. + select NO_EXCEPT_FILL
  2256. + select SWAP_IO_SPACE
  2257. + select SYS_HAS_CPU_MIPS32_R1
  2258. + select SYS_HAS_EARLY_PRINTK
  2259. + select SYS_SUPPORTS_32BIT_KERNEL
  2260. + select SYS_SUPPORTS_KGDB
  2261. + select SYS_SUPPORTS_LITTLE_ENDIAN
  2262. + select SYS_SUPPORTS_BIG_ENDIAN
  2263. + select GENERIC_GPIO
  2264. + select GENERIC_HARDIRQS_NO__DO_IRQ
  2265. +
  2266. config MACH_ALCHEMY
  2267. bool "Alchemy processor based machines"
  2268. diff -Nur linux-2.6.29.1.orig/arch/mips/kernel/traps.c linux-2.6.29.1/arch/mips/kernel/traps.c
  2269. --- linux-2.6.29.1.orig/arch/mips/kernel/traps.c 2009-04-02 22:55:27.000000000 +0200
  2270. +++ linux-2.6.29.1/arch/mips/kernel/traps.c 2009-05-31 23:46:49.000000000 +0200
  2271. @@ -1256,9 +1256,22 @@
  2272. exception_handlers[n] = handler;
  2273. if (n == 0 && cpu_has_divec) {
  2274. - *(u32 *)(ebase + 0x200) = 0x08000000 |
  2275. - (0x03ffffff & (handler >> 2));
  2276. - local_flush_icache_range(ebase + 0x200, ebase + 0x204);
  2277. + if ((handler ^ (ebase + 4)) & 0xfc000000) {
  2278. + /* lui k0, 0x0000 */
  2279. + *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
  2280. + /* ori k0, 0x0000 */
  2281. + *(u32 *)(ebase + 0x204) =
  2282. + 0x375a0000 | (handler & 0xffff);
  2283. + /* jr k0 */
  2284. + *(u32 *)(ebase + 0x208) = 0x03400008;
  2285. + /* nop */
  2286. + *(u32 *)(ebase + 0x20C) = 0x00000000;
  2287. + flush_icache_range(ebase + 0x200, ebase + 0x210);
  2288. + } else {
  2289. + *(u32 *)(ebase + 0x200) =
  2290. + 0x08000000 | (0x03ffffff & (handler >> 2));
  2291. + flush_icache_range(ebase + 0x200, ebase + 0x204);
  2292. + }
  2293. }
  2294. return (void *)old_handler;
  2295. }
  2296. diff -Nur linux-2.6.29.1.orig/arch/mips/Makefile linux-2.6.29.1/arch/mips/Makefile
  2297. --- linux-2.6.29.1.orig/arch/mips/Makefile 2009-04-02 22:55:27.000000000 +0200
  2298. +++ linux-2.6.29.1/arch/mips/Makefile 2009-05-31 20:01:45.000000000 +0200
  2299. @@ -173,6 +173,13 @@
  2300. #
  2301. #
  2302. +# Texas Instruments AR7
  2303. +#
  2304. +core-$(CONFIG_AR7) += arch/mips/ar7/
  2305. +cflags-$(CONFIG_AR7) += -I$(srctree)/arch/mips/include/asm/mach-ar7
  2306. +load-$(CONFIG_AR7) += 0xffffffff94100000
  2307. +
  2308. +#
  2309. # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
  2310. #
  2311. core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
  2312. diff -Nur linux-2.6.29.1.orig/drivers/char/ar7_gpio.c linux-2.6.29.1/drivers/char/ar7_gpio.c
  2313. --- linux-2.6.29.1.orig/drivers/char/ar7_gpio.c 1970-01-01 01:00:00.000000000 +0100
  2314. +++ linux-2.6.29.1/drivers/char/ar7_gpio.c 2009-05-31 19:53:09.000000000 +0200
  2315. @@ -0,0 +1,158 @@
  2316. +/*
  2317. + * Copyright (C) 2007 Nicolas Thill <nico@openwrt.org>
  2318. + *
  2319. + * This program is free software; you can redistribute it and/or modify
  2320. + * it under the terms of the GNU General Public License as published by
  2321. + * the Free Software Foundation; either version 2 of the License, or
  2322. + * (at your option) any later version.
  2323. + *
  2324. + * This program is distributed in the hope that it will be useful,
  2325. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2326. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2327. + * GNU General Public License for more details.
  2328. + *
  2329. + * You should have received a copy of the GNU General Public License
  2330. + * along with this program; if not, write to the Free Software
  2331. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2332. + */
  2333. +
  2334. +#include <linux/device.h>
  2335. +#include <linux/fs.h>
  2336. +#include <linux/module.h>
  2337. +#include <linux/errno.h>
  2338. +#include <linux/kernel.h>
  2339. +#include <linux/init.h>
  2340. +#include <linux/platform_device.h>
  2341. +#include <linux/uaccess.h>
  2342. +#include <linux/io.h>
  2343. +#include <linux/types.h>
  2344. +#include <linux/cdev.h>
  2345. +#include <gpio.h>
  2346. +
  2347. +#define DRVNAME "ar7_gpio"
  2348. +#define LONGNAME "TI AR7 GPIOs Driver"
  2349. +
  2350. +MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
  2351. +MODULE_DESCRIPTION(LONGNAME);
  2352. +MODULE_LICENSE("GPL");
  2353. +
  2354. +static int ar7_gpio_major;
  2355. +
  2356. +static ssize_t ar7_gpio_write(struct file *file, const char __user *buf,
  2357. + size_t len, loff_t *ppos)
  2358. +{
  2359. + int pin = iminor(file->f_dentry->d_inode);
  2360. + size_t i;
  2361. +
  2362. + for (i = 0; i < len; ++i) {
  2363. + char c;
  2364. + if (get_user(c, buf + i))
  2365. + return -EFAULT;
  2366. + switch (c) {
  2367. + case '0':
  2368. + gpio_set_value(pin, 0);
  2369. + break;
  2370. + case '1':
  2371. + gpio_set_value(pin, 1);
  2372. + break;
  2373. + case 'd':
  2374. + case 'D':
  2375. + ar7_gpio_disable(pin);
  2376. + break;
  2377. + case 'e':
  2378. + case 'E':
  2379. + ar7_gpio_enable(pin);
  2380. + break;
  2381. + case 'i':
  2382. + case 'I':
  2383. + case '<':
  2384. + gpio_direction_input(pin);
  2385. + break;
  2386. + case 'o':
  2387. + case 'O':
  2388. + case '>':
  2389. + gpio_direction_output(pin, 0);
  2390. + break;
  2391. + default:
  2392. + return -EINVAL;
  2393. + }
  2394. + }
  2395. +
  2396. + return len;
  2397. +}
  2398. +
  2399. +static ssize_t ar7_gpio_read(struct file *file, char __user *buf,
  2400. + size_t len, loff_t *ppos)
  2401. +{
  2402. + int pin = iminor(file->f_dentry->d_inode);
  2403. + int value;
  2404. +
  2405. + value = gpio_get_value(pin);
  2406. + if (put_user(value ? '1' : '0', buf))
  2407. + return -EFAULT;
  2408. +
  2409. + return 1;
  2410. +}
  2411. +
  2412. +static int ar7_gpio_open(struct inode *inode, struct file *file)
  2413. +{
  2414. + int m = iminor(inode);
  2415. +
  2416. + if (m >= AR7_GPIO_MAX)
  2417. + return -EINVAL;
  2418. +
  2419. + return nonseekable_open(inode, file);
  2420. +}
  2421. +
  2422. +static int ar7_gpio_release(struct inode *inode, struct file *file)
  2423. +{
  2424. + return 0;
  2425. +}
  2426. +
  2427. +static const struct file_operations ar7_gpio_fops = {
  2428. + .owner = THIS_MODULE,
  2429. + .write = ar7_gpio_write,
  2430. + .read = ar7_gpio_read,
  2431. + .open = ar7_gpio_open,
  2432. + .release = ar7_gpio_release,
  2433. + .llseek = no_llseek,
  2434. +};
  2435. +
  2436. +static struct platform_device *ar7_gpio_device;
  2437. +
  2438. +static int __init ar7_gpio_init(void)
  2439. +{
  2440. + int rc;
  2441. +
  2442. + ar7_gpio_device = platform_device_alloc(DRVNAME, -1);
  2443. + if (!ar7_gpio_device)
  2444. + return -ENOMEM;
  2445. +
  2446. + rc = platform_device_add(ar7_gpio_device);
  2447. + if (rc < 0)
  2448. + goto out_put;
  2449. +
  2450. + rc = register_chrdev(ar7_gpio_major, DRVNAME, &ar7_gpio_fops);
  2451. + if (rc < 0)
  2452. + goto out_put;
  2453. +
  2454. + ar7_gpio_major = rc;
  2455. +
  2456. + rc = 0;
  2457. +
  2458. + goto out;
  2459. +
  2460. +out_put:
  2461. + platform_device_put(ar7_gpio_device);
  2462. +out:
  2463. + return rc;
  2464. +}
  2465. +
  2466. +static void __exit ar7_gpio_exit(void)
  2467. +{
  2468. + unregister_chrdev(ar7_gpio_major, DRVNAME);
  2469. + platform_device_unregister(ar7_gpio_device);
  2470. +}
  2471. +
  2472. +module_init(ar7_gpio_init);
  2473. +module_exit(ar7_gpio_exit);
  2474. diff -Nur linux-2.6.29.1.orig/drivers/char/Kconfig linux-2.6.29.1/drivers/char/Kconfig
  2475. --- linux-2.6.29.1.orig/drivers/char/Kconfig 2009-04-02 22:55:27.000000000 +0200
  2476. +++ linux-2.6.29.1/drivers/char/Kconfig 2009-05-31 20:03:22.000000000 +0200
  2477. @@ -974,6 +974,15 @@
  2478. To compile this driver as a module, choose M here: the
  2479. module will be called mwave.
  2480. +config AR7_GPIO
  2481. + tristate "TI AR7 GPIO Support"
  2482. + depends on AR7
  2483. + help
  2484. + Give userspace access to the GPIO pins on the Texas Instruments AR7
  2485. + processors.
  2486. +
  2487. + If compiled as a module, it will be called ar7_gpio.
  2488. +
  2489. config SCx200_GPIO
  2490. tristate "NatSemi SCx200 GPIO Support"
  2491. depends on SCx200
  2492. diff -Nur linux-2.6.29.1.orig/drivers/char/Makefile linux-2.6.29.1/drivers/char/Makefile
  2493. --- linux-2.6.29.1.orig/drivers/char/Makefile 2009-04-02 22:55:27.000000000 +0200
  2494. +++ linux-2.6.29.1/drivers/char/Makefile 2009-05-31 20:03:22.000000000 +0200
  2495. @@ -90,6 +90,7 @@
  2496. obj-$(CONFIG_PPDEV) += ppdev.o
  2497. obj-$(CONFIG_NWBUTTON) += nwbutton.o
  2498. obj-$(CONFIG_NWFLASH) += nwflash.o
  2499. +obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
  2500. obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
  2501. obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
  2502. obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
  2503. diff -Nur linux-2.6.29.1.orig/drivers/Kconfig linux-2.6.29.1/drivers/Kconfig
  2504. --- linux-2.6.29.1.orig/drivers/Kconfig 2009-04-02 22:55:27.000000000 +0200
  2505. +++ linux-2.6.29.1/drivers/Kconfig 2009-05-31 20:03:35.000000000 +0200
  2506. @@ -104,6 +104,8 @@
  2507. source "drivers/uio/Kconfig"
  2508. +source "drivers/vlynq/Kconfig"
  2509. +
  2510. source "drivers/xen/Kconfig"
  2511. source "drivers/staging/Kconfig"
  2512. diff -Nur linux-2.6.29.1.orig/drivers/Makefile linux-2.6.29.1/drivers/Makefile
  2513. --- linux-2.6.29.1.orig/drivers/Makefile 2009-04-02 22:55:27.000000000 +0200
  2514. +++ linux-2.6.29.1/drivers/Makefile 2009-05-31 20:03:35.000000000 +0200
  2515. @@ -102,6 +102,7 @@
  2516. obj-$(CONFIG_HID) += hid/
  2517. obj-$(CONFIG_PPC_PS3) += ps3/
  2518. obj-$(CONFIG_OF) += of/
  2519. +obj-$(CONFIG_VLYNQ) += vlynq/
  2520. obj-$(CONFIG_SSB) += ssb/
  2521. obj-$(CONFIG_VIRTIO) += virtio/
  2522. obj-$(CONFIG_STAGING) += staging/
  2523. diff -Nur linux-2.6.29.1.orig/drivers/mtd/maps/physmap.c linux-2.6.29.1/drivers/mtd/maps/physmap.c
  2524. --- linux-2.6.29.1.orig/drivers/mtd/maps/physmap.c 2009-04-02 22:55:27.000000000 +0200
  2525. +++ linux-2.6.29.1/drivers/mtd/maps/physmap.c 2009-05-31 20:02:55.000000000 +0200
  2526. @@ -80,7 +80,7 @@
  2527. "map_rom",
  2528. NULL };
  2529. #ifdef CONFIG_MTD_PARTITIONS
  2530. -static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  2531. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "ar7part", NULL };
  2532. #endif
  2533. static int physmap_flash_probe(struct platform_device *dev)
  2534. diff -Nur linux-2.6.29.1.orig/drivers/net/cpmac.c linux-2.6.29.1/drivers/net/cpmac.c
  2535. --- linux-2.6.29.1.orig/drivers/net/cpmac.c 2009-04-02 22:55:27.000000000 +0200
  2536. +++ linux-2.6.29.1/drivers/net/cpmac.c 2009-06-01 15:23:14.000000000 +0200
  2537. @@ -615,13 +615,13 @@
  2538. dev_kfree_skb_irq(desc->skb);
  2539. desc->skb = NULL;
  2540. - if (netif_subqueue_stopped(dev, queue))
  2541. + if (__netif_subqueue_stopped(dev, queue))
  2542. netif_wake_subqueue(dev, queue);
  2543. } else {
  2544. if (netif_msg_tx_err(priv) && net_ratelimit())
  2545. printk(KERN_WARNING
  2546. "%s: end_xmit: spurious interrupt\n", dev->name);
  2547. - if (netif_subqueue_stopped(dev, queue))
  2548. + if (__netif_subqueue_stopped(dev, queue))
  2549. netif_wake_subqueue(dev, queue);
  2550. }
  2551. }
  2552. @@ -731,7 +731,6 @@
  2553. static void cpmac_hw_error(struct work_struct *work)
  2554. {
  2555. - int i;
  2556. struct cpmac_priv *priv =
  2557. container_of(work, struct cpmac_priv, reset_work);
  2558. @@ -818,7 +817,6 @@
  2559. static void cpmac_tx_timeout(struct net_device *dev)
  2560. {
  2561. - int i;
  2562. struct cpmac_priv *priv = netdev_priv(dev);
  2563. spin_lock(&priv->lock);
  2564. @@ -1093,12 +1091,10 @@
  2565. return 0;
  2566. }
  2567. -static int external_switch;
  2568. -
  2569. static int __devinit cpmac_probe(struct platform_device *pdev)
  2570. {
  2571. - int rc, phy_id, i;
  2572. - char *mdio_bus_id = "0";
  2573. + int rc, phy_id;
  2574. + char mdio_bus_id[BUS_ID_SIZE];
  2575. struct resource *mem;
  2576. struct cpmac_priv *priv;
  2577. struct net_device *dev;
  2578. @@ -1115,16 +1111,13 @@
  2579. }
  2580. if (phy_id == PHY_MAX_ADDR) {
  2581. - if (external_switch || dumb_switch) {
  2582. - mdio_bus_id = 0; /* fixed phys bus */
  2583. - phy_id = pdev->id;
  2584. - } else {
  2585. dev_err(&pdev->dev, "no PHY present\n");
  2586. return -ENODEV;
  2587. }
  2588. }
  2589. dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
  2590. + //~ dev = alloc_etherdev(sizeof(*priv));
  2591. if (!dev) {
  2592. printk(KERN_ERR "cpmac: Unable to allocate net_device\n");
  2593. @@ -1236,17 +1229,11 @@
  2594. cpmac_mii->reset(cpmac_mii);
  2595. - for (i = 0; i < 300000; i++)
  2596. + for (i = 0; i < 300; i++)
  2597. if ((mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE)))
  2598. break;
  2599. else
  2600. - cpu_relax();
  2601. -
  2602. - mask &= 0x7fffffff;
  2603. - if (mask & (mask - 1)) {
  2604. - external_switch = 1;
  2605. - mask = 0;
  2606. - }
  2607. + msleep(10);
  2608. cpmac_mii->phy_mask = ~(mask | 0x80000000);
  2609. snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "0");
  2610. diff -Nur linux-2.6.29.1.orig/drivers/net/cpmac.c.orig linux-2.6.29.1/drivers/net/cpmac.c.orig
  2611. --- linux-2.6.29.1.orig/drivers/net/cpmac.c.orig 1970-01-01 01:00:00.000000000 +0100
  2612. +++ linux-2.6.29.1/drivers/net/cpmac.c.orig 2009-06-01 14:37:40.000000000 +0200
  2613. @@ -0,0 +1,1285 @@
  2614. +/*
  2615. + * Copyright (C) 2006, 2007 Eugene Konev
  2616. + *
  2617. + * This program is free software; you can redistribute it and/or modify
  2618. + * it under the terms of the GNU General Public License as published by
  2619. + * the Free Software Foundation; either version 2 of the License, or
  2620. + * (at your option) any later version.
  2621. + *
  2622. + * This program is distributed in the hope that it will be useful,
  2623. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2624. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2625. + * GNU General Public License for more details.
  2626. + *
  2627. + * You should have received a copy of the GNU General Public License
  2628. + * along with this program; if not, write to the Free Software
  2629. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2630. + */
  2631. +
  2632. +#include <linux/module.h>
  2633. +#include <linux/init.h>
  2634. +#include <linux/moduleparam.h>
  2635. +
  2636. +#include <linux/sched.h>
  2637. +#include <linux/kernel.h>
  2638. +#include <linux/slab.h>
  2639. +#include <linux/errno.h>
  2640. +#include <linux/types.h>
  2641. +#include <linux/delay.h>
  2642. +
  2643. +#include <linux/netdevice.h>
  2644. +#include <linux/etherdevice.h>
  2645. +#include <linux/ethtool.h>
  2646. +#include <linux/skbuff.h>
  2647. +#include <linux/mii.h>
  2648. +#include <linux/phy.h>
  2649. +#include <linux/phy_fixed.h>
  2650. +#include <linux/platform_device.h>
  2651. +#include <linux/dma-mapping.h>
  2652. +#include <asm/gpio.h>
  2653. +#include <asm/atomic.h>
  2654. +
  2655. +MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
  2656. +MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
  2657. +MODULE_LICENSE("GPL");
  2658. +MODULE_ALIAS("platform:cpmac");
  2659. +
  2660. +static int debug_level = 8;
  2661. +static int dumb_switch;
  2662. +
  2663. +/* Next 2 are only used in cpmac_probe, so it's pointless to change them */
  2664. +module_param(debug_level, int, 0444);
  2665. +module_param(dumb_switch, int, 0444);
  2666. +
  2667. +MODULE_PARM_DESC(debug_level, "Number of NETIF_MSG bits to enable");
  2668. +MODULE_PARM_DESC(dumb_switch, "Assume switch is not connected to MDIO bus");
  2669. +
  2670. +#define CPMAC_VERSION "0.5.0"
  2671. +/* frame size + 802.1q tag */
  2672. +#define CPMAC_SKB_SIZE (ETH_FRAME_LEN + 4)
  2673. +#define CPMAC_QUEUES 8
  2674. +
  2675. +/* Ethernet registers */
  2676. +#define CPMAC_TX_CONTROL 0x0004
  2677. +#define CPMAC_TX_TEARDOWN 0x0008
  2678. +#define CPMAC_RX_CONTROL 0x0014
  2679. +#define CPMAC_RX_TEARDOWN 0x0018
  2680. +#define CPMAC_MBP 0x0100
  2681. +# define MBP_RXPASSCRC 0x40000000
  2682. +# define MBP_RXQOS 0x20000000
  2683. +# define MBP_RXNOCHAIN 0x10000000
  2684. +# define MBP_RXCMF 0x01000000
  2685. +# define MBP_RXSHORT 0x00800000
  2686. +# define MBP_RXCEF 0x00400000
  2687. +# define MBP_RXPROMISC 0x00200000
  2688. +# define MBP_PROMISCCHAN(channel) (((channel) & 0x7) << 16)
  2689. +# define MBP_RXBCAST 0x00002000
  2690. +# define MBP_BCASTCHAN(channel) (((channel) & 0x7) << 8)
  2691. +# define MBP_RXMCAST 0x00000020
  2692. +# define MBP_MCASTCHAN(channel) ((channel) & 0x7)
  2693. +#define CPMAC_UNICAST_ENABLE 0x0104
  2694. +#define CPMAC_UNICAST_CLEAR 0x0108
  2695. +#define CPMAC_MAX_LENGTH 0x010c
  2696. +#define CPMAC_BUFFER_OFFSET 0x0110
  2697. +#define CPMAC_MAC_CONTROL 0x0160
  2698. +# define MAC_TXPTYPE 0x00000200
  2699. +# define MAC_TXPACE 0x00000040
  2700. +# define MAC_MII 0x00000020
  2701. +# define MAC_TXFLOW 0x00000010
  2702. +# define MAC_RXFLOW 0x00000008
  2703. +# define MAC_MTEST 0x00000004
  2704. +# define MAC_LOOPBACK 0x00000002
  2705. +# define MAC_FDX 0x00000001
  2706. +#define CPMAC_MAC_STATUS 0x0164
  2707. +# define MAC_STATUS_QOS 0x00000004
  2708. +# define MAC_STATUS_RXFLOW 0x00000002
  2709. +# define MAC_STATUS_TXFLOW 0x00000001
  2710. +#define CPMAC_TX_INT_ENABLE 0x0178
  2711. +#define CPMAC_TX_INT_CLEAR 0x017c
  2712. +#define CPMAC_MAC_INT_VECTOR 0x0180
  2713. +# define MAC_INT_STATUS 0x00080000
  2714. +# define MAC_INT_HOST 0x00040000
  2715. +# define MAC_INT_RX 0x00020000
  2716. +# define MAC_INT_TX 0x00010000
  2717. +#define CPMAC_MAC_EOI_VECTOR 0x0184
  2718. +#define CPMAC_RX_INT_ENABLE 0x0198
  2719. +#define CPMAC_RX_INT_CLEAR 0x019c
  2720. +#define CPMAC_MAC_INT_ENABLE 0x01a8
  2721. +#define CPMAC_MAC_INT_CLEAR 0x01ac
  2722. +#define CPMAC_MAC_ADDR_LO(channel) (0x01b0 + (channel) * 4)
  2723. +#define CPMAC_MAC_ADDR_MID 0x01d0
  2724. +#define CPMAC_MAC_ADDR_HI 0x01d4
  2725. +#define CPMAC_MAC_HASH_LO 0x01d8
  2726. +#define CPMAC_MAC_HASH_HI 0x01dc
  2727. +#define CPMAC_TX_PTR(channel) (0x0600 + (channel) * 4)
  2728. +#define CPMAC_RX_PTR(channel) (0x0620 + (channel) * 4)
  2729. +#define CPMAC_TX_ACK(channel) (0x0640 + (channel) * 4)
  2730. +#define CPMAC_RX_ACK(channel) (0x0660 + (channel) * 4)
  2731. +#define CPMAC_REG_END 0x0680
  2732. +/*
  2733. + * Rx/Tx statistics
  2734. + * TODO: use some of them to fill stats in cpmac_stats()
  2735. + */
  2736. +#define CPMAC_STATS_RX_GOOD 0x0200
  2737. +#define CPMAC_STATS_RX_BCAST 0x0204
  2738. +#define CPMAC_STATS_RX_MCAST 0x0208
  2739. +#define CPMAC_STATS_RX_PAUSE 0x020c
  2740. +#define CPMAC_STATS_RX_CRC 0x0210
  2741. +#define CPMAC_STATS_RX_ALIGN 0x0214
  2742. +#define CPMAC_STATS_RX_OVER 0x0218
  2743. +#define CPMAC_STATS_RX_JABBER 0x021c
  2744. +#define CPMAC_STATS_RX_UNDER 0x0220
  2745. +#define CPMAC_STATS_RX_FRAG 0x0224
  2746. +#define CPMAC_STATS_RX_FILTER 0x0228
  2747. +#define CPMAC_STATS_RX_QOSFILTER 0x022c
  2748. +#define CPMAC_STATS_RX_OCTETS 0x0230
  2749. +
  2750. +#define CPMAC_STATS_TX_GOOD 0x0234
  2751. +#define CPMAC_STATS_TX_BCAST 0x0238
  2752. +#define CPMAC_STATS_TX_MCAST 0x023c
  2753. +#define CPMAC_STATS_TX_PAUSE 0x0240
  2754. +#define CPMAC_STATS_TX_DEFER 0x0244
  2755. +#define CPMAC_STATS_TX_COLLISION 0x0248
  2756. +#define CPMAC_STATS_TX_SINGLECOLL 0x024c
  2757. +#define CPMAC_STATS_TX_MULTICOLL 0x0250
  2758. +#define CPMAC_STATS_TX_EXCESSCOLL 0x0254
  2759. +#define CPMAC_STATS_TX_LATECOLL 0x0258
  2760. +#define CPMAC_STATS_TX_UNDERRUN 0x025c
  2761. +#define CPMAC_STATS_TX_CARRIERSENSE 0x0260
  2762. +#define CPMAC_STATS_TX_OCTETS 0x0264
  2763. +
  2764. +#define cpmac_read(base, reg) (readl((void __iomem *)(base) + (reg)))
  2765. +#define cpmac_write(base, reg, val) (writel(val, (void __iomem *)(base) + \
  2766. + (reg)))
  2767. +
  2768. +/* MDIO bus */
  2769. +#define CPMAC_MDIO_VERSION 0x0000
  2770. +#define CPMAC_MDIO_CONTROL 0x0004
  2771. +# define MDIOC_IDLE 0x80000000
  2772. +# define MDIOC_ENABLE 0x40000000
  2773. +# define MDIOC_PREAMBLE 0x00100000
  2774. +# define MDIOC_FAULT 0x00080000
  2775. +# define MDIOC_FAULTDETECT 0x00040000
  2776. +# define MDIOC_INTTEST 0x00020000
  2777. +# define MDIOC_CLKDIV(div) ((div) & 0xff)
  2778. +#define CPMAC_MDIO_ALIVE 0x0008
  2779. +#define CPMAC_MDIO_LINK 0x000c
  2780. +#define CPMAC_MDIO_ACCESS(channel) (0x0080 + (channel) * 8)
  2781. +# define MDIO_BUSY 0x80000000
  2782. +# define MDIO_WRITE 0x40000000
  2783. +# define MDIO_REG(reg) (((reg) & 0x1f) << 21)
  2784. +# define MDIO_PHY(phy) (((phy) & 0x1f) << 16)
  2785. +# define MDIO_DATA(data) ((data) & 0xffff)
  2786. +#define CPMAC_MDIO_PHYSEL(channel) (0x0084 + (channel) * 8)
  2787. +# define PHYSEL_LINKSEL 0x00000040
  2788. +# define PHYSEL_LINKINT 0x00000020
  2789. +
  2790. +struct cpmac_desc {
  2791. + u32 hw_next;
  2792. + u32 hw_data;
  2793. + u16 buflen;
  2794. + u16 bufflags;
  2795. + u16 datalen;
  2796. + u16 dataflags;
  2797. +#define CPMAC_SOP 0x8000
  2798. +#define CPMAC_EOP 0x4000
  2799. +#define CPMAC_OWN 0x2000
  2800. +#define CPMAC_EOQ 0x1000
  2801. + struct sk_buff *skb;
  2802. + struct cpmac_desc *next;
  2803. + struct cpmac_desc *prev;
  2804. + dma_addr_t mapping;
  2805. + dma_addr_t data_mapping;
  2806. +};
  2807. +
  2808. +struct cpmac_priv {
  2809. + spinlock_t lock;
  2810. + spinlock_t rx_lock;
  2811. + struct cpmac_desc *rx_head;
  2812. + int ring_size;
  2813. + struct cpmac_desc *desc_ring;
  2814. + dma_addr_t dma_ring;
  2815. + void __iomem *regs;
  2816. + struct mii_bus *mii_bus;
  2817. + struct phy_device *phy;
  2818. + char phy_name[BUS_ID_SIZE];
  2819. + int oldlink, oldspeed, oldduplex;
  2820. + u32 msg_enable;
  2821. + struct net_device *dev;
  2822. + struct work_struct reset_work;
  2823. + struct platform_device *pdev;
  2824. + struct napi_struct napi;
  2825. + atomic_t reset_pending;
  2826. +};
  2827. +
  2828. +static irqreturn_t cpmac_irq(int, void *);
  2829. +static void cpmac_hw_start(struct net_device *dev);
  2830. +static void cpmac_hw_stop(struct net_device *dev);
  2831. +static int cpmac_stop(struct net_device *dev);
  2832. +static int cpmac_open(struct net_device *dev);
  2833. +
  2834. +static void cpmac_dump_regs(struct net_device *dev)
  2835. +{
  2836. + int i;
  2837. + struct cpmac_priv *priv = netdev_priv(dev);
  2838. + for (i = 0; i < CPMAC_REG_END; i += 4) {
  2839. + if (i % 16 == 0) {
  2840. + if (i)
  2841. + printk("\n");
  2842. + printk(KERN_DEBUG "%s: reg[%p]:", dev->name,
  2843. + priv->regs + i);
  2844. + }
  2845. + printk(" %08x", cpmac_read(priv->regs, i));
  2846. + }
  2847. + printk("\n");
  2848. +}
  2849. +
  2850. +static void cpmac_dump_desc(struct net_device *dev, struct cpmac_desc *desc)
  2851. +{
  2852. + int i;
  2853. + printk(KERN_DEBUG "%s: desc[%p]:", dev->name, desc);
  2854. + for (i = 0; i < sizeof(*desc) / 4; i++)
  2855. + printk(" %08x", ((u32 *)desc)[i]);
  2856. + printk("\n");
  2857. +}
  2858. +
  2859. +static void cpmac_dump_all_desc(struct net_device *dev)
  2860. +{
  2861. + struct cpmac_priv *priv = netdev_priv(dev);
  2862. + struct cpmac_desc *dump = priv->rx_head;
  2863. + do {
  2864. + cpmac_dump_desc(dev, dump);
  2865. + dump = dump->next;
  2866. + } while (dump != priv->rx_head);
  2867. +}
  2868. +
  2869. +static void cpmac_dump_skb(struct net_device *dev, struct sk_buff *skb)
  2870. +{
  2871. + int i;
  2872. + printk(KERN_DEBUG "%s: skb 0x%p, len=%d\n", dev->name, skb, skb->len);
  2873. + for (i = 0; i < skb->len; i++) {
  2874. + if (i % 16 == 0) {
  2875. + if (i)
  2876. + printk("\n");
  2877. + printk(KERN_DEBUG "%s: data[%p]:", dev->name,
  2878. + skb->data + i);
  2879. + }
  2880. + printk(" %02x", ((u8 *)skb->data)[i]);
  2881. + }
  2882. + printk("\n");
  2883. +}
  2884. +
  2885. +static int cpmac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
  2886. +{
  2887. + u32 val;
  2888. +
  2889. + while (cpmac_read(bus->priv, CPMAC_MDIO_ACCESS(0)) & MDIO_BUSY)
  2890. + cpu_relax();
  2891. + cpmac_write(bus->priv, CPMAC_MDIO_ACCESS(0), MDIO_BUSY | MDIO_REG(reg) |
  2892. + MDIO_PHY(phy_id));
  2893. + while ((val = cpmac_read(bus->priv, CPMAC_MDIO_ACCESS(0))) & MDIO_BUSY)
  2894. + cpu_relax();
  2895. + return MDIO_DATA(val);
  2896. +}
  2897. +
  2898. +static int cpmac_mdio_write(struct mii_bus *bus, int phy_id,
  2899. + int reg, u16 val)
  2900. +{
  2901. + while (cpmac_read(bus->priv, CPMAC_MDIO_ACCESS(0)) & MDIO_BUSY)
  2902. + cpu_relax();
  2903. + cpmac_write(bus->priv, CPMAC_MDIO_ACCESS(0), MDIO_BUSY | MDIO_WRITE |
  2904. + MDIO_REG(reg) | MDIO_PHY(phy_id) | MDIO_DATA(val));
  2905. + return 0;
  2906. +}
  2907. +
  2908. +static int cpmac_mdio_reset(struct mii_bus *bus)
  2909. +{
  2910. + ar7_device_reset(AR7_RESET_BIT_MDIO);
  2911. + cpmac_write(bus->priv, CPMAC_MDIO_CONTROL, MDIOC_ENABLE |
  2912. + MDIOC_CLKDIV(ar7_cpmac_freq() / 2200000 - 1));
  2913. + return 0;
  2914. +}
  2915. +
  2916. +static int mii_irqs[PHY_MAX_ADDR] = { PHY_POLL, };
  2917. +
  2918. +static struct mii_bus *cpmac_mii;
  2919. +
  2920. +static int cpmac_config(struct net_device *dev, struct ifmap *map)
  2921. +{
  2922. + if (dev->flags & IFF_UP)
  2923. + return -EBUSY;
  2924. +
  2925. + /* Don't allow changing the I/O address */
  2926. + if (map->base_addr != dev->base_addr)
  2927. + return -EOPNOTSUPP;
  2928. +
  2929. + /* ignore other fields */
  2930. + return 0;
  2931. +}
  2932. +
  2933. +static void cpmac_set_multicast_list(struct net_device *dev)
  2934. +{
  2935. + struct dev_mc_list *iter;
  2936. + int i;
  2937. + u8 tmp;
  2938. + u32 mbp, bit, hash[2] = { 0, };
  2939. + struct cpmac_priv *priv = netdev_priv(dev);
  2940. +
  2941. + mbp = cpmac_read(priv->regs, CPMAC_MBP);
  2942. + if (dev->flags & IFF_PROMISC) {
  2943. + cpmac_write(priv->regs, CPMAC_MBP, (mbp & ~MBP_PROMISCCHAN(0)) |
  2944. + MBP_RXPROMISC);
  2945. + } else {
  2946. + cpmac_write(priv->regs, CPMAC_MBP, mbp & ~MBP_RXPROMISC);
  2947. + if (dev->flags & IFF_ALLMULTI) {
  2948. + /* enable all multicast mode */
  2949. + cpmac_write(priv->regs, CPMAC_MAC_HASH_LO, 0xffffffff);
  2950. + cpmac_write(priv->regs, CPMAC_MAC_HASH_HI, 0xffffffff);
  2951. + } else {
  2952. + /*
  2953. + * cpmac uses some strange mac address hashing
  2954. + * (not crc32)
  2955. + */
  2956. + for (i = 0, iter = dev->mc_list; i < dev->mc_count;
  2957. + i++, iter = iter->next) {
  2958. + bit = 0;
  2959. + tmp = iter->dmi_addr[0];
  2960. + bit ^= (tmp >> 2) ^ (tmp << 4);
  2961. + tmp = iter->dmi_addr[1];
  2962. + bit ^= (tmp >> 4) ^ (tmp << 2);
  2963. + tmp = iter->dmi_addr[2];
  2964. + bit ^= (tmp >> 6) ^ tmp;
  2965. + tmp = iter->dmi_addr[3];
  2966. + bit ^= (tmp >> 2) ^ (tmp << 4);
  2967. + tmp = iter->dmi_addr[4];
  2968. + bit ^= (tmp >> 4) ^ (tmp << 2);
  2969. + tmp = iter->dmi_addr[5];
  2970. + bit ^= (tmp >> 6) ^ tmp;
  2971. + bit &= 0x3f;
  2972. + hash[bit / 32] |= 1 << (bit % 32);
  2973. + }
  2974. +
  2975. + cpmac_write(priv->regs, CPMAC_MAC_HASH_LO, hash[0]);
  2976. + cpmac_write(priv->regs, CPMAC_MAC_HASH_HI, hash[1]);
  2977. + }
  2978. + }
  2979. +}
  2980. +
  2981. +static struct sk_buff *cpmac_rx_one(struct cpmac_priv *priv,
  2982. + struct cpmac_desc *desc)
  2983. +{
  2984. + struct sk_buff *skb, *result = NULL;
  2985. +
  2986. + if (unlikely(netif_msg_hw(priv)))
  2987. + cpmac_dump_desc(priv->dev, desc);
  2988. + cpmac_write(priv->regs, CPMAC_RX_ACK(0), (u32)desc->mapping);
  2989. + if (unlikely(!desc->datalen)) {
  2990. + if (netif_msg_rx_err(priv) && net_ratelimit())
  2991. + printk(KERN_WARNING "%s: rx: spurious interrupt\n",
  2992. + priv->dev->name);
  2993. + return NULL;
  2994. + }
  2995. +
  2996. + skb = netdev_alloc_skb(priv->dev, CPMAC_SKB_SIZE);
  2997. + if (likely(skb)) {
  2998. + skb_reserve(skb, 2);
  2999. + skb_put(desc->skb, desc->datalen);
  3000. + desc->skb->protocol = eth_type_trans(desc->skb, priv->dev);
  3001. + desc->skb->ip_summed = CHECKSUM_NONE;
  3002. + priv->dev->stats.rx_packets++;
  3003. + priv->dev->stats.rx_bytes += desc->datalen;
  3004. + result = desc->skb;
  3005. + dma_unmap_single(&priv->dev->dev, desc->data_mapping,
  3006. + CPMAC_SKB_SIZE, DMA_FROM_DEVICE);
  3007. + desc->skb = skb;
  3008. + desc->data_mapping = dma_map_single(&priv->dev->dev, skb->data,
  3009. + CPMAC_SKB_SIZE,
  3010. + DMA_FROM_DEVICE);
  3011. + desc->hw_data = (u32)desc->data_mapping;
  3012. + if (unlikely(netif_msg_pktdata(priv))) {
  3013. + printk(KERN_DEBUG "%s: received packet:\n",
  3014. + priv->dev->name);
  3015. + cpmac_dump_skb(priv->dev, result);
  3016. + }
  3017. + } else {
  3018. + if (netif_msg_rx_err(priv) && net_ratelimit())
  3019. + printk(KERN_WARNING
  3020. + "%s: low on skbs, dropping packet\n",
  3021. + priv->dev->name);
  3022. + priv->dev->stats.rx_dropped++;
  3023. + }
  3024. +
  3025. + desc->buflen = CPMAC_SKB_SIZE;
  3026. + desc->dataflags = CPMAC_OWN;
  3027. +
  3028. + return result;
  3029. +}
  3030. +
  3031. +static int cpmac_poll(struct napi_struct *napi, int budget)
  3032. +{
  3033. + struct sk_buff *skb;
  3034. + struct cpmac_desc *desc, *restart;
  3035. + struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
  3036. + int received = 0, processed = 0;
  3037. +
  3038. + spin_lock(&priv->rx_lock);
  3039. + if (unlikely(!priv->rx_head)) {
  3040. + if (netif_msg_rx_err(priv) && net_ratelimit())
  3041. + printk(KERN_WARNING "%s: rx: polling, but no queue\n",
  3042. + priv->dev->name);
  3043. + spin_unlock(&priv->rx_lock);
  3044. + netif_rx_complete(napi);
  3045. + return 0;
  3046. + }
  3047. +
  3048. + desc = priv->rx_head;
  3049. + restart = NULL;
  3050. + while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
  3051. + processed++;
  3052. +
  3053. + if ((desc->dataflags & CPMAC_EOQ) != 0) {
  3054. + /* The last update to eoq->hw_next didn't happen
  3055. + * soon enough, and the receiver stopped here.
  3056. + *Remember this descriptor so we can restart
  3057. + * the receiver after freeing some space.
  3058. + */
  3059. + if (unlikely(restart)) {
  3060. + if (netif_msg_rx_err(priv))
  3061. + printk(KERN_ERR "%s: poll found a"
  3062. + " duplicate EOQ: %p and %p\n",
  3063. + priv->dev->name, restart, desc);
  3064. + goto fatal_error;
  3065. + }
  3066. +
  3067. + restart = desc->next;
  3068. + }
  3069. +
  3070. + skb = cpmac_rx_one(priv, desc);
  3071. + if (likely(skb)) {
  3072. + netif_receive_skb(skb);
  3073. + received++;
  3074. + }
  3075. + desc = desc->next;
  3076. + }
  3077. +
  3078. + if (desc != priv->rx_head) {
  3079. + /* We freed some buffers, but not the whole ring,
  3080. + * add what we did free to the rx list */
  3081. + desc->prev->hw_next = (u32)0;
  3082. + priv->rx_head->prev->hw_next = priv->rx_head->mapping;
  3083. + }
  3084. +
  3085. + /* Optimization: If we did not actually process an EOQ (perhaps because
  3086. + * of quota limits), check to see if the tail of the queue has EOQ set.
  3087. + * We should immediately restart in that case so that the receiver can
  3088. + * restart and run in parallel with more packet processing.
  3089. + * This lets us handle slightly larger bursts before running
  3090. + * out of ring space (assuming dev->weight < ring_size) */
  3091. +
  3092. + if (!restart &&
  3093. + (priv->rx_head->prev->dataflags & (CPMAC_OWN|CPMAC_EOQ))
  3094. + == CPMAC_EOQ &&
  3095. + (priv->rx_head->dataflags & CPMAC_OWN) != 0) {
  3096. + /* reset EOQ so the poll loop (above) doesn't try to
  3097. + * restart this when it eventually gets to this descriptor.
  3098. + */
  3099. + priv->rx_head->prev->dataflags &= ~CPMAC_EOQ;
  3100. + restart = priv->rx_head;
  3101. + }
  3102. +
  3103. + if (restart) {
  3104. + priv->dev->stats.rx_errors++;
  3105. + priv->dev->stats.rx_fifo_errors++;
  3106. + if (netif_msg_rx_err(priv) && net_ratelimit())
  3107. + printk(KERN_WARNING "%s: rx dma ring overrun\n",
  3108. + priv->dev->name);
  3109. +
  3110. + if (unlikely((restart->dataflags & CPMAC_OWN) == 0)) {
  3111. + if (netif_msg_drv(priv))
  3112. + printk(KERN_ERR "%s: cpmac_poll is trying to "
  3113. + "restart rx from a descriptor that's "
  3114. + "not free: %p\n",
  3115. + priv->dev->name, restart);
  3116. + goto fatal_error;
  3117. + }
  3118. +
  3119. + cpmac_write(priv->regs, CPMAC_RX_PTR(0), restart->mapping);
  3120. + }
  3121. +
  3122. + priv->rx_head = desc;
  3123. + spin_unlock(&priv->rx_lock);
  3124. + if (unlikely(netif_msg_rx_status(priv)))
  3125. + printk(KERN_DEBUG "%s: poll processed %d packets\n",
  3126. + priv->dev->name, received);
  3127. + if (processed == 0) {
  3128. + /* we ran out of packets to read,
  3129. + * revert to interrupt-driven mode */
  3130. + netif_rx_complete(napi);
  3131. + cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
  3132. + return 0;
  3133. + }
  3134. +
  3135. + return 1;
  3136. +
  3137. +fatal_error:
  3138. + /* Something went horribly wrong.
  3139. + * Reset hardware to try to recover rather than wedging. */
  3140. +
  3141. + if (netif_msg_drv(priv)) {
  3142. + printk(KERN_ERR "%s: cpmac_poll is confused. "
  3143. + "Resetting hardware\n", priv->dev->name);
  3144. + cpmac_dump_all_desc(priv->dev);
  3145. + printk(KERN_DEBUG "%s: RX_PTR(0)=0x%08x RX_ACK(0)=0x%08x\n",
  3146. + priv->dev->name,
  3147. + cpmac_read(priv->regs, CPMAC_RX_PTR(0)),
  3148. + cpmac_read(priv->regs, CPMAC_RX_ACK(0)));
  3149. + }
  3150. +
  3151. + spin_unlock(&priv->rx_lock);
  3152. + netif_rx_complete(napi);
  3153. + netif_tx_stop_all_queues(priv->dev);
  3154. + napi_disable(&priv->napi);
  3155. +
  3156. + atomic_inc(&priv->reset_pending);
  3157. + cpmac_hw_stop(priv->dev);
  3158. + if (!schedule_work(&priv->reset_work))
  3159. + atomic_dec(&priv->reset_pending);
  3160. + return 0;
  3161. +
  3162. +}
  3163. +
  3164. +static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3165. +{
  3166. + int queue, len;
  3167. + struct cpmac_desc *desc;
  3168. + struct cpmac_priv *priv = netdev_priv(dev);
  3169. +
  3170. + if (unlikely(atomic_read(&priv->reset_pending)))
  3171. + return NETDEV_TX_BUSY;
  3172. +
  3173. + if (unlikely(skb_padto(skb, ETH_ZLEN)))
  3174. + return NETDEV_TX_OK;
  3175. +
  3176. + len = max(skb->len, ETH_ZLEN);
  3177. + queue = skb_get_queue_mapping(skb);
  3178. + netif_stop_subqueue(dev, queue);
  3179. +
  3180. + desc = &priv->desc_ring[queue];
  3181. + if (unlikely(desc->dataflags & CPMAC_OWN)) {
  3182. + if (netif_msg_tx_err(priv) && net_ratelimit())
  3183. + printk(KERN_WARNING "%s: tx dma ring full\n",
  3184. + dev->name);
  3185. + return NETDEV_TX_BUSY;
  3186. + }
  3187. +
  3188. + spin_lock(&priv->lock);
  3189. + dev->trans_start = jiffies;
  3190. + spin_unlock(&priv->lock);
  3191. + desc->dataflags = CPMAC_SOP | CPMAC_EOP | CPMAC_OWN;
  3192. + desc->skb = skb;
  3193. + desc->data_mapping = dma_map_single(&dev->dev, skb->data, len,
  3194. + DMA_TO_DEVICE);
  3195. + desc->hw_data = (u32)desc->data_mapping;
  3196. + desc->datalen = len;
  3197. + desc->buflen = len;
  3198. + if (unlikely(netif_msg_tx_queued(priv)))
  3199. + printk(KERN_DEBUG "%s: sending 0x%p, len=%d\n", dev->name, skb,
  3200. + skb->len);
  3201. + if (unlikely(netif_msg_hw(priv)))
  3202. + cpmac_dump_desc(dev, desc);
  3203. + if (unlikely(netif_msg_pktdata(priv)))
  3204. + cpmac_dump_skb(dev, skb);
  3205. + cpmac_write(priv->regs, CPMAC_TX_PTR(queue), (u32)desc->mapping);
  3206. +
  3207. + return NETDEV_TX_OK;
  3208. +}
  3209. +
  3210. +static void cpmac_end_xmit(struct net_device *dev, int queue)
  3211. +{
  3212. + struct cpmac_desc *desc;
  3213. + struct cpmac_priv *priv = netdev_priv(dev);
  3214. +
  3215. + desc = &priv->desc_ring[queue];
  3216. + cpmac_write(priv->regs, CPMAC_TX_ACK(queue), (u32)desc->mapping);
  3217. + if (likely(desc->skb)) {
  3218. + spin_lock(&priv->lock);
  3219. + dev->stats.tx_packets++;
  3220. + dev->stats.tx_bytes += desc->skb->len;
  3221. + spin_unlock(&priv->lock);
  3222. + dma_unmap_single(&dev->dev, desc->data_mapping, desc->skb->len,
  3223. + DMA_TO_DEVICE);
  3224. +
  3225. + if (unlikely(netif_msg_tx_done(priv)))
  3226. + printk(KERN_DEBUG "%s: sent 0x%p, len=%d\n", dev->name,
  3227. + desc->skb, desc->skb->len);
  3228. +
  3229. + dev_kfree_skb_irq(desc->skb);
  3230. + desc->skb = NULL;
  3231. + if (netif_subqueue_stopped(dev, queue))
  3232. + netif_wake_subqueue(dev, queue);
  3233. + } else {
  3234. + if (netif_msg_tx_err(priv) && net_ratelimit())
  3235. + printk(KERN_WARNING
  3236. + "%s: end_xmit: spurious interrupt\n", dev->name);
  3237. + if (netif_subqueue_stopped(dev, queue))
  3238. + netif_wake_subqueue(dev, queue);
  3239. + }
  3240. +}
  3241. +
  3242. +static void cpmac_hw_stop(struct net_device *dev)
  3243. +{
  3244. + int i;
  3245. + struct cpmac_priv *priv = netdev_priv(dev);
  3246. + struct plat_cpmac_data *pdata = priv->pdev->dev.platform_data;
  3247. +
  3248. + ar7_device_reset(pdata->reset_bit);
  3249. + cpmac_write(priv->regs, CPMAC_RX_CONTROL,
  3250. + cpmac_read(priv->regs, CPMAC_RX_CONTROL) & ~1);
  3251. + cpmac_write(priv->regs, CPMAC_TX_CONTROL,
  3252. + cpmac_read(priv->regs, CPMAC_TX_CONTROL) & ~1);
  3253. + for (i = 0; i < 8; i++) {
  3254. + cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0);
  3255. + cpmac_write(priv->regs, CPMAC_RX_PTR(i), 0);
  3256. + }
  3257. + cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff);
  3258. + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff);
  3259. + cpmac_write(priv->regs, CPMAC_TX_INT_CLEAR, 0xff);
  3260. + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
  3261. + cpmac_write(priv->regs, CPMAC_MAC_CONTROL,
  3262. + cpmac_read(priv->regs, CPMAC_MAC_CONTROL) & ~MAC_MII);
  3263. +}
  3264. +
  3265. +static void cpmac_hw_start(struct net_device *dev)
  3266. +{
  3267. + int i;
  3268. + struct cpmac_priv *priv = netdev_priv(dev);
  3269. + struct plat_cpmac_data *pdata = priv->pdev->dev.platform_data;
  3270. +
  3271. + ar7_device_reset(pdata->reset_bit);
  3272. + for (i = 0; i < 8; i++) {
  3273. + cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0);
  3274. + cpmac_write(priv->regs, CPMAC_RX_PTR(i), 0);
  3275. + }
  3276. + cpmac_write(priv->regs, CPMAC_RX_PTR(0), priv->rx_head->mapping);
  3277. +
  3278. + cpmac_write(priv->regs, CPMAC_MBP, MBP_RXSHORT | MBP_RXBCAST |
  3279. + MBP_RXMCAST);
  3280. + cpmac_write(priv->regs, CPMAC_BUFFER_OFFSET, 0);
  3281. + for (i = 0; i < 8; i++)
  3282. + cpmac_write(priv->regs, CPMAC_MAC_ADDR_LO(i), dev->dev_addr[5]);
  3283. + cpmac_write(priv->regs, CPMAC_MAC_ADDR_MID, dev->dev_addr[4]);
  3284. + cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, dev->dev_addr[0] |
  3285. + (dev->dev_addr[1] << 8) | (dev->dev_addr[2] << 16) |
  3286. + (dev->dev_addr[3] << 24));
  3287. + cpmac_write(priv->regs, CPMAC_MAX_LENGTH, CPMAC_SKB_SIZE);
  3288. + cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff);
  3289. + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff);
  3290. + cpmac_write(priv->regs, CPMAC_TX_INT_CLEAR, 0xff);
  3291. + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
  3292. + cpmac_write(priv->regs, CPMAC_UNICAST_ENABLE, 1);
  3293. + cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
  3294. + cpmac_write(priv->regs, CPMAC_TX_INT_ENABLE, 0xff);
  3295. + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
  3296. +
  3297. + cpmac_write(priv->regs, CPMAC_RX_CONTROL,
  3298. + cpmac_read(priv->regs, CPMAC_RX_CONTROL) | 1);
  3299. + cpmac_write(priv->regs, CPMAC_TX_CONTROL,
  3300. + cpmac_read(priv->regs, CPMAC_TX_CONTROL) | 1);
  3301. + cpmac_write(priv->regs, CPMAC_MAC_CONTROL,
  3302. + cpmac_read(priv->regs, CPMAC_MAC_CONTROL) | MAC_MII |
  3303. + MAC_FDX);
  3304. +}
  3305. +
  3306. +static void cpmac_clear_rx(struct net_device *dev)
  3307. +{
  3308. + struct cpmac_priv *priv = netdev_priv(dev);
  3309. + struct cpmac_desc *desc;
  3310. + int i;
  3311. + if (unlikely(!priv->rx_head))
  3312. + return;
  3313. + desc = priv->rx_head;
  3314. + for (i = 0; i < priv->ring_size; i++) {
  3315. + if ((desc->dataflags & CPMAC_OWN) == 0) {
  3316. + if (netif_msg_rx_err(priv) && net_ratelimit())
  3317. + printk(KERN_WARNING "%s: packet dropped\n",
  3318. + dev->name);
  3319. + if (unlikely(netif_msg_hw(priv)))
  3320. + cpmac_dump_desc(dev, desc);
  3321. + desc->dataflags = CPMAC_OWN;
  3322. + dev->stats.rx_dropped++;
  3323. + }
  3324. + desc->hw_next = desc->next->mapping;
  3325. + desc = desc->next;
  3326. + }
  3327. + priv->rx_head->prev->hw_next = 0;
  3328. +}
  3329. +
  3330. +static void cpmac_clear_tx(struct net_device *dev)
  3331. +{
  3332. + struct cpmac_priv *priv = netdev_priv(dev);
  3333. + int i;
  3334. + if (unlikely(!priv->desc_ring))
  3335. + return;
  3336. + for (i = 0; i < CPMAC_QUEUES; i++) {
  3337. + priv->desc_ring[i].dataflags = 0;
  3338. + if (priv->desc_ring[i].skb) {
  3339. + dev_kfree_skb_any(priv->desc_ring[i].skb);
  3340. + priv->desc_ring[i].skb = NULL;
  3341. + }
  3342. + }
  3343. +}
  3344. +
  3345. +static void cpmac_hw_error(struct work_struct *work)
  3346. +{
  3347. + int i;
  3348. + struct cpmac_priv *priv =
  3349. + container_of(work, struct cpmac_priv, reset_work);
  3350. +
  3351. + spin_lock(&priv->rx_lock);
  3352. + cpmac_clear_rx(priv->dev);
  3353. + spin_unlock(&priv->rx_lock);
  3354. + cpmac_clear_tx(priv->dev);
  3355. + cpmac_hw_start(priv->dev);
  3356. + barrier();
  3357. + atomic_dec(&priv->reset_pending);
  3358. +
  3359. + netif_tx_wake_all_queues(priv->dev);
  3360. + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
  3361. +}
  3362. +
  3363. +static void cpmac_check_status(struct net_device *dev)
  3364. +{
  3365. + struct cpmac_priv *priv = netdev_priv(dev);
  3366. +
  3367. + u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
  3368. + int rx_channel = (macstatus >> 8) & 7;
  3369. + int rx_code = (macstatus >> 12) & 15;
  3370. + int tx_channel = (macstatus >> 16) & 7;
  3371. + int tx_code = (macstatus >> 20) & 15;
  3372. +
  3373. + if (rx_code || tx_code) {
  3374. + if (netif_msg_drv(priv) && net_ratelimit()) {
  3375. + /* Can't find any documentation on what these
  3376. + *error codes actually are. So just log them and hope..
  3377. + */
  3378. + if (rx_code)
  3379. + printk(KERN_WARNING "%s: host error %d on rx "
  3380. + "channel %d (macstatus %08x), resetting\n",
  3381. + dev->name, rx_code, rx_channel, macstatus);
  3382. + if (tx_code)
  3383. + printk(KERN_WARNING "%s: host error %d on tx "
  3384. + "channel %d (macstatus %08x), resetting\n",
  3385. + dev->name, tx_code, tx_channel, macstatus);
  3386. + }
  3387. +
  3388. + netif_tx_stop_all_queues(dev);
  3389. + cpmac_hw_stop(dev);
  3390. + if (schedule_work(&priv->reset_work))
  3391. + atomic_inc(&priv->reset_pending);
  3392. + if (unlikely(netif_msg_hw(priv)))
  3393. + cpmac_dump_regs(dev);
  3394. + }
  3395. + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
  3396. +}
  3397. +
  3398. +static irqreturn_t cpmac_irq(int irq, void *dev_id)
  3399. +{
  3400. + struct net_device *dev = dev_id;
  3401. + struct cpmac_priv *priv;
  3402. + int queue;
  3403. + u32 status;
  3404. +
  3405. + priv = netdev_priv(dev);
  3406. +
  3407. + status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
  3408. +
  3409. + if (unlikely(netif_msg_intr(priv)))
  3410. + printk(KERN_DEBUG "%s: interrupt status: 0x%08x\n", dev->name,
  3411. + status);
  3412. +
  3413. + if (status & MAC_INT_TX)
  3414. + cpmac_end_xmit(dev, (status & 7));
  3415. +
  3416. + if (status & MAC_INT_RX) {
  3417. + queue = (status >> 8) & 7;
  3418. + if (netif_rx_schedule_prep(&priv->napi)) {
  3419. + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue);
  3420. + __netif_rx_schedule(&priv->napi);
  3421. + }
  3422. + }
  3423. +
  3424. + cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
  3425. +
  3426. + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
  3427. + cpmac_check_status(dev);
  3428. +
  3429. + return IRQ_HANDLED;
  3430. +}
  3431. +
  3432. +static void cpmac_tx_timeout(struct net_device *dev)
  3433. +{
  3434. + int i;
  3435. + struct cpmac_priv *priv = netdev_priv(dev);
  3436. +
  3437. + spin_lock(&priv->lock);
  3438. + dev->stats.tx_errors++;
  3439. + spin_unlock(&priv->lock);
  3440. + if (netif_msg_tx_err(priv) && net_ratelimit())
  3441. + printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
  3442. +
  3443. + atomic_inc(&priv->reset_pending);
  3444. + barrier();
  3445. + cpmac_clear_tx(dev);
  3446. + barrier();
  3447. + atomic_dec(&priv->reset_pending);
  3448. +
  3449. + netif_tx_wake_all_queues(priv->dev);
  3450. +}
  3451. +
  3452. +static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  3453. +{
  3454. + struct cpmac_priv *priv = netdev_priv(dev);
  3455. + if (!(netif_running(dev)))
  3456. + return -EINVAL;
  3457. + if (!priv->phy)
  3458. + return -EINVAL;
  3459. + if ((cmd == SIOCGMIIPHY) || (cmd == SIOCGMIIREG) ||
  3460. + (cmd == SIOCSMIIREG))
  3461. + return phy_mii_ioctl(priv->phy, if_mii(ifr), cmd);
  3462. +
  3463. + return -EOPNOTSUPP;
  3464. +}
  3465. +
  3466. +static int cpmac_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3467. +{
  3468. + struct cpmac_priv *priv = netdev_priv(dev);
  3469. +
  3470. + if (priv->phy)
  3471. + return phy_ethtool_gset(priv->phy, cmd);
  3472. +
  3473. + return -EINVAL;
  3474. +}
  3475. +
  3476. +static int cpmac_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3477. +{
  3478. + struct cpmac_priv *priv = netdev_priv(dev);
  3479. +
  3480. + if (!capable(CAP_NET_ADMIN))
  3481. + return -EPERM;
  3482. +
  3483. + if (priv->phy)
  3484. + return phy_ethtool_sset(priv->phy, cmd);
  3485. +
  3486. + return -EINVAL;
  3487. +}
  3488. +
  3489. +static void cpmac_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
  3490. +{
  3491. + struct cpmac_priv *priv = netdev_priv(dev);
  3492. +
  3493. + ring->rx_max_pending = 1024;
  3494. + ring->rx_mini_max_pending = 1;
  3495. + ring->rx_jumbo_max_pending = 1;
  3496. + ring->tx_max_pending = 1;
  3497. +
  3498. + ring->rx_pending = priv->ring_size;
  3499. + ring->rx_mini_pending = 1;
  3500. + ring->rx_jumbo_pending = 1;
  3501. + ring->tx_pending = 1;
  3502. +}
  3503. +
  3504. +static int cpmac_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
  3505. +{
  3506. + struct cpmac_priv *priv = netdev_priv(dev);
  3507. +
  3508. + if (netif_running(dev))
  3509. + return -EBUSY;
  3510. + priv->ring_size = ring->rx_pending;
  3511. + return 0;
  3512. +}
  3513. +
  3514. +static void cpmac_get_drvinfo(struct net_device *dev,
  3515. + struct ethtool_drvinfo *info)
  3516. +{
  3517. + strcpy(info->driver, "cpmac");
  3518. + strcpy(info->version, CPMAC_VERSION);
  3519. + info->fw_version[0] = '\0';
  3520. + sprintf(info->bus_info, "%s", "cpmac");
  3521. + info->regdump_len = 0;
  3522. +}
  3523. +
  3524. +static const struct ethtool_ops cpmac_ethtool_ops = {
  3525. + .get_settings = cpmac_get_settings,
  3526. + .set_settings = cpmac_set_settings,
  3527. + .get_drvinfo = cpmac_get_drvinfo,
  3528. + .get_link = ethtool_op_get_link,
  3529. + .get_ringparam = cpmac_get_ringparam,
  3530. + .set_ringparam = cpmac_set_ringparam,
  3531. +};
  3532. +
  3533. +static void cpmac_adjust_link(struct net_device *dev)
  3534. +{
  3535. + struct cpmac_priv *priv = netdev_priv(dev);
  3536. + int new_state = 0;
  3537. +
  3538. + spin_lock(&priv->lock);
  3539. + if (priv->phy->link) {
  3540. + netif_tx_start_all_queues(dev);
  3541. + if (priv->phy->duplex != priv->oldduplex) {
  3542. + new_state = 1;
  3543. + priv->oldduplex = priv->phy->duplex;
  3544. + }
  3545. +
  3546. + if (priv->phy->speed != priv->oldspeed) {
  3547. + new_state = 1;
  3548. + priv->oldspeed = priv->phy->speed;
  3549. + }
  3550. +
  3551. + if (!priv->oldlink) {
  3552. + new_state = 1;
  3553. + priv->oldlink = 1;
  3554. + }
  3555. + } else if (priv->oldlink) {
  3556. + new_state = 1;
  3557. + priv->oldlink = 0;
  3558. + priv->oldspeed = 0;
  3559. + priv->oldduplex = -1;
  3560. + }
  3561. +
  3562. + if (new_state && netif_msg_link(priv) && net_ratelimit())
  3563. + phy_print_status(priv->phy);
  3564. +
  3565. + spin_unlock(&priv->lock);
  3566. +}
  3567. +
  3568. +static int cpmac_open(struct net_device *dev)
  3569. +{
  3570. + int i, size, res;
  3571. + struct cpmac_priv *priv = netdev_priv(dev);
  3572. + struct resource *mem;
  3573. + struct cpmac_desc *desc;
  3574. + struct sk_buff *skb;
  3575. +
  3576. + mem = platform_get_resource_byname(priv->pdev, IORESOURCE_MEM, "regs");
  3577. + if (!request_mem_region(mem->start, mem->end - mem->start, dev->name)) {
  3578. + if (netif_msg_drv(priv))
  3579. + printk(KERN_ERR "%s: failed to request registers\n",
  3580. + dev->name);
  3581. + res = -ENXIO;
  3582. + goto fail_reserve;
  3583. + }
  3584. +
  3585. + priv->regs = ioremap(mem->start, mem->end - mem->start);
  3586. + if (!priv->regs) {
  3587. + if (netif_msg_drv(priv))
  3588. + printk(KERN_ERR "%s: failed to remap registers\n",
  3589. + dev->name);
  3590. + res = -ENXIO;
  3591. + goto fail_remap;
  3592. + }
  3593. +
  3594. + size = priv->ring_size + CPMAC_QUEUES;
  3595. + priv->desc_ring = dma_alloc_coherent(&dev->dev,
  3596. + sizeof(struct cpmac_desc) * size,
  3597. + &priv->dma_ring,
  3598. + GFP_KERNEL);
  3599. + if (!priv->desc_ring) {
  3600. + res = -ENOMEM;
  3601. + goto fail_alloc;
  3602. + }
  3603. +
  3604. + for (i = 0; i < size; i++)
  3605. + priv->desc_ring[i].mapping = priv->dma_ring + sizeof(*desc) * i;
  3606. +
  3607. + priv->rx_head = &priv->desc_ring[CPMAC_QUEUES];
  3608. + for (i = 0, desc = priv->rx_head; i < priv->ring_size; i++, desc++) {
  3609. + skb = netdev_alloc_skb(dev, CPMAC_SKB_SIZE);
  3610. + if (unlikely(!skb)) {
  3611. + res = -ENOMEM;
  3612. + goto fail_desc;
  3613. + }
  3614. + skb_reserve(skb, 2);
  3615. + desc->skb = skb;
  3616. + desc->data_mapping = dma_map_single(&dev->dev, skb->data,
  3617. + CPMAC_SKB_SIZE,
  3618. + DMA_FROM_DEVICE);
  3619. + desc->hw_data = (u32)desc->data_mapping;
  3620. + desc->buflen = CPMAC_SKB_SIZE;
  3621. + desc->dataflags = CPMAC_OWN;
  3622. + desc->next = &priv->rx_head[(i + 1) % priv->ring_size];
  3623. + desc->next->prev = desc;
  3624. + desc->hw_next = (u32)desc->next->mapping;
  3625. + }
  3626. +
  3627. + priv->rx_head->prev->hw_next = (u32)0;
  3628. +
  3629. + if ((res = request_irq(dev->irq, cpmac_irq, IRQF_SHARED,
  3630. + dev->name, dev))) {
  3631. + if (netif_msg_drv(priv))
  3632. + printk(KERN_ERR "%s: failed to obtain irq\n",
  3633. + dev->name);
  3634. + goto fail_irq;
  3635. + }
  3636. +
  3637. + atomic_set(&priv->reset_pending, 0);
  3638. + INIT_WORK(&priv->reset_work, cpmac_hw_error);
  3639. + cpmac_hw_start(dev);
  3640. +
  3641. + napi_enable(&priv->napi);
  3642. + priv->phy->state = PHY_CHANGELINK;
  3643. + phy_start(priv->phy);
  3644. +
  3645. + return 0;
  3646. +
  3647. +fail_irq:
  3648. +fail_desc:
  3649. + for (i = 0; i < priv->ring_size; i++) {
  3650. + if (priv->rx_head[i].skb) {
  3651. + dma_unmap_single(&dev->dev,
  3652. + priv->rx_head[i].data_mapping,
  3653. + CPMAC_SKB_SIZE,
  3654. + DMA_FROM_DEVICE);
  3655. + kfree_skb(priv->rx_head[i].skb);
  3656. + }
  3657. + }
  3658. +fail_alloc:
  3659. + kfree(priv->desc_ring);
  3660. + iounmap(priv->regs);
  3661. +
  3662. +fail_remap:
  3663. + release_mem_region(mem->start, mem->end - mem->start);
  3664. +
  3665. +fail_reserve:
  3666. + return res;
  3667. +}
  3668. +
  3669. +static int cpmac_stop(struct net_device *dev)
  3670. +{
  3671. + int i;
  3672. + struct cpmac_priv *priv = netdev_priv(dev);
  3673. + struct resource *mem;
  3674. +
  3675. + netif_tx_stop_all_queues(dev);
  3676. +
  3677. + cancel_work_sync(&priv->reset_work);
  3678. + napi_disable(&priv->napi);
  3679. + phy_stop(priv->phy);
  3680. +
  3681. + cpmac_hw_stop(dev);
  3682. +
  3683. + for (i = 0; i < 8; i++)
  3684. + cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0);
  3685. + cpmac_write(priv->regs, CPMAC_RX_PTR(0), 0);
  3686. + cpmac_write(priv->regs, CPMAC_MBP, 0);
  3687. +
  3688. + free_irq(dev->irq, dev);
  3689. + iounmap(priv->regs);
  3690. + mem = platform_get_resource_byname(priv->pdev, IORESOURCE_MEM, "regs");
  3691. + release_mem_region(mem->start, mem->end - mem->start);
  3692. + priv->rx_head = &priv->desc_ring[CPMAC_QUEUES];
  3693. + for (i = 0; i < priv->ring_size; i++) {
  3694. + if (priv->rx_head[i].skb) {
  3695. + dma_unmap_single(&dev->dev,
  3696. + priv->rx_head[i].data_mapping,
  3697. + CPMAC_SKB_SIZE,
  3698. + DMA_FROM_DEVICE);
  3699. + kfree_skb(priv->rx_head[i].skb);
  3700. + }
  3701. + }
  3702. +
  3703. + dma_free_coherent(&dev->dev, sizeof(struct cpmac_desc) *
  3704. + (CPMAC_QUEUES + priv->ring_size),
  3705. + priv->desc_ring, priv->dma_ring);
  3706. + return 0;
  3707. +}
  3708. +
  3709. +static int external_switch;
  3710. +
  3711. +static int __devinit cpmac_probe(struct platform_device *pdev)
  3712. +{
  3713. + int rc, phy_id, i;
  3714. + char *mdio_bus_id = "0";
  3715. + struct resource *mem;
  3716. + struct cpmac_priv *priv;
  3717. + struct net_device *dev;
  3718. + struct plat_cpmac_data *pdata;
  3719. +
  3720. + pdata = pdev->dev.platform_data;
  3721. +
  3722. + for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
  3723. + if (!(pdata->phy_mask & (1 << phy_id)))
  3724. + continue;
  3725. + if (!cpmac_mii->phy_map[phy_id])
  3726. + continue;
  3727. + break;
  3728. + }
  3729. +
  3730. + if (phy_id == PHY_MAX_ADDR) {
  3731. + if (external_switch || dumb_switch) {
  3732. + mdio_bus_id = 0; /* fixed phys bus */
  3733. + phy_id = pdev->id;
  3734. + } else {
  3735. + dev_err(&pdev->dev, "no PHY present\n");
  3736. + return -ENODEV;
  3737. + }
  3738. + }
  3739. +
  3740. + dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
  3741. +
  3742. + if (!dev) {
  3743. + printk(KERN_ERR "cpmac: Unable to allocate net_device\n");
  3744. + return -ENOMEM;
  3745. + }
  3746. +
  3747. + platform_set_drvdata(pdev, dev);
  3748. + priv = netdev_priv(dev);
  3749. +
  3750. + priv->pdev = pdev;
  3751. + mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  3752. + if (!mem) {
  3753. + rc = -ENODEV;
  3754. + goto fail;
  3755. + }
  3756. +
  3757. + dev->irq = platform_get_irq_byname(pdev, "irq");
  3758. +
  3759. + dev->open = cpmac_open;
  3760. + dev->stop = cpmac_stop;
  3761. + dev->set_config = cpmac_config;
  3762. + dev->hard_start_xmit = cpmac_start_xmit;
  3763. + dev->do_ioctl = cpmac_ioctl;
  3764. + dev->set_multicast_list = cpmac_set_multicast_list;
  3765. + dev->tx_timeout = cpmac_tx_timeout;
  3766. + dev->ethtool_ops = &cpmac_ethtool_ops;
  3767. +
  3768. + netif_napi_add(dev, &priv->napi, cpmac_poll, 64);
  3769. +
  3770. + spin_lock_init(&priv->lock);
  3771. + spin_lock_init(&priv->rx_lock);
  3772. + priv->dev = dev;
  3773. + priv->ring_size = 64;
  3774. + priv->msg_enable = netif_msg_init(debug_level, 0xff);
  3775. + memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
  3776. +
  3777. + priv->phy = phy_connect(dev, cpmac_mii->phy_map[phy_id]->dev.bus_id,
  3778. + &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
  3779. + if (IS_ERR(priv->phy)) {
  3780. + if (netif_msg_drv(priv))
  3781. + printk(KERN_ERR "%s: Could not attach to PHY\n",
  3782. + dev->name);
  3783. + return PTR_ERR(priv->phy);
  3784. + }
  3785. +
  3786. + if ((rc = register_netdev(dev))) {
  3787. + printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
  3788. + dev->name);
  3789. + goto fail;
  3790. + }
  3791. +
  3792. + if (netif_msg_probe(priv)) {
  3793. + printk(KERN_INFO
  3794. + "cpmac: device %s (regs: %p, irq: %d, phy: %s, "
  3795. + "mac: %pM)\n", dev->name, (void *)mem->start, dev->irq,
  3796. + priv->phy_name, dev->dev_addr);
  3797. + }
  3798. + return 0;
  3799. +
  3800. +fail:
  3801. + free_netdev(dev);
  3802. + return rc;
  3803. +}
  3804. +
  3805. +static int __devexit cpmac_remove(struct platform_device *pdev)
  3806. +{
  3807. + struct net_device *dev = platform_get_drvdata(pdev);
  3808. + unregister_netdev(dev);
  3809. + free_netdev(dev);
  3810. + return 0;
  3811. +}
  3812. +
  3813. +static struct platform_driver cpmac_driver = {
  3814. + .driver.name = "cpmac",
  3815. + .driver.owner = THIS_MODULE,
  3816. + .probe = cpmac_probe,
  3817. + .remove = __devexit_p(cpmac_remove),
  3818. +};
  3819. +
  3820. +int __devinit cpmac_init(void)
  3821. +{
  3822. + u32 mask;
  3823. + int i, res;
  3824. +
  3825. + cpmac_mii = mdiobus_alloc();
  3826. + if (cpmac_mii == NULL)
  3827. + return -ENOMEM;
  3828. +
  3829. + cpmac_mii->name = "cpmac-mii";
  3830. + cpmac_mii->read = cpmac_mdio_read;
  3831. + cpmac_mii->write = cpmac_mdio_write;
  3832. + cpmac_mii->reset = cpmac_mdio_reset;
  3833. + cpmac_mii->irq = mii_irqs;
  3834. +
  3835. + cpmac_mii->priv = ioremap(AR7_REGS_MDIO, 256);
  3836. +
  3837. + if (!cpmac_mii->priv) {
  3838. + printk(KERN_ERR "Can't ioremap mdio registers\n");
  3839. + res = -ENXIO;
  3840. + goto fail_alloc;
  3841. + }
  3842. +
  3843. +#warning FIXME: unhardcode gpio&reset bits
  3844. + ar7_gpio_disable(26);
  3845. + ar7_gpio_disable(27);
  3846. + ar7_device_reset(AR7_RESET_BIT_CPMAC_LO);
  3847. + ar7_device_reset(AR7_RESET_BIT_CPMAC_HI);
  3848. + ar7_device_reset(AR7_RESET_BIT_EPHY);
  3849. +
  3850. + cpmac_mii->reset(cpmac_mii);
  3851. +
  3852. + for (i = 0; i < 300000; i++)
  3853. + if ((mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE)))
  3854. + break;
  3855. + else
  3856. + cpu_relax();
  3857. +
  3858. + mask &= 0x7fffffff;
  3859. + if (mask & (mask - 1)) {
  3860. + external_switch = 1;
  3861. + mask = 0;
  3862. + }
  3863. +
  3864. + cpmac_mii->phy_mask = ~(mask | 0x80000000);
  3865. + snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "0");
  3866. +
  3867. + res = mdiobus_register(cpmac_mii);
  3868. + if (res)
  3869. + goto fail_mii;
  3870. +
  3871. + res = platform_driver_register(&cpmac_driver);
  3872. + if (res)
  3873. + goto fail_cpmac;
  3874. +
  3875. + return 0;
  3876. +
  3877. +fail_cpmac:
  3878. + mdiobus_unregister(cpmac_mii);
  3879. +
  3880. +fail_mii:
  3881. + iounmap(cpmac_mii->priv);
  3882. +
  3883. +fail_alloc:
  3884. + mdiobus_free(cpmac_mii);
  3885. +
  3886. + return res;
  3887. +}
  3888. +
  3889. +void __devexit cpmac_exit(void)
  3890. +{
  3891. + platform_driver_unregister(&cpmac_driver);
  3892. + mdiobus_unregister(cpmac_mii);
  3893. + mdiobus_free(cpmac_mii);
  3894. + iounmap(cpmac_mii->priv);
  3895. +}
  3896. +
  3897. +module_init(cpmac_init);
  3898. +module_exit(cpmac_exit);
  3899. diff -Nur linux-2.6.29.1.orig/drivers/net/Kconfig linux-2.6.29.1/drivers/net/Kconfig
  3900. --- linux-2.6.29.1.orig/drivers/net/Kconfig 2009-04-02 22:55:27.000000000 +0200
  3901. +++ linux-2.6.29.1/drivers/net/Kconfig 2009-05-31 20:04:03.000000000 +0200
  3902. @@ -1741,7 +1741,7 @@
  3903. config CPMAC
  3904. tristate "TI AR7 CPMAC Ethernet support (EXPERIMENTAL)"
  3905. - depends on NET_ETHERNET && EXPERIMENTAL && AR7 && BROKEN
  3906. + depends on NET_ETHERNET && EXPERIMENTAL && AR7
  3907. select PHYLIB
  3908. help
  3909. TI AR7 CPMAC Ethernet support
  3910. diff -Nur linux-2.6.29.1.orig/drivers/vlynq/Kconfig linux-2.6.29.1/drivers/vlynq/Kconfig
  3911. --- linux-2.6.29.1.orig/drivers/vlynq/Kconfig 1970-01-01 01:00:00.000000000 +0100
  3912. +++ linux-2.6.29.1/drivers/vlynq/Kconfig 2009-05-31 19:50:05.000000000 +0200
  3913. @@ -0,0 +1,13 @@
  3914. +menu "TI VLYNQ"
  3915. +
  3916. +config VLYNQ
  3917. + bool "TI VLYNQ bus support"
  3918. + depends on AR7 && EXPERIMENTAL
  3919. + help
  3920. + Support for the TI VLYNQ bus
  3921. +
  3922. + The module will be called vlynq
  3923. +
  3924. + If unsure, say N
  3925. +
  3926. +endmenu
  3927. diff -Nur linux-2.6.29.1.orig/drivers/vlynq/Makefile linux-2.6.29.1/drivers/vlynq/Makefile
  3928. --- linux-2.6.29.1.orig/drivers/vlynq/Makefile 1970-01-01 01:00:00.000000000 +0100
  3929. +++ linux-2.6.29.1/drivers/vlynq/Makefile 2009-05-31 19:50:06.000000000 +0200
  3930. @@ -0,0 +1,5 @@
  3931. +#
  3932. +# Makefile for kernel vlynq drivers
  3933. +#
  3934. +
  3935. +obj-$(CONFIG_VLYNQ) += vlynq.o
  3936. diff -Nur linux-2.6.29.1.orig/drivers/vlynq/vlynq.c linux-2.6.29.1/drivers/vlynq/vlynq.c
  3937. --- linux-2.6.29.1.orig/drivers/vlynq/vlynq.c 1970-01-01 01:00:00.000000000 +0100
  3938. +++ linux-2.6.29.1/drivers/vlynq/vlynq.c 2009-05-31 19:50:06.000000000 +0200
  3939. @@ -0,0 +1,783 @@
  3940. +/*
  3941. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  3942. + *
  3943. + * This program is free software; you can redistribute it and/or modify
  3944. + * it under the terms of the GNU General Public License as published by
  3945. + * the Free Software Foundation; either version 2 of the License, or
  3946. + * (at your option) any later version.
  3947. + *
  3948. + * This program is distributed in the hope that it will be useful,
  3949. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3950. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3951. + * GNU General Public License for more details.
  3952. + *
  3953. + * You should have received a copy of the GNU General Public License
  3954. + * along with this program; if not, write to the Free Software
  3955. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  3956. + */
  3957. +
  3958. +#include <linux/init.h>
  3959. +#include <linux/types.h>
  3960. +#include <linux/kernel.h>
  3961. +#include <linux/string.h>
  3962. +#include <linux/device.h>
  3963. +#include <linux/module.h>
  3964. +#include <linux/errno.h>
  3965. +#include <linux/platform_device.h>
  3966. +#include <linux/interrupt.h>
  3967. +#include <linux/device.h>
  3968. +#include <linux/delay.h>
  3969. +#include <linux/io.h>
  3970. +
  3971. +#include <linux/vlynq.h>
  3972. +
  3973. +#define VLYNQ_CTRL_PM_ENABLE 0x80000000
  3974. +#define VLYNQ_CTRL_CLOCK_INT 0x00008000
  3975. +#define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
  3976. +#define VLYNQ_CTRL_INT_LOCAL 0x00004000
  3977. +#define VLYNQ_CTRL_INT_ENABLE 0x00002000
  3978. +#define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
  3979. +#define VLYNQ_CTRL_INT2CFG 0x00000080
  3980. +#define VLYNQ_CTRL_RESET 0x00000001
  3981. +
  3982. +#define VLYNQ_CTRL_CLOCK_MASK (0x7 << 16)
  3983. +
  3984. +#define VLYNQ_INT_OFFSET 0x00000014
  3985. +#define VLYNQ_REMOTE_OFFSET 0x00000080
  3986. +
  3987. +#define VLYNQ_STATUS_LINK 0x00000001
  3988. +#define VLYNQ_STATUS_LERROR 0x00000080
  3989. +#define VLYNQ_STATUS_RERROR 0x00000100
  3990. +
  3991. +#define VINT_ENABLE 0x00000100
  3992. +#define VINT_TYPE_EDGE 0x00000080
  3993. +#define VINT_LEVEL_LOW 0x00000040
  3994. +#define VINT_VECTOR(x) ((x) & 0x1f)
  3995. +#define VINT_OFFSET(irq) (8 * ((irq) % 4))
  3996. +
  3997. +#define VLYNQ_AUTONEGO_V2 0x00010000
  3998. +
  3999. +struct vlynq_regs {
  4000. + u32 revision;
  4001. + u32 control;
  4002. + u32 status;
  4003. + u32 int_prio;
  4004. + u32 int_status;
  4005. + u32 int_pending;
  4006. + u32 int_ptr;
  4007. + u32 tx_offset;
  4008. + struct vlynq_mapping rx_mapping[4];
  4009. + u32 chip;
  4010. + u32 autonego;
  4011. + u32 unused[6];
  4012. + u32 int_device[8];
  4013. +};
  4014. +
  4015. +#define vlynq_reg_read(reg) readl(&(reg))
  4016. +#define vlynq_reg_write(reg, val) writel(val, &(reg))
  4017. +
  4018. +static int __vlynq_enable_device(struct vlynq_device *dev);
  4019. +
  4020. +#ifdef VLYNQ_DEBUG
  4021. +static void vlynq_dump_regs(struct vlynq_device *dev)
  4022. +{
  4023. + int i;
  4024. + printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
  4025. + dev->local, dev->remote);
  4026. + for (i = 0; i < 32; i++) {
  4027. + printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
  4028. + i + 1, ((u32 *)dev->local)[i]);
  4029. + printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
  4030. + i + 1, ((u32 *)dev->remote)[i]);
  4031. + }
  4032. +}
  4033. +
  4034. +static void vlynq_dump_mem(u32 *base, int count)
  4035. +{
  4036. + int i;
  4037. + for (i = 0; i < (count + 3) / 4; i++) {
  4038. + if (i % 4 == 0) printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
  4039. + printk(KERN_DEBUG " 0x%08x", *(base + i));
  4040. + }
  4041. + printk(KERN_DEBUG "\n");
  4042. +}
  4043. +#endif
  4044. +
  4045. +int vlynq_linked(struct vlynq_device *dev)
  4046. +{
  4047. + int i;
  4048. +
  4049. + for (i = 0; i < 100; i++)
  4050. + if (vlynq_reg_read(dev->local->status) & VLYNQ_STATUS_LINK)
  4051. + return 1;
  4052. + else
  4053. + cpu_relax();
  4054. +
  4055. + return 0;
  4056. +}
  4057. +
  4058. +static void vlynq_reset(struct vlynq_device *dev)
  4059. +{
  4060. + vlynq_reg_write(dev->local->control,
  4061. + vlynq_reg_read(dev->local->control) |
  4062. + VLYNQ_CTRL_RESET);
  4063. +
  4064. + /* Wait for the devices to finish resetting */
  4065. + msleep(5);
  4066. +
  4067. + /* Remove reset bit */
  4068. + vlynq_reg_write(dev->local->control,
  4069. + vlynq_reg_read(dev->local->control) &
  4070. + ~VLYNQ_CTRL_RESET);
  4071. +
  4072. + /* Give some time for the devices to settle */
  4073. + msleep(5);
  4074. +}
  4075. +
  4076. +static void vlynq_irq_unmask(unsigned int irq)
  4077. +{
  4078. + u32 val;
  4079. + struct vlynq_device *dev = get_irq_chip_data(irq);
  4080. + int virq;
  4081. +
  4082. + BUG_ON(!dev);
  4083. + virq = irq - dev->irq_start;
  4084. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  4085. + val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
  4086. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  4087. +}
  4088. +
  4089. +static void vlynq_irq_mask(unsigned int irq)
  4090. +{
  4091. + u32 val;
  4092. + struct vlynq_device *dev = get_irq_chip_data(irq);
  4093. + int virq;
  4094. +
  4095. + BUG_ON(!dev);
  4096. + virq = irq - dev->irq_start;
  4097. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  4098. + val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
  4099. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  4100. +}
  4101. +
  4102. +static int vlynq_irq_type(unsigned int irq, unsigned int flow_type)
  4103. +{
  4104. + u32 val;
  4105. + struct vlynq_device *dev = get_irq_chip_data(irq);
  4106. + int virq;
  4107. +
  4108. + BUG_ON(!dev);
  4109. + virq = irq - dev->irq_start;
  4110. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  4111. + switch (flow_type & IRQ_TYPE_SENSE_MASK) {
  4112. + case IRQ_TYPE_EDGE_RISING:
  4113. + case IRQ_TYPE_EDGE_FALLING:
  4114. + case IRQ_TYPE_EDGE_BOTH:
  4115. + val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
  4116. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  4117. + break;
  4118. + case IRQ_TYPE_LEVEL_HIGH:
  4119. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  4120. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  4121. + break;
  4122. + case IRQ_TYPE_LEVEL_LOW:
  4123. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  4124. + val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
  4125. + break;
  4126. + default:
  4127. + return -EINVAL;
  4128. + }
  4129. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  4130. + return 0;
  4131. +}
  4132. +
  4133. +static void vlynq_local_ack(unsigned int irq)
  4134. +{
  4135. + struct vlynq_device *dev = get_irq_chip_data(irq);
  4136. + u32 status = vlynq_reg_read(dev->local->status);
  4137. + if (printk_ratelimit())
  4138. + printk(KERN_DEBUG "%s: local status: 0x%08x\n",
  4139. + dev->dev.bus_id, status);
  4140. + vlynq_reg_write(dev->local->status, status);
  4141. +}
  4142. +
  4143. +static void vlynq_remote_ack(unsigned int irq)
  4144. +{
  4145. + struct vlynq_device *dev = get_irq_chip_data(irq);
  4146. + u32 status = vlynq_reg_read(dev->remote->status);
  4147. + if (printk_ratelimit())
  4148. + printk(KERN_DEBUG "%s: remote status: 0x%08x\n",
  4149. + dev->dev.bus_id, status);
  4150. + vlynq_reg_write(dev->remote->status, status);
  4151. +}
  4152. +
  4153. +static irqreturn_t vlynq_irq(int irq, void *dev_id)
  4154. +{
  4155. + struct vlynq_device *dev = dev_id;
  4156. + u32 status;
  4157. + int virq = 0;
  4158. +
  4159. + status = vlynq_reg_read(dev->local->int_status);
  4160. + vlynq_reg_write(dev->local->int_status, status);
  4161. +
  4162. + if (unlikely(!status))
  4163. + spurious_interrupt();
  4164. +
  4165. + while (status) {
  4166. + if (status & 1)
  4167. + do_IRQ(dev->irq_start + virq);
  4168. + status >>= 1;
  4169. + virq++;
  4170. + }
  4171. +
  4172. + return IRQ_HANDLED;
  4173. +}
  4174. +
  4175. +static struct irq_chip vlynq_irq_chip = {
  4176. + .name = "vlynq",
  4177. + .unmask = vlynq_irq_unmask,
  4178. + .mask = vlynq_irq_mask,
  4179. + .set_type = vlynq_irq_type,
  4180. +};
  4181. +
  4182. +static struct irq_chip vlynq_local_chip = {
  4183. + .name = "vlynq local error",
  4184. + .unmask = vlynq_irq_unmask,
  4185. + .mask = vlynq_irq_mask,
  4186. + .ack = vlynq_local_ack,
  4187. +};
  4188. +
  4189. +static struct irq_chip vlynq_remote_chip = {
  4190. + .name = "vlynq local error",
  4191. + .unmask = vlynq_irq_unmask,
  4192. + .mask = vlynq_irq_mask,
  4193. + .ack = vlynq_remote_ack,
  4194. +};
  4195. +
  4196. +static int vlynq_setup_irq(struct vlynq_device *dev)
  4197. +{
  4198. + u32 val;
  4199. + int i, virq;
  4200. +
  4201. + if (dev->local_irq == dev->remote_irq) {
  4202. + printk(KERN_ERR
  4203. + "%s: local vlynq irq should be different from remote\n",
  4204. + dev->dev.bus_id);
  4205. + return -EINVAL;
  4206. + }
  4207. +
  4208. + /* Clear local and remote error bits */
  4209. + vlynq_reg_write(dev->local->status, vlynq_reg_read(dev->local->status));
  4210. + vlynq_reg_write(dev->remote->status,
  4211. + vlynq_reg_read(dev->remote->status));
  4212. +
  4213. + /* Now setup interrupts */
  4214. + val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
  4215. + val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
  4216. + VLYNQ_CTRL_INT2CFG;
  4217. + val |= vlynq_reg_read(dev->local->control);
  4218. + vlynq_reg_write(dev->local->int_ptr, VLYNQ_INT_OFFSET);
  4219. + vlynq_reg_write(dev->local->control, val);
  4220. +
  4221. + val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
  4222. + val |= VLYNQ_CTRL_INT_ENABLE;
  4223. + val |= vlynq_reg_read(dev->remote->control);
  4224. + vlynq_reg_write(dev->remote->int_ptr, VLYNQ_INT_OFFSET);
  4225. + vlynq_reg_write(dev->remote->control, val);
  4226. +
  4227. + for (i = dev->irq_start; i <= dev->irq_end; i++) {
  4228. + virq = i - dev->irq_start;
  4229. + if (virq == dev->local_irq) {
  4230. + set_irq_chip_and_handler(i, &vlynq_local_chip,
  4231. + handle_level_irq);
  4232. + set_irq_chip_data(i, dev);
  4233. + } else if (virq == dev->remote_irq) {
  4234. + set_irq_chip_and_handler(i, &vlynq_remote_chip,
  4235. + handle_level_irq);
  4236. + set_irq_chip_data(i, dev);
  4237. + } else {
  4238. + set_irq_chip_and_handler(i, &vlynq_irq_chip,
  4239. + handle_simple_irq);
  4240. + set_irq_chip_data(i, dev);
  4241. + vlynq_reg_write(dev->remote->int_device[virq >> 2], 0);
  4242. + }
  4243. + }
  4244. +
  4245. + if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
  4246. + printk(KERN_ERR "%s: request_irq failed\n", dev->dev.bus_id);
  4247. + return -EAGAIN;
  4248. + }
  4249. +
  4250. + return 0;
  4251. +}
  4252. +
  4253. +static void vlynq_device_release(struct device *dev)
  4254. +{
  4255. + struct vlynq_device *vdev = to_vlynq_device(dev);
  4256. + kfree(vdev);
  4257. +}
  4258. +
  4259. +static int vlynq_device_match(struct device *dev,
  4260. + struct device_driver *drv)
  4261. +{
  4262. + struct vlynq_device *vdev = to_vlynq_device(dev);
  4263. + struct vlynq_driver *vdrv = to_vlynq_driver(drv);
  4264. + struct vlynq_device_id *ids = vdrv->id_table;
  4265. +
  4266. + while (ids->id) {
  4267. + if (ids->id == vdev->dev_id) {
  4268. + vdev->divisor = ids->divisor;
  4269. + vlynq_set_drvdata(vdev, ids);
  4270. + printk(KERN_INFO "Driver found for VLYNQ " \
  4271. + "device: %08x\n", vdev->dev_id);
  4272. + return 1;
  4273. + }
  4274. + printk(KERN_DEBUG "Not using the %08x VLYNQ device's driver" \
  4275. + " for VLYNQ device: %08x\n", ids->id, vdev->dev_id);
  4276. + ids++;
  4277. + }
  4278. + return 0;
  4279. +}
  4280. +
  4281. +static int vlynq_device_probe(struct device *dev)
  4282. +{
  4283. + struct vlynq_device *vdev = to_vlynq_device(dev);
  4284. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  4285. + struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
  4286. + int result = -ENODEV;
  4287. +
  4288. + get_device(dev);
  4289. + if (drv && drv->probe)
  4290. + result = drv->probe(vdev, id);
  4291. + if (result)
  4292. + put_device(dev);
  4293. + return result;
  4294. +}
  4295. +
  4296. +static int vlynq_device_remove(struct device *dev)
  4297. +{
  4298. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  4299. + if (drv && drv->remove)
  4300. + drv->remove(to_vlynq_device(dev));
  4301. + put_device(dev);
  4302. + return 0;
  4303. +}
  4304. +
  4305. +int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
  4306. +{
  4307. + driver->driver.name = driver->name;
  4308. + driver->driver.bus = &vlynq_bus_type;
  4309. + return driver_register(&driver->driver);
  4310. +}
  4311. +EXPORT_SYMBOL(__vlynq_register_driver);
  4312. +
  4313. +void vlynq_unregister_driver(struct vlynq_driver *driver)
  4314. +{
  4315. + driver_unregister(&driver->driver);
  4316. +}
  4317. +EXPORT_SYMBOL(vlynq_unregister_driver);
  4318. +
  4319. +static int __vlynq_try_remote(struct vlynq_device *dev)
  4320. +{
  4321. + int i;
  4322. +
  4323. + vlynq_reset(dev);
  4324. + for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
  4325. + i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
  4326. + dev->dev_id ? i++ : i--) {
  4327. +
  4328. + if (!vlynq_linked(dev))
  4329. + break;
  4330. +
  4331. + vlynq_reg_write(dev->remote->control,
  4332. + (vlynq_reg_read(dev->remote->control) &
  4333. + ~VLYNQ_CTRL_CLOCK_MASK) |
  4334. + VLYNQ_CTRL_CLOCK_INT |
  4335. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1));
  4336. + vlynq_reg_write(dev->local->control,
  4337. + ((vlynq_reg_read(dev->local->control)
  4338. + & ~(VLYNQ_CTRL_CLOCK_INT |
  4339. + VLYNQ_CTRL_CLOCK_MASK)) |
  4340. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1)));
  4341. +
  4342. + if (vlynq_linked(dev)) {
  4343. + printk(KERN_DEBUG
  4344. + "%s: using remote clock divisor %d\n",
  4345. + dev->dev.bus_id, i - vlynq_rdiv1 + 1);
  4346. + dev->divisor = i;
  4347. + return 0;
  4348. + } else {
  4349. + vlynq_reset(dev);
  4350. + }
  4351. + }
  4352. +
  4353. + return -ENODEV;
  4354. +}
  4355. +
  4356. +static int __vlynq_try_local(struct vlynq_device *dev)
  4357. +{
  4358. + int i;
  4359. +
  4360. + vlynq_reset(dev);
  4361. +
  4362. + for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
  4363. + i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
  4364. + dev->dev_id ? i++ : i--) {
  4365. +
  4366. + vlynq_reg_write(dev->local->control,
  4367. + (vlynq_reg_read(dev->local->control) &
  4368. + ~VLYNQ_CTRL_CLOCK_MASK) |
  4369. + VLYNQ_CTRL_CLOCK_INT |
  4370. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1));
  4371. +
  4372. + if (vlynq_linked(dev)) {
  4373. + printk(KERN_DEBUG
  4374. + "%s: using local clock divisor %d\n",
  4375. + dev->dev.bus_id, i - vlynq_ldiv1 + 1);
  4376. + dev->divisor = i;
  4377. + return 0;
  4378. + } else {
  4379. + vlynq_reset(dev);
  4380. + }
  4381. + }
  4382. +
  4383. + return -ENODEV;
  4384. +}
  4385. +
  4386. +static int __vlynq_try_external(struct vlynq_device *dev)
  4387. +{
  4388. + vlynq_reset(dev);
  4389. + if (!vlynq_linked(dev))
  4390. + return -ENODEV;
  4391. +
  4392. + vlynq_reg_write(dev->remote->control,
  4393. + (vlynq_reg_read(dev->remote->control) &
  4394. + ~VLYNQ_CTRL_CLOCK_INT));
  4395. +
  4396. + vlynq_reg_write(dev->local->control,
  4397. + (vlynq_reg_read(dev->local->control) &
  4398. + ~VLYNQ_CTRL_CLOCK_INT));
  4399. +
  4400. + if (vlynq_linked(dev)) {
  4401. + printk(KERN_DEBUG "%s: using external clock\n",
  4402. + dev->dev.bus_id);
  4403. + dev->divisor = vlynq_div_external;
  4404. + return 0;
  4405. + }
  4406. +
  4407. + return -ENODEV;
  4408. +}
  4409. +
  4410. +static int __vlynq_enable_device(struct vlynq_device *dev)
  4411. +{
  4412. + int result;
  4413. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  4414. +
  4415. + result = ops->on(dev);
  4416. + if (result)
  4417. + return result;
  4418. +
  4419. + switch (dev->divisor) {
  4420. + case vlynq_div_external:
  4421. + case vlynq_div_auto:
  4422. + /* When the device is brought from reset it should have clock
  4423. + generation negotiated by hardware.
  4424. + Check which device is generating clocks and perform setup
  4425. + accordingly */
  4426. + if (vlynq_linked(dev) && vlynq_reg_read(dev->remote->control) &
  4427. + VLYNQ_CTRL_CLOCK_INT) {
  4428. + if (!__vlynq_try_remote(dev) ||
  4429. + !__vlynq_try_local(dev) ||
  4430. + !__vlynq_try_external(dev))
  4431. + return 0;
  4432. + } else {
  4433. + if (!__vlynq_try_external(dev) ||
  4434. + !__vlynq_try_local(dev) ||
  4435. + !__vlynq_try_remote(dev))
  4436. + return 0;
  4437. + }
  4438. + break;
  4439. + case vlynq_ldiv1: case vlynq_ldiv2: case vlynq_ldiv3: case vlynq_ldiv4:
  4440. + case vlynq_ldiv5: case vlynq_ldiv6: case vlynq_ldiv7: case vlynq_ldiv8:
  4441. + vlynq_reg_write(dev->local->control,
  4442. + VLYNQ_CTRL_CLOCK_INT |
  4443. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  4444. + vlynq_ldiv1));
  4445. + vlynq_reg_write(dev->remote->control, 0);
  4446. + if (vlynq_linked(dev)) {
  4447. + printk(KERN_DEBUG
  4448. + "%s: using local clock divisor %d\n",
  4449. + dev->dev.bus_id, dev->divisor - vlynq_ldiv1 + 1);
  4450. + return 0;
  4451. + }
  4452. + break;
  4453. + case vlynq_rdiv1: case vlynq_rdiv2: case vlynq_rdiv3: case vlynq_rdiv4:
  4454. + case vlynq_rdiv5: case vlynq_rdiv6: case vlynq_rdiv7: case vlynq_rdiv8:
  4455. + vlynq_reg_write(dev->local->control, 0);
  4456. + vlynq_reg_write(dev->remote->control,
  4457. + VLYNQ_CTRL_CLOCK_INT |
  4458. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  4459. + vlynq_rdiv1));
  4460. + if (vlynq_linked(dev)) {
  4461. + printk(KERN_DEBUG
  4462. + "%s: using remote clock divisor %d\n",
  4463. + dev->dev.bus_id, dev->divisor - vlynq_rdiv1 + 1);
  4464. + return 0;
  4465. + }
  4466. + break;
  4467. + }
  4468. +
  4469. + ops->off(dev);
  4470. + return -ENODEV;
  4471. +}
  4472. +
  4473. +int vlynq_enable_device(struct vlynq_device *dev)
  4474. +{
  4475. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  4476. + int result = -ENODEV;
  4477. +
  4478. + result = __vlynq_enable_device(dev);
  4479. + if (result)
  4480. + return result;
  4481. +
  4482. + result = vlynq_setup_irq(dev);
  4483. + if (result)
  4484. + ops->off(dev);
  4485. +
  4486. + dev->enabled = !result;
  4487. + return result;
  4488. +}
  4489. +EXPORT_SYMBOL(vlynq_enable_device);
  4490. +
  4491. +
  4492. +void vlynq_disable_device(struct vlynq_device *dev)
  4493. +{
  4494. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  4495. +
  4496. + dev->enabled = 0;
  4497. + free_irq(dev->irq, dev);
  4498. + ops->off(dev);
  4499. +}
  4500. +EXPORT_SYMBOL(vlynq_disable_device);
  4501. +
  4502. +int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  4503. + struct vlynq_mapping *mapping)
  4504. +{
  4505. + int i;
  4506. +
  4507. + if (!dev->enabled)
  4508. + return -ENXIO;
  4509. +
  4510. + vlynq_reg_write(dev->local->tx_offset, tx_offset);
  4511. + for (i = 0; i < 4; i++) {
  4512. + vlynq_reg_write(dev->local->rx_mapping[i].offset,
  4513. + mapping[i].offset);
  4514. + vlynq_reg_write(dev->local->rx_mapping[i].size,
  4515. + mapping[i].size);
  4516. + }
  4517. + return 0;
  4518. +}
  4519. +EXPORT_SYMBOL(vlynq_set_local_mapping);
  4520. +
  4521. +int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  4522. + struct vlynq_mapping *mapping)
  4523. +{
  4524. + int i;
  4525. +
  4526. + if (!dev->enabled)
  4527. + return -ENXIO;
  4528. +
  4529. + vlynq_reg_write(dev->remote->tx_offset, tx_offset);
  4530. + for (i = 0; i < 4; i++) {
  4531. + vlynq_reg_write(dev->remote->rx_mapping[i].offset,
  4532. + mapping[i].offset);
  4533. + vlynq_reg_write(dev->remote->rx_mapping[i].size,
  4534. + mapping[i].size);
  4535. + }
  4536. + return 0;
  4537. +}
  4538. +EXPORT_SYMBOL(vlynq_set_remote_mapping);
  4539. +
  4540. +int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
  4541. +{
  4542. + int irq = dev->irq_start + virq;
  4543. + if (dev->enabled)
  4544. + return -EBUSY;
  4545. +
  4546. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4547. + return -EINVAL;
  4548. +
  4549. + if (virq == dev->remote_irq)
  4550. + return -EINVAL;
  4551. +
  4552. + dev->local_irq = virq;
  4553. +
  4554. + return 0;
  4555. +}
  4556. +EXPORT_SYMBOL(vlynq_set_local_irq);
  4557. +
  4558. +int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
  4559. +{
  4560. + int irq = dev->irq_start + virq;
  4561. + if (dev->enabled)
  4562. + return -EBUSY;
  4563. +
  4564. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4565. + return -EINVAL;
  4566. +
  4567. + if (virq == dev->local_irq)
  4568. + return -EINVAL;
  4569. +
  4570. + dev->remote_irq = virq;
  4571. +
  4572. + return 0;
  4573. +}
  4574. +EXPORT_SYMBOL(vlynq_set_remote_irq);
  4575. +
  4576. +static int vlynq_probe(struct platform_device *pdev)
  4577. +{
  4578. + struct vlynq_device *dev;
  4579. + struct resource *regs_res, *mem_res, *irq_res;
  4580. + int len, result;
  4581. +
  4582. + regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  4583. + if (!regs_res)
  4584. + return -ENODEV;
  4585. +
  4586. + mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
  4587. + if (!mem_res)
  4588. + return -ENODEV;
  4589. +
  4590. + irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
  4591. + if (!irq_res)
  4592. + return -ENODEV;
  4593. +
  4594. + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  4595. + if (!dev) {
  4596. + printk(KERN_ERR
  4597. + "vlynq: failed to allocate device structure\n");
  4598. + return -ENOMEM;
  4599. + }
  4600. +
  4601. + dev->id = pdev->id;
  4602. + dev->dev.bus = &vlynq_bus_type;
  4603. + dev->dev.parent = &pdev->dev;
  4604. + snprintf(dev->dev.bus_id, BUS_ID_SIZE, "vlynq%d", dev->id);
  4605. + dev->dev.bus_id[BUS_ID_SIZE - 1] = 0;
  4606. + dev->dev.platform_data = pdev->dev.platform_data;
  4607. + dev->dev.release = vlynq_device_release;
  4608. +
  4609. + dev->regs_start = regs_res->start;
  4610. + dev->regs_end = regs_res->end;
  4611. + dev->mem_start = mem_res->start;
  4612. + dev->mem_end = mem_res->end;
  4613. +
  4614. + len = regs_res->end - regs_res->start;
  4615. + if (!request_mem_region(regs_res->start, len, dev->dev.bus_id)) {
  4616. + printk(KERN_ERR "%s: Can't request vlynq registers\n",
  4617. + dev->dev.bus_id);
  4618. + result = -ENXIO;
  4619. + goto fail_request;
  4620. + }
  4621. +
  4622. + dev->local = ioremap(regs_res->start, len);
  4623. + if (!dev->local) {
  4624. + printk(KERN_ERR "%s: Can't remap vlynq registers\n",
  4625. + dev->dev.bus_id);
  4626. + result = -ENXIO;
  4627. + goto fail_remap;
  4628. + }
  4629. +
  4630. + dev->remote = (struct vlynq_regs *)((void *)dev->local +
  4631. + VLYNQ_REMOTE_OFFSET);
  4632. +
  4633. + dev->irq = platform_get_irq_byname(pdev, "irq");
  4634. + dev->irq_start = irq_res->start;
  4635. + dev->irq_end = irq_res->end;
  4636. + dev->local_irq = dev->irq_end - dev->irq_start;
  4637. + dev->remote_irq = dev->local_irq - 1;
  4638. +
  4639. + if (device_register(&dev->dev))
  4640. + goto fail_register;
  4641. + platform_set_drvdata(pdev, dev);
  4642. +
  4643. + printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
  4644. + dev->dev.bus_id, (void *)dev->regs_start, dev->irq,
  4645. + (void *)dev->mem_start);
  4646. +
  4647. + dev->dev_id = 0;
  4648. + dev->divisor = vlynq_div_auto;
  4649. + result = __vlynq_enable_device(dev);
  4650. + if (result == 0) {
  4651. + dev->dev_id = vlynq_reg_read(dev->remote->chip);
  4652. + ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
  4653. + }
  4654. + if (dev->dev_id)
  4655. + printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
  4656. +
  4657. + return 0;
  4658. +
  4659. +fail_register:
  4660. + iounmap(dev->local);
  4661. +fail_remap:
  4662. +fail_request:
  4663. + release_mem_region(regs_res->start, len);
  4664. + kfree(dev);
  4665. + return result;
  4666. +}
  4667. +
  4668. +static int vlynq_remove(struct platform_device *pdev)
  4669. +{
  4670. + struct vlynq_device *dev = platform_get_drvdata(pdev);
  4671. +
  4672. + device_unregister(&dev->dev);
  4673. + iounmap(dev->local);
  4674. + release_mem_region(dev->regs_start, dev->regs_end - dev->regs_start);
  4675. +
  4676. + kfree(dev);
  4677. +
  4678. + return 0;
  4679. +}
  4680. +
  4681. +static struct platform_driver vlynq_platform_driver = {
  4682. + .driver.name = "vlynq",
  4683. + .probe = vlynq_probe,
  4684. + .remove = __devexit_p(vlynq_remove),
  4685. +};
  4686. +
  4687. +struct bus_type vlynq_bus_type = {
  4688. + .name = "vlynq",
  4689. + .match = vlynq_device_match,
  4690. + .probe = vlynq_device_probe,
  4691. + .remove = vlynq_device_remove,
  4692. +};
  4693. +EXPORT_SYMBOL(vlynq_bus_type);
  4694. +
  4695. +static int __devinit vlynq_init(void)
  4696. +{
  4697. + int res = 0;
  4698. +
  4699. + res = bus_register(&vlynq_bus_type);
  4700. + if (res)
  4701. + goto fail_bus;
  4702. +
  4703. + res = platform_driver_register(&vlynq_platform_driver);
  4704. + if (res)
  4705. + goto fail_platform;
  4706. +
  4707. + return 0;
  4708. +
  4709. +fail_platform:
  4710. + bus_unregister(&vlynq_bus_type);
  4711. +fail_bus:
  4712. + return res;
  4713. +}
  4714. +
  4715. +static void __devexit vlynq_exit(void)
  4716. +{
  4717. + platform_driver_unregister(&vlynq_platform_driver);
  4718. + bus_unregister(&vlynq_bus_type);
  4719. +}
  4720. +
  4721. +module_init(vlynq_init);
  4722. +module_exit(vlynq_exit);
  4723. diff -Nur linux-2.6.29.1.orig/drivers/watchdog/ar7_wdt.c linux-2.6.29.1/drivers/watchdog/ar7_wdt.c
  4724. --- linux-2.6.29.1.orig/drivers/watchdog/ar7_wdt.c 2009-04-02 22:55:27.000000000 +0200
  4725. +++ linux-2.6.29.1/drivers/watchdog/ar7_wdt.c 2009-05-31 19:54:01.000000000 +0200
  4726. @@ -69,8 +69,7 @@
  4727. u32 prescale;
  4728. };
  4729. -static unsigned long wdt_is_open;
  4730. -static spinlock_t wdt_lock;
  4731. +static struct semaphore open_semaphore;
  4732. static unsigned expect_close;
  4733. /* XXX currently fixed, allows max margin ~68.72 secs */
  4734. @@ -155,10 +154,8 @@
  4735. u32 change;
  4736. change = new_margin * (ar7_vbus_freq() / prescale_value);
  4737. - if (change < 1)
  4738. - change = 1;
  4739. - if (change > 0xffff)
  4740. - change = 0xffff;
  4741. + if (change < 1) change = 1;
  4742. + if (change > 0xffff) change = 0xffff;
  4743. ar7_wdt_change(change);
  4744. margin = change * prescale_value / ar7_vbus_freq();
  4745. printk(KERN_INFO DRVNAME
  4746. @@ -182,7 +179,7 @@
  4747. static int ar7_wdt_open(struct inode *inode, struct file *file)
  4748. {
  4749. /* only allow one at a time */
  4750. - if (test_and_set_bit(0, &wdt_is_open))
  4751. + if (down_trylock(&open_semaphore))
  4752. return -EBUSY;
  4753. ar7_wdt_enable_wdt();
  4754. expect_close = 0;
  4755. @@ -198,7 +195,9 @@
  4756. "will not disable the watchdog timer\n");
  4757. else if (!nowayout)
  4758. ar7_wdt_disable_wdt();
  4759. - clear_bit(0, &wdt_is_open);
  4760. +
  4761. + up(&open_semaphore);
  4762. +
  4763. return 0;
  4764. }
  4765. @@ -213,7 +212,7 @@
  4766. }
  4767. static struct notifier_block ar7_wdt_notifier = {
  4768. - .notifier_call = ar7_wdt_notify_sys,
  4769. + .notifier_call = ar7_wdt_notify_sys
  4770. };
  4771. static ssize_t ar7_wdt_write(struct file *file, const char *data,
  4772. @@ -223,14 +222,12 @@
  4773. if (len) {
  4774. size_t i;
  4775. - spin_lock(&wdt_lock);
  4776. ar7_wdt_kick(1);
  4777. - spin_unlock(&wdt_lock);
  4778. expect_close = 0;
  4779. for (i = 0; i < len; ++i) {
  4780. char c;
  4781. - if (get_user(c, data + i))
  4782. + if (get_user(c, data+i))
  4783. return -EFAULT;
  4784. if (c == 'V')
  4785. expect_close = 1;
  4786. @@ -240,17 +237,19 @@
  4787. return len;
  4788. }
  4789. -static long ar7_wdt_ioctl(struct file *file,
  4790. - unsigned int cmd, unsigned long arg)
  4791. +static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
  4792. + unsigned int cmd, unsigned long arg)
  4793. {
  4794. static struct watchdog_info ident = {
  4795. .identity = LONGNAME,
  4796. .firmware_version = 1,
  4797. - .options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING),
  4798. + .options = (WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING),
  4799. };
  4800. int new_margin;
  4801. switch (cmd) {
  4802. + default:
  4803. + return -ENOTTY;
  4804. case WDIOC_GETSUPPORT:
  4805. if (copy_to_user((struct watchdog_info *)arg, &ident,
  4806. sizeof(ident)))
  4807. @@ -270,24 +269,20 @@
  4808. if (new_margin < 1)
  4809. return -EINVAL;
  4810. - spin_lock(&wdt_lock);
  4811. ar7_wdt_update_margin(new_margin);
  4812. ar7_wdt_kick(1);
  4813. - spin_unlock(&wdt_lock);
  4814. case WDIOC_GETTIMEOUT:
  4815. if (put_user(margin, (int *)arg))
  4816. return -EFAULT;
  4817. return 0;
  4818. - default:
  4819. - return -ENOTTY;
  4820. }
  4821. }
  4822. -static const struct file_operations ar7_wdt_fops = {
  4823. +static struct file_operations ar7_wdt_fops = {
  4824. .owner = THIS_MODULE,
  4825. .write = ar7_wdt_write,
  4826. - .unlocked_ioctl = ar7_wdt_ioctl,
  4827. + .ioctl = ar7_wdt_ioctl,
  4828. .open = ar7_wdt_open,
  4829. .release = ar7_wdt_release,
  4830. };
  4831. @@ -302,8 +297,6 @@
  4832. {
  4833. int rc;
  4834. - spin_lock_init(&wdt_lock);
  4835. -
  4836. ar7_wdt_get_regs();
  4837. if (!request_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt),
  4838. @@ -319,6 +312,8 @@
  4839. ar7_wdt_prescale(prescale_value);
  4840. ar7_wdt_update_margin(margin);
  4841. + sema_init(&open_semaphore, 1);
  4842. +
  4843. rc = register_reboot_notifier(&ar7_wdt_notifier);
  4844. if (rc) {
  4845. printk(KERN_ERR DRVNAME
  4846. diff -Nur linux-2.6.29.1.orig/include/linux/vlynq.h linux-2.6.29.1/include/linux/vlynq.h
  4847. --- linux-2.6.29.1.orig/include/linux/vlynq.h 1970-01-01 01:00:00.000000000 +0100
  4848. +++ linux-2.6.29.1/include/linux/vlynq.h 2009-05-31 20:25:54.000000000 +0200
  4849. @@ -0,0 +1,161 @@
  4850. +/*
  4851. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  4852. + *
  4853. + * This program is free software; you can redistribute it and/or modify
  4854. + * it under the terms of the GNU General Public License as published by
  4855. + * the Free Software Foundation; either version 2 of the License, or
  4856. + * (at your option) any later version.
  4857. + *
  4858. + * This program is distributed in the hope that it will be useful,
  4859. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4860. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4861. + * GNU General Public License for more details.
  4862. + *
  4863. + * You should have received a copy of the GNU General Public License
  4864. + * along with this program; if not, write to the Free Software
  4865. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  4866. + */
  4867. +
  4868. +#ifndef __VLYNQ_H__
  4869. +#define __VLYNQ_H__
  4870. +
  4871. +#include <linux/device.h>
  4872. +#include <linux/module.h>
  4873. +#include <linux/types.h>
  4874. +
  4875. +#define VLYNQ_NUM_IRQS 32
  4876. +
  4877. +struct vlynq_mapping {
  4878. + u32 size;
  4879. + u32 offset;
  4880. +};
  4881. +
  4882. +enum vlynq_divisor {
  4883. + vlynq_div_auto = 0,
  4884. + vlynq_ldiv1,
  4885. + vlynq_ldiv2,
  4886. + vlynq_ldiv3,
  4887. + vlynq_ldiv4,
  4888. + vlynq_ldiv5,
  4889. + vlynq_ldiv6,
  4890. + vlynq_ldiv7,
  4891. + vlynq_ldiv8,
  4892. + vlynq_rdiv1,
  4893. + vlynq_rdiv2,
  4894. + vlynq_rdiv3,
  4895. + vlynq_rdiv4,
  4896. + vlynq_rdiv5,
  4897. + vlynq_rdiv6,
  4898. + vlynq_rdiv7,
  4899. + vlynq_rdiv8,
  4900. + vlynq_div_external
  4901. +};
  4902. +
  4903. +struct vlynq_device_id {
  4904. + u32 id;
  4905. + enum vlynq_divisor divisor;
  4906. + unsigned long driver_data;
  4907. +};
  4908. +
  4909. +struct vlynq_regs;
  4910. +struct vlynq_device {
  4911. + u32 id, dev_id;
  4912. + int local_irq;
  4913. + int remote_irq;
  4914. + enum vlynq_divisor divisor;
  4915. + u32 regs_start, regs_end;
  4916. + u32 mem_start, mem_end;
  4917. + u32 irq_start, irq_end;
  4918. + int irq;
  4919. + int enabled;
  4920. + struct vlynq_regs *local;
  4921. + struct vlynq_regs *remote;
  4922. + struct device dev;
  4923. +};
  4924. +
  4925. +struct vlynq_driver {
  4926. + char *name;
  4927. + struct vlynq_device_id *id_table;
  4928. + int (*probe)(struct vlynq_device *dev, struct vlynq_device_id *id);
  4929. + void (*remove)(struct vlynq_device *dev);
  4930. + struct device_driver driver;
  4931. +};
  4932. +
  4933. +struct plat_vlynq_ops {
  4934. + int (*on)(struct vlynq_device *dev);
  4935. + void (*off)(struct vlynq_device *dev);
  4936. +};
  4937. +
  4938. +static inline struct vlynq_driver *to_vlynq_driver(struct device_driver *drv)
  4939. +{
  4940. + return container_of(drv, struct vlynq_driver, driver);
  4941. +}
  4942. +
  4943. +static inline struct vlynq_device *to_vlynq_device(struct device *device)
  4944. +{
  4945. + return container_of(device, struct vlynq_device, dev);
  4946. +}
  4947. +
  4948. +extern struct bus_type vlynq_bus_type;
  4949. +
  4950. +extern int __vlynq_register_driver(struct vlynq_driver *driver,
  4951. + struct module *owner);
  4952. +
  4953. +static inline int vlynq_register_driver(struct vlynq_driver *driver)
  4954. +{
  4955. + return __vlynq_register_driver(driver, THIS_MODULE);
  4956. +}
  4957. +
  4958. +static inline void *vlynq_get_drvdata(struct vlynq_device *dev)
  4959. +{
  4960. + return dev_get_drvdata(&dev->dev);
  4961. +}
  4962. +
  4963. +static inline void vlynq_set_drvdata(struct vlynq_device *dev, void *data)
  4964. +{
  4965. + dev_set_drvdata(&dev->dev, data);
  4966. +}
  4967. +
  4968. +static inline u32 vlynq_mem_start(struct vlynq_device *dev)
  4969. +{
  4970. + return dev->mem_start;
  4971. +}
  4972. +
  4973. +static inline u32 vlynq_mem_end(struct vlynq_device *dev)
  4974. +{
  4975. + return dev->mem_end;
  4976. +}
  4977. +
  4978. +static inline u32 vlynq_mem_len(struct vlynq_device *dev)
  4979. +{
  4980. + return dev->mem_end - dev->mem_start + 1;
  4981. +}
  4982. +
  4983. +static inline int vlynq_virq_to_irq(struct vlynq_device *dev, int virq)
  4984. +{
  4985. + int irq = dev->irq_start + virq;
  4986. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4987. + return -EINVAL;
  4988. +
  4989. + return irq;
  4990. +}
  4991. +
  4992. +static inline int vlynq_irq_to_virq(struct vlynq_device *dev, int irq)
  4993. +{
  4994. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4995. + return -EINVAL;
  4996. +
  4997. + return irq - dev->irq_start;
  4998. +}
  4999. +
  5000. +extern void vlynq_unregister_driver(struct vlynq_driver *driver);
  5001. +extern int vlynq_enable_device(struct vlynq_device *dev);
  5002. +extern void vlynq_disable_device(struct vlynq_device *dev);
  5003. +extern int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  5004. + struct vlynq_mapping *mapping);
  5005. +extern int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  5006. + struct vlynq_mapping *mapping);
  5007. +extern int vlynq_set_local_irq(struct vlynq_device *dev, int virq);
  5008. +extern int vlynq_set_remote_irq(struct vlynq_device *dev, int virq);
  5009. +
  5010. +#endif /* __VLYNQ_H__ */
  5011. diff -Nur linux-2.6.29.1.orig/kernel/futex.c linux-2.6.29.1/kernel/futex.c
  5012. --- linux-2.6.29.1.orig/kernel/futex.c 2009-04-02 22:55:27.000000000 +0200
  5013. +++ linux-2.6.29.1/kernel/futex.c 2009-06-01 12:42:57.000000000 +0200
  5014. @@ -2027,9 +2027,11 @@
  5015. * implementation, the non functional ones will return
  5016. * -ENOSYS.
  5017. */
  5018. - curval = cmpxchg_futex_value_locked(NULL, 0, 0);
  5019. - if (curval == -EFAULT)
  5020. - futex_cmpxchg_enabled = 1;
  5021. + // exeption handler on ar7 is broken
  5022. + //curval = cmpxchg_futex_value_locked(NULL, 0, 0);
  5023. + //if (curval == -EFAULT)
  5024. + // futex_cmpxchg_enabled = 1;
  5025. + futex_cmpxchg_enabled = 0;
  5026. for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
  5027. plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
  5028. diff -Nur linux-2.6.29.1.orig/kernel/printk.c linux-2.6.29.1/kernel/printk.c
  5029. --- linux-2.6.29.1.orig/kernel/printk.c 2009-04-02 22:55:27.000000000 +0200
  5030. +++ linux-2.6.29.1/kernel/printk.c 2009-06-01 13:40:39.000000000 +0200
  5031. @@ -1253,6 +1253,7 @@
  5032. static int __init disable_boot_consoles(void)
  5033. {
  5034. + /* triggers reboot on ar7
  5035. if (console_drivers != NULL) {
  5036. if (console_drivers->flags & CON_BOOT) {
  5037. printk(KERN_INFO "turn off boot console %s%d\n",
  5038. @@ -1260,6 +1261,7 @@
  5039. return unregister_console(console_drivers);
  5040. }
  5041. }
  5042. + */
  5043. return 0;
  5044. }
  5045. late_initcall(disable_boot_consoles);