1
0

ar7.patch 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501
  1. diff -Nur linux-2.6.30.5.orig/arch/mips/ar7/clock.c linux-2.6.30.5/arch/mips/ar7/clock.c
  2. --- linux-2.6.30.5.orig/arch/mips/ar7/clock.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.30.5/arch/mips/ar7/clock.c 2009-08-26 20:05:03.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/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.30.5.orig/arch/mips/ar7/gpio.c linux-2.6.30.5/arch/mips/ar7/gpio.c
  489. --- linux-2.6.30.5.orig/arch/mips/ar7/gpio.c 1970-01-01 01:00:00.000000000 +0100
  490. +++ linux-2.6.30.5/arch/mips/ar7/gpio.c 2009-08-26 20:05:03.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/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.30.5.orig/arch/mips/ar7/irq.c linux-2.6.30.5/arch/mips/ar7/irq.c
  542. --- linux-2.6.30.5.orig/arch/mips/ar7/irq.c 1970-01-01 01:00:00.000000000 +0100
  543. +++ linux-2.6.30.5/arch/mips/ar7/irq.c 2009-08-26 20:05:03.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/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.30.5.orig/arch/mips/ar7/Makefile linux-2.6.30.5/arch/mips/ar7/Makefile
  729. --- linux-2.6.30.5.orig/arch/mips/ar7/Makefile 1970-01-01 01:00:00.000000000 +0100
  730. +++ linux-2.6.30.5/arch/mips/ar7/Makefile 2009-08-26 20:05:03.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.30.5.orig/arch/mips/ar7/memory.c linux-2.6.30.5/arch/mips/ar7/memory.c
  743. --- linux-2.6.30.5.orig/arch/mips/ar7/memory.c 1970-01-01 01:00:00.000000000 +0100
  744. +++ linux-2.6.30.5/arch/mips/ar7/memory.c 2009-08-26 20:05:03.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.30.5.orig/arch/mips/ar7/platform.c linux-2.6.30.5/arch/mips/ar7/platform.c
  821. --- linux-2.6.30.5.orig/arch/mips/ar7/platform.c 1970-01-01 01:00:00.000000000 +0100
  822. +++ linux-2.6.30.5/arch/mips/ar7/platform.c 2009-08-26 20:06:50.000000000 +0200
  823. @@ -0,0 +1,550 @@
  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. +#include <linux/phy.h>
  860. +#include <linux/phy_fixed.h>
  861. +
  862. +#include <asm/addrspace.h>
  863. +#include <asm/ar7/ar7.h>
  864. +#include <asm/ar7/gpio.h>
  865. +#include <asm/ar7/prom.h>
  866. +
  867. +struct plat_vlynq_data {
  868. + struct plat_vlynq_ops ops;
  869. + int gpio_bit;
  870. + int reset_bit;
  871. +};
  872. +
  873. +
  874. +static int vlynq_on(struct vlynq_device *dev)
  875. +{
  876. + int result;
  877. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  878. +
  879. + if ((result = gpio_request(pdata->gpio_bit, "vlynq")))
  880. + goto out;
  881. +
  882. + ar7_device_reset(pdata->reset_bit);
  883. +
  884. + if ((result = ar7_gpio_disable(pdata->gpio_bit)))
  885. + goto out_enabled;
  886. +
  887. + if ((result = ar7_gpio_enable(pdata->gpio_bit)))
  888. + goto out_enabled;
  889. +
  890. + if ((result = gpio_direction_output(pdata->gpio_bit, 0)))
  891. + goto out_gpio_enabled;
  892. +
  893. + mdelay(50);
  894. +
  895. + gpio_set_value(pdata->gpio_bit, 1);
  896. + mdelay(50);
  897. +
  898. + return 0;
  899. +
  900. +out_gpio_enabled:
  901. + ar7_gpio_disable(pdata->gpio_bit);
  902. +out_enabled:
  903. + ar7_device_disable(pdata->reset_bit);
  904. + gpio_free(pdata->gpio_bit);
  905. +out:
  906. + return result;
  907. +}
  908. +
  909. +static void vlynq_off(struct vlynq_device *dev)
  910. +{
  911. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  912. + ar7_gpio_disable(pdata->gpio_bit);
  913. + gpio_free(pdata->gpio_bit);
  914. + ar7_device_disable(pdata->reset_bit);
  915. +}
  916. +
  917. +static struct resource physmap_flash_resource = {
  918. + .name = "mem",
  919. + .flags = IORESOURCE_MEM,
  920. + .start = 0x10000000,
  921. + .end = 0x107fffff,
  922. +};
  923. +
  924. +static struct resource cpmac_low_res[] = {
  925. + {
  926. + .name = "regs",
  927. + .flags = IORESOURCE_MEM,
  928. + .start = AR7_REGS_MAC0,
  929. + .end = AR7_REGS_MAC0 + 0x7ff,
  930. + },
  931. + {
  932. + .name = "irq",
  933. + .flags = IORESOURCE_IRQ,
  934. + .start = 27,
  935. + .end = 27,
  936. + },
  937. +};
  938. +
  939. +static struct resource cpmac_high_res[] = {
  940. + {
  941. + .name = "regs",
  942. + .flags = IORESOURCE_MEM,
  943. + .start = AR7_REGS_MAC1,
  944. + .end = AR7_REGS_MAC1 + 0x7ff,
  945. + },
  946. + {
  947. + .name = "irq",
  948. + .flags = IORESOURCE_IRQ,
  949. + .start = 41,
  950. + .end = 41,
  951. + },
  952. +};
  953. +
  954. +static struct resource vlynq_low_res[] = {
  955. + {
  956. + .name = "regs",
  957. + .flags = IORESOURCE_MEM,
  958. + .start = AR7_REGS_VLYNQ0,
  959. + .end = AR7_REGS_VLYNQ0 + 0xff,
  960. + },
  961. + {
  962. + .name = "irq",
  963. + .flags = IORESOURCE_IRQ,
  964. + .start = 29,
  965. + .end = 29,
  966. + },
  967. + {
  968. + .name = "mem",
  969. + .flags = IORESOURCE_MEM,
  970. + .start = 0x04000000,
  971. + .end = 0x04ffffff,
  972. + },
  973. + {
  974. + .name = "devirq",
  975. + .flags = IORESOURCE_IRQ,
  976. + .start = 80,
  977. + .end = 111,
  978. + },
  979. +};
  980. +
  981. +static struct resource vlynq_high_res[] = {
  982. + {
  983. + .name = "regs",
  984. + .flags = IORESOURCE_MEM,
  985. + .start = AR7_REGS_VLYNQ1,
  986. + .end = AR7_REGS_VLYNQ1 + 0xff,
  987. + },
  988. + {
  989. + .name = "irq",
  990. + .flags = IORESOURCE_IRQ,
  991. + .start = 33,
  992. + .end = 33,
  993. + },
  994. + {
  995. + .name = "mem",
  996. + .flags = IORESOURCE_MEM,
  997. + .start = 0x0c000000,
  998. + .end = 0x0cffffff,
  999. + },
  1000. + {
  1001. + .name = "devirq",
  1002. + .flags = IORESOURCE_IRQ,
  1003. + .start = 112,
  1004. + .end = 143,
  1005. + },
  1006. +};
  1007. +
  1008. +static struct resource usb_res[] = {
  1009. + {
  1010. + .name = "regs",
  1011. + .flags = IORESOURCE_MEM,
  1012. + .start = AR7_REGS_USB,
  1013. + .end = AR7_REGS_USB + 0xff,
  1014. + },
  1015. + {
  1016. + .name = "irq",
  1017. + .flags = IORESOURCE_IRQ,
  1018. + .start = 32,
  1019. + .end = 32,
  1020. + },
  1021. + {
  1022. + .name = "mem",
  1023. + .flags = IORESOURCE_MEM,
  1024. + .start = 0x03400000,
  1025. + .end = 0x034001fff,
  1026. + },
  1027. +};
  1028. +
  1029. +static struct physmap_flash_data physmap_flash_data = {
  1030. + .width = 2,
  1031. +};
  1032. +
  1033. +/* lets assume this is suitable for both high and low cpmacs links */
  1034. +static struct fixed_phy_status fixed_phy_status __initdata = {
  1035. + .link = 1,
  1036. + .speed = 100,
  1037. + .duplex = 1,
  1038. +};
  1039. +
  1040. +static struct plat_cpmac_data cpmac_low_data = {
  1041. + .reset_bit = 17,
  1042. + .power_bit = 20,
  1043. + .phy_mask = 0x80000000,
  1044. +};
  1045. +
  1046. +static struct plat_cpmac_data cpmac_high_data = {
  1047. + .reset_bit = 21,
  1048. + .power_bit = 22,
  1049. + .phy_mask = 0x7fffffff,
  1050. +};
  1051. +
  1052. +static struct plat_vlynq_data vlynq_low_data = {
  1053. + .ops.on = vlynq_on,
  1054. + .ops.off = vlynq_off,
  1055. + .reset_bit = 20,
  1056. + .gpio_bit = 18,
  1057. +};
  1058. +
  1059. +static struct plat_vlynq_data vlynq_high_data = {
  1060. + .ops.on = vlynq_on,
  1061. + .ops.off = vlynq_off,
  1062. + .reset_bit = 16,
  1063. + .gpio_bit = 19,
  1064. +};
  1065. +
  1066. +static struct platform_device physmap_flash = {
  1067. + .id = 0,
  1068. + .name = "physmap-flash",
  1069. + .dev.platform_data = &physmap_flash_data,
  1070. + .resource = &physmap_flash_resource,
  1071. + .num_resources = 1,
  1072. +};
  1073. +
  1074. +static u64 cpmac_dma_mask = DMA_32BIT_MASK;
  1075. +static struct platform_device cpmac_low = {
  1076. + .id = 0,
  1077. + .name = "cpmac",
  1078. + .dev = {
  1079. + .dma_mask = &cpmac_dma_mask,
  1080. + .coherent_dma_mask = DMA_32BIT_MASK,
  1081. + .platform_data = &cpmac_low_data,
  1082. + },
  1083. + .resource = cpmac_low_res,
  1084. + .num_resources = ARRAY_SIZE(cpmac_low_res),
  1085. +};
  1086. +
  1087. +static struct platform_device cpmac_high = {
  1088. + .id = 1,
  1089. + .name = "cpmac",
  1090. + .dev = {
  1091. + .dma_mask = &cpmac_dma_mask,
  1092. + .coherent_dma_mask = DMA_32BIT_MASK,
  1093. + .platform_data = &cpmac_high_data,
  1094. + },
  1095. + .resource = cpmac_high_res,
  1096. + .num_resources = ARRAY_SIZE(cpmac_high_res),
  1097. +};
  1098. +
  1099. +static struct platform_device vlynq_low = {
  1100. + .id = 0,
  1101. + .name = "vlynq",
  1102. + .dev.platform_data = &vlynq_low_data,
  1103. + .resource = vlynq_low_res,
  1104. + .num_resources = ARRAY_SIZE(vlynq_low_res),
  1105. +};
  1106. +
  1107. +static struct platform_device vlynq_high = {
  1108. + .id = 1,
  1109. + .name = "vlynq",
  1110. + .dev.platform_data = &vlynq_high_data,
  1111. + .resource = vlynq_high_res,
  1112. + .num_resources = ARRAY_SIZE(vlynq_high_res),
  1113. +};
  1114. +
  1115. +
  1116. +/* This is proper way to define uart ports, but they are then detected
  1117. + * as xscale and, obviously, don't work...
  1118. + */
  1119. +#if !defined(CONFIG_SERIAL_8250)
  1120. +
  1121. +static struct plat_serial8250_port uart0_data = {
  1122. + .mapbase = AR7_REGS_UART0,
  1123. + .irq = AR7_IRQ_UART0,
  1124. + .regshift = 2,
  1125. + .iotype = UPIO_MEM,
  1126. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1127. +};
  1128. +
  1129. +static struct plat_serial8250_port uart1_data = {
  1130. + .mapbase = UR8_REGS_UART1,
  1131. + .irq = AR7_IRQ_UART1,
  1132. + .regshift = 2,
  1133. + .iotype = UPIO_MEM,
  1134. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1135. +};
  1136. +
  1137. +static struct plat_serial8250_port uart_data[] = {
  1138. + uart0_data,
  1139. + uart1_data,
  1140. + { .flags = 0 }
  1141. +};
  1142. +
  1143. +static struct plat_serial8250_port uart_data_single[] = {
  1144. + uart0_data,
  1145. + { .flags = 0 }
  1146. +};
  1147. +
  1148. +static struct platform_device uart = {
  1149. + .id = 0,
  1150. + .name = "serial8250",
  1151. + .dev.platform_data = uart_data_single
  1152. +};
  1153. +#endif
  1154. +
  1155. +static struct gpio_led default_leds[] = {
  1156. + { .name = "status", .gpio = 8, .active_low = 1, },
  1157. +};
  1158. +
  1159. +static struct gpio_led dsl502t_leds[] = {
  1160. + { .name = "status", .gpio = 9, .active_low = 1, },
  1161. + { .name = "ethernet", .gpio = 7, .active_low = 1, },
  1162. + { .name = "usb", .gpio = 12, .active_low = 1, },
  1163. +};
  1164. +
  1165. +static struct gpio_led dg834g_leds[] = {
  1166. + { .name = "ppp", .gpio = 6, .active_low = 1, },
  1167. + { .name = "status", .gpio = 7, .active_low = 1, },
  1168. + { .name = "adsl", .gpio = 8, .active_low = 1, },
  1169. + { .name = "wifi", .gpio = 12, .active_low = 1, },
  1170. + { .name = "power", .gpio = 14, .active_low = 1, .default_trigger = "default-on", },
  1171. +};
  1172. +
  1173. +static struct gpio_led fb_sl_leds[] = {
  1174. + { .name = "1", .gpio = 7, },
  1175. + { .name = "2", .gpio = 13, .active_low = 1, },
  1176. + { .name = "3", .gpio = 10, .active_low = 1, },
  1177. + { .name = "4", .gpio = 12, .active_low = 1, },
  1178. + { .name = "5", .gpio = 9, .active_low = 1, },
  1179. +};
  1180. +
  1181. +static struct gpio_led fb_fon_leds[] = {
  1182. + { .name = "1", .gpio = 8, },
  1183. + { .name = "2", .gpio = 3, .active_low = 1, },
  1184. + { .name = "3", .gpio = 5, },
  1185. + { .name = "4", .gpio = 4, .active_low = 1, },
  1186. + { .name = "5", .gpio = 11, .active_low = 1, },
  1187. +};
  1188. +
  1189. +static struct gpio_led_platform_data ar7_led_data;
  1190. +
  1191. +static struct platform_device ar7_gpio_leds = {
  1192. + .name = "leds-gpio",
  1193. + .id = -1,
  1194. + .dev = {
  1195. + .platform_data = &ar7_led_data,
  1196. + }
  1197. +};
  1198. +
  1199. +static struct platform_device ar7_udc = {
  1200. + .id = -1,
  1201. + .name = "ar7_udc",
  1202. + .resource = usb_res,
  1203. + .num_resources = ARRAY_SIZE(usb_res),
  1204. +};
  1205. +
  1206. +static inline unsigned char char2hex(char h)
  1207. +{
  1208. + switch (h) {
  1209. + case '0': case '1': case '2': case '3': case '4':
  1210. + case '5': case '6': case '7': case '8': case '9':
  1211. + return h - '0';
  1212. + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  1213. + return h - 'A' + 10;
  1214. + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  1215. + return h - 'a' + 10;
  1216. + default:
  1217. + return 0;
  1218. + }
  1219. +}
  1220. +
  1221. +static void cpmac_get_mac(int instance, unsigned char *dev_addr)
  1222. +{
  1223. + int i;
  1224. + char name[5], default_mac[] = "00:00:00:12:34:56", *mac;
  1225. +
  1226. + mac = NULL;
  1227. + sprintf(name, "mac%c", 'a' + instance);
  1228. + mac = prom_getenv(name);
  1229. + if (!mac) {
  1230. + sprintf(name, "mac%c", 'a');
  1231. + mac = prom_getenv(name);
  1232. + }
  1233. + if (!mac)
  1234. + mac = default_mac;
  1235. + for (i = 0; i < 6; i++)
  1236. + dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
  1237. + char2hex(mac[i * 3 + 1]);
  1238. +}
  1239. +
  1240. +static void __init detect_leds(void)
  1241. +{
  1242. + char *prId, *usb_prod;
  1243. +
  1244. + /* Default LEDs */
  1245. + ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
  1246. + ar7_led_data.leds = default_leds;
  1247. +
  1248. + /* FIXME: the whole thing is unreliable */
  1249. + prId = prom_getenv("ProductID");
  1250. + usb_prod = prom_getenv("usb_prod");
  1251. +
  1252. + /* If we can't get the product id from PROM, use the default LEDs */
  1253. + if (!prId)
  1254. + return;
  1255. +
  1256. + if (strstr(prId, "Fritz_Box_FON")) {
  1257. + ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
  1258. + ar7_led_data.leds = fb_fon_leds;
  1259. + } else if (strstr(prId, "Fritz_Box_")) {
  1260. + ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
  1261. + ar7_led_data.leds = fb_sl_leds;
  1262. + } else if ((!strcmp(prId, "AR7RD") || !strcmp(prId, "AR7DB")) && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
  1263. + ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
  1264. + ar7_led_data.leds = dsl502t_leds;
  1265. + } else if (strstr(prId, "DG834")) {
  1266. + ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
  1267. + ar7_led_data.leds = dg834g_leds;
  1268. + }
  1269. +}
  1270. +
  1271. +static int __init ar7_register_devices(void)
  1272. +{
  1273. + int res;
  1274. +
  1275. +#ifdef CONFIG_SERIAL_8250
  1276. +
  1277. + static struct uart_port uart_port[2];
  1278. +
  1279. + memset(uart_port, 0, sizeof(struct uart_port) * 2);
  1280. +
  1281. + uart_port[0].type = PORT_AR7;
  1282. + uart_port[0].line = 0;
  1283. + uart_port[0].irq = AR7_IRQ_UART0;
  1284. + uart_port[0].uartclk = ar7_bus_freq() / 2;
  1285. + uart_port[0].iotype = UPIO_MEM;
  1286. + uart_port[0].mapbase = AR7_REGS_UART0;
  1287. + uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
  1288. + uart_port[0].regshift = 2;
  1289. + res = early_serial_setup(&uart_port[0]);
  1290. + if (res)
  1291. + return res;
  1292. +
  1293. +
  1294. + /* Only TNETD73xx have a second serial port */
  1295. + if (ar7_has_second_uart()) {
  1296. + uart_port[1].type = PORT_AR7;
  1297. + uart_port[1].line = 1;
  1298. + uart_port[1].irq = AR7_IRQ_UART1;
  1299. + uart_port[1].uartclk = ar7_bus_freq() / 2;
  1300. + uart_port[1].iotype = UPIO_MEM;
  1301. + uart_port[1].mapbase = UR8_REGS_UART1;
  1302. + uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
  1303. + uart_port[1].regshift = 2;
  1304. + res = early_serial_setup(&uart_port[1]);
  1305. + if (res)
  1306. + return res;
  1307. + }
  1308. +
  1309. +#else /* !CONFIG_SERIAL_8250 */
  1310. +
  1311. + uart_data[0].uartclk = ar7_bus_freq() / 2;
  1312. + uart_data[1].uartclk = uart_data[0].uartclk;
  1313. +
  1314. + /* Only TNETD73xx have a second serial port */
  1315. + if (ar7_has_second_uart())
  1316. + uart.dev.platform_data = uart_data;
  1317. +
  1318. + res = platform_device_register(&uart);
  1319. + if (res)
  1320. + return res;
  1321. +
  1322. +#endif /* CONFIG_SERIAL_8250 */
  1323. +
  1324. + res = platform_device_register(&physmap_flash);
  1325. + if (res)
  1326. + return res;
  1327. +
  1328. + ar7_device_disable(vlynq_low_data.reset_bit);
  1329. + res = platform_device_register(&vlynq_low);
  1330. + if (res)
  1331. + return res;
  1332. +
  1333. + if (ar7_has_high_vlynq()) {
  1334. + ar7_device_disable(vlynq_high_data.reset_bit);
  1335. + res = platform_device_register(&vlynq_high);
  1336. + if (res)
  1337. + return res;
  1338. + }
  1339. +
  1340. + if (ar7_has_high_cpmac()) {
  1341. + res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
  1342. + if (res && res != -ENODEV)
  1343. + return res;
  1344. +
  1345. + cpmac_get_mac(1, cpmac_high_data.dev_addr);
  1346. + res = platform_device_register(&cpmac_high);
  1347. + if (res)
  1348. + return res;
  1349. + } else {
  1350. + cpmac_low_data.phy_mask = 0xffffffff;
  1351. + }
  1352. +
  1353. + res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
  1354. + if (res && res != -ENODEV)
  1355. + return res;
  1356. +
  1357. + cpmac_get_mac(0, cpmac_low_data.dev_addr);
  1358. + res = platform_device_register(&cpmac_low);
  1359. + if (res)
  1360. + return res;
  1361. +
  1362. + detect_leds();
  1363. + res = platform_device_register(&ar7_gpio_leds);
  1364. + if (res)
  1365. + return res;
  1366. +
  1367. + res = platform_device_register(&ar7_udc);
  1368. +
  1369. + return res;
  1370. +}
  1371. +
  1372. +
  1373. +arch_initcall(ar7_register_devices);
  1374. diff -Nur linux-2.6.30.5.orig/arch/mips/ar7/prom.c linux-2.6.30.5/arch/mips/ar7/prom.c
  1375. --- linux-2.6.30.5.orig/arch/mips/ar7/prom.c 1970-01-01 01:00:00.000000000 +0100
  1376. +++ linux-2.6.30.5/arch/mips/ar7/prom.c 2009-08-26 20:05:03.000000000 +0200
  1377. @@ -0,0 +1,321 @@
  1378. +/*
  1379. + * Carsten Langgaard, carstenl@mips.com
  1380. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1381. + *
  1382. + * This program is free software; you can distribute it and/or modify it
  1383. + * under the terms of the GNU General Public License (Version 2) as
  1384. + * published by the Free Software Foundation.
  1385. + *
  1386. + * This program is distributed in the hope it will be useful, but WITHOUT
  1387. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1388. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1389. + * for more details.
  1390. + *
  1391. + * You should have received a copy of the GNU General Public License along
  1392. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1393. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1394. + *
  1395. + * Putting things on the screen/serial line using YAMONs facilities.
  1396. + */
  1397. +#include <linux/init.h>
  1398. +#include <linux/kernel.h>
  1399. +#include <linux/serial_reg.h>
  1400. +#include <linux/spinlock.h>
  1401. +#include <linux/module.h>
  1402. +#include <linux/string.h>
  1403. +#include <linux/io.h>
  1404. +#include <asm/bootinfo.h>
  1405. +
  1406. +#include <asm/ar7/ar7.h>
  1407. +#include <asm/ar7/prom.h>
  1408. +
  1409. +#define MAX_ENTRY 80
  1410. +
  1411. +struct env_var {
  1412. + char *name;
  1413. + char *value;
  1414. +};
  1415. +
  1416. +static struct env_var adam2_env[MAX_ENTRY] = { { 0, }, };
  1417. +
  1418. +char *prom_getenv(const char *name)
  1419. +{
  1420. + int i;
  1421. + for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
  1422. + if (!strcmp(name, adam2_env[i].name))
  1423. + return adam2_env[i].value;
  1424. +
  1425. + return NULL;
  1426. +}
  1427. +EXPORT_SYMBOL(prom_getenv);
  1428. +
  1429. +char * __init prom_getcmdline(void)
  1430. +{
  1431. + return &(arcs_cmdline[0]);
  1432. +}
  1433. +
  1434. +static void __init ar7_init_cmdline(int argc, char *argv[])
  1435. +{
  1436. + char *cp;
  1437. + int actr;
  1438. +
  1439. + actr = 1; /* Always ignore argv[0] */
  1440. +
  1441. + cp = &(arcs_cmdline[0]);
  1442. + while (actr < argc) {
  1443. + strcpy(cp, argv[actr]);
  1444. + cp += strlen(argv[actr]);
  1445. + *cp++ = ' ';
  1446. + actr++;
  1447. + }
  1448. + if (cp != &(arcs_cmdline[0])) {
  1449. + /* get rid of trailing space */
  1450. + --cp;
  1451. + *cp = '\0';
  1452. + }
  1453. +}
  1454. +
  1455. +struct psbl_rec {
  1456. + u32 psbl_size;
  1457. + u32 env_base;
  1458. + u32 env_size;
  1459. + u32 ffs_base;
  1460. + u32 ffs_size;
  1461. +};
  1462. +
  1463. +static __initdata char psp_env_version[] = "TIENV0.8";
  1464. +
  1465. +struct psp_env_chunk {
  1466. + u8 num;
  1467. + u8 ctrl;
  1468. + u16 csum;
  1469. + u8 len;
  1470. + char data[11];
  1471. +} __attribute__ ((packed));
  1472. +
  1473. +struct psp_var_map_entry {
  1474. + u8 num;
  1475. + char *value;
  1476. +};
  1477. +
  1478. +static struct psp_var_map_entry psp_var_map[] = {
  1479. + { 1, "cpufrequency" },
  1480. + { 2, "memsize" },
  1481. + { 3, "flashsize" },
  1482. + { 4, "modetty0" },
  1483. + { 5, "modetty1" },
  1484. + { 8, "maca" },
  1485. + { 9, "macb" },
  1486. + { 28, "sysfrequency" },
  1487. + { 38, "mipsfrequency" },
  1488. +};
  1489. +
  1490. +/*
  1491. +
  1492. +Well-known variable (num is looked up in table above for matching variable name)
  1493. +Example: cpufrequency=211968000
  1494. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1495. +| 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
  1496. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1497. +
  1498. +Name=Value pair in a single chunk
  1499. +Example: NAME=VALUE
  1500. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1501. +| 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
  1502. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1503. +
  1504. +Name=Value pair in 2 chunks (len is the number of chunks)
  1505. +Example: bootloaderVersion=1.3.7.15
  1506. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1507. +| 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
  1508. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1509. +| _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
  1510. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1511. +
  1512. +Data is padded with 0xFF
  1513. +
  1514. +*/
  1515. +
  1516. +#define PSP_ENV_SIZE 4096
  1517. +
  1518. +static char psp_env_data[PSP_ENV_SIZE] = { 0, };
  1519. +
  1520. +static char * __init lookup_psp_var_map(u8 num)
  1521. +{
  1522. + int i;
  1523. +
  1524. + for (i = 0; i < sizeof(psp_var_map); i++)
  1525. + if (psp_var_map[i].num == num)
  1526. + return psp_var_map[i].value;
  1527. +
  1528. + return NULL;
  1529. +}
  1530. +
  1531. +static void __init add_adam2_var(char *name, char *value)
  1532. +{
  1533. + int i;
  1534. + for (i = 0; i < MAX_ENTRY; i++) {
  1535. + if (!adam2_env[i].name) {
  1536. + adam2_env[i].name = name;
  1537. + adam2_env[i].value = value;
  1538. + return;
  1539. + } else if (!strcmp(adam2_env[i].name, name)) {
  1540. + adam2_env[i].value = value;
  1541. + return;
  1542. + }
  1543. + }
  1544. +}
  1545. +
  1546. +static int __init parse_psp_env(void *psp_env_base)
  1547. +{
  1548. + int i, n;
  1549. + char *name, *value;
  1550. + struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
  1551. +
  1552. + memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
  1553. +
  1554. + i = 1;
  1555. + n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
  1556. + while (i < n) {
  1557. + if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
  1558. + break;
  1559. + value = chunks[i].data;
  1560. + if (chunks[i].num) {
  1561. + name = lookup_psp_var_map(chunks[i].num);
  1562. + } else {
  1563. + name = value;
  1564. + value += strlen(name) + 1;
  1565. + }
  1566. + if (name)
  1567. + add_adam2_var(name, value);
  1568. + i += chunks[i].len;
  1569. + }
  1570. + return 0;
  1571. +}
  1572. +
  1573. +static void __init ar7_init_env(struct env_var *env)
  1574. +{
  1575. + int i;
  1576. + struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
  1577. + void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
  1578. +
  1579. + if (strcmp(psp_env, psp_env_version) == 0) {
  1580. + parse_psp_env(psp_env);
  1581. + } else {
  1582. + for (i = 0; i < MAX_ENTRY; i++, env++)
  1583. + if (env->name)
  1584. + add_adam2_var(env->name, env->value);
  1585. + }
  1586. +}
  1587. +
  1588. +static void __init console_config(void)
  1589. +{
  1590. +#ifdef CONFIG_SERIAL_8250_CONSOLE
  1591. + char console_string[40];
  1592. + int baud = 0;
  1593. + char parity = '\0', bits = '\0', flow = '\0';
  1594. + char *s, *p;
  1595. +
  1596. + if (strstr(prom_getcmdline(), "console="))
  1597. + return;
  1598. +
  1599. +#ifdef CONFIG_KGDB
  1600. + if (!strstr(prom_getcmdline(), "nokgdb")) {
  1601. + strcat(prom_getcmdline(), " console=kgdb");
  1602. + kgdb_enabled = 1;
  1603. + return;
  1604. + }
  1605. +#endif
  1606. +
  1607. + if ((s = prom_getenv("modetty0"))) {
  1608. + baud = simple_strtoul(s, &p, 10);
  1609. + s = p;
  1610. + if (*s == ',') s++;
  1611. + if (*s) parity = *s++;
  1612. + if (*s == ',') s++;
  1613. + if (*s) bits = *s++;
  1614. + if (*s == ',') s++;
  1615. + if (*s == 'h') flow = 'r';
  1616. + }
  1617. +
  1618. + if (baud == 0)
  1619. + baud = 38400;
  1620. + if (parity != 'n' && parity != 'o' && parity != 'e')
  1621. + parity = 'n';
  1622. + if (bits != '7' && bits != '8')
  1623. + bits = '8';
  1624. +
  1625. + if (flow == 'r')
  1626. + sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  1627. + parity, bits, flow);
  1628. + else
  1629. + sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
  1630. + bits);
  1631. + strcat(prom_getcmdline(), console_string);
  1632. +#endif
  1633. +}
  1634. +
  1635. +void __init prom_init(void)
  1636. +{
  1637. + ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
  1638. + ar7_init_env((struct env_var *)fw_arg2);
  1639. + console_config();
  1640. +}
  1641. +
  1642. +#define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
  1643. +static inline unsigned int serial_in(int offset)
  1644. +{
  1645. + return readb((void *)PORT(offset));
  1646. +}
  1647. +
  1648. +static inline void serial_out(int offset, int value)
  1649. +{
  1650. + writeb(value, (void *)PORT(offset));
  1651. +}
  1652. +
  1653. +char prom_getchar(void)
  1654. +{
  1655. + while (!(serial_in(UART_LSR) & UART_LSR_DR));
  1656. + return serial_in(UART_RX);
  1657. +}
  1658. +
  1659. +int prom_putchar(char c)
  1660. +{
  1661. + while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0);
  1662. + serial_out(UART_TX, c);
  1663. + return 1;
  1664. +}
  1665. +
  1666. +/* from adm5120/prom.c */
  1667. +void prom_printf(const char *fmt, ...)
  1668. +{
  1669. + va_list args;
  1670. + int l;
  1671. + char *p, *buf_end;
  1672. + char buf[1024];
  1673. +
  1674. + va_start(args, fmt);
  1675. + l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
  1676. + va_end(args);
  1677. +
  1678. + buf_end = buf + l;
  1679. +
  1680. + for (p = buf; p < buf_end; p++) {
  1681. + /* Crude cr/nl handling is better than none */
  1682. + if (*p == '\n')
  1683. + prom_putchar('\r');
  1684. + prom_putchar(*p);
  1685. + }
  1686. +}
  1687. +
  1688. +#ifdef CONFIG_KGDB
  1689. +int putDebugChar(char c)
  1690. +{
  1691. + return prom_putchar(c);
  1692. +}
  1693. +
  1694. +char getDebugChar(void)
  1695. +{
  1696. + return prom_getchar();
  1697. +}
  1698. +#endif
  1699. diff -Nur linux-2.6.30.5.orig/arch/mips/ar7/setup.c linux-2.6.30.5/arch/mips/ar7/setup.c
  1700. --- linux-2.6.30.5.orig/arch/mips/ar7/setup.c 1970-01-01 01:00:00.000000000 +0100
  1701. +++ linux-2.6.30.5/arch/mips/ar7/setup.c 2009-08-26 20:05:03.000000000 +0200
  1702. @@ -0,0 +1,105 @@
  1703. +/*
  1704. + * Carsten Langgaard, carstenl@mips.com
  1705. + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  1706. + *
  1707. + * This program is free software; you can distribute it and/or modify it
  1708. + * under the terms of the GNU General Public License (Version 2) as
  1709. + * published by the Free Software Foundation.
  1710. + *
  1711. + * This program is distributed in the hope it will be useful, but WITHOUT
  1712. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1713. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1714. + * for more details.
  1715. + *
  1716. + * You should have received a copy of the GNU General Public License along
  1717. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1718. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1719. + */
  1720. +#include <linux/version.h>
  1721. +#include <linux/init.h>
  1722. +#include <linux/ioport.h>
  1723. +#include <linux/pm.h>
  1724. +
  1725. +#include <asm/reboot.h>
  1726. +#include <asm/time.h>
  1727. +#include <asm/ar7/ar7.h>
  1728. +#include <asm/ar7/prom.h>
  1729. +
  1730. +static void ar7_machine_restart(char *command);
  1731. +static void ar7_machine_halt(void);
  1732. +static void ar7_machine_power_off(void);
  1733. +
  1734. +static void ar7_machine_restart(char *command)
  1735. +{
  1736. + u32 *softres_reg = (u32 *)ioremap(AR7_REGS_RESET +
  1737. + AR7_RESET_SOFTWARE, 1);
  1738. + writel(1, softres_reg);
  1739. +}
  1740. +
  1741. +static void ar7_machine_halt(void)
  1742. +{
  1743. + while (1);
  1744. +}
  1745. +
  1746. +static void ar7_machine_power_off(void)
  1747. +{
  1748. + u32 *power_reg = (u32 *)ioremap(AR7_REGS_POWER, 1);
  1749. + u32 power_state = readl(power_reg) | (3 << 30);
  1750. + writel(power_state, power_reg);
  1751. + ar7_machine_halt();
  1752. +}
  1753. +
  1754. +const char *get_system_type(void)
  1755. +{
  1756. + u16 chip_id = ar7_chip_id();
  1757. + switch (chip_id) {
  1758. + case AR7_CHIP_7300:
  1759. + return "TI AR7 (TNETD7300)";
  1760. + case AR7_CHIP_7100:
  1761. + return "TI AR7 (TNETD7100)";
  1762. + case AR7_CHIP_7200:
  1763. + return "TI AR7 (TNETD7200)";
  1764. + default:
  1765. + return "TI AR7 (Unknown)";
  1766. + }
  1767. +}
  1768. +
  1769. +static int __init ar7_init_console(void)
  1770. +{
  1771. + return 0;
  1772. +}
  1773. +
  1774. +/*
  1775. + * Initializes basic routines and structures pointers, memory size (as
  1776. + * given by the bios and saves the command line.
  1777. + */
  1778. +
  1779. +extern void ar7_init_clocks(void);
  1780. +
  1781. +void __init plat_mem_setup(void)
  1782. +{
  1783. + unsigned long io_base;
  1784. +
  1785. + _machine_restart = ar7_machine_restart;
  1786. + _machine_halt = ar7_machine_halt;
  1787. + pm_power_off = ar7_machine_power_off;
  1788. + panic_timeout = 3;
  1789. +
  1790. + io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
  1791. + if (!io_base) panic("Can't remap IO base!\n");
  1792. + set_io_port_base(io_base);
  1793. +
  1794. + prom_meminit();
  1795. + ar7_init_clocks();
  1796. +
  1797. + ioport_resource.start = 0;
  1798. + ioport_resource.end = ~0;
  1799. + iomem_resource.start = 0;
  1800. + iomem_resource.end = ~0;
  1801. +
  1802. + printk(KERN_INFO "%s, ID: 0x%04x, Revision: 0x%02x\n",
  1803. + get_system_type(),
  1804. + ar7_chip_id(), ar7_chip_rev());
  1805. +}
  1806. +
  1807. +console_initcall(ar7_init_console);
  1808. diff -Nur linux-2.6.30.5.orig/arch/mips/ar7/time.c linux-2.6.30.5/arch/mips/ar7/time.c
  1809. --- linux-2.6.30.5.orig/arch/mips/ar7/time.c 1970-01-01 01:00:00.000000000 +0100
  1810. +++ linux-2.6.30.5/arch/mips/ar7/time.c 2009-08-26 20:05:03.000000000 +0200
  1811. @@ -0,0 +1,28 @@
  1812. +/*
  1813. + * Carsten Langgaard, carstenl@mips.com
  1814. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1815. + *
  1816. + * This program is free software; you can distribute it and/or modify it
  1817. + * under the terms of the GNU General Public License (Version 2) as
  1818. + * published by the Free Software Foundation.
  1819. + *
  1820. + * This program is distributed in the hope it will be useful, but WITHOUT
  1821. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1822. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1823. + * for more details.
  1824. + *
  1825. + * You should have received a copy of the GNU General Public License along
  1826. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1827. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1828. + *
  1829. + * Setting up the clock on the MIPS boards.
  1830. + */
  1831. +
  1832. +#include <linux/version.h>
  1833. +#include <asm/time.h>
  1834. +#include <asm/ar7/ar7.h>
  1835. +
  1836. +void __init plat_time_init(void)
  1837. +{
  1838. + mips_hpt_frequency = ar7_cpu_freq() / 2;
  1839. +}
  1840. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/ar7.h linux-2.6.30.5/arch/mips/include/asm/ar7/ar7.h
  1841. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/ar7.h 1970-01-01 01:00:00.000000000 +0100
  1842. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/ar7.h 2009-08-26 20:05:03.000000000 +0200
  1843. @@ -0,0 +1,170 @@
  1844. +/*
  1845. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  1846. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  1847. + *
  1848. + * This program is free software; you can redistribute it and/or modify
  1849. + * it under the terms of the GNU General Public License as published by
  1850. + * the Free Software Foundation; either version 2 of the License, or
  1851. + * (at your option) any later version.
  1852. + *
  1853. + * This program is distributed in the hope that it will be useful,
  1854. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1855. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1856. + * GNU General Public License for more details.
  1857. + *
  1858. + * You should have received a copy of the GNU General Public License
  1859. + * along with this program; if not, write to the Free Software
  1860. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  1861. + */
  1862. +
  1863. +#ifndef __AR7_H__
  1864. +#define __AR7_H__
  1865. +
  1866. +#include <linux/delay.h>
  1867. +#include <asm/addrspace.h>
  1868. +#include <linux/io.h>
  1869. +
  1870. +#define AR7_REGS_BASE 0x08610000
  1871. +
  1872. +#define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  1873. +#define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  1874. +/* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  1875. +#define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  1876. +#define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  1877. +#define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  1878. +#define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  1879. +#define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  1880. +#define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  1881. +#define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  1882. +#define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  1883. +#define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  1884. +#define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  1885. +
  1886. +#define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  1887. +#define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  1888. +#define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  1889. +
  1890. +#define AR7_RESET_PEREPHERIAL 0x0
  1891. +#define AR7_RESET_SOFTWARE 0x4
  1892. +#define AR7_RESET_STATUS 0x8
  1893. +
  1894. +#define AR7_RESET_BIT_CPMAC_LO 17
  1895. +#define AR7_RESET_BIT_CPMAC_HI 21
  1896. +#define AR7_RESET_BIT_MDIO 22
  1897. +#define AR7_RESET_BIT_EPHY 26
  1898. +
  1899. +/* GPIO control registers */
  1900. +#define AR7_GPIO_INPUT 0x0
  1901. +#define AR7_GPIO_OUTPUT 0x4
  1902. +#define AR7_GPIO_DIR 0x8
  1903. +#define AR7_GPIO_ENABLE 0xc
  1904. +
  1905. +#define AR7_CHIP_7100 0x18
  1906. +#define AR7_CHIP_7200 0x2b
  1907. +#define AR7_CHIP_7300 0x05
  1908. +
  1909. +/* Interrupts */
  1910. +#define AR7_IRQ_UART0 15
  1911. +#define AR7_IRQ_UART1 16
  1912. +
  1913. +/* Clocks */
  1914. +#define AR7_AFE_CLOCK 35328000
  1915. +#define AR7_REF_CLOCK 25000000
  1916. +#define AR7_XTAL_CLOCK 24000000
  1917. +
  1918. +struct plat_cpmac_data {
  1919. + int reset_bit;
  1920. + int power_bit;
  1921. + u32 phy_mask;
  1922. + char dev_addr[6];
  1923. +};
  1924. +
  1925. +struct plat_dsl_data {
  1926. + int reset_bit_dsl;
  1927. + int reset_bit_sar;
  1928. +};
  1929. +
  1930. +extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
  1931. +
  1932. +static inline u16 ar7_chip_id(void)
  1933. +{
  1934. + return readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff;
  1935. +}
  1936. +
  1937. +static inline u8 ar7_chip_rev(void)
  1938. +{
  1939. + return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) >> 16) & 0xff;
  1940. +}
  1941. +
  1942. +static inline int ar7_cpu_freq(void)
  1943. +{
  1944. + return ar7_cpu_clock;
  1945. +}
  1946. +
  1947. +static inline int ar7_bus_freq(void)
  1948. +{
  1949. + return ar7_bus_clock;
  1950. +}
  1951. +
  1952. +static inline int ar7_vbus_freq(void)
  1953. +{
  1954. + return ar7_bus_clock / 2;
  1955. +}
  1956. +#define ar7_cpmac_freq ar7_vbus_freq
  1957. +
  1958. +static inline int ar7_dsp_freq(void)
  1959. +{
  1960. + return ar7_dsp_clock;
  1961. +}
  1962. +
  1963. +static inline int ar7_has_high_cpmac(void)
  1964. +{
  1965. + u16 chip_id = ar7_chip_id();
  1966. + switch (chip_id) {
  1967. + case AR7_CHIP_7100:
  1968. + case AR7_CHIP_7200:
  1969. + return 0;
  1970. + default:
  1971. + return 1;
  1972. + }
  1973. +}
  1974. +#define ar7_has_high_vlynq ar7_has_high_cpmac
  1975. +#define ar7_has_second_uart ar7_has_high_cpmac
  1976. +
  1977. +static inline void ar7_device_enable(u32 bit)
  1978. +{
  1979. + void *reset_reg =
  1980. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  1981. + writel(readl(reset_reg) | (1 << bit), reset_reg);
  1982. + mdelay(20);
  1983. +}
  1984. +
  1985. +static inline void ar7_device_disable(u32 bit)
  1986. +{
  1987. + void *reset_reg =
  1988. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  1989. + writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  1990. + mdelay(20);
  1991. +}
  1992. +
  1993. +static inline void ar7_device_reset(u32 bit)
  1994. +{
  1995. + ar7_device_disable(bit);
  1996. + ar7_device_enable(bit);
  1997. +}
  1998. +
  1999. +static inline void ar7_device_on(u32 bit)
  2000. +{
  2001. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  2002. + writel(readl(power_reg) | (1 << bit), power_reg);
  2003. + mdelay(20);
  2004. +}
  2005. +
  2006. +static inline void ar7_device_off(u32 bit)
  2007. +{
  2008. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  2009. + writel(readl(power_reg) & ~(1 << bit), power_reg);
  2010. + mdelay(20);
  2011. +}
  2012. +
  2013. +#endif /* __AR7_H__ */
  2014. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/gpio.h linux-2.6.30.5/arch/mips/include/asm/ar7/gpio.h
  2015. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/gpio.h 1970-01-01 01:00:00.000000000 +0100
  2016. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/gpio.h 2009-08-26 20:05:03.000000000 +0200
  2017. @@ -0,0 +1,109 @@
  2018. +/*
  2019. + * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  2020. + *
  2021. + * This program is free software; you can redistribute it and/or modify
  2022. + * it under the terms of the GNU General Public License as published by
  2023. + * the Free Software Foundation; either version 2 of the License, or
  2024. + * (at your option) any later version.
  2025. + *
  2026. + * This program is distributed in the hope that it will be useful,
  2027. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2028. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2029. + * GNU General Public License for more details.
  2030. + *
  2031. + * You should have received a copy of the GNU General Public License
  2032. + * along with this program; if not, write to the Free Software
  2033. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2034. + */
  2035. +
  2036. +#ifndef __AR7_GPIO_H__
  2037. +#define __AR7_GPIO_H__
  2038. +#include <asm/ar7/ar7.h>
  2039. +
  2040. +#define AR7_GPIO_MAX 32
  2041. +
  2042. +extern int gpio_request(unsigned gpio, const char *label);
  2043. +extern void gpio_free(unsigned gpio);
  2044. +
  2045. +/* Common GPIO layer */
  2046. +static inline int gpio_get_value(unsigned gpio)
  2047. +{
  2048. + void __iomem *gpio_in =
  2049. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
  2050. +
  2051. + return readl(gpio_in) & (1 << gpio);
  2052. +}
  2053. +
  2054. +static inline void gpio_set_value(unsigned gpio, int value)
  2055. +{
  2056. + void __iomem *gpio_out =
  2057. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
  2058. + unsigned tmp;
  2059. +
  2060. + tmp = readl(gpio_out) & ~(1 << gpio);
  2061. + if (value)
  2062. + tmp |= 1 << gpio;
  2063. + writel(tmp, gpio_out);
  2064. +}
  2065. +
  2066. +static inline int gpio_direction_input(unsigned gpio)
  2067. +{
  2068. + void __iomem *gpio_dir =
  2069. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2070. +
  2071. + if (gpio >= AR7_GPIO_MAX)
  2072. + return -EINVAL;
  2073. +
  2074. + writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
  2075. +
  2076. + return 0;
  2077. +}
  2078. +
  2079. +static inline int gpio_direction_output(unsigned gpio, int value)
  2080. +{
  2081. + void __iomem *gpio_dir =
  2082. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2083. +
  2084. + if (gpio >= AR7_GPIO_MAX)
  2085. + return -EINVAL;
  2086. +
  2087. + gpio_set_value(gpio, value);
  2088. + writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
  2089. +
  2090. + return 0;
  2091. +}
  2092. +
  2093. +static inline int gpio_to_irq(unsigned gpio)
  2094. +{
  2095. + return -EINVAL;
  2096. +}
  2097. +
  2098. +static inline int irq_to_gpio(unsigned irq)
  2099. +{
  2100. + return -EINVAL;
  2101. +}
  2102. +
  2103. +/* Board specific GPIO functions */
  2104. +static inline int ar7_gpio_enable(unsigned gpio)
  2105. +{
  2106. + void __iomem *gpio_en =
  2107. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2108. +
  2109. + writel(readl(gpio_en) | (1 << gpio), gpio_en);
  2110. +
  2111. + return 0;
  2112. +}
  2113. +
  2114. +static inline int ar7_gpio_disable(unsigned gpio)
  2115. +{
  2116. + void __iomem *gpio_en =
  2117. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2118. +
  2119. + writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
  2120. +
  2121. + return 0;
  2122. +}
  2123. +
  2124. +#include <asm-generic/gpio.h>
  2125. +
  2126. +#endif
  2127. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/irq.h linux-2.6.30.5/arch/mips/include/asm/ar7/irq.h
  2128. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/irq.h 1970-01-01 01:00:00.000000000 +0100
  2129. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/irq.h 2009-08-26 20:05:03.000000000 +0200
  2130. @@ -0,0 +1,16 @@
  2131. +/*
  2132. + * This file is subject to the terms and conditions of the GNU General Public
  2133. + * License. See the file "COPYING" in the main directory of this archive
  2134. + * for more details.
  2135. + *
  2136. + * Shamelessly copied from asm-mips/mach-emma2rh/
  2137. + * Copyright (C) 2003 by Ralf Baechle
  2138. + */
  2139. +#ifndef __ASM_AR7_IRQ_H
  2140. +#define __ASM_AR7_IRQ_H
  2141. +
  2142. +#define NR_IRQS 256
  2143. +
  2144. +#include_next <irq.h>
  2145. +
  2146. +#endif /* __ASM_AR7_IRQ_H */
  2147. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/prom.h linux-2.6.30.5/arch/mips/include/asm/ar7/prom.h
  2148. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/prom.h 1970-01-01 01:00:00.000000000 +0100
  2149. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/prom.h 2009-08-26 20:05:03.000000000 +0200
  2150. @@ -0,0 +1,26 @@
  2151. +/*
  2152. + * Copyright (C) 2006, 2007 Florian Fainelli <florian@openwrt.org>
  2153. + *
  2154. + * This program is free software; you can redistribute it and/or modify
  2155. + * it under the terms of the GNU General Public License as published by
  2156. + * the Free Software Foundation; either version 2 of the License, or
  2157. + * (at your option) any later version.
  2158. + *
  2159. + * This program is distributed in the hope that it will be useful,
  2160. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2161. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2162. + * GNU General Public License for more details.
  2163. + *
  2164. + * You should have received a copy of the GNU General Public License
  2165. + * along with this program; if not, write to the Free Software
  2166. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2167. + */
  2168. +
  2169. +#ifndef __PROM_H__
  2170. +#define __PROM_H__
  2171. +
  2172. +extern char *prom_getenv(const char *name);
  2173. +extern void prom_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
  2174. +extern void prom_meminit(void);
  2175. +
  2176. +#endif /* __PROM_H__ */
  2177. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/spaces.h linux-2.6.30.5/arch/mips/include/asm/ar7/spaces.h
  2178. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/spaces.h 1970-01-01 01:00:00.000000000 +0100
  2179. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/spaces.h 2009-08-26 20:05:03.000000000 +0200
  2180. @@ -0,0 +1,32 @@
  2181. +/*
  2182. + * This file is subject to the terms and conditions of the GNU General Public
  2183. + * License. See the file "COPYING" in the main directory of this archive
  2184. + * for more details.
  2185. + *
  2186. + * Copyright (C) 1994 - 1999, 2000, 03, 04 Ralf Baechle
  2187. + * Copyright (C) 2000, 2002 Maciej W. Rozycki
  2188. + * Copyright (C) 1990, 1999, 2000 Silicon Graphics, Inc.
  2189. + */
  2190. +#ifndef _ASM_AR7_SPACES_H
  2191. +#define _ASM_AR7_SPACES_H
  2192. +
  2193. +#define CAC_BASE 0x80000000
  2194. +#define IO_BASE 0xa0000000
  2195. +#define UNCAC_BASE 0xa0000000
  2196. +#define MAP_BASE 0xc0000000
  2197. +
  2198. +/*
  2199. + * This handles the memory map.
  2200. + * We handle pages at KSEG0 for kernels with 32 bit address space.
  2201. + */
  2202. +#define PAGE_OFFSET 0x94000000UL
  2203. +#define PHYS_OFFSET 0x14000000UL
  2204. +
  2205. +/*
  2206. + * Memory above this physical address will be considered highmem.
  2207. + */
  2208. +#ifndef HIGHMEM_START
  2209. +#define HIGHMEM_START 0x40000000UL
  2210. +#endif
  2211. +
  2212. +#endif /* __ASM_AR7_SPACES_H */
  2213. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/ar7/war.h linux-2.6.30.5/arch/mips/include/asm/ar7/war.h
  2214. --- linux-2.6.30.5.orig/arch/mips/include/asm/ar7/war.h 1970-01-01 01:00:00.000000000 +0100
  2215. +++ linux-2.6.30.5/arch/mips/include/asm/ar7/war.h 2009-08-26 20:05:03.000000000 +0200
  2216. @@ -0,0 +1,25 @@
  2217. +/*
  2218. + * This file is subject to the terms and conditions of the GNU General Public
  2219. + * License. See the file "COPYING" in the main directory of this archive
  2220. + * for more details.
  2221. + *
  2222. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  2223. + */
  2224. +#ifndef __ASM_MIPS_MACH_BCM947XX_WAR_H
  2225. +#define __ASM_MIPS_MACH_BCM947XX_WAR_H
  2226. +
  2227. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  2228. +#define R4600_V1_HIT_CACHEOP_WAR 0
  2229. +#define R4600_V2_HIT_CACHEOP_WAR 0
  2230. +#define R5432_CP0_INTERRUPT_WAR 0
  2231. +#define BCM1250_M3_WAR 0
  2232. +#define SIBYTE_1956_WAR 0
  2233. +#define MIPS4K_ICACHE_REFILL_WAR 0
  2234. +#define MIPS_CACHE_SYNC_WAR 0
  2235. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  2236. +#define RM9000_CDEX_SMP_WAR 0
  2237. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  2238. +#define R10000_LLSC_WAR 0
  2239. +#define MIPS34K_MISSED_ITLB_WAR 0
  2240. +
  2241. +#endif /* __ASM_MIPS_MACH_BCM947XX_WAR_H */
  2242. diff -Nur linux-2.6.30.5.orig/arch/mips/include/asm/page.h linux-2.6.30.5/arch/mips/include/asm/page.h
  2243. --- linux-2.6.30.5.orig/arch/mips/include/asm/page.h 2009-08-16 23:19:38.000000000 +0200
  2244. +++ linux-2.6.30.5/arch/mips/include/asm/page.h 2009-08-26 20:05:14.000000000 +0200
  2245. @@ -185,8 +185,10 @@
  2246. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  2247. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  2248. -#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
  2249. -#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
  2250. +#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
  2251. + PHYS_OFFSET)
  2252. +#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
  2253. + PHYS_OFFSET)
  2254. #include <asm-generic/memory_model.h>
  2255. #include <asm-generic/page.h>
  2256. diff -Nur linux-2.6.30.5.orig/arch/mips/Kconfig linux-2.6.30.5/arch/mips/Kconfig
  2257. --- linux-2.6.30.5.orig/arch/mips/Kconfig 2009-08-16 23:19:38.000000000 +0200
  2258. +++ linux-2.6.30.5/arch/mips/Kconfig 2009-08-27 21:44:10.000000000 +0200
  2259. @@ -19,6 +19,23 @@
  2260. prompt "System type"
  2261. default SGI_IP22
  2262. +config AR7
  2263. + bool "Texas Instruments AR7"
  2264. + select BOOT_ELF32
  2265. + select DMA_NONCOHERENT
  2266. + select CEVT_R4K
  2267. + select CSRC_R4K
  2268. + select IRQ_CPU
  2269. + select SWAP_IO_SPACE
  2270. + select SYS_HAS_CPU_MIPS32_R1
  2271. + select SYS_HAS_EARLY_PRINTK
  2272. + select SYS_SUPPORTS_32BIT_KERNEL
  2273. + select SYS_SUPPORTS_KGDB
  2274. + select SYS_SUPPORTS_LITTLE_ENDIAN
  2275. + select SYS_SUPPORTS_BIG_ENDIAN
  2276. + select GENERIC_GPIO
  2277. + select GENERIC_HARDIRQS_NO__DO_IRQ
  2278. +
  2279. config MACH_ALCHEMY
  2280. bool "Alchemy processor based machines"
  2281. diff -Nur linux-2.6.30.5.orig/arch/mips/kernel/traps.c linux-2.6.30.5/arch/mips/kernel/traps.c
  2282. --- linux-2.6.30.5.orig/arch/mips/kernel/traps.c 2009-08-16 23:19:38.000000000 +0200
  2283. +++ linux-2.6.30.5/arch/mips/kernel/traps.c 2009-08-26 20:05:14.000000000 +0200
  2284. @@ -1256,9 +1256,22 @@
  2285. exception_handlers[n] = handler;
  2286. if (n == 0 && cpu_has_divec) {
  2287. - *(u32 *)(ebase + 0x200) = 0x08000000 |
  2288. - (0x03ffffff & (handler >> 2));
  2289. - local_flush_icache_range(ebase + 0x200, ebase + 0x204);
  2290. + if ((handler ^ (ebase + 4)) & 0xfc000000) {
  2291. + /* lui k0, 0x0000 */
  2292. + *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
  2293. + /* ori k0, 0x0000 */
  2294. + *(u32 *)(ebase + 0x204) =
  2295. + 0x375a0000 | (handler & 0xffff);
  2296. + /* jr k0 */
  2297. + *(u32 *)(ebase + 0x208) = 0x03400008;
  2298. + /* nop */
  2299. + *(u32 *)(ebase + 0x20C) = 0x00000000;
  2300. + flush_icache_range(ebase + 0x200, ebase + 0x210);
  2301. + } else {
  2302. + *(u32 *)(ebase + 0x200) =
  2303. + 0x08000000 | (0x03ffffff & (handler >> 2));
  2304. + flush_icache_range(ebase + 0x200, ebase + 0x204);
  2305. + }
  2306. }
  2307. return (void *)old_handler;
  2308. }
  2309. diff -Nur linux-2.6.30.5.orig/arch/mips/Makefile linux-2.6.30.5/arch/mips/Makefile
  2310. --- linux-2.6.30.5.orig/arch/mips/Makefile 2009-08-16 23:19:38.000000000 +0200
  2311. +++ linux-2.6.30.5/arch/mips/Makefile 2009-08-26 20:05:14.000000000 +0200
  2312. @@ -174,6 +174,13 @@
  2313. #
  2314. #
  2315. +# Texas Instruments AR7
  2316. +#
  2317. +core-$(CONFIG_AR7) += arch/mips/ar7/
  2318. +cflags-$(CONFIG_AR7) += -Iinclude/asm-mips/ar7
  2319. +load-$(CONFIG_AR7) += 0xffffffff94100000
  2320. +
  2321. +#
  2322. # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
  2323. #
  2324. core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
  2325. diff -Nur linux-2.6.30.5.orig/drivers/char/ar7_gpio.c linux-2.6.30.5/drivers/char/ar7_gpio.c
  2326. --- linux-2.6.30.5.orig/drivers/char/ar7_gpio.c 1970-01-01 01:00:00.000000000 +0100
  2327. +++ linux-2.6.30.5/drivers/char/ar7_gpio.c 2009-08-26 20:05:03.000000000 +0200
  2328. @@ -0,0 +1,158 @@
  2329. +/*
  2330. + * Copyright (C) 2007 Nicolas Thill <nico@openwrt.org>
  2331. + *
  2332. + * This program is free software; you can redistribute it and/or modify
  2333. + * it under the terms of the GNU General Public License as published by
  2334. + * the Free Software Foundation; either version 2 of the License, or
  2335. + * (at your option) any later version.
  2336. + *
  2337. + * This program is distributed in the hope that it will be useful,
  2338. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2339. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2340. + * GNU General Public License for more details.
  2341. + *
  2342. + * You should have received a copy of the GNU General Public License
  2343. + * along with this program; if not, write to the Free Software
  2344. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2345. + */
  2346. +
  2347. +#include <linux/device.h>
  2348. +#include <linux/fs.h>
  2349. +#include <linux/module.h>
  2350. +#include <linux/errno.h>
  2351. +#include <linux/kernel.h>
  2352. +#include <linux/init.h>
  2353. +#include <linux/platform_device.h>
  2354. +#include <linux/uaccess.h>
  2355. +#include <linux/io.h>
  2356. +#include <linux/types.h>
  2357. +#include <linux/cdev.h>
  2358. +#include <gpio.h>
  2359. +
  2360. +#define DRVNAME "ar7_gpio"
  2361. +#define LONGNAME "TI AR7 GPIOs Driver"
  2362. +
  2363. +MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
  2364. +MODULE_DESCRIPTION(LONGNAME);
  2365. +MODULE_LICENSE("GPL");
  2366. +
  2367. +static int ar7_gpio_major;
  2368. +
  2369. +static ssize_t ar7_gpio_write(struct file *file, const char __user *buf,
  2370. + size_t len, loff_t *ppos)
  2371. +{
  2372. + int pin = iminor(file->f_dentry->d_inode);
  2373. + size_t i;
  2374. +
  2375. + for (i = 0; i < len; ++i) {
  2376. + char c;
  2377. + if (get_user(c, buf + i))
  2378. + return -EFAULT;
  2379. + switch (c) {
  2380. + case '0':
  2381. + gpio_set_value(pin, 0);
  2382. + break;
  2383. + case '1':
  2384. + gpio_set_value(pin, 1);
  2385. + break;
  2386. + case 'd':
  2387. + case 'D':
  2388. + ar7_gpio_disable(pin);
  2389. + break;
  2390. + case 'e':
  2391. + case 'E':
  2392. + ar7_gpio_enable(pin);
  2393. + break;
  2394. + case 'i':
  2395. + case 'I':
  2396. + case '<':
  2397. + gpio_direction_input(pin);
  2398. + break;
  2399. + case 'o':
  2400. + case 'O':
  2401. + case '>':
  2402. + gpio_direction_output(pin, 0);
  2403. + break;
  2404. + default:
  2405. + return -EINVAL;
  2406. + }
  2407. + }
  2408. +
  2409. + return len;
  2410. +}
  2411. +
  2412. +static ssize_t ar7_gpio_read(struct file *file, char __user *buf,
  2413. + size_t len, loff_t *ppos)
  2414. +{
  2415. + int pin = iminor(file->f_dentry->d_inode);
  2416. + int value;
  2417. +
  2418. + value = gpio_get_value(pin);
  2419. + if (put_user(value ? '1' : '0', buf))
  2420. + return -EFAULT;
  2421. +
  2422. + return 1;
  2423. +}
  2424. +
  2425. +static int ar7_gpio_open(struct inode *inode, struct file *file)
  2426. +{
  2427. + int m = iminor(inode);
  2428. +
  2429. + if (m >= AR7_GPIO_MAX)
  2430. + return -EINVAL;
  2431. +
  2432. + return nonseekable_open(inode, file);
  2433. +}
  2434. +
  2435. +static int ar7_gpio_release(struct inode *inode, struct file *file)
  2436. +{
  2437. + return 0;
  2438. +}
  2439. +
  2440. +static const struct file_operations ar7_gpio_fops = {
  2441. + .owner = THIS_MODULE,
  2442. + .write = ar7_gpio_write,
  2443. + .read = ar7_gpio_read,
  2444. + .open = ar7_gpio_open,
  2445. + .release = ar7_gpio_release,
  2446. + .llseek = no_llseek,
  2447. +};
  2448. +
  2449. +static struct platform_device *ar7_gpio_device;
  2450. +
  2451. +static int __init ar7_gpio_init(void)
  2452. +{
  2453. + int rc;
  2454. +
  2455. + ar7_gpio_device = platform_device_alloc(DRVNAME, -1);
  2456. + if (!ar7_gpio_device)
  2457. + return -ENOMEM;
  2458. +
  2459. + rc = platform_device_add(ar7_gpio_device);
  2460. + if (rc < 0)
  2461. + goto out_put;
  2462. +
  2463. + rc = register_chrdev(ar7_gpio_major, DRVNAME, &ar7_gpio_fops);
  2464. + if (rc < 0)
  2465. + goto out_put;
  2466. +
  2467. + ar7_gpio_major = rc;
  2468. +
  2469. + rc = 0;
  2470. +
  2471. + goto out;
  2472. +
  2473. +out_put:
  2474. + platform_device_put(ar7_gpio_device);
  2475. +out:
  2476. + return rc;
  2477. +}
  2478. +
  2479. +static void __exit ar7_gpio_exit(void)
  2480. +{
  2481. + unregister_chrdev(ar7_gpio_major, DRVNAME);
  2482. + platform_device_unregister(ar7_gpio_device);
  2483. +}
  2484. +
  2485. +module_init(ar7_gpio_init);
  2486. +module_exit(ar7_gpio_exit);
  2487. diff -Nur linux-2.6.30.5.orig/drivers/char/Kconfig linux-2.6.30.5/drivers/char/Kconfig
  2488. --- linux-2.6.30.5.orig/drivers/char/Kconfig 2009-08-16 23:19:38.000000000 +0200
  2489. +++ linux-2.6.30.5/drivers/char/Kconfig 2009-08-26 20:05:23.000000000 +0200
  2490. @@ -974,6 +974,15 @@
  2491. To compile this driver as a module, choose M here: the
  2492. module will be called mwave.
  2493. +config AR7_GPIO
  2494. + tristate "TI AR7 GPIO Support"
  2495. + depends on AR7
  2496. + help
  2497. + Give userspace access to the GPIO pins on the Texas Instruments AR7
  2498. + processors.
  2499. +
  2500. + If compiled as a module, it will be called ar7_gpio.
  2501. +
  2502. config SCx200_GPIO
  2503. tristate "NatSemi SCx200 GPIO Support"
  2504. depends on SCx200
  2505. diff -Nur linux-2.6.30.5.orig/drivers/char/Makefile linux-2.6.30.5/drivers/char/Makefile
  2506. --- linux-2.6.30.5.orig/drivers/char/Makefile 2009-08-16 23:19:38.000000000 +0200
  2507. +++ linux-2.6.30.5/drivers/char/Makefile 2009-08-26 20:05:23.000000000 +0200
  2508. @@ -90,6 +90,7 @@
  2509. obj-$(CONFIG_PPDEV) += ppdev.o
  2510. obj-$(CONFIG_NWBUTTON) += nwbutton.o
  2511. obj-$(CONFIG_NWFLASH) += nwflash.o
  2512. +obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
  2513. obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
  2514. obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
  2515. obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
  2516. diff -Nur linux-2.6.30.5.orig/drivers/char/watchdog/ar7_wdt.c linux-2.6.30.5/drivers/char/watchdog/ar7_wdt.c
  2517. --- linux-2.6.30.5.orig/drivers/char/watchdog/ar7_wdt.c 1970-01-01 01:00:00.000000000 +0100
  2518. +++ linux-2.6.30.5/drivers/char/watchdog/ar7_wdt.c 2009-08-26 20:05:03.000000000 +0200
  2519. @@ -0,0 +1,349 @@
  2520. +/*
  2521. + * drivers/watchdog/ar7_wdt.c
  2522. + *
  2523. + * Copyright (C) 2007 Nicolas Thill <nico@openwrt.org>
  2524. + * Copyright (c) 2005 Enrik Berkhan <Enrik.Berkhan@akk.org>
  2525. + *
  2526. + * Some code taken from:
  2527. + * National Semiconductor SCx200 Watchdog support
  2528. + * Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
  2529. + *
  2530. + * This program is free software; you can redistribute it and/or modify
  2531. + * it under the terms of the GNU General Public License as published by
  2532. + * the Free Software Foundation; either version 2 of the License, or
  2533. + * (at your option) any later version.
  2534. + *
  2535. + * This program is distributed in the hope that it will be useful,
  2536. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2537. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2538. + * GNU General Public License for more details.
  2539. + *
  2540. + * You should have received a copy of the GNU General Public License
  2541. + * along with this program; if not, write to the Free Software
  2542. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2543. + */
  2544. +
  2545. +#include <linux/module.h>
  2546. +#include <linux/moduleparam.h>
  2547. +#include <linux/errno.h>
  2548. +#include <linux/init.h>
  2549. +#include <linux/miscdevice.h>
  2550. +#include <linux/watchdog.h>
  2551. +#include <linux/notifier.h>
  2552. +#include <linux/reboot.h>
  2553. +#include <linux/fs.h>
  2554. +#include <linux/ioport.h>
  2555. +#include <linux/io.h>
  2556. +#include <linux/uaccess.h>
  2557. +
  2558. +#include <asm/addrspace.h>
  2559. +#include <asm/ar7/ar7.h>
  2560. +
  2561. +#define DRVNAME "ar7_wdt"
  2562. +#define LONGNAME "TI AR7 Watchdog Timer"
  2563. +
  2564. +MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
  2565. +MODULE_DESCRIPTION(LONGNAME);
  2566. +MODULE_LICENSE("GPL");
  2567. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  2568. +
  2569. +static int margin = 60;
  2570. +module_param(margin, int, 0);
  2571. +MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
  2572. +
  2573. +static int nowayout = WATCHDOG_NOWAYOUT;
  2574. +module_param(nowayout, int, 0);
  2575. +MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
  2576. +
  2577. +#define READ_REG(x) readl((void __iomem *)&(x))
  2578. +#define WRITE_REG(x, v) writel((v), (void __iomem *)&(x))
  2579. +
  2580. +struct ar7_wdt {
  2581. + u32 kick_lock;
  2582. + u32 kick;
  2583. + u32 change_lock;
  2584. + u32 change;
  2585. + u32 disable_lock;
  2586. + u32 disable;
  2587. + u32 prescale_lock;
  2588. + u32 prescale;
  2589. +};
  2590. +
  2591. +static struct semaphore open_semaphore;
  2592. +static unsigned expect_close;
  2593. +
  2594. +/* XXX currently fixed, allows max margin ~68.72 secs */
  2595. +#define prescale_value 0xffff
  2596. +
  2597. +/* Offset of the WDT registers */
  2598. +static unsigned long ar7_regs_wdt;
  2599. +/* Pointer to the remapped WDT IO space */
  2600. +static struct ar7_wdt *ar7_wdt;
  2601. +static void ar7_wdt_get_regs(void)
  2602. +{
  2603. + u16 chip_id = ar7_chip_id();
  2604. + switch (chip_id) {
  2605. + case AR7_CHIP_7100:
  2606. + case AR7_CHIP_7200:
  2607. + ar7_regs_wdt = AR7_REGS_WDT;
  2608. + break;
  2609. + default:
  2610. + ar7_regs_wdt = UR8_REGS_WDT;
  2611. + break;
  2612. + }
  2613. +}
  2614. +
  2615. +
  2616. +static void ar7_wdt_kick(u32 value)
  2617. +{
  2618. + WRITE_REG(ar7_wdt->kick_lock, 0x5555);
  2619. + if ((READ_REG(ar7_wdt->kick_lock) & 3) == 1) {
  2620. + WRITE_REG(ar7_wdt->kick_lock, 0xaaaa);
  2621. + if ((READ_REG(ar7_wdt->kick_lock) & 3) == 3) {
  2622. + WRITE_REG(ar7_wdt->kick, value);
  2623. + return;
  2624. + }
  2625. + }
  2626. + printk(KERN_ERR DRVNAME ": failed to unlock WDT kick reg\n");
  2627. +}
  2628. +
  2629. +static void ar7_wdt_prescale(u32 value)
  2630. +{
  2631. + WRITE_REG(ar7_wdt->prescale_lock, 0x5a5a);
  2632. + if ((READ_REG(ar7_wdt->prescale_lock) & 3) == 1) {
  2633. + WRITE_REG(ar7_wdt->prescale_lock, 0xa5a5);
  2634. + if ((READ_REG(ar7_wdt->prescale_lock) & 3) == 3) {
  2635. + WRITE_REG(ar7_wdt->prescale, value);
  2636. + return;
  2637. + }
  2638. + }
  2639. + printk(KERN_ERR DRVNAME ": failed to unlock WDT prescale reg\n");
  2640. +}
  2641. +
  2642. +static void ar7_wdt_change(u32 value)
  2643. +{
  2644. + WRITE_REG(ar7_wdt->change_lock, 0x6666);
  2645. + if ((READ_REG(ar7_wdt->change_lock) & 3) == 1) {
  2646. + WRITE_REG(ar7_wdt->change_lock, 0xbbbb);
  2647. + if ((READ_REG(ar7_wdt->change_lock) & 3) == 3) {
  2648. + WRITE_REG(ar7_wdt->change, value);
  2649. + return;
  2650. + }
  2651. + }
  2652. + printk(KERN_ERR DRVNAME ": failed to unlock WDT change reg\n");
  2653. +}
  2654. +
  2655. +static void ar7_wdt_disable(u32 value)
  2656. +{
  2657. + WRITE_REG(ar7_wdt->disable_lock, 0x7777);
  2658. + if ((READ_REG(ar7_wdt->disable_lock) & 3) == 1) {
  2659. + WRITE_REG(ar7_wdt->disable_lock, 0xcccc);
  2660. + if ((READ_REG(ar7_wdt->disable_lock) & 3) == 2) {
  2661. + WRITE_REG(ar7_wdt->disable_lock, 0xdddd);
  2662. + if ((READ_REG(ar7_wdt->disable_lock) & 3) == 3) {
  2663. + WRITE_REG(ar7_wdt->disable, value);
  2664. + return;
  2665. + }
  2666. + }
  2667. + }
  2668. + printk(KERN_ERR DRVNAME ": failed to unlock WDT disable reg\n");
  2669. +}
  2670. +
  2671. +static void ar7_wdt_update_margin(int new_margin)
  2672. +{
  2673. + u32 change;
  2674. +
  2675. + change = new_margin * (ar7_vbus_freq() / prescale_value);
  2676. + if (change < 1) change = 1;
  2677. + if (change > 0xffff) change = 0xffff;
  2678. + ar7_wdt_change(change);
  2679. + margin = change * prescale_value / ar7_vbus_freq();
  2680. + printk(KERN_INFO DRVNAME
  2681. + ": timer margin %d seconds (prescale %d, change %d, freq %d)\n",
  2682. + margin, prescale_value, change, ar7_vbus_freq());
  2683. +}
  2684. +
  2685. +static void ar7_wdt_enable_wdt(void)
  2686. +{
  2687. + printk(KERN_DEBUG DRVNAME ": enabling watchdog timer\n");
  2688. + ar7_wdt_disable(1);
  2689. + ar7_wdt_kick(1);
  2690. +}
  2691. +
  2692. +static void ar7_wdt_disable_wdt(void)
  2693. +{
  2694. + printk(KERN_DEBUG DRVNAME ": disabling watchdog timer\n");
  2695. + ar7_wdt_disable(0);
  2696. +}
  2697. +
  2698. +static int ar7_wdt_open(struct inode *inode, struct file *file)
  2699. +{
  2700. + /* only allow one at a time */
  2701. + if (down_trylock(&open_semaphore))
  2702. + return -EBUSY;
  2703. + ar7_wdt_enable_wdt();
  2704. + expect_close = 0;
  2705. +
  2706. + return nonseekable_open(inode, file);
  2707. +}
  2708. +
  2709. +static int ar7_wdt_release(struct inode *inode, struct file *file)
  2710. +{
  2711. + if (!expect_close)
  2712. + printk(KERN_WARNING DRVNAME
  2713. + ": watchdog device closed unexpectedly,"
  2714. + "will not disable the watchdog timer\n");
  2715. + else if (!nowayout)
  2716. + ar7_wdt_disable_wdt();
  2717. +
  2718. + up(&open_semaphore);
  2719. +
  2720. + return 0;
  2721. +}
  2722. +
  2723. +static int ar7_wdt_notify_sys(struct notifier_block *this,
  2724. + unsigned long code, void *unused)
  2725. +{
  2726. + if (code == SYS_HALT || code == SYS_POWER_OFF)
  2727. + if (!nowayout)
  2728. + ar7_wdt_disable_wdt();
  2729. +
  2730. + return NOTIFY_DONE;
  2731. +}
  2732. +
  2733. +static struct notifier_block ar7_wdt_notifier = {
  2734. + .notifier_call = ar7_wdt_notify_sys
  2735. +};
  2736. +
  2737. +static ssize_t ar7_wdt_write(struct file *file, const char *data,
  2738. + size_t len, loff_t *ppos)
  2739. +{
  2740. + /* check for a magic close character */
  2741. + if (len) {
  2742. + size_t i;
  2743. +
  2744. + ar7_wdt_kick(1);
  2745. +
  2746. + expect_close = 0;
  2747. + for (i = 0; i < len; ++i) {
  2748. + char c;
  2749. + if (get_user(c, data+i))
  2750. + return -EFAULT;
  2751. + if (c == 'V')
  2752. + expect_close = 1;
  2753. + }
  2754. +
  2755. + }
  2756. + return len;
  2757. +}
  2758. +
  2759. +static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
  2760. + unsigned int cmd, unsigned long arg)
  2761. +{
  2762. + static struct watchdog_info ident = {
  2763. + .identity = LONGNAME,
  2764. + .firmware_version = 1,
  2765. + .options = (WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING),
  2766. + };
  2767. + int new_margin;
  2768. +
  2769. + switch (cmd) {
  2770. + default:
  2771. + return -ENOTTY;
  2772. + case WDIOC_GETSUPPORT:
  2773. + if (copy_to_user((struct watchdog_info *)arg, &ident,
  2774. + sizeof(ident)))
  2775. + return -EFAULT;
  2776. + return 0;
  2777. + case WDIOC_GETSTATUS:
  2778. + case WDIOC_GETBOOTSTATUS:
  2779. + if (put_user(0, (int *)arg))
  2780. + return -EFAULT;
  2781. + return 0;
  2782. + case WDIOC_KEEPALIVE:
  2783. + ar7_wdt_kick(1);
  2784. + return 0;
  2785. + case WDIOC_SETTIMEOUT:
  2786. + if (get_user(new_margin, (int *)arg))
  2787. + return -EFAULT;
  2788. + if (new_margin < 1)
  2789. + return -EINVAL;
  2790. +
  2791. + ar7_wdt_update_margin(new_margin);
  2792. + ar7_wdt_kick(1);
  2793. +
  2794. + case WDIOC_GETTIMEOUT:
  2795. + if (put_user(margin, (int *)arg))
  2796. + return -EFAULT;
  2797. + return 0;
  2798. + }
  2799. +}
  2800. +
  2801. +static struct file_operations ar7_wdt_fops = {
  2802. + .owner = THIS_MODULE,
  2803. + .write = ar7_wdt_write,
  2804. + .ioctl = ar7_wdt_ioctl,
  2805. + .open = ar7_wdt_open,
  2806. + .release = ar7_wdt_release,
  2807. +};
  2808. +
  2809. +static struct miscdevice ar7_wdt_miscdev = {
  2810. + .minor = WATCHDOG_MINOR,
  2811. + .name = "watchdog",
  2812. + .fops = &ar7_wdt_fops,
  2813. +};
  2814. +
  2815. +static int __init ar7_wdt_init(void)
  2816. +{
  2817. + int rc;
  2818. +
  2819. + ar7_wdt_get_regs();
  2820. +
  2821. + if (!request_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt),
  2822. + LONGNAME)) {
  2823. + printk(KERN_WARNING DRVNAME ": watchdog I/O region busy\n");
  2824. + return -EBUSY;
  2825. + }
  2826. +
  2827. + ar7_wdt = (struct ar7_wdt *)
  2828. + ioremap(ar7_regs_wdt, sizeof(struct ar7_wdt));
  2829. +
  2830. + ar7_wdt_disable_wdt();
  2831. + ar7_wdt_prescale(prescale_value);
  2832. + ar7_wdt_update_margin(margin);
  2833. +
  2834. + sema_init(&open_semaphore, 1);
  2835. +
  2836. + rc = register_reboot_notifier(&ar7_wdt_notifier);
  2837. + if (rc) {
  2838. + printk(KERN_ERR DRVNAME
  2839. + ": unable to register reboot notifier\n");
  2840. + goto out_alloc;
  2841. + }
  2842. +
  2843. + rc = misc_register(&ar7_wdt_miscdev);
  2844. + if (rc) {
  2845. + printk(KERN_ERR DRVNAME ": unable to register misc device\n");
  2846. + goto out_register;
  2847. + }
  2848. + goto out;
  2849. +
  2850. +out_register:
  2851. + unregister_reboot_notifier(&ar7_wdt_notifier);
  2852. +out_alloc:
  2853. + iounmap(ar7_wdt);
  2854. + release_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt));
  2855. +out:
  2856. + return rc;
  2857. +}
  2858. +
  2859. +static void __exit ar7_wdt_cleanup(void)
  2860. +{
  2861. + misc_deregister(&ar7_wdt_miscdev);
  2862. + unregister_reboot_notifier(&ar7_wdt_notifier);
  2863. + iounmap(ar7_wdt);
  2864. + release_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt));
  2865. +}
  2866. +
  2867. +module_init(ar7_wdt_init);
  2868. +module_exit(ar7_wdt_cleanup);
  2869. diff -Nur linux-2.6.30.5.orig/drivers/Kconfig linux-2.6.30.5/drivers/Kconfig
  2870. --- linux-2.6.30.5.orig/drivers/Kconfig 2009-08-16 23:19:38.000000000 +0200
  2871. +++ linux-2.6.30.5/drivers/Kconfig 2009-08-26 20:05:30.000000000 +0200
  2872. @@ -104,6 +104,8 @@
  2873. source "drivers/uio/Kconfig"
  2874. +source "drivers/vlynq/Kconfig"
  2875. +
  2876. source "drivers/xen/Kconfig"
  2877. source "drivers/staging/Kconfig"
  2878. diff -Nur linux-2.6.30.5.orig/drivers/Makefile linux-2.6.30.5/drivers/Makefile
  2879. --- linux-2.6.30.5.orig/drivers/Makefile 2009-08-16 23:19:38.000000000 +0200
  2880. +++ linux-2.6.30.5/drivers/Makefile 2009-08-26 20:05:30.000000000 +0200
  2881. @@ -103,6 +103,7 @@
  2882. obj-$(CONFIG_HID) += hid/
  2883. obj-$(CONFIG_PPC_PS3) += ps3/
  2884. obj-$(CONFIG_OF) += of/
  2885. +obj-$(CONFIG_VLYNQ) += vlynq/
  2886. obj-$(CONFIG_SSB) += ssb/
  2887. obj-$(CONFIG_VIRTIO) += virtio/
  2888. obj-$(CONFIG_STAGING) += staging/
  2889. diff -Nur linux-2.6.30.5.orig/drivers/mtd/maps/physmap.c linux-2.6.30.5/drivers/mtd/maps/physmap.c
  2890. --- linux-2.6.30.5.orig/drivers/mtd/maps/physmap.c 2009-08-16 23:19:38.000000000 +0200
  2891. +++ linux-2.6.30.5/drivers/mtd/maps/physmap.c 2009-08-26 20:05:19.000000000 +0200
  2892. @@ -80,7 +80,7 @@
  2893. "map_rom",
  2894. NULL };
  2895. #ifdef CONFIG_MTD_PARTITIONS
  2896. -static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  2897. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "ar7part", NULL };
  2898. #endif
  2899. static int physmap_flash_probe(struct platform_device *dev)
  2900. diff -Nur linux-2.6.30.5.orig/drivers/net/cpmac.c linux-2.6.30.5/drivers/net/cpmac.c
  2901. --- linux-2.6.30.5.orig/drivers/net/cpmac.c 2009-08-16 23:19:38.000000000 +0200
  2902. +++ linux-2.6.30.5/drivers/net/cpmac.c 2009-08-26 22:00:29.000000000 +0200
  2903. @@ -615,13 +615,13 @@
  2904. dev_kfree_skb_irq(desc->skb);
  2905. desc->skb = NULL;
  2906. - if (netif_subqueue_stopped(dev, queue))
  2907. + if (__netif_subqueue_stopped(dev, queue))
  2908. netif_wake_subqueue(dev, queue);
  2909. } else {
  2910. if (netif_msg_tx_err(priv) && net_ratelimit())
  2911. printk(KERN_WARNING
  2912. "%s: end_xmit: spurious interrupt\n", dev->name);
  2913. - if (netif_subqueue_stopped(dev, queue))
  2914. + if (__netif_subqueue_stopped(dev, queue))
  2915. netif_wake_subqueue(dev, queue);
  2916. }
  2917. }
  2918. @@ -731,7 +731,6 @@
  2919. static void cpmac_hw_error(struct work_struct *work)
  2920. {
  2921. - int i;
  2922. struct cpmac_priv *priv =
  2923. container_of(work, struct cpmac_priv, reset_work);
  2924. @@ -818,7 +817,6 @@
  2925. static void cpmac_tx_timeout(struct net_device *dev)
  2926. {
  2927. - int i;
  2928. struct cpmac_priv *priv = netdev_priv(dev);
  2929. spin_lock(&priv->lock);
  2930. @@ -1097,15 +1095,18 @@
  2931. static int __devinit cpmac_probe(struct platform_device *pdev)
  2932. {
  2933. - int rc, phy_id, i;
  2934. - char *mdio_bus_id = "0";
  2935. + int rc, phy_id;
  2936. + char mdio_bus_id[BUS_ID_SIZE];
  2937. struct resource *mem;
  2938. struct cpmac_priv *priv;
  2939. struct net_device *dev;
  2940. struct plat_cpmac_data *pdata;
  2941. pdata = pdev->dev.platform_data;
  2942. + strncpy(mdio_bus_id, "0", BUS_ID_SIZE);
  2943. + phy_id = pdev->id;
  2944. + /*
  2945. for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
  2946. if (!(pdata->phy_mask & (1 << phy_id)))
  2947. continue;
  2948. @@ -1116,15 +1117,17 @@
  2949. if (phy_id == PHY_MAX_ADDR) {
  2950. if (external_switch || dumb_switch) {
  2951. - mdio_bus_id = 0; /* fixed phys bus */
  2952. + strncpy(mdio_bus_id, "0", BUS_ID_SIZE);
  2953. phy_id = pdev->id;
  2954. } else {
  2955. dev_err(&pdev->dev, "no PHY present\n");
  2956. return -ENODEV;
  2957. }
  2958. }
  2959. + */
  2960. dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
  2961. + //~ dev = alloc_etherdev(sizeof(*priv));
  2962. if (!dev) {
  2963. printk(KERN_ERR "cpmac: Unable to allocate net_device\n");
  2964. @@ -1161,8 +1164,11 @@
  2965. priv->msg_enable = netif_msg_init(debug_level, 0xff);
  2966. memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
  2967. - priv->phy = phy_connect(dev, dev_name(&cpmac_mii->phy_map[phy_id]->dev),
  2968. + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
  2969. + //priv->phy = phy_connect(dev, dev_name(&cpmac_mii->phy_map[phy_id]->dev),
  2970. + priv->phy = phy_connect(dev, priv->phy_name,
  2971. &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
  2972. +
  2973. if (IS_ERR(priv->phy)) {
  2974. if (netif_msg_drv(priv))
  2975. printk(KERN_ERR "%s: Could not attach to PHY\n",
  2976. @@ -1249,7 +1255,7 @@
  2977. }
  2978. cpmac_mii->phy_mask = ~(mask | 0x80000000);
  2979. - snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "0");
  2980. + snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "1");
  2981. res = mdiobus_register(cpmac_mii);
  2982. if (res)
  2983. diff -Nur linux-2.6.30.5.orig/drivers/net/Kconfig linux-2.6.30.5/drivers/net/Kconfig
  2984. --- linux-2.6.30.5.orig/drivers/net/Kconfig 2009-08-16 23:19:38.000000000 +0200
  2985. +++ linux-2.6.30.5/drivers/net/Kconfig 2009-08-26 20:06:44.000000000 +0200
  2986. @@ -1760,7 +1760,7 @@
  2987. config CPMAC
  2988. tristate "TI AR7 CPMAC Ethernet support (EXPERIMENTAL)"
  2989. - depends on NET_ETHERNET && EXPERIMENTAL && AR7 && BROKEN
  2990. + depends on NET_ETHERNET && EXPERIMENTAL && AR7
  2991. select PHYLIB
  2992. help
  2993. TI AR7 CPMAC Ethernet support
  2994. diff -Nur linux-2.6.30.5.orig/drivers/serial/8250.c linux-2.6.30.5/drivers/serial/8250.c
  2995. --- linux-2.6.30.5.orig/drivers/serial/8250.c 2009-08-16 23:19:38.000000000 +0200
  2996. +++ linux-2.6.30.5/drivers/serial/8250.c 2009-08-26 20:06:59.000000000 +0200
  2997. @@ -287,6 +287,13 @@
  2998. .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
  2999. .flags = UART_CAP_FIFO,
  3000. },
  3001. + [PORT_AR7] = {
  3002. + .name = "TI-AR7",
  3003. + .fifo_size = 16,
  3004. + .tx_loadsz = 16,
  3005. + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
  3006. + .flags = UART_CAP_FIFO | UART_CAP_AFE,
  3007. + },
  3008. };
  3009. #if defined (CONFIG_SERIAL_8250_AU1X00)
  3010. @@ -2702,7 +2709,11 @@
  3011. {
  3012. struct uart_8250_port *up = (struct uart_8250_port *)port;
  3013. +#ifdef CONFIG_AR7
  3014. + wait_for_xmitr(up, BOTH_EMPTY);
  3015. +#else
  3016. wait_for_xmitr(up, UART_LSR_THRE);
  3017. +#endif
  3018. serial_out(up, UART_TX, ch);
  3019. }
  3020. diff -Nur linux-2.6.30.5.orig/drivers/vlynq/Kconfig linux-2.6.30.5/drivers/vlynq/Kconfig
  3021. --- linux-2.6.30.5.orig/drivers/vlynq/Kconfig 1970-01-01 01:00:00.000000000 +0100
  3022. +++ linux-2.6.30.5/drivers/vlynq/Kconfig 2009-08-26 20:05:03.000000000 +0200
  3023. @@ -0,0 +1,13 @@
  3024. +menu "TI VLYNQ"
  3025. +
  3026. +config VLYNQ
  3027. + bool "TI VLYNQ bus support"
  3028. + depends on AR7 && EXPERIMENTAL
  3029. + help
  3030. + Support for the TI VLYNQ bus
  3031. +
  3032. + The module will be called vlynq
  3033. +
  3034. + If unsure, say N
  3035. +
  3036. +endmenu
  3037. diff -Nur linux-2.6.30.5.orig/drivers/vlynq/Makefile linux-2.6.30.5/drivers/vlynq/Makefile
  3038. --- linux-2.6.30.5.orig/drivers/vlynq/Makefile 1970-01-01 01:00:00.000000000 +0100
  3039. +++ linux-2.6.30.5/drivers/vlynq/Makefile 2009-08-26 20:05:03.000000000 +0200
  3040. @@ -0,0 +1,5 @@
  3041. +#
  3042. +# Makefile for kernel vlynq drivers
  3043. +#
  3044. +
  3045. +obj-$(CONFIG_VLYNQ) += vlynq.o
  3046. diff -Nur linux-2.6.30.5.orig/drivers/vlynq/vlynq.c linux-2.6.30.5/drivers/vlynq/vlynq.c
  3047. --- linux-2.6.30.5.orig/drivers/vlynq/vlynq.c 1970-01-01 01:00:00.000000000 +0100
  3048. +++ linux-2.6.30.5/drivers/vlynq/vlynq.c 2009-08-26 20:06:33.000000000 +0200
  3049. @@ -0,0 +1,813 @@
  3050. +/*
  3051. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  3052. + *
  3053. + * This program is free software; you can redistribute it and/or modify
  3054. + * it under the terms of the GNU General Public License as published by
  3055. + * the Free Software Foundation; either version 2 of the License, or
  3056. + * (at your option) any later version.
  3057. + *
  3058. + * This program is distributed in the hope that it will be useful,
  3059. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3060. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3061. + * GNU General Public License for more details.
  3062. + *
  3063. + * You should have received a copy of the GNU General Public License
  3064. + * along with this program; if not, write to the Free Software
  3065. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  3066. + *
  3067. + * Parts of the VLYNQ specification can be found here:
  3068. + * http://www.ti.com/litv/pdf/sprue36a
  3069. + */
  3070. +
  3071. +#include <linux/init.h>
  3072. +#include <linux/types.h>
  3073. +#include <linux/kernel.h>
  3074. +#include <linux/string.h>
  3075. +#include <linux/device.h>
  3076. +#include <linux/module.h>
  3077. +#include <linux/errno.h>
  3078. +#include <linux/platform_device.h>
  3079. +#include <linux/interrupt.h>
  3080. +#include <linux/delay.h>
  3081. +#include <linux/io.h>
  3082. +
  3083. +#include <linux/vlynq.h>
  3084. +
  3085. +#define VLYNQ_CTRL_PM_ENABLE 0x80000000
  3086. +#define VLYNQ_CTRL_CLOCK_INT 0x00008000
  3087. +#define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
  3088. +#define VLYNQ_CTRL_INT_LOCAL 0x00004000
  3089. +#define VLYNQ_CTRL_INT_ENABLE 0x00002000
  3090. +#define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
  3091. +#define VLYNQ_CTRL_INT2CFG 0x00000080
  3092. +#define VLYNQ_CTRL_RESET 0x00000001
  3093. +
  3094. +#define VLYNQ_CTRL_CLOCK_MASK (0x7 << 16)
  3095. +
  3096. +#define VLYNQ_INT_OFFSET 0x00000014
  3097. +#define VLYNQ_REMOTE_OFFSET 0x00000080
  3098. +
  3099. +#define VLYNQ_STATUS_LINK 0x00000001
  3100. +#define VLYNQ_STATUS_LERROR 0x00000080
  3101. +#define VLYNQ_STATUS_RERROR 0x00000100
  3102. +
  3103. +#define VINT_ENABLE 0x00000100
  3104. +#define VINT_TYPE_EDGE 0x00000080
  3105. +#define VINT_LEVEL_LOW 0x00000040
  3106. +#define VINT_VECTOR(x) ((x) & 0x1f)
  3107. +#define VINT_OFFSET(irq) (8 * ((irq) % 4))
  3108. +
  3109. +#define VLYNQ_AUTONEGO_V2 0x00010000
  3110. +
  3111. +struct vlynq_regs {
  3112. + u32 revision;
  3113. + u32 control;
  3114. + u32 status;
  3115. + u32 int_prio;
  3116. + u32 int_status;
  3117. + u32 int_pending;
  3118. + u32 int_ptr;
  3119. + u32 tx_offset;
  3120. + struct vlynq_mapping rx_mapping[4];
  3121. + u32 chip;
  3122. + u32 autonego;
  3123. + u32 unused[6];
  3124. + u32 int_device[8];
  3125. +};
  3126. +
  3127. +#ifdef CONFIG_VLYNQ_DEBUG
  3128. +static void vlynq_dump_regs(struct vlynq_device *dev)
  3129. +{
  3130. + int i;
  3131. +
  3132. + printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
  3133. + dev->local, dev->remote);
  3134. + for (i = 0; i < 32; i++) {
  3135. + printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
  3136. + i + 1, ((u32 *)dev->local)[i]);
  3137. + printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
  3138. + i + 1, ((u32 *)dev->remote)[i]);
  3139. + }
  3140. +}
  3141. +
  3142. +static void vlynq_dump_mem(u32 *base, int count)
  3143. +{
  3144. + int i;
  3145. +
  3146. + for (i = 0; i < (count + 3) / 4; i++) {
  3147. + if (i % 4 == 0)
  3148. + printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
  3149. + printk(KERN_DEBUG " 0x%08x", *(base + i));
  3150. + }
  3151. + printk(KERN_DEBUG "\n");
  3152. +}
  3153. +#endif
  3154. +
  3155. +/* Check the VLYNQ link status with a given device */
  3156. +static int vlynq_linked(struct vlynq_device *dev)
  3157. +{
  3158. + int i;
  3159. +
  3160. + for (i = 0; i < 100; i++)
  3161. + if (readl(&dev->local->status) & VLYNQ_STATUS_LINK)
  3162. + return 1;
  3163. + else
  3164. + cpu_relax();
  3165. +
  3166. + return 0;
  3167. +}
  3168. +
  3169. +static void vlynq_reset(struct vlynq_device *dev)
  3170. +{
  3171. + writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
  3172. + &dev->local->control);
  3173. +
  3174. + /* Wait for the devices to finish resetting */
  3175. + msleep(5);
  3176. +
  3177. + /* Remove reset bit */
  3178. + writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
  3179. + &dev->local->control);
  3180. +
  3181. + /* Give some time for the devices to settle */
  3182. + msleep(5);
  3183. +}
  3184. +
  3185. +static void vlynq_irq_unmask(unsigned int irq)
  3186. +{
  3187. + u32 val;
  3188. + struct vlynq_device *dev = get_irq_chip_data(irq);
  3189. + int virq;
  3190. +
  3191. + BUG_ON(!dev);
  3192. + virq = irq - dev->irq_start;
  3193. + val = readl(&dev->remote->int_device[virq >> 2]);
  3194. + val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
  3195. + writel(val, &dev->remote->int_device[virq >> 2]);
  3196. +}
  3197. +
  3198. +static void vlynq_irq_mask(unsigned int irq)
  3199. +{
  3200. + u32 val;
  3201. + struct vlynq_device *dev = get_irq_chip_data(irq);
  3202. + int virq;
  3203. +
  3204. + BUG_ON(!dev);
  3205. + virq = irq - dev->irq_start;
  3206. + val = readl(&dev->remote->int_device[virq >> 2]);
  3207. + val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
  3208. + writel(val, &dev->remote->int_device[virq >> 2]);
  3209. +}
  3210. +
  3211. +static int vlynq_irq_type(unsigned int irq, unsigned int flow_type)
  3212. +{
  3213. + u32 val;
  3214. + struct vlynq_device *dev = get_irq_chip_data(irq);
  3215. + int virq;
  3216. +
  3217. + BUG_ON(!dev);
  3218. + virq = irq - dev->irq_start;
  3219. + val = readl(&dev->remote->int_device[virq >> 2]);
  3220. + switch (flow_type & IRQ_TYPE_SENSE_MASK) {
  3221. + case IRQ_TYPE_EDGE_RISING:
  3222. + case IRQ_TYPE_EDGE_FALLING:
  3223. + case IRQ_TYPE_EDGE_BOTH:
  3224. + val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
  3225. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  3226. + break;
  3227. + case IRQ_TYPE_LEVEL_HIGH:
  3228. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  3229. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  3230. + break;
  3231. + case IRQ_TYPE_LEVEL_LOW:
  3232. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  3233. + val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
  3234. + break;
  3235. + default:
  3236. + return -EINVAL;
  3237. + }
  3238. + writel(val, &dev->remote->int_device[virq >> 2]);
  3239. + return 0;
  3240. +}
  3241. +
  3242. +static void vlynq_local_ack(unsigned int irq)
  3243. +{
  3244. + struct vlynq_device *dev = get_irq_chip_data(irq);
  3245. +
  3246. + u32 status = readl(&dev->local->status);
  3247. +
  3248. + pr_debug("%s: local status: 0x%08x\n",
  3249. + dev_name(&dev->dev), status);
  3250. + writel(status, &dev->local->status);
  3251. +}
  3252. +
  3253. +static void vlynq_remote_ack(unsigned int irq)
  3254. +{
  3255. + struct vlynq_device *dev = get_irq_chip_data(irq);
  3256. +
  3257. + u32 status = readl(&dev->remote->status);
  3258. +
  3259. + pr_debug("%s: remote status: 0x%08x\n",
  3260. + dev_name(&dev->dev), status);
  3261. + writel(status, &dev->remote->status);
  3262. +}
  3263. +
  3264. +static irqreturn_t vlynq_irq(int irq, void *dev_id)
  3265. +{
  3266. + struct vlynq_device *dev = dev_id;
  3267. + u32 status;
  3268. + int virq = 0;
  3269. +
  3270. + status = readl(&dev->local->int_status);
  3271. + writel(status, &dev->local->int_status);
  3272. +
  3273. + if (unlikely(!status))
  3274. + spurious_interrupt();
  3275. +
  3276. + while (status) {
  3277. + if (status & 1)
  3278. + do_IRQ(dev->irq_start + virq);
  3279. + status >>= 1;
  3280. + virq++;
  3281. + }
  3282. +
  3283. + return IRQ_HANDLED;
  3284. +}
  3285. +
  3286. +static struct irq_chip vlynq_irq_chip = {
  3287. + .name = "vlynq",
  3288. + .unmask = vlynq_irq_unmask,
  3289. + .mask = vlynq_irq_mask,
  3290. + .set_type = vlynq_irq_type,
  3291. +};
  3292. +
  3293. +static struct irq_chip vlynq_local_chip = {
  3294. + .name = "vlynq local error",
  3295. + .unmask = vlynq_irq_unmask,
  3296. + .mask = vlynq_irq_mask,
  3297. + .ack = vlynq_local_ack,
  3298. +};
  3299. +
  3300. +static struct irq_chip vlynq_remote_chip = {
  3301. + .name = "vlynq local error",
  3302. + .unmask = vlynq_irq_unmask,
  3303. + .mask = vlynq_irq_mask,
  3304. + .ack = vlynq_remote_ack,
  3305. +};
  3306. +
  3307. +static int vlynq_setup_irq(struct vlynq_device *dev)
  3308. +{
  3309. + u32 val;
  3310. + int i, virq;
  3311. +
  3312. + if (dev->local_irq == dev->remote_irq) {
  3313. + printk(KERN_ERR
  3314. + "%s: local vlynq irq should be different from remote\n",
  3315. + dev_name(&dev->dev));
  3316. + return -EINVAL;
  3317. + }
  3318. +
  3319. + /* Clear local and remote error bits */
  3320. + writel(readl(&dev->local->status), &dev->local->status);
  3321. + writel(readl(&dev->remote->status), &dev->remote->status);
  3322. +
  3323. + /* Now setup interrupts */
  3324. + val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
  3325. + val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
  3326. + VLYNQ_CTRL_INT2CFG;
  3327. + val |= readl(&dev->local->control);
  3328. + writel(VLYNQ_INT_OFFSET, &dev->local->int_ptr);
  3329. + writel(val, &dev->local->control);
  3330. +
  3331. + val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
  3332. + val |= VLYNQ_CTRL_INT_ENABLE;
  3333. + val |= readl(&dev->remote->control);
  3334. + writel(VLYNQ_INT_OFFSET, &dev->remote->int_ptr);
  3335. + writel(val, &dev->remote->int_ptr);
  3336. + writel(val, &dev->remote->control);
  3337. +
  3338. + for (i = dev->irq_start; i <= dev->irq_end; i++) {
  3339. + virq = i - dev->irq_start;
  3340. + if (virq == dev->local_irq) {
  3341. + set_irq_chip_and_handler(i, &vlynq_local_chip,
  3342. + handle_level_irq);
  3343. + set_irq_chip_data(i, dev);
  3344. + } else if (virq == dev->remote_irq) {
  3345. + set_irq_chip_and_handler(i, &vlynq_remote_chip,
  3346. + handle_level_irq);
  3347. + set_irq_chip_data(i, dev);
  3348. + } else {
  3349. + set_irq_chip_and_handler(i, &vlynq_irq_chip,
  3350. + handle_simple_irq);
  3351. + set_irq_chip_data(i, dev);
  3352. + writel(0, &dev->remote->int_device[virq >> 2]);
  3353. + }
  3354. + }
  3355. +
  3356. + if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
  3357. + printk(KERN_ERR "%s: request_irq failed\n",
  3358. + dev_name(&dev->dev));
  3359. + return -EAGAIN;
  3360. + }
  3361. +
  3362. + return 0;
  3363. +}
  3364. +
  3365. +static void vlynq_device_release(struct device *dev)
  3366. +{
  3367. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3368. + kfree(vdev);
  3369. +}
  3370. +
  3371. +static int vlynq_device_match(struct device *dev,
  3372. + struct device_driver *drv)
  3373. +{
  3374. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3375. + struct vlynq_driver *vdrv = to_vlynq_driver(drv);
  3376. + struct vlynq_device_id *ids = vdrv->id_table;
  3377. +
  3378. + while (ids->id) {
  3379. + if (ids->id == vdev->dev_id) {
  3380. + vdev->divisor = ids->divisor;
  3381. + vlynq_set_drvdata(vdev, ids);
  3382. + printk(KERN_INFO "Driver found for VLYNQ "
  3383. + "device: %08x\n", vdev->dev_id);
  3384. + return 1;
  3385. + }
  3386. + printk(KERN_DEBUG "Not using the %08x VLYNQ device's driver"
  3387. + " for VLYNQ device: %08x\n", ids->id, vdev->dev_id);
  3388. + ids++;
  3389. + }
  3390. + return 0;
  3391. +}
  3392. +
  3393. +static int vlynq_device_probe(struct device *dev)
  3394. +{
  3395. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3396. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  3397. + struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
  3398. + int result = -ENODEV;
  3399. +
  3400. + if (drv->probe)
  3401. + result = drv->probe(vdev, id);
  3402. + if (result)
  3403. + put_device(dev);
  3404. + return result;
  3405. +}
  3406. +
  3407. +static int vlynq_device_remove(struct device *dev)
  3408. +{
  3409. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  3410. +
  3411. + if (drv->remove)
  3412. + drv->remove(to_vlynq_device(dev));
  3413. +
  3414. + return 0;
  3415. +}
  3416. +
  3417. +int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
  3418. +{
  3419. + driver->driver.name = driver->name;
  3420. + driver->driver.bus = &vlynq_bus_type;
  3421. + return driver_register(&driver->driver);
  3422. +}
  3423. +EXPORT_SYMBOL(__vlynq_register_driver);
  3424. +
  3425. +void vlynq_unregister_driver(struct vlynq_driver *driver)
  3426. +{
  3427. + driver_unregister(&driver->driver);
  3428. +}
  3429. +EXPORT_SYMBOL(vlynq_unregister_driver);
  3430. +
  3431. +/*
  3432. + * A VLYNQ remote device can clock the VLYNQ bus master
  3433. + * using a dedicated clock line. In that case, both the
  3434. + * remove device and the bus master should have the same
  3435. + * serial clock dividers configured. Iterate through the
  3436. + * 8 possible dividers until we actually link with the
  3437. + * device.
  3438. + */
  3439. +static int __vlynq_try_remote(struct vlynq_device *dev)
  3440. +{
  3441. + int i;
  3442. +
  3443. + vlynq_reset(dev);
  3444. + for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
  3445. + i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
  3446. + dev->dev_id ? i++ : i--) {
  3447. +
  3448. + if (!vlynq_linked(dev))
  3449. + break;
  3450. +
  3451. + writel((readl(&dev->remote->control) &
  3452. + ~VLYNQ_CTRL_CLOCK_MASK) |
  3453. + VLYNQ_CTRL_CLOCK_INT |
  3454. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
  3455. + &dev->remote->control);
  3456. + writel((readl(&dev->local->control)
  3457. + & ~(VLYNQ_CTRL_CLOCK_INT |
  3458. + VLYNQ_CTRL_CLOCK_MASK)) |
  3459. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
  3460. + &dev->local->control);
  3461. +
  3462. + if (vlynq_linked(dev)) {
  3463. + printk(KERN_DEBUG
  3464. + "%s: using remote clock divisor %d\n",
  3465. + dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
  3466. + dev->divisor = i;
  3467. + return 0;
  3468. + } else {
  3469. + vlynq_reset(dev);
  3470. + }
  3471. + }
  3472. +
  3473. + return -ENODEV;
  3474. +}
  3475. +
  3476. +/*
  3477. + * A VLYNQ remote device can be clocked by the VLYNQ bus
  3478. + * master using a dedicated clock line. In that case, only
  3479. + * the bus master configures the serial clock divider.
  3480. + * Iterate through the 8 possible dividers until we
  3481. + * actually get a link with the device.
  3482. + */
  3483. +static int __vlynq_try_local(struct vlynq_device *dev)
  3484. +{
  3485. + int i;
  3486. +
  3487. + vlynq_reset(dev);
  3488. +
  3489. + for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
  3490. + i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
  3491. + dev->dev_id ? i++ : i--) {
  3492. +
  3493. + writel((readl(&dev->local->control) &
  3494. + ~VLYNQ_CTRL_CLOCK_MASK) |
  3495. + VLYNQ_CTRL_CLOCK_INT |
  3496. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
  3497. + &dev->local->control);
  3498. +
  3499. + if (vlynq_linked(dev)) {
  3500. + printk(KERN_DEBUG
  3501. + "%s: using local clock divisor %d\n",
  3502. + dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
  3503. + dev->divisor = i;
  3504. + return 0;
  3505. + } else {
  3506. + vlynq_reset(dev);
  3507. + }
  3508. + }
  3509. +
  3510. + return -ENODEV;
  3511. +}
  3512. +
  3513. +/*
  3514. + * When using external clocking method, serial clock
  3515. + * is supplied by an external oscillator, therefore we
  3516. + * should mask the local clock bit in the clock control
  3517. + * register for both the bus master and the remote device.
  3518. + */
  3519. +static int __vlynq_try_external(struct vlynq_device *dev)
  3520. +{
  3521. + vlynq_reset(dev);
  3522. + if (!vlynq_linked(dev))
  3523. + return -ENODEV;
  3524. +
  3525. + writel((readl(&dev->remote->control) &
  3526. + ~VLYNQ_CTRL_CLOCK_INT),
  3527. + &dev->remote->control);
  3528. +
  3529. + writel((readl(&dev->local->control) &
  3530. + ~VLYNQ_CTRL_CLOCK_INT),
  3531. + &dev->local->control);
  3532. +
  3533. + if (vlynq_linked(dev)) {
  3534. + printk(KERN_DEBUG "%s: using external clock\n",
  3535. + dev_name(&dev->dev));
  3536. + dev->divisor = vlynq_div_external;
  3537. + return 0;
  3538. + }
  3539. +
  3540. + return -ENODEV;
  3541. +}
  3542. +
  3543. +static int __vlynq_enable_device(struct vlynq_device *dev)
  3544. +{
  3545. + int result;
  3546. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3547. +
  3548. + result = ops->on(dev);
  3549. + if (result)
  3550. + return result;
  3551. +
  3552. + switch (dev->divisor) {
  3553. + case vlynq_div_external:
  3554. + case vlynq_div_auto:
  3555. + /* When the device is brought from reset it should have clock
  3556. + * generation negotiated by hardware.
  3557. + * Check which device is generating clocks and perform setup
  3558. + * accordingly */
  3559. + if (vlynq_linked(dev) && readl(&dev->remote->control) &
  3560. + VLYNQ_CTRL_CLOCK_INT) {
  3561. + if (!__vlynq_try_remote(dev) ||
  3562. + !__vlynq_try_local(dev) ||
  3563. + !__vlynq_try_external(dev))
  3564. + return 0;
  3565. + } else {
  3566. + if (!__vlynq_try_external(dev) ||
  3567. + !__vlynq_try_local(dev) ||
  3568. + !__vlynq_try_remote(dev))
  3569. + return 0;
  3570. + }
  3571. + break;
  3572. + case vlynq_ldiv1:
  3573. + case vlynq_ldiv2:
  3574. + case vlynq_ldiv3:
  3575. + case vlynq_ldiv4:
  3576. + case vlynq_ldiv5:
  3577. + case vlynq_ldiv6:
  3578. + case vlynq_ldiv7:
  3579. + case vlynq_ldiv8:
  3580. + writel(VLYNQ_CTRL_CLOCK_INT |
  3581. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  3582. + vlynq_ldiv1), &dev->local->control);
  3583. + writel(0, &dev->remote->control);
  3584. + if (vlynq_linked(dev)) {
  3585. + printk(KERN_DEBUG
  3586. + "%s: using local clock divisor %d\n",
  3587. + dev_name(&dev->dev),
  3588. + dev->divisor - vlynq_ldiv1 + 1);
  3589. + return 0;
  3590. + }
  3591. + break;
  3592. + case vlynq_rdiv1:
  3593. + case vlynq_rdiv2:
  3594. + case vlynq_rdiv3:
  3595. + case vlynq_rdiv4:
  3596. + case vlynq_rdiv5:
  3597. + case vlynq_rdiv6:
  3598. + case vlynq_rdiv7:
  3599. + case vlynq_rdiv8:
  3600. + writel(0, &dev->local->control);
  3601. + writel(VLYNQ_CTRL_CLOCK_INT |
  3602. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  3603. + vlynq_rdiv1), &dev->remote->control);
  3604. + if (vlynq_linked(dev)) {
  3605. + printk(KERN_DEBUG
  3606. + "%s: using remote clock divisor %d\n",
  3607. + dev_name(&dev->dev),
  3608. + dev->divisor - vlynq_rdiv1 + 1);
  3609. + return 0;
  3610. + }
  3611. + break;
  3612. + }
  3613. +
  3614. + ops->off(dev);
  3615. + return -ENODEV;
  3616. +}
  3617. +
  3618. +int vlynq_enable_device(struct vlynq_device *dev)
  3619. +{
  3620. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3621. + int result = -ENODEV;
  3622. +
  3623. + result = __vlynq_enable_device(dev);
  3624. + if (result)
  3625. + return result;
  3626. +
  3627. + result = vlynq_setup_irq(dev);
  3628. + if (result)
  3629. + ops->off(dev);
  3630. +
  3631. + dev->enabled = !result;
  3632. + return result;
  3633. +}
  3634. +EXPORT_SYMBOL(vlynq_enable_device);
  3635. +
  3636. +
  3637. +void vlynq_disable_device(struct vlynq_device *dev)
  3638. +{
  3639. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3640. +
  3641. + dev->enabled = 0;
  3642. + free_irq(dev->irq, dev);
  3643. + ops->off(dev);
  3644. +}
  3645. +EXPORT_SYMBOL(vlynq_disable_device);
  3646. +
  3647. +int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  3648. + struct vlynq_mapping *mapping)
  3649. +{
  3650. + int i;
  3651. +
  3652. + if (!dev->enabled)
  3653. + return -ENXIO;
  3654. +
  3655. + writel(tx_offset, &dev->local->tx_offset);
  3656. + for (i = 0; i < 4; i++) {
  3657. + writel(mapping[i].offset, &dev->local->rx_mapping[i].offset);
  3658. + writel(mapping[i].size, &dev->local->rx_mapping[i].size);
  3659. + }
  3660. + return 0;
  3661. +}
  3662. +EXPORT_SYMBOL(vlynq_set_local_mapping);
  3663. +
  3664. +int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  3665. + struct vlynq_mapping *mapping)
  3666. +{
  3667. + int i;
  3668. +
  3669. + if (!dev->enabled)
  3670. + return -ENXIO;
  3671. +
  3672. + writel(tx_offset, &dev->remote->tx_offset);
  3673. + for (i = 0; i < 4; i++) {
  3674. + writel(mapping[i].offset, &dev->remote->rx_mapping[i].offset);
  3675. + writel(mapping[i].size, &dev->remote->rx_mapping[i].size);
  3676. + }
  3677. + return 0;
  3678. +}
  3679. +EXPORT_SYMBOL(vlynq_set_remote_mapping);
  3680. +
  3681. +int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
  3682. +{
  3683. + int irq = dev->irq_start + virq;
  3684. + if (dev->enabled)
  3685. + return -EBUSY;
  3686. +
  3687. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3688. + return -EINVAL;
  3689. +
  3690. + if (virq == dev->remote_irq)
  3691. + return -EINVAL;
  3692. +
  3693. + dev->local_irq = virq;
  3694. +
  3695. + return 0;
  3696. +}
  3697. +EXPORT_SYMBOL(vlynq_set_local_irq);
  3698. +
  3699. +int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
  3700. +{
  3701. + int irq = dev->irq_start + virq;
  3702. + if (dev->enabled)
  3703. + return -EBUSY;
  3704. +
  3705. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3706. + return -EINVAL;
  3707. +
  3708. + if (virq == dev->local_irq)
  3709. + return -EINVAL;
  3710. +
  3711. + dev->remote_irq = virq;
  3712. +
  3713. + return 0;
  3714. +}
  3715. +EXPORT_SYMBOL(vlynq_set_remote_irq);
  3716. +
  3717. +static int vlynq_probe(struct platform_device *pdev)
  3718. +{
  3719. + struct vlynq_device *dev;
  3720. + struct resource *regs_res, *mem_res, *irq_res;
  3721. + int len, result;
  3722. +
  3723. + regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  3724. + if (!regs_res)
  3725. + return -ENODEV;
  3726. +
  3727. + mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
  3728. + if (!mem_res)
  3729. + return -ENODEV;
  3730. +
  3731. + irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
  3732. + if (!irq_res)
  3733. + return -ENODEV;
  3734. +
  3735. + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  3736. + if (!dev) {
  3737. + printk(KERN_ERR
  3738. + "vlynq: failed to allocate device structure\n");
  3739. + return -ENOMEM;
  3740. + }
  3741. +
  3742. + dev->id = pdev->id;
  3743. + dev->dev.bus = &vlynq_bus_type;
  3744. + dev->dev.parent = &pdev->dev;
  3745. + dev_set_name(&dev->dev, "vlynq%d", dev->id);
  3746. + dev->dev.platform_data = pdev->dev.platform_data;
  3747. + dev->dev.release = vlynq_device_release;
  3748. +
  3749. + dev->regs_start = regs_res->start;
  3750. + dev->regs_end = regs_res->end;
  3751. + dev->mem_start = mem_res->start;
  3752. + dev->mem_end = mem_res->end;
  3753. +
  3754. + len = regs_res->end - regs_res->start;
  3755. + if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
  3756. + printk(KERN_ERR "%s: Can't request vlynq registers\n",
  3757. + dev_name(&dev->dev));
  3758. + result = -ENXIO;
  3759. + goto fail_request;
  3760. + }
  3761. +
  3762. + dev->local = ioremap(regs_res->start, len);
  3763. + if (!dev->local) {
  3764. + printk(KERN_ERR "%s: Can't remap vlynq registers\n",
  3765. + dev_name(&dev->dev));
  3766. + result = -ENXIO;
  3767. + goto fail_remap;
  3768. + }
  3769. +
  3770. + dev->remote = (struct vlynq_regs *)((void *)dev->local +
  3771. + VLYNQ_REMOTE_OFFSET);
  3772. +
  3773. + dev->irq = platform_get_irq_byname(pdev, "irq");
  3774. + dev->irq_start = irq_res->start;
  3775. + dev->irq_end = irq_res->end;
  3776. + dev->local_irq = dev->irq_end - dev->irq_start;
  3777. + dev->remote_irq = dev->local_irq - 1;
  3778. +
  3779. + if (device_register(&dev->dev))
  3780. + goto fail_register;
  3781. + platform_set_drvdata(pdev, dev);
  3782. +
  3783. + printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
  3784. + dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
  3785. + (void *)dev->mem_start);
  3786. +
  3787. + dev->dev_id = 0;
  3788. + dev->divisor = vlynq_div_auto;
  3789. + result = __vlynq_enable_device(dev);
  3790. + if (result == 0) {
  3791. + dev->dev_id = readl(&dev->remote->chip);
  3792. + ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
  3793. + }
  3794. + if (dev->dev_id)
  3795. + printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
  3796. +
  3797. + return 0;
  3798. +
  3799. +fail_register:
  3800. + iounmap(dev->local);
  3801. +fail_remap:
  3802. +fail_request:
  3803. + release_mem_region(regs_res->start, len);
  3804. + kfree(dev);
  3805. + return result;
  3806. +}
  3807. +
  3808. +static int vlynq_remove(struct platform_device *pdev)
  3809. +{
  3810. + struct vlynq_device *dev = platform_get_drvdata(pdev);
  3811. +
  3812. + device_unregister(&dev->dev);
  3813. + iounmap(dev->local);
  3814. + release_mem_region(dev->regs_start, dev->regs_end - dev->regs_start);
  3815. +
  3816. + kfree(dev);
  3817. +
  3818. + return 0;
  3819. +}
  3820. +
  3821. +static struct platform_driver vlynq_platform_driver = {
  3822. + .driver.name = "vlynq",
  3823. + .probe = vlynq_probe,
  3824. + .remove = __devexit_p(vlynq_remove),
  3825. +};
  3826. +
  3827. +struct bus_type vlynq_bus_type = {
  3828. + .name = "vlynq",
  3829. + .match = vlynq_device_match,
  3830. + .probe = vlynq_device_probe,
  3831. + .remove = vlynq_device_remove,
  3832. +};
  3833. +EXPORT_SYMBOL(vlynq_bus_type);
  3834. +
  3835. +static int __devinit vlynq_init(void)
  3836. +{
  3837. + int res = 0;
  3838. +
  3839. + res = bus_register(&vlynq_bus_type);
  3840. + if (res)
  3841. + goto fail_bus;
  3842. +
  3843. + res = platform_driver_register(&vlynq_platform_driver);
  3844. + if (res)
  3845. + goto fail_platform;
  3846. +
  3847. + return 0;
  3848. +
  3849. +fail_platform:
  3850. + bus_unregister(&vlynq_bus_type);
  3851. +fail_bus:
  3852. + return res;
  3853. +}
  3854. +
  3855. +static void __devexit vlynq_exit(void)
  3856. +{
  3857. + platform_driver_unregister(&vlynq_platform_driver);
  3858. + bus_unregister(&vlynq_bus_type);
  3859. +}
  3860. +
  3861. +module_init(vlynq_init);
  3862. +module_exit(vlynq_exit);
  3863. diff -Nur linux-2.6.30.5.orig/drivers/watchdog/ar7_wdt.c linux-2.6.30.5/drivers/watchdog/ar7_wdt.c
  3864. --- linux-2.6.30.5.orig/drivers/watchdog/ar7_wdt.c 2009-08-16 23:19:38.000000000 +0200
  3865. +++ linux-2.6.30.5/drivers/watchdog/ar7_wdt.c 2009-08-26 20:06:40.000000000 +0200
  3866. @@ -298,14 +298,28 @@
  3867. .fops = &ar7_wdt_fops,
  3868. };
  3869. +#define AR7_WDT_HARDWARE_ENABLE 0x10
  3870. +
  3871. static int __init ar7_wdt_init(void)
  3872. {
  3873. int rc;
  3874. + u32 *bootcr;
  3875. + u32 bootcr_value;
  3876. spin_lock_init(&wdt_lock);
  3877. ar7_wdt_get_regs();
  3878. + /* arch/mips/ar7/clocks.c is the only other thing that reads this */
  3879. + bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
  3880. + bootcr_value = *bootcr;
  3881. + iounmap(bootcr);
  3882. +
  3883. + if (!(bootcr_value & AR7_WDT_HARDWARE_ENABLE)) {
  3884. + printk(KERN_INFO DRVNAME ": watchdog disabled in hardware (bootcr=%#x)\n", bootcr_value);
  3885. + return -ENODEV;
  3886. + }
  3887. +
  3888. if (!request_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt),
  3889. LONGNAME)) {
  3890. printk(KERN_WARNING DRVNAME ": watchdog I/O region busy\n");
  3891. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/ar7.h linux-2.6.30.5/include/asm-mips/ar7/ar7.h
  3892. --- linux-2.6.30.5.orig/include/asm-mips/ar7/ar7.h 1970-01-01 01:00:00.000000000 +0100
  3893. +++ linux-2.6.30.5/include/asm-mips/ar7/ar7.h 2009-08-26 20:05:02.000000000 +0200
  3894. @@ -0,0 +1,170 @@
  3895. +/*
  3896. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  3897. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  3898. + *
  3899. + * This program is free software; you can redistribute it and/or modify
  3900. + * it under the terms of the GNU General Public License as published by
  3901. + * the Free Software Foundation; either version 2 of the License, or
  3902. + * (at your option) any later version.
  3903. + *
  3904. + * This program is distributed in the hope that it will be useful,
  3905. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3906. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3907. + * GNU General Public License for more details.
  3908. + *
  3909. + * You should have received a copy of the GNU General Public License
  3910. + * along with this program; if not, write to the Free Software
  3911. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  3912. + */
  3913. +
  3914. +#ifndef __AR7_H__
  3915. +#define __AR7_H__
  3916. +
  3917. +#include <linux/delay.h>
  3918. +#include <asm/addrspace.h>
  3919. +#include <linux/io.h>
  3920. +
  3921. +#define AR7_REGS_BASE 0x08610000
  3922. +
  3923. +#define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  3924. +#define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  3925. +/* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  3926. +#define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  3927. +#define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  3928. +#define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  3929. +#define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  3930. +#define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  3931. +#define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  3932. +#define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  3933. +#define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  3934. +#define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  3935. +#define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  3936. +
  3937. +#define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  3938. +#define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  3939. +#define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  3940. +
  3941. +#define AR7_RESET_PEREPHERIAL 0x0
  3942. +#define AR7_RESET_SOFTWARE 0x4
  3943. +#define AR7_RESET_STATUS 0x8
  3944. +
  3945. +#define AR7_RESET_BIT_CPMAC_LO 17
  3946. +#define AR7_RESET_BIT_CPMAC_HI 21
  3947. +#define AR7_RESET_BIT_MDIO 22
  3948. +#define AR7_RESET_BIT_EPHY 26
  3949. +
  3950. +/* GPIO control registers */
  3951. +#define AR7_GPIO_INPUT 0x0
  3952. +#define AR7_GPIO_OUTPUT 0x4
  3953. +#define AR7_GPIO_DIR 0x8
  3954. +#define AR7_GPIO_ENABLE 0xc
  3955. +
  3956. +#define AR7_CHIP_7100 0x18
  3957. +#define AR7_CHIP_7200 0x2b
  3958. +#define AR7_CHIP_7300 0x05
  3959. +
  3960. +/* Interrupts */
  3961. +#define AR7_IRQ_UART0 15
  3962. +#define AR7_IRQ_UART1 16
  3963. +
  3964. +/* Clocks */
  3965. +#define AR7_AFE_CLOCK 35328000
  3966. +#define AR7_REF_CLOCK 25000000
  3967. +#define AR7_XTAL_CLOCK 24000000
  3968. +
  3969. +struct plat_cpmac_data {
  3970. + int reset_bit;
  3971. + int power_bit;
  3972. + u32 phy_mask;
  3973. + char dev_addr[6];
  3974. +};
  3975. +
  3976. +struct plat_dsl_data {
  3977. + int reset_bit_dsl;
  3978. + int reset_bit_sar;
  3979. +};
  3980. +
  3981. +extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
  3982. +
  3983. +static inline u16 ar7_chip_id(void)
  3984. +{
  3985. + return readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff;
  3986. +}
  3987. +
  3988. +static inline u8 ar7_chip_rev(void)
  3989. +{
  3990. + return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) >> 16) & 0xff;
  3991. +}
  3992. +
  3993. +static inline int ar7_cpu_freq(void)
  3994. +{
  3995. + return ar7_cpu_clock;
  3996. +}
  3997. +
  3998. +static inline int ar7_bus_freq(void)
  3999. +{
  4000. + return ar7_bus_clock;
  4001. +}
  4002. +
  4003. +static inline int ar7_vbus_freq(void)
  4004. +{
  4005. + return ar7_bus_clock / 2;
  4006. +}
  4007. +#define ar7_cpmac_freq ar7_vbus_freq
  4008. +
  4009. +static inline int ar7_dsp_freq(void)
  4010. +{
  4011. + return ar7_dsp_clock;
  4012. +}
  4013. +
  4014. +static inline int ar7_has_high_cpmac(void)
  4015. +{
  4016. + u16 chip_id = ar7_chip_id();
  4017. + switch (chip_id) {
  4018. + case AR7_CHIP_7100:
  4019. + case AR7_CHIP_7200:
  4020. + return 0;
  4021. + default:
  4022. + return 1;
  4023. + }
  4024. +}
  4025. +#define ar7_has_high_vlynq ar7_has_high_cpmac
  4026. +#define ar7_has_second_uart ar7_has_high_cpmac
  4027. +
  4028. +static inline void ar7_device_enable(u32 bit)
  4029. +{
  4030. + void *reset_reg =
  4031. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  4032. + writel(readl(reset_reg) | (1 << bit), reset_reg);
  4033. + mdelay(20);
  4034. +}
  4035. +
  4036. +static inline void ar7_device_disable(u32 bit)
  4037. +{
  4038. + void *reset_reg =
  4039. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  4040. + writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  4041. + mdelay(20);
  4042. +}
  4043. +
  4044. +static inline void ar7_device_reset(u32 bit)
  4045. +{
  4046. + ar7_device_disable(bit);
  4047. + ar7_device_enable(bit);
  4048. +}
  4049. +
  4050. +static inline void ar7_device_on(u32 bit)
  4051. +{
  4052. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  4053. + writel(readl(power_reg) | (1 << bit), power_reg);
  4054. + mdelay(20);
  4055. +}
  4056. +
  4057. +static inline void ar7_device_off(u32 bit)
  4058. +{
  4059. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  4060. + writel(readl(power_reg) & ~(1 << bit), power_reg);
  4061. + mdelay(20);
  4062. +}
  4063. +
  4064. +#endif /* __AR7_H__ */
  4065. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/gpio.h linux-2.6.30.5/include/asm-mips/ar7/gpio.h
  4066. --- linux-2.6.30.5.orig/include/asm-mips/ar7/gpio.h 1970-01-01 01:00:00.000000000 +0100
  4067. +++ linux-2.6.30.5/include/asm-mips/ar7/gpio.h 2009-08-26 20:05:02.000000000 +0200
  4068. @@ -0,0 +1,109 @@
  4069. +/*
  4070. + * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  4071. + *
  4072. + * This program is free software; you can redistribute it and/or modify
  4073. + * it under the terms of the GNU General Public License as published by
  4074. + * the Free Software Foundation; either version 2 of the License, or
  4075. + * (at your option) any later version.
  4076. + *
  4077. + * This program is distributed in the hope that it will be useful,
  4078. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4079. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4080. + * GNU General Public License for more details.
  4081. + *
  4082. + * You should have received a copy of the GNU General Public License
  4083. + * along with this program; if not, write to the Free Software
  4084. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  4085. + */
  4086. +
  4087. +#ifndef __AR7_GPIO_H__
  4088. +#define __AR7_GPIO_H__
  4089. +#include <asm/ar7/ar7.h>
  4090. +
  4091. +#define AR7_GPIO_MAX 32
  4092. +
  4093. +extern int gpio_request(unsigned gpio, const char *label);
  4094. +extern void gpio_free(unsigned gpio);
  4095. +
  4096. +/* Common GPIO layer */
  4097. +static inline int gpio_get_value(unsigned gpio)
  4098. +{
  4099. + void __iomem *gpio_in =
  4100. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
  4101. +
  4102. + return readl(gpio_in) & (1 << gpio);
  4103. +}
  4104. +
  4105. +static inline void gpio_set_value(unsigned gpio, int value)
  4106. +{
  4107. + void __iomem *gpio_out =
  4108. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
  4109. + unsigned tmp;
  4110. +
  4111. + tmp = readl(gpio_out) & ~(1 << gpio);
  4112. + if (value)
  4113. + tmp |= 1 << gpio;
  4114. + writel(tmp, gpio_out);
  4115. +}
  4116. +
  4117. +static inline int gpio_direction_input(unsigned gpio)
  4118. +{
  4119. + void __iomem *gpio_dir =
  4120. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  4121. +
  4122. + if (gpio >= AR7_GPIO_MAX)
  4123. + return -EINVAL;
  4124. +
  4125. + writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
  4126. +
  4127. + return 0;
  4128. +}
  4129. +
  4130. +static inline int gpio_direction_output(unsigned gpio, int value)
  4131. +{
  4132. + void __iomem *gpio_dir =
  4133. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  4134. +
  4135. + if (gpio >= AR7_GPIO_MAX)
  4136. + return -EINVAL;
  4137. +
  4138. + gpio_set_value(gpio, value);
  4139. + writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
  4140. +
  4141. + return 0;
  4142. +}
  4143. +
  4144. +static inline int gpio_to_irq(unsigned gpio)
  4145. +{
  4146. + return -EINVAL;
  4147. +}
  4148. +
  4149. +static inline int irq_to_gpio(unsigned irq)
  4150. +{
  4151. + return -EINVAL;
  4152. +}
  4153. +
  4154. +/* Board specific GPIO functions */
  4155. +static inline int ar7_gpio_enable(unsigned gpio)
  4156. +{
  4157. + void __iomem *gpio_en =
  4158. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  4159. +
  4160. + writel(readl(gpio_en) | (1 << gpio), gpio_en);
  4161. +
  4162. + return 0;
  4163. +}
  4164. +
  4165. +static inline int ar7_gpio_disable(unsigned gpio)
  4166. +{
  4167. + void __iomem *gpio_en =
  4168. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  4169. +
  4170. + writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
  4171. +
  4172. + return 0;
  4173. +}
  4174. +
  4175. +#include <asm-generic/gpio.h>
  4176. +
  4177. +#endif
  4178. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/irq.h linux-2.6.30.5/include/asm-mips/ar7/irq.h
  4179. --- linux-2.6.30.5.orig/include/asm-mips/ar7/irq.h 1970-01-01 01:00:00.000000000 +0100
  4180. +++ linux-2.6.30.5/include/asm-mips/ar7/irq.h 2009-08-26 20:05:02.000000000 +0200
  4181. @@ -0,0 +1,16 @@
  4182. +/*
  4183. + * This file is subject to the terms and conditions of the GNU General Public
  4184. + * License. See the file "COPYING" in the main directory of this archive
  4185. + * for more details.
  4186. + *
  4187. + * Shamelessly copied from asm-mips/mach-emma2rh/
  4188. + * Copyright (C) 2003 by Ralf Baechle
  4189. + */
  4190. +#ifndef __ASM_AR7_IRQ_H
  4191. +#define __ASM_AR7_IRQ_H
  4192. +
  4193. +#define NR_IRQS 256
  4194. +
  4195. +#include_next <irq.h>
  4196. +
  4197. +#endif /* __ASM_AR7_IRQ_H */
  4198. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/prom.h linux-2.6.30.5/include/asm-mips/ar7/prom.h
  4199. --- linux-2.6.30.5.orig/include/asm-mips/ar7/prom.h 1970-01-01 01:00:00.000000000 +0100
  4200. +++ linux-2.6.30.5/include/asm-mips/ar7/prom.h 2009-08-26 20:05:02.000000000 +0200
  4201. @@ -0,0 +1,26 @@
  4202. +/*
  4203. + * Copyright (C) 2006, 2007 Florian Fainelli <florian@openwrt.org>
  4204. + *
  4205. + * This program is free software; you can redistribute it and/or modify
  4206. + * it under the terms of the GNU General Public License as published by
  4207. + * the Free Software Foundation; either version 2 of the License, or
  4208. + * (at your option) any later version.
  4209. + *
  4210. + * This program is distributed in the hope that it will be useful,
  4211. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4212. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4213. + * GNU General Public License for more details.
  4214. + *
  4215. + * You should have received a copy of the GNU General Public License
  4216. + * along with this program; if not, write to the Free Software
  4217. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  4218. + */
  4219. +
  4220. +#ifndef __PROM_H__
  4221. +#define __PROM_H__
  4222. +
  4223. +extern char *prom_getenv(const char *name);
  4224. +extern void prom_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
  4225. +extern void prom_meminit(void);
  4226. +
  4227. +#endif /* __PROM_H__ */
  4228. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/spaces.h linux-2.6.30.5/include/asm-mips/ar7/spaces.h
  4229. --- linux-2.6.30.5.orig/include/asm-mips/ar7/spaces.h 1970-01-01 01:00:00.000000000 +0100
  4230. +++ linux-2.6.30.5/include/asm-mips/ar7/spaces.h 2009-08-26 20:05:02.000000000 +0200
  4231. @@ -0,0 +1,32 @@
  4232. +/*
  4233. + * This file is subject to the terms and conditions of the GNU General Public
  4234. + * License. See the file "COPYING" in the main directory of this archive
  4235. + * for more details.
  4236. + *
  4237. + * Copyright (C) 1994 - 1999, 2000, 03, 04 Ralf Baechle
  4238. + * Copyright (C) 2000, 2002 Maciej W. Rozycki
  4239. + * Copyright (C) 1990, 1999, 2000 Silicon Graphics, Inc.
  4240. + */
  4241. +#ifndef _ASM_AR7_SPACES_H
  4242. +#define _ASM_AR7_SPACES_H
  4243. +
  4244. +#define CAC_BASE 0x80000000
  4245. +#define IO_BASE 0xa0000000
  4246. +#define UNCAC_BASE 0xa0000000
  4247. +#define MAP_BASE 0xc0000000
  4248. +
  4249. +/*
  4250. + * This handles the memory map.
  4251. + * We handle pages at KSEG0 for kernels with 32 bit address space.
  4252. + */
  4253. +#define PAGE_OFFSET 0x94000000UL
  4254. +#define PHYS_OFFSET 0x14000000UL
  4255. +
  4256. +/*
  4257. + * Memory above this physical address will be considered highmem.
  4258. + */
  4259. +#ifndef HIGHMEM_START
  4260. +#define HIGHMEM_START 0x40000000UL
  4261. +#endif
  4262. +
  4263. +#endif /* __ASM_AR7_SPACES_H */
  4264. diff -Nur linux-2.6.30.5.orig/include/asm-mips/ar7/war.h linux-2.6.30.5/include/asm-mips/ar7/war.h
  4265. --- linux-2.6.30.5.orig/include/asm-mips/ar7/war.h 1970-01-01 01:00:00.000000000 +0100
  4266. +++ linux-2.6.30.5/include/asm-mips/ar7/war.h 2009-08-26 20:05:02.000000000 +0200
  4267. @@ -0,0 +1,25 @@
  4268. +/*
  4269. + * This file is subject to the terms and conditions of the GNU General Public
  4270. + * License. See the file "COPYING" in the main directory of this archive
  4271. + * for more details.
  4272. + *
  4273. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  4274. + */
  4275. +#ifndef __ASM_MIPS_MACH_BCM947XX_WAR_H
  4276. +#define __ASM_MIPS_MACH_BCM947XX_WAR_H
  4277. +
  4278. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  4279. +#define R4600_V1_HIT_CACHEOP_WAR 0
  4280. +#define R4600_V2_HIT_CACHEOP_WAR 0
  4281. +#define R5432_CP0_INTERRUPT_WAR 0
  4282. +#define BCM1250_M3_WAR 0
  4283. +#define SIBYTE_1956_WAR 0
  4284. +#define MIPS4K_ICACHE_REFILL_WAR 0
  4285. +#define MIPS_CACHE_SYNC_WAR 0
  4286. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  4287. +#define RM9000_CDEX_SMP_WAR 0
  4288. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  4289. +#define R10000_LLSC_WAR 0
  4290. +#define MIPS34K_MISSED_ITLB_WAR 0
  4291. +
  4292. +#endif /* __ASM_MIPS_MACH_BCM947XX_WAR_H */
  4293. diff -Nur linux-2.6.30.5.orig/include/linux/serial_core.h linux-2.6.30.5/include/linux/serial_core.h
  4294. --- linux-2.6.30.5.orig/include/linux/serial_core.h 2009-08-16 23:19:38.000000000 +0200
  4295. +++ linux-2.6.30.5/include/linux/serial_core.h 2009-08-26 20:06:59.000000000 +0200
  4296. @@ -41,6 +41,7 @@
  4297. #define PORT_XSCALE 15
  4298. #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
  4299. #define PORT_OCTEON 17 /* Cavium OCTEON internal UART */
  4300. +#define PORT_AR7 18 /* TI AR7 internal UART */
  4301. #define PORT_MAX_8250 17 /* max port ID */
  4302. /*
  4303. diff -Nur linux-2.6.30.5.orig/include/linux/vlynq.h linux-2.6.30.5/include/linux/vlynq.h
  4304. --- linux-2.6.30.5.orig/include/linux/vlynq.h 1970-01-01 01:00:00.000000000 +0100
  4305. +++ linux-2.6.30.5/include/linux/vlynq.h 2009-08-26 20:05:02.000000000 +0200
  4306. @@ -0,0 +1,161 @@
  4307. +/*
  4308. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  4309. + *
  4310. + * This program is free software; you can redistribute it and/or modify
  4311. + * it under the terms of the GNU General Public License as published by
  4312. + * the Free Software Foundation; either version 2 of the License, or
  4313. + * (at your option) any later version.
  4314. + *
  4315. + * This program is distributed in the hope that it will be useful,
  4316. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4317. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4318. + * GNU General Public License for more details.
  4319. + *
  4320. + * You should have received a copy of the GNU General Public License
  4321. + * along with this program; if not, write to the Free Software
  4322. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  4323. + */
  4324. +
  4325. +#ifndef __VLYNQ_H__
  4326. +#define __VLYNQ_H__
  4327. +
  4328. +#include <linux/device.h>
  4329. +#include <linux/module.h>
  4330. +#include <linux/types.h>
  4331. +
  4332. +#define VLYNQ_NUM_IRQS 32
  4333. +
  4334. +struct vlynq_mapping {
  4335. + u32 size;
  4336. + u32 offset;
  4337. +};
  4338. +
  4339. +enum vlynq_divisor {
  4340. + vlynq_div_auto = 0,
  4341. + vlynq_ldiv1,
  4342. + vlynq_ldiv2,
  4343. + vlynq_ldiv3,
  4344. + vlynq_ldiv4,
  4345. + vlynq_ldiv5,
  4346. + vlynq_ldiv6,
  4347. + vlynq_ldiv7,
  4348. + vlynq_ldiv8,
  4349. + vlynq_rdiv1,
  4350. + vlynq_rdiv2,
  4351. + vlynq_rdiv3,
  4352. + vlynq_rdiv4,
  4353. + vlynq_rdiv5,
  4354. + vlynq_rdiv6,
  4355. + vlynq_rdiv7,
  4356. + vlynq_rdiv8,
  4357. + vlynq_div_external
  4358. +};
  4359. +
  4360. +struct vlynq_device_id {
  4361. + u32 id;
  4362. + enum vlynq_divisor divisor;
  4363. + unsigned long driver_data;
  4364. +};
  4365. +
  4366. +struct vlynq_regs;
  4367. +struct vlynq_device {
  4368. + u32 id, dev_id;
  4369. + int local_irq;
  4370. + int remote_irq;
  4371. + enum vlynq_divisor divisor;
  4372. + u32 regs_start, regs_end;
  4373. + u32 mem_start, mem_end;
  4374. + u32 irq_start, irq_end;
  4375. + int irq;
  4376. + int enabled;
  4377. + struct vlynq_regs *local;
  4378. + struct vlynq_regs *remote;
  4379. + struct device dev;
  4380. +};
  4381. +
  4382. +struct vlynq_driver {
  4383. + char *name;
  4384. + struct vlynq_device_id *id_table;
  4385. + int (*probe)(struct vlynq_device *dev, struct vlynq_device_id *id);
  4386. + void (*remove)(struct vlynq_device *dev);
  4387. + struct device_driver driver;
  4388. +};
  4389. +
  4390. +struct plat_vlynq_ops {
  4391. + int (*on)(struct vlynq_device *dev);
  4392. + void (*off)(struct vlynq_device *dev);
  4393. +};
  4394. +
  4395. +static inline struct vlynq_driver *to_vlynq_driver(struct device_driver *drv)
  4396. +{
  4397. + return container_of(drv, struct vlynq_driver, driver);
  4398. +}
  4399. +
  4400. +static inline struct vlynq_device *to_vlynq_device(struct device *device)
  4401. +{
  4402. + return container_of(device, struct vlynq_device, dev);
  4403. +}
  4404. +
  4405. +extern struct bus_type vlynq_bus_type;
  4406. +
  4407. +extern int __vlynq_register_driver(struct vlynq_driver *driver,
  4408. + struct module *owner);
  4409. +
  4410. +static inline int vlynq_register_driver(struct vlynq_driver *driver)
  4411. +{
  4412. + return __vlynq_register_driver(driver, THIS_MODULE);
  4413. +}
  4414. +
  4415. +static inline void *vlynq_get_drvdata(struct vlynq_device *dev)
  4416. +{
  4417. + return dev_get_drvdata(&dev->dev);
  4418. +}
  4419. +
  4420. +static inline void vlynq_set_drvdata(struct vlynq_device *dev, void *data)
  4421. +{
  4422. + dev_set_drvdata(&dev->dev, data);
  4423. +}
  4424. +
  4425. +static inline u32 vlynq_mem_start(struct vlynq_device *dev)
  4426. +{
  4427. + return dev->mem_start;
  4428. +}
  4429. +
  4430. +static inline u32 vlynq_mem_end(struct vlynq_device *dev)
  4431. +{
  4432. + return dev->mem_end;
  4433. +}
  4434. +
  4435. +static inline u32 vlynq_mem_len(struct vlynq_device *dev)
  4436. +{
  4437. + return dev->mem_end - dev->mem_start + 1;
  4438. +}
  4439. +
  4440. +static inline int vlynq_virq_to_irq(struct vlynq_device *dev, int virq)
  4441. +{
  4442. + int irq = dev->irq_start + virq;
  4443. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4444. + return -EINVAL;
  4445. +
  4446. + return irq;
  4447. +}
  4448. +
  4449. +static inline int vlynq_irq_to_virq(struct vlynq_device *dev, int irq)
  4450. +{
  4451. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  4452. + return -EINVAL;
  4453. +
  4454. + return irq - dev->irq_start;
  4455. +}
  4456. +
  4457. +extern void vlynq_unregister_driver(struct vlynq_driver *driver);
  4458. +extern int vlynq_enable_device(struct vlynq_device *dev);
  4459. +extern void vlynq_disable_device(struct vlynq_device *dev);
  4460. +extern int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  4461. + struct vlynq_mapping *mapping);
  4462. +extern int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  4463. + struct vlynq_mapping *mapping);
  4464. +extern int vlynq_set_local_irq(struct vlynq_device *dev, int virq);
  4465. +extern int vlynq_set_remote_irq(struct vlynq_device *dev, int virq);
  4466. +
  4467. +#endif /* __VLYNQ_H__ */