100-board.patch 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123
  1. --- a/arch/mips/Kconfig
  2. +++ b/arch/mips/Kconfig
  3. @@ -60,6 +60,19 @@ config BCM47XX
  4. help
  5. Support for BCM47XX based boards
  6. +config ATHEROS
  7. + bool "Atheros 231x/531x SoC support"
  8. + select CEVT_R4K
  9. + select CSRC_R4K
  10. + select DMA_NONCOHERENT
  11. + select IRQ_CPU
  12. + select SYS_HAS_CPU_MIPS32_R1
  13. + select SYS_SUPPORTS_BIG_ENDIAN
  14. + select SYS_SUPPORTS_32BIT_KERNEL
  15. + select GENERIC_GPIO
  16. + help
  17. + Support for AR231x and AR531x based boards
  18. +
  19. config MIPS_COBALT
  20. bool "Cobalt Server"
  21. select CEVT_R4K
  22. @@ -597,6 +610,7 @@ config WR_PPMC
  23. endchoice
  24. +source "arch/mips/ar231x/Kconfig"
  25. source "arch/mips/alchemy/Kconfig"
  26. source "arch/mips/basler/excite/Kconfig"
  27. source "arch/mips/emma/Kconfig"
  28. --- a/arch/mips/Makefile
  29. +++ b/arch/mips/Makefile
  30. @@ -278,6 +278,13 @@ libs-$(CONFIG_MIPS_XXS1500) += arch/mips
  31. load-$(CONFIG_MIPS_XXS1500) += 0xffffffff80100000
  32. #
  33. +# Atheros AR5312/AR2312 WiSoC
  34. +#
  35. +core-$(CONFIG_ATHEROS) += arch/mips/ar231x/
  36. +cflags-$(CONFIG_ATHEROS) += -I$(srctree)/arch/mips/include/asm/mach-ar231x
  37. +load-$(CONFIG_ATHEROS) += 0xffffffff80041000
  38. +
  39. +#
  40. # Cobalt Server
  41. #
  42. core-$(CONFIG_MIPS_COBALT) += arch/mips/cobalt/
  43. --- /dev/null
  44. +++ b/arch/mips/ar231x/Kconfig
  45. @@ -0,0 +1,17 @@
  46. +config ATHEROS_AR5312
  47. + bool "Atheros 5312/2312+ support"
  48. + depends on ATHEROS
  49. + default y
  50. +
  51. +config ATHEROS_AR2315
  52. + bool "Atheros 2315+ support"
  53. + depends on ATHEROS
  54. + select DMA_NONCOHERENT
  55. + select CEVT_R4K
  56. + select CSRC_R4K
  57. + select IRQ_CPU
  58. + select SYS_HAS_CPU_MIPS32_R1
  59. + select SYS_SUPPORTS_32BIT_KERNEL
  60. + select SYS_SUPPORTS_BIG_ENDIAN
  61. + select GENERIC_GPIO
  62. + default y
  63. --- /dev/null
  64. +++ b/arch/mips/ar231x/Makefile
  65. @@ -0,0 +1,13 @@
  66. +#
  67. +# This file is subject to the terms and conditions of the GNU General Public
  68. +# License. See the file "COPYING" in the main directory of this archive
  69. +# for more details.
  70. +#
  71. +# Copyright (C) 2006 FON Technology, SL.
  72. +# Copyright (C) 2006 Imre Kaloz <[email protected]>
  73. +# Copyright (C) 2006-2009 Felix Fietkau <[email protected]>
  74. +#
  75. +
  76. +obj-y += board.o prom.o devices.o
  77. +obj-$(CONFIG_ATHEROS_AR5312) += ar5312.o
  78. +obj-$(CONFIG_ATHEROS_AR2315) += ar2315.o
  79. --- /dev/null
  80. +++ b/arch/mips/ar231x/board.c
  81. @@ -0,0 +1,247 @@
  82. +/*
  83. + * This file is subject to the terms and conditions of the GNU General Public
  84. + * License. See the file "COPYING" in the main directory of this archive
  85. + * for more details.
  86. + *
  87. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  88. + * Copyright (C) 2006 FON Technology, SL.
  89. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  90. + * Copyright (C) 2006-2009 Felix Fietkau <[email protected]>
  91. + */
  92. +
  93. +#include <linux/autoconf.h>
  94. +#include <linux/init.h>
  95. +#include <linux/module.h>
  96. +#include <linux/types.h>
  97. +#include <linux/string.h>
  98. +#include <linux/platform_device.h>
  99. +#include <linux/kernel.h>
  100. +#include <linux/random.h>
  101. +#include <linux/etherdevice.h>
  102. +#include <asm/irq_cpu.h>
  103. +#include <asm/reboot.h>
  104. +#include <asm/io.h>
  105. +
  106. +#include <ar231x_platform.h>
  107. +#include "devices.h"
  108. +#include "ar5312.h"
  109. +#include "ar2315.h"
  110. +
  111. +void (*ar231x_irq_dispatch)(void);
  112. +
  113. +static inline bool
  114. +check_radio_magic(u8 *addr)
  115. +{
  116. + addr += 0x7a; /* offset for flash magic */
  117. + if ((addr[0] == 0x5a) && (addr[1] == 0xa5)) {
  118. + return 1;
  119. + }
  120. + return 0;
  121. +}
  122. +
  123. +static inline bool
  124. +check_board_data(u8 *flash_limit, u8 *addr, bool broken)
  125. +{
  126. + /* config magic found */
  127. + if (*((u32 *)addr) == AR531X_BD_MAGIC)
  128. + return 1;
  129. +
  130. + if (!broken)
  131. + return 0;
  132. +
  133. + if (check_radio_magic(addr + 0xf8))
  134. + ar231x_board.radio = addr + 0xf8;
  135. + if ((addr < flash_limit + 0x10000) &&
  136. + check_radio_magic(addr + 0x10000))
  137. + ar231x_board.radio = addr + 0x10000;
  138. +
  139. + if (ar231x_board.radio) {
  140. + /* broken board data detected, use radio data to find the offset,
  141. + * user will fix this */
  142. + return 1;
  143. + }
  144. + return 0;
  145. +}
  146. +
  147. +static u8 *
  148. +find_board_config(u8 *flash_limit, bool broken)
  149. +{
  150. + u8 *addr;
  151. + int found = 0;
  152. +
  153. + for (addr = flash_limit - 0x1000;
  154. + addr >= flash_limit - 0x30000;
  155. + addr -= 0x1000) {
  156. +
  157. + if (check_board_data(flash_limit, addr, broken)) {
  158. + found = 1;
  159. + break;
  160. + }
  161. + }
  162. +
  163. + if (!found)
  164. + addr = NULL;
  165. +
  166. + return addr;
  167. +}
  168. +
  169. +static u8 *
  170. +find_radio_config(u8 *flash_limit, u8 *board_config)
  171. +{
  172. + int found;
  173. + u8 *radio_config;
  174. +
  175. + /*
  176. + * Now find the start of Radio Configuration data, using heuristics:
  177. + * Search forward from Board Configuration data by 0x1000 bytes
  178. + * at a time until we find non-0xffffffff.
  179. + */
  180. + found = 0;
  181. + for (radio_config = board_config + 0x1000;
  182. + (radio_config < flash_limit);
  183. + radio_config += 0x1000) {
  184. + if ((*(u32 *)radio_config != 0xffffffff) &&
  185. + check_radio_magic(radio_config)) {
  186. + found = 1;
  187. + break;
  188. + }
  189. + }
  190. +
  191. + /* AR2316 relocates radio config to new location */
  192. + if (!found) {
  193. + for (radio_config = board_config + 0xf8;
  194. + (radio_config < flash_limit - 0x1000 + 0xf8);
  195. + radio_config += 0x1000) {
  196. + if ((*(u32 *)radio_config != 0xffffffff) &&
  197. + check_radio_magic(radio_config)) {
  198. + found = 1;
  199. + break;
  200. + }
  201. + }
  202. + }
  203. +
  204. + if (!found) {
  205. + printk("Could not find Radio Configuration data\n");
  206. + radio_config = 0;
  207. + }
  208. +
  209. + return (u8 *) radio_config;
  210. +}
  211. +
  212. +int __init
  213. +ar231x_find_config(u8 *flash_limit)
  214. +{
  215. + struct ar231x_boarddata *config;
  216. + unsigned int rcfg_size;
  217. + int broken_boarddata = 0;
  218. + u8 *bcfg, *rcfg;
  219. + u8 *board_data;
  220. + u8 *radio_data;
  221. + u32 offset;
  222. +
  223. + ar231x_board.config = NULL;
  224. + ar231x_board.radio = NULL;
  225. + /* Copy the board and radio data to RAM, because accessing the mapped
  226. + * memory of the flash directly after booting is not safe */
  227. +
  228. + /* Try to find valid board and radio data */
  229. + bcfg = find_board_config(flash_limit, false);
  230. +
  231. + /* If that fails, try to at least find valid radio data */
  232. + if (!bcfg) {
  233. + bcfg = find_board_config(flash_limit, true);
  234. + broken_boarddata = 1;
  235. + }
  236. +
  237. + if (!bcfg) {
  238. + printk(KERN_WARNING "WARNING: No board configuration data found!\n");
  239. + return -ENODEV;
  240. + }
  241. +
  242. + board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
  243. + ar231x_board.config = (struct ar231x_boarddata *) board_data;
  244. + memcpy(board_data, bcfg, 0x100);
  245. + if (broken_boarddata) {
  246. + printk(KERN_WARNING "WARNING: broken board data detected\n");
  247. + config = ar231x_board.config;
  248. + if (!memcmp(config->enet0_mac, "\x00\x00\x00\x00\x00\x00", 6)) {
  249. + printk(KERN_INFO "Fixing up empty mac addresses\n");
  250. + random_ether_addr(config->enet0_mac);
  251. + random_ether_addr(config->enet1_mac);
  252. + }
  253. + }
  254. +
  255. +
  256. + /* Radio config starts 0x100 bytes after board config, regardless
  257. + * of what the physical layout on the flash chip looks like */
  258. +
  259. + if (ar231x_board.radio)
  260. + rcfg = (u8 *) ar231x_board.radio;
  261. + else
  262. + rcfg = find_radio_config(flash_limit, bcfg);
  263. +
  264. + if (!rcfg)
  265. + return -ENODEV;
  266. +
  267. + radio_data = board_data + 0x100 + ((rcfg - bcfg) & 0xfff);
  268. + ar231x_board.radio = radio_data;
  269. + offset = radio_data - board_data;
  270. + printk(KERN_INFO "Radio config found at offset 0x%x(0x%x)\n", rcfg - bcfg, offset);
  271. + rcfg_size = BOARD_CONFIG_BUFSZ - offset;
  272. + memcpy(radio_data, rcfg, rcfg_size);
  273. +
  274. + return 0;
  275. +}
  276. +
  277. +static void
  278. +ar231x_halt(void)
  279. +{
  280. + local_irq_disable();
  281. + while (1);
  282. +}
  283. +
  284. +void __init
  285. +plat_mem_setup(void)
  286. +{
  287. + _machine_halt = ar231x_halt;
  288. + pm_power_off = ar231x_halt;
  289. +
  290. + ar5312_plat_setup();
  291. + ar2315_plat_setup();
  292. +
  293. + /* Disable data watchpoints */
  294. + write_c0_watchlo0(0);
  295. +}
  296. +
  297. +
  298. +asmlinkage void
  299. +plat_irq_dispatch(void)
  300. +{
  301. + ar231x_irq_dispatch();
  302. +}
  303. +
  304. +void __init
  305. +plat_time_init(void)
  306. +{
  307. + ar5312_time_init();
  308. + ar2315_time_init();
  309. +}
  310. +
  311. +unsigned int __cpuinit
  312. +get_c0_compare_irq(void)
  313. +{
  314. + return CP0_LEGACY_COMPARE_IRQ;
  315. +}
  316. +
  317. +void __init
  318. +arch_init_irq(void)
  319. +{
  320. + clear_c0_status(ST0_IM);
  321. + mips_cpu_irq_init();
  322. +
  323. + /* Initialize interrupt controllers */
  324. + ar5312_irq_init();
  325. + ar2315_irq_init();
  326. +}
  327. +
  328. +
  329. --- /dev/null
  330. +++ b/arch/mips/ar231x/prom.c
  331. @@ -0,0 +1,37 @@
  332. +/*
  333. + * This file is subject to the terms and conditions of the GNU General Public
  334. + * License. See the file "COPYING" in the main directory of this archive
  335. + * for more details.
  336. + *
  337. + * Copyright MontaVista Software Inc
  338. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  339. + * Copyright (C) 2006 FON Technology, SL.
  340. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  341. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  342. + */
  343. +
  344. +/*
  345. + * Prom setup file for ar531x
  346. + */
  347. +
  348. +#include <linux/init.h>
  349. +#include <linux/autoconf.h>
  350. +#include <linux/kernel.h>
  351. +#include <linux/string.h>
  352. +#include <linux/mm.h>
  353. +#include <linux/bootmem.h>
  354. +
  355. +#include <asm/bootinfo.h>
  356. +#include <asm/addrspace.h>
  357. +#include "ar5312.h"
  358. +#include "ar2315.h"
  359. +
  360. +void __init prom_init(void)
  361. +{
  362. + ar5312_prom_init();
  363. + ar2315_prom_init();
  364. +}
  365. +
  366. +void __init prom_free_prom_memory(void)
  367. +{
  368. +}
  369. --- /dev/null
  370. +++ b/arch/mips/include/asm/mach-ar231x/ar231x_platform.h
  371. @@ -0,0 +1,83 @@
  372. +#ifndef __AR531X_PLATFORM_H
  373. +#define __AR531X_PLATFORM_H
  374. +
  375. +/*
  376. + * This is board-specific data that is stored in a "fixed" location in flash.
  377. + * It is shared across operating systems, so it should not be changed lightly.
  378. + * The main reason we need it is in order to extract the ethernet MAC
  379. + * address(es).
  380. + */
  381. +struct ar231x_boarddata {
  382. + u32 magic; /* board data is valid */
  383. +#define AR531X_BD_MAGIC 0x35333131 /* "5311", for all 531x platforms */
  384. + u16 cksum; /* checksum (starting with BD_REV 2) */
  385. + u16 rev; /* revision of this struct */
  386. +#define BD_REV 4
  387. + char boardName[64]; /* Name of board */
  388. + u16 major; /* Board major number */
  389. + u16 minor; /* Board minor number */
  390. + u32 flags; /* Board configuration */
  391. +#define BD_ENET0 0x00000001 /* ENET0 is stuffed */
  392. +#define BD_ENET1 0x00000002 /* ENET1 is stuffed */
  393. +#define BD_UART1 0x00000004 /* UART1 is stuffed */
  394. +#define BD_UART0 0x00000008 /* UART0 is stuffed (dma) */
  395. +#define BD_RSTFACTORY 0x00000010 /* Reset factory defaults stuffed */
  396. +#define BD_SYSLED 0x00000020 /* System LED stuffed */
  397. +#define BD_EXTUARTCLK 0x00000040 /* External UART clock */
  398. +#define BD_CPUFREQ 0x00000080 /* cpu freq is valid in nvram */
  399. +#define BD_SYSFREQ 0x00000100 /* sys freq is set in nvram */
  400. +#define BD_WLAN0 0x00000200 /* Enable WLAN0 */
  401. +#define BD_MEMCAP 0x00000400 /* CAP SDRAM @ memCap for testing */
  402. +#define BD_DISWATCHDOG 0x00000800 /* disable system watchdog */
  403. +#define BD_WLAN1 0x00001000 /* Enable WLAN1 (ar5212) */
  404. +#define BD_ISCASPER 0x00002000 /* FLAG for AR2312 */
  405. +#define BD_WLAN0_2G_EN 0x00004000 /* FLAG for radio0_2G */
  406. +#define BD_WLAN0_5G_EN 0x00008000 /* FLAG for radio0_2G */
  407. +#define BD_WLAN1_2G_EN 0x00020000 /* FLAG for radio0_2G */
  408. +#define BD_WLAN1_5G_EN 0x00040000 /* FLAG for radio0_2G */
  409. + u16 resetConfigGpio; /* Reset factory GPIO pin */
  410. + u16 sysLedGpio; /* System LED GPIO pin */
  411. +
  412. + u32 cpuFreq; /* CPU core frequency in Hz */
  413. + u32 sysFreq; /* System frequency in Hz */
  414. + u32 cntFreq; /* Calculated C0_COUNT frequency */
  415. +
  416. + u8 wlan0_mac[6];
  417. + u8 enet0_mac[6];
  418. + u8 enet1_mac[6];
  419. +
  420. + u16 pciId; /* Pseudo PCIID for common code */
  421. + u16 memCap; /* cap bank1 in MB */
  422. +
  423. + /* version 3 */
  424. + u8 wlan1_mac[6]; /* (ar5212) */
  425. +};
  426. +
  427. +#define BOARD_CONFIG_BUFSZ 0x1000
  428. +
  429. +/*
  430. + * Platform device information for the Wireless MAC
  431. + */
  432. +struct ar231x_board_config {
  433. + u16 devid;
  434. +
  435. + /* board config data */
  436. + struct ar231x_boarddata *config;
  437. +
  438. + /* radio calibration data */
  439. + const char *radio;
  440. +};
  441. +
  442. +/*
  443. + * Platform device information for the Ethernet MAC
  444. + */
  445. +struct ar231x_eth {
  446. + u32 reset_base;
  447. + u32 reset_mac;
  448. + u32 reset_phy;
  449. + u32 phy_base;
  450. + struct ar231x_board_config *config;
  451. + char *macaddr;
  452. +};
  453. +
  454. +#endif /* __AR531X_PLATFORM_H */
  455. --- /dev/null
  456. +++ b/arch/mips/include/asm/mach-ar231x/cpu-feature-overrides.h
  457. @@ -0,0 +1,84 @@
  458. +/*
  459. + * Atheros SoC specific CPU feature overrides
  460. + *
  461. + * Copyright (C) 2008 Gabor Juhos <[email protected]>
  462. + *
  463. + * This file was derived from: include/asm-mips/cpu-features.h
  464. + * Copyright (C) 2003, 2004 Ralf Baechle
  465. + * Copyright (C) 2004 Maciej W. Rozycki
  466. + *
  467. + * This program is free software; you can redistribute it and/or modify it
  468. + * under the terms of the GNU General Public License version 2 as published
  469. + * by the Free Software Foundation.
  470. + *
  471. + */
  472. +#ifndef __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H
  473. +#define __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H
  474. +
  475. +/*
  476. + * The ATHEROS SoCs have MIPS 4Kc/4KEc core.
  477. + */
  478. +#define cpu_has_tlb 1
  479. +#define cpu_has_4kex 1
  480. +#define cpu_has_3k_cache 0
  481. +#define cpu_has_4k_cache 1
  482. +#define cpu_has_tx39_cache 0
  483. +#define cpu_has_sb1_cache 0
  484. +#define cpu_has_fpu 0
  485. +#define cpu_has_32fpr 0
  486. +#define cpu_has_counter 1
  487. +/* #define cpu_has_watch ? */
  488. +/* #define cpu_has_divec ? */
  489. +/* #define cpu_has_vce ? */
  490. +/* #define cpu_has_cache_cdex_p ? */
  491. +/* #define cpu_has_cache_cdex_s ? */
  492. +/* #define cpu_has_prefetch ? */
  493. +/* #define cpu_has_mcheck ? */
  494. +#define cpu_has_ejtag 1
  495. +
  496. +#if !defined(CONFIG_ATHEROS_AR5312)
  497. +# define cpu_has_llsc 1
  498. +#else
  499. +/*
  500. + * The MIPS 4Kc V0.9 core in the AR5312/AR2312 have problems with the
  501. + * ll/sc instructions.
  502. + */
  503. +# define cpu_has_llsc 0
  504. +#endif
  505. +
  506. +#define cpu_has_mips16 0
  507. +#define cpu_has_mdmx 0
  508. +#define cpu_has_mips3d 0
  509. +#define cpu_has_smartmips 0
  510. +
  511. +/* #define cpu_has_vtag_icache ? */
  512. +/* #define cpu_has_dc_aliases ? */
  513. +/* #define cpu_has_ic_fills_f_dc ? */
  514. +/* #define cpu_has_pindexed_dcache ? */
  515. +
  516. +/* #define cpu_icache_snoops_remote_store ? */
  517. +
  518. +#define cpu_has_mips32r1 1
  519. +
  520. +#if !defined(CONFIG_ATHEROS_AR5312)
  521. +# define cpu_has_mips32r2 1
  522. +#endif
  523. +
  524. +#define cpu_has_mips64r1 0
  525. +#define cpu_has_mips64r2 0
  526. +
  527. +#define cpu_has_dsp 0
  528. +#define cpu_has_mipsmt 0
  529. +
  530. +/* #define cpu_has_nofpuex ? */
  531. +#define cpu_has_64bits 0
  532. +#define cpu_has_64bit_zero_reg 0
  533. +#define cpu_has_64bit_gp_regs 0
  534. +#define cpu_has_64bit_addresses 0
  535. +
  536. +/* #define cpu_has_inclusive_pcaches ? */
  537. +
  538. +/* #define cpu_dcache_line_size() ? */
  539. +/* #define cpu_icache_line_size() ? */
  540. +
  541. +#endif /* __ASM_MACH_ATHEROS_CPU_FEATURE_OVERRIDES_H */
  542. --- /dev/null
  543. +++ b/arch/mips/include/asm/mach-ar231x/dma-coherence.h
  544. @@ -0,0 +1,41 @@
  545. +/*
  546. + * This file is subject to the terms and conditions of the GNU General Public
  547. + * License. See the file "COPYING" in the main directory of this archive
  548. + * for more details.
  549. + *
  550. + * Copyright (C) 2006 Ralf Baechle <[email protected]>
  551. + * Copyright (C) 2007 Felix Fietkau <[email protected]>
  552. + *
  553. + */
  554. +#ifndef __ASM_MACH_GENERIC_DMA_COHERENCE_H
  555. +#define __ASM_MACH_GENERIC_DMA_COHERENCE_H
  556. +
  557. +#define PCI_DMA_OFFSET 0x20000000
  558. +
  559. +struct device;
  560. +
  561. +static dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size)
  562. +{
  563. + return virt_to_phys(addr) + (dev != NULL ? PCI_DMA_OFFSET : 0);
  564. +}
  565. +
  566. +static dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
  567. +{
  568. + return page_to_phys(page) + (dev != NULL ? PCI_DMA_OFFSET : 0);
  569. +}
  570. +
  571. +static unsigned long plat_dma_addr_to_phys(dma_addr_t dma_addr)
  572. +{
  573. + return (dma_addr > PCI_DMA_OFFSET ? dma_addr - PCI_DMA_OFFSET : dma_addr);
  574. +}
  575. +
  576. +static void plat_unmap_dma_mem(dma_addr_t dma_addr)
  577. +{
  578. +}
  579. +
  580. +static inline int plat_device_is_coherent(struct device *dev)
  581. +{
  582. + return 0;
  583. +}
  584. +
  585. +#endif /* __ASM_MACH_GENERIC_DMA_COHERENCE_H */
  586. --- /dev/null
  587. +++ b/arch/mips/include/asm/mach-ar231x/gpio.h
  588. @@ -0,0 +1,79 @@
  589. +#ifndef _ATHEROS_GPIO_H_
  590. +#define _ATHEROS_GPIO_H_
  591. +
  592. +#include <ar231x.h>
  593. +
  594. +struct ar231x_gpiodev {
  595. + u32 valid_mask;
  596. + u32 (*get_output)(void);
  597. + u32 (*set_output)(u32 mask, u32 val);
  598. + u32 (*get)(void);
  599. + u32 (*set)(u32 mask, u32 val);
  600. +};
  601. +
  602. +extern const struct ar231x_gpiodev *ar231x_gpiodev;
  603. +
  604. +/*
  605. + * Wrappers for the generic GPIO layer
  606. + */
  607. +
  608. +static inline int gpio_direction_input(unsigned gpio) {
  609. + u32 mask = 1 << gpio;
  610. +
  611. + if (!(ar231x_gpiodev->valid_mask & mask))
  612. + return -ENXIO;
  613. +
  614. + ar231x_gpiodev->set_output(mask, 0);
  615. + return 0;
  616. +}
  617. +
  618. +static inline void gpio_set_value(unsigned gpio, int value) {
  619. + u32 mask = 1 << gpio;
  620. +
  621. + if (!(ar231x_gpiodev->valid_mask & mask))
  622. + return;
  623. +
  624. + ar231x_gpiodev->set(mask, (!!value) * mask);
  625. +}
  626. +
  627. +static inline int gpio_direction_output(unsigned gpio, int value) {
  628. + u32 mask = 1 << gpio;
  629. +
  630. + if (!(ar231x_gpiodev->valid_mask & mask))
  631. + return -ENXIO;
  632. +
  633. + ar231x_gpiodev->set_output(mask, mask);
  634. + ar231x_gpiodev->set(mask, (!!value) * mask);
  635. + return 0;
  636. +}
  637. +
  638. +/* Reads the gpio pin. Unchecked function */
  639. +static inline int gpio_get_value(unsigned gpio) {
  640. + u32 mask = 1 << gpio;
  641. +
  642. + if (!(ar231x_gpiodev->valid_mask & mask))
  643. + return 0;
  644. +
  645. + return !!(ar231x_gpiodev->get() & mask);
  646. +}
  647. +
  648. +static inline int gpio_request(unsigned gpio, const char *label) {
  649. + return 0;
  650. +}
  651. +
  652. +static inline void gpio_free(unsigned gpio) {
  653. +}
  654. +
  655. +/* Returns IRQ to attach for gpio. Unchecked function */
  656. +static inline int gpio_to_irq(unsigned gpio) {
  657. + return AR531X_GPIO_IRQ(gpio);
  658. +}
  659. +
  660. +/* Returns gpio for IRQ attached. Unchecked function */
  661. +static inline int irq_to_gpio(unsigned irq) {
  662. + return (irq - (AR531X_GPIO_IRQ(0)));
  663. +}
  664. +
  665. +#include <asm-generic/gpio.h> /* cansleep wrappers */
  666. +
  667. +#endif
  668. --- /dev/null
  669. +++ b/arch/mips/include/asm/mach-ar231x/reset.h
  670. @@ -0,0 +1,6 @@
  671. +#ifndef __AR531X_RESET_H
  672. +#define __AR531X_RESET_H
  673. +
  674. +void ar531x_disable_reset_button(void);
  675. +
  676. +#endif /* __AR531X_RESET_H */
  677. --- /dev/null
  678. +++ b/arch/mips/include/asm/mach-ar231x/war.h
  679. @@ -0,0 +1,25 @@
  680. +/*
  681. + * This file is subject to the terms and conditions of the GNU General Public
  682. + * License. See the file "COPYING" in the main directory of this archive
  683. + * for more details.
  684. + *
  685. + * Copyright (C) 2008 Felix Fietkau <[email protected]>
  686. + */
  687. +#ifndef __ASM_MIPS_MACH_ATHEROS_WAR_H
  688. +#define __ASM_MIPS_MACH_ATHEROS_WAR_H
  689. +
  690. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  691. +#define R4600_V1_HIT_CACHEOP_WAR 0
  692. +#define R4600_V2_HIT_CACHEOP_WAR 0
  693. +#define R5432_CP0_INTERRUPT_WAR 0
  694. +#define BCM1250_M3_WAR 0
  695. +#define SIBYTE_1956_WAR 0
  696. +#define MIPS4K_ICACHE_REFILL_WAR 0
  697. +#define MIPS_CACHE_SYNC_WAR 0
  698. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  699. +#define RM9000_CDEX_SMP_WAR 0
  700. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  701. +#define R10000_LLSC_WAR 0
  702. +#define MIPS34K_MISSED_ITLB_WAR 0
  703. +
  704. +#endif /* __ASM_MIPS_MACH_ATHEROS_WAR_H */
  705. --- /dev/null
  706. +++ b/arch/mips/include/asm/mach-ar231x/ar2315_regs.h
  707. @@ -0,0 +1,580 @@
  708. +/*
  709. + * Register definitions for AR2315+
  710. + *
  711. + * This file is subject to the terms and conditions of the GNU General Public
  712. + * License. See the file "COPYING" in the main directory of this archive
  713. + * for more details.
  714. + *
  715. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  716. + * Copyright (C) 2006 FON Technology, SL.
  717. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  718. + * Copyright (C) 2006-2008 Felix Fietkau <[email protected]>
  719. + */
  720. +
  721. +#ifndef __AR2315_REG_H
  722. +#define __AR2315_REG_H
  723. +
  724. +/*
  725. + * IRQs
  726. + */
  727. +#define AR2315_IRQ_MISC_INTRS MIPS_CPU_IRQ_BASE+2 /* C0_CAUSE: 0x0400 */
  728. +#define AR2315_IRQ_WLAN0_INTRS MIPS_CPU_IRQ_BASE+3 /* C0_CAUSE: 0x0800 */
  729. +#define AR2315_IRQ_ENET0_INTRS MIPS_CPU_IRQ_BASE+4 /* C0_CAUSE: 0x1000 */
  730. +#define AR2315_IRQ_LCBUS_PCI MIPS_CPU_IRQ_BASE+5 /* C0_CAUSE: 0x2000 */
  731. +#define AR2315_IRQ_WLAN0_POLL MIPS_CPU_IRQ_BASE+6 /* C0_CAUSE: 0x4000 */
  732. +
  733. +/*
  734. + * Address map
  735. + */
  736. +#define AR2315_SPI_READ 0x08000000 /* SPI FLASH */
  737. +#define AR2315_WLAN0 0xB0000000 /* Wireless MMR */
  738. +#define AR2315_PCI 0xB0100000 /* PCI MMR */
  739. +#define AR2315_SDRAMCTL 0xB0300000 /* SDRAM MMR */
  740. +#define AR2315_LOCAL 0xB0400000 /* LOCAL BUS MMR */
  741. +#define AR2315_ENET0 0xB0500000 /* ETHERNET MMR */
  742. +#define AR2315_DSLBASE 0xB1000000 /* RESET CONTROL MMR */
  743. +#define AR2315_UART0 0xB1100003 /* UART MMR */
  744. +#define AR2315_SPI 0xB1300000 /* SPI FLASH MMR */
  745. +#define AR2315_PCIEXT 0x80000000 /* pci external */
  746. +
  747. +/*
  748. + * Reset Register
  749. + */
  750. +#define AR2315_COLD_RESET (AR2315_DSLBASE + 0x0000)
  751. +
  752. +#define AR2315_RESET_COLD_AHB 0x00000001
  753. +#define AR2315_RESET_COLD_APB 0x00000002
  754. +#define AR2315_RESET_COLD_CPU 0x00000004
  755. +#define AR2315_RESET_COLD_CPUWARM 0x00000008
  756. +#define AR2315_RESET_SYSTEM (RESET_COLD_CPU | RESET_COLD_APB | RESET_COLD_AHB) /* full system */
  757. +#define AR2317_RESET_SYSTEM 0x00000010
  758. +
  759. +
  760. +#define AR2315_RESET (AR2315_DSLBASE + 0x0004)
  761. +
  762. +#define AR2315_RESET_WARM_WLAN0_MAC 0x00000001 /* warm reset WLAN0 MAC */
  763. +#define AR2315_RESET_WARM_WLAN0_BB 0x00000002 /* warm reset WLAN0 BaseBand */
  764. +#define AR2315_RESET_MPEGTS_RSVD 0x00000004 /* warm reset MPEG-TS */
  765. +#define AR2315_RESET_PCIDMA 0x00000008 /* warm reset PCI ahb/dma */
  766. +#define AR2315_RESET_MEMCTL 0x00000010 /* warm reset memory controller */
  767. +#define AR2315_RESET_LOCAL 0x00000020 /* warm reset local bus */
  768. +#define AR2315_RESET_I2C_RSVD 0x00000040 /* warm reset I2C bus */
  769. +#define AR2315_RESET_SPI 0x00000080 /* warm reset SPI interface */
  770. +#define AR2315_RESET_UART0 0x00000100 /* warm reset UART0 */
  771. +#define AR2315_RESET_IR_RSVD 0x00000200 /* warm reset IR interface */
  772. +#define AR2315_RESET_EPHY0 0x00000400 /* cold reset ENET0 phy */
  773. +#define AR2315_RESET_ENET0 0x00000800 /* cold reset ENET0 mac */
  774. +
  775. +/*
  776. + * AHB master arbitration control
  777. + */
  778. +#define AR2315_AHB_ARB_CTL (AR2315_DSLBASE + 0x0008)
  779. +
  780. +#define AR2315_ARB_CPU 0x00000001 /* CPU, default */
  781. +#define AR2315_ARB_WLAN 0x00000002 /* WLAN */
  782. +#define AR2315_ARB_MPEGTS_RSVD 0x00000004 /* MPEG-TS */
  783. +#define AR2315_ARB_LOCAL 0x00000008 /* LOCAL */
  784. +#define AR2315_ARB_PCI 0x00000010 /* PCI */
  785. +#define AR2315_ARB_ETHERNET 0x00000020 /* Ethernet */
  786. +#define AR2315_ARB_RETRY 0x00000100 /* retry policy, debug only */
  787. +
  788. +/*
  789. + * Config Register
  790. + */
  791. +#define AR2315_ENDIAN_CTL (AR2315_DSLBASE + 0x000c)
  792. +
  793. +#define AR2315_CONFIG_AHB 0x00000001 /* EC - AHB bridge endianess */
  794. +#define AR2315_CONFIG_WLAN 0x00000002 /* WLAN byteswap */
  795. +#define AR2315_CONFIG_MPEGTS_RSVD 0x00000004 /* MPEG-TS byteswap */
  796. +#define AR2315_CONFIG_PCI 0x00000008 /* PCI byteswap */
  797. +#define AR2315_CONFIG_MEMCTL 0x00000010 /* Memory controller endianess */
  798. +#define AR2315_CONFIG_LOCAL 0x00000020 /* Local bus byteswap */
  799. +#define AR2315_CONFIG_ETHERNET 0x00000040 /* Ethernet byteswap */
  800. +
  801. +#define AR2315_CONFIG_MERGE 0x00000200 /* CPU write buffer merge */
  802. +#define AR2315_CONFIG_CPU 0x00000400 /* CPU big endian */
  803. +#define AR2315_CONFIG_PCIAHB 0x00000800
  804. +#define AR2315_CONFIG_PCIAHB_BRIDGE 0x00001000
  805. +#define AR2315_CONFIG_SPI 0x00008000 /* SPI byteswap */
  806. +#define AR2315_CONFIG_CPU_DRAM 0x00010000
  807. +#define AR2315_CONFIG_CPU_PCI 0x00020000
  808. +#define AR2315_CONFIG_CPU_MMR 0x00040000
  809. +#define AR2315_CONFIG_BIG 0x00000400
  810. +
  811. +
  812. +/*
  813. + * NMI control
  814. + */
  815. +#define AR2315_NMI_CTL (AR2315_DSLBASE + 0x0010)
  816. +
  817. +#define AR2315_NMI_EN 1
  818. +
  819. +/*
  820. + * Revision Register - Initial value is 0x3010 (WMAC 3.0, AR531X 1.0).
  821. + */
  822. +#define AR2315_SREV (AR2315_DSLBASE + 0x0014)
  823. +
  824. +#define AR2315_REV_MAJ 0x00f0
  825. +#define AR2315_REV_MAJ_S 4
  826. +#define AR2315_REV_MIN 0x000f
  827. +#define AR2315_REV_MIN_S 0
  828. +#define AR2315_REV_CHIP (AR2315_REV_MAJ|AR2315_REV_MIN)
  829. +
  830. +/*
  831. + * Interface Enable
  832. + */
  833. +#define AR2315_IF_CTL (AR2315_DSLBASE + 0x0018)
  834. +
  835. +#define AR2315_IF_MASK 0x00000007
  836. +#define AR2315_IF_DISABLED 0
  837. +#define AR2315_IF_PCI 1
  838. +#define AR2315_IF_TS_LOCAL 2
  839. +#define AR2315_IF_ALL 3 /* only for emulation with separate pins */
  840. +#define AR2315_IF_LOCAL_HOST 0x00000008
  841. +#define AR2315_IF_PCI_HOST 0x00000010
  842. +#define AR2315_IF_PCI_INTR 0x00000020
  843. +#define AR2315_IF_PCI_CLK_MASK 0x00030000
  844. +#define AR2315_IF_PCI_CLK_INPUT 0
  845. +#define AR2315_IF_PCI_CLK_OUTPUT_LOW 1
  846. +#define AR2315_IF_PCI_CLK_OUTPUT_CLK 2
  847. +#define AR2315_IF_PCI_CLK_OUTPUT_HIGH 3
  848. +#define AR2315_IF_PCI_CLK_SHIFT 16
  849. +
  850. +/*
  851. + * APB Interrupt control
  852. + */
  853. +
  854. +#define AR2315_ISR (AR2315_DSLBASE + 0x0020)
  855. +#define AR2315_IMR (AR2315_DSLBASE + 0x0024)
  856. +#define AR2315_GISR (AR2315_DSLBASE + 0x0028)
  857. +
  858. +#define AR2315_ISR_UART0 0x0001 /* high speed UART */
  859. +#define AR2315_ISR_I2C_RSVD 0x0002 /* I2C bus */
  860. +#define AR2315_ISR_SPI 0x0004 /* SPI bus */
  861. +#define AR2315_ISR_AHB 0x0008 /* AHB error */
  862. +#define AR2315_ISR_APB 0x0010 /* APB error */
  863. +#define AR2315_ISR_TIMER 0x0020 /* timer */
  864. +#define AR2315_ISR_GPIO 0x0040 /* GPIO */
  865. +#define AR2315_ISR_WD 0x0080 /* watchdog */
  866. +#define AR2315_ISR_IR_RSVD 0x0100 /* IR */
  867. +
  868. +#define AR2315_GISR_MISC 0x0001
  869. +#define AR2315_GISR_WLAN0 0x0002
  870. +#define AR2315_GISR_MPEGTS_RSVD 0x0004
  871. +#define AR2315_GISR_LOCALPCI 0x0008
  872. +#define AR2315_GISR_WMACPOLL 0x0010
  873. +#define AR2315_GISR_TIMER 0x0020
  874. +#define AR2315_GISR_ETHERNET 0x0040
  875. +
  876. +/*
  877. + * Interrupt routing from IO to the processor IP bits
  878. + * Define our inter mask and level
  879. + */
  880. +#define AR2315_INTR_MISCIO SR_IBIT3
  881. +#define AR2315_INTR_WLAN0 SR_IBIT4
  882. +#define AR2315_INTR_ENET0 SR_IBIT5
  883. +#define AR2315_INTR_LOCALPCI SR_IBIT6
  884. +#define AR2315_INTR_WMACPOLL SR_IBIT7
  885. +#define AR2315_INTR_COMPARE SR_IBIT8
  886. +
  887. +/*
  888. + * Timers
  889. + */
  890. +#define AR2315_TIMER (AR2315_DSLBASE + 0x0030)
  891. +#define AR2315_RELOAD (AR2315_DSLBASE + 0x0034)
  892. +#define AR2315_WD (AR2315_DSLBASE + 0x0038)
  893. +#define AR2315_WDC (AR2315_DSLBASE + 0x003c)
  894. +
  895. +#define AR2315_WDC_IGNORE_EXPIRATION 0x00000000
  896. +#define AR2315_WDC_NMI 0x00000001 /* NMI on watchdog */
  897. +#define AR2315_WDC_RESET 0x00000002 /* reset on watchdog */
  898. +
  899. +/*
  900. + * CPU Performance Counters
  901. + */
  902. +#define AR2315_PERFCNT0 (AR2315_DSLBASE + 0x0048)
  903. +#define AR2315_PERFCNT1 (AR2315_DSLBASE + 0x004c)
  904. +
  905. +#define AR2315_PERF0_DATAHIT 0x0001 /* Count Data Cache Hits */
  906. +#define AR2315_PERF0_DATAMISS 0x0002 /* Count Data Cache Misses */
  907. +#define AR2315_PERF0_INSTHIT 0x0004 /* Count Instruction Cache Hits */
  908. +#define AR2315_PERF0_INSTMISS 0x0008 /* Count Instruction Cache Misses */
  909. +#define AR2315_PERF0_ACTIVE 0x0010 /* Count Active Processor Cycles */
  910. +#define AR2315_PERF0_WBHIT 0x0020 /* Count CPU Write Buffer Hits */
  911. +#define AR2315_PERF0_WBMISS 0x0040 /* Count CPU Write Buffer Misses */
  912. +
  913. +#define AR2315_PERF1_EB_ARDY 0x0001 /* Count EB_ARdy signal */
  914. +#define AR2315_PERF1_EB_AVALID 0x0002 /* Count EB_AValid signal */
  915. +#define AR2315_PERF1_EB_WDRDY 0x0004 /* Count EB_WDRdy signal */
  916. +#define AR2315_PERF1_EB_RDVAL 0x0008 /* Count EB_RdVal signal */
  917. +#define AR2315_PERF1_VRADDR 0x0010 /* Count valid read address cycles */
  918. +#define AR2315_PERF1_VWADDR 0x0020 /* Count valid write address cycles */
  919. +#define AR2315_PERF1_VWDATA 0x0040 /* Count valid write data cycles */
  920. +
  921. +/*
  922. + * AHB Error Reporting.
  923. + */
  924. +#define AR2315_AHB_ERR0 (AR2315_DSLBASE + 0x0050) /* error */
  925. +#define AR2315_AHB_ERR1 (AR2315_DSLBASE + 0x0054) /* haddr */
  926. +#define AR2315_AHB_ERR2 (AR2315_DSLBASE + 0x0058) /* hwdata */
  927. +#define AR2315_AHB_ERR3 (AR2315_DSLBASE + 0x005c) /* hrdata */
  928. +#define AR2315_AHB_ERR4 (AR2315_DSLBASE + 0x0060) /* status */
  929. +
  930. +#define AHB_ERROR_DET 1 /* AHB Error has been detected, */
  931. + /* write 1 to clear all bits in ERR0 */
  932. +#define AHB_ERROR_OVR 2 /* AHB Error overflow has been detected */
  933. +#define AHB_ERROR_WDT 4 /* AHB Error due to wdt instead of hresp */
  934. +
  935. +#define AR2315_PROCERR_HMAST 0x0000000f
  936. +#define AR2315_PROCERR_HMAST_DFLT 0
  937. +#define AR2315_PROCERR_HMAST_WMAC 1
  938. +#define AR2315_PROCERR_HMAST_ENET 2
  939. +#define AR2315_PROCERR_HMAST_PCIENDPT 3
  940. +#define AR2315_PROCERR_HMAST_LOCAL 4
  941. +#define AR2315_PROCERR_HMAST_CPU 5
  942. +#define AR2315_PROCERR_HMAST_PCITGT 6
  943. +
  944. +#define AR2315_PROCERR_HMAST_S 0
  945. +#define AR2315_PROCERR_HWRITE 0x00000010
  946. +#define AR2315_PROCERR_HSIZE 0x00000060
  947. +#define AR2315_PROCERR_HSIZE_S 5
  948. +#define AR2315_PROCERR_HTRANS 0x00000180
  949. +#define AR2315_PROCERR_HTRANS_S 7
  950. +#define AR2315_PROCERR_HBURST 0x00000e00
  951. +#define AR2315_PROCERR_HBURST_S 9
  952. +
  953. +/*
  954. + * Clock Control
  955. + */
  956. +#define AR2315_PLLC_CTL (AR2315_DSLBASE + 0x0064)
  957. +#define AR2315_PLLV_CTL (AR2315_DSLBASE + 0x0068)
  958. +#define AR2315_CPUCLK (AR2315_DSLBASE + 0x006c)
  959. +#define AR2315_AMBACLK (AR2315_DSLBASE + 0x0070)
  960. +#define AR2315_SYNCCLK (AR2315_DSLBASE + 0x0074)
  961. +#define AR2315_DSL_SLEEP_CTL (AR2315_DSLBASE + 0x0080)
  962. +#define AR2315_DSL_SLEEP_DUR (AR2315_DSLBASE + 0x0084)
  963. +
  964. +/* PLLc Control fields */
  965. +#define PLLC_REF_DIV_M 0x00000003
  966. +#define PLLC_REF_DIV_S 0
  967. +#define PLLC_FDBACK_DIV_M 0x0000007C
  968. +#define PLLC_FDBACK_DIV_S 2
  969. +#define PLLC_ADD_FDBACK_DIV_M 0x00000080
  970. +#define PLLC_ADD_FDBACK_DIV_S 7
  971. +#define PLLC_CLKC_DIV_M 0x0001c000
  972. +#define PLLC_CLKC_DIV_S 14
  973. +#define PLLC_CLKM_DIV_M 0x00700000
  974. +#define PLLC_CLKM_DIV_S 20
  975. +
  976. +/* CPU CLK Control fields */
  977. +#define CPUCLK_CLK_SEL_M 0x00000003
  978. +#define CPUCLK_CLK_SEL_S 0
  979. +#define CPUCLK_CLK_DIV_M 0x0000000c
  980. +#define CPUCLK_CLK_DIV_S 2
  981. +
  982. +/* AMBA CLK Control fields */
  983. +#define AMBACLK_CLK_SEL_M 0x00000003
  984. +#define AMBACLK_CLK_SEL_S 0
  985. +#define AMBACLK_CLK_DIV_M 0x0000000c
  986. +#define AMBACLK_CLK_DIV_S 2
  987. +
  988. +/*
  989. + * GPIO
  990. + */
  991. +#define AR2315_GPIO_DI (AR2315_DSLBASE + 0x0088)
  992. +#define AR2315_GPIO_DO (AR2315_DSLBASE + 0x0090)
  993. +#define AR2315_GPIO_CR (AR2315_DSLBASE + 0x0098)
  994. +#define AR2315_GPIO_INT (AR2315_DSLBASE + 0x00a0)
  995. +
  996. +#define AR2315_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  997. +#define AR2315_GPIO_CR_O(x) (1 << (x)) /* output */
  998. +#define AR2315_GPIO_CR_I(x) (0) /* input */
  999. +
  1000. +#define AR2315_GPIO_INT_S(x) (x) /* interrupt enable */
  1001. +#define AR2315_GPIO_INT_M (0x3F) /* mask for int */
  1002. +#define AR2315_GPIO_INT_LVL(x) ((x) << 6) /* interrupt level */
  1003. +#define AR2315_GPIO_INT_LVL_M ((0x3) << 6) /* mask for int level */
  1004. +
  1005. +#define AR2315_GPIO_INT_MAX_Y 1 /* Maximum value of Y for AR5313_GPIO_INT_* macros */
  1006. +#define AR2315_GPIO_INT_LVL_OFF 0 /* Triggerring off */
  1007. +#define AR2315_GPIO_INT_LVL_LOW 1 /* Low Level Triggered */
  1008. +#define AR2315_GPIO_INT_LVL_HIGH 2 /* High Level Triggered */
  1009. +#define AR2315_GPIO_INT_LVL_EDGE 3 /* Edge Triggered */
  1010. +
  1011. +#define AR2315_RESET_GPIO 5
  1012. +#define AR2315_NUM_GPIO 22
  1013. +
  1014. +/*
  1015. + * PCI Clock Control
  1016. + */
  1017. +#define AR2315_PCICLK (AR2315_DSLBASE + 0x00a4)
  1018. +
  1019. +#define AR2315_PCICLK_INPUT_M 0x3
  1020. +#define AR2315_PCICLK_INPUT_S 0
  1021. +
  1022. +#define AR2315_PCICLK_PLLC_CLKM 0
  1023. +#define AR2315_PCICLK_PLLC_CLKM1 1
  1024. +#define AR2315_PCICLK_PLLC_CLKC 2
  1025. +#define AR2315_PCICLK_REF_CLK 3
  1026. +
  1027. +#define AR2315_PCICLK_DIV_M 0xc
  1028. +#define AR2315_PCICLK_DIV_S 2
  1029. +
  1030. +#define AR2315_PCICLK_IN_FREQ 0
  1031. +#define AR2315_PCICLK_IN_FREQ_DIV_6 1
  1032. +#define AR2315_PCICLK_IN_FREQ_DIV_8 2
  1033. +#define AR2315_PCICLK_IN_FREQ_DIV_10 3
  1034. +
  1035. +/*
  1036. + * Observation Control Register
  1037. + */
  1038. +#define AR2315_OCR (AR2315_DSLBASE + 0x00b0)
  1039. +#define OCR_GPIO0_IRIN 0x0040
  1040. +#define OCR_GPIO1_IROUT 0x0080
  1041. +#define OCR_GPIO3_RXCLR 0x0200
  1042. +
  1043. +/*
  1044. + * General Clock Control
  1045. + */
  1046. +
  1047. +#define AR2315_MISCCLK (AR2315_DSLBASE + 0x00b4)
  1048. +#define MISCCLK_PLLBYPASS_EN 0x00000001
  1049. +#define MISCCLK_PROCREFCLK 0x00000002
  1050. +
  1051. +/*
  1052. + * SDRAM Controller
  1053. + * - No read or write buffers are included.
  1054. + */
  1055. +#define AR2315_MEM_CFG (AR2315_SDRAMCTL + 0x00)
  1056. +#define AR2315_MEM_CTRL (AR2315_SDRAMCTL + 0x0c)
  1057. +#define AR2315_MEM_REF (AR2315_SDRAMCTL + 0x10)
  1058. +
  1059. +#define SDRAM_DATA_WIDTH_M 0x00006000
  1060. +#define SDRAM_DATA_WIDTH_S 13
  1061. +
  1062. +#define SDRAM_COL_WIDTH_M 0x00001E00
  1063. +#define SDRAM_COL_WIDTH_S 9
  1064. +
  1065. +#define SDRAM_ROW_WIDTH_M 0x000001E0
  1066. +#define SDRAM_ROW_WIDTH_S 5
  1067. +
  1068. +#define SDRAM_BANKADDR_BITS_M 0x00000018
  1069. +#define SDRAM_BANKADDR_BITS_S 3
  1070. +
  1071. +/*
  1072. + * SPI Flash Interface Registers
  1073. + */
  1074. +
  1075. +#define AR2315_SPI_CTL (AR2315_SPI + 0x00)
  1076. +#define AR2315_SPI_OPCODE (AR2315_SPI + 0x04)
  1077. +#define AR2315_SPI_DATA (AR2315_SPI + 0x08)
  1078. +
  1079. +#define SPI_CTL_START 0x00000100
  1080. +#define SPI_CTL_BUSY 0x00010000
  1081. +#define SPI_CTL_TXCNT_MASK 0x0000000f
  1082. +#define SPI_CTL_RXCNT_MASK 0x000000f0
  1083. +#define SPI_CTL_TX_RX_CNT_MASK 0x000000ff
  1084. +#define SPI_CTL_SIZE_MASK 0x00060000
  1085. +
  1086. +#define SPI_CTL_CLK_SEL_MASK 0x03000000
  1087. +#define SPI_OPCODE_MASK 0x000000ff
  1088. +
  1089. +/*
  1090. + * PCI Bus Interface Registers
  1091. + */
  1092. +#define AR2315_PCI_1MS_REG (AR2315_PCI + 0x0008)
  1093. +#define AR2315_PCI_1MS_MASK 0x3FFFF /* # of AHB clk cycles in 1ms */
  1094. +
  1095. +#define AR2315_PCI_MISC_CONFIG (AR2315_PCI + 0x000c)
  1096. +#define AR2315_PCIMISC_TXD_EN 0x00000001 /* Enable TXD for fragments */
  1097. +#define AR2315_PCIMISC_CFG_SEL 0x00000002 /* mem or config cycles */
  1098. +#define AR2315_PCIMISC_GIG_MASK 0x0000000C /* bits 31-30 for pci req */
  1099. +#define AR2315_PCIMISC_RST_MODE 0x00000030
  1100. +#define AR2315_PCIRST_INPUT 0x00000000 /* 4:5=0 rst is input */
  1101. +#define AR2315_PCIRST_LOW 0x00000010 /* 4:5=1 rst to GND */
  1102. +#define AR2315_PCIRST_HIGH 0x00000020 /* 4:5=2 rst to VDD */
  1103. +#define AR2315_PCIGRANT_EN 0x00000000 /* 6:7=0 early grant en */
  1104. +#define AR2315_PCIGRANT_FRAME 0x00000040 /* 6:7=1 grant waits 4 frame */
  1105. +#define AR2315_PCIGRANT_IDLE 0x00000080 /* 6:7=2 grant waits 4 idle */
  1106. +#define AR2315_PCIGRANT_GAP 0x00000000 /* 6:7=2 grant waits 4 idle */
  1107. +#define AR2315_PCICACHE_DIS 0x00001000 /* PCI external access cache disable */
  1108. +
  1109. +#define AR2315_PCI_OUT_TSTAMP (AR2315_PCI + 0x0010)
  1110. +
  1111. +#define AR2315_PCI_UNCACHE_CFG (AR2315_PCI + 0x0014)
  1112. +
  1113. +#define AR2315_PCI_IN_EN (AR2315_PCI + 0x0100)
  1114. +#define AR2315_PCI_IN_EN0 0x01 /* Enable chain 0 */
  1115. +#define AR2315_PCI_IN_EN1 0x02 /* Enable chain 1 */
  1116. +#define AR2315_PCI_IN_EN2 0x04 /* Enable chain 2 */
  1117. +#define AR2315_PCI_IN_EN3 0x08 /* Enable chain 3 */
  1118. +
  1119. +#define AR2315_PCI_IN_DIS (AR2315_PCI + 0x0104)
  1120. +#define AR2315_PCI_IN_DIS0 0x01 /* Disable chain 0 */
  1121. +#define AR2315_PCI_IN_DIS1 0x02 /* Disable chain 1 */
  1122. +#define AR2315_PCI_IN_DIS2 0x04 /* Disable chain 2 */
  1123. +#define AR2315_PCI_IN_DIS3 0x08 /* Disable chain 3 */
  1124. +
  1125. +#define AR2315_PCI_IN_PTR (AR2315_PCI + 0x0200)
  1126. +
  1127. +#define AR2315_PCI_OUT_EN (AR2315_PCI + 0x0400)
  1128. +#define AR2315_PCI_OUT_EN0 0x01 /* Enable chain 0 */
  1129. +
  1130. +#define AR2315_PCI_OUT_DIS (AR2315_PCI + 0x0404)
  1131. +#define AR2315_PCI_OUT_DIS0 0x01 /* Disable chain 0 */
  1132. +
  1133. +#define AR2315_PCI_OUT_PTR (AR2315_PCI + 0x0408)
  1134. +
  1135. +#define AR2315_PCI_INT_STATUS (AR2315_PCI + 0x0500) /* write one to clr */
  1136. +#define AR2315_PCI_TXINT 0x00000001 /* Desc In Completed */
  1137. +#define AR2315_PCI_TXOK 0x00000002 /* Desc In OK */
  1138. +#define AR2315_PCI_TXERR 0x00000004 /* Desc In ERR */
  1139. +#define AR2315_PCI_TXEOL 0x00000008 /* Desc In End-of-List */
  1140. +#define AR2315_PCI_RXINT 0x00000010 /* Desc Out Completed */
  1141. +#define AR2315_PCI_RXOK 0x00000020 /* Desc Out OK */
  1142. +#define AR2315_PCI_RXERR 0x00000040 /* Desc Out ERR */
  1143. +#define AR2315_PCI_RXEOL 0x00000080 /* Desc Out EOL */
  1144. +#define AR2315_PCI_TXOOD 0x00000200 /* Desc In Out-of-Desc */
  1145. +#define AR2315_PCI_MASK 0x0000FFFF /* Desc Mask */
  1146. +#define AR2315_PCI_EXT_INT 0x02000000
  1147. +#define AR2315_PCI_ABORT_INT 0x04000000
  1148. +
  1149. +#define AR2315_PCI_INT_MASK (AR2315_PCI + 0x0504) /* same as INT_STATUS */
  1150. +
  1151. +#define AR2315_PCI_INTEN_REG (AR2315_PCI + 0x0508)
  1152. +#define AR2315_PCI_INT_DISABLE 0x00 /* disable pci interrupts */
  1153. +#define AR2315_PCI_INT_ENABLE 0x01 /* enable pci interrupts */
  1154. +
  1155. +#define AR2315_PCI_HOST_IN_EN (AR2315_PCI + 0x0800)
  1156. +#define AR2315_PCI_HOST_IN_DIS (AR2315_PCI + 0x0804)
  1157. +#define AR2315_PCI_HOST_IN_PTR (AR2315_PCI + 0x0810)
  1158. +#define AR2315_PCI_HOST_OUT_EN (AR2315_PCI + 0x0900)
  1159. +#define AR2315_PCI_HOST_OUT_DIS (AR2315_PCI + 0x0904)
  1160. +#define AR2315_PCI_HOST_OUT_PTR (AR2315_PCI + 0x0908)
  1161. +
  1162. +
  1163. +/*
  1164. + * Local Bus Interface Registers
  1165. + */
  1166. +#define AR2315_LB_CONFIG (AR2315_LOCAL + 0x0000)
  1167. +#define AR2315_LBCONF_OE 0x00000001 /* =1 OE is low-true */
  1168. +#define AR2315_LBCONF_CS0 0x00000002 /* =1 first CS is low-true */
  1169. +#define AR2315_LBCONF_CS1 0x00000004 /* =1 2nd CS is low-true */
  1170. +#define AR2315_LBCONF_RDY 0x00000008 /* =1 RDY is low-true */
  1171. +#define AR2315_LBCONF_WE 0x00000010 /* =1 Write En is low-true */
  1172. +#define AR2315_LBCONF_WAIT 0x00000020 /* =1 WAIT is low-true */
  1173. +#define AR2315_LBCONF_ADS 0x00000040 /* =1 Adr Strobe is low-true */
  1174. +#define AR2315_LBCONF_MOT 0x00000080 /* =0 Intel, =1 Motorola */
  1175. +#define AR2315_LBCONF_8CS 0x00000100 /* =1 8 bits CS, 0= 16bits */
  1176. +#define AR2315_LBCONF_8DS 0x00000200 /* =1 8 bits Data S, 0=16bits */
  1177. +#define AR2315_LBCONF_ADS_EN 0x00000400 /* =1 Enable ADS */
  1178. +#define AR2315_LBCONF_ADR_OE 0x00000800 /* =1 Adr cap on OE, WE or DS */
  1179. +#define AR2315_LBCONF_ADDT_MUX 0x00001000 /* =1 Adr and Data share bus */
  1180. +#define AR2315_LBCONF_DATA_OE 0x00002000 /* =1 Data cap on OE, WE, DS */
  1181. +#define AR2315_LBCONF_16DATA 0x00004000 /* =1 Data is 16 bits wide */
  1182. +#define AR2315_LBCONF_SWAPDT 0x00008000 /* =1 Byte swap data */
  1183. +#define AR2315_LBCONF_SYNC 0x00010000 /* =1 Bus synchronous to clk */
  1184. +#define AR2315_LBCONF_INT 0x00020000 /* =1 Intr is low true */
  1185. +#define AR2315_LBCONF_INT_CTR0 0x00000000 /* GND high-Z, Vdd is high-Z */
  1186. +#define AR2315_LBCONF_INT_CTR1 0x00040000 /* GND drive, Vdd is high-Z */
  1187. +#define AR2315_LBCONF_INT_CTR2 0x00080000 /* GND high-Z, Vdd drive */
  1188. +#define AR2315_LBCONF_INT_CTR3 0x000C0000 /* GND drive, Vdd drive */
  1189. +#define AR2315_LBCONF_RDY_WAIT 0x00100000 /* =1 RDY is negative of WAIT */
  1190. +#define AR2315_LBCONF_INT_PULSE 0x00200000 /* =1 Interrupt is a pulse */
  1191. +#define AR2315_LBCONF_ENABLE 0x00400000 /* =1 Falcon respond to LB */
  1192. +
  1193. +#define AR2315_LB_CLKSEL (AR2315_LOCAL + 0x0004)
  1194. +#define AR2315_LBCLK_EXT 0x0001 /* use external clk for lb */
  1195. +
  1196. +#define AR2315_LB_1MS (AR2315_LOCAL + 0x0008)
  1197. +#define AR2315_LB1MS_MASK 0x3FFFF /* # of AHB clk cycles in 1ms */
  1198. +
  1199. +#define AR2315_LB_MISCCFG (AR2315_LOCAL + 0x000C)
  1200. +#define AR2315_LBM_TXD_EN 0x00000001 /* Enable TXD for fragments */
  1201. +#define AR2315_LBM_RX_INTEN 0x00000002 /* Enable LB ints on RX ready */
  1202. +#define AR2315_LBM_MBOXWR_INTEN 0x00000004 /* Enable LB ints on mbox wr */
  1203. +#define AR2315_LBM_MBOXRD_INTEN 0x00000008 /* Enable LB ints on mbox rd */
  1204. +#define AR2315_LMB_DESCSWAP_EN 0x00000010 /* Byte swap desc enable */
  1205. +#define AR2315_LBM_TIMEOUT_MASK 0x00FFFF80
  1206. +#define AR2315_LBM_TIMEOUT_SHFT 7
  1207. +#define AR2315_LBM_PORTMUX 0x07000000
  1208. +
  1209. +
  1210. +#define AR2315_LB_RXTSOFF (AR2315_LOCAL + 0x0010)
  1211. +
  1212. +#define AR2315_LB_TX_CHAIN_EN (AR2315_LOCAL + 0x0100)
  1213. +#define AR2315_LB_TXEN_0 0x01
  1214. +#define AR2315_LB_TXEN_1 0x02
  1215. +#define AR2315_LB_TXEN_2 0x04
  1216. +#define AR2315_LB_TXEN_3 0x08
  1217. +
  1218. +#define AR2315_LB_TX_CHAIN_DIS (AR2315_LOCAL + 0x0104)
  1219. +#define AR2315_LB_TX_DESC_PTR (AR2315_LOCAL + 0x0200)
  1220. +
  1221. +#define AR2315_LB_RX_CHAIN_EN (AR2315_LOCAL + 0x0400)
  1222. +#define AR2315_LB_RXEN 0x01
  1223. +
  1224. +#define AR2315_LB_RX_CHAIN_DIS (AR2315_LOCAL + 0x0404)
  1225. +#define AR2315_LB_RX_DESC_PTR (AR2315_LOCAL + 0x0408)
  1226. +
  1227. +#define AR2315_LB_INT_STATUS (AR2315_LOCAL + 0x0500)
  1228. +#define AR2315_INT_TX_DESC 0x0001
  1229. +#define AR2315_INT_TX_OK 0x0002
  1230. +#define AR2315_INT_TX_ERR 0x0004
  1231. +#define AR2315_INT_TX_EOF 0x0008
  1232. +#define AR2315_INT_RX_DESC 0x0010
  1233. +#define AR2315_INT_RX_OK 0x0020
  1234. +#define AR2315_INT_RX_ERR 0x0040
  1235. +#define AR2315_INT_RX_EOF 0x0080
  1236. +#define AR2315_INT_TX_TRUNC 0x0100
  1237. +#define AR2315_INT_TX_STARVE 0x0200
  1238. +#define AR2315_INT_LB_TIMEOUT 0x0400
  1239. +#define AR2315_INT_LB_ERR 0x0800
  1240. +#define AR2315_INT_MBOX_WR 0x1000
  1241. +#define AR2315_INT_MBOX_RD 0x2000
  1242. +
  1243. +/* Bit definitions for INT MASK are the same as INT_STATUS */
  1244. +#define AR2315_LB_INT_MASK (AR2315_LOCAL + 0x0504)
  1245. +
  1246. +#define AR2315_LB_INT_EN (AR2315_LOCAL + 0x0508)
  1247. +#define AR2315_LB_MBOX (AR2315_LOCAL + 0x0600)
  1248. +
  1249. +/*
  1250. + * IR Interface Registers
  1251. + */
  1252. +#define AR2315_IR_PKTDATA (AR2315_IR + 0x0000)
  1253. +
  1254. +#define AR2315_IR_PKTLEN (AR2315_IR + 0x07fc) /* 0 - 63 */
  1255. +
  1256. +#define AR2315_IR_CONTROL (AR2315_IR + 0x0800)
  1257. +#define AR2315_IRCTL_TX 0x00000000 /* use as tranmitter */
  1258. +#define AR2315_IRCTL_RX 0x00000001 /* use as receiver */
  1259. +#define AR2315_IRCTL_SAMPLECLK_MASK 0x00003ffe /* Sample clk divisor mask */
  1260. +#define AR2315_IRCTL_SAMPLECLK_SHFT 1
  1261. +#define AR2315_IRCTL_OUTPUTCLK_MASK 0x03ffc000 /* Output clk divisor mask */
  1262. +#define AR2315_IRCTL_OUTPUTCLK_SHFT 14
  1263. +
  1264. +#define AR2315_IR_STATUS (AR2315_IR + 0x0804)
  1265. +#define AR2315_IRSTS_RX 0x00000001 /* receive in progress */
  1266. +#define AR2315_IRSTS_TX 0x00000002 /* transmit in progress */
  1267. +
  1268. +#define AR2315_IR_CONFIG (AR2315_IR + 0x0808)
  1269. +#define AR2315_IRCFG_INVIN 0x00000001 /* invert input polarity */
  1270. +#define AR2315_IRCFG_INVOUT 0x00000002 /* invert output polarity */
  1271. +#define AR2315_IRCFG_SEQ_START_WIN_SEL 0x00000004 /* 1 => 28, 0 => 7 */
  1272. +#define AR2315_IRCFG_SEQ_START_THRESH 0x000000f0 /* */
  1273. +#define AR2315_IRCFG_SEQ_END_UNIT_SEL 0x00000100 /* */
  1274. +#define AR2315_IRCFG_SEQ_END_UNIT_THRESH 0x00007e00 /* */
  1275. +#define AR2315_IRCFG_SEQ_END_WIN_SEL 0x00008000 /* */
  1276. +#define AR2315_IRCFG_SEQ_END_WIN_THRESH 0x001f0000 /* */
  1277. +#define AR2315_IRCFG_NUM_BACKOFF_WORDS 0x01e00000 /* */
  1278. +
  1279. +#define HOST_PCI_DEV_ID 3
  1280. +#define HOST_PCI_MBAR0 0x10000000
  1281. +#define HOST_PCI_MBAR1 0x20000000
  1282. +#define HOST_PCI_MBAR2 0x30000000
  1283. +
  1284. +#define HOST_PCI_SDRAM_BASEADDR HOST_PCI_MBAR1
  1285. +#define PCI_DEVICE_MEM_SPACE 0x800000
  1286. +
  1287. +#endif /* __AR2315_REG_H */
  1288. --- /dev/null
  1289. +++ b/arch/mips/include/asm/mach-ar231x/ar5312_regs.h
  1290. @@ -0,0 +1,236 @@
  1291. +/*
  1292. + * This file is subject to the terms and conditions of the GNU General Public
  1293. + * License. See the file "COPYING" in the main directory of this archive
  1294. + * for more details.
  1295. + *
  1296. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1297. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  1298. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  1299. + */
  1300. +
  1301. +#ifndef AR5312_H
  1302. +#define AR5312_H
  1303. +
  1304. +#include <asm/addrspace.h>
  1305. +
  1306. +/*
  1307. + * IRQs
  1308. + */
  1309. +
  1310. +#define AR5312_IRQ_WLAN0_INTRS MIPS_CPU_IRQ_BASE+2 /* C0_CAUSE: 0x0400 */
  1311. +#define AR5312_IRQ_ENET0_INTRS MIPS_CPU_IRQ_BASE+3 /* C0_CAUSE: 0x0800 */
  1312. +#define AR5312_IRQ_ENET1_INTRS MIPS_CPU_IRQ_BASE+4 /* C0_CAUSE: 0x1000 */
  1313. +#define AR5312_IRQ_WLAN1_INTRS MIPS_CPU_IRQ_BASE+5 /* C0_CAUSE: 0x2000 */
  1314. +#define AR5312_IRQ_MISC_INTRS MIPS_CPU_IRQ_BASE+6 /* C0_CAUSE: 0x4000 */
  1315. +
  1316. +
  1317. +/* Address Map */
  1318. +#define AR531X_WLAN0 0x18000000
  1319. +#define AR531X_WLAN1 0x18500000
  1320. +#define AR531X_ENET0 0x18100000
  1321. +#define AR531X_ENET1 0x18200000
  1322. +#define AR531X_SDRAMCTL 0x18300000
  1323. +#define AR531X_FLASHCTL 0x18400000
  1324. +#define AR531X_APBBASE 0x1c000000
  1325. +#define AR531X_FLASH 0x1e000000
  1326. +#define AR531X_UART0 0xbc000003 /* UART MMR */
  1327. +
  1328. +/*
  1329. + * AR531X_NUM_ENET_MAC defines the number of ethernet MACs that
  1330. + * should be considered available. The AR5312 supports 2 enet MACS,
  1331. + * even though many reference boards only actually use 1 of them
  1332. + * (i.e. Only MAC 0 is actually connected to an enet PHY or PHY switch.
  1333. + * The AR2312 supports 1 enet MAC.
  1334. + */
  1335. +#define AR531X_NUM_ENET_MAC 2
  1336. +
  1337. +/*
  1338. + * Need these defines to determine true number of ethernet MACs
  1339. + */
  1340. +#define AR5212_AR5312_REV2 0x0052 /* AR5312 WMAC (AP31) */
  1341. +#define AR5212_AR5312_REV7 0x0057 /* AR5312 WMAC (AP30-040) */
  1342. +#define AR5212_AR2313_REV8 0x0058 /* AR2313 WMAC (AP43-030) */
  1343. +#define AR531X_RADIO_MASK_OFF 0xc8
  1344. +#define AR531X_RADIO0_MASK 0x0003
  1345. +#define AR531X_RADIO1_MASK 0x000c
  1346. +#define AR531X_RADIO1_S 2
  1347. +
  1348. +/*
  1349. + * AR531X_NUM_WMAC defines the number of Wireless MACs that\
  1350. + * should be considered available.
  1351. + */
  1352. +#define AR531X_NUM_WMAC 2
  1353. +
  1354. +/* Reset/Timer Block Address Map */
  1355. +#define AR531X_RESETTMR (AR531X_APBBASE + 0x3000)
  1356. +#define AR531X_TIMER (AR531X_RESETTMR + 0x0000) /* countdown timer */
  1357. +#define AR531X_WD_CTRL (AR531X_RESETTMR + 0x0008) /* watchdog cntrl */
  1358. +#define AR531X_WD_TIMER (AR531X_RESETTMR + 0x000c) /* watchdog timer */
  1359. +#define AR531X_ISR (AR531X_RESETTMR + 0x0010) /* Intr Status Reg */
  1360. +#define AR531X_IMR (AR531X_RESETTMR + 0x0014) /* Intr Mask Reg */
  1361. +#define AR531X_RESET (AR531X_RESETTMR + 0x0020)
  1362. +#define AR5312_CLOCKCTL1 (AR531X_RESETTMR + 0x0064)
  1363. +#define AR5312_SCRATCH (AR531X_RESETTMR + 0x006c)
  1364. +#define AR531X_PROCADDR (AR531X_RESETTMR + 0x0070)
  1365. +#define AR531X_PROC1 (AR531X_RESETTMR + 0x0074)
  1366. +#define AR531X_DMAADDR (AR531X_RESETTMR + 0x0078)
  1367. +#define AR531X_DMA1 (AR531X_RESETTMR + 0x007c)
  1368. +#define AR531X_ENABLE (AR531X_RESETTMR + 0x0080) /* interface enb */
  1369. +#define AR531X_REV (AR531X_RESETTMR + 0x0090) /* revision */
  1370. +
  1371. +/* AR531X_WD_CTRL register bit field definitions */
  1372. +#define AR531X_WD_CTRL_IGNORE_EXPIRATION 0x0000
  1373. +#define AR531X_WD_CTRL_NMI 0x0001
  1374. +#define AR531X_WD_CTRL_RESET 0x0002
  1375. +
  1376. +/* AR531X_ISR register bit field definitions */
  1377. +#define AR531X_ISR_NONE 0x0000
  1378. +#define AR531X_ISR_TIMER 0x0001
  1379. +#define AR531X_ISR_AHBPROC 0x0002
  1380. +#define AR531X_ISR_AHBDMA 0x0004
  1381. +#define AR531X_ISR_GPIO 0x0008
  1382. +#define AR531X_ISR_UART0 0x0010
  1383. +#define AR531X_ISR_UART0DMA 0x0020
  1384. +#define AR531X_ISR_WD 0x0040
  1385. +#define AR531X_ISR_LOCAL 0x0080
  1386. +
  1387. +/* AR531X_RESET register bit field definitions */
  1388. +#define AR531X_RESET_SYSTEM 0x00000001 /* cold reset full system */
  1389. +#define AR531X_RESET_PROC 0x00000002 /* cold reset MIPS core */
  1390. +#define AR531X_RESET_WLAN0 0x00000004 /* cold reset WLAN MAC and BB */
  1391. +#define AR531X_RESET_EPHY0 0x00000008 /* cold reset ENET0 phy */
  1392. +#define AR531X_RESET_EPHY1 0x00000010 /* cold reset ENET1 phy */
  1393. +#define AR531X_RESET_ENET0 0x00000020 /* cold reset ENET0 mac */
  1394. +#define AR531X_RESET_ENET1 0x00000040 /* cold reset ENET1 mac */
  1395. +#define AR531X_RESET_UART0 0x00000100 /* cold reset UART0 (high speed) */
  1396. +#define AR531X_RESET_WLAN1 0x00000200 /* cold reset WLAN MAC/BB */
  1397. +#define AR531X_RESET_APB 0x00000400 /* cold reset APB (ar5312) */
  1398. +#define AR531X_RESET_WARM_PROC 0x00001000 /* warm reset MIPS core */
  1399. +#define AR531X_RESET_WARM_WLAN0_MAC 0x00002000 /* warm reset WLAN0 MAC */
  1400. +#define AR531X_RESET_WARM_WLAN0_BB 0x00004000 /* warm reset WLAN0 BaseBand */
  1401. +#define AR531X_RESET_NMI 0x00010000 /* send an NMI to the processor */
  1402. +#define AR531X_RESET_WARM_WLAN1_MAC 0x00020000 /* warm reset WLAN1 mac */
  1403. +#define AR531X_RESET_WARM_WLAN1_BB 0x00040000 /* warm reset WLAN1 baseband */
  1404. +#define AR531X_RESET_LOCAL_BUS 0x00080000 /* reset local bus */
  1405. +#define AR531X_RESET_WDOG 0x00100000 /* last reset was a watchdog */
  1406. +
  1407. +#define AR531X_RESET_WMAC0_BITS \
  1408. + AR531X_RESET_WLAN0 |\
  1409. + AR531X_RESET_WARM_WLAN0_MAC |\
  1410. + AR531X_RESET_WARM_WLAN0_BB
  1411. +
  1412. +#define AR531X_RESERT_WMAC1_BITS \
  1413. + AR531X_RESET_WLAN1 |\
  1414. + AR531X_RESET_WARM_WLAN1_MAC |\
  1415. + AR531X_RESET_WARM_WLAN1_BB
  1416. +
  1417. +/* AR5312_CLOCKCTL1 register bit field definitions */
  1418. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  1419. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  1420. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  1421. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  1422. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  1423. +
  1424. +/* Valid for AR5312 and AR2312 */
  1425. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  1426. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  1427. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  1428. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  1429. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  1430. +
  1431. +/* Valid for AR2313 */
  1432. +#define AR2313_CLOCKCTL1_PREDIVIDE_MASK 0x00003000
  1433. +#define AR2313_CLOCKCTL1_PREDIVIDE_SHIFT 12
  1434. +#define AR2313_CLOCKCTL1_MULTIPLIER_MASK 0x001f0000
  1435. +#define AR2313_CLOCKCTL1_MULTIPLIER_SHIFT 16
  1436. +#define AR2313_CLOCKCTL1_DOUBLER_MASK 0x00000000
  1437. +
  1438. +
  1439. +/* AR531X_ENABLE register bit field definitions */
  1440. +#define AR531X_ENABLE_WLAN0 0x0001
  1441. +#define AR531X_ENABLE_ENET0 0x0002
  1442. +#define AR531X_ENABLE_ENET1 0x0004
  1443. +#define AR531X_ENABLE_UART_AND_WLAN1_PIO 0x0008 /* UART, and WLAN1 PIOs */
  1444. +#define AR531X_ENABLE_WLAN1_DMA 0x0010 /* WLAN1 DMAs */
  1445. +#define AR531X_ENABLE_WLAN1 \
  1446. + (AR531X_ENABLE_UART_AND_WLAN1_PIO | AR531X_ENABLE_WLAN1_DMA)
  1447. +
  1448. +/* AR531X_REV register bit field definitions */
  1449. +#define AR531X_REV_WMAC_MAJ 0xf000
  1450. +#define AR531X_REV_WMAC_MAJ_S 12
  1451. +#define AR531X_REV_WMAC_MIN 0x0f00
  1452. +#define AR531X_REV_WMAC_MIN_S 8
  1453. +#define AR531X_REV_MAJ 0x00f0
  1454. +#define AR531X_REV_MAJ_S 4
  1455. +#define AR531X_REV_MIN 0x000f
  1456. +#define AR531X_REV_MIN_S 0
  1457. +#define AR531X_REV_CHIP (AR531X_REV_MAJ|AR531X_REV_MIN)
  1458. +
  1459. +/* Major revision numbers, bits 7..4 of Revision ID register */
  1460. +#define AR531X_REV_MAJ_AR5312 0x4
  1461. +#define AR531X_REV_MAJ_AR2313 0x5
  1462. +
  1463. +/* Minor revision numbers, bits 3..0 of Revision ID register */
  1464. +#define AR5312_REV_MIN_DUAL 0x0 /* Dual WLAN version */
  1465. +#define AR5312_REV_MIN_SINGLE 0x1 /* Single WLAN version */
  1466. +
  1467. +/* AR531X_FLASHCTL register bit field definitions */
  1468. +#define FLASHCTL_IDCY 0x0000000f /* Idle cycle turn around time */
  1469. +#define FLASHCTL_IDCY_S 0
  1470. +#define FLASHCTL_WST1 0x000003e0 /* Wait state 1 */
  1471. +#define FLASHCTL_WST1_S 5
  1472. +#define FLASHCTL_RBLE 0x00000400 /* Read byte lane enable */
  1473. +#define FLASHCTL_WST2 0x0000f800 /* Wait state 2 */
  1474. +#define FLASHCTL_WST2_S 11
  1475. +#define FLASHCTL_AC 0x00070000 /* Flash address check (added) */
  1476. +#define FLASHCTL_AC_S 16
  1477. +#define FLASHCTL_AC_128K 0x00000000
  1478. +#define FLASHCTL_AC_256K 0x00010000
  1479. +#define FLASHCTL_AC_512K 0x00020000
  1480. +#define FLASHCTL_AC_1M 0x00030000
  1481. +#define FLASHCTL_AC_2M 0x00040000
  1482. +#define FLASHCTL_AC_4M 0x00050000
  1483. +#define FLASHCTL_AC_8M 0x00060000
  1484. +#define FLASHCTL_AC_RES 0x00070000 /* 16MB is not supported */
  1485. +#define FLASHCTL_E 0x00080000 /* Flash bank enable (added) */
  1486. +#define FLASHCTL_BUSERR 0x01000000 /* Bus transfer error status flag */
  1487. +#define FLASHCTL_WPERR 0x02000000 /* Write protect error status flag */
  1488. +#define FLASHCTL_WP 0x04000000 /* Write protect */
  1489. +#define FLASHCTL_BM 0x08000000 /* Burst mode */
  1490. +#define FLASHCTL_MW 0x30000000 /* Memory width */
  1491. +#define FLASHCTL_MWx8 0x00000000 /* Memory width x8 */
  1492. +#define FLASHCTL_MWx16 0x10000000 /* Memory width x16 */
  1493. +#define FLASHCTL_MWx32 0x20000000 /* Memory width x32 (not supported) */
  1494. +#define FLASHCTL_ATNR 0x00000000 /* Access type == no retry */
  1495. +#define FLASHCTL_ATR 0x80000000 /* Access type == retry every */
  1496. +#define FLASHCTL_ATR4 0xc0000000 /* Access type == retry every 4 */
  1497. +
  1498. +/* ARM Flash Controller -- 3 flash banks with either x8 or x16 devices. */
  1499. +#define AR531X_FLASHCTL0 (AR531X_FLASHCTL + 0x00)
  1500. +#define AR531X_FLASHCTL1 (AR531X_FLASHCTL + 0x04)
  1501. +#define AR531X_FLASHCTL2 (AR531X_FLASHCTL + 0x08)
  1502. +
  1503. +/* ARM SDRAM Controller -- just enough to determine memory size */
  1504. +#define AR531X_MEM_CFG1 (AR531X_SDRAMCTL + 0x04)
  1505. +#define MEM_CFG1_AC0 0x00000700 /* bank 0: SDRAM addr check (added) */
  1506. +#define MEM_CFG1_AC0_S 8
  1507. +#define MEM_CFG1_AC1 0x00007000 /* bank 1: SDRAM addr check (added) */
  1508. +#define MEM_CFG1_AC1_S 12
  1509. +
  1510. +/* GPIO Address Map */
  1511. +#define AR531X_GPIO (AR531X_APBBASE + 0x2000)
  1512. +#define AR531X_GPIO_DO (AR531X_GPIO + 0x00) /* output register */
  1513. +#define AR531X_GPIO_DI (AR531X_GPIO + 0x04) /* intput register */
  1514. +#define AR531X_GPIO_CR (AR531X_GPIO + 0x08) /* control register */
  1515. +
  1516. +/* GPIO Control Register bit field definitions */
  1517. +#define AR531X_GPIO_CR_M(x) (1 << (x)) /* mask for i/o */
  1518. +#define AR531X_GPIO_CR_O(x) (0 << (x)) /* mask for output */
  1519. +#define AR531X_GPIO_CR_I(x) (1 << (x)) /* mask for input */
  1520. +#define AR531X_GPIO_CR_INT(x) (1 << ((x)+8)) /* mask for interrupt */
  1521. +#define AR531X_GPIO_CR_UART(x) (1 << ((x)+16)) /* uart multiplex */
  1522. +#define AR531X_NUM_GPIO 8
  1523. +
  1524. +
  1525. +#endif
  1526. +
  1527. --- /dev/null
  1528. +++ b/arch/mips/ar231x/ar5312.c
  1529. @@ -0,0 +1,563 @@
  1530. +/*
  1531. + * This file is subject to the terms and conditions of the GNU General Public
  1532. + * License. See the file "COPYING" in the main directory of this archive
  1533. + * for more details.
  1534. + *
  1535. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1536. + * Copyright (C) 2006 FON Technology, SL.
  1537. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  1538. + * Copyright (C) 2006-2009 Felix Fietkau <[email protected]>
  1539. + */
  1540. +
  1541. +/*
  1542. + * Platform devices for Atheros SoCs
  1543. + */
  1544. +
  1545. +#include <linux/autoconf.h>
  1546. +#include <linux/init.h>
  1547. +#include <linux/module.h>
  1548. +#include <linux/types.h>
  1549. +#include <linux/string.h>
  1550. +#include <linux/mtd/physmap.h>
  1551. +#include <linux/platform_device.h>
  1552. +#include <linux/kernel.h>
  1553. +#include <linux/reboot.h>
  1554. +#include <linux/leds.h>
  1555. +#include <asm/bootinfo.h>
  1556. +#include <asm/reboot.h>
  1557. +#include <asm/time.h>
  1558. +#include <asm/irq.h>
  1559. +#include <asm/io.h>
  1560. +#include <gpio.h>
  1561. +
  1562. +#include <ar231x_platform.h>
  1563. +#include <ar5312_regs.h>
  1564. +#include <ar231x.h>
  1565. +#include "devices.h"
  1566. +#include "ar5312.h"
  1567. +
  1568. +#define IS_5312() (current_cpu_data.cputype != CPU_4KEC)
  1569. +
  1570. +static void
  1571. +ar5312_misc_irq_dispatch(void)
  1572. +{
  1573. + unsigned int ar231x_misc_intrs = ar231x_read_reg(AR531X_ISR) & ar231x_read_reg(AR531X_IMR);
  1574. +
  1575. + if (ar231x_misc_intrs & AR531X_ISR_TIMER) {
  1576. + do_IRQ(AR531X_MISC_IRQ_TIMER);
  1577. + (void)ar231x_read_reg(AR531X_TIMER);
  1578. + } else if (ar231x_misc_intrs & AR531X_ISR_AHBPROC)
  1579. + do_IRQ(AR531X_MISC_IRQ_AHB_PROC);
  1580. + else if ((ar231x_misc_intrs & AR531X_ISR_UART0))
  1581. + do_IRQ(AR531X_MISC_IRQ_UART0);
  1582. + else if (ar231x_misc_intrs & AR531X_ISR_WD)
  1583. + do_IRQ(AR531X_MISC_IRQ_WATCHDOG);
  1584. + else
  1585. + do_IRQ(AR531X_MISC_IRQ_NONE);
  1586. +}
  1587. +
  1588. +void
  1589. +ar5312_irq_dispatch(void)
  1590. +{
  1591. + int pending = read_c0_status() & read_c0_cause();
  1592. +
  1593. + if (pending & CAUSEF_IP2)
  1594. + do_IRQ(AR5312_IRQ_WLAN0_INTRS);
  1595. + else if (pending & CAUSEF_IP3)
  1596. + do_IRQ(AR5312_IRQ_ENET0_INTRS);
  1597. + else if (pending & CAUSEF_IP4)
  1598. + do_IRQ(AR5312_IRQ_ENET1_INTRS);
  1599. + else if (pending & CAUSEF_IP5)
  1600. + do_IRQ(AR5312_IRQ_WLAN1_INTRS);
  1601. + else if (pending & CAUSEF_IP6)
  1602. + ar5312_misc_irq_dispatch();
  1603. + else if (pending & CAUSEF_IP7)
  1604. + do_IRQ(AR531X_IRQ_CPU_CLOCK);
  1605. +}
  1606. +
  1607. +
  1608. +/* Enable the specified AR531X_MISC_IRQ interrupt */
  1609. +static void
  1610. +ar5312_misc_intr_enable(unsigned int irq)
  1611. +{
  1612. + unsigned int imr;
  1613. +
  1614. + imr = ar231x_read_reg(AR531X_IMR);
  1615. + imr |= (1 << (irq - AR531X_MISC_IRQ_BASE - 1));
  1616. + ar231x_write_reg(AR531X_IMR, imr);
  1617. +}
  1618. +
  1619. +/* Disable the specified AR531X_MISC_IRQ interrupt */
  1620. +static void
  1621. +ar5312_misc_intr_disable(unsigned int irq)
  1622. +{
  1623. + unsigned int imr;
  1624. +
  1625. + imr = ar231x_read_reg(AR531X_IMR);
  1626. + imr &= ~(1 << (irq - AR531X_MISC_IRQ_BASE - 1));
  1627. + ar231x_write_reg(AR531X_IMR, imr);
  1628. + ar231x_read_reg(AR531X_IMR); /* flush write buffer */
  1629. +}
  1630. +
  1631. +static unsigned int
  1632. +ar5312_misc_intr_startup(unsigned int irq)
  1633. +{
  1634. + ar5312_misc_intr_enable(irq);
  1635. + return 0;
  1636. +}
  1637. +
  1638. +static void
  1639. +ar5312_misc_intr_end(unsigned int irq)
  1640. +{
  1641. + if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  1642. + ar5312_misc_intr_enable(irq);
  1643. +}
  1644. +
  1645. +static struct irq_chip ar5312_misc_intr_controller = {
  1646. + .name = "AR5312-MISC",
  1647. + .startup = ar5312_misc_intr_startup,
  1648. + .shutdown = ar5312_misc_intr_disable,
  1649. + .enable = ar5312_misc_intr_enable,
  1650. + .disable = ar5312_misc_intr_disable,
  1651. + .ack = ar5312_misc_intr_disable,
  1652. + .end = ar5312_misc_intr_end,
  1653. +};
  1654. +
  1655. +
  1656. +static irqreturn_t ar5312_ahb_proc_handler(int cpl, void *dev_id)
  1657. +{
  1658. + u32 proc1 = ar231x_read_reg(AR531X_PROC1);
  1659. + u32 procAddr = ar231x_read_reg(AR531X_PROCADDR); /* clears error state */
  1660. + u32 dma1 = ar231x_read_reg(AR531X_DMA1);
  1661. + u32 dmaAddr = ar231x_read_reg(AR531X_DMAADDR); /* clears error state */
  1662. +
  1663. + printk("AHB interrupt: PROCADDR=0x%8.8x PROC1=0x%8.8x DMAADDR=0x%8.8x DMA1=0x%8.8x\n",
  1664. + procAddr, proc1, dmaAddr, dma1);
  1665. +
  1666. + machine_restart("AHB error"); /* Catastrophic failure */
  1667. + return IRQ_HANDLED;
  1668. +}
  1669. +
  1670. +
  1671. +static struct irqaction ar5312_ahb_proc_interrupt = {
  1672. + .handler = ar5312_ahb_proc_handler,
  1673. + .flags = IRQF_DISABLED,
  1674. + .name = "ar5312_ahb_proc_interrupt",
  1675. +};
  1676. +
  1677. +
  1678. +static struct irqaction cascade = {
  1679. + .handler = no_action,
  1680. + .flags = IRQF_DISABLED,
  1681. + .name = "cascade",
  1682. +};
  1683. +
  1684. +void __init ar5312_irq_init(void)
  1685. +{
  1686. + int i;
  1687. +
  1688. + if (!IS_5312())
  1689. + return;
  1690. +
  1691. + ar231x_irq_dispatch = ar5312_irq_dispatch;
  1692. + for (i = 0; i < AR531X_MISC_IRQ_COUNT; i++) {
  1693. + int irq = AR531X_MISC_IRQ_BASE + i;
  1694. + irq_desc[irq].status = IRQ_DISABLED;
  1695. + irq_desc[irq].action = NULL;
  1696. + irq_desc[irq].depth = 1;
  1697. + irq_desc[irq].chip = &ar5312_misc_intr_controller;
  1698. + }
  1699. + setup_irq(AR531X_MISC_IRQ_AHB_PROC, &ar5312_ahb_proc_interrupt);
  1700. + setup_irq(AR5312_IRQ_MISC_INTRS, &cascade);
  1701. +}
  1702. +
  1703. +const struct ar231x_gpiodev ar5312_gpiodev;
  1704. +
  1705. +static u32
  1706. +ar5312_gpio_get_output(void)
  1707. +{
  1708. + u32 reg;
  1709. + reg = ~(ar231x_read_reg(AR531X_GPIO_CR));
  1710. + reg &= ar5312_gpiodev.valid_mask;
  1711. + return reg;
  1712. +}
  1713. +
  1714. +static u32
  1715. +ar5312_gpio_set_output(u32 mask, u32 val)
  1716. +{
  1717. + u32 reg;
  1718. +
  1719. + reg = ar231x_read_reg(AR531X_GPIO_CR);
  1720. + reg |= mask;
  1721. + reg &= ~val;
  1722. + ar231x_write_reg(AR531X_GPIO_CR, reg);
  1723. + return reg;
  1724. +}
  1725. +
  1726. +static u32
  1727. +ar5312_gpio_get(void)
  1728. +{
  1729. + u32 reg;
  1730. + reg = ar231x_read_reg(AR531X_GPIO_DI);
  1731. + reg &= ar5312_gpiodev.valid_mask;
  1732. + return reg;
  1733. +}
  1734. +
  1735. +static u32
  1736. +ar5312_gpio_set(u32 mask, u32 value)
  1737. +{
  1738. + u32 reg;
  1739. + reg = ar231x_read_reg(AR531X_GPIO_DO);
  1740. + reg &= ~mask;
  1741. + reg |= value;
  1742. + ar231x_write_reg(AR531X_GPIO_DO, reg);
  1743. + return reg;
  1744. +}
  1745. +
  1746. +const struct ar231x_gpiodev ar5312_gpiodev = {
  1747. + .valid_mask = (1 << 8) - 1,
  1748. + .get_output = ar5312_gpio_get_output,
  1749. + .set_output = ar5312_gpio_set_output,
  1750. + .get = ar5312_gpio_get,
  1751. + .set = ar5312_gpio_set,
  1752. +};
  1753. +
  1754. +static struct physmap_flash_data ar5312_flash_data = {
  1755. + .width = 2,
  1756. +};
  1757. +
  1758. +static struct resource ar5312_flash_resource = {
  1759. + .start = AR531X_FLASH,
  1760. + .end = AR531X_FLASH + 0x800000 - 1,
  1761. + .flags = IORESOURCE_MEM,
  1762. +};
  1763. +
  1764. +static struct ar231x_eth ar5312_eth0_data = {
  1765. + .reset_base = AR531X_RESET,
  1766. + .reset_mac = AR531X_RESET_ENET0,
  1767. + .reset_phy = AR531X_RESET_EPHY0,
  1768. + .phy_base = KSEG1ADDR(AR531X_ENET0),
  1769. + .config = &ar231x_board,
  1770. +};
  1771. +
  1772. +static struct ar231x_eth ar5312_eth1_data = {
  1773. + .reset_base = AR531X_RESET,
  1774. + .reset_mac = AR531X_RESET_ENET1,
  1775. + .reset_phy = AR531X_RESET_EPHY1,
  1776. + .phy_base = KSEG1ADDR(AR531X_ENET1),
  1777. + .config = &ar231x_board,
  1778. +};
  1779. +
  1780. +static struct platform_device ar5312_physmap_flash = {
  1781. + .name = "physmap-flash",
  1782. + .id = 0,
  1783. + .dev.platform_data = &ar5312_flash_data,
  1784. + .resource = &ar5312_flash_resource,
  1785. + .num_resources = 1,
  1786. +};
  1787. +
  1788. +#ifdef CONFIG_LEDS_GPIO
  1789. +static struct gpio_led ar5312_leds[] = {
  1790. + { .name = "wlan", .gpio = 0, .active_low = 1, },
  1791. +};
  1792. +
  1793. +static const struct gpio_led_platform_data ar5312_led_data = {
  1794. + .num_leds = ARRAY_SIZE(ar5312_leds),
  1795. + .leds = (void *) ar5312_leds,
  1796. +};
  1797. +
  1798. +static struct platform_device ar5312_gpio_leds = {
  1799. + .name = "leds-gpio",
  1800. + .id = -1,
  1801. + .dev.platform_data = (void *) &ar5312_led_data,
  1802. +};
  1803. +#endif
  1804. +
  1805. +/*
  1806. + * NB: This mapping size is larger than the actual flash size,
  1807. + * but this shouldn't be a problem here, because the flash
  1808. + * will simply be mapped multiple times.
  1809. + */
  1810. +static char __init *ar5312_flash_limit(void)
  1811. +{
  1812. + u32 ctl;
  1813. + /*
  1814. + * Configure flash bank 0.
  1815. + * Assume 8M window size. Flash will be aliased if it's smaller
  1816. + */
  1817. + ctl = FLASHCTL_E |
  1818. + FLASHCTL_AC_8M |
  1819. + FLASHCTL_RBLE |
  1820. + (0x01 << FLASHCTL_IDCY_S) |
  1821. + (0x07 << FLASHCTL_WST1_S) |
  1822. + (0x07 << FLASHCTL_WST2_S) |
  1823. + (ar231x_read_reg(AR531X_FLASHCTL0) & FLASHCTL_MW);
  1824. +
  1825. + ar231x_write_reg(AR531X_FLASHCTL0, ctl);
  1826. +
  1827. + /* Disable other flash banks */
  1828. + ar231x_write_reg(AR531X_FLASHCTL1,
  1829. + ar231x_read_reg(AR531X_FLASHCTL1) & ~(FLASHCTL_E | FLASHCTL_AC));
  1830. +
  1831. + ar231x_write_reg(AR531X_FLASHCTL2,
  1832. + ar231x_read_reg(AR531X_FLASHCTL2) & ~(FLASHCTL_E | FLASHCTL_AC));
  1833. +
  1834. + return (char *) KSEG1ADDR(AR531X_FLASH + 0x800000);
  1835. +}
  1836. +
  1837. +int __init ar5312_init_devices(void)
  1838. +{
  1839. + struct ar231x_boarddata *config;
  1840. + u32 fctl = 0;
  1841. + const u8 *radio;
  1842. + u8 *c;
  1843. +
  1844. + if (!IS_5312())
  1845. + return 0;
  1846. +
  1847. + /* Locate board/radio config data */
  1848. + ar231x_find_config(ar5312_flash_limit());
  1849. + config = ar231x_board.config;
  1850. +
  1851. +
  1852. + /*
  1853. + * Chip IDs and hardware detection for some Atheros
  1854. + * models are really broken!
  1855. + *
  1856. + * Atheros uses a disabled WMAC0 and Silicon ID of AR5312
  1857. + * as indication for AR2312, which is otherwise
  1858. + * indistinguishable from the real AR5312.
  1859. + */
  1860. + if (ar231x_board.radio) {
  1861. + radio = ar231x_board.radio + AR531X_RADIO_MASK_OFF;
  1862. + if ((*((const u32 *) radio) & AR531X_RADIO0_MASK) == 0)
  1863. + config->flags |= BD_ISCASPER;
  1864. + } else
  1865. + radio = NULL;
  1866. +
  1867. + /* AR2313 has CPU minor rev. 10 */
  1868. + if ((current_cpu_data.processor_id & 0xff) == 0x0a)
  1869. + ar231x_devtype = DEV_TYPE_AR2313;
  1870. +
  1871. + /* AR2312 shares the same Silicon ID as AR5312 */
  1872. + else if (config->flags & BD_ISCASPER)
  1873. + ar231x_devtype = DEV_TYPE_AR2312;
  1874. +
  1875. + /* Everything else is probably AR5312 or compatible */
  1876. + else
  1877. + ar231x_devtype = DEV_TYPE_AR5312;
  1878. +
  1879. + /* fixup flash width */
  1880. + fctl = ar231x_read_reg(AR531X_FLASHCTL) & FLASHCTL_MW;
  1881. + switch (fctl) {
  1882. + case FLASHCTL_MWx16:
  1883. + ar5312_flash_data.width = 2;
  1884. + break;
  1885. + case FLASHCTL_MWx8:
  1886. + default:
  1887. + ar5312_flash_data.width = 1;
  1888. + break;
  1889. + }
  1890. +
  1891. + platform_device_register(&ar5312_physmap_flash);
  1892. +
  1893. +#ifdef CONFIG_LEDS_GPIO
  1894. + ar5312_leds[0].gpio = config->sysLedGpio;
  1895. + platform_device_register(&ar5312_gpio_leds);
  1896. +#endif
  1897. +
  1898. + /* Fix up MAC addresses if necessary */
  1899. + if (!memcmp(config->enet0_mac, "\xff\xff\xff\xff\xff\xff", 6))
  1900. + memcpy(config->enet0_mac, config->enet1_mac, 6);
  1901. +
  1902. + /* If ENET0 and ENET1 have the same mac address,
  1903. + * increment the one from ENET1 */
  1904. + if (memcmp(config->enet0_mac, config->enet1_mac, 6) == 0) {
  1905. + c = config->enet1_mac + 5;
  1906. + while ((c >= config->enet1_mac) && !(++(*c)))
  1907. + c--;
  1908. + }
  1909. +
  1910. + switch(ar231x_devtype) {
  1911. + case DEV_TYPE_AR5312:
  1912. + ar5312_eth0_data.macaddr = config->enet0_mac;
  1913. + ar231x_add_ethernet(0, KSEG1ADDR(AR531X_ENET0),
  1914. + AR5312_IRQ_ENET0_INTRS, &ar5312_eth0_data);
  1915. +
  1916. + ar5312_eth1_data.macaddr = config->enet1_mac;
  1917. + ar231x_add_ethernet(1, KSEG1ADDR(AR531X_ENET1),
  1918. + AR5312_IRQ_ENET1_INTRS, &ar5312_eth1_data);
  1919. +
  1920. + if (!ar231x_board.radio)
  1921. + return 0;
  1922. +
  1923. + if (*((u32 *) radio) & AR531X_RADIO0_MASK)
  1924. + ar231x_add_wmac(0, AR531X_WLAN0,
  1925. + AR5312_IRQ_WLAN0_INTRS);
  1926. +
  1927. + break;
  1928. + /*
  1929. + * AR2312/3 ethernet uses the PHY of ENET0, but the MAC
  1930. + * of ENET1. Atheros calls it 'twisted' for a reason :)
  1931. + */
  1932. + case DEV_TYPE_AR2312:
  1933. + case DEV_TYPE_AR2313:
  1934. + ar5312_eth1_data.phy_base = ar5312_eth0_data.phy_base;
  1935. + ar5312_eth1_data.reset_phy = ar5312_eth0_data.reset_phy;
  1936. + ar5312_eth1_data.macaddr = config->enet0_mac;
  1937. + ar231x_add_ethernet(0, KSEG1ADDR(AR531X_ENET1),
  1938. + AR5312_IRQ_ENET1_INTRS, &ar5312_eth1_data);
  1939. +
  1940. + if (!ar231x_board.radio)
  1941. + return 0;
  1942. + break;
  1943. + default:
  1944. + break;
  1945. + }
  1946. +
  1947. + if (*((u32 *) radio) & AR531X_RADIO1_MASK)
  1948. + ar231x_add_wmac(1, AR531X_WLAN1,
  1949. + AR5312_IRQ_WLAN1_INTRS);
  1950. +
  1951. + return 0;
  1952. +}
  1953. +
  1954. +
  1955. +static void ar5312_restart(char *command)
  1956. +{
  1957. + /* reset the system */
  1958. + local_irq_disable();
  1959. + while(1) {
  1960. + ar231x_write_reg(AR531X_RESET, AR531X_RESET_SYSTEM);
  1961. + }
  1962. +}
  1963. +
  1964. +
  1965. +/*
  1966. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  1967. + * to determine the predevisor value.
  1968. + */
  1969. +static int __initdata CLOCKCTL1_PREDIVIDE_TABLE[4] = {
  1970. + 1,
  1971. + 2,
  1972. + 4,
  1973. + 5
  1974. +};
  1975. +
  1976. +
  1977. +static int __init
  1978. +ar5312_cpu_frequency(void)
  1979. +{
  1980. + unsigned int result;
  1981. + unsigned int predivide_mask, predivide_shift;
  1982. + unsigned int multiplier_mask, multiplier_shift;
  1983. + unsigned int clockCtl1, preDivideSelect, preDivisor, multiplier;
  1984. + unsigned int doubler_mask;
  1985. + u16 devid;
  1986. +
  1987. + /* Trust the bootrom's idea of cpu frequency. */
  1988. + if ((result = ar231x_read_reg(AR5312_SCRATCH)))
  1989. + return result;
  1990. +
  1991. + devid = ar231x_read_reg(AR531X_REV);
  1992. + devid &= AR531X_REV_MAJ;
  1993. + devid >>= AR531X_REV_MAJ_S;
  1994. + if (devid == AR531X_REV_MAJ_AR2313) {
  1995. + predivide_mask = AR2313_CLOCKCTL1_PREDIVIDE_MASK;
  1996. + predivide_shift = AR2313_CLOCKCTL1_PREDIVIDE_SHIFT;
  1997. + multiplier_mask = AR2313_CLOCKCTL1_MULTIPLIER_MASK;
  1998. + multiplier_shift = AR2313_CLOCKCTL1_MULTIPLIER_SHIFT;
  1999. + doubler_mask = AR2313_CLOCKCTL1_DOUBLER_MASK;
  2000. + } else { /* AR5312 and AR2312 */
  2001. + predivide_mask = AR5312_CLOCKCTL1_PREDIVIDE_MASK;
  2002. + predivide_shift = AR5312_CLOCKCTL1_PREDIVIDE_SHIFT;
  2003. + multiplier_mask = AR5312_CLOCKCTL1_MULTIPLIER_MASK;
  2004. + multiplier_shift = AR5312_CLOCKCTL1_MULTIPLIER_SHIFT;
  2005. + doubler_mask = AR5312_CLOCKCTL1_DOUBLER_MASK;
  2006. + }
  2007. +
  2008. + /*
  2009. + * Clocking is derived from a fixed 40MHz input clock.
  2010. + *
  2011. + * cpuFreq = InputClock * MULT (where MULT is PLL multiplier)
  2012. + * sysFreq = cpuFreq / 4 (used for APB clock, serial,
  2013. + * flash, Timer, Watchdog Timer)
  2014. + *
  2015. + * cntFreq = cpuFreq / 2 (use for CPU count/compare)
  2016. + *
  2017. + * So, for example, with a PLL multiplier of 5, we have
  2018. + *
  2019. + * cpuFreq = 200MHz
  2020. + * sysFreq = 50MHz
  2021. + * cntFreq = 100MHz
  2022. + *
  2023. + * We compute the CPU frequency, based on PLL settings.
  2024. + */
  2025. +
  2026. + clockCtl1 = ar231x_read_reg(AR5312_CLOCKCTL1);
  2027. + preDivideSelect = (clockCtl1 & predivide_mask) >> predivide_shift;
  2028. + preDivisor = CLOCKCTL1_PREDIVIDE_TABLE[preDivideSelect];
  2029. + multiplier = (clockCtl1 & multiplier_mask) >> multiplier_shift;
  2030. +
  2031. + if (clockCtl1 & doubler_mask) {
  2032. + multiplier = multiplier << 1;
  2033. + }
  2034. + return (40000000 / preDivisor) * multiplier;
  2035. +}
  2036. +
  2037. +static inline int
  2038. +ar5312_sys_frequency(void)
  2039. +{
  2040. + return ar5312_cpu_frequency() / 4;
  2041. +}
  2042. +
  2043. +void __init
  2044. +ar5312_time_init(void)
  2045. +{
  2046. + if (!IS_5312())
  2047. + return;
  2048. +
  2049. + mips_hpt_frequency = ar5312_cpu_frequency() / 2;
  2050. +}
  2051. +
  2052. +
  2053. +void __init
  2054. +ar5312_prom_init(void)
  2055. +{
  2056. + u32 memsize, memcfg, bank0AC, bank1AC;
  2057. + u32 devid;
  2058. +
  2059. + if (!IS_5312())
  2060. + return;
  2061. +
  2062. + /* Detect memory size */
  2063. + memcfg = ar231x_read_reg(AR531X_MEM_CFG1);
  2064. + bank0AC = (memcfg & MEM_CFG1_AC0) >> MEM_CFG1_AC0_S;
  2065. + bank1AC = (memcfg & MEM_CFG1_AC1) >> MEM_CFG1_AC1_S;
  2066. + memsize = (bank0AC ? (1 << (bank0AC+1)) : 0)
  2067. + + (bank1AC ? (1 << (bank1AC+1)) : 0);
  2068. + memsize <<= 20;
  2069. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  2070. +
  2071. + devid = ar231x_read_reg(AR531X_REV);
  2072. + devid >>= AR531X_REV_WMAC_MIN_S;
  2073. + devid &= AR531X_REV_CHIP;
  2074. + ar231x_board.devid = (u16) devid;
  2075. + ar231x_gpiodev = &ar5312_gpiodev;
  2076. +}
  2077. +
  2078. +void __init
  2079. +ar5312_plat_setup(void)
  2080. +{
  2081. + if (!IS_5312())
  2082. + return;
  2083. +
  2084. + /* Clear any lingering AHB errors */
  2085. + ar231x_read_reg(AR531X_PROCADDR);
  2086. + ar231x_read_reg(AR531X_DMAADDR);
  2087. + ar231x_write_reg(AR531X_WD_CTRL, AR531X_WD_CTRL_IGNORE_EXPIRATION);
  2088. +
  2089. + _machine_restart = ar5312_restart;
  2090. + ar231x_serial_setup(KSEG1ADDR(AR531X_UART0), ar5312_sys_frequency());
  2091. +}
  2092. +
  2093. --- /dev/null
  2094. +++ b/arch/mips/ar231x/ar2315.c
  2095. @@ -0,0 +1,679 @@
  2096. +/*
  2097. + * This file is subject to the terms and conditions of the GNU General Public
  2098. + * License. See the file "COPYING" in the main directory of this archive
  2099. + * for more details.
  2100. + *
  2101. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  2102. + * Copyright (C) 2006 FON Technology, SL.
  2103. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  2104. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  2105. + */
  2106. +
  2107. +/*
  2108. + * Platform devices for Atheros SoCs
  2109. + */
  2110. +
  2111. +#include <linux/autoconf.h>
  2112. +#include <linux/init.h>
  2113. +#include <linux/module.h>
  2114. +#include <linux/types.h>
  2115. +#include <linux/string.h>
  2116. +#include <linux/platform_device.h>
  2117. +#include <linux/kernel.h>
  2118. +#include <linux/reboot.h>
  2119. +#include <linux/delay.h>
  2120. +#include <linux/leds.h>
  2121. +#include <asm/bootinfo.h>
  2122. +#include <asm/reboot.h>
  2123. +#include <asm/time.h>
  2124. +#include <asm/irq.h>
  2125. +#include <asm/io.h>
  2126. +#include <asm/gpio.h>
  2127. +
  2128. +#include <ar231x_platform.h>
  2129. +#include <ar2315_regs.h>
  2130. +#include <ar231x.h>
  2131. +#include "devices.h"
  2132. +#include "ar2315.h"
  2133. +
  2134. +#define IS_2315() (current_cpu_data.cputype == CPU_4KEC)
  2135. +
  2136. +static u32 gpiointmask = 0, gpiointval = 0;
  2137. +
  2138. +static inline void ar2315_gpio_irq(void)
  2139. +{
  2140. + u32 pend;
  2141. + int bit = -1;
  2142. +
  2143. + /* only do one gpio interrupt at a time */
  2144. + pend = (ar231x_read_reg(AR2315_GPIO_DI) ^ gpiointval) & gpiointmask;
  2145. +
  2146. + if (pend) {
  2147. + bit = fls(pend) - 1;
  2148. + printk("GPIO IRQ: pend=0x%08x, val=%08x, bit=%d\n", pend, gpiointval, bit);
  2149. + pend &= ~(1 << bit);
  2150. + gpiointval ^= (1 << bit);
  2151. + printk("AFTER IRQ: pend=0x%08x, val=%08x, bit=%d\n", pend, gpiointval, bit);
  2152. + }
  2153. +
  2154. + if (!pend)
  2155. + ar231x_write_reg(AR2315_ISR, AR2315_ISR_GPIO);
  2156. +
  2157. + if (bit >= 0)
  2158. + do_IRQ(AR531X_GPIO_IRQ_BASE + bit);
  2159. +}
  2160. +
  2161. +
  2162. +/*
  2163. + * Called when an interrupt is received, this function
  2164. + * determines exactly which interrupt it was, and it
  2165. + * invokes the appropriate handler.
  2166. + *
  2167. + * Implicitly, we also define interrupt priority by
  2168. + * choosing which to dispatch first.
  2169. + */
  2170. +static void
  2171. +ar2315_irq_dispatch(void)
  2172. +{
  2173. + int pending = read_c0_status() & read_c0_cause();
  2174. +
  2175. + if (pending & CAUSEF_IP3)
  2176. + do_IRQ(AR2315_IRQ_WLAN0_INTRS);
  2177. + else if (pending & CAUSEF_IP4)
  2178. + do_IRQ(AR2315_IRQ_ENET0_INTRS);
  2179. + else if (pending & CAUSEF_IP2) {
  2180. + unsigned int misc_intr = ar231x_read_reg(AR2315_ISR) & ar231x_read_reg(AR2315_IMR);
  2181. +
  2182. + if (misc_intr & AR2315_ISR_SPI)
  2183. + do_IRQ(AR531X_MISC_IRQ_SPI);
  2184. + else if (misc_intr & AR2315_ISR_TIMER)
  2185. + do_IRQ(AR531X_MISC_IRQ_TIMER);
  2186. + else if (misc_intr & AR2315_ISR_AHB)
  2187. + do_IRQ(AR531X_MISC_IRQ_AHB_PROC);
  2188. + else if (misc_intr & AR2315_ISR_GPIO)
  2189. + ar2315_gpio_irq();
  2190. + else if (misc_intr & AR2315_ISR_UART0)
  2191. + do_IRQ(AR531X_MISC_IRQ_UART0);
  2192. + else if (misc_intr & AR2315_ISR_WD)
  2193. + do_IRQ(AR531X_MISC_IRQ_WATCHDOG);
  2194. + else
  2195. + do_IRQ(AR531X_MISC_IRQ_NONE);
  2196. + } else if (pending & CAUSEF_IP7)
  2197. + do_IRQ(AR531X_IRQ_CPU_CLOCK);
  2198. +}
  2199. +
  2200. +static void ar2315_set_gpiointmask(int gpio, int level)
  2201. +{
  2202. + u32 reg;
  2203. +
  2204. + reg = ar231x_read_reg(AR2315_GPIO_INT);
  2205. + reg &= ~(AR2315_GPIO_INT_M | AR2315_GPIO_INT_LVL_M);
  2206. + reg |= gpio | AR2315_GPIO_INT_LVL(level);
  2207. + ar231x_write_reg(AR2315_GPIO_INT, reg);
  2208. +}
  2209. +
  2210. +static void ar2315_gpio_intr_enable(unsigned int irq)
  2211. +{
  2212. + unsigned int gpio = irq - AR531X_GPIO_IRQ_BASE;
  2213. +
  2214. + /* reconfigure GPIO line as input */
  2215. + ar231x_mask_reg(AR2315_GPIO_CR, AR2315_GPIO_CR_M(gpio), AR2315_GPIO_CR_I(gpio));
  2216. +
  2217. + /* Enable interrupt with edge detection */
  2218. + gpiointmask |= (1 << gpio);
  2219. + ar2315_set_gpiointmask(gpio, 3);
  2220. +}
  2221. +
  2222. +static void ar2315_gpio_intr_disable(unsigned int irq)
  2223. +{
  2224. + unsigned int gpio = irq - AR531X_GPIO_IRQ_BASE;
  2225. +
  2226. + /* Disable interrupt */
  2227. + gpiointmask &= ~(1 << gpio);
  2228. + ar2315_set_gpiointmask(gpio, 0);
  2229. +}
  2230. +
  2231. +static unsigned int
  2232. +ar2315_gpio_intr_startup(unsigned int irq)
  2233. +{
  2234. + ar2315_gpio_intr_enable(irq);
  2235. + return 0;
  2236. +}
  2237. +
  2238. +static void
  2239. +ar2315_gpio_intr_end(unsigned int irq)
  2240. +{
  2241. + if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  2242. + ar2315_gpio_intr_enable(irq);
  2243. +}
  2244. +
  2245. +static struct irq_chip ar2315_gpio_intr_controller = {
  2246. + .typename = "AR2315-GPIO",
  2247. + .startup = ar2315_gpio_intr_startup,
  2248. + .shutdown = ar2315_gpio_intr_disable,
  2249. + .enable = ar2315_gpio_intr_enable,
  2250. + .disable = ar2315_gpio_intr_disable,
  2251. + .ack = ar2315_gpio_intr_disable,
  2252. + .end = ar2315_gpio_intr_end,
  2253. +};
  2254. +
  2255. +static void
  2256. +ar2315_misc_intr_enable(unsigned int irq)
  2257. +{
  2258. + unsigned int imr;
  2259. +
  2260. + imr = ar231x_read_reg(AR2315_IMR);
  2261. + switch(irq) {
  2262. + case AR531X_MISC_IRQ_SPI:
  2263. + imr |= AR2315_ISR_SPI;
  2264. + break;
  2265. + case AR531X_MISC_IRQ_TIMER:
  2266. + imr |= AR2315_ISR_TIMER;
  2267. + break;
  2268. + case AR531X_MISC_IRQ_AHB_PROC:
  2269. + imr |= AR2315_ISR_AHB;
  2270. + break;
  2271. + case AR531X_MISC_IRQ_GPIO:
  2272. + imr |= AR2315_ISR_GPIO;
  2273. + break;
  2274. + case AR531X_MISC_IRQ_UART0:
  2275. + imr |= AR2315_ISR_UART0;
  2276. + break;
  2277. + case AR531X_MISC_IRQ_WATCHDOG:
  2278. + imr |= AR2315_ISR_WD;
  2279. + break;
  2280. + default:
  2281. + break;
  2282. + }
  2283. + ar231x_write_reg(AR2315_IMR, imr);
  2284. +}
  2285. +
  2286. +static void
  2287. +ar2315_misc_intr_disable(unsigned int irq)
  2288. +{
  2289. + unsigned int imr;
  2290. +
  2291. + imr = ar231x_read_reg(AR2315_IMR);
  2292. + switch(irq) {
  2293. + case AR531X_MISC_IRQ_SPI:
  2294. + imr &= ~AR2315_ISR_SPI;
  2295. + break;
  2296. + case AR531X_MISC_IRQ_TIMER:
  2297. + imr &= ~AR2315_ISR_TIMER;
  2298. + break;
  2299. + case AR531X_MISC_IRQ_AHB_PROC:
  2300. + imr &= ~AR2315_ISR_AHB;
  2301. + break;
  2302. + case AR531X_MISC_IRQ_GPIO:
  2303. + imr &= ~AR2315_ISR_GPIO;
  2304. + break;
  2305. + case AR531X_MISC_IRQ_UART0:
  2306. + imr &= ~AR2315_ISR_UART0;
  2307. + break;
  2308. + case AR531X_MISC_IRQ_WATCHDOG:
  2309. + imr &= ~AR2315_ISR_WD;
  2310. + break;
  2311. + default:
  2312. + break;
  2313. + }
  2314. + ar231x_write_reg(AR2315_IMR, imr);
  2315. +}
  2316. +
  2317. +static unsigned int
  2318. +ar2315_misc_intr_startup(unsigned int irq)
  2319. +{
  2320. + ar2315_misc_intr_enable(irq);
  2321. + return 0;
  2322. +}
  2323. +
  2324. +static void
  2325. +ar2315_misc_intr_end(unsigned int irq)
  2326. +{
  2327. + if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  2328. + ar2315_misc_intr_enable(irq);
  2329. +}
  2330. +
  2331. +
  2332. +static struct irq_chip ar2315_misc_intr_controller = {
  2333. + .typename = "AR2315-MISC",
  2334. + .startup = ar2315_misc_intr_startup,
  2335. + .shutdown = ar2315_misc_intr_disable,
  2336. + .enable = ar2315_misc_intr_enable,
  2337. + .disable = ar2315_misc_intr_disable,
  2338. + .ack = ar2315_misc_intr_disable,
  2339. + .end = ar2315_misc_intr_end,
  2340. +};
  2341. +
  2342. +static irqreturn_t ar2315_ahb_proc_handler(int cpl, void *dev_id)
  2343. +{
  2344. + ar231x_write_reg(AR2315_AHB_ERR0, AHB_ERROR_DET);
  2345. + ar231x_read_reg(AR2315_AHB_ERR1);
  2346. +
  2347. + printk(KERN_ERR "AHB fatal error\n");
  2348. + machine_restart("AHB error"); /* Catastrophic failure */
  2349. +
  2350. + return IRQ_HANDLED;
  2351. +}
  2352. +
  2353. +static struct irqaction ar2315_ahb_proc_interrupt = {
  2354. + .handler = ar2315_ahb_proc_handler,
  2355. + .flags = IRQF_DISABLED,
  2356. + .name = "ar2315_ahb_proc_interrupt",
  2357. +};
  2358. +
  2359. +static struct irqaction cascade = {
  2360. + .handler = no_action,
  2361. + .flags = IRQF_DISABLED,
  2362. + .name = "cascade",
  2363. +};
  2364. +
  2365. +void
  2366. +ar2315_irq_init(void)
  2367. +{
  2368. + int i;
  2369. +
  2370. + if (!IS_2315())
  2371. + return;
  2372. +
  2373. + ar231x_irq_dispatch = ar2315_irq_dispatch;
  2374. + gpiointval = ar231x_read_reg(AR2315_GPIO_DI);
  2375. + for (i = 0; i < AR531X_MISC_IRQ_COUNT; i++) {
  2376. + int irq = AR531X_MISC_IRQ_BASE + i;
  2377. + irq_desc[irq].status = IRQ_DISABLED;
  2378. + irq_desc[irq].action = NULL;
  2379. + irq_desc[irq].depth = 1;
  2380. + irq_desc[irq].chip = &ar2315_misc_intr_controller;
  2381. + }
  2382. + for (i = 0; i < AR531X_GPIO_IRQ_COUNT; i++) {
  2383. + int irq = AR531X_GPIO_IRQ_BASE + i;
  2384. + irq_desc[irq].status = IRQ_DISABLED;
  2385. + irq_desc[irq].action = NULL;
  2386. + irq_desc[irq].depth = 1;
  2387. + irq_desc[irq].chip = &ar2315_gpio_intr_controller;
  2388. + }
  2389. + setup_irq(AR531X_MISC_IRQ_GPIO, &cascade);
  2390. + setup_irq(AR531X_MISC_IRQ_AHB_PROC, &ar2315_ahb_proc_interrupt);
  2391. + setup_irq(AR2315_IRQ_MISC_INTRS, &cascade);
  2392. +}
  2393. +
  2394. +const struct ar231x_gpiodev ar2315_gpiodev;
  2395. +
  2396. +static u32
  2397. +ar2315_gpio_get_output(void)
  2398. +{
  2399. + u32 reg;
  2400. + reg = ar231x_read_reg(AR2315_GPIO_CR);
  2401. + reg &= ar2315_gpiodev.valid_mask;
  2402. + return reg;
  2403. +}
  2404. +
  2405. +static u32
  2406. +ar2315_gpio_set_output(u32 mask, u32 val)
  2407. +{
  2408. + u32 reg;
  2409. +
  2410. + reg = ar231x_read_reg(AR2315_GPIO_CR);
  2411. + reg &= ~mask;
  2412. + reg |= val;
  2413. + ar231x_write_reg(AR2315_GPIO_CR, reg);
  2414. + return reg;
  2415. +}
  2416. +
  2417. +static u32
  2418. +ar2315_gpio_get(void)
  2419. +{
  2420. + u32 reg;
  2421. + reg = ar231x_read_reg(AR2315_GPIO_DI);
  2422. + reg &= ar2315_gpiodev.valid_mask;
  2423. + return reg;
  2424. +}
  2425. +
  2426. +static u32
  2427. +ar2315_gpio_set(u32 mask, u32 value)
  2428. +{
  2429. + u32 reg;
  2430. + reg = ar231x_read_reg(AR2315_GPIO_DO);
  2431. + reg &= ~mask;
  2432. + reg |= value;
  2433. + ar231x_write_reg(AR2315_GPIO_DO, reg);
  2434. + return reg;
  2435. +}
  2436. +
  2437. +const struct ar231x_gpiodev ar2315_gpiodev = {
  2438. + .valid_mask = (1 << 22) - 1,
  2439. + .get_output = ar2315_gpio_get_output,
  2440. + .set_output = ar2315_gpio_set_output,
  2441. + .get = ar2315_gpio_get,
  2442. + .set = ar2315_gpio_set,
  2443. +};
  2444. +
  2445. +static struct ar231x_eth ar2315_eth_data = {
  2446. + .reset_base = AR2315_RESET,
  2447. + .reset_mac = AR2315_RESET_ENET0,
  2448. + .reset_phy = AR2315_RESET_EPHY0,
  2449. + .phy_base = AR2315_ENET0,
  2450. + .config = &ar231x_board,
  2451. +};
  2452. +
  2453. +static struct resource ar2315_spiflash_res[] = {
  2454. + {
  2455. + .name = "flash_base",
  2456. + .flags = IORESOURCE_MEM,
  2457. + .start = KSEG1ADDR(AR2315_SPI_READ),
  2458. + .end = KSEG1ADDR(AR2315_SPI_READ) + 0x1000000 - 1,
  2459. + },
  2460. + {
  2461. + .name = "flash_regs",
  2462. + .flags = IORESOURCE_MEM,
  2463. + .start = 0x11300000,
  2464. + .end = 0x11300012,
  2465. + },
  2466. +};
  2467. +
  2468. +static struct platform_device ar2315_spiflash = {
  2469. + .id = 0,
  2470. + .name = "spiflash",
  2471. + .resource = ar2315_spiflash_res,
  2472. + .num_resources = ARRAY_SIZE(ar2315_spiflash_res)
  2473. +};
  2474. +
  2475. +static struct platform_device ar2315_wdt = {
  2476. + .id = 0,
  2477. + .name = "ar2315_wdt",
  2478. +};
  2479. +
  2480. +#define SPI_FLASH_CTL 0x00
  2481. +#define SPI_FLASH_OPCODE 0x04
  2482. +#define SPI_FLASH_DATA 0x08
  2483. +
  2484. +static inline u32
  2485. +spiflash_read_reg(int reg)
  2486. +{
  2487. + return ar231x_read_reg(KSEG1ADDR(AR2315_SPI) + reg);
  2488. +}
  2489. +
  2490. +static inline void
  2491. +spiflash_write_reg(int reg, u32 data)
  2492. +{
  2493. + ar231x_write_reg(KSEG1ADDR(AR2315_SPI) + reg, data);
  2494. +}
  2495. +
  2496. +static u32
  2497. +spiflash_wait_status(void)
  2498. +{
  2499. + u32 reg;
  2500. +
  2501. + do {
  2502. + reg = spiflash_read_reg(SPI_FLASH_CTL);
  2503. + } while (reg & SPI_CTL_BUSY);
  2504. +
  2505. + return reg;
  2506. +}
  2507. +
  2508. +static u8
  2509. +spiflash_probe(void)
  2510. +{
  2511. + u32 reg;
  2512. +
  2513. + reg = spiflash_wait_status();
  2514. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  2515. + reg |= (1 << 4) | 4 | SPI_CTL_START;
  2516. +
  2517. + spiflash_write_reg(SPI_FLASH_OPCODE, 0xab);
  2518. + spiflash_write_reg(SPI_FLASH_CTL, reg);
  2519. +
  2520. + reg = spiflash_wait_status();
  2521. + reg = spiflash_read_reg(SPI_FLASH_DATA);
  2522. + reg &= 0xff;
  2523. +
  2524. + return (u8) reg;
  2525. +}
  2526. +
  2527. +
  2528. +#define STM_8MBIT_SIGNATURE 0x13
  2529. +#define STM_16MBIT_SIGNATURE 0x14
  2530. +#define STM_32MBIT_SIGNATURE 0x15
  2531. +#define STM_64MBIT_SIGNATURE 0x16
  2532. +#define STM_128MBIT_SIGNATURE 0x17
  2533. +
  2534. +static u8 __init *
  2535. +ar2315_flash_limit(void)
  2536. +{
  2537. + u32 flash_size = 0;
  2538. +
  2539. + /* probe the flash chip size */
  2540. + switch(spiflash_probe()) {
  2541. + case STM_8MBIT_SIGNATURE:
  2542. + flash_size = 0x00100000;
  2543. + break;
  2544. + case STM_16MBIT_SIGNATURE:
  2545. + flash_size = 0x00200000;
  2546. + break;
  2547. + case STM_32MBIT_SIGNATURE:
  2548. + flash_size = 0x00400000;
  2549. + break;
  2550. + case STM_64MBIT_SIGNATURE:
  2551. + flash_size = 0x00800000;
  2552. + break;
  2553. + case STM_128MBIT_SIGNATURE:
  2554. + flash_size = 0x01000000;
  2555. + break;
  2556. + }
  2557. +
  2558. + ar2315_spiflash_res[0].end = ar2315_spiflash_res[0].start +
  2559. + flash_size - 1;
  2560. + return (u8 *) ar2315_spiflash_res[0].end + 1;
  2561. +}
  2562. +
  2563. +#ifdef CONFIG_LEDS_GPIO
  2564. +static struct gpio_led ar2315_leds[6];
  2565. +static struct gpio_led_platform_data ar2315_led_data = {
  2566. + .leds = (void *) ar2315_leds,
  2567. +};
  2568. +
  2569. +static struct platform_device ar2315_gpio_leds = {
  2570. + .name = "leds-gpio",
  2571. + .id = -1,
  2572. + .dev = {
  2573. + .platform_data = (void *) &ar2315_led_data,
  2574. + }
  2575. +};
  2576. +
  2577. +static void __init
  2578. +ar2315_init_gpio(void)
  2579. +{
  2580. + static char led_names[6][6];
  2581. + int i, led = 0;
  2582. +
  2583. + ar2315_led_data.num_leds = 0;
  2584. + for(i = 1; i < 8; i++)
  2585. + {
  2586. + if((i == AR2315_RESET_GPIO) ||
  2587. + (i == ar231x_board.config->resetConfigGpio))
  2588. + continue;
  2589. +
  2590. + if(i == ar231x_board.config->sysLedGpio)
  2591. + strcpy(led_names[led], "wlan");
  2592. + else
  2593. + sprintf(led_names[led], "gpio%d", i);
  2594. +
  2595. + ar2315_leds[led].name = led_names[led];
  2596. + ar2315_leds[led].gpio = i;
  2597. + ar2315_leds[led].active_low = 0;
  2598. + led++;
  2599. + }
  2600. + ar2315_led_data.num_leds = led;
  2601. + platform_device_register(&ar2315_gpio_leds);
  2602. +}
  2603. +#else
  2604. +static inline void ar2315_init_gpio(void)
  2605. +{
  2606. +}
  2607. +#endif
  2608. +
  2609. +int __init
  2610. +ar2315_init_devices(void)
  2611. +{
  2612. + if (!IS_2315())
  2613. + return 0;
  2614. +
  2615. + /* Find board configuration */
  2616. + ar231x_find_config(ar2315_flash_limit());
  2617. + ar2315_eth_data.macaddr = ar231x_board.config->enet0_mac;
  2618. +
  2619. + ar2315_init_gpio();
  2620. + platform_device_register(&ar2315_wdt);
  2621. + platform_device_register(&ar2315_spiflash);
  2622. + ar231x_add_ethernet(0, AR2315_ENET0, AR2315_IRQ_ENET0_INTRS,
  2623. + &ar2315_eth_data);
  2624. + ar231x_add_wmac(0, AR2315_WLAN0, AR2315_IRQ_WLAN0_INTRS);
  2625. +
  2626. + return 0;
  2627. +}
  2628. +
  2629. +static void
  2630. +ar2315_restart(char *command)
  2631. +{
  2632. + void (*mips_reset_vec)(void) = (void *) 0xbfc00000;
  2633. +
  2634. + local_irq_disable();
  2635. +
  2636. + /* try reset the system via reset control */
  2637. + ar231x_write_reg(AR2315_COLD_RESET,AR2317_RESET_SYSTEM);
  2638. +
  2639. + /* Cold reset does not work on the AR2315/6, use the GPIO reset bits a workaround.
  2640. + * give it some time to attempt a gpio based hardware reset
  2641. + * (atheros reference design workaround) */
  2642. + gpio_direction_output(AR2315_RESET_GPIO, 0);
  2643. + mdelay(100);
  2644. +
  2645. + /* Some boards (e.g. Senao EOC-2610) don't implement the reset logic
  2646. + * workaround. Attempt to jump to the mips reset location -
  2647. + * the boot loader itself might be able to recover the system */
  2648. + mips_reset_vec();
  2649. +}
  2650. +
  2651. +
  2652. +/*
  2653. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  2654. + * to determine the predevisor value.
  2655. + */
  2656. +static int __initdata CLOCKCTL1_PREDIVIDE_TABLE[4] = {
  2657. + 1,
  2658. + 2,
  2659. + 4,
  2660. + 5
  2661. +};
  2662. +
  2663. +static int __initdata PLLC_DIVIDE_TABLE[5] = {
  2664. + 2,
  2665. + 3,
  2666. + 4,
  2667. + 6,
  2668. + 3
  2669. +};
  2670. +
  2671. +static unsigned int __init
  2672. +ar2315_sys_clk(unsigned int clockCtl)
  2673. +{
  2674. + unsigned int pllcCtrl,cpuDiv;
  2675. + unsigned int pllcOut,refdiv,fdiv,divby2;
  2676. + unsigned int clkDiv;
  2677. +
  2678. + pllcCtrl = ar231x_read_reg(AR2315_PLLC_CTL);
  2679. + refdiv = (pllcCtrl & PLLC_REF_DIV_M) >> PLLC_REF_DIV_S;
  2680. + refdiv = CLOCKCTL1_PREDIVIDE_TABLE[refdiv];
  2681. + fdiv = (pllcCtrl & PLLC_FDBACK_DIV_M) >> PLLC_FDBACK_DIV_S;
  2682. + divby2 = (pllcCtrl & PLLC_ADD_FDBACK_DIV_M) >> PLLC_ADD_FDBACK_DIV_S;
  2683. + divby2 += 1;
  2684. + pllcOut = (40000000/refdiv)*(2*divby2)*fdiv;
  2685. +
  2686. +
  2687. + /* clkm input selected */
  2688. + switch(clockCtl & CPUCLK_CLK_SEL_M) {
  2689. + case 0:
  2690. + case 1:
  2691. + clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKM_DIV_M) >> PLLC_CLKM_DIV_S];
  2692. + break;
  2693. + case 2:
  2694. + clkDiv = PLLC_DIVIDE_TABLE[(pllcCtrl & PLLC_CLKC_DIV_M) >> PLLC_CLKC_DIV_S];
  2695. + break;
  2696. + default:
  2697. + pllcOut = 40000000;
  2698. + clkDiv = 1;
  2699. + break;
  2700. + }
  2701. + cpuDiv = (clockCtl & CPUCLK_CLK_DIV_M) >> CPUCLK_CLK_DIV_S;
  2702. + cpuDiv = cpuDiv * 2 ?: 1;
  2703. + return (pllcOut/(clkDiv * cpuDiv));
  2704. +}
  2705. +
  2706. +static inline unsigned int
  2707. +ar2315_cpu_frequency(void)
  2708. +{
  2709. + return ar2315_sys_clk(ar231x_read_reg(AR2315_CPUCLK));
  2710. +}
  2711. +
  2712. +static inline unsigned int
  2713. +ar2315_apb_frequency(void)
  2714. +{
  2715. + return ar2315_sys_clk(ar231x_read_reg(AR2315_AMBACLK));
  2716. +}
  2717. +
  2718. +void __init
  2719. +ar2315_time_init(void)
  2720. +{
  2721. + if (!IS_2315())
  2722. + return;
  2723. +
  2724. + mips_hpt_frequency = ar2315_cpu_frequency() / 2;
  2725. +}
  2726. +
  2727. +void __init
  2728. +ar2315_prom_init(void)
  2729. +{
  2730. + u32 memsize, memcfg, devid;
  2731. +
  2732. + if (!IS_2315())
  2733. + return;
  2734. +
  2735. + memcfg = ar231x_read_reg(AR2315_MEM_CFG);
  2736. + memsize = 1 + ((memcfg & SDRAM_DATA_WIDTH_M) >> SDRAM_DATA_WIDTH_S);
  2737. + memsize <<= 1 + ((memcfg & SDRAM_COL_WIDTH_M) >> SDRAM_COL_WIDTH_S);
  2738. + memsize <<= 1 + ((memcfg & SDRAM_ROW_WIDTH_M) >> SDRAM_ROW_WIDTH_S);
  2739. + memsize <<= 3;
  2740. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  2741. +
  2742. + /* Detect the hardware based on the device ID */
  2743. + devid = ar231x_read_reg(AR2315_SREV) & AR2315_REV_CHIP;
  2744. + switch(devid) {
  2745. + case 0x90:
  2746. + case 0x91:
  2747. + ar231x_devtype = DEV_TYPE_AR2317;
  2748. + break;
  2749. + default:
  2750. + ar231x_devtype = DEV_TYPE_AR2315;
  2751. + break;
  2752. + }
  2753. + ar231x_gpiodev = &ar2315_gpiodev;
  2754. + ar231x_board.devid = devid;
  2755. +}
  2756. +
  2757. +void __init
  2758. +ar2315_plat_setup(void)
  2759. +{
  2760. + u32 config;
  2761. +
  2762. + if (!IS_2315())
  2763. + return;
  2764. +
  2765. + /* Clear any lingering AHB errors */
  2766. + config = read_c0_config();
  2767. + write_c0_config(config & ~0x3);
  2768. + ar231x_write_reg(AR2315_AHB_ERR0,AHB_ERROR_DET);
  2769. + ar231x_read_reg(AR2315_AHB_ERR1);
  2770. + ar231x_write_reg(AR2315_WDC, AR2315_WDC_IGNORE_EXPIRATION);
  2771. +
  2772. + _machine_restart = ar2315_restart;
  2773. + ar231x_serial_setup(KSEG1ADDR(AR2315_UART0), ar2315_apb_frequency());
  2774. +}
  2775. --- /dev/null
  2776. +++ b/arch/mips/ar231x/ar2315.h
  2777. @@ -0,0 +1,37 @@
  2778. +#ifndef __AR2315_H
  2779. +#define __AR2315_H
  2780. +
  2781. +#ifdef CONFIG_ATHEROS_AR2315
  2782. +
  2783. +extern void ar2315_irq_init(void);
  2784. +extern int ar2315_init_devices(void);
  2785. +extern void ar2315_prom_init(void);
  2786. +extern void ar2315_plat_setup(void);
  2787. +extern void ar2315_time_init(void);
  2788. +
  2789. +#else
  2790. +
  2791. +static inline void ar2315_irq_init(void)
  2792. +{
  2793. +}
  2794. +
  2795. +static inline int ar2315_init_devices(void)
  2796. +{
  2797. + return 0;
  2798. +}
  2799. +
  2800. +static inline void ar2315_prom_init(void)
  2801. +{
  2802. +}
  2803. +
  2804. +static inline void ar2315_plat_setup(void)
  2805. +{
  2806. +}
  2807. +
  2808. +static inline void ar2315_time_init(void)
  2809. +{
  2810. +}
  2811. +
  2812. +#endif
  2813. +
  2814. +#endif
  2815. --- /dev/null
  2816. +++ b/arch/mips/ar231x/ar5312.h
  2817. @@ -0,0 +1,38 @@
  2818. +#ifndef __AR5312_H
  2819. +#define __AR5312_H
  2820. +
  2821. +#ifdef CONFIG_ATHEROS_AR5312
  2822. +
  2823. +extern void ar5312_irq_init(void);
  2824. +extern int ar5312_init_devices(void);
  2825. +extern void ar5312_prom_init(void);
  2826. +extern void ar5312_plat_setup(void);
  2827. +extern void ar5312_time_init(void);
  2828. +extern void ar5312_time_init(void);
  2829. +
  2830. +#else
  2831. +
  2832. +static inline void ar5312_irq_init(void)
  2833. +{
  2834. +}
  2835. +
  2836. +static inline int ar5312_init_devices(void)
  2837. +{
  2838. + return 0;
  2839. +}
  2840. +
  2841. +static inline void ar5312_prom_init(void)
  2842. +{
  2843. +}
  2844. +
  2845. +static inline void ar5312_plat_setup(void)
  2846. +{
  2847. +}
  2848. +
  2849. +static inline void ar5312_time_init(void)
  2850. +{
  2851. +}
  2852. +
  2853. +#endif
  2854. +
  2855. +#endif
  2856. --- /dev/null
  2857. +++ b/arch/mips/include/asm/mach-ar231x/ar231x.h
  2858. @@ -0,0 +1,54 @@
  2859. +#ifndef __AR531X_H
  2860. +#define __AR531X_H
  2861. +
  2862. +#define AR531X_MISC_IRQ_BASE 0x20
  2863. +#define AR531X_GPIO_IRQ_BASE 0x30
  2864. +
  2865. +/* Software's idea of interrupts handled by "CPU Interrupt Controller" */
  2866. +#define AR531X_IRQ_NONE MIPS_CPU_IRQ_BASE+0
  2867. +#define AR531X_IRQ_CPU_CLOCK MIPS_CPU_IRQ_BASE+7 /* C0_CAUSE: 0x8000 */
  2868. +
  2869. +/* Miscellaneous interrupts, which share IP6 */
  2870. +#define AR531X_MISC_IRQ_NONE AR531X_MISC_IRQ_BASE+0
  2871. +#define AR531X_MISC_IRQ_TIMER AR531X_MISC_IRQ_BASE+1
  2872. +#define AR531X_MISC_IRQ_AHB_PROC AR531X_MISC_IRQ_BASE+2
  2873. +#define AR531X_MISC_IRQ_AHB_DMA AR531X_MISC_IRQ_BASE+3
  2874. +#define AR531X_MISC_IRQ_GPIO AR531X_MISC_IRQ_BASE+4
  2875. +#define AR531X_MISC_IRQ_UART0 AR531X_MISC_IRQ_BASE+5
  2876. +#define AR531X_MISC_IRQ_UART0_DMA AR531X_MISC_IRQ_BASE+6
  2877. +#define AR531X_MISC_IRQ_WATCHDOG AR531X_MISC_IRQ_BASE+7
  2878. +#define AR531X_MISC_IRQ_LOCAL AR531X_MISC_IRQ_BASE+8
  2879. +#define AR531X_MISC_IRQ_SPI AR531X_MISC_IRQ_BASE+9
  2880. +#define AR531X_MISC_IRQ_COUNT 10
  2881. +
  2882. +/* GPIO Interrupts [0..7], share AR531X_MISC_IRQ_GPIO */
  2883. +#define AR531X_GPIO_IRQ_NONE AR531X_GPIO_IRQ_BASE+0
  2884. +#define AR531X_GPIO_IRQ(n) AR531X_GPIO_IRQ_BASE+n
  2885. +#define AR531X_GPIO_IRQ_COUNT 22
  2886. +
  2887. +static inline u32
  2888. +ar231x_read_reg(u32 reg)
  2889. +{
  2890. + return __raw_readl((u32 *) KSEG1ADDR(reg));
  2891. +}
  2892. +
  2893. +static inline void
  2894. +ar231x_write_reg(u32 reg, u32 val)
  2895. +{
  2896. + __raw_writel(val, (u32 *) KSEG1ADDR(reg));
  2897. +}
  2898. +
  2899. +static inline u32
  2900. +ar231x_mask_reg(u32 reg, u32 mask, u32 val)
  2901. +{
  2902. + u32 ret;
  2903. +
  2904. + ret = ar231x_read_reg(reg);
  2905. + ret &= ~mask;
  2906. + ret |= val;
  2907. + ar231x_write_reg(reg, ret);
  2908. +
  2909. + return ret;
  2910. +}
  2911. +
  2912. +#endif
  2913. --- /dev/null
  2914. +++ b/arch/mips/ar231x/devices.h
  2915. @@ -0,0 +1,27 @@
  2916. +#ifndef __AR231X_DEVICES_H
  2917. +#define __AR231X_DEVICES_H
  2918. +
  2919. +enum {
  2920. + /* handled by ar5312.c */
  2921. + DEV_TYPE_AR2312,
  2922. + DEV_TYPE_AR2313,
  2923. + DEV_TYPE_AR5312,
  2924. +
  2925. + /* handled by ar2315.c */
  2926. + DEV_TYPE_AR2315,
  2927. + DEV_TYPE_AR2316,
  2928. + DEV_TYPE_AR2317,
  2929. +
  2930. + DEV_TYPE_UNKNOWN
  2931. +};
  2932. +
  2933. +extern int ar231x_devtype;
  2934. +extern struct ar231x_board_config ar231x_board;
  2935. +extern void (*ar231x_irq_dispatch)(void);
  2936. +
  2937. +extern int ar231x_find_config(u8 *flash_limit);
  2938. +extern void ar231x_serial_setup(u32 mapbase, unsigned int uartclk);
  2939. +extern int ar231x_add_wmac(int nr, u32 base, int irq);
  2940. +extern int ar231x_add_ethernet(int nr, u32 base, int irq, void *pdata);
  2941. +
  2942. +#endif
  2943. --- /dev/null
  2944. +++ b/arch/mips/ar231x/devices.c
  2945. @@ -0,0 +1,174 @@
  2946. +#include <linux/kernel.h>
  2947. +#include <linux/init.h>
  2948. +#include <linux/serial.h>
  2949. +#include <linux/serial_core.h>
  2950. +#include <linux/serial_8250.h>
  2951. +#include <linux/platform_device.h>
  2952. +#include <ar231x_platform.h>
  2953. +#include <ar231x.h>
  2954. +#include "devices.h"
  2955. +#include "ar5312.h"
  2956. +#include "ar2315.h"
  2957. +
  2958. +struct ar231x_board_config ar231x_board;
  2959. +int ar231x_devtype = DEV_TYPE_UNKNOWN;
  2960. +const struct ar231x_gpiodev *ar231x_gpiodev;
  2961. +
  2962. +static struct resource ar231x_eth0_res[] = {
  2963. + {
  2964. + .name = "eth0_membase",
  2965. + .flags = IORESOURCE_MEM,
  2966. + },
  2967. + {
  2968. + .name = "eth0_irq",
  2969. + .flags = IORESOURCE_IRQ,
  2970. + }
  2971. +};
  2972. +
  2973. +static struct resource ar231x_eth1_res[] = {
  2974. + {
  2975. + .name = "eth1_membase",
  2976. + .flags = IORESOURCE_MEM,
  2977. + },
  2978. + {
  2979. + .name = "eth1_irq",
  2980. + .flags = IORESOURCE_IRQ,
  2981. + }
  2982. +};
  2983. +
  2984. +static struct platform_device ar231x_eth[] = {
  2985. + {
  2986. + .id = 0,
  2987. + .name = "ar231x-eth",
  2988. + .resource = ar231x_eth0_res,
  2989. + .num_resources = ARRAY_SIZE(ar231x_eth0_res)
  2990. + },
  2991. + {
  2992. + .id = 1,
  2993. + .name = "ar231x-eth",
  2994. + .resource = ar231x_eth1_res,
  2995. + .num_resources = ARRAY_SIZE(ar231x_eth1_res)
  2996. + }
  2997. +};
  2998. +
  2999. +static struct resource ar231x_wmac0_res[] = {
  3000. + {
  3001. + .name = "wmac0_membase",
  3002. + .flags = IORESOURCE_MEM,
  3003. + },
  3004. + {
  3005. + .name = "wmac0_irq",
  3006. + .flags = IORESOURCE_IRQ,
  3007. + }
  3008. +};
  3009. +
  3010. +static struct resource ar231x_wmac1_res[] = {
  3011. + {
  3012. + .name = "wmac1_membase",
  3013. + .flags = IORESOURCE_MEM,
  3014. + },
  3015. + {
  3016. + .name = "wmac1_irq",
  3017. + .flags = IORESOURCE_IRQ,
  3018. + }
  3019. +};
  3020. +
  3021. +
  3022. +static struct platform_device ar231x_wmac[] = {
  3023. + {
  3024. + .id = 0,
  3025. + .name = "ar231x-wmac",
  3026. + .resource = ar231x_wmac0_res,
  3027. + .num_resources = ARRAY_SIZE(ar231x_wmac0_res),
  3028. + .dev.platform_data = &ar231x_board,
  3029. + },
  3030. + {
  3031. + .id = 1,
  3032. + .name = "ar231x-wmac",
  3033. + .resource = ar231x_wmac1_res,
  3034. + .num_resources = ARRAY_SIZE(ar231x_wmac1_res),
  3035. + .dev.platform_data = &ar231x_board,
  3036. + },
  3037. +};
  3038. +
  3039. +static const char *devtype_strings[] = {
  3040. + [DEV_TYPE_AR5312] = "Atheros AR5312",
  3041. + [DEV_TYPE_AR2312] = "Atheros AR2312",
  3042. + [DEV_TYPE_AR2313] = "Atheros AR2313",
  3043. + [DEV_TYPE_AR2315] = "Atheros AR2315",
  3044. + [DEV_TYPE_AR2316] = "Atheros AR2316",
  3045. + [DEV_TYPE_AR2317] = "Atheros AR2317",
  3046. + [DEV_TYPE_UNKNOWN] = "Atheros (unknown)",
  3047. +};
  3048. +
  3049. +const char *get_system_type(void)
  3050. +{
  3051. + if ((ar231x_devtype >= ARRAY_SIZE(devtype_strings)) ||
  3052. + !devtype_strings[ar231x_devtype])
  3053. + return devtype_strings[DEV_TYPE_UNKNOWN];
  3054. + return devtype_strings[ar231x_devtype];
  3055. +}
  3056. +
  3057. +
  3058. +int __init
  3059. +ar231x_add_ethernet(int nr, u32 base, int irq, void *pdata)
  3060. +{
  3061. + struct resource *res;
  3062. +
  3063. + ar231x_eth[nr].dev.platform_data = pdata;
  3064. + res = &ar231x_eth[nr].resource[0];
  3065. + res->start = base;
  3066. + res->end = base + 0x2000 - 1;
  3067. + res++;
  3068. + res->start = irq;
  3069. + res->end = irq;
  3070. + return platform_device_register(&ar231x_eth[nr]);
  3071. +}
  3072. +
  3073. +void __init
  3074. +ar231x_serial_setup(u32 mapbase, unsigned int uartclk)
  3075. +{
  3076. + struct uart_port s;
  3077. +
  3078. + memset(&s, 0, sizeof(s));
  3079. +
  3080. + s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  3081. + s.iotype = UPIO_MEM;
  3082. + s.irq = AR531X_MISC_IRQ_UART0;
  3083. + s.regshift = 2;
  3084. + s.mapbase = mapbase;
  3085. + s.uartclk = uartclk;
  3086. + s.membase = (void __iomem *)s.mapbase;
  3087. +
  3088. + early_serial_setup(&s);
  3089. +}
  3090. +
  3091. +int __init
  3092. +ar231x_add_wmac(int nr, u32 base, int irq)
  3093. +{
  3094. + struct resource *res;
  3095. +
  3096. + ar231x_wmac[nr].dev.platform_data = &ar231x_board;
  3097. + res = &ar231x_wmac[nr].resource[0];
  3098. + res->start = base;
  3099. + res->end = base + 0x10000 - 1;
  3100. + res++;
  3101. + res->start = irq;
  3102. + res->end = irq;
  3103. + return platform_device_register(&ar231x_wmac[nr]);
  3104. +}
  3105. +
  3106. +static int __init ar231x_register_devices(void)
  3107. +{
  3108. + static struct resource res = {
  3109. + .start = 0xFFFFFFFF,
  3110. + };
  3111. +
  3112. + platform_device_register_simple("GPIODEV", 0, &res, 1);
  3113. + ar5312_init_devices();
  3114. + ar2315_init_devices();
  3115. +
  3116. + return 0;
  3117. +}
  3118. +
  3119. +device_initcall(ar231x_register_devices);