ar7.patch 94 KB

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