ar7.patch 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865
  1. diff -Nur linux-2.6.30.orig/arch/mips/Kconfig linux-2.6.30/arch/mips/Kconfig
  2. --- linux-2.6.30.orig/arch/mips/Kconfig 2009-06-10 05:05:27.000000000 +0200
  3. +++ linux-2.6.30/arch/mips/Kconfig 2009-06-11 20:55:34.588179514 +0200
  4. @@ -19,6 +19,24 @@
  5. prompt "System type"
  6. default SGI_IP22
  7. +config AR7
  8. + bool "Texas Instruments AR7"
  9. + select BOOT_ELF32
  10. + select DMA_NONCOHERENT
  11. + select CEVT_R4K
  12. + select CSRC_R4K
  13. + select IRQ_CPU
  14. + select NO_EXCEPT_FILL
  15. + select SWAP_IO_SPACE
  16. + select SYS_HAS_CPU_MIPS32_R1
  17. + select SYS_HAS_EARLY_PRINTK
  18. + select SYS_SUPPORTS_32BIT_KERNEL
  19. + select SYS_SUPPORTS_KGDB
  20. + select SYS_SUPPORTS_LITTLE_ENDIAN
  21. + select SYS_SUPPORTS_BIG_ENDIAN
  22. + select GENERIC_GPIO
  23. + select GENERIC_HARDIRQS_NO__DO_IRQ
  24. +
  25. config MACH_ALCHEMY
  26. bool "Alchemy processor based machines"
  27. diff -Nur linux-2.6.30.orig/arch/mips/Makefile linux-2.6.30/arch/mips/Makefile
  28. --- linux-2.6.30.orig/arch/mips/Makefile 2009-06-10 05:05:27.000000000 +0200
  29. +++ linux-2.6.30/arch/mips/Makefile 2009-06-11 20:55:34.591474348 +0200
  30. @@ -174,6 +174,13 @@
  31. #
  32. #
  33. +# Texas Instruments AR7
  34. +#
  35. +core-$(CONFIG_AR7) += arch/mips/ar7/
  36. +cflags-$(CONFIG_AR7) += -I$(srctree)/arch/mips/include/asm/mach-ar7
  37. +load-$(CONFIG_AR7) += 0xffffffff94100000
  38. +
  39. +#
  40. # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
  41. #
  42. core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
  43. diff -Nur linux-2.6.30.orig/arch/mips/ar7/Makefile linux-2.6.30/arch/mips/ar7/Makefile
  44. --- linux-2.6.30.orig/arch/mips/ar7/Makefile 1970-01-01 01:00:00.000000000 +0100
  45. +++ linux-2.6.30/arch/mips/ar7/Makefile 2009-06-11 20:55:34.591474348 +0200
  46. @@ -0,0 +1,10 @@
  47. +
  48. +obj-y := \
  49. + prom.o \
  50. + setup.o \
  51. + memory.o \
  52. + irq.o \
  53. + time.o \
  54. + platform.o \
  55. + gpio.o \
  56. + clock.o
  57. diff -Nur linux-2.6.30.orig/arch/mips/ar7/clock.c linux-2.6.30/arch/mips/ar7/clock.c
  58. --- linux-2.6.30.orig/arch/mips/ar7/clock.c 1970-01-01 01:00:00.000000000 +0100
  59. +++ linux-2.6.30/arch/mips/ar7/clock.c 2009-06-11 20:55:34.591474348 +0200
  60. @@ -0,0 +1,483 @@
  61. +/*
  62. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  63. + * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
  64. + *
  65. + * This program is free software; you can redistribute it and/or modify
  66. + * it under the terms of the GNU General Public License as published by
  67. + * the Free Software Foundation; either version 2 of the License, or
  68. + * (at your option) any later version.
  69. + *
  70. + * This program is distributed in the hope that it will be useful,
  71. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  72. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  73. + * GNU General Public License for more details.
  74. + *
  75. + * You should have received a copy of the GNU General Public License
  76. + * along with this program; if not, write to the Free Software
  77. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  78. + */
  79. +
  80. +#include <linux/init.h>
  81. +#include <linux/types.h>
  82. +#include <linux/module.h>
  83. +#include <linux/delay.h>
  84. +#include <asm/addrspace.h>
  85. +#include <asm/io.h>
  86. +#include <asm/mach-ar7/ar7.h>
  87. +
  88. +#define BOOT_PLL_SOURCE_MASK 0x3
  89. +#define CPU_PLL_SOURCE_SHIFT 16
  90. +#define BUS_PLL_SOURCE_SHIFT 14
  91. +#define USB_PLL_SOURCE_SHIFT 18
  92. +#define DSP_PLL_SOURCE_SHIFT 22
  93. +#define BOOT_PLL_SOURCE_AFE 0
  94. +#define BOOT_PLL_SOURCE_BUS 0
  95. +#define BOOT_PLL_SOURCE_REF 1
  96. +#define BOOT_PLL_SOURCE_XTAL 2
  97. +#define BOOT_PLL_SOURCE_CPU 3
  98. +#define BOOT_PLL_BYPASS 0x00000020
  99. +#define BOOT_PLL_ASYNC_MODE 0x02000000
  100. +#define BOOT_PLL_2TO1_MODE 0x00008000
  101. +
  102. +#define TNETD7200_CLOCK_ID_CPU 0
  103. +#define TNETD7200_CLOCK_ID_DSP 1
  104. +#define TNETD7200_CLOCK_ID_USB 2
  105. +
  106. +#define TNETD7200_DEF_CPU_CLK 211000000
  107. +#define TNETD7200_DEF_DSP_CLK 125000000
  108. +#define TNETD7200_DEF_USB_CLK 48000000
  109. +
  110. +struct tnetd7300_clock {
  111. + u32 ctrl;
  112. +#define PREDIV_MASK 0x001f0000
  113. +#define PREDIV_SHIFT 16
  114. +#define POSTDIV_MASK 0x0000001f
  115. + u32 unused1[3];
  116. + u32 pll;
  117. +#define MUL_MASK 0x0000f000
  118. +#define MUL_SHIFT 12
  119. +#define PLL_MODE_MASK 0x00000001
  120. +#define PLL_NDIV 0x00000800
  121. +#define PLL_DIV 0x00000002
  122. +#define PLL_STATUS 0x00000001
  123. + u32 unused2[3];
  124. +};
  125. +
  126. +struct tnetd7300_clocks {
  127. + struct tnetd7300_clock bus;
  128. + struct tnetd7300_clock cpu;
  129. + struct tnetd7300_clock usb;
  130. + struct tnetd7300_clock dsp;
  131. +};
  132. +
  133. +struct tnetd7200_clock {
  134. + u32 ctrl;
  135. + u32 unused1[3];
  136. +#define DIVISOR_ENABLE_MASK 0x00008000
  137. + u32 mul;
  138. + u32 prediv;
  139. + u32 postdiv;
  140. + u32 postdiv2;
  141. + u32 unused2[6];
  142. + u32 cmd;
  143. + u32 status;
  144. + u32 cmden;
  145. + u32 padding[15];
  146. +};
  147. +
  148. +struct tnetd7200_clocks {
  149. + struct tnetd7200_clock cpu;
  150. + struct tnetd7200_clock dsp;
  151. + struct tnetd7200_clock usb;
  152. +};
  153. +
  154. +int ar7_cpu_clock = 150000000;
  155. +EXPORT_SYMBOL(ar7_cpu_clock);
  156. +int ar7_bus_clock = 125000000;
  157. +EXPORT_SYMBOL(ar7_bus_clock);
  158. +int ar7_dsp_clock;
  159. +EXPORT_SYMBOL(ar7_dsp_clock);
  160. +
  161. +static int gcd(int a, int b)
  162. +{
  163. + int c;
  164. +
  165. + if (a < b) {
  166. + c = a;
  167. + a = b;
  168. + b = c;
  169. + }
  170. + while ((c = (a % b))) {
  171. + a = b;
  172. + b = c;
  173. + }
  174. + return b;
  175. +}
  176. +
  177. +static void approximate(int base, int target, int *prediv,
  178. + int *postdiv, int *mul)
  179. +{
  180. + int i, j, k, freq, res = target;
  181. + for (i = 1; i <= 16; i++)
  182. + for (j = 1; j <= 32; j++)
  183. + for (k = 1; k <= 32; k++) {
  184. + freq = abs(base / j * i / k - target);
  185. + if (freq < res) {
  186. + res = freq;
  187. + *mul = i;
  188. + *prediv = j;
  189. + *postdiv = k;
  190. + }
  191. + }
  192. +}
  193. +
  194. +static void calculate(int base, int target, int *prediv, int *postdiv,
  195. + int *mul)
  196. +{
  197. + int tmp_gcd, tmp_base, tmp_freq;
  198. +
  199. + for (*prediv = 1; *prediv <= 32; (*prediv)++) {
  200. + tmp_base = base / *prediv;
  201. + tmp_gcd = gcd(target, tmp_base);
  202. + *mul = target / tmp_gcd;
  203. + *postdiv = tmp_base / tmp_gcd;
  204. + if ((*mul < 1) || (*mul >= 16))
  205. + continue;
  206. + if ((*postdiv > 0) & (*postdiv <= 32))
  207. + break;
  208. + }
  209. +
  210. + if (base / (*prediv) * (*mul) / (*postdiv) != target) {
  211. + approximate(base, target, prediv, postdiv, mul);
  212. + tmp_freq = base / (*prediv) * (*mul) / (*postdiv);
  213. + printk(KERN_WARNING
  214. + "Adjusted requested frequency %d to %d\n",
  215. + target, tmp_freq);
  216. + }
  217. +
  218. + printk(KERN_DEBUG "Clocks: prediv: %d, postdiv: %d, mul: %d\n",
  219. + *prediv, *postdiv, *mul);
  220. +}
  221. +
  222. +static int tnetd7300_dsp_clock(void)
  223. +{
  224. + u32 didr1, didr2;
  225. + u8 rev = ar7_chip_rev();
  226. + didr1 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x18));
  227. + didr2 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x1c));
  228. + if (didr2 & (1 << 23))
  229. + return 0;
  230. + if ((rev >= 0x23) && (rev != 0x57))
  231. + return 250000000;
  232. + if ((((didr2 & 0x1fff) << 10) | ((didr1 & 0xffc00000) >> 22))
  233. + > 4208000)
  234. + return 250000000;
  235. + return 0;
  236. +}
  237. +
  238. +static int tnetd7300_get_clock(u32 shift, struct tnetd7300_clock *clock,
  239. + u32 *bootcr, u32 bus_clock)
  240. +{
  241. + int product;
  242. + int base_clock = AR7_REF_CLOCK;
  243. + u32 ctrl = readl(&clock->ctrl);
  244. + u32 pll = readl(&clock->pll);
  245. + int prediv = ((ctrl & PREDIV_MASK) >> PREDIV_SHIFT) + 1;
  246. + int postdiv = (ctrl & POSTDIV_MASK) + 1;
  247. + int divisor = prediv * postdiv;
  248. + int mul = ((pll & MUL_MASK) >> MUL_SHIFT) + 1;
  249. +
  250. + switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
  251. + case BOOT_PLL_SOURCE_BUS:
  252. + base_clock = bus_clock;
  253. + break;
  254. + case BOOT_PLL_SOURCE_REF:
  255. + base_clock = AR7_REF_CLOCK;
  256. + break;
  257. + case BOOT_PLL_SOURCE_XTAL:
  258. + base_clock = AR7_XTAL_CLOCK;
  259. + break;
  260. + case BOOT_PLL_SOURCE_CPU:
  261. + base_clock = ar7_cpu_clock;
  262. + break;
  263. + }
  264. +
  265. + if (*bootcr & BOOT_PLL_BYPASS)
  266. + return base_clock / divisor;
  267. +
  268. + if ((pll & PLL_MODE_MASK) == 0)
  269. + return (base_clock >> (mul / 16 + 1)) / divisor;
  270. +
  271. + if ((pll & (PLL_NDIV | PLL_DIV)) == (PLL_NDIV | PLL_DIV)) {
  272. + product = (mul & 1) ?
  273. + (base_clock * mul) >> 1 :
  274. + (base_clock * (mul - 1)) >> 2;
  275. + return product / divisor;
  276. + }
  277. +
  278. + if (mul == 16)
  279. + return base_clock / divisor;
  280. +
  281. + return base_clock * mul / divisor;
  282. +}
  283. +
  284. +static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
  285. + u32 *bootcr, u32 frequency)
  286. +{
  287. + int prediv, postdiv, mul;
  288. + int base_clock = ar7_bus_clock;
  289. +
  290. + switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
  291. + case BOOT_PLL_SOURCE_BUS:
  292. + base_clock = ar7_bus_clock;
  293. + break;
  294. + case BOOT_PLL_SOURCE_REF:
  295. + base_clock = AR7_REF_CLOCK;
  296. + break;
  297. + case BOOT_PLL_SOURCE_XTAL:
  298. + base_clock = AR7_XTAL_CLOCK;
  299. + break;
  300. + case BOOT_PLL_SOURCE_CPU:
  301. + base_clock = ar7_cpu_clock;
  302. + break;
  303. + }
  304. +
  305. + calculate(base_clock, frequency, &prediv, &postdiv, &mul);
  306. +
  307. + writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl);
  308. + mdelay(1);
  309. + writel(4, &clock->pll);
  310. + while (readl(&clock->pll) & PLL_STATUS);
  311. + writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll);
  312. + mdelay(75);
  313. +}
  314. +
  315. +static void __init tnetd7300_init_clocks(void)
  316. +{
  317. + u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
  318. + struct tnetd7300_clocks *clocks =
  319. + (struct tnetd7300_clocks *)
  320. + ioremap_nocache(AR7_REGS_POWER + 0x20,
  321. + sizeof(struct tnetd7300_clocks));
  322. +
  323. + ar7_bus_clock = tnetd7300_get_clock(BUS_PLL_SOURCE_SHIFT,
  324. + &clocks->bus, bootcr, AR7_AFE_CLOCK);
  325. +
  326. + if (*bootcr & BOOT_PLL_ASYNC_MODE)
  327. + ar7_cpu_clock = tnetd7300_get_clock(CPU_PLL_SOURCE_SHIFT,
  328. + &clocks->cpu, bootcr, AR7_AFE_CLOCK);
  329. + else
  330. + ar7_cpu_clock = ar7_bus_clock;
  331. +/*
  332. + tnetd7300_set_clock(USB_PLL_SOURCE_SHIFT, &clocks->usb,
  333. + bootcr, 48000000);
  334. +*/
  335. + if (ar7_dsp_clock == 250000000)
  336. + tnetd7300_set_clock(DSP_PLL_SOURCE_SHIFT, &clocks->dsp,
  337. + bootcr, ar7_dsp_clock);
  338. +
  339. + iounmap(clocks);
  340. + iounmap(bootcr);
  341. +}
  342. +
  343. +static int tnetd7200_get_clock(int base, struct tnetd7200_clock *clock,
  344. + u32 *bootcr, u32 bus_clock)
  345. +{
  346. + int divisor = ((readl(&clock->prediv) & 0x1f) + 1) *
  347. + ((readl(&clock->postdiv) & 0x1f) + 1);
  348. +
  349. + if (*bootcr & BOOT_PLL_BYPASS)
  350. + return base / divisor;
  351. +
  352. + return base * ((readl(&clock->mul) & 0xf) + 1) / divisor;
  353. +}
  354. +
  355. +
  356. +static void tnetd7200_set_clock(int base, struct tnetd7200_clock *clock,
  357. + int prediv, int postdiv, int postdiv2, int mul, u32 frequency)
  358. +{
  359. + printk(KERN_INFO
  360. + "Clocks: base = %d, frequency = %u, prediv = %d, "
  361. + "postdiv = %d, postdiv2 = %d, mul = %d\n",
  362. + base, frequency, prediv, postdiv, postdiv2, mul);
  363. +
  364. + writel(0, &clock->ctrl);
  365. + writel(DIVISOR_ENABLE_MASK | ((prediv - 1) & 0x1F), &clock->prediv);
  366. + writel((mul - 1) & 0xF, &clock->mul);
  367. +
  368. + for (mul = 0; mul < 2000; mul++) /* nop */;
  369. +
  370. + while (readl(&clock->status) & 0x1) /* nop */;
  371. +
  372. + writel(DIVISOR_ENABLE_MASK | ((postdiv - 1) & 0x1F), &clock->postdiv);
  373. +
  374. + writel(readl(&clock->cmden) | 1, &clock->cmden);
  375. + writel(readl(&clock->cmd) | 1, &clock->cmd);
  376. +
  377. + while (readl(&clock->status) & 0x1) /* nop */;
  378. +
  379. + writel(DIVISOR_ENABLE_MASK | ((postdiv2 - 1) & 0x1F), &clock->postdiv2);
  380. +
  381. + writel(readl(&clock->cmden) | 1, &clock->cmden);
  382. + writel(readl(&clock->cmd) | 1, &clock->cmd);
  383. +
  384. + while (readl(&clock->status) & 0x1) /* nop */;
  385. +
  386. + writel(readl(&clock->ctrl) | 1, &clock->ctrl);
  387. +}
  388. +
  389. +static int tnetd7200_get_clock_base(int clock_id, u32 *bootcr)
  390. +{
  391. + if (*bootcr & BOOT_PLL_ASYNC_MODE)
  392. + /* Async */
  393. + switch (clock_id) {
  394. + case TNETD7200_CLOCK_ID_DSP:
  395. + return AR7_REF_CLOCK;
  396. + default:
  397. + return AR7_AFE_CLOCK;
  398. + }
  399. + else
  400. + /* Sync */
  401. + if (*bootcr & BOOT_PLL_2TO1_MODE)
  402. + /* 2:1 */
  403. + switch (clock_id) {
  404. + case TNETD7200_CLOCK_ID_DSP:
  405. + return AR7_REF_CLOCK;
  406. + default:
  407. + return AR7_AFE_CLOCK;
  408. + }
  409. + else
  410. + /* 1:1 */
  411. + return AR7_REF_CLOCK;
  412. +}
  413. +
  414. +
  415. +static void __init tnetd7200_init_clocks(void)
  416. +{
  417. + u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
  418. + struct tnetd7200_clocks *clocks =
  419. + (struct tnetd7200_clocks *)
  420. + ioremap_nocache(AR7_REGS_POWER + 0x80,
  421. + sizeof(struct tnetd7200_clocks));
  422. + int cpu_base, cpu_mul, cpu_prediv, cpu_postdiv;
  423. + int dsp_base, dsp_mul, dsp_prediv, dsp_postdiv;
  424. + int usb_base, usb_mul, usb_prediv, usb_postdiv;
  425. +
  426. +/*
  427. + Log from Fritz!Box 7170 Annex B:
  428. +
  429. + CPU revision is: 00018448
  430. + Clocks: Async mode
  431. + Clocks: Setting DSP clock
  432. + Clocks: prediv: 1, postdiv: 1, mul: 5
  433. + Clocks: base = 25000000, frequency = 125000000, prediv = 1,
  434. + postdiv = 2, postdiv2 = 1, mul = 10
  435. + Clocks: Setting CPU clock
  436. + Adjusted requested frequency 211000000 to 211968000
  437. + Clocks: prediv: 1, postdiv: 1, mul: 6
  438. + Clocks: base = 35328000, frequency = 211968000, prediv = 1,
  439. + postdiv = 1, postdiv2 = -1, mul = 6
  440. + Clocks: Setting USB clock
  441. + Adjusted requested frequency 48000000 to 48076920
  442. + Clocks: prediv: 13, postdiv: 1, mul: 5
  443. + Clocks: base = 125000000, frequency = 48000000, prediv = 13,
  444. + postdiv = 1, postdiv2 = -1, mul = 5
  445. +
  446. + DSL didn't work if you didn't set the postdiv 2:1 postdiv2 combination,
  447. + driver hung on startup.
  448. + Haven't tested this on a synchronous board,
  449. + neither do i know what to do with ar7_dsp_clock
  450. +*/
  451. +
  452. + cpu_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_CPU, bootcr);
  453. + dsp_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_DSP, bootcr);
  454. +
  455. + if (*bootcr & BOOT_PLL_ASYNC_MODE) {
  456. + printk(KERN_INFO "Clocks: Async mode\n");
  457. +
  458. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  459. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK,
  460. + &dsp_prediv, &dsp_postdiv, &dsp_mul);
  461. + ar7_bus_clock =
  462. + ((dsp_base / dsp_prediv) * dsp_mul) / dsp_postdiv;
  463. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  464. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv, dsp_mul * 2,
  465. + ar7_bus_clock);
  466. +
  467. + printk(KERN_INFO "Clocks: Setting CPU clock\n");
  468. + calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
  469. + &cpu_postdiv, &cpu_mul);
  470. + ar7_cpu_clock =
  471. + ((cpu_base / cpu_prediv) * cpu_mul) / cpu_postdiv;
  472. + tnetd7200_set_clock(cpu_base, &clocks->cpu,
  473. + cpu_prediv, cpu_postdiv, -1, cpu_mul,
  474. + ar7_cpu_clock);
  475. +
  476. + } else
  477. + if (*bootcr & BOOT_PLL_2TO1_MODE) {
  478. + printk(KERN_INFO "Clocks: Sync 2:1 mode\n");
  479. +
  480. + printk(KERN_INFO "Clocks: Setting CPU clock\n");
  481. + calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
  482. + &cpu_postdiv, &cpu_mul);
  483. + ar7_cpu_clock = ((cpu_base / cpu_prediv) * cpu_mul)
  484. + / cpu_postdiv;
  485. + tnetd7200_set_clock(cpu_base, &clocks->cpu,
  486. + cpu_prediv, cpu_postdiv, -1, cpu_mul,
  487. + ar7_cpu_clock);
  488. +
  489. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  490. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
  491. + &dsp_postdiv, &dsp_mul);
  492. + ar7_bus_clock = ar7_cpu_clock / 2;
  493. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  494. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
  495. + dsp_mul * 2, ar7_bus_clock);
  496. + } else {
  497. + printk(KERN_INFO "Clocks: Sync 1:1 mode\n");
  498. +
  499. + printk(KERN_INFO "Clocks: Setting DSP clock\n");
  500. + calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
  501. + &dsp_postdiv, &dsp_mul);
  502. + ar7_bus_clock = ((dsp_base / dsp_prediv) * dsp_mul)
  503. + / dsp_postdiv;
  504. + tnetd7200_set_clock(dsp_base, &clocks->dsp,
  505. + dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
  506. + dsp_mul * 2, ar7_bus_clock);
  507. +
  508. + ar7_cpu_clock = ar7_bus_clock;
  509. + }
  510. +
  511. + printk(KERN_INFO "Clocks: Setting USB clock\n");
  512. + usb_base = ar7_bus_clock;
  513. + calculate(usb_base, TNETD7200_DEF_USB_CLK, &usb_prediv,
  514. + &usb_postdiv, &usb_mul);
  515. + tnetd7200_set_clock(usb_base, &clocks->usb,
  516. + usb_prediv, usb_postdiv, -1, usb_mul,
  517. + TNETD7200_DEF_USB_CLK);
  518. +
  519. + #warning FIXME
  520. + ar7_dsp_clock = ar7_cpu_clock;
  521. +
  522. + iounmap(clocks);
  523. + iounmap(bootcr);
  524. +}
  525. +
  526. +void __init ar7_init_clocks(void)
  527. +{
  528. + switch (ar7_chip_id()) {
  529. + case AR7_CHIP_7100:
  530. +#warning FIXME: Check if the new 7200 clock init works for 7100
  531. + tnetd7200_init_clocks();
  532. + break;
  533. + case AR7_CHIP_7200:
  534. + tnetd7200_init_clocks();
  535. + break;
  536. + case AR7_CHIP_7300:
  537. + ar7_dsp_clock = tnetd7300_dsp_clock();
  538. + tnetd7300_init_clocks();
  539. + break;
  540. + default:
  541. + break;
  542. + }
  543. +}
  544. diff -Nur linux-2.6.30.orig/arch/mips/ar7/gpio.c linux-2.6.30/arch/mips/ar7/gpio.c
  545. --- linux-2.6.30.orig/arch/mips/ar7/gpio.c 1970-01-01 01:00:00.000000000 +0100
  546. +++ linux-2.6.30/arch/mips/ar7/gpio.c 2009-06-11 20:55:34.595485753 +0200
  547. @@ -0,0 +1,49 @@
  548. +/*
  549. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  550. + * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
  551. + *
  552. + * This program is free software; you can redistribute it and/or modify
  553. + * it under the terms of the GNU General Public License as published by
  554. + * the Free Software Foundation; either version 2 of the License, or
  555. + * (at your option) any later version.
  556. + *
  557. + * This program is distributed in the hope that it will be useful,
  558. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  559. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  560. + * GNU General Public License for more details.
  561. + *
  562. + * You should have received a copy of the GNU General Public License
  563. + * along with this program; if not, write to the Free Software
  564. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  565. + */
  566. +
  567. +#include <linux/module.h>
  568. +
  569. +#include <asm/mach-ar7/gpio.h>
  570. +
  571. +static const char *ar7_gpio_list[AR7_GPIO_MAX];
  572. +
  573. +int gpio_request(unsigned gpio, const char *label)
  574. +{
  575. + if (gpio >= AR7_GPIO_MAX)
  576. + return -EINVAL;
  577. +
  578. + if (ar7_gpio_list[gpio])
  579. + return -EBUSY;
  580. +
  581. + if (label) {
  582. + ar7_gpio_list[gpio] = label;
  583. + } else {
  584. + ar7_gpio_list[gpio] = "busy";
  585. + }
  586. +
  587. + return 0;
  588. +}
  589. +EXPORT_SYMBOL(gpio_request);
  590. +
  591. +void gpio_free(unsigned gpio)
  592. +{
  593. + BUG_ON(!ar7_gpio_list[gpio]);
  594. + ar7_gpio_list[gpio] = NULL;
  595. +}
  596. +EXPORT_SYMBOL(gpio_free);
  597. diff -Nur linux-2.6.30.orig/arch/mips/ar7/irq.c linux-2.6.30/arch/mips/ar7/irq.c
  598. --- linux-2.6.30.orig/arch/mips/ar7/irq.c 1970-01-01 01:00:00.000000000 +0100
  599. +++ linux-2.6.30/arch/mips/ar7/irq.c 2009-06-11 20:55:34.595485753 +0200
  600. @@ -0,0 +1,183 @@
  601. +/*
  602. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  603. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  604. + *
  605. + * This program is free software; you can redistribute it and/or modify
  606. + * it under the terms of the GNU General Public License as published by
  607. + * the Free Software Foundation; either version 2 of the License, or
  608. + * (at your option) any later version.
  609. + *
  610. + * This program is distributed in the hope that it will be useful,
  611. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  612. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  613. + * GNU General Public License for more details.
  614. + *
  615. + * You should have received a copy of the GNU General Public License
  616. + * along with this program; if not, write to the Free Software
  617. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  618. + */
  619. +
  620. +#include <linux/interrupt.h>
  621. +#include <linux/io.h>
  622. +
  623. +#include <asm/irq_cpu.h>
  624. +#include <asm/mipsregs.h>
  625. +#include <asm/mach-ar7/ar7.h>
  626. +
  627. +#define EXCEPT_OFFSET 0x80
  628. +#define PACE_OFFSET 0xA0
  629. +#define CHNLS_OFFSET 0x200
  630. +
  631. +#define REG_OFFSET(irq, reg) ((irq) / 32 * 0x4 + reg * 0x10)
  632. +#define SEC_REG_OFFSET(reg) (EXCEPT_OFFSET + reg * 0x8)
  633. +#define SEC_SR_OFFSET (SEC_REG_OFFSET(0)) /* 0x80 */
  634. +#define CR_OFFSET(irq) (REG_OFFSET(irq, 1)) /* 0x10 */
  635. +#define SEC_CR_OFFSET (SEC_REG_OFFSET(1)) /* 0x88 */
  636. +#define ESR_OFFSET(irq) (REG_OFFSET(irq, 2)) /* 0x20 */
  637. +#define SEC_ESR_OFFSET (SEC_REG_OFFSET(2)) /* 0x90 */
  638. +#define ECR_OFFSET(irq) (REG_OFFSET(irq, 3)) /* 0x30 */
  639. +#define SEC_ECR_OFFSET (SEC_REG_OFFSET(3)) /* 0x98 */
  640. +#define PIR_OFFSET (0x40)
  641. +#define MSR_OFFSET (0x44)
  642. +#define PM_OFFSET(irq) (REG_OFFSET(irq, 5)) /* 0x50 */
  643. +#define TM_OFFSET(irq) (REG_OFFSET(irq, 6)) /* 0x60 */
  644. +
  645. +#define REG(addr) ((u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
  646. +
  647. +#define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
  648. +
  649. +static void ar7_unmask_irq(unsigned int irq_nr);
  650. +static void ar7_mask_irq(unsigned int irq_nr);
  651. +static void ar7_ack_irq(unsigned int irq_nr);
  652. +static void ar7_unmask_sec_irq(unsigned int irq_nr);
  653. +static void ar7_mask_sec_irq(unsigned int irq_nr);
  654. +static void ar7_ack_sec_irq(unsigned int irq_nr);
  655. +static void ar7_cascade(void);
  656. +static void ar7_irq_init(int base);
  657. +static int ar7_irq_base;
  658. +
  659. +static struct irq_chip ar7_irq_type = {
  660. + .name = "AR7",
  661. + .unmask = ar7_unmask_irq,
  662. + .mask = ar7_mask_irq,
  663. + .ack = ar7_ack_irq
  664. +};
  665. +
  666. +static struct irq_chip ar7_sec_irq_type = {
  667. + .name = "AR7",
  668. + .unmask = ar7_unmask_sec_irq,
  669. + .mask = ar7_mask_sec_irq,
  670. + .ack = ar7_ack_sec_irq,
  671. +};
  672. +
  673. +static struct irqaction ar7_cascade_action = {
  674. + .handler = no_action,
  675. + .name = "AR7 cascade interrupt"
  676. +};
  677. +
  678. +static void ar7_unmask_irq(unsigned int irq)
  679. +{
  680. + writel(1 << ((irq - ar7_irq_base) % 32),
  681. + REG(ESR_OFFSET(irq - ar7_irq_base)));
  682. +}
  683. +
  684. +static void ar7_mask_irq(unsigned int irq)
  685. +{
  686. + writel(1 << ((irq - ar7_irq_base) % 32),
  687. + REG(ECR_OFFSET(irq - ar7_irq_base)));
  688. +}
  689. +
  690. +static void ar7_ack_irq(unsigned int irq)
  691. +{
  692. + writel(1 << ((irq - ar7_irq_base) % 32),
  693. + REG(CR_OFFSET(irq - ar7_irq_base)));
  694. +}
  695. +
  696. +static void ar7_unmask_sec_irq(unsigned int irq)
  697. +{
  698. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ESR_OFFSET));
  699. +}
  700. +
  701. +static void ar7_mask_sec_irq(unsigned int irq)
  702. +{
  703. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ECR_OFFSET));
  704. +}
  705. +
  706. +static void ar7_ack_sec_irq(unsigned int irq)
  707. +{
  708. + writel(1 << (irq - ar7_irq_base - 40), REG(SEC_CR_OFFSET));
  709. +}
  710. +
  711. +void __init arch_init_irq(void) {
  712. + mips_cpu_irq_init();
  713. + ar7_irq_init(8);
  714. +}
  715. +
  716. +static void __init ar7_irq_init(int base)
  717. +{
  718. + int i;
  719. + /*
  720. + * Disable interrupts and clear pending
  721. + */
  722. + writel(0xffffffff, REG(ECR_OFFSET(0)));
  723. + writel(0xff, REG(ECR_OFFSET(32)));
  724. + writel(0xffffffff, REG(SEC_ECR_OFFSET));
  725. + writel(0xffffffff, REG(CR_OFFSET(0)));
  726. + writel(0xff, REG(CR_OFFSET(32)));
  727. + writel(0xffffffff, REG(SEC_CR_OFFSET));
  728. +
  729. + ar7_irq_base = base;
  730. +
  731. + for (i = 0; i < 40; i++) {
  732. + writel(i, REG(CHNL_OFFSET(i)));
  733. + /* Primary IRQ's */
  734. + set_irq_chip_and_handler(base + i, &ar7_irq_type,
  735. + handle_level_irq);
  736. + /* Secondary IRQ's */
  737. + if (i < 32)
  738. + set_irq_chip_and_handler(base + i + 40,
  739. + &ar7_sec_irq_type,
  740. + handle_level_irq);
  741. + }
  742. +
  743. + setup_irq(2, &ar7_cascade_action);
  744. + setup_irq(ar7_irq_base, &ar7_cascade_action);
  745. + set_c0_status(IE_IRQ0);
  746. +}
  747. +
  748. +static void ar7_cascade(void)
  749. +{
  750. + u32 status;
  751. + int i, irq;
  752. +
  753. + /* Primary IRQ's */
  754. + irq = readl(REG(PIR_OFFSET)) & 0x3f;
  755. + if (irq) {
  756. + do_IRQ(ar7_irq_base + irq);
  757. + return;
  758. + }
  759. +
  760. + /* Secondary IRQ's are cascaded through primary '0' */
  761. + writel(1, REG(CR_OFFSET(irq)));
  762. + status = readl(REG(SEC_SR_OFFSET));
  763. + for (i = 0; i < 32; i++) {
  764. + if (status & 1) {
  765. + do_IRQ(ar7_irq_base + i + 40);
  766. + return;
  767. + }
  768. + status >>= 1;
  769. + }
  770. +
  771. + spurious_interrupt();
  772. +}
  773. +
  774. +asmlinkage void plat_irq_dispatch(void)
  775. +{
  776. + unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  777. + if (pending & STATUSF_IP7) /* cpu timer */
  778. + do_IRQ(7);
  779. + else if (pending & STATUSF_IP2) /* int0 hardware line */
  780. + ar7_cascade();
  781. + else
  782. + spurious_interrupt();
  783. +}
  784. diff -Nur linux-2.6.30.orig/arch/mips/ar7/memory.c linux-2.6.30/arch/mips/ar7/memory.c
  785. --- linux-2.6.30.orig/arch/mips/ar7/memory.c 1970-01-01 01:00:00.000000000 +0100
  786. +++ linux-2.6.30/arch/mips/ar7/memory.c 2009-06-11 20:55:34.595485753 +0200
  787. @@ -0,0 +1,74 @@
  788. +/*
  789. + * Based on arch/mips/mm/init.c
  790. + * Copyright (C) 1994 - 2000 Ralf Baechle
  791. + * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  792. + * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  793. + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  794. + *
  795. + * This program is free software; you can redistribute it and/or modify
  796. + * it under the terms of the GNU General Public License as published by
  797. + * the Free Software Foundation; either version 2 of the License, or
  798. + * (at your option) any later version.
  799. + *
  800. + * This program is distributed in the hope that it will be useful,
  801. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  802. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  803. + * GNU General Public License for more details.
  804. + *
  805. + * You should have received a copy of the GNU General Public License
  806. + * along with this program; if not, write to the Free Software
  807. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  808. + */
  809. +#include <linux/bootmem.h>
  810. +#include <linux/init.h>
  811. +#include <linux/mm.h>
  812. +#include <linux/module.h>
  813. +#include <linux/pfn.h>
  814. +#include <linux/proc_fs.h>
  815. +#include <linux/string.h>
  816. +#include <linux/swap.h>
  817. +
  818. +#include <asm/bootinfo.h>
  819. +#include <asm/page.h>
  820. +#include <asm/sections.h>
  821. +
  822. +#include <asm/mips-boards/prom.h>
  823. +
  824. +static int __init memsize(void)
  825. +{
  826. + u32 size = (64 << 20);
  827. + u32 *addr = (u32 *)KSEG1ADDR(0x14000000 + size - 4);
  828. + u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end));
  829. + u32 *tmpaddr = addr;
  830. +
  831. + while (tmpaddr > kernel_end) {
  832. + *tmpaddr = (u32)tmpaddr;
  833. + size >>= 1;
  834. + tmpaddr -= size >> 2;
  835. + }
  836. +
  837. + do {
  838. + tmpaddr += size >> 2;
  839. + if (*tmpaddr != (u32)tmpaddr)
  840. + break;
  841. + size <<= 1;
  842. + } while (size < (64 << 20));
  843. +
  844. + writel(tmpaddr, &addr);
  845. +
  846. + return size;
  847. +}
  848. +
  849. +void __init prom_meminit(void)
  850. +{
  851. + unsigned long pages;
  852. +
  853. + pages = memsize() >> PAGE_SHIFT;
  854. + add_memory_region(PHYS_OFFSET, pages << PAGE_SHIFT,
  855. + BOOT_MEM_RAM);
  856. +}
  857. +
  858. +void __init prom_free_prom_memory(void)
  859. +{
  860. + return;
  861. +}
  862. diff -Nur linux-2.6.30.orig/arch/mips/ar7/platform.c linux-2.6.30/arch/mips/ar7/platform.c
  863. --- linux-2.6.30.orig/arch/mips/ar7/platform.c 1970-01-01 01:00:00.000000000 +0100
  864. +++ linux-2.6.30/arch/mips/ar7/platform.c 2009-06-11 20:55:34.599474529 +0200
  865. @@ -0,0 +1,554 @@
  866. +/*
  867. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  868. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  869. + *
  870. + * This program is free software; you can redistribute it and/or modify
  871. + * it under the terms of the GNU General Public License as published by
  872. + * the Free Software Foundation; either version 2 of the License, or
  873. + * (at your option) any later version.
  874. + *
  875. + * This program is distributed in the hope that it will be useful,
  876. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  877. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  878. + * GNU General Public License for more details.
  879. + *
  880. + * You should have received a copy of the GNU General Public License
  881. + * along with this program; if not, write to the Free Software
  882. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  883. + */
  884. +
  885. +#include <linux/autoconf.h>
  886. +#include <linux/init.h>
  887. +#include <linux/types.h>
  888. +#include <linux/module.h>
  889. +#include <linux/delay.h>
  890. +#include <linux/dma-mapping.h>
  891. +#include <linux/platform_device.h>
  892. +#include <linux/mtd/physmap.h>
  893. +#include <linux/serial.h>
  894. +#include <linux/serial_8250.h>
  895. +#include <linux/ioport.h>
  896. +#include <linux/io.h>
  897. +#include <linux/version.h>
  898. +#include <linux/vlynq.h>
  899. +#include <linux/leds.h>
  900. +#include <linux/string.h>
  901. +#include <linux/phy.h>
  902. +#include <linux/phy_fixed.h>
  903. +
  904. +
  905. +#include <asm/addrspace.h>
  906. +#include <asm/mach-ar7/ar7.h>
  907. +#include <asm/mach-ar7/gpio.h>
  908. +#include <asm/mach-ar7/prom.h>
  909. +
  910. +struct plat_vlynq_data {
  911. + struct plat_vlynq_ops ops;
  912. + int gpio_bit;
  913. + int reset_bit;
  914. +};
  915. +
  916. +
  917. +static int vlynq_on(struct vlynq_device *dev)
  918. +{
  919. + int result;
  920. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  921. +
  922. + if ((result = gpio_request(pdata->gpio_bit, "vlynq")))
  923. + goto out;
  924. +
  925. + ar7_device_reset(pdata->reset_bit);
  926. +
  927. + if ((result = ar7_gpio_disable(pdata->gpio_bit)))
  928. + goto out_enabled;
  929. +
  930. + if ((result = ar7_gpio_enable(pdata->gpio_bit)))
  931. + goto out_enabled;
  932. +
  933. + if ((result = gpio_direction_output(pdata->gpio_bit, 0)))
  934. + goto out_gpio_enabled;
  935. +
  936. + mdelay(50);
  937. +
  938. + gpio_set_value(pdata->gpio_bit, 1);
  939. + mdelay(50);
  940. +
  941. + return 0;
  942. +
  943. +out_gpio_enabled:
  944. + ar7_gpio_disable(pdata->gpio_bit);
  945. +out_enabled:
  946. + ar7_device_disable(pdata->reset_bit);
  947. + gpio_free(pdata->gpio_bit);
  948. +out:
  949. + return result;
  950. +}
  951. +
  952. +static void vlynq_off(struct vlynq_device *dev)
  953. +{
  954. + struct plat_vlynq_data *pdata = dev->dev.platform_data;
  955. + ar7_gpio_disable(pdata->gpio_bit);
  956. + gpio_free(pdata->gpio_bit);
  957. + ar7_device_disable(pdata->reset_bit);
  958. +}
  959. +
  960. +static struct resource physmap_flash_resource = {
  961. + .name = "mem",
  962. + .flags = IORESOURCE_MEM,
  963. + .start = 0x10000000,
  964. + .end = 0x107fffff,
  965. +};
  966. +
  967. +static struct resource cpmac_low_res[] = {
  968. + {
  969. + .name = "regs",
  970. + .flags = IORESOURCE_MEM,
  971. + .start = AR7_REGS_MAC0,
  972. + .end = AR7_REGS_MAC0 + 0x7ff,
  973. + },
  974. + {
  975. + .name = "irq",
  976. + .flags = IORESOURCE_IRQ,
  977. + .start = 27,
  978. + .end = 27,
  979. + },
  980. +};
  981. +
  982. +static struct resource cpmac_high_res[] = {
  983. + {
  984. + .name = "regs",
  985. + .flags = IORESOURCE_MEM,
  986. + .start = AR7_REGS_MAC1,
  987. + .end = AR7_REGS_MAC1 + 0x7ff,
  988. + },
  989. + {
  990. + .name = "irq",
  991. + .flags = IORESOURCE_IRQ,
  992. + .start = 41,
  993. + .end = 41,
  994. + },
  995. +};
  996. +
  997. +static struct resource vlynq_low_res[] = {
  998. + {
  999. + .name = "regs",
  1000. + .flags = IORESOURCE_MEM,
  1001. + .start = AR7_REGS_VLYNQ0,
  1002. + .end = AR7_REGS_VLYNQ0 + 0xff,
  1003. + },
  1004. + {
  1005. + .name = "irq",
  1006. + .flags = IORESOURCE_IRQ,
  1007. + .start = 29,
  1008. + .end = 29,
  1009. + },
  1010. + {
  1011. + .name = "mem",
  1012. + .flags = IORESOURCE_MEM,
  1013. + .start = 0x04000000,
  1014. + .end = 0x04ffffff,
  1015. + },
  1016. + {
  1017. + .name = "devirq",
  1018. + .flags = IORESOURCE_IRQ,
  1019. + .start = 80,
  1020. + .end = 111,
  1021. + },
  1022. +};
  1023. +
  1024. +static struct resource vlynq_high_res[] = {
  1025. + {
  1026. + .name = "regs",
  1027. + .flags = IORESOURCE_MEM,
  1028. + .start = AR7_REGS_VLYNQ1,
  1029. + .end = AR7_REGS_VLYNQ1 + 0xff,
  1030. + },
  1031. + {
  1032. + .name = "irq",
  1033. + .flags = IORESOURCE_IRQ,
  1034. + .start = 33,
  1035. + .end = 33,
  1036. + },
  1037. + {
  1038. + .name = "mem",
  1039. + .flags = IORESOURCE_MEM,
  1040. + .start = 0x0c000000,
  1041. + .end = 0x0cffffff,
  1042. + },
  1043. + {
  1044. + .name = "devirq",
  1045. + .flags = IORESOURCE_IRQ,
  1046. + .start = 112,
  1047. + .end = 143,
  1048. + },
  1049. +};
  1050. +
  1051. +static struct resource usb_res[] = {
  1052. + {
  1053. + .name = "regs",
  1054. + .flags = IORESOURCE_MEM,
  1055. + .start = AR7_REGS_USB,
  1056. + .end = AR7_REGS_USB + 0xff,
  1057. + },
  1058. + {
  1059. + .name = "irq",
  1060. + .flags = IORESOURCE_IRQ,
  1061. + .start = 32,
  1062. + .end = 32,
  1063. + },
  1064. + {
  1065. + .name = "mem",
  1066. + .flags = IORESOURCE_MEM,
  1067. + .start = 0x03400000,
  1068. + .end = 0x034001fff,
  1069. + },
  1070. +};
  1071. +
  1072. +static struct physmap_flash_data physmap_flash_data = {
  1073. + .width = 2,
  1074. +};
  1075. +
  1076. +/* lets assume this is suitable for both high and low cpmacs links */
  1077. +static struct fixed_phy_status fixed_phy_status __initdata = {
  1078. + .link = 1,
  1079. + .speed = 100,
  1080. + .duplex = 1,
  1081. +};
  1082. +
  1083. +static struct plat_cpmac_data cpmac_low_data = {
  1084. + .reset_bit = 17,
  1085. + .power_bit = 20,
  1086. + .phy_mask = 0x80000000,
  1087. +};
  1088. +
  1089. +static struct plat_cpmac_data cpmac_high_data = {
  1090. + .reset_bit = 21,
  1091. + .power_bit = 22,
  1092. + .phy_mask = 0x7fffffff,
  1093. +};
  1094. +
  1095. +static struct plat_vlynq_data vlynq_low_data = {
  1096. + .ops.on = vlynq_on,
  1097. + .ops.off = vlynq_off,
  1098. + .reset_bit = 20,
  1099. + .gpio_bit = 18,
  1100. +};
  1101. +
  1102. +static struct plat_vlynq_data vlynq_high_data = {
  1103. + .ops.on = vlynq_on,
  1104. + .ops.off = vlynq_off,
  1105. + .reset_bit = 16,
  1106. + .gpio_bit = 19,
  1107. +};
  1108. +
  1109. +static struct platform_device physmap_flash = {
  1110. + .id = 0,
  1111. + .name = "physmap-flash",
  1112. + .dev.platform_data = &physmap_flash_data,
  1113. + .resource = &physmap_flash_resource,
  1114. + .num_resources = 1,
  1115. +};
  1116. +
  1117. +static u64 cpmac_dma_mask = DMA_32BIT_MASK;
  1118. +static struct platform_device cpmac_low = {
  1119. + .id = 0,
  1120. + .name = "cpmac",
  1121. + .dev = {
  1122. + .dma_mask = &cpmac_dma_mask,
  1123. + .coherent_dma_mask = DMA_32BIT_MASK,
  1124. + .platform_data = &cpmac_low_data,
  1125. + },
  1126. + .resource = cpmac_low_res,
  1127. + .num_resources = ARRAY_SIZE(cpmac_low_res),
  1128. +};
  1129. +
  1130. +static struct platform_device cpmac_high = {
  1131. + .id = 1,
  1132. + .name = "cpmac",
  1133. + .dev = {
  1134. + .dma_mask = &cpmac_dma_mask,
  1135. + .coherent_dma_mask = DMA_32BIT_MASK,
  1136. + .platform_data = &cpmac_high_data,
  1137. + },
  1138. + .resource = cpmac_high_res,
  1139. + .num_resources = ARRAY_SIZE(cpmac_high_res),
  1140. +};
  1141. +
  1142. +static struct platform_device vlynq_low = {
  1143. + .id = 0,
  1144. + .name = "vlynq",
  1145. + .dev.platform_data = &vlynq_low_data,
  1146. + .resource = vlynq_low_res,
  1147. + .num_resources = ARRAY_SIZE(vlynq_low_res),
  1148. +};
  1149. +
  1150. +static struct platform_device vlynq_high = {
  1151. + .id = 1,
  1152. + .name = "vlynq",
  1153. + .dev.platform_data = &vlynq_high_data,
  1154. + .resource = vlynq_high_res,
  1155. + .num_resources = ARRAY_SIZE(vlynq_high_res),
  1156. +};
  1157. +
  1158. +
  1159. +/* This is proper way to define uart ports, but they are then detected
  1160. + * as xscale and, obviously, don't work...
  1161. + */
  1162. +#if !defined(CONFIG_SERIAL_8250)
  1163. +
  1164. +static struct plat_serial8250_port uart0_data = {
  1165. + .mapbase = AR7_REGS_UART0,
  1166. + .irq = AR7_IRQ_UART0,
  1167. + .regshift = 2,
  1168. + .iotype = UPIO_MEM,
  1169. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1170. +};
  1171. +
  1172. +static struct plat_serial8250_port uart1_data = {
  1173. + .mapbase = UR8_REGS_UART1,
  1174. + .irq = AR7_IRQ_UART1,
  1175. + .regshift = 2,
  1176. + .iotype = UPIO_MEM,
  1177. + .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  1178. +};
  1179. +
  1180. +static struct plat_serial8250_port uart_data[] = {
  1181. + uart0_data,
  1182. + uart1_data,
  1183. + { .flags = 0 }
  1184. +};
  1185. +
  1186. +static struct plat_serial8250_port uart_data_single[] = {
  1187. + uart0_data,
  1188. + { .flags = 0 }
  1189. +};
  1190. +
  1191. +static struct platform_device uart = {
  1192. + .id = 0,
  1193. + .name = "serial8250",
  1194. + .dev.platform_data = uart_data_single
  1195. +};
  1196. +#endif
  1197. +
  1198. +static struct gpio_led default_leds[] = {
  1199. + { .name = "status", .gpio = 8, .active_low = 1, },
  1200. +};
  1201. +
  1202. +static struct gpio_led dsl502t_leds[] = {
  1203. + { .name = "status", .gpio = 9, .active_low = 1, },
  1204. + { .name = "ethernet", .gpio = 7, .active_low = 1, },
  1205. + { .name = "usb", .gpio = 12, .active_low = 1, },
  1206. +};
  1207. +
  1208. +static struct gpio_led dg834g_leds[] = {
  1209. + { .name = "ppp", .gpio = 6, .active_low = 1, },
  1210. + { .name = "status", .gpio = 7, .active_low = 1, },
  1211. + { .name = "adsl", .gpio = 8, .active_low = 1, },
  1212. + { .name = "wifi", .gpio = 12, .active_low = 1, },
  1213. + { .name = "power", .gpio = 14, .active_low = 1, .default_trigger = "default-on", },
  1214. +};
  1215. +
  1216. +static struct gpio_led fb_sl_leds[] = {
  1217. + { .name = "1", .gpio = 7, },
  1218. + { .name = "2", .gpio = 13, .active_low = 1, },
  1219. + { .name = "3", .gpio = 10, .active_low = 1, },
  1220. + { .name = "4", .gpio = 12, .active_low = 1, },
  1221. + { .name = "5", .gpio = 9, .active_low = 1, },
  1222. +};
  1223. +
  1224. +static struct gpio_led fb_fon_leds[] = {
  1225. + { .name = "1", .gpio = 8, },
  1226. + { .name = "2", .gpio = 3, .active_low = 1, },
  1227. + { .name = "3", .gpio = 5, },
  1228. + { .name = "4", .gpio = 4, .active_low = 1, },
  1229. + { .name = "5", .gpio = 11, .active_low = 1, },
  1230. +};
  1231. +
  1232. +static struct gpio_led_platform_data ar7_led_data;
  1233. +
  1234. +static struct platform_device ar7_gpio_leds = {
  1235. + .name = "leds-gpio",
  1236. + .id = -1,
  1237. + .dev = {
  1238. + .platform_data = &ar7_led_data,
  1239. + }
  1240. +};
  1241. +
  1242. +static struct platform_device ar7_udc = {
  1243. + .id = -1,
  1244. + .name = "ar7_udc",
  1245. + .resource = usb_res,
  1246. + .num_resources = ARRAY_SIZE(usb_res),
  1247. +};
  1248. +
  1249. +static inline unsigned char char2hex(char h)
  1250. +{
  1251. + switch (h) {
  1252. + case '0': case '1': case '2': case '3': case '4':
  1253. + case '5': case '6': case '7': case '8': case '9':
  1254. + return h - '0';
  1255. + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  1256. + return h - 'A' + 10;
  1257. + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  1258. + return h - 'a' + 10;
  1259. + default:
  1260. + return 0;
  1261. + }
  1262. +}
  1263. +
  1264. +static void cpmac_get_mac(int instance, unsigned char *dev_addr)
  1265. +{
  1266. + int i;
  1267. + char name[5], default_mac[] = "00:00:00:12:34:56", *mac;
  1268. +
  1269. + mac = NULL;
  1270. + sprintf(name, "mac%c", 'a' + instance);
  1271. + mac = prom_getenv(name);
  1272. + if (!mac) {
  1273. + sprintf(name, "mac%c", 'a');
  1274. + mac = prom_getenv(name);
  1275. + }
  1276. + if (!mac)
  1277. + mac = default_mac;
  1278. + for (i = 0; i < 6; i++)
  1279. + dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
  1280. + char2hex(mac[i * 3 + 1]);
  1281. +}
  1282. +
  1283. +static void __init detect_leds(void)
  1284. +{
  1285. + char *prId, *usb_prod;
  1286. +
  1287. + /* Default LEDs */
  1288. + ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
  1289. + ar7_led_data.leds = default_leds;
  1290. +
  1291. + /* FIXME: the whole thing is unreliable */
  1292. + prId = prom_getenv("ProductID");
  1293. + usb_prod = prom_getenv("usb_prod");
  1294. +
  1295. + /* If we can't get the product id from PROM, use the default LEDs */
  1296. + if (!prId)
  1297. + return;
  1298. +
  1299. + if (strstr(prId, "Fritz_Box_FON")) {
  1300. + ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
  1301. + ar7_led_data.leds = fb_fon_leds;
  1302. + } else if (strstr(prId, "Fritz_Box_")) {
  1303. + ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
  1304. + ar7_led_data.leds = fb_sl_leds;
  1305. + } else if ((!strcmp(prId, "AR7RD") || !strcmp(prId, "AR7DB")) && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
  1306. + ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
  1307. + ar7_led_data.leds = dsl502t_leds;
  1308. + } else if (strstr(prId, "DG834")) {
  1309. + ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
  1310. + ar7_led_data.leds = dg834g_leds;
  1311. + }
  1312. +}
  1313. +
  1314. +static int __init ar7_register_devices(void)
  1315. +{
  1316. + int res;
  1317. +
  1318. +#ifdef CONFIG_SERIAL_8250
  1319. +
  1320. + static struct uart_port uart_port[2];
  1321. +
  1322. + memset(uart_port, 0, sizeof(struct uart_port) * 2);
  1323. +
  1324. + // use default type
  1325. + //uart_port[0].type = PORT_AR7;
  1326. + uart_port[0].line = 0;
  1327. + uart_port[0].irq = AR7_IRQ_UART0;
  1328. + uart_port[0].uartclk = ar7_bus_freq() / 2;
  1329. + uart_port[0].iotype = UPIO_MEM;
  1330. + uart_port[0].mapbase = AR7_REGS_UART0;
  1331. + uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
  1332. + uart_port[0].regshift = 2;
  1333. + res = early_serial_setup(&uart_port[0]);
  1334. + if (res)
  1335. + return res;
  1336. +
  1337. +
  1338. + /* Only TNETD73xx have a second serial port */
  1339. + if (ar7_has_second_uart()) {
  1340. + // use default type
  1341. + //uart_port[1].type = PORT_AR7;
  1342. + uart_port[1].line = 1;
  1343. + uart_port[1].irq = AR7_IRQ_UART1;
  1344. + uart_port[1].uartclk = ar7_bus_freq() / 2;
  1345. + uart_port[1].iotype = UPIO_MEM;
  1346. + uart_port[1].mapbase = UR8_REGS_UART1;
  1347. + uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
  1348. + uart_port[1].regshift = 2;
  1349. + res = early_serial_setup(&uart_port[1]);
  1350. + if (res)
  1351. + return res;
  1352. + }
  1353. +
  1354. +#else /* !CONFIG_SERIAL_8250 */
  1355. +
  1356. + uart_data[0].uartclk = ar7_bus_freq() / 2;
  1357. + uart_data[1].uartclk = uart_data[0].uartclk;
  1358. +
  1359. + /* Only TNETD73xx have a second serial port */
  1360. + if (ar7_has_second_uart())
  1361. + uart.dev.platform_data = uart_data;
  1362. +
  1363. + res = platform_device_register(&uart);
  1364. + if (res)
  1365. + return res;
  1366. +
  1367. +#endif /* CONFIG_SERIAL_8250 */
  1368. +
  1369. + res = platform_device_register(&physmap_flash);
  1370. + if (res)
  1371. + return res;
  1372. +
  1373. + ar7_device_disable(vlynq_low_data.reset_bit);
  1374. + res = platform_device_register(&vlynq_low);
  1375. + if (res)
  1376. + return res;
  1377. +
  1378. + if (ar7_has_high_vlynq()) {
  1379. + ar7_device_disable(vlynq_high_data.reset_bit);
  1380. + res = platform_device_register(&vlynq_high);
  1381. + if (res)
  1382. + return res;
  1383. + }
  1384. +
  1385. + if (ar7_has_high_cpmac()) {
  1386. + res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
  1387. + if (res && res != -ENODEV) {
  1388. + return res;
  1389. + }
  1390. + cpmac_get_mac(1, cpmac_high_data.dev_addr);
  1391. + res = platform_device_register(&cpmac_high);
  1392. + if (res)
  1393. + return res;
  1394. + } else {
  1395. + cpmac_low_data.phy_mask = 0xffffffff;
  1396. + }
  1397. +
  1398. + res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
  1399. + if (res && res != -ENODEV) {
  1400. + return res;
  1401. + }
  1402. +
  1403. + cpmac_get_mac(0, cpmac_low_data.dev_addr);
  1404. + res = platform_device_register(&cpmac_low);
  1405. + if (res)
  1406. + return res;
  1407. +
  1408. + detect_leds();
  1409. + res = platform_device_register(&ar7_gpio_leds);
  1410. + if (res)
  1411. + return res;
  1412. +
  1413. + res = platform_device_register(&ar7_udc);
  1414. +
  1415. + return res;
  1416. +}
  1417. +
  1418. +
  1419. +arch_initcall(ar7_register_devices);
  1420. diff -Nur linux-2.6.30.orig/arch/mips/ar7/prom.c linux-2.6.30/arch/mips/ar7/prom.c
  1421. --- linux-2.6.30.orig/arch/mips/ar7/prom.c 1970-01-01 01:00:00.000000000 +0100
  1422. +++ linux-2.6.30/arch/mips/ar7/prom.c 2009-06-11 20:55:34.599474529 +0200
  1423. @@ -0,0 +1,321 @@
  1424. +/*
  1425. + * Carsten Langgaard, carstenl@mips.com
  1426. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1427. + *
  1428. + * This program is free software; you can distribute it and/or modify it
  1429. + * under the terms of the GNU General Public License (Version 2) as
  1430. + * published by the Free Software Foundation.
  1431. + *
  1432. + * This program is distributed in the hope it will be useful, but WITHOUT
  1433. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1434. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1435. + * for more details.
  1436. + *
  1437. + * You should have received a copy of the GNU General Public License along
  1438. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1439. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1440. + *
  1441. + * Putting things on the screen/serial line using YAMONs facilities.
  1442. + */
  1443. +#include <linux/init.h>
  1444. +#include <linux/kernel.h>
  1445. +#include <linux/serial_reg.h>
  1446. +#include <linux/spinlock.h>
  1447. +#include <linux/module.h>
  1448. +#include <linux/string.h>
  1449. +#include <linux/io.h>
  1450. +#include <asm/bootinfo.h>
  1451. +
  1452. +#include <asm/mach-ar7/ar7.h>
  1453. +#include <asm/mach-ar7/prom.h>
  1454. +
  1455. +#define MAX_ENTRY 80
  1456. +
  1457. +struct env_var {
  1458. + char *name;
  1459. + char *value;
  1460. +};
  1461. +
  1462. +static struct env_var adam2_env[MAX_ENTRY] = { { 0, }, };
  1463. +
  1464. +char *prom_getenv(const char *name)
  1465. +{
  1466. + int i;
  1467. + for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
  1468. + if (!strcmp(name, adam2_env[i].name))
  1469. + return adam2_env[i].value;
  1470. +
  1471. + return NULL;
  1472. +}
  1473. +EXPORT_SYMBOL(prom_getenv);
  1474. +
  1475. +char * __init prom_getcmdline(void)
  1476. +{
  1477. + return &(arcs_cmdline[0]);
  1478. +}
  1479. +
  1480. +static void __init ar7_init_cmdline(int argc, char *argv[])
  1481. +{
  1482. + char *cp;
  1483. + int actr;
  1484. +
  1485. + actr = 1; /* Always ignore argv[0] */
  1486. +
  1487. + cp = &(arcs_cmdline[0]);
  1488. + while (actr < argc) {
  1489. + strcpy(cp, argv[actr]);
  1490. + cp += strlen(argv[actr]);
  1491. + *cp++ = ' ';
  1492. + actr++;
  1493. + }
  1494. + if (cp != &(arcs_cmdline[0])) {
  1495. + /* get rid of trailing space */
  1496. + --cp;
  1497. + *cp = '\0';
  1498. + }
  1499. +}
  1500. +
  1501. +struct psbl_rec {
  1502. + u32 psbl_size;
  1503. + u32 env_base;
  1504. + u32 env_size;
  1505. + u32 ffs_base;
  1506. + u32 ffs_size;
  1507. +};
  1508. +
  1509. +static __initdata char psp_env_version[] = "TIENV0.8";
  1510. +
  1511. +struct psp_env_chunk {
  1512. + u8 num;
  1513. + u8 ctrl;
  1514. + u16 csum;
  1515. + u8 len;
  1516. + char data[11];
  1517. +} __attribute__ ((packed));
  1518. +
  1519. +struct psp_var_map_entry {
  1520. + u8 num;
  1521. + char *value;
  1522. +};
  1523. +
  1524. +static struct psp_var_map_entry psp_var_map[] = {
  1525. + { 1, "cpufrequency" },
  1526. + { 2, "memsize" },
  1527. + { 3, "flashsize" },
  1528. + { 4, "modetty0" },
  1529. + { 5, "modetty1" },
  1530. + { 8, "maca" },
  1531. + { 9, "macb" },
  1532. + { 28, "sysfrequency" },
  1533. + { 38, "mipsfrequency" },
  1534. +};
  1535. +
  1536. +/*
  1537. +
  1538. +Well-known variable (num is looked up in table above for matching variable name)
  1539. +Example: cpufrequency=211968000
  1540. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1541. +| 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
  1542. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1543. +
  1544. +Name=Value pair in a single chunk
  1545. +Example: NAME=VALUE
  1546. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1547. +| 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
  1548. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1549. +
  1550. +Name=Value pair in 2 chunks (len is the number of chunks)
  1551. +Example: bootloaderVersion=1.3.7.15
  1552. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1553. +| 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
  1554. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1555. +| _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
  1556. ++----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  1557. +
  1558. +Data is padded with 0xFF
  1559. +
  1560. +*/
  1561. +
  1562. +#define PSP_ENV_SIZE 4096
  1563. +
  1564. +static char psp_env_data[PSP_ENV_SIZE] = { 0, };
  1565. +
  1566. +static char * __init lookup_psp_var_map(u8 num)
  1567. +{
  1568. + int i;
  1569. +
  1570. + for (i = 0; i < sizeof(psp_var_map); i++)
  1571. + if (psp_var_map[i].num == num)
  1572. + return psp_var_map[i].value;
  1573. +
  1574. + return NULL;
  1575. +}
  1576. +
  1577. +static void __init add_adam2_var(char *name, char *value)
  1578. +{
  1579. + int i;
  1580. + for (i = 0; i < MAX_ENTRY; i++) {
  1581. + if (!adam2_env[i].name) {
  1582. + adam2_env[i].name = name;
  1583. + adam2_env[i].value = value;
  1584. + return;
  1585. + } else if (!strcmp(adam2_env[i].name, name)) {
  1586. + adam2_env[i].value = value;
  1587. + return;
  1588. + }
  1589. + }
  1590. +}
  1591. +
  1592. +static int __init parse_psp_env(void *psp_env_base)
  1593. +{
  1594. + int i, n;
  1595. + char *name, *value;
  1596. + struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
  1597. +
  1598. + memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
  1599. +
  1600. + i = 1;
  1601. + n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
  1602. + while (i < n) {
  1603. + if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
  1604. + break;
  1605. + value = chunks[i].data;
  1606. + if (chunks[i].num) {
  1607. + name = lookup_psp_var_map(chunks[i].num);
  1608. + } else {
  1609. + name = value;
  1610. + value += strlen(name) + 1;
  1611. + }
  1612. + if (name)
  1613. + add_adam2_var(name, value);
  1614. + i += chunks[i].len;
  1615. + }
  1616. + return 0;
  1617. +}
  1618. +
  1619. +static void __init ar7_init_env(struct env_var *env)
  1620. +{
  1621. + int i;
  1622. + struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
  1623. + void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
  1624. +
  1625. + if (strcmp(psp_env, psp_env_version) == 0) {
  1626. + parse_psp_env(psp_env);
  1627. + } else {
  1628. + for (i = 0; i < MAX_ENTRY; i++, env++)
  1629. + if (env->name)
  1630. + add_adam2_var(env->name, env->value);
  1631. + }
  1632. +}
  1633. +
  1634. +static void __init console_config(void)
  1635. +{
  1636. +#ifdef CONFIG_SERIAL_8250_CONSOLE
  1637. + char console_string[40];
  1638. + int baud = 0;
  1639. + char parity = '\0', bits = '\0', flow = '\0';
  1640. + char *s, *p;
  1641. +
  1642. + if (strstr(prom_getcmdline(), "console="))
  1643. + return;
  1644. +
  1645. +#ifdef CONFIG_KGDB
  1646. + if (!strstr(prom_getcmdline(), "nokgdb")) {
  1647. + strcat(prom_getcmdline(), " console=kgdb");
  1648. + kgdb_enabled = 1;
  1649. + return;
  1650. + }
  1651. +#endif
  1652. +
  1653. + if ((s = prom_getenv("modetty0"))) {
  1654. + baud = simple_strtoul(s, &p, 10);
  1655. + s = p;
  1656. + if (*s == ',') s++;
  1657. + if (*s) parity = *s++;
  1658. + if (*s == ',') s++;
  1659. + if (*s) bits = *s++;
  1660. + if (*s == ',') s++;
  1661. + if (*s == 'h') flow = 'r';
  1662. + }
  1663. +
  1664. + if (baud == 0)
  1665. + baud = 38400;
  1666. + if (parity != 'n' && parity != 'o' && parity != 'e')
  1667. + parity = 'n';
  1668. + if (bits != '7' && bits != '8')
  1669. + bits = '8';
  1670. +
  1671. + if (flow == 'r')
  1672. + sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  1673. + parity, bits, flow);
  1674. + else
  1675. + sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
  1676. + bits);
  1677. + strcat(prom_getcmdline(), console_string);
  1678. +#endif
  1679. +}
  1680. +
  1681. +void __init prom_init(void)
  1682. +{
  1683. + ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
  1684. + ar7_init_env((struct env_var *)fw_arg2);
  1685. + console_config();
  1686. +}
  1687. +
  1688. +#define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
  1689. +static inline unsigned int serial_in(int offset)
  1690. +{
  1691. + return readb((void *)PORT(offset));
  1692. +}
  1693. +
  1694. +static inline void serial_out(int offset, int value)
  1695. +{
  1696. + writeb(value, (void *)PORT(offset));
  1697. +}
  1698. +
  1699. +char prom_getchar(void)
  1700. +{
  1701. + while (!(serial_in(UART_LSR) & UART_LSR_DR));
  1702. + return serial_in(UART_RX);
  1703. +}
  1704. +
  1705. +int prom_putchar(char c)
  1706. +{
  1707. + while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0);
  1708. + serial_out(UART_TX, c);
  1709. + return 1;
  1710. +}
  1711. +
  1712. +/* from adm5120/prom.c */
  1713. +void prom_printf(const char *fmt, ...)
  1714. +{
  1715. + va_list args;
  1716. + int l;
  1717. + char *p, *buf_end;
  1718. + char buf[1024];
  1719. +
  1720. + va_start(args, fmt);
  1721. + l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
  1722. + va_end(args);
  1723. +
  1724. + buf_end = buf + l;
  1725. +
  1726. + for (p = buf; p < buf_end; p++) {
  1727. + /* Crude cr/nl handling is better than none */
  1728. + if (*p == '\n')
  1729. + prom_putchar('\r');
  1730. + prom_putchar(*p);
  1731. + }
  1732. +}
  1733. +
  1734. +#ifdef CONFIG_KGDB
  1735. +int putDebugChar(char c)
  1736. +{
  1737. + return prom_putchar(c);
  1738. +}
  1739. +
  1740. +char getDebugChar(void)
  1741. +{
  1742. + return prom_getchar();
  1743. +}
  1744. +#endif
  1745. diff -Nur linux-2.6.30.orig/arch/mips/ar7/setup.c linux-2.6.30/arch/mips/ar7/setup.c
  1746. --- linux-2.6.30.orig/arch/mips/ar7/setup.c 1970-01-01 01:00:00.000000000 +0100
  1747. +++ linux-2.6.30/arch/mips/ar7/setup.c 2009-06-11 20:55:34.603475038 +0200
  1748. @@ -0,0 +1,105 @@
  1749. +/*
  1750. + * Carsten Langgaard, carstenl@mips.com
  1751. + * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  1752. + *
  1753. + * This program is free software; you can distribute it and/or modify it
  1754. + * under the terms of the GNU General Public License (Version 2) as
  1755. + * published by the Free Software Foundation.
  1756. + *
  1757. + * This program is distributed in the hope it will be useful, but WITHOUT
  1758. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1759. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1760. + * for more details.
  1761. + *
  1762. + * You should have received a copy of the GNU General Public License along
  1763. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1764. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1765. + */
  1766. +#include <linux/version.h>
  1767. +#include <linux/init.h>
  1768. +#include <linux/ioport.h>
  1769. +#include <linux/pm.h>
  1770. +
  1771. +#include <asm/reboot.h>
  1772. +#include <asm/time.h>
  1773. +#include <asm/mach-ar7/ar7.h>
  1774. +#include <asm/mach-ar7/prom.h>
  1775. +
  1776. +static void ar7_machine_restart(char *command);
  1777. +static void ar7_machine_halt(void);
  1778. +static void ar7_machine_power_off(void);
  1779. +
  1780. +static void ar7_machine_restart(char *command)
  1781. +{
  1782. + u32 *softres_reg = (u32 *)ioremap(AR7_REGS_RESET +
  1783. + AR7_RESET_SOFTWARE, 1);
  1784. + writel(1, softres_reg);
  1785. +}
  1786. +
  1787. +static void ar7_machine_halt(void)
  1788. +{
  1789. + while (1);
  1790. +}
  1791. +
  1792. +static void ar7_machine_power_off(void)
  1793. +{
  1794. + u32 *power_reg = (u32 *)ioremap(AR7_REGS_POWER, 1);
  1795. + u32 power_state = readl(power_reg) | (3 << 30);
  1796. + writel(power_state, power_reg);
  1797. + ar7_machine_halt();
  1798. +}
  1799. +
  1800. +const char *get_system_type(void)
  1801. +{
  1802. + u16 chip_id = ar7_chip_id();
  1803. + switch (chip_id) {
  1804. + case AR7_CHIP_7300:
  1805. + return "TI AR7 (TNETD7300)";
  1806. + case AR7_CHIP_7100:
  1807. + return "TI AR7 (TNETD7100)";
  1808. + case AR7_CHIP_7200:
  1809. + return "TI AR7 (TNETD7200)";
  1810. + default:
  1811. + return "TI AR7 (Unknown)";
  1812. + }
  1813. +}
  1814. +
  1815. +static int __init ar7_init_console(void)
  1816. +{
  1817. + return 0;
  1818. +}
  1819. +
  1820. +/*
  1821. + * Initializes basic routines and structures pointers, memory size (as
  1822. + * given by the bios and saves the command line.
  1823. + */
  1824. +
  1825. +extern void ar7_init_clocks(void);
  1826. +
  1827. +void __init plat_mem_setup(void)
  1828. +{
  1829. + unsigned long io_base;
  1830. +
  1831. + _machine_restart = ar7_machine_restart;
  1832. + _machine_halt = ar7_machine_halt;
  1833. + pm_power_off = ar7_machine_power_off;
  1834. + panic_timeout = 3;
  1835. +
  1836. + io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
  1837. + if (!io_base) panic("Can't remap IO base!\n");
  1838. + set_io_port_base(io_base);
  1839. +
  1840. + prom_meminit();
  1841. + ar7_init_clocks();
  1842. +
  1843. + ioport_resource.start = 0;
  1844. + ioport_resource.end = ~0;
  1845. + iomem_resource.start = 0;
  1846. + iomem_resource.end = ~0;
  1847. +
  1848. + printk(KERN_INFO "%s, ID: 0x%04x, Revision: 0x%02x\n",
  1849. + get_system_type(),
  1850. + ar7_chip_id(), ar7_chip_rev());
  1851. +}
  1852. +
  1853. +console_initcall(ar7_init_console);
  1854. diff -Nur linux-2.6.30.orig/arch/mips/ar7/time.c linux-2.6.30/arch/mips/ar7/time.c
  1855. --- linux-2.6.30.orig/arch/mips/ar7/time.c 1970-01-01 01:00:00.000000000 +0100
  1856. +++ linux-2.6.30/arch/mips/ar7/time.c 2009-06-11 20:55:34.603475038 +0200
  1857. @@ -0,0 +1,28 @@
  1858. +/*
  1859. + * Carsten Langgaard, carstenl@mips.com
  1860. + * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  1861. + *
  1862. + * This program is free software; you can distribute it and/or modify it
  1863. + * under the terms of the GNU General Public License (Version 2) as
  1864. + * published by the Free Software Foundation.
  1865. + *
  1866. + * This program is distributed in the hope it will be useful, but WITHOUT
  1867. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1868. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1869. + * for more details.
  1870. + *
  1871. + * You should have received a copy of the GNU General Public License along
  1872. + * with this program; if not, write to the Free Software Foundation, Inc.,
  1873. + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  1874. + *
  1875. + * Setting up the clock on the MIPS boards.
  1876. + */
  1877. +
  1878. +#include <linux/version.h>
  1879. +#include <asm/time.h>
  1880. +#include <asm/mach-ar7/ar7.h>
  1881. +
  1882. +void __init plat_time_init(void)
  1883. +{
  1884. + mips_hpt_frequency = ar7_cpu_freq() / 2;
  1885. +}
  1886. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/ar7.h linux-2.6.30/arch/mips/include/asm/mach-ar7/ar7.h
  1887. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/ar7.h 1970-01-01 01:00:00.000000000 +0100
  1888. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/ar7.h 2009-06-11 20:55:34.603475038 +0200
  1889. @@ -0,0 +1,170 @@
  1890. +/*
  1891. + * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  1892. + * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  1893. + *
  1894. + * This program is free software; you can redistribute it and/or modify
  1895. + * it under the terms of the GNU General Public License as published by
  1896. + * the Free Software Foundation; either version 2 of the License, or
  1897. + * (at your option) any later version.
  1898. + *
  1899. + * This program is distributed in the hope that it will be useful,
  1900. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1901. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1902. + * GNU General Public License for more details.
  1903. + *
  1904. + * You should have received a copy of the GNU General Public License
  1905. + * along with this program; if not, write to the Free Software
  1906. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  1907. + */
  1908. +
  1909. +#ifndef __AR7_H__
  1910. +#define __AR7_H__
  1911. +
  1912. +#include <linux/delay.h>
  1913. +#include <asm/addrspace.h>
  1914. +#include <linux/io.h>
  1915. +
  1916. +#define AR7_REGS_BASE 0x08610000
  1917. +
  1918. +#define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  1919. +#define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  1920. +/* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  1921. +#define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  1922. +#define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  1923. +#define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  1924. +#define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  1925. +#define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  1926. +#define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  1927. +#define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  1928. +#define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  1929. +#define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  1930. +#define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  1931. +
  1932. +#define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  1933. +#define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  1934. +#define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  1935. +
  1936. +#define AR7_RESET_PEREPHERIAL 0x0
  1937. +#define AR7_RESET_SOFTWARE 0x4
  1938. +#define AR7_RESET_STATUS 0x8
  1939. +
  1940. +#define AR7_RESET_BIT_CPMAC_LO 17
  1941. +#define AR7_RESET_BIT_CPMAC_HI 21
  1942. +#define AR7_RESET_BIT_MDIO 22
  1943. +#define AR7_RESET_BIT_EPHY 26
  1944. +
  1945. +/* GPIO control registers */
  1946. +#define AR7_GPIO_INPUT 0x0
  1947. +#define AR7_GPIO_OUTPUT 0x4
  1948. +#define AR7_GPIO_DIR 0x8
  1949. +#define AR7_GPIO_ENABLE 0xc
  1950. +
  1951. +#define AR7_CHIP_7100 0x18
  1952. +#define AR7_CHIP_7200 0x2b
  1953. +#define AR7_CHIP_7300 0x05
  1954. +
  1955. +/* Interrupts */
  1956. +#define AR7_IRQ_UART0 15
  1957. +#define AR7_IRQ_UART1 16
  1958. +
  1959. +/* Clocks */
  1960. +#define AR7_AFE_CLOCK 35328000
  1961. +#define AR7_REF_CLOCK 25000000
  1962. +#define AR7_XTAL_CLOCK 24000000
  1963. +
  1964. +struct plat_cpmac_data {
  1965. + int reset_bit;
  1966. + int power_bit;
  1967. + u32 phy_mask;
  1968. + char dev_addr[6];
  1969. +};
  1970. +
  1971. +struct plat_dsl_data {
  1972. + int reset_bit_dsl;
  1973. + int reset_bit_sar;
  1974. +};
  1975. +
  1976. +extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
  1977. +
  1978. +static inline u16 ar7_chip_id(void)
  1979. +{
  1980. + return readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff;
  1981. +}
  1982. +
  1983. +static inline u8 ar7_chip_rev(void)
  1984. +{
  1985. + return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) >> 16) & 0xff;
  1986. +}
  1987. +
  1988. +static inline int ar7_cpu_freq(void)
  1989. +{
  1990. + return ar7_cpu_clock;
  1991. +}
  1992. +
  1993. +static inline int ar7_bus_freq(void)
  1994. +{
  1995. + return ar7_bus_clock;
  1996. +}
  1997. +
  1998. +static inline int ar7_vbus_freq(void)
  1999. +{
  2000. + return ar7_bus_clock / 2;
  2001. +}
  2002. +#define ar7_cpmac_freq ar7_vbus_freq
  2003. +
  2004. +static inline int ar7_dsp_freq(void)
  2005. +{
  2006. + return ar7_dsp_clock;
  2007. +}
  2008. +
  2009. +static inline int ar7_has_high_cpmac(void)
  2010. +{
  2011. + u16 chip_id = ar7_chip_id();
  2012. + switch (chip_id) {
  2013. + case AR7_CHIP_7100:
  2014. + case AR7_CHIP_7200:
  2015. + return 0;
  2016. + default:
  2017. + return 1;
  2018. + }
  2019. +}
  2020. +#define ar7_has_high_vlynq ar7_has_high_cpmac
  2021. +#define ar7_has_second_uart ar7_has_high_cpmac
  2022. +
  2023. +static inline void ar7_device_enable(u32 bit)
  2024. +{
  2025. + void *reset_reg =
  2026. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  2027. + writel(readl(reset_reg) | (1 << bit), reset_reg);
  2028. + mdelay(20);
  2029. +}
  2030. +
  2031. +static inline void ar7_device_disable(u32 bit)
  2032. +{
  2033. + void *reset_reg =
  2034. + (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
  2035. + writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  2036. + mdelay(20);
  2037. +}
  2038. +
  2039. +static inline void ar7_device_reset(u32 bit)
  2040. +{
  2041. + ar7_device_disable(bit);
  2042. + ar7_device_enable(bit);
  2043. +}
  2044. +
  2045. +static inline void ar7_device_on(u32 bit)
  2046. +{
  2047. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  2048. + writel(readl(power_reg) | (1 << bit), power_reg);
  2049. + mdelay(20);
  2050. +}
  2051. +
  2052. +static inline void ar7_device_off(u32 bit)
  2053. +{
  2054. + void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  2055. + writel(readl(power_reg) & ~(1 << bit), power_reg);
  2056. + mdelay(20);
  2057. +}
  2058. +
  2059. +#endif /* __AR7_H__ */
  2060. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/gpio.h linux-2.6.30/arch/mips/include/asm/mach-ar7/gpio.h
  2061. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/gpio.h 1970-01-01 01:00:00.000000000 +0100
  2062. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/gpio.h 2009-06-11 20:55:34.603475038 +0200
  2063. @@ -0,0 +1,109 @@
  2064. +/*
  2065. + * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  2066. + *
  2067. + * This program is free software; you can redistribute it and/or modify
  2068. + * it under the terms of the GNU General Public License as published by
  2069. + * the Free Software Foundation; either version 2 of the License, or
  2070. + * (at your option) any later version.
  2071. + *
  2072. + * This program is distributed in the hope that it will be useful,
  2073. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2074. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2075. + * GNU General Public License for more details.
  2076. + *
  2077. + * You should have received a copy of the GNU General Public License
  2078. + * along with this program; if not, write to the Free Software
  2079. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2080. + */
  2081. +
  2082. +#ifndef __AR7_GPIO_H__
  2083. +#define __AR7_GPIO_H__
  2084. +#include <asm/mach-ar7/ar7.h>
  2085. +
  2086. +#define AR7_GPIO_MAX 32
  2087. +
  2088. +extern int gpio_request(unsigned gpio, const char *label);
  2089. +extern void gpio_free(unsigned gpio);
  2090. +
  2091. +/* Common GPIO layer */
  2092. +static inline int gpio_get_value(unsigned gpio)
  2093. +{
  2094. + void __iomem *gpio_in =
  2095. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
  2096. +
  2097. + return readl(gpio_in) & (1 << gpio);
  2098. +}
  2099. +
  2100. +static inline void gpio_set_value(unsigned gpio, int value)
  2101. +{
  2102. + void __iomem *gpio_out =
  2103. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
  2104. + unsigned tmp;
  2105. +
  2106. + tmp = readl(gpio_out) & ~(1 << gpio);
  2107. + if (value)
  2108. + tmp |= 1 << gpio;
  2109. + writel(tmp, gpio_out);
  2110. +}
  2111. +
  2112. +static inline int gpio_direction_input(unsigned gpio)
  2113. +{
  2114. + void __iomem *gpio_dir =
  2115. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2116. +
  2117. + if (gpio >= AR7_GPIO_MAX)
  2118. + return -EINVAL;
  2119. +
  2120. + writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
  2121. +
  2122. + return 0;
  2123. +}
  2124. +
  2125. +static inline int gpio_direction_output(unsigned gpio, int value)
  2126. +{
  2127. + void __iomem *gpio_dir =
  2128. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
  2129. +
  2130. + if (gpio >= AR7_GPIO_MAX)
  2131. + return -EINVAL;
  2132. +
  2133. + gpio_set_value(gpio, value);
  2134. + writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
  2135. +
  2136. + return 0;
  2137. +}
  2138. +
  2139. +static inline int gpio_to_irq(unsigned gpio)
  2140. +{
  2141. + return -EINVAL;
  2142. +}
  2143. +
  2144. +static inline int irq_to_gpio(unsigned irq)
  2145. +{
  2146. + return -EINVAL;
  2147. +}
  2148. +
  2149. +/* Board specific GPIO functions */
  2150. +static inline int ar7_gpio_enable(unsigned gpio)
  2151. +{
  2152. + void __iomem *gpio_en =
  2153. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2154. +
  2155. + writel(readl(gpio_en) | (1 << gpio), gpio_en);
  2156. +
  2157. + return 0;
  2158. +}
  2159. +
  2160. +static inline int ar7_gpio_disable(unsigned gpio)
  2161. +{
  2162. + void __iomem *gpio_en =
  2163. + (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
  2164. +
  2165. + writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
  2166. +
  2167. + return 0;
  2168. +}
  2169. +
  2170. +#include <asm-generic/gpio.h>
  2171. +
  2172. +#endif
  2173. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/irq.h linux-2.6.30/arch/mips/include/asm/mach-ar7/irq.h
  2174. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/irq.h 1970-01-01 01:00:00.000000000 +0100
  2175. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/irq.h 2009-06-11 20:55:34.607474989 +0200
  2176. @@ -0,0 +1,16 @@
  2177. +/*
  2178. + * This file is subject to the terms and conditions of the GNU General Public
  2179. + * License. See the file "COPYING" in the main directory of this archive
  2180. + * for more details.
  2181. + *
  2182. + * Shamelessly copied from asm-mips/mach-emma2rh/
  2183. + * Copyright (C) 2003 by Ralf Baechle
  2184. + */
  2185. +#ifndef __ASM_AR7_IRQ_H
  2186. +#define __ASM_AR7_IRQ_H
  2187. +
  2188. +#define NR_IRQS 256
  2189. +
  2190. +#include_next <irq.h>
  2191. +
  2192. +#endif /* __ASM_AR7_IRQ_H */
  2193. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/prom.h linux-2.6.30/arch/mips/include/asm/mach-ar7/prom.h
  2194. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/prom.h 1970-01-01 01:00:00.000000000 +0100
  2195. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/prom.h 2009-06-11 20:55:34.607474989 +0200
  2196. @@ -0,0 +1,26 @@
  2197. +/*
  2198. + * Copyright (C) 2006, 2007 Florian Fainelli <florian@openwrt.org>
  2199. + *
  2200. + * This program is free software; you can redistribute it and/or modify
  2201. + * it under the terms of the GNU General Public License as published by
  2202. + * the Free Software Foundation; either version 2 of the License, or
  2203. + * (at your option) any later version.
  2204. + *
  2205. + * This program is distributed in the hope that it will be useful,
  2206. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2207. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2208. + * GNU General Public License for more details.
  2209. + *
  2210. + * You should have received a copy of the GNU General Public License
  2211. + * along with this program; if not, write to the Free Software
  2212. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2213. + */
  2214. +
  2215. +#ifndef __PROM_H__
  2216. +#define __PROM_H__
  2217. +
  2218. +extern char *prom_getenv(const char *name);
  2219. +extern void prom_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
  2220. +extern void prom_meminit(void);
  2221. +
  2222. +#endif /* __PROM_H__ */
  2223. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/spaces.h linux-2.6.30/arch/mips/include/asm/mach-ar7/spaces.h
  2224. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/spaces.h 1970-01-01 01:00:00.000000000 +0100
  2225. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/spaces.h 2009-06-11 20:55:34.607474989 +0200
  2226. @@ -0,0 +1,32 @@
  2227. +/*
  2228. + * This file is subject to the terms and conditions of the GNU General Public
  2229. + * License. See the file "COPYING" in the main directory of this archive
  2230. + * for more details.
  2231. + *
  2232. + * Copyright (C) 1994 - 1999, 2000, 03, 04 Ralf Baechle
  2233. + * Copyright (C) 2000, 2002 Maciej W. Rozycki
  2234. + * Copyright (C) 1990, 1999, 2000 Silicon Graphics, Inc.
  2235. + */
  2236. +#ifndef _ASM_AR7_SPACES_H
  2237. +#define _ASM_AR7_SPACES_H
  2238. +
  2239. +#define CAC_BASE 0x80000000
  2240. +#define IO_BASE 0xa0000000
  2241. +#define UNCAC_BASE 0xa0000000
  2242. +#define MAP_BASE 0xc0000000
  2243. +
  2244. +/*
  2245. + * This handles the memory map.
  2246. + * We handle pages at KSEG0 for kernels with 32 bit address space.
  2247. + */
  2248. +#define PAGE_OFFSET 0x94000000UL
  2249. +#define PHYS_OFFSET 0x14000000UL
  2250. +
  2251. +/*
  2252. + * Memory above this physical address will be considered highmem.
  2253. + */
  2254. +#ifndef HIGHMEM_START
  2255. +#define HIGHMEM_START 0x40000000UL
  2256. +#endif
  2257. +
  2258. +#endif /* __ASM_AR7_SPACES_H */
  2259. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/war.h linux-2.6.30/arch/mips/include/asm/mach-ar7/war.h
  2260. --- linux-2.6.30.orig/arch/mips/include/asm/mach-ar7/war.h 1970-01-01 01:00:00.000000000 +0100
  2261. +++ linux-2.6.30/arch/mips/include/asm/mach-ar7/war.h 2009-06-11 20:55:34.607474989 +0200
  2262. @@ -0,0 +1,25 @@
  2263. +/*
  2264. + * This file is subject to the terms and conditions of the GNU General Public
  2265. + * License. See the file "COPYING" in the main directory of this archive
  2266. + * for more details.
  2267. + *
  2268. + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
  2269. + */
  2270. +#ifndef __ASM_MIPS_MACH_BCM947XX_WAR_H
  2271. +#define __ASM_MIPS_MACH_BCM947XX_WAR_H
  2272. +
  2273. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  2274. +#define R4600_V1_HIT_CACHEOP_WAR 0
  2275. +#define R4600_V2_HIT_CACHEOP_WAR 0
  2276. +#define R5432_CP0_INTERRUPT_WAR 0
  2277. +#define BCM1250_M3_WAR 0
  2278. +#define SIBYTE_1956_WAR 0
  2279. +#define MIPS4K_ICACHE_REFILL_WAR 0
  2280. +#define MIPS_CACHE_SYNC_WAR 0
  2281. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  2282. +#define RM9000_CDEX_SMP_WAR 0
  2283. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  2284. +#define R10000_LLSC_WAR 0
  2285. +#define MIPS34K_MISSED_ITLB_WAR 0
  2286. +
  2287. +#endif /* __ASM_MIPS_MACH_BCM947XX_WAR_H */
  2288. diff -Nur linux-2.6.30.orig/arch/mips/include/asm/page.h linux-2.6.30/arch/mips/include/asm/page.h
  2289. --- linux-2.6.30.orig/arch/mips/include/asm/page.h 2009-06-10 05:05:27.000000000 +0200
  2290. +++ linux-2.6.30/arch/mips/include/asm/page.h 2009-06-11 20:55:34.607474989 +0200
  2291. @@ -185,8 +185,11 @@
  2292. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  2293. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  2294. -#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
  2295. -#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
  2296. +#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
  2297. + PHYS_OFFSET)
  2298. +#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
  2299. + PHYS_OFFSET)
  2300. +
  2301. #include <asm-generic/memory_model.h>
  2302. #include <asm-generic/page.h>
  2303. diff -Nur linux-2.6.30.orig/arch/mips/kernel/traps.c linux-2.6.30/arch/mips/kernel/traps.c
  2304. --- linux-2.6.30.orig/arch/mips/kernel/traps.c 2009-06-10 05:05:27.000000000 +0200
  2305. +++ linux-2.6.30/arch/mips/kernel/traps.c 2009-06-11 20:55:34.619476239 +0200
  2306. @@ -1256,9 +1256,22 @@
  2307. exception_handlers[n] = handler;
  2308. if (n == 0 && cpu_has_divec) {
  2309. - *(u32 *)(ebase + 0x200) = 0x08000000 |
  2310. - (0x03ffffff & (handler >> 2));
  2311. - local_flush_icache_range(ebase + 0x200, ebase + 0x204);
  2312. + if ((handler ^ (ebase + 4)) & 0xfc000000) {
  2313. + /* lui k0, 0x0000 */
  2314. + *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
  2315. + /* ori k0, 0x0000 */
  2316. + *(u32 *)(ebase + 0x204) =
  2317. + 0x375a0000 | (handler & 0xffff);
  2318. + /* jr k0 */
  2319. + *(u32 *)(ebase + 0x208) = 0x03400008;
  2320. + /* nop */
  2321. + *(u32 *)(ebase + 0x20C) = 0x00000000;
  2322. + flush_icache_range(ebase + 0x200, ebase + 0x210);
  2323. + } else {
  2324. + *(u32 *)(ebase + 0x200) =
  2325. + 0x08000000 | (0x03ffffff & (handler >> 2));
  2326. + flush_icache_range(ebase + 0x200, ebase + 0x204);
  2327. + }
  2328. }
  2329. return (void *)old_handler;
  2330. }
  2331. diff -Nur linux-2.6.30.orig/arch/mips/lib/delay.c linux-2.6.30/arch/mips/lib/delay.c
  2332. --- linux-2.6.30.orig/arch/mips/lib/delay.c 2009-06-10 05:05:27.000000000 +0200
  2333. +++ linux-2.6.30/arch/mips/lib/delay.c 2009-06-11 21:10:53.309003369 +0200
  2334. @@ -51,6 +51,6 @@
  2335. {
  2336. unsigned int lpj = current_cpu_data.udelay_val;
  2337. - __delay((us * 0x00000005 * HZ * lpj) >> 32);
  2338. + __delay((ns * 0x00000005 * HZ * lpj) >> 32);
  2339. }
  2340. EXPORT_SYMBOL(__ndelay);
  2341. diff -Nur linux-2.6.30.orig/drivers/Kconfig linux-2.6.30/drivers/Kconfig
  2342. --- linux-2.6.30.orig/drivers/Kconfig 2009-06-10 05:05:27.000000000 +0200
  2343. +++ linux-2.6.30/drivers/Kconfig 2009-06-11 20:55:34.619476239 +0200
  2344. @@ -104,6 +104,8 @@
  2345. source "drivers/uio/Kconfig"
  2346. +source "drivers/vlynq/Kconfig"
  2347. +
  2348. source "drivers/xen/Kconfig"
  2349. source "drivers/staging/Kconfig"
  2350. diff -Nur linux-2.6.30.orig/drivers/Makefile linux-2.6.30/drivers/Makefile
  2351. --- linux-2.6.30.orig/drivers/Makefile 2009-06-10 05:05:27.000000000 +0200
  2352. +++ linux-2.6.30/drivers/Makefile 2009-06-11 20:55:34.619476239 +0200
  2353. @@ -103,6 +103,7 @@
  2354. obj-$(CONFIG_HID) += hid/
  2355. obj-$(CONFIG_PPC_PS3) += ps3/
  2356. obj-$(CONFIG_OF) += of/
  2357. +obj-$(CONFIG_VLYNQ) += vlynq/
  2358. obj-$(CONFIG_SSB) += ssb/
  2359. obj-$(CONFIG_VIRTIO) += virtio/
  2360. obj-$(CONFIG_STAGING) += staging/
  2361. diff -Nur linux-2.6.30.orig/drivers/char/Kconfig linux-2.6.30/drivers/char/Kconfig
  2362. --- linux-2.6.30.orig/drivers/char/Kconfig 2009-06-10 05:05:27.000000000 +0200
  2363. +++ linux-2.6.30/drivers/char/Kconfig 2009-06-11 20:55:34.623477307 +0200
  2364. @@ -974,6 +974,15 @@
  2365. To compile this driver as a module, choose M here: the
  2366. module will be called mwave.
  2367. +config AR7_GPIO
  2368. + tristate "TI AR7 GPIO Support"
  2369. + depends on AR7
  2370. + help
  2371. + Give userspace access to the GPIO pins on the Texas Instruments AR7
  2372. + processors.
  2373. +
  2374. + If compiled as a module, it will be called ar7_gpio.
  2375. +
  2376. config SCx200_GPIO
  2377. tristate "NatSemi SCx200 GPIO Support"
  2378. depends on SCx200
  2379. diff -Nur linux-2.6.30.orig/drivers/char/Makefile linux-2.6.30/drivers/char/Makefile
  2380. --- linux-2.6.30.orig/drivers/char/Makefile 2009-06-10 05:05:27.000000000 +0200
  2381. +++ linux-2.6.30/drivers/char/Makefile 2009-06-11 20:55:34.623477307 +0200
  2382. @@ -90,6 +90,7 @@
  2383. obj-$(CONFIG_PPDEV) += ppdev.o
  2384. obj-$(CONFIG_NWBUTTON) += nwbutton.o
  2385. obj-$(CONFIG_NWFLASH) += nwflash.o
  2386. +obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
  2387. obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
  2388. obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
  2389. obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
  2390. diff -Nur linux-2.6.30.orig/drivers/char/ar7_gpio.c linux-2.6.30/drivers/char/ar7_gpio.c
  2391. --- linux-2.6.30.orig/drivers/char/ar7_gpio.c 1970-01-01 01:00:00.000000000 +0100
  2392. +++ linux-2.6.30/drivers/char/ar7_gpio.c 2009-06-11 20:55:34.623477307 +0200
  2393. @@ -0,0 +1,158 @@
  2394. +/*
  2395. + * Copyright (C) 2007 Nicolas Thill <nico@openwrt.org>
  2396. + *
  2397. + * This program is free software; you can redistribute it and/or modify
  2398. + * it under the terms of the GNU General Public License as published by
  2399. + * the Free Software Foundation; either version 2 of the License, or
  2400. + * (at your option) any later version.
  2401. + *
  2402. + * This program is distributed in the hope that it will be useful,
  2403. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2404. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2405. + * GNU General Public License for more details.
  2406. + *
  2407. + * You should have received a copy of the GNU General Public License
  2408. + * along with this program; if not, write to the Free Software
  2409. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2410. + */
  2411. +
  2412. +#include <linux/device.h>
  2413. +#include <linux/fs.h>
  2414. +#include <linux/module.h>
  2415. +#include <linux/errno.h>
  2416. +#include <linux/kernel.h>
  2417. +#include <linux/init.h>
  2418. +#include <linux/platform_device.h>
  2419. +#include <linux/uaccess.h>
  2420. +#include <linux/io.h>
  2421. +#include <linux/types.h>
  2422. +#include <linux/cdev.h>
  2423. +#include <gpio.h>
  2424. +
  2425. +#define DRVNAME "ar7_gpio"
  2426. +#define LONGNAME "TI AR7 GPIOs Driver"
  2427. +
  2428. +MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
  2429. +MODULE_DESCRIPTION(LONGNAME);
  2430. +MODULE_LICENSE("GPL");
  2431. +
  2432. +static int ar7_gpio_major;
  2433. +
  2434. +static ssize_t ar7_gpio_write(struct file *file, const char __user *buf,
  2435. + size_t len, loff_t *ppos)
  2436. +{
  2437. + int pin = iminor(file->f_dentry->d_inode);
  2438. + size_t i;
  2439. +
  2440. + for (i = 0; i < len; ++i) {
  2441. + char c;
  2442. + if (get_user(c, buf + i))
  2443. + return -EFAULT;
  2444. + switch (c) {
  2445. + case '0':
  2446. + gpio_set_value(pin, 0);
  2447. + break;
  2448. + case '1':
  2449. + gpio_set_value(pin, 1);
  2450. + break;
  2451. + case 'd':
  2452. + case 'D':
  2453. + ar7_gpio_disable(pin);
  2454. + break;
  2455. + case 'e':
  2456. + case 'E':
  2457. + ar7_gpio_enable(pin);
  2458. + break;
  2459. + case 'i':
  2460. + case 'I':
  2461. + case '<':
  2462. + gpio_direction_input(pin);
  2463. + break;
  2464. + case 'o':
  2465. + case 'O':
  2466. + case '>':
  2467. + gpio_direction_output(pin, 0);
  2468. + break;
  2469. + default:
  2470. + return -EINVAL;
  2471. + }
  2472. + }
  2473. +
  2474. + return len;
  2475. +}
  2476. +
  2477. +static ssize_t ar7_gpio_read(struct file *file, char __user *buf,
  2478. + size_t len, loff_t *ppos)
  2479. +{
  2480. + int pin = iminor(file->f_dentry->d_inode);
  2481. + int value;
  2482. +
  2483. + value = gpio_get_value(pin);
  2484. + if (put_user(value ? '1' : '0', buf))
  2485. + return -EFAULT;
  2486. +
  2487. + return 1;
  2488. +}
  2489. +
  2490. +static int ar7_gpio_open(struct inode *inode, struct file *file)
  2491. +{
  2492. + int m = iminor(inode);
  2493. +
  2494. + if (m >= AR7_GPIO_MAX)
  2495. + return -EINVAL;
  2496. +
  2497. + return nonseekable_open(inode, file);
  2498. +}
  2499. +
  2500. +static int ar7_gpio_release(struct inode *inode, struct file *file)
  2501. +{
  2502. + return 0;
  2503. +}
  2504. +
  2505. +static const struct file_operations ar7_gpio_fops = {
  2506. + .owner = THIS_MODULE,
  2507. + .write = ar7_gpio_write,
  2508. + .read = ar7_gpio_read,
  2509. + .open = ar7_gpio_open,
  2510. + .release = ar7_gpio_release,
  2511. + .llseek = no_llseek,
  2512. +};
  2513. +
  2514. +static struct platform_device *ar7_gpio_device;
  2515. +
  2516. +static int __init ar7_gpio_init(void)
  2517. +{
  2518. + int rc;
  2519. +
  2520. + ar7_gpio_device = platform_device_alloc(DRVNAME, -1);
  2521. + if (!ar7_gpio_device)
  2522. + return -ENOMEM;
  2523. +
  2524. + rc = platform_device_add(ar7_gpio_device);
  2525. + if (rc < 0)
  2526. + goto out_put;
  2527. +
  2528. + rc = register_chrdev(ar7_gpio_major, DRVNAME, &ar7_gpio_fops);
  2529. + if (rc < 0)
  2530. + goto out_put;
  2531. +
  2532. + ar7_gpio_major = rc;
  2533. +
  2534. + rc = 0;
  2535. +
  2536. + goto out;
  2537. +
  2538. +out_put:
  2539. + platform_device_put(ar7_gpio_device);
  2540. +out:
  2541. + return rc;
  2542. +}
  2543. +
  2544. +static void __exit ar7_gpio_exit(void)
  2545. +{
  2546. + unregister_chrdev(ar7_gpio_major, DRVNAME);
  2547. + platform_device_unregister(ar7_gpio_device);
  2548. +}
  2549. +
  2550. +module_init(ar7_gpio_init);
  2551. +module_exit(ar7_gpio_exit);
  2552. diff -Nur linux-2.6.30.orig/drivers/mtd/maps/physmap.c linux-2.6.30/drivers/mtd/maps/physmap.c
  2553. --- linux-2.6.30.orig/drivers/mtd/maps/physmap.c 2009-06-10 05:05:27.000000000 +0200
  2554. +++ linux-2.6.30/drivers/mtd/maps/physmap.c 2009-06-11 20:55:34.627477258 +0200
  2555. @@ -80,7 +80,7 @@
  2556. "map_rom",
  2557. NULL };
  2558. #ifdef CONFIG_MTD_PARTITIONS
  2559. -static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
  2560. +static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "ar7part", NULL };
  2561. #endif
  2562. static int physmap_flash_probe(struct platform_device *dev)
  2563. diff -Nur linux-2.6.30.orig/drivers/net/Kconfig linux-2.6.30/drivers/net/Kconfig
  2564. --- linux-2.6.30.orig/drivers/net/Kconfig 2009-06-10 05:05:27.000000000 +0200
  2565. +++ linux-2.6.30/drivers/net/Kconfig 2009-06-11 20:55:34.627477258 +0200
  2566. @@ -1760,7 +1760,7 @@
  2567. config CPMAC
  2568. tristate "TI AR7 CPMAC Ethernet support (EXPERIMENTAL)"
  2569. - depends on NET_ETHERNET && EXPERIMENTAL && AR7 && BROKEN
  2570. + depends on NET_ETHERNET && EXPERIMENTAL && AR7
  2571. select PHYLIB
  2572. help
  2573. TI AR7 CPMAC Ethernet support
  2574. diff -Nur linux-2.6.30.orig/drivers/net/cpmac.c linux-2.6.30/drivers/net/cpmac.c
  2575. --- linux-2.6.30.orig/drivers/net/cpmac.c 2009-06-10 05:05:27.000000000 +0200
  2576. +++ linux-2.6.30/drivers/net/cpmac.c 2009-06-11 20:55:34.635477718 +0200
  2577. @@ -615,13 +615,13 @@
  2578. dev_kfree_skb_irq(desc->skb);
  2579. desc->skb = NULL;
  2580. - if (netif_subqueue_stopped(dev, queue))
  2581. + if (__netif_subqueue_stopped(dev, queue))
  2582. netif_wake_subqueue(dev, queue);
  2583. } else {
  2584. if (netif_msg_tx_err(priv) && net_ratelimit())
  2585. printk(KERN_WARNING
  2586. "%s: end_xmit: spurious interrupt\n", dev->name);
  2587. - if (netif_subqueue_stopped(dev, queue))
  2588. + if (__netif_subqueue_stopped(dev, queue))
  2589. netif_wake_subqueue(dev, queue);
  2590. }
  2591. }
  2592. @@ -731,7 +731,6 @@
  2593. static void cpmac_hw_error(struct work_struct *work)
  2594. {
  2595. - int i;
  2596. struct cpmac_priv *priv =
  2597. container_of(work, struct cpmac_priv, reset_work);
  2598. @@ -818,7 +817,6 @@
  2599. static void cpmac_tx_timeout(struct net_device *dev)
  2600. {
  2601. - int i;
  2602. struct cpmac_priv *priv = netdev_priv(dev);
  2603. spin_lock(&priv->lock);
  2604. @@ -1097,15 +1095,18 @@
  2605. static int __devinit cpmac_probe(struct platform_device *pdev)
  2606. {
  2607. - int rc, phy_id, i;
  2608. - char *mdio_bus_id = "0";
  2609. + int rc, phy_id;
  2610. + char mdio_bus_id[BUS_ID_SIZE];
  2611. struct resource *mem;
  2612. struct cpmac_priv *priv;
  2613. struct net_device *dev;
  2614. struct plat_cpmac_data *pdata;
  2615. pdata = pdev->dev.platform_data;
  2616. + strncpy(mdio_bus_id, "0", BUS_ID_SIZE);
  2617. + phy_id = pdev->id;
  2618. + /*
  2619. for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
  2620. if (!(pdata->phy_mask & (1 << phy_id)))
  2621. continue;
  2622. @@ -1116,15 +1117,17 @@
  2623. if (phy_id == PHY_MAX_ADDR) {
  2624. if (external_switch || dumb_switch) {
  2625. - mdio_bus_id = 0; /* fixed phys bus */
  2626. + mdio_bus_id = 0;
  2627. phy_id = pdev->id;
  2628. } else {
  2629. dev_err(&pdev->dev, "no PHY present\n");
  2630. return -ENODEV;
  2631. }
  2632. }
  2633. + */
  2634. dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES);
  2635. + //~ dev = alloc_etherdev(sizeof(*priv));
  2636. if (!dev) {
  2637. printk(KERN_ERR "cpmac: Unable to allocate net_device\n");
  2638. @@ -1161,7 +1164,8 @@
  2639. priv->msg_enable = netif_msg_init(debug_level, 0xff);
  2640. memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
  2641. - priv->phy = phy_connect(dev, dev_name(&cpmac_mii->phy_map[phy_id]->dev),
  2642. + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
  2643. + priv->phy = phy_connect(dev, priv->phy_name,
  2644. &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
  2645. if (IS_ERR(priv->phy)) {
  2646. if (netif_msg_drv(priv))
  2647. @@ -1230,31 +1234,34 @@
  2648. #warning FIXME: unhardcode gpio&reset bits
  2649. ar7_gpio_disable(26);
  2650. ar7_gpio_disable(27);
  2651. - ar7_device_reset(AR7_RESET_BIT_CPMAC_LO);
  2652. ar7_device_reset(AR7_RESET_BIT_CPMAC_HI);
  2653. + ar7_device_reset(AR7_RESET_BIT_CPMAC_LO);
  2654. ar7_device_reset(AR7_RESET_BIT_EPHY);
  2655. cpmac_mii->reset(cpmac_mii);
  2656. - for (i = 0; i < 300000; i++)
  2657. + for (i = 0; i < 300; i++)
  2658. if ((mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE)))
  2659. break;
  2660. else
  2661. - cpu_relax();
  2662. + msleep(10);
  2663. mask &= 0x7fffffff;
  2664. - if (mask & (mask - 1)) {
  2665. +
  2666. + //if (mask & (mask - 1)) {
  2667. external_switch = 1;
  2668. mask = 0;
  2669. - }
  2670. + //}
  2671. + /*
  2672. cpmac_mii->phy_mask = ~(mask | 0x80000000);
  2673. - snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "0");
  2674. + snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "1");
  2675. res = mdiobus_register(cpmac_mii);
  2676. if (res)
  2677. goto fail_mii;
  2678. + */
  2679. res = platform_driver_register(&cpmac_driver);
  2680. if (res)
  2681. goto fail_cpmac;
  2682. diff -Nur linux-2.6.30.orig/drivers/vlynq/Kconfig linux-2.6.30/drivers/vlynq/Kconfig
  2683. --- linux-2.6.30.orig/drivers/vlynq/Kconfig 1970-01-01 01:00:00.000000000 +0100
  2684. +++ linux-2.6.30/drivers/vlynq/Kconfig 2009-06-11 20:55:34.635477718 +0200
  2685. @@ -0,0 +1,13 @@
  2686. +menu "TI VLYNQ"
  2687. +
  2688. +config VLYNQ
  2689. + bool "TI VLYNQ bus support"
  2690. + depends on AR7 && EXPERIMENTAL
  2691. + help
  2692. + Support for the TI VLYNQ bus
  2693. +
  2694. + The module will be called vlynq
  2695. +
  2696. + If unsure, say N
  2697. +
  2698. +endmenu
  2699. diff -Nur linux-2.6.30.orig/drivers/vlynq/Makefile linux-2.6.30/drivers/vlynq/Makefile
  2700. --- linux-2.6.30.orig/drivers/vlynq/Makefile 1970-01-01 01:00:00.000000000 +0100
  2701. +++ linux-2.6.30/drivers/vlynq/Makefile 2009-06-11 20:55:34.635477718 +0200
  2702. @@ -0,0 +1,5 @@
  2703. +#
  2704. +# Makefile for kernel vlynq drivers
  2705. +#
  2706. +
  2707. +obj-$(CONFIG_VLYNQ) += vlynq.o
  2708. diff -Nur linux-2.6.30.orig/drivers/vlynq/vlynq.c linux-2.6.30/drivers/vlynq/vlynq.c
  2709. --- linux-2.6.30.orig/drivers/vlynq/vlynq.c 1970-01-01 01:00:00.000000000 +0100
  2710. +++ linux-2.6.30/drivers/vlynq/vlynq.c 2009-06-11 20:55:52.962219898 +0200
  2711. @@ -0,0 +1,782 @@
  2712. +/*
  2713. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  2714. + *
  2715. + * This program is free software; you can redistribute it and/or modify
  2716. + * it under the terms of the GNU General Public License as published by
  2717. + * the Free Software Foundation; either version 2 of the License, or
  2718. + * (at your option) any later version.
  2719. + *
  2720. + * This program is distributed in the hope that it will be useful,
  2721. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2722. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2723. + * GNU General Public License for more details.
  2724. + *
  2725. + * You should have received a copy of the GNU General Public License
  2726. + * along with this program; if not, write to the Free Software
  2727. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  2728. + */
  2729. +
  2730. +#include <linux/init.h>
  2731. +#include <linux/types.h>
  2732. +#include <linux/kernel.h>
  2733. +#include <linux/string.h>
  2734. +#include <linux/device.h>
  2735. +#include <linux/module.h>
  2736. +#include <linux/errno.h>
  2737. +#include <linux/platform_device.h>
  2738. +#include <linux/interrupt.h>
  2739. +#include <linux/device.h>
  2740. +#include <linux/delay.h>
  2741. +#include <linux/io.h>
  2742. +
  2743. +#include <linux/vlynq.h>
  2744. +
  2745. +#define VLYNQ_CTRL_PM_ENABLE 0x80000000
  2746. +#define VLYNQ_CTRL_CLOCK_INT 0x00008000
  2747. +#define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
  2748. +#define VLYNQ_CTRL_INT_LOCAL 0x00004000
  2749. +#define VLYNQ_CTRL_INT_ENABLE 0x00002000
  2750. +#define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
  2751. +#define VLYNQ_CTRL_INT2CFG 0x00000080
  2752. +#define VLYNQ_CTRL_RESET 0x00000001
  2753. +
  2754. +#define VLYNQ_CTRL_CLOCK_MASK (0x7 << 16)
  2755. +
  2756. +#define VLYNQ_INT_OFFSET 0x00000014
  2757. +#define VLYNQ_REMOTE_OFFSET 0x00000080
  2758. +
  2759. +#define VLYNQ_STATUS_LINK 0x00000001
  2760. +#define VLYNQ_STATUS_LERROR 0x00000080
  2761. +#define VLYNQ_STATUS_RERROR 0x00000100
  2762. +
  2763. +#define VINT_ENABLE 0x00000100
  2764. +#define VINT_TYPE_EDGE 0x00000080
  2765. +#define VINT_LEVEL_LOW 0x00000040
  2766. +#define VINT_VECTOR(x) ((x) & 0x1f)
  2767. +#define VINT_OFFSET(irq) (8 * ((irq) % 4))
  2768. +
  2769. +#define VLYNQ_AUTONEGO_V2 0x00010000
  2770. +
  2771. +struct vlynq_regs {
  2772. + u32 revision;
  2773. + u32 control;
  2774. + u32 status;
  2775. + u32 int_prio;
  2776. + u32 int_status;
  2777. + u32 int_pending;
  2778. + u32 int_ptr;
  2779. + u32 tx_offset;
  2780. + struct vlynq_mapping rx_mapping[4];
  2781. + u32 chip;
  2782. + u32 autonego;
  2783. + u32 unused[6];
  2784. + u32 int_device[8];
  2785. +};
  2786. +
  2787. +#define vlynq_reg_read(reg) readl(&(reg))
  2788. +#define vlynq_reg_write(reg, val) writel(val, &(reg))
  2789. +
  2790. +static int __vlynq_enable_device(struct vlynq_device *dev);
  2791. +
  2792. +#ifdef VLYNQ_DEBUG
  2793. +static void vlynq_dump_regs(struct vlynq_device *dev)
  2794. +{
  2795. + int i;
  2796. + printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
  2797. + dev->local, dev->remote);
  2798. + for (i = 0; i < 32; i++) {
  2799. + printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
  2800. + i + 1, ((u32 *)dev->local)[i]);
  2801. + printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
  2802. + i + 1, ((u32 *)dev->remote)[i]);
  2803. + }
  2804. +}
  2805. +
  2806. +static void vlynq_dump_mem(u32 *base, int count)
  2807. +{
  2808. + int i;
  2809. + for (i = 0; i < (count + 3) / 4; i++) {
  2810. + if (i % 4 == 0) printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
  2811. + printk(KERN_DEBUG " 0x%08x", *(base + i));
  2812. + }
  2813. + printk(KERN_DEBUG "\n");
  2814. +}
  2815. +#endif
  2816. +
  2817. +int vlynq_linked(struct vlynq_device *dev)
  2818. +{
  2819. + int i;
  2820. +
  2821. + for (i = 0; i < 100; i++)
  2822. + if (vlynq_reg_read(dev->local->status) & VLYNQ_STATUS_LINK)
  2823. + return 1;
  2824. + else
  2825. + cpu_relax();
  2826. +
  2827. + return 0;
  2828. +}
  2829. +
  2830. +static void vlynq_reset(struct vlynq_device *dev)
  2831. +{
  2832. + vlynq_reg_write(dev->local->control,
  2833. + vlynq_reg_read(dev->local->control) |
  2834. + VLYNQ_CTRL_RESET);
  2835. +
  2836. + /* Wait for the devices to finish resetting */
  2837. + msleep(5);
  2838. +
  2839. + /* Remove reset bit */
  2840. + vlynq_reg_write(dev->local->control,
  2841. + vlynq_reg_read(dev->local->control) &
  2842. + ~VLYNQ_CTRL_RESET);
  2843. +
  2844. + /* Give some time for the devices to settle */
  2845. + msleep(5);
  2846. +}
  2847. +
  2848. +static void vlynq_irq_unmask(unsigned int irq)
  2849. +{
  2850. + u32 val;
  2851. + struct vlynq_device *dev = get_irq_chip_data(irq);
  2852. + int virq;
  2853. +
  2854. + BUG_ON(!dev);
  2855. + virq = irq - dev->irq_start;
  2856. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  2857. + val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
  2858. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  2859. +}
  2860. +
  2861. +static void vlynq_irq_mask(unsigned int irq)
  2862. +{
  2863. + u32 val;
  2864. + struct vlynq_device *dev = get_irq_chip_data(irq);
  2865. + int virq;
  2866. +
  2867. + BUG_ON(!dev);
  2868. + virq = irq - dev->irq_start;
  2869. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  2870. + val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
  2871. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  2872. +}
  2873. +
  2874. +static int vlynq_irq_type(unsigned int irq, unsigned int flow_type)
  2875. +{
  2876. + u32 val;
  2877. + struct vlynq_device *dev = get_irq_chip_data(irq);
  2878. + int virq;
  2879. +
  2880. + BUG_ON(!dev);
  2881. + virq = irq - dev->irq_start;
  2882. + val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
  2883. + switch (flow_type & IRQ_TYPE_SENSE_MASK) {
  2884. + case IRQ_TYPE_EDGE_RISING:
  2885. + case IRQ_TYPE_EDGE_FALLING:
  2886. + case IRQ_TYPE_EDGE_BOTH:
  2887. + val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
  2888. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  2889. + break;
  2890. + case IRQ_TYPE_LEVEL_HIGH:
  2891. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  2892. + val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
  2893. + break;
  2894. + case IRQ_TYPE_LEVEL_LOW:
  2895. + val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
  2896. + val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
  2897. + break;
  2898. + default:
  2899. + return -EINVAL;
  2900. + }
  2901. + vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
  2902. + return 0;
  2903. +}
  2904. +
  2905. +static void vlynq_local_ack(unsigned int irq)
  2906. +{
  2907. + struct vlynq_device *dev = get_irq_chip_data(irq);
  2908. + u32 status = vlynq_reg_read(dev->local->status);
  2909. + if (printk_ratelimit())
  2910. + printk(KERN_DEBUG "%s: local status: 0x%08x\n",
  2911. + dev_name(&dev->dev), status);
  2912. + vlynq_reg_write(dev->local->status, status);
  2913. +}
  2914. +
  2915. +static void vlynq_remote_ack(unsigned int irq)
  2916. +{
  2917. + struct vlynq_device *dev = get_irq_chip_data(irq);
  2918. + u32 status = vlynq_reg_read(dev->remote->status);
  2919. + if (printk_ratelimit())
  2920. + printk(KERN_DEBUG "%s: remote status: 0x%08x\n",
  2921. + dev_name(&dev->dev), status);
  2922. + vlynq_reg_write(dev->remote->status, status);
  2923. +}
  2924. +
  2925. +static irqreturn_t vlynq_irq(int irq, void *dev_id)
  2926. +{
  2927. + struct vlynq_device *dev = dev_id;
  2928. + u32 status;
  2929. + int virq = 0;
  2930. +
  2931. + status = vlynq_reg_read(dev->local->int_status);
  2932. + vlynq_reg_write(dev->local->int_status, status);
  2933. +
  2934. + if (unlikely(!status))
  2935. + spurious_interrupt();
  2936. +
  2937. + while (status) {
  2938. + if (status & 1)
  2939. + do_IRQ(dev->irq_start + virq);
  2940. + status >>= 1;
  2941. + virq++;
  2942. + }
  2943. +
  2944. + return IRQ_HANDLED;
  2945. +}
  2946. +
  2947. +static struct irq_chip vlynq_irq_chip = {
  2948. + .name = "vlynq",
  2949. + .unmask = vlynq_irq_unmask,
  2950. + .mask = vlynq_irq_mask,
  2951. + .set_type = vlynq_irq_type,
  2952. +};
  2953. +
  2954. +static struct irq_chip vlynq_local_chip = {
  2955. + .name = "vlynq local error",
  2956. + .unmask = vlynq_irq_unmask,
  2957. + .mask = vlynq_irq_mask,
  2958. + .ack = vlynq_local_ack,
  2959. +};
  2960. +
  2961. +static struct irq_chip vlynq_remote_chip = {
  2962. + .name = "vlynq local error",
  2963. + .unmask = vlynq_irq_unmask,
  2964. + .mask = vlynq_irq_mask,
  2965. + .ack = vlynq_remote_ack,
  2966. +};
  2967. +
  2968. +static int vlynq_setup_irq(struct vlynq_device *dev)
  2969. +{
  2970. + u32 val;
  2971. + int i, virq;
  2972. +
  2973. + if (dev->local_irq == dev->remote_irq) {
  2974. + printk(KERN_ERR
  2975. + "%s: local vlynq irq should be different from remote\n",
  2976. + dev_name(&dev->dev));
  2977. + return -EINVAL;
  2978. + }
  2979. +
  2980. + /* Clear local and remote error bits */
  2981. + vlynq_reg_write(dev->local->status, vlynq_reg_read(dev->local->status));
  2982. + vlynq_reg_write(dev->remote->status,
  2983. + vlynq_reg_read(dev->remote->status));
  2984. +
  2985. + /* Now setup interrupts */
  2986. + val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
  2987. + val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
  2988. + VLYNQ_CTRL_INT2CFG;
  2989. + val |= vlynq_reg_read(dev->local->control);
  2990. + vlynq_reg_write(dev->local->int_ptr, VLYNQ_INT_OFFSET);
  2991. + vlynq_reg_write(dev->local->control, val);
  2992. +
  2993. + val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
  2994. + val |= VLYNQ_CTRL_INT_ENABLE;
  2995. + val |= vlynq_reg_read(dev->remote->control);
  2996. + vlynq_reg_write(dev->remote->int_ptr, VLYNQ_INT_OFFSET);
  2997. + vlynq_reg_write(dev->remote->control, val);
  2998. +
  2999. + for (i = dev->irq_start; i <= dev->irq_end; i++) {
  3000. + virq = i - dev->irq_start;
  3001. + if (virq == dev->local_irq) {
  3002. + set_irq_chip_and_handler(i, &vlynq_local_chip,
  3003. + handle_level_irq);
  3004. + set_irq_chip_data(i, dev);
  3005. + } else if (virq == dev->remote_irq) {
  3006. + set_irq_chip_and_handler(i, &vlynq_remote_chip,
  3007. + handle_level_irq);
  3008. + set_irq_chip_data(i, dev);
  3009. + } else {
  3010. + set_irq_chip_and_handler(i, &vlynq_irq_chip,
  3011. + handle_simple_irq);
  3012. + set_irq_chip_data(i, dev);
  3013. + vlynq_reg_write(dev->remote->int_device[virq >> 2], 0);
  3014. + }
  3015. + }
  3016. +
  3017. + if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
  3018. + printk(KERN_ERR "%s: request_irq failed\n", dev_name(&dev->dev));
  3019. + return -EAGAIN;
  3020. + }
  3021. +
  3022. + return 0;
  3023. +}
  3024. +
  3025. +static void vlynq_device_release(struct device *dev)
  3026. +{
  3027. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3028. + kfree(vdev);
  3029. +}
  3030. +
  3031. +static int vlynq_device_match(struct device *dev,
  3032. + struct device_driver *drv)
  3033. +{
  3034. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3035. + struct vlynq_driver *vdrv = to_vlynq_driver(drv);
  3036. + struct vlynq_device_id *ids = vdrv->id_table;
  3037. +
  3038. + while (ids->id) {
  3039. + if (ids->id == vdev->dev_id) {
  3040. + vdev->divisor = ids->divisor;
  3041. + vlynq_set_drvdata(vdev, ids);
  3042. + printk(KERN_INFO "Driver found for VLYNQ " \
  3043. + "device: %08x\n", vdev->dev_id);
  3044. + return 1;
  3045. + }
  3046. + printk(KERN_DEBUG "Not using the %08x VLYNQ device's driver" \
  3047. + " for VLYNQ device: %08x\n", ids->id, vdev->dev_id);
  3048. + ids++;
  3049. + }
  3050. + return 0;
  3051. +}
  3052. +
  3053. +static int vlynq_device_probe(struct device *dev)
  3054. +{
  3055. + struct vlynq_device *vdev = to_vlynq_device(dev);
  3056. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  3057. + struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
  3058. + int result = -ENODEV;
  3059. +
  3060. + get_device(dev);
  3061. + if (drv && drv->probe)
  3062. + result = drv->probe(vdev, id);
  3063. + if (result)
  3064. + put_device(dev);
  3065. + return result;
  3066. +}
  3067. +
  3068. +static int vlynq_device_remove(struct device *dev)
  3069. +{
  3070. + struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
  3071. + if (drv && drv->remove)
  3072. + drv->remove(to_vlynq_device(dev));
  3073. + put_device(dev);
  3074. + return 0;
  3075. +}
  3076. +
  3077. +int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
  3078. +{
  3079. + driver->driver.name = driver->name;
  3080. + driver->driver.bus = &vlynq_bus_type;
  3081. + return driver_register(&driver->driver);
  3082. +}
  3083. +EXPORT_SYMBOL(__vlynq_register_driver);
  3084. +
  3085. +void vlynq_unregister_driver(struct vlynq_driver *driver)
  3086. +{
  3087. + driver_unregister(&driver->driver);
  3088. +}
  3089. +EXPORT_SYMBOL(vlynq_unregister_driver);
  3090. +
  3091. +static int __vlynq_try_remote(struct vlynq_device *dev)
  3092. +{
  3093. + int i;
  3094. +
  3095. + vlynq_reset(dev);
  3096. + for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
  3097. + i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
  3098. + dev->dev_id ? i++ : i--) {
  3099. +
  3100. + if (!vlynq_linked(dev))
  3101. + break;
  3102. +
  3103. + vlynq_reg_write(dev->remote->control,
  3104. + (vlynq_reg_read(dev->remote->control) &
  3105. + ~VLYNQ_CTRL_CLOCK_MASK) |
  3106. + VLYNQ_CTRL_CLOCK_INT |
  3107. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1));
  3108. + vlynq_reg_write(dev->local->control,
  3109. + ((vlynq_reg_read(dev->local->control)
  3110. + & ~(VLYNQ_CTRL_CLOCK_INT |
  3111. + VLYNQ_CTRL_CLOCK_MASK)) |
  3112. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1)));
  3113. +
  3114. + if (vlynq_linked(dev)) {
  3115. + printk(KERN_DEBUG
  3116. + "%s: using remote clock divisor %d\n",
  3117. + dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
  3118. + dev->divisor = i;
  3119. + return 0;
  3120. + } else {
  3121. + vlynq_reset(dev);
  3122. + }
  3123. + }
  3124. +
  3125. + return -ENODEV;
  3126. +}
  3127. +
  3128. +static int __vlynq_try_local(struct vlynq_device *dev)
  3129. +{
  3130. + int i;
  3131. +
  3132. + vlynq_reset(dev);
  3133. +
  3134. + for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
  3135. + i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
  3136. + dev->dev_id ? i++ : i--) {
  3137. +
  3138. + vlynq_reg_write(dev->local->control,
  3139. + (vlynq_reg_read(dev->local->control) &
  3140. + ~VLYNQ_CTRL_CLOCK_MASK) |
  3141. + VLYNQ_CTRL_CLOCK_INT |
  3142. + VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1));
  3143. +
  3144. + if (vlynq_linked(dev)) {
  3145. + printk(KERN_DEBUG
  3146. + "%s: using local clock divisor %d\n",
  3147. + dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
  3148. + dev->divisor = i;
  3149. + return 0;
  3150. + } else {
  3151. + vlynq_reset(dev);
  3152. + }
  3153. + }
  3154. +
  3155. + return -ENODEV;
  3156. +}
  3157. +
  3158. +static int __vlynq_try_external(struct vlynq_device *dev)
  3159. +{
  3160. + vlynq_reset(dev);
  3161. + if (!vlynq_linked(dev))
  3162. + return -ENODEV;
  3163. +
  3164. + vlynq_reg_write(dev->remote->control,
  3165. + (vlynq_reg_read(dev->remote->control) &
  3166. + ~VLYNQ_CTRL_CLOCK_INT));
  3167. +
  3168. + vlynq_reg_write(dev->local->control,
  3169. + (vlynq_reg_read(dev->local->control) &
  3170. + ~VLYNQ_CTRL_CLOCK_INT));
  3171. +
  3172. + if (vlynq_linked(dev)) {
  3173. + printk(KERN_DEBUG "%s: using external clock\n",
  3174. + dev_name(&dev->dev));
  3175. + dev->divisor = vlynq_div_external;
  3176. + return 0;
  3177. + }
  3178. +
  3179. + return -ENODEV;
  3180. +}
  3181. +
  3182. +static int __vlynq_enable_device(struct vlynq_device *dev)
  3183. +{
  3184. + int result;
  3185. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3186. +
  3187. + result = ops->on(dev);
  3188. + if (result)
  3189. + return result;
  3190. +
  3191. + switch (dev->divisor) {
  3192. + case vlynq_div_external:
  3193. + case vlynq_div_auto:
  3194. + /* When the device is brought from reset it should have clock
  3195. + generation negotiated by hardware.
  3196. + Check which device is generating clocks and perform setup
  3197. + accordingly */
  3198. + if (vlynq_linked(dev) && vlynq_reg_read(dev->remote->control) &
  3199. + VLYNQ_CTRL_CLOCK_INT) {
  3200. + if (!__vlynq_try_remote(dev) ||
  3201. + !__vlynq_try_local(dev) ||
  3202. + !__vlynq_try_external(dev))
  3203. + return 0;
  3204. + } else {
  3205. + if (!__vlynq_try_external(dev) ||
  3206. + !__vlynq_try_local(dev) ||
  3207. + !__vlynq_try_remote(dev))
  3208. + return 0;
  3209. + }
  3210. + break;
  3211. + case vlynq_ldiv1: case vlynq_ldiv2: case vlynq_ldiv3: case vlynq_ldiv4:
  3212. + case vlynq_ldiv5: case vlynq_ldiv6: case vlynq_ldiv7: case vlynq_ldiv8:
  3213. + vlynq_reg_write(dev->local->control,
  3214. + VLYNQ_CTRL_CLOCK_INT |
  3215. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  3216. + vlynq_ldiv1));
  3217. + vlynq_reg_write(dev->remote->control, 0);
  3218. + if (vlynq_linked(dev)) {
  3219. + printk(KERN_DEBUG
  3220. + "%s: using local clock divisor %d\n",
  3221. + dev_name(&dev->dev), dev->divisor - vlynq_ldiv1 + 1);
  3222. + return 0;
  3223. + }
  3224. + break;
  3225. + case vlynq_rdiv1: case vlynq_rdiv2: case vlynq_rdiv3: case vlynq_rdiv4:
  3226. + case vlynq_rdiv5: case vlynq_rdiv6: case vlynq_rdiv7: case vlynq_rdiv8:
  3227. + vlynq_reg_write(dev->local->control, 0);
  3228. + vlynq_reg_write(dev->remote->control,
  3229. + VLYNQ_CTRL_CLOCK_INT |
  3230. + VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  3231. + vlynq_rdiv1));
  3232. + if (vlynq_linked(dev)) {
  3233. + printk(KERN_DEBUG
  3234. + "%s: using remote clock divisor %d\n",
  3235. + dev_name(&dev->dev), dev->divisor - vlynq_rdiv1 + 1);
  3236. + return 0;
  3237. + }
  3238. + break;
  3239. + }
  3240. +
  3241. + ops->off(dev);
  3242. + return -ENODEV;
  3243. +}
  3244. +
  3245. +int vlynq_enable_device(struct vlynq_device *dev)
  3246. +{
  3247. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3248. + int result = -ENODEV;
  3249. +
  3250. + result = __vlynq_enable_device(dev);
  3251. + if (result)
  3252. + return result;
  3253. +
  3254. + result = vlynq_setup_irq(dev);
  3255. + if (result)
  3256. + ops->off(dev);
  3257. +
  3258. + dev->enabled = !result;
  3259. + return result;
  3260. +}
  3261. +EXPORT_SYMBOL(vlynq_enable_device);
  3262. +
  3263. +
  3264. +void vlynq_disable_device(struct vlynq_device *dev)
  3265. +{
  3266. + struct plat_vlynq_ops *ops = dev->dev.platform_data;
  3267. +
  3268. + dev->enabled = 0;
  3269. + free_irq(dev->irq, dev);
  3270. + ops->off(dev);
  3271. +}
  3272. +EXPORT_SYMBOL(vlynq_disable_device);
  3273. +
  3274. +int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  3275. + struct vlynq_mapping *mapping)
  3276. +{
  3277. + int i;
  3278. +
  3279. + if (!dev->enabled)
  3280. + return -ENXIO;
  3281. +
  3282. + vlynq_reg_write(dev->local->tx_offset, tx_offset);
  3283. + for (i = 0; i < 4; i++) {
  3284. + vlynq_reg_write(dev->local->rx_mapping[i].offset,
  3285. + mapping[i].offset);
  3286. + vlynq_reg_write(dev->local->rx_mapping[i].size,
  3287. + mapping[i].size);
  3288. + }
  3289. + return 0;
  3290. +}
  3291. +EXPORT_SYMBOL(vlynq_set_local_mapping);
  3292. +
  3293. +int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  3294. + struct vlynq_mapping *mapping)
  3295. +{
  3296. + int i;
  3297. +
  3298. + if (!dev->enabled)
  3299. + return -ENXIO;
  3300. +
  3301. + vlynq_reg_write(dev->remote->tx_offset, tx_offset);
  3302. + for (i = 0; i < 4; i++) {
  3303. + vlynq_reg_write(dev->remote->rx_mapping[i].offset,
  3304. + mapping[i].offset);
  3305. + vlynq_reg_write(dev->remote->rx_mapping[i].size,
  3306. + mapping[i].size);
  3307. + }
  3308. + return 0;
  3309. +}
  3310. +EXPORT_SYMBOL(vlynq_set_remote_mapping);
  3311. +
  3312. +int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
  3313. +{
  3314. + int irq = dev->irq_start + virq;
  3315. + if (dev->enabled)
  3316. + return -EBUSY;
  3317. +
  3318. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3319. + return -EINVAL;
  3320. +
  3321. + if (virq == dev->remote_irq)
  3322. + return -EINVAL;
  3323. +
  3324. + dev->local_irq = virq;
  3325. +
  3326. + return 0;
  3327. +}
  3328. +EXPORT_SYMBOL(vlynq_set_local_irq);
  3329. +
  3330. +int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
  3331. +{
  3332. + int irq = dev->irq_start + virq;
  3333. + if (dev->enabled)
  3334. + return -EBUSY;
  3335. +
  3336. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3337. + return -EINVAL;
  3338. +
  3339. + if (virq == dev->local_irq)
  3340. + return -EINVAL;
  3341. +
  3342. + dev->remote_irq = virq;
  3343. +
  3344. + return 0;
  3345. +}
  3346. +EXPORT_SYMBOL(vlynq_set_remote_irq);
  3347. +
  3348. +static int vlynq_probe(struct platform_device *pdev)
  3349. +{
  3350. + struct vlynq_device *dev;
  3351. + struct resource *regs_res, *mem_res, *irq_res;
  3352. + int len, result;
  3353. +
  3354. + regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  3355. + if (!regs_res)
  3356. + return -ENODEV;
  3357. +
  3358. + mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
  3359. + if (!mem_res)
  3360. + return -ENODEV;
  3361. +
  3362. + irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
  3363. + if (!irq_res)
  3364. + return -ENODEV;
  3365. +
  3366. + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  3367. + if (!dev) {
  3368. + printk(KERN_ERR
  3369. + "vlynq: failed to allocate device structure\n");
  3370. + return -ENOMEM;
  3371. + }
  3372. +
  3373. + dev->id = pdev->id;
  3374. + dev->dev.bus = &vlynq_bus_type;
  3375. + dev->dev.parent = &pdev->dev;
  3376. + dev_set_name(&dev->dev, "vlynq%d", dev->id);
  3377. + dev->dev.platform_data = pdev->dev.platform_data;
  3378. + dev->dev.release = vlynq_device_release;
  3379. +
  3380. + dev->regs_start = regs_res->start;
  3381. + dev->regs_end = regs_res->end;
  3382. + dev->mem_start = mem_res->start;
  3383. + dev->mem_end = mem_res->end;
  3384. +
  3385. + len = regs_res->end - regs_res->start;
  3386. + if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
  3387. + printk(KERN_ERR "%s: Can't request vlynq registers\n",
  3388. + dev_name(&dev->dev));
  3389. + result = -ENXIO;
  3390. + goto fail_request;
  3391. + }
  3392. +
  3393. + dev->local = ioremap(regs_res->start, len);
  3394. + if (!dev->local) {
  3395. + printk(KERN_ERR "%s: Can't remap vlynq registers\n",
  3396. + dev_name(&dev->dev));
  3397. + result = -ENXIO;
  3398. + goto fail_remap;
  3399. + }
  3400. +
  3401. + dev->remote = (struct vlynq_regs *)((void *)dev->local +
  3402. + VLYNQ_REMOTE_OFFSET);
  3403. +
  3404. + dev->irq = platform_get_irq_byname(pdev, "irq");
  3405. + dev->irq_start = irq_res->start;
  3406. + dev->irq_end = irq_res->end;
  3407. + dev->local_irq = dev->irq_end - dev->irq_start;
  3408. + dev->remote_irq = dev->local_irq - 1;
  3409. +
  3410. + if (device_register(&dev->dev))
  3411. + goto fail_register;
  3412. + platform_set_drvdata(pdev, dev);
  3413. +
  3414. + printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
  3415. + dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
  3416. + (void *)dev->mem_start);
  3417. +
  3418. + dev->dev_id = 0;
  3419. + dev->divisor = vlynq_div_auto;
  3420. + result = __vlynq_enable_device(dev);
  3421. + if (result == 0) {
  3422. + dev->dev_id = vlynq_reg_read(dev->remote->chip);
  3423. + ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
  3424. + }
  3425. + if (dev->dev_id)
  3426. + printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
  3427. +
  3428. + return 0;
  3429. +
  3430. +fail_register:
  3431. + iounmap(dev->local);
  3432. +fail_remap:
  3433. +fail_request:
  3434. + release_mem_region(regs_res->start, len);
  3435. + kfree(dev);
  3436. + return result;
  3437. +}
  3438. +
  3439. +static int vlynq_remove(struct platform_device *pdev)
  3440. +{
  3441. + struct vlynq_device *dev = platform_get_drvdata(pdev);
  3442. +
  3443. + device_unregister(&dev->dev);
  3444. + iounmap(dev->local);
  3445. + release_mem_region(dev->regs_start, dev->regs_end - dev->regs_start);
  3446. +
  3447. + kfree(dev);
  3448. +
  3449. + return 0;
  3450. +}
  3451. +
  3452. +static struct platform_driver vlynq_platform_driver = {
  3453. + .driver.name = "vlynq",
  3454. + .probe = vlynq_probe,
  3455. + .remove = __devexit_p(vlynq_remove),
  3456. +};
  3457. +
  3458. +struct bus_type vlynq_bus_type = {
  3459. + .name = "vlynq",
  3460. + .match = vlynq_device_match,
  3461. + .probe = vlynq_device_probe,
  3462. + .remove = vlynq_device_remove,
  3463. +};
  3464. +EXPORT_SYMBOL(vlynq_bus_type);
  3465. +
  3466. +static int __devinit vlynq_init(void)
  3467. +{
  3468. + int res = 0;
  3469. +
  3470. + res = bus_register(&vlynq_bus_type);
  3471. + if (res)
  3472. + goto fail_bus;
  3473. +
  3474. + res = platform_driver_register(&vlynq_platform_driver);
  3475. + if (res)
  3476. + goto fail_platform;
  3477. +
  3478. + return 0;
  3479. +
  3480. +fail_platform:
  3481. + bus_unregister(&vlynq_bus_type);
  3482. +fail_bus:
  3483. + return res;
  3484. +}
  3485. +
  3486. +static void __devexit vlynq_exit(void)
  3487. +{
  3488. + platform_driver_unregister(&vlynq_platform_driver);
  3489. + bus_unregister(&vlynq_bus_type);
  3490. +}
  3491. +
  3492. +module_init(vlynq_init);
  3493. +module_exit(vlynq_exit);
  3494. diff -Nur linux-2.6.30.orig/drivers/watchdog/ar7_wdt.c linux-2.6.30/drivers/watchdog/ar7_wdt.c
  3495. --- linux-2.6.30.orig/drivers/watchdog/ar7_wdt.c 2009-06-10 05:05:27.000000000 +0200
  3496. +++ linux-2.6.30/drivers/watchdog/ar7_wdt.c 2009-06-11 20:55:34.639477111 +0200
  3497. @@ -69,8 +69,7 @@
  3498. u32 prescale;
  3499. };
  3500. -static unsigned long wdt_is_open;
  3501. -static spinlock_t wdt_lock;
  3502. +static struct semaphore open_semaphore;
  3503. static unsigned expect_close;
  3504. /* XXX currently fixed, allows max margin ~68.72 secs */
  3505. @@ -155,10 +154,8 @@
  3506. u32 change;
  3507. change = new_margin * (ar7_vbus_freq() / prescale_value);
  3508. - if (change < 1)
  3509. - change = 1;
  3510. - if (change > 0xffff)
  3511. - change = 0xffff;
  3512. + if (change < 1) change = 1;
  3513. + if (change > 0xffff) change = 0xffff;
  3514. ar7_wdt_change(change);
  3515. margin = change * prescale_value / ar7_vbus_freq();
  3516. printk(KERN_INFO DRVNAME
  3517. @@ -182,7 +179,7 @@
  3518. static int ar7_wdt_open(struct inode *inode, struct file *file)
  3519. {
  3520. /* only allow one at a time */
  3521. - if (test_and_set_bit(0, &wdt_is_open))
  3522. + if (down_trylock(&open_semaphore))
  3523. return -EBUSY;
  3524. ar7_wdt_enable_wdt();
  3525. expect_close = 0;
  3526. @@ -198,7 +195,9 @@
  3527. "will not disable the watchdog timer\n");
  3528. else if (!nowayout)
  3529. ar7_wdt_disable_wdt();
  3530. - clear_bit(0, &wdt_is_open);
  3531. +
  3532. + up(&open_semaphore);
  3533. +
  3534. return 0;
  3535. }
  3536. @@ -213,7 +212,7 @@
  3537. }
  3538. static struct notifier_block ar7_wdt_notifier = {
  3539. - .notifier_call = ar7_wdt_notify_sys,
  3540. + .notifier_call = ar7_wdt_notify_sys
  3541. };
  3542. static ssize_t ar7_wdt_write(struct file *file, const char *data,
  3543. @@ -223,14 +222,12 @@
  3544. if (len) {
  3545. size_t i;
  3546. - spin_lock(&wdt_lock);
  3547. ar7_wdt_kick(1);
  3548. - spin_unlock(&wdt_lock);
  3549. expect_close = 0;
  3550. for (i = 0; i < len; ++i) {
  3551. char c;
  3552. - if (get_user(c, data + i))
  3553. + if (get_user(c, data+i))
  3554. return -EFAULT;
  3555. if (c == 'V')
  3556. expect_close = 1;
  3557. @@ -240,17 +237,19 @@
  3558. return len;
  3559. }
  3560. -static long ar7_wdt_ioctl(struct file *file,
  3561. - unsigned int cmd, unsigned long arg)
  3562. +static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
  3563. + unsigned int cmd, unsigned long arg)
  3564. {
  3565. static struct watchdog_info ident = {
  3566. .identity = LONGNAME,
  3567. .firmware_version = 1,
  3568. - .options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING),
  3569. + .options = (WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING),
  3570. };
  3571. int new_margin;
  3572. switch (cmd) {
  3573. + default:
  3574. + return -ENOTTY;
  3575. case WDIOC_GETSUPPORT:
  3576. if (copy_to_user((struct watchdog_info *)arg, &ident,
  3577. sizeof(ident)))
  3578. @@ -270,24 +269,20 @@
  3579. if (new_margin < 1)
  3580. return -EINVAL;
  3581. - spin_lock(&wdt_lock);
  3582. ar7_wdt_update_margin(new_margin);
  3583. ar7_wdt_kick(1);
  3584. - spin_unlock(&wdt_lock);
  3585. case WDIOC_GETTIMEOUT:
  3586. if (put_user(margin, (int *)arg))
  3587. return -EFAULT;
  3588. return 0;
  3589. - default:
  3590. - return -ENOTTY;
  3591. }
  3592. }
  3593. -static const struct file_operations ar7_wdt_fops = {
  3594. +static struct file_operations ar7_wdt_fops = {
  3595. .owner = THIS_MODULE,
  3596. .write = ar7_wdt_write,
  3597. - .unlocked_ioctl = ar7_wdt_ioctl,
  3598. + .ioctl = ar7_wdt_ioctl,
  3599. .open = ar7_wdt_open,
  3600. .release = ar7_wdt_release,
  3601. };
  3602. @@ -302,8 +297,6 @@
  3603. {
  3604. int rc;
  3605. - spin_lock_init(&wdt_lock);
  3606. -
  3607. ar7_wdt_get_regs();
  3608. if (!request_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt),
  3609. @@ -319,6 +312,8 @@
  3610. ar7_wdt_prescale(prescale_value);
  3611. ar7_wdt_update_margin(margin);
  3612. + sema_init(&open_semaphore, 1);
  3613. +
  3614. rc = register_reboot_notifier(&ar7_wdt_notifier);
  3615. if (rc) {
  3616. printk(KERN_ERR DRVNAME
  3617. diff -Nur linux-2.6.30.orig/include/linux/vlynq.h linux-2.6.30/include/linux/vlynq.h
  3618. --- linux-2.6.30.orig/include/linux/vlynq.h 1970-01-01 01:00:00.000000000 +0100
  3619. +++ linux-2.6.30/include/linux/vlynq.h 2009-06-11 20:55:34.639477111 +0200
  3620. @@ -0,0 +1,161 @@
  3621. +/*
  3622. + * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
  3623. + *
  3624. + * This program is free software; you can redistribute it and/or modify
  3625. + * it under the terms of the GNU General Public License as published by
  3626. + * the Free Software Foundation; either version 2 of the License, or
  3627. + * (at your option) any later version.
  3628. + *
  3629. + * This program is distributed in the hope that it will be useful,
  3630. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3631. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3632. + * GNU General Public License for more details.
  3633. + *
  3634. + * You should have received a copy of the GNU General Public License
  3635. + * along with this program; if not, write to the Free Software
  3636. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  3637. + */
  3638. +
  3639. +#ifndef __VLYNQ_H__
  3640. +#define __VLYNQ_H__
  3641. +
  3642. +#include <linux/device.h>
  3643. +#include <linux/module.h>
  3644. +#include <linux/types.h>
  3645. +
  3646. +#define VLYNQ_NUM_IRQS 32
  3647. +
  3648. +struct vlynq_mapping {
  3649. + u32 size;
  3650. + u32 offset;
  3651. +};
  3652. +
  3653. +enum vlynq_divisor {
  3654. + vlynq_div_auto = 0,
  3655. + vlynq_ldiv1,
  3656. + vlynq_ldiv2,
  3657. + vlynq_ldiv3,
  3658. + vlynq_ldiv4,
  3659. + vlynq_ldiv5,
  3660. + vlynq_ldiv6,
  3661. + vlynq_ldiv7,
  3662. + vlynq_ldiv8,
  3663. + vlynq_rdiv1,
  3664. + vlynq_rdiv2,
  3665. + vlynq_rdiv3,
  3666. + vlynq_rdiv4,
  3667. + vlynq_rdiv5,
  3668. + vlynq_rdiv6,
  3669. + vlynq_rdiv7,
  3670. + vlynq_rdiv8,
  3671. + vlynq_div_external
  3672. +};
  3673. +
  3674. +struct vlynq_device_id {
  3675. + u32 id;
  3676. + enum vlynq_divisor divisor;
  3677. + unsigned long driver_data;
  3678. +};
  3679. +
  3680. +struct vlynq_regs;
  3681. +struct vlynq_device {
  3682. + u32 id, dev_id;
  3683. + int local_irq;
  3684. + int remote_irq;
  3685. + enum vlynq_divisor divisor;
  3686. + u32 regs_start, regs_end;
  3687. + u32 mem_start, mem_end;
  3688. + u32 irq_start, irq_end;
  3689. + int irq;
  3690. + int enabled;
  3691. + struct vlynq_regs *local;
  3692. + struct vlynq_regs *remote;
  3693. + struct device dev;
  3694. +};
  3695. +
  3696. +struct vlynq_driver {
  3697. + char *name;
  3698. + struct vlynq_device_id *id_table;
  3699. + int (*probe)(struct vlynq_device *dev, struct vlynq_device_id *id);
  3700. + void (*remove)(struct vlynq_device *dev);
  3701. + struct device_driver driver;
  3702. +};
  3703. +
  3704. +struct plat_vlynq_ops {
  3705. + int (*on)(struct vlynq_device *dev);
  3706. + void (*off)(struct vlynq_device *dev);
  3707. +};
  3708. +
  3709. +static inline struct vlynq_driver *to_vlynq_driver(struct device_driver *drv)
  3710. +{
  3711. + return container_of(drv, struct vlynq_driver, driver);
  3712. +}
  3713. +
  3714. +static inline struct vlynq_device *to_vlynq_device(struct device *device)
  3715. +{
  3716. + return container_of(device, struct vlynq_device, dev);
  3717. +}
  3718. +
  3719. +extern struct bus_type vlynq_bus_type;
  3720. +
  3721. +extern int __vlynq_register_driver(struct vlynq_driver *driver,
  3722. + struct module *owner);
  3723. +
  3724. +static inline int vlynq_register_driver(struct vlynq_driver *driver)
  3725. +{
  3726. + return __vlynq_register_driver(driver, THIS_MODULE);
  3727. +}
  3728. +
  3729. +static inline void *vlynq_get_drvdata(struct vlynq_device *dev)
  3730. +{
  3731. + return dev_get_drvdata(&dev->dev);
  3732. +}
  3733. +
  3734. +static inline void vlynq_set_drvdata(struct vlynq_device *dev, void *data)
  3735. +{
  3736. + dev_set_drvdata(&dev->dev, data);
  3737. +}
  3738. +
  3739. +static inline u32 vlynq_mem_start(struct vlynq_device *dev)
  3740. +{
  3741. + return dev->mem_start;
  3742. +}
  3743. +
  3744. +static inline u32 vlynq_mem_end(struct vlynq_device *dev)
  3745. +{
  3746. + return dev->mem_end;
  3747. +}
  3748. +
  3749. +static inline u32 vlynq_mem_len(struct vlynq_device *dev)
  3750. +{
  3751. + return dev->mem_end - dev->mem_start + 1;
  3752. +}
  3753. +
  3754. +static inline int vlynq_virq_to_irq(struct vlynq_device *dev, int virq)
  3755. +{
  3756. + int irq = dev->irq_start + virq;
  3757. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3758. + return -EINVAL;
  3759. +
  3760. + return irq;
  3761. +}
  3762. +
  3763. +static inline int vlynq_irq_to_virq(struct vlynq_device *dev, int irq)
  3764. +{
  3765. + if ((irq < dev->irq_start) || (irq > dev->irq_end))
  3766. + return -EINVAL;
  3767. +
  3768. + return irq - dev->irq_start;
  3769. +}
  3770. +
  3771. +extern void vlynq_unregister_driver(struct vlynq_driver *driver);
  3772. +extern int vlynq_enable_device(struct vlynq_device *dev);
  3773. +extern void vlynq_disable_device(struct vlynq_device *dev);
  3774. +extern int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
  3775. + struct vlynq_mapping *mapping);
  3776. +extern int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
  3777. + struct vlynq_mapping *mapping);
  3778. +extern int vlynq_set_local_irq(struct vlynq_device *dev, int virq);
  3779. +extern int vlynq_set_remote_irq(struct vlynq_device *dev, int virq);
  3780. +
  3781. +#endif /* __VLYNQ_H__ */
  3782. diff -Nur linux-2.6.30.orig/kernel/futex.c linux-2.6.30/kernel/futex.c
  3783. --- linux-2.6.30.orig/kernel/futex.c 2009-06-10 05:05:27.000000000 +0200
  3784. +++ linux-2.6.30/kernel/futex.c 2009-06-11 20:55:34.643477901 +0200
  3785. @@ -1985,9 +1985,11 @@
  3786. * implementation, the non functional ones will return
  3787. * -ENOSYS.
  3788. */
  3789. - curval = cmpxchg_futex_value_locked(NULL, 0, 0);
  3790. - if (curval == -EFAULT)
  3791. - futex_cmpxchg_enabled = 1;
  3792. + // exeption handler on ar7 is broken
  3793. + //curval = cmpxchg_futex_value_locked(NULL, 0, 0);
  3794. + //if (curval == -EFAULT)
  3795. + // futex_cmpxchg_enabled = 1;
  3796. + futex_cmpxchg_enabled = 0;
  3797. for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
  3798. plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
  3799. diff -Nur linux-2.6.30.orig/kernel/printk.c linux-2.6.30/kernel/printk.c
  3800. --- linux-2.6.30.orig/kernel/printk.c 2009-06-10 05:05:27.000000000 +0200
  3801. +++ linux-2.6.30/kernel/printk.c 2009-06-11 20:55:34.643477901 +0200
  3802. @@ -1272,6 +1272,7 @@
  3803. static int __init disable_boot_consoles(void)
  3804. {
  3805. + /* triggers reboot on ar7
  3806. if (console_drivers != NULL) {
  3807. if (console_drivers->flags & CON_BOOT) {
  3808. printk(KERN_INFO "turn off boot console %s%d\n",
  3809. @@ -1279,6 +1280,7 @@
  3810. return unregister_console(console_drivers);
  3811. }
  3812. }
  3813. + */
  3814. return 0;
  3815. }
  3816. late_initcall(disable_boot_consoles);