010-board.patch 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  1. --- a/arch/mips/Kconfig
  2. +++ b/arch/mips/Kconfig
  3. @@ -96,6 +96,19 @@ config AR7
  4. Support for the Texas Instruments AR7 System-on-a-Chip
  5. family: TNETD7100, 7200 and 7300.
  6. +config ATH25
  7. + bool "Atheros AR231x/AR531x SoC support"
  8. + select CEVT_R4K
  9. + select CSRC_R4K
  10. + select DMA_NONCOHERENT
  11. + select IRQ_CPU
  12. + select IRQ_DOMAIN
  13. + select SYS_HAS_CPU_MIPS32_R1
  14. + select SYS_SUPPORTS_BIG_ENDIAN
  15. + select SYS_SUPPORTS_32BIT_KERNEL
  16. + help
  17. + Support for Atheros AR231x and Atheros AR531x based boards
  18. +
  19. config ATH79
  20. bool "Atheros AR71XX/AR724X/AR913X based boards"
  21. select ARCH_REQUIRE_GPIOLIB
  22. @@ -835,6 +848,7 @@ config MIPS_PARAVIRT
  23. endchoice
  24. source "arch/mips/alchemy/Kconfig"
  25. +source "arch/mips/ath25/Kconfig"
  26. source "arch/mips/ath79/Kconfig"
  27. source "arch/mips/bcm47xx/Kconfig"
  28. source "arch/mips/bcm63xx/Kconfig"
  29. --- a/arch/mips/Kbuild.platforms
  30. +++ b/arch/mips/Kbuild.platforms
  31. @@ -2,6 +2,7 @@
  32. platforms += alchemy
  33. platforms += ar7
  34. +platforms += ath25
  35. platforms += ath79
  36. platforms += bcm47xx
  37. platforms += bcm63xx
  38. --- /dev/null
  39. +++ b/arch/mips/ath25/Platform
  40. @@ -0,0 +1,6 @@
  41. +#
  42. +# Atheros AR531X/AR231X WiSoC
  43. +#
  44. +platform-$(CONFIG_ATH25) += ath25/
  45. +cflags-$(CONFIG_ATH25) += -I$(srctree)/arch/mips/include/asm/mach-ath25
  46. +load-$(CONFIG_ATH25) += 0xffffffff80041000
  47. --- /dev/null
  48. +++ b/arch/mips/ath25/Kconfig
  49. @@ -0,0 +1,9 @@
  50. +config SOC_AR5312
  51. + bool "Atheros AR5312/AR2312+ SoC support"
  52. + depends on ATH25
  53. + default y
  54. +
  55. +config SOC_AR2315
  56. + bool "Atheros AR2315+ SoC support"
  57. + depends on ATH25
  58. + default y
  59. --- /dev/null
  60. +++ b/arch/mips/ath25/Makefile
  61. @@ -0,0 +1,13 @@
  62. +#
  63. +# This file is subject to the terms and conditions of the GNU General Public
  64. +# License. See the file "COPYING" in the main directory of this archive
  65. +# for more details.
  66. +#
  67. +# Copyright (C) 2006 FON Technology, SL.
  68. +# Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  69. +# Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  70. +#
  71. +
  72. +obj-y += board.o prom.o devices.o
  73. +obj-$(CONFIG_SOC_AR5312) += ar5312.o
  74. +obj-$(CONFIG_SOC_AR2315) += ar2315.o
  75. --- /dev/null
  76. +++ b/arch/mips/ath25/board.c
  77. @@ -0,0 +1,234 @@
  78. +/*
  79. + * This file is subject to the terms and conditions of the GNU General Public
  80. + * License. See the file "COPYING" in the main directory of this archive
  81. + * for more details.
  82. + *
  83. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  84. + * Copyright (C) 2006 FON Technology, SL.
  85. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  86. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  87. + */
  88. +
  89. +#include <linux/init.h>
  90. +#include <linux/interrupt.h>
  91. +#include <asm/irq_cpu.h>
  92. +#include <asm/reboot.h>
  93. +#include <asm/bootinfo.h>
  94. +#include <asm/time.h>
  95. +
  96. +#include <ath25_platform.h>
  97. +#include "devices.h"
  98. +#include "ar5312.h"
  99. +#include "ar2315.h"
  100. +
  101. +void (*ath25_irq_dispatch)(void);
  102. +
  103. +static inline bool check_radio_magic(const void __iomem *addr)
  104. +{
  105. + addr += 0x7a; /* offset for flash magic */
  106. + return (__raw_readb(addr) == 0x5a) && (__raw_readb(addr + 1) == 0xa5);
  107. +}
  108. +
  109. +static inline bool check_notempty(const void __iomem *addr)
  110. +{
  111. + return __raw_readl(addr) != 0xffffffff;
  112. +}
  113. +
  114. +static inline bool check_board_data(const void __iomem *addr, bool broken)
  115. +{
  116. + /* config magic found */
  117. + if (__raw_readl(addr) == ATH25_BD_MAGIC)
  118. + return true;
  119. +
  120. + if (!broken)
  121. + return false;
  122. +
  123. + /* broken board data detected, use radio data to find the
  124. + * offset, user will fix this */
  125. +
  126. + if (check_radio_magic(addr + 0x1000))
  127. + return true;
  128. + if (check_radio_magic(addr + 0xf8))
  129. + return true;
  130. +
  131. + return false;
  132. +}
  133. +
  134. +static const void __iomem * __init find_board_config(const void __iomem *limit,
  135. + const bool broken)
  136. +{
  137. + const void __iomem *addr;
  138. + const void __iomem *begin = limit - 0x1000;
  139. + const void __iomem *end = limit - 0x30000;
  140. +
  141. + for (addr = begin; addr >= end; addr -= 0x1000)
  142. + if (check_board_data(addr, broken))
  143. + return addr;
  144. +
  145. + return NULL;
  146. +}
  147. +
  148. +static const void __iomem * __init find_radio_config(const void __iomem *limit,
  149. + const void __iomem *bcfg)
  150. +{
  151. + const void __iomem *rcfg, *begin, *end;
  152. +
  153. + /*
  154. + * Now find the start of Radio Configuration data, using heuristics:
  155. + * Search forward from Board Configuration data by 0x1000 bytes
  156. + * at a time until we find non-0xffffffff.
  157. + */
  158. + begin = bcfg + 0x1000;
  159. + end = limit;
  160. + for (rcfg = begin; rcfg < end; rcfg += 0x1000)
  161. + if (check_notempty(rcfg) && check_radio_magic(rcfg))
  162. + return rcfg;
  163. +
  164. + /* AR2316 relocates radio config to new location */
  165. + begin = bcfg + 0xf8;
  166. + end = limit - 0x1000 + 0xf8;
  167. + for (rcfg = begin; rcfg < end; rcfg += 0x1000)
  168. + if (check_notempty(rcfg) && check_radio_magic(rcfg))
  169. + return rcfg;
  170. +
  171. + return NULL;
  172. +}
  173. +
  174. +/*
  175. + * NB: Search region size could be larger than the actual flash size,
  176. + * but this shouldn't be a problem here, because the flash
  177. + * will simply be mapped multiple times.
  178. + */
  179. +int __init ath25_find_config(phys_addr_t base, unsigned long size)
  180. +{
  181. + const void __iomem *flash_base, *flash_limit;
  182. + struct ath25_boarddata *config;
  183. + unsigned int rcfg_size;
  184. + int broken_boarddata = 0;
  185. + const void __iomem *bcfg, *rcfg;
  186. + u8 *board_data;
  187. + u8 *radio_data;
  188. + u8 *mac_addr;
  189. + u32 offset;
  190. +
  191. + flash_base = ioremap_nocache(base, size);
  192. + flash_limit = flash_base + size;
  193. +
  194. + ath25_board.config = NULL;
  195. + ath25_board.radio = NULL;
  196. +
  197. + /* Copy the board and radio data to RAM, because accessing the mapped
  198. + * memory of the flash directly after booting is not safe */
  199. +
  200. + /* Try to find valid board and radio data */
  201. + bcfg = find_board_config(flash_limit, false);
  202. +
  203. + /* If that fails, try to at least find valid radio data */
  204. + if (!bcfg) {
  205. + bcfg = find_board_config(flash_limit, true);
  206. + broken_boarddata = 1;
  207. + }
  208. +
  209. + if (!bcfg) {
  210. + pr_warn("WARNING: No board configuration data found!\n");
  211. + goto error;
  212. + }
  213. +
  214. + board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
  215. + ath25_board.config = (struct ath25_boarddata *)board_data;
  216. + memcpy_fromio(board_data, bcfg, 0x100);
  217. + if (broken_boarddata) {
  218. + pr_warn("WARNING: broken board data detected\n");
  219. + config = ath25_board.config;
  220. + if (is_zero_ether_addr(config->enet0_mac)) {
  221. + pr_info("Fixing up empty mac addresses\n");
  222. + config->reset_config_gpio = 0xffff;
  223. + config->sys_led_gpio = 0xffff;
  224. + random_ether_addr(config->wlan0_mac);
  225. + config->wlan0_mac[0] &= ~0x06;
  226. + random_ether_addr(config->enet0_mac);
  227. + random_ether_addr(config->enet1_mac);
  228. + }
  229. + }
  230. +
  231. + /* Radio config starts 0x100 bytes after board config, regardless
  232. + * of what the physical layout on the flash chip looks like */
  233. +
  234. + rcfg = find_radio_config(flash_limit, bcfg);
  235. + if (!rcfg) {
  236. + pr_warn("WARNING: Could not find Radio Configuration data\n");
  237. + goto error;
  238. + }
  239. +
  240. + radio_data = board_data + 0x100 + ((rcfg - bcfg) & 0xfff);
  241. + ath25_board.radio = radio_data;
  242. + offset = radio_data - board_data;
  243. + pr_info("Radio config found at offset 0x%x (0x%x)\n", rcfg - bcfg,
  244. + offset);
  245. + rcfg_size = BOARD_CONFIG_BUFSZ - offset;
  246. + memcpy_fromio(radio_data, rcfg, rcfg_size);
  247. +
  248. + mac_addr = &radio_data[0x1d * 2];
  249. + if (is_broadcast_ether_addr(mac_addr)) {
  250. + pr_info("Radio MAC is blank; using board-data\n");
  251. + ether_addr_copy(mac_addr, ath25_board.config->wlan0_mac);
  252. + }
  253. +
  254. + iounmap(flash_base);
  255. +
  256. + return 0;
  257. +
  258. +error:
  259. + iounmap(flash_base);
  260. + return -ENODEV;
  261. +}
  262. +
  263. +static void ath25_halt(void)
  264. +{
  265. + local_irq_disable();
  266. + unreachable();
  267. +}
  268. +
  269. +void __init plat_mem_setup(void)
  270. +{
  271. + _machine_halt = ath25_halt;
  272. + pm_power_off = ath25_halt;
  273. +
  274. + if (is_ar5312())
  275. + ar5312_plat_mem_setup();
  276. + else
  277. + ar2315_plat_mem_setup();
  278. +
  279. + /* Disable data watchpoints */
  280. + write_c0_watchlo0(0);
  281. +}
  282. +
  283. +asmlinkage void plat_irq_dispatch(void)
  284. +{
  285. + ath25_irq_dispatch();
  286. +}
  287. +
  288. +void __init plat_time_init(void)
  289. +{
  290. + if (is_ar5312())
  291. + ar5312_plat_time_init();
  292. + else
  293. + ar2315_plat_time_init();
  294. +}
  295. +
  296. +unsigned int __cpuinit get_c0_compare_int(void)
  297. +{
  298. + return CP0_LEGACY_COMPARE_IRQ;
  299. +}
  300. +
  301. +void __init arch_init_irq(void)
  302. +{
  303. + clear_c0_status(ST0_IM);
  304. + mips_cpu_irq_init();
  305. +
  306. + /* Initialize interrupt controllers */
  307. + if (is_ar5312())
  308. + ar5312_arch_init_irq();
  309. + else
  310. + ar2315_arch_init_irq();
  311. +}
  312. --- /dev/null
  313. +++ b/arch/mips/ath25/prom.c
  314. @@ -0,0 +1,26 @@
  315. +/*
  316. + * This file is subject to the terms and conditions of the GNU General Public
  317. + * License. See the file "COPYING" in the main directory of this archive
  318. + * for more details.
  319. + *
  320. + * Copyright MontaVista Software Inc
  321. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  322. + * Copyright (C) 2006 FON Technology, SL.
  323. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  324. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  325. + */
  326. +
  327. +/*
  328. + * Prom setup file for AR5312/AR231x SoCs
  329. + */
  330. +
  331. +#include <linux/init.h>
  332. +#include <asm/bootinfo.h>
  333. +
  334. +void __init prom_init(void)
  335. +{
  336. +}
  337. +
  338. +void __init prom_free_prom_memory(void)
  339. +{
  340. +}
  341. --- /dev/null
  342. +++ b/arch/mips/include/asm/mach-ath25/ath25_platform.h
  343. @@ -0,0 +1,73 @@
  344. +#ifndef __ASM_MACH_ATH25_PLATFORM_H
  345. +#define __ASM_MACH_ATH25_PLATFORM_H
  346. +
  347. +#include <linux/etherdevice.h>
  348. +
  349. +/*
  350. + * This is board-specific data that is stored in a "fixed" location in flash.
  351. + * It is shared across operating systems, so it should not be changed lightly.
  352. + * The main reason we need it is in order to extract the ethernet MAC
  353. + * address(es).
  354. + */
  355. +struct ath25_boarddata {
  356. + u32 magic; /* board data is valid */
  357. +#define ATH25_BD_MAGIC 0x35333131 /* "5311", for all 531x/231x platforms */
  358. + u16 cksum; /* checksum (starting with BD_REV 2) */
  359. + u16 rev; /* revision of this struct */
  360. +#define BD_REV 4
  361. + char board_name[64]; /* Name of board */
  362. + u16 major; /* Board major number */
  363. + u16 minor; /* Board minor number */
  364. + u32 flags; /* Board configuration */
  365. +#define BD_ENET0 0x00000001 /* ENET0 is stuffed */
  366. +#define BD_ENET1 0x00000002 /* ENET1 is stuffed */
  367. +#define BD_UART1 0x00000004 /* UART1 is stuffed */
  368. +#define BD_UART0 0x00000008 /* UART0 is stuffed (dma) */
  369. +#define BD_RSTFACTORY 0x00000010 /* Reset factory defaults stuffed */
  370. +#define BD_SYSLED 0x00000020 /* System LED stuffed */
  371. +#define BD_EXTUARTCLK 0x00000040 /* External UART clock */
  372. +#define BD_CPUFREQ 0x00000080 /* cpu freq is valid in nvram */
  373. +#define BD_SYSFREQ 0x00000100 /* sys freq is set in nvram */
  374. +#define BD_WLAN0 0x00000200 /* Enable WLAN0 */
  375. +#define BD_MEMCAP 0x00000400 /* CAP SDRAM @ mem_cap for testing */
  376. +#define BD_DISWATCHDOG 0x00000800 /* disable system watchdog */
  377. +#define BD_WLAN1 0x00001000 /* Enable WLAN1 (ar5212) */
  378. +#define BD_ISCASPER 0x00002000 /* FLAG for AR2312 */
  379. +#define BD_WLAN0_2G_EN 0x00004000 /* FLAG for radio0_2G */
  380. +#define BD_WLAN0_5G_EN 0x00008000 /* FLAG for radio0_2G */
  381. +#define BD_WLAN1_2G_EN 0x00020000 /* FLAG for radio0_2G */
  382. +#define BD_WLAN1_5G_EN 0x00040000 /* FLAG for radio0_2G */
  383. + u16 reset_config_gpio; /* Reset factory GPIO pin */
  384. + u16 sys_led_gpio; /* System LED GPIO pin */
  385. +
  386. + u32 cpu_freq; /* CPU core frequency in Hz */
  387. + u32 sys_freq; /* System frequency in Hz */
  388. + u32 cnt_freq; /* Calculated C0_COUNT frequency */
  389. +
  390. + u8 wlan0_mac[ETH_ALEN];
  391. + u8 enet0_mac[ETH_ALEN];
  392. + u8 enet1_mac[ETH_ALEN];
  393. +
  394. + u16 pci_id; /* Pseudo PCIID for common code */
  395. + u16 mem_cap; /* cap bank1 in MB */
  396. +
  397. + /* version 3 */
  398. + u8 wlan1_mac[ETH_ALEN]; /* (ar5212) */
  399. +};
  400. +
  401. +#define BOARD_CONFIG_BUFSZ 0x1000
  402. +
  403. +/*
  404. + * Platform device information for the Wireless MAC
  405. + */
  406. +struct ar231x_board_config {
  407. + u16 devid;
  408. +
  409. + /* board config data */
  410. + struct ath25_boarddata *config;
  411. +
  412. + /* radio calibration data */
  413. + const char *radio;
  414. +};
  415. +
  416. +#endif /* __ASM_MACH_ATH25_PLATFORM_H */
  417. --- /dev/null
  418. +++ b/arch/mips/include/asm/mach-ath25/cpu-feature-overrides.h
  419. @@ -0,0 +1,64 @@
  420. +/*
  421. + * Atheros AR231x/AR531x SoC specific CPU feature overrides
  422. + *
  423. + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
  424. + *
  425. + * This file was derived from: include/asm-mips/cpu-features.h
  426. + * Copyright (C) 2003, 2004 Ralf Baechle
  427. + * Copyright (C) 2004 Maciej W. Rozycki
  428. + *
  429. + * This program is free software; you can redistribute it and/or modify it
  430. + * under the terms of the GNU General Public License version 2 as published
  431. + * by the Free Software Foundation.
  432. + *
  433. + */
  434. +#ifndef __ASM_MACH_ATH25_CPU_FEATURE_OVERRIDES_H
  435. +#define __ASM_MACH_ATH25_CPU_FEATURE_OVERRIDES_H
  436. +
  437. +/*
  438. + * The Atheros AR531x/AR231x SoCs have MIPS 4Kc/4KEc core.
  439. + */
  440. +#define cpu_has_tlb 1
  441. +#define cpu_has_4kex 1
  442. +#define cpu_has_3k_cache 0
  443. +#define cpu_has_4k_cache 1
  444. +#define cpu_has_tx39_cache 0
  445. +#define cpu_has_sb1_cache 0
  446. +#define cpu_has_fpu 0
  447. +#define cpu_has_32fpr 0
  448. +#define cpu_has_counter 1
  449. +#define cpu_has_ejtag 1
  450. +
  451. +#if !defined(CONFIG_SOC_AR5312)
  452. +# define cpu_has_llsc 1
  453. +#else
  454. +/*
  455. + * The MIPS 4Kc V0.9 core in the AR5312/AR2312 have problems with the
  456. + * ll/sc instructions.
  457. + */
  458. +# define cpu_has_llsc 0
  459. +#endif
  460. +
  461. +#define cpu_has_mips16 0
  462. +#define cpu_has_mdmx 0
  463. +#define cpu_has_mips3d 0
  464. +#define cpu_has_smartmips 0
  465. +
  466. +#define cpu_has_mips32r1 1
  467. +
  468. +#if !defined(CONFIG_SOC_AR5312)
  469. +# define cpu_has_mips32r2 1
  470. +#endif
  471. +
  472. +#define cpu_has_mips64r1 0
  473. +#define cpu_has_mips64r2 0
  474. +
  475. +#define cpu_has_dsp 0
  476. +#define cpu_has_mipsmt 0
  477. +
  478. +#define cpu_has_64bits 0
  479. +#define cpu_has_64bit_zero_reg 0
  480. +#define cpu_has_64bit_gp_regs 0
  481. +#define cpu_has_64bit_addresses 0
  482. +
  483. +#endif /* __ASM_MACH_ATH25_CPU_FEATURE_OVERRIDES_H */
  484. --- /dev/null
  485. +++ b/arch/mips/include/asm/mach-ath25/dma-coherence.h
  486. @@ -0,0 +1,82 @@
  487. +/*
  488. + * This file is subject to the terms and conditions of the GNU General Public
  489. + * License. See the file "COPYING" in the main directory of this archive
  490. + * for more details.
  491. + *
  492. + * Copyright (C) 2006 Ralf Baechle <ralf@linux-mips.org>
  493. + * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
  494. + *
  495. + */
  496. +#ifndef __ASM_MACH_ATH25_DMA_COHERENCE_H
  497. +#define __ASM_MACH_ATH25_DMA_COHERENCE_H
  498. +
  499. +#include <linux/device.h>
  500. +
  501. +/*
  502. + * We need some arbitrary non-zero value to be programmed to the BAR1 register
  503. + * of PCI host controller to enable DMA. The same value should be used as the
  504. + * offset to calculate the physical address of DMA buffer for PCI devices.
  505. + */
  506. +#define AR2315_PCI_HOST_SDRAM_BASEADDR 0x20000000
  507. +
  508. +static inline dma_addr_t ath25_dev_offset(struct device *dev)
  509. +{
  510. +#ifdef CONFIG_PCI
  511. + extern struct bus_type pci_bus_type;
  512. +
  513. + if (dev && dev->bus == &pci_bus_type)
  514. + return AR2315_PCI_HOST_SDRAM_BASEADDR;
  515. +#endif
  516. + return 0;
  517. +}
  518. +
  519. +static inline dma_addr_t
  520. +plat_map_dma_mem(struct device *dev, void *addr, size_t size)
  521. +{
  522. + return virt_to_phys(addr) + ath25_dev_offset(dev);
  523. +}
  524. +
  525. +static inline dma_addr_t
  526. +plat_map_dma_mem_page(struct device *dev, struct page *page)
  527. +{
  528. + return page_to_phys(page) + ath25_dev_offset(dev);
  529. +}
  530. +
  531. +static inline unsigned long
  532. +plat_dma_addr_to_phys(struct device *dev, dma_addr_t dma_addr)
  533. +{
  534. + return dma_addr - ath25_dev_offset(dev);
  535. +}
  536. +
  537. +static inline void
  538. +plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr, size_t size,
  539. + enum dma_data_direction direction)
  540. +{
  541. +}
  542. +
  543. +static inline int plat_dma_supported(struct device *dev, u64 mask)
  544. +{
  545. + return 1;
  546. +}
  547. +
  548. +static inline void plat_extra_sync_for_device(struct device *dev)
  549. +{
  550. +}
  551. +
  552. +static inline int plat_dma_mapping_error(struct device *dev,
  553. + dma_addr_t dma_addr)
  554. +{
  555. + return 0;
  556. +}
  557. +
  558. +static inline int plat_device_is_coherent(struct device *dev)
  559. +{
  560. +#ifdef CONFIG_DMA_COHERENT
  561. + return 1;
  562. +#endif
  563. +#ifdef CONFIG_DMA_NONCOHERENT
  564. + return 0;
  565. +#endif
  566. +}
  567. +
  568. +#endif /* __ASM_MACH_ATH25_DMA_COHERENCE_H */
  569. --- /dev/null
  570. +++ b/arch/mips/include/asm/mach-ath25/gpio.h
  571. @@ -0,0 +1,16 @@
  572. +#ifndef __ASM_MACH_ATH25_GPIO_H
  573. +#define __ASM_MACH_ATH25_GPIO_H
  574. +
  575. +#include <asm-generic/gpio.h>
  576. +
  577. +#define gpio_get_value __gpio_get_value
  578. +#define gpio_set_value __gpio_set_value
  579. +#define gpio_cansleep __gpio_cansleep
  580. +#define gpio_to_irq __gpio_to_irq
  581. +
  582. +static inline int irq_to_gpio(unsigned irq)
  583. +{
  584. + return -EINVAL;
  585. +}
  586. +
  587. +#endif /* __ASM_MACH_ATH25_GPIO_H */
  588. --- /dev/null
  589. +++ b/arch/mips/include/asm/mach-ath25/war.h
  590. @@ -0,0 +1,25 @@
  591. +/*
  592. + * This file is subject to the terms and conditions of the GNU General Public
  593. + * License. See the file "COPYING" in the main directory of this archive
  594. + * for more details.
  595. + *
  596. + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  597. + */
  598. +#ifndef __ASM_MACH_ATH25_WAR_H
  599. +#define __ASM_MACH_ATH25_WAR_H
  600. +
  601. +#define R4600_V1_INDEX_ICACHEOP_WAR 0
  602. +#define R4600_V1_HIT_CACHEOP_WAR 0
  603. +#define R4600_V2_HIT_CACHEOP_WAR 0
  604. +#define R5432_CP0_INTERRUPT_WAR 0
  605. +#define BCM1250_M3_WAR 0
  606. +#define SIBYTE_1956_WAR 0
  607. +#define MIPS4K_ICACHE_REFILL_WAR 0
  608. +#define MIPS_CACHE_SYNC_WAR 0
  609. +#define TX49XX_ICACHE_INDEX_INV_WAR 0
  610. +#define RM9000_CDEX_SMP_WAR 0
  611. +#define ICACHE_REFILLS_WORKAROUND_WAR 0
  612. +#define R10000_LLSC_WAR 0
  613. +#define MIPS34K_MISSED_ITLB_WAR 0
  614. +
  615. +#endif /* __ASM_MACH_ATH25_WAR_H */
  616. --- /dev/null
  617. +++ b/arch/mips/ath25/ar2315_regs.h
  618. @@ -0,0 +1,410 @@
  619. +/*
  620. + * Register definitions for AR2315+
  621. + *
  622. + * This file is subject to the terms and conditions of the GNU General Public
  623. + * License. See the file "COPYING" in the main directory of this archive
  624. + * for more details.
  625. + *
  626. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  627. + * Copyright (C) 2006 FON Technology, SL.
  628. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  629. + * Copyright (C) 2006-2008 Felix Fietkau <nbd@openwrt.org>
  630. + */
  631. +
  632. +#ifndef __ASM_MACH_ATH25_AR2315_REGS_H
  633. +#define __ASM_MACH_ATH25_AR2315_REGS_H
  634. +
  635. +/*
  636. + * IRQs
  637. + */
  638. +#define AR2315_IRQ_MISC (MIPS_CPU_IRQ_BASE + 2) /* C0_CAUSE: 0x0400 */
  639. +#define AR2315_IRQ_WLAN0 (MIPS_CPU_IRQ_BASE + 3) /* C0_CAUSE: 0x0800 */
  640. +#define AR2315_IRQ_ENET0 (MIPS_CPU_IRQ_BASE + 4) /* C0_CAUSE: 0x1000 */
  641. +#define AR2315_IRQ_LCBUS_PCI (MIPS_CPU_IRQ_BASE + 5) /* C0_CAUSE: 0x2000 */
  642. +#define AR2315_IRQ_WLAN0_POLL (MIPS_CPU_IRQ_BASE + 6) /* C0_CAUSE: 0x4000 */
  643. +
  644. +/*
  645. + * Miscellaneous interrupts, which share IP2.
  646. + */
  647. +#define AR2315_MISC_IRQ_UART0 0
  648. +#define AR2315_MISC_IRQ_I2C_RSVD 1
  649. +#define AR2315_MISC_IRQ_SPI 2
  650. +#define AR2315_MISC_IRQ_AHB 3
  651. +#define AR2315_MISC_IRQ_APB 4
  652. +#define AR2315_MISC_IRQ_TIMER 5
  653. +#define AR2315_MISC_IRQ_GPIO 6
  654. +#define AR2315_MISC_IRQ_WATCHDOG 7
  655. +#define AR2315_MISC_IRQ_IR_RSVD 8
  656. +#define AR2315_MISC_IRQ_COUNT 9
  657. +
  658. +/*
  659. + * Address map
  660. + */
  661. +#define AR2315_SPI_READ_BASE 0x08000000 /* SPI flash */
  662. +#define AR2315_SPI_READ_SIZE 0x01000000
  663. +#define AR2315_WLAN0_BASE 0x10000000 /* Wireless MMR */
  664. +#define AR2315_PCI_BASE 0x10100000 /* PCI MMR */
  665. +#define AR2315_PCI_SIZE 0x00001000
  666. +#define AR2315_SDRAMCTL_BASE 0x10300000 /* SDRAM MMR */
  667. +#define AR2315_SDRAMCTL_SIZE 0x00000020
  668. +#define AR2315_LOCAL_BASE 0x10400000 /* Local bus MMR */
  669. +#define AR2315_ENET0_BASE 0x10500000 /* Ethernet MMR */
  670. +#define AR2315_RST_BASE 0x11000000 /* Reset control MMR */
  671. +#define AR2315_RST_SIZE 0x00000100
  672. +#define AR2315_UART0_BASE 0x11100000 /* UART MMR */
  673. +#define AR2315_SPI_MMR_BASE 0x11300000 /* SPI flash MMR */
  674. +#define AR2315_SPI_MMR_SIZE 0x00000010
  675. +#define AR2315_PCI_EXT_BASE 0x80000000 /* PCI external */
  676. +#define AR2315_PCI_EXT_SIZE 0x40000000
  677. +
  678. +/*
  679. + * Configuration registers
  680. + */
  681. +
  682. +/* Cold reset register */
  683. +#define AR2315_COLD_RESET 0x0000
  684. +
  685. +#define AR2315_RESET_COLD_AHB 0x00000001
  686. +#define AR2315_RESET_COLD_APB 0x00000002
  687. +#define AR2315_RESET_COLD_CPU 0x00000004
  688. +#define AR2315_RESET_COLD_CPUWARM 0x00000008
  689. +#define AR2315_RESET_SYSTEM (RESET_COLD_CPU |\
  690. + RESET_COLD_APB |\
  691. + RESET_COLD_AHB) /* full system */
  692. +#define AR2317_RESET_SYSTEM 0x00000010
  693. +
  694. +/* Reset register */
  695. +#define AR2315_RESET 0x0004
  696. +
  697. +#define AR2315_RESET_WARM_WLAN0_MAC 0x00000001 /* warm reset WLAN0 MAC */
  698. +#define AR2315_RESET_WARM_WLAN0_BB 0x00000002 /* warm reset WLAN0 BB */
  699. +#define AR2315_RESET_MPEGTS_RSVD 0x00000004 /* warm reset MPEG-TS */
  700. +#define AR2315_RESET_PCIDMA 0x00000008 /* warm reset PCI ahb/dma */
  701. +#define AR2315_RESET_MEMCTL 0x00000010 /* warm reset mem control */
  702. +#define AR2315_RESET_LOCAL 0x00000020 /* warm reset local bus */
  703. +#define AR2315_RESET_I2C_RSVD 0x00000040 /* warm reset I2C bus */
  704. +#define AR2315_RESET_SPI 0x00000080 /* warm reset SPI iface */
  705. +#define AR2315_RESET_UART0 0x00000100 /* warm reset UART0 */
  706. +#define AR2315_RESET_IR_RSVD 0x00000200 /* warm reset IR iface */
  707. +#define AR2315_RESET_EPHY0 0x00000400 /* cold reset ENET0 phy */
  708. +#define AR2315_RESET_ENET0 0x00000800 /* cold reset ENET0 MAC */
  709. +
  710. +/* AHB master arbitration control */
  711. +#define AR2315_AHB_ARB_CTL 0x0008
  712. +
  713. +#define AR2315_ARB_CPU 0x00000001 /* CPU, default */
  714. +#define AR2315_ARB_WLAN 0x00000002 /* WLAN */
  715. +#define AR2315_ARB_MPEGTS_RSVD 0x00000004 /* MPEG-TS */
  716. +#define AR2315_ARB_LOCAL 0x00000008 /* Local bus */
  717. +#define AR2315_ARB_PCI 0x00000010 /* PCI bus */
  718. +#define AR2315_ARB_ETHERNET 0x00000020 /* Ethernet */
  719. +#define AR2315_ARB_RETRY 0x00000100 /* Retry policy (debug) */
  720. +
  721. +/* Config Register */
  722. +#define AR2315_ENDIAN_CTL 0x000c
  723. +
  724. +#define AR2315_CONFIG_AHB 0x00000001 /* EC-AHB bridge endian */
  725. +#define AR2315_CONFIG_WLAN 0x00000002 /* WLAN byteswap */
  726. +#define AR2315_CONFIG_MPEGTS_RSVD 0x00000004 /* MPEG-TS byteswap */
  727. +#define AR2315_CONFIG_PCI 0x00000008 /* PCI byteswap */
  728. +#define AR2315_CONFIG_MEMCTL 0x00000010 /* Mem controller endian */
  729. +#define AR2315_CONFIG_LOCAL 0x00000020 /* Local bus byteswap */
  730. +#define AR2315_CONFIG_ETHERNET 0x00000040 /* Ethernet byteswap */
  731. +#define AR2315_CONFIG_MERGE 0x00000200 /* CPU write buffer merge */
  732. +#define AR2315_CONFIG_CPU 0x00000400 /* CPU big endian */
  733. +#define AR2315_CONFIG_BIG 0x00000400
  734. +#define AR2315_CONFIG_PCIAHB 0x00000800
  735. +#define AR2315_CONFIG_PCIAHB_BRIDGE 0x00001000
  736. +#define AR2315_CONFIG_SPI 0x00008000 /* SPI byteswap */
  737. +#define AR2315_CONFIG_CPU_DRAM 0x00010000
  738. +#define AR2315_CONFIG_CPU_PCI 0x00020000
  739. +#define AR2315_CONFIG_CPU_MMR 0x00040000
  740. +
  741. +/* NMI control */
  742. +#define AR2315_NMI_CTL 0x0010
  743. +
  744. +#define AR2315_NMI_EN 1
  745. +
  746. +/* Revision Register - Initial value is 0x3010 (WMAC 3.0, AR231X 1.0). */
  747. +#define AR2315_SREV 0x0014
  748. +
  749. +#define AR2315_REV_MAJ 0x000000f0
  750. +#define AR2315_REV_MAJ_S 4
  751. +#define AR2315_REV_MIN 0x0000000f
  752. +#define AR2315_REV_MIN_S 0
  753. +#define AR2315_REV_CHIP (AR2315_REV_MAJ | AR2315_REV_MIN)
  754. +
  755. +/* Interface Enable */
  756. +#define AR2315_IF_CTL 0x0018
  757. +
  758. +#define AR2315_IF_MASK 0x00000007
  759. +#define AR2315_IF_DISABLED 0 /* Disable all */
  760. +#define AR2315_IF_PCI 1 /* PCI */
  761. +#define AR2315_IF_TS_LOCAL 2 /* Local bus */
  762. +#define AR2315_IF_ALL 3 /* Emulation only */
  763. +#define AR2315_IF_LOCAL_HOST 0x00000008
  764. +#define AR2315_IF_PCI_HOST 0x00000010
  765. +#define AR2315_IF_PCI_INTR 0x00000020
  766. +#define AR2315_IF_PCI_CLK_MASK 0x00030000
  767. +#define AR2315_IF_PCI_CLK_INPUT 0
  768. +#define AR2315_IF_PCI_CLK_OUTPUT_LOW 1
  769. +#define AR2315_IF_PCI_CLK_OUTPUT_CLK 2
  770. +#define AR2315_IF_PCI_CLK_OUTPUT_HIGH 3
  771. +#define AR2315_IF_PCI_CLK_SHIFT 16
  772. +
  773. +/* APB Interrupt control */
  774. +#define AR2315_ISR 0x0020
  775. +#define AR2315_IMR 0x0024
  776. +#define AR2315_GISR 0x0028
  777. +
  778. +#define AR2315_ISR_UART0 0x00000001 /* high speed UART */
  779. +#define AR2315_ISR_I2C_RSVD 0x00000002 /* I2C bus */
  780. +#define AR2315_ISR_SPI 0x00000004 /* SPI bus */
  781. +#define AR2315_ISR_AHB 0x00000008 /* AHB error */
  782. +#define AR2315_ISR_APB 0x00000010 /* APB error */
  783. +#define AR2315_ISR_TIMER 0x00000020 /* Timer */
  784. +#define AR2315_ISR_GPIO 0x00000040 /* GPIO */
  785. +#define AR2315_ISR_WD 0x00000080 /* Watchdog */
  786. +#define AR2315_ISR_IR_RSVD 0x00000100 /* IR */
  787. +
  788. +#define AR2315_GISR_MISC 0x00000001 /* Misc */
  789. +#define AR2315_GISR_WLAN0 0x00000002 /* WLAN0 */
  790. +#define AR2315_GISR_MPEGTS_RSVD 0x00000004 /* MPEG-TS */
  791. +#define AR2315_GISR_LOCALPCI 0x00000008 /* Local/PCI bus */
  792. +#define AR2315_GISR_WMACPOLL 0x00000010
  793. +#define AR2315_GISR_TIMER 0x00000020
  794. +#define AR2315_GISR_ETHERNET 0x00000040 /* Ethernet */
  795. +
  796. +/* Generic timer */
  797. +#define AR2315_TIMER 0x0030
  798. +#define AR2315_RELOAD 0x0034
  799. +
  800. +/* Watchdog timer */
  801. +#define AR2315_WDT_TIMER 0x0038
  802. +#define AR2315_WDT_CTRL 0x003c
  803. +
  804. +#define AR2315_WDT_CTRL_IGNORE 0x00000000 /* ignore expiration */
  805. +#define AR2315_WDT_CTRL_NMI 0x00000001 /* NMI on watchdog */
  806. +#define AR2315_WDT_CTRL_RESET 0x00000002 /* reset on watchdog */
  807. +
  808. +/* CPU Performance Counters */
  809. +#define AR2315_PERFCNT0 0x0048
  810. +#define AR2315_PERFCNT1 0x004c
  811. +
  812. +#define AR2315_PERF0_DATAHIT 0x00000001 /* Count Data Cache Hits */
  813. +#define AR2315_PERF0_DATAMISS 0x00000002 /* Count Data Cache Misses */
  814. +#define AR2315_PERF0_INSTHIT 0x00000004 /* Count Instruction Cache Hits */
  815. +#define AR2315_PERF0_INSTMISS 0x00000008 /* Count Instruction Cache Misses */
  816. +#define AR2315_PERF0_ACTIVE 0x00000010 /* Count Active Processor Cycles */
  817. +#define AR2315_PERF0_WBHIT 0x00000020 /* Count CPU Write Buffer Hits */
  818. +#define AR2315_PERF0_WBMISS 0x00000040 /* Count CPU Write Buffer Misses */
  819. +
  820. +#define AR2315_PERF1_EB_ARDY 0x00000001 /* Count EB_ARdy signal */
  821. +#define AR2315_PERF1_EB_AVALID 0x00000002 /* Count EB_AValid signal */
  822. +#define AR2315_PERF1_EB_WDRDY 0x00000004 /* Count EB_WDRdy signal */
  823. +#define AR2315_PERF1_EB_RDVAL 0x00000008 /* Count EB_RdVal signal */
  824. +#define AR2315_PERF1_VRADDR 0x00000010 /* Count valid read address cycles*/
  825. +#define AR2315_PERF1_VWADDR 0x00000020 /* Count valid write address cycl.*/
  826. +#define AR2315_PERF1_VWDATA 0x00000040 /* Count valid write data cycles */
  827. +
  828. +/* AHB Error Reporting */
  829. +#define AR2315_AHB_ERR0 0x0050 /* error */
  830. +#define AR2315_AHB_ERR1 0x0054 /* haddr */
  831. +#define AR2315_AHB_ERR2 0x0058 /* hwdata */
  832. +#define AR2315_AHB_ERR3 0x005c /* hrdata */
  833. +#define AR2315_AHB_ERR4 0x0060 /* status */
  834. +
  835. +#define AR2315_AHB_ERROR_DET 1 /* AHB Error has been detected, */
  836. + /* write 1 to clear all bits in ERR0 */
  837. +#define AR2315_AHB_ERROR_OVR 2 /* AHB Error overflow has been detected */
  838. +#define AR2315_AHB_ERROR_WDT 4 /* AHB Error due to wdt instead of hresp */
  839. +
  840. +#define AR2315_PROCERR_HMAST 0x0000000f
  841. +#define AR2315_PROCERR_HMAST_DFLT 0
  842. +#define AR2315_PROCERR_HMAST_WMAC 1
  843. +#define AR2315_PROCERR_HMAST_ENET 2
  844. +#define AR2315_PROCERR_HMAST_PCIENDPT 3
  845. +#define AR2315_PROCERR_HMAST_LOCAL 4
  846. +#define AR2315_PROCERR_HMAST_CPU 5
  847. +#define AR2315_PROCERR_HMAST_PCITGT 6
  848. +#define AR2315_PROCERR_HMAST_S 0
  849. +#define AR2315_PROCERR_HWRITE 0x00000010
  850. +#define AR2315_PROCERR_HSIZE 0x00000060
  851. +#define AR2315_PROCERR_HSIZE_S 5
  852. +#define AR2315_PROCERR_HTRANS 0x00000180
  853. +#define AR2315_PROCERR_HTRANS_S 7
  854. +#define AR2315_PROCERR_HBURST 0x00000e00
  855. +#define AR2315_PROCERR_HBURST_S 9
  856. +
  857. +/* Clock Control */
  858. +#define AR2315_PLLC_CTL 0x0064
  859. +#define AR2315_PLLV_CTL 0x0068
  860. +#define AR2315_CPUCLK 0x006c
  861. +#define AR2315_AMBACLK 0x0070
  862. +#define AR2315_SYNCCLK 0x0074
  863. +#define AR2315_DSL_SLEEP_CTL 0x0080
  864. +#define AR2315_DSL_SLEEP_DUR 0x0084
  865. +
  866. +/* PLLc Control fields */
  867. +#define AR2315_PLLC_REF_DIV_M 0x00000003
  868. +#define AR2315_PLLC_REF_DIV_S 0
  869. +#define AR2315_PLLC_FDBACK_DIV_M 0x0000007c
  870. +#define AR2315_PLLC_FDBACK_DIV_S 2
  871. +#define AR2315_PLLC_ADD_FDBACK_DIV_M 0x00000080
  872. +#define AR2315_PLLC_ADD_FDBACK_DIV_S 7
  873. +#define AR2315_PLLC_CLKC_DIV_M 0x0001c000
  874. +#define AR2315_PLLC_CLKC_DIV_S 14
  875. +#define AR2315_PLLC_CLKM_DIV_M 0x00700000
  876. +#define AR2315_PLLC_CLKM_DIV_S 20
  877. +
  878. +/* CPU CLK Control fields */
  879. +#define AR2315_CPUCLK_CLK_SEL_M 0x00000003
  880. +#define AR2315_CPUCLK_CLK_SEL_S 0
  881. +#define AR2315_CPUCLK_CLK_DIV_M 0x0000000c
  882. +#define AR2315_CPUCLK_CLK_DIV_S 2
  883. +
  884. +/* AMBA CLK Control fields */
  885. +#define AR2315_AMBACLK_CLK_SEL_M 0x00000003
  886. +#define AR2315_AMBACLK_CLK_SEL_S 0
  887. +#define AR2315_AMBACLK_CLK_DIV_M 0x0000000c
  888. +#define AR2315_AMBACLK_CLK_DIV_S 2
  889. +
  890. +/* PCI Clock Control */
  891. +#define AR2315_PCICLK 0x00a4
  892. +
  893. +#define AR2315_PCICLK_INPUT_M 0x00000003
  894. +#define AR2315_PCICLK_INPUT_S 0
  895. +#define AR2315_PCICLK_PLLC_CLKM 0
  896. +#define AR2315_PCICLK_PLLC_CLKM1 1
  897. +#define AR2315_PCICLK_PLLC_CLKC 2
  898. +#define AR2315_PCICLK_REF_CLK 3
  899. +#define AR2315_PCICLK_DIV_M 0x0000000c
  900. +#define AR2315_PCICLK_DIV_S 2
  901. +#define AR2315_PCICLK_IN_FREQ 0
  902. +#define AR2315_PCICLK_IN_FREQ_DIV_6 1
  903. +#define AR2315_PCICLK_IN_FREQ_DIV_8 2
  904. +#define AR2315_PCICLK_IN_FREQ_DIV_10 3
  905. +
  906. +/* Observation Control Register */
  907. +#define AR2315_OCR 0x00b0
  908. +
  909. +#define AR2315_OCR_GPIO0_IRIN 0x00000040
  910. +#define AR2315_OCR_GPIO1_IROUT 0x00000080
  911. +#define AR2315_OCR_GPIO3_RXCLR 0x00000200
  912. +
  913. +/* General Clock Control */
  914. +#define AR2315_MISCCLK 0x00b4
  915. +
  916. +#define AR2315_MISCCLK_PLLBYPASS_EN 0x00000001
  917. +#define AR2315_MISCCLK_PROCREFCLK 0x00000002
  918. +
  919. +/*
  920. + * SDRAM Controller
  921. + * - No read or write buffers are included.
  922. + */
  923. +#define AR2315_MEM_CFG 0x0000
  924. +#define AR2315_MEM_CTRL 0x000c
  925. +#define AR2315_MEM_REF 0x0010
  926. +
  927. +#define AR2315_MEM_CFG_DATA_WIDTH_M 0x00006000
  928. +#define AR2315_MEM_CFG_DATA_WIDTH_S 13
  929. +#define AR2315_MEM_CFG_COL_WIDTH_M 0x00001e00
  930. +#define AR2315_MEM_CFG_COL_WIDTH_S 9
  931. +#define AR2315_MEM_CFG_ROW_WIDTH_M 0x000001e0
  932. +#define AR2315_MEM_CFG_ROW_WIDTH_S 5
  933. +#define AR2315_MEM_CFG_BANKADDR_BITS_M 0x00000018
  934. +#define AR2315_MEM_CFG_BANKADDR_BITS_S 3
  935. +
  936. +/*
  937. + * Local Bus Interface Registers
  938. + */
  939. +#define AR2315_LB_CONFIG 0x0000
  940. +
  941. +#define AR2315_LBCONF_OE 0x00000001 /* =1 OE is low-true */
  942. +#define AR2315_LBCONF_CS0 0x00000002 /* =1 first CS is low-true */
  943. +#define AR2315_LBCONF_CS1 0x00000004 /* =1 2nd CS is low-true */
  944. +#define AR2315_LBCONF_RDY 0x00000008 /* =1 RDY is low-true */
  945. +#define AR2315_LBCONF_WE 0x00000010 /* =1 Write En is low-true */
  946. +#define AR2315_LBCONF_WAIT 0x00000020 /* =1 WAIT is low-true */
  947. +#define AR2315_LBCONF_ADS 0x00000040 /* =1 Adr Strobe is low-true */
  948. +#define AR2315_LBCONF_MOT 0x00000080 /* =0 Intel, =1 Motorola */
  949. +#define AR2315_LBCONF_8CS 0x00000100 /* =1 8 bits CS, 0= 16bits */
  950. +#define AR2315_LBCONF_8DS 0x00000200 /* =1 8 bits Data S, 0=16bits */
  951. +#define AR2315_LBCONF_ADS_EN 0x00000400 /* =1 Enable ADS */
  952. +#define AR2315_LBCONF_ADR_OE 0x00000800 /* =1 Adr cap on OE, WE or DS */
  953. +#define AR2315_LBCONF_ADDT_MUX 0x00001000 /* =1 Adr and Data share bus */
  954. +#define AR2315_LBCONF_DATA_OE 0x00002000 /* =1 Data cap on OE, WE, DS */
  955. +#define AR2315_LBCONF_16DATA 0x00004000 /* =1 Data is 16 bits wide */
  956. +#define AR2315_LBCONF_SWAPDT 0x00008000 /* =1 Byte swap data */
  957. +#define AR2315_LBCONF_SYNC 0x00010000 /* =1 Bus synchronous to clk */
  958. +#define AR2315_LBCONF_INT 0x00020000 /* =1 Intr is low true */
  959. +#define AR2315_LBCONF_INT_CTR0 0x00000000 /* GND high-Z, Vdd is high-Z */
  960. +#define AR2315_LBCONF_INT_CTR1 0x00040000 /* GND drive, Vdd is high-Z */
  961. +#define AR2315_LBCONF_INT_CTR2 0x00080000 /* GND high-Z, Vdd drive */
  962. +#define AR2315_LBCONF_INT_CTR3 0x000c0000 /* GND drive, Vdd drive */
  963. +#define AR2315_LBCONF_RDY_WAIT 0x00100000 /* =1 RDY is negative of WAIT */
  964. +#define AR2315_LBCONF_INT_PULSE 0x00200000 /* =1 Interrupt is a pulse */
  965. +#define AR2315_LBCONF_ENABLE 0x00400000 /* =1 Falcon respond to LB */
  966. +
  967. +#define AR2315_LB_CLKSEL 0x0004
  968. +
  969. +#define AR2315_LBCLK_EXT 0x00000001 /* use external clk for lb */
  970. +
  971. +#define AR2315_LB_1MS 0x0008
  972. +
  973. +#define AR2315_LB1MS_MASK 0x0003ffff /* # of AHB clk cycles in 1ms */
  974. +
  975. +#define AR2315_LB_MISCCFG 0x000c
  976. +
  977. +#define AR2315_LBM_TXD_EN 0x00000001 /* Enable TXD for fragments */
  978. +#define AR2315_LBM_RX_INTEN 0x00000002 /* Enable LB ints on RX ready */
  979. +#define AR2315_LBM_MBOXWR_INTEN 0x00000004 /* Enable LB ints on mbox wr */
  980. +#define AR2315_LBM_MBOXRD_INTEN 0x00000008 /* Enable LB ints on mbox rd */
  981. +#define AR2315_LMB_DESCSWAP_EN 0x00000010 /* Byte swap desc enable */
  982. +#define AR2315_LBM_TIMEOUT_M 0x00ffff80
  983. +#define AR2315_LBM_TIMEOUT_S 7
  984. +#define AR2315_LBM_PORTMUX 0x07000000
  985. +
  986. +#define AR2315_LB_RXTSOFF 0x0010
  987. +
  988. +#define AR2315_LB_TX_CHAIN_EN 0x0100
  989. +
  990. +#define AR2315_LB_TXEN_0 0x00000001
  991. +#define AR2315_LB_TXEN_1 0x00000002
  992. +#define AR2315_LB_TXEN_2 0x00000004
  993. +#define AR2315_LB_TXEN_3 0x00000008
  994. +
  995. +#define AR2315_LB_TX_CHAIN_DIS 0x0104
  996. +#define AR2315_LB_TX_DESC_PTR 0x0200
  997. +
  998. +#define AR2315_LB_RX_CHAIN_EN 0x0400
  999. +
  1000. +#define AR2315_LB_RXEN 0x00000001
  1001. +
  1002. +#define AR2315_LB_RX_CHAIN_DIS 0x0404
  1003. +#define AR2315_LB_RX_DESC_PTR 0x0408
  1004. +
  1005. +#define AR2315_LB_INT_STATUS 0x0500
  1006. +
  1007. +#define AR2315_LB_INT_TX_DESC 0x00000001
  1008. +#define AR2315_LB_INT_TX_OK 0x00000002
  1009. +#define AR2315_LB_INT_TX_ERR 0x00000004
  1010. +#define AR2315_LB_INT_TX_EOF 0x00000008
  1011. +#define AR2315_LB_INT_RX_DESC 0x00000010
  1012. +#define AR2315_LB_INT_RX_OK 0x00000020
  1013. +#define AR2315_LB_INT_RX_ERR 0x00000040
  1014. +#define AR2315_LB_INT_RX_EOF 0x00000080
  1015. +#define AR2315_LB_INT_TX_TRUNC 0x00000100
  1016. +#define AR2315_LB_INT_TX_STARVE 0x00000200
  1017. +#define AR2315_LB_INT_LB_TIMEOUT 0x00000400
  1018. +#define AR2315_LB_INT_LB_ERR 0x00000800
  1019. +#define AR2315_LB_INT_MBOX_WR 0x00001000
  1020. +#define AR2315_LB_INT_MBOX_RD 0x00002000
  1021. +
  1022. +/* Bit definitions for INT MASK are the same as INT_STATUS */
  1023. +#define AR2315_LB_INT_MASK 0x0504
  1024. +
  1025. +#define AR2315_LB_INT_EN 0x0508
  1026. +#define AR2315_LB_MBOX 0x0600
  1027. +
  1028. +#endif /* __ASM_MACH_ATH25_AR2315_REGS_H */
  1029. --- /dev/null
  1030. +++ b/arch/mips/ath25/ar5312_regs.h
  1031. @@ -0,0 +1,224 @@
  1032. +/*
  1033. + * This file is subject to the terms and conditions of the GNU General Public
  1034. + * License. See the file "COPYING" in the main directory of this archive
  1035. + * for more details.
  1036. + *
  1037. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1038. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  1039. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  1040. + */
  1041. +
  1042. +#ifndef __ASM_MACH_ATH25_AR5312_REGS_H
  1043. +#define __ASM_MACH_ATH25_AR5312_REGS_H
  1044. +
  1045. +/*
  1046. + * IRQs
  1047. + */
  1048. +#define AR5312_IRQ_WLAN0 (MIPS_CPU_IRQ_BASE + 2) /* C0_CAUSE: 0x0400 */
  1049. +#define AR5312_IRQ_ENET0 (MIPS_CPU_IRQ_BASE + 3) /* C0_CAUSE: 0x0800 */
  1050. +#define AR5312_IRQ_ENET1 (MIPS_CPU_IRQ_BASE + 4) /* C0_CAUSE: 0x1000 */
  1051. +#define AR5312_IRQ_WLAN1 (MIPS_CPU_IRQ_BASE + 5) /* C0_CAUSE: 0x2000 */
  1052. +#define AR5312_IRQ_MISC (MIPS_CPU_IRQ_BASE + 6) /* C0_CAUSE: 0x4000 */
  1053. +
  1054. +/*
  1055. + * Miscellaneous interrupts, which share IP6.
  1056. + */
  1057. +#define AR5312_MISC_IRQ_TIMER 0
  1058. +#define AR5312_MISC_IRQ_AHB_PROC 1
  1059. +#define AR5312_MISC_IRQ_AHB_DMA 2
  1060. +#define AR5312_MISC_IRQ_GPIO 3
  1061. +#define AR5312_MISC_IRQ_UART0 4
  1062. +#define AR5312_MISC_IRQ_UART0_DMA 5
  1063. +#define AR5312_MISC_IRQ_WATCHDOG 6
  1064. +#define AR5312_MISC_IRQ_LOCAL 7
  1065. +#define AR5312_MISC_IRQ_SPI 8
  1066. +#define AR5312_MISC_IRQ_COUNT 9
  1067. +
  1068. +/*
  1069. + * Address Map
  1070. + *
  1071. + * The AR5312 supports 2 enet MACS, even though many reference boards only
  1072. + * actually use 1 of them (i.e. Only MAC 0 is actually connected to an enet
  1073. + * PHY or PHY switch. The AR2312 supports 1 enet MAC.
  1074. + */
  1075. +#define AR5312_WLAN0_BASE 0x18000000
  1076. +#define AR5312_ENET0_BASE 0x18100000
  1077. +#define AR5312_ENET1_BASE 0x18200000
  1078. +#define AR5312_SDRAMCTL_BASE 0x18300000
  1079. +#define AR5312_SDRAMCTL_SIZE 0x00000010
  1080. +#define AR5312_FLASHCTL_BASE 0x18400000
  1081. +#define AR5312_FLASHCTL_SIZE 0x00000010
  1082. +#define AR5312_WLAN1_BASE 0x18500000
  1083. +#define AR5312_UART0_BASE 0x1c000000 /* UART MMR */
  1084. +#define AR5312_GPIO_BASE 0x1c002000
  1085. +#define AR5312_GPIO_SIZE 0x00000010
  1086. +#define AR5312_RST_BASE 0x1c003000
  1087. +#define AR5312_RST_SIZE 0x00000100
  1088. +#define AR5312_FLASH_BASE 0x1e000000
  1089. +#define AR5312_FLASH_SIZE 0x00800000
  1090. +
  1091. +/*
  1092. + * Need these defines to determine true number of ethernet MACs
  1093. + */
  1094. +#define AR5312_AR5312_REV2 0x0052 /* AR5312 WMAC (AP31) */
  1095. +#define AR5312_AR5312_REV7 0x0057 /* AR5312 WMAC (AP30-040) */
  1096. +#define AR5312_AR2313_REV8 0x0058 /* AR2313 WMAC (AP43-030) */
  1097. +
  1098. +/* Reset/Timer Block Address Map */
  1099. +#define AR5312_TIMER 0x0000 /* countdown timer */
  1100. +#define AR5312_RELOAD 0x0004 /* timer reload value */
  1101. +#define AR5312_WDT_CTRL 0x0008 /* watchdog cntrl */
  1102. +#define AR5312_WDT_TIMER 0x000c /* watchdog timer */
  1103. +#define AR5312_ISR 0x0010 /* Intr Status Reg */
  1104. +#define AR5312_IMR 0x0014 /* Intr Mask Reg */
  1105. +#define AR5312_RESET 0x0020
  1106. +#define AR5312_CLOCKCTL1 0x0064
  1107. +#define AR5312_SCRATCH 0x006c
  1108. +#define AR5312_PROCADDR 0x0070
  1109. +#define AR5312_PROC1 0x0074
  1110. +#define AR5312_DMAADDR 0x0078
  1111. +#define AR5312_DMA1 0x007c
  1112. +#define AR5312_ENABLE 0x0080 /* interface enb */
  1113. +#define AR5312_REV 0x0090 /* revision */
  1114. +
  1115. +/* AR5312_WDT_CTRL register bit field definitions */
  1116. +#define AR5312_WDT_CTRL_IGNORE 0x00000000 /* ignore expiration */
  1117. +#define AR5312_WDT_CTRL_NMI 0x00000001
  1118. +#define AR5312_WDT_CTRL_RESET 0x00000002
  1119. +
  1120. +/* AR5312_ISR register bit field definitions */
  1121. +#define AR5312_ISR_TIMER 0x00000001
  1122. +#define AR5312_ISR_AHBPROC 0x00000002
  1123. +#define AR5312_ISR_AHBDMA 0x00000004
  1124. +#define AR5312_ISR_GPIO 0x00000008
  1125. +#define AR5312_ISR_UART0 0x00000010
  1126. +#define AR5312_ISR_UART0DMA 0x00000020
  1127. +#define AR5312_ISR_WD 0x00000040
  1128. +#define AR5312_ISR_LOCAL 0x00000080
  1129. +
  1130. +/* AR5312_RESET register bit field definitions */
  1131. +#define AR5312_RESET_SYSTEM 0x00000001 /* cold reset full system */
  1132. +#define AR5312_RESET_PROC 0x00000002 /* cold reset MIPS core */
  1133. +#define AR5312_RESET_WLAN0 0x00000004 /* cold reset WLAN MAC/BB */
  1134. +#define AR5312_RESET_EPHY0 0x00000008 /* cold reset ENET0 phy */
  1135. +#define AR5312_RESET_EPHY1 0x00000010 /* cold reset ENET1 phy */
  1136. +#define AR5312_RESET_ENET0 0x00000020 /* cold reset ENET0 MAC */
  1137. +#define AR5312_RESET_ENET1 0x00000040 /* cold reset ENET1 MAC */
  1138. +#define AR5312_RESET_UART0 0x00000100 /* cold reset UART0 */
  1139. +#define AR5312_RESET_WLAN1 0x00000200 /* cold reset WLAN MAC/BB */
  1140. +#define AR5312_RESET_APB 0x00000400 /* cold reset APB ar5312 */
  1141. +#define AR5312_RESET_WARM_PROC 0x00001000 /* warm reset MIPS core */
  1142. +#define AR5312_RESET_WARM_WLAN0_MAC 0x00002000 /* warm reset WLAN0 MAC */
  1143. +#define AR5312_RESET_WARM_WLAN0_BB 0x00004000 /* warm reset WLAN0 BB */
  1144. +#define AR5312_RESET_NMI 0x00010000 /* send an NMI to the CPU */
  1145. +#define AR5312_RESET_WARM_WLAN1_MAC 0x00020000 /* warm reset WLAN1 MAC */
  1146. +#define AR5312_RESET_WARM_WLAN1_BB 0x00040000 /* warm reset WLAN1 BB */
  1147. +#define AR5312_RESET_LOCAL_BUS 0x00080000 /* reset local bus */
  1148. +#define AR5312_RESET_WDOG 0x00100000 /* last reset was a wdt */
  1149. +
  1150. +#define AR5312_RESET_WMAC0_BITS (AR5312_RESET_WLAN0 |\
  1151. + AR5312_RESET_WARM_WLAN0_MAC |\
  1152. + AR5312_RESET_WARM_WLAN0_BB)
  1153. +
  1154. +#define AR5312_RESET_WMAC1_BITS (AR5312_RESET_WLAN1 |\
  1155. + AR5312_RESET_WARM_WLAN1_MAC |\
  1156. + AR5312_RESET_WARM_WLAN1_BB)
  1157. +
  1158. +/* AR5312_CLOCKCTL1 register bit field definitions */
  1159. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  1160. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  1161. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  1162. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  1163. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  1164. +
  1165. +/* Valid for AR5312 and AR2312 */
  1166. +#define AR5312_CLOCKCTL1_PREDIVIDE_MASK 0x00000030
  1167. +#define AR5312_CLOCKCTL1_PREDIVIDE_SHIFT 4
  1168. +#define AR5312_CLOCKCTL1_MULTIPLIER_MASK 0x00001f00
  1169. +#define AR5312_CLOCKCTL1_MULTIPLIER_SHIFT 8
  1170. +#define AR5312_CLOCKCTL1_DOUBLER_MASK 0x00010000
  1171. +
  1172. +/* Valid for AR2313 */
  1173. +#define AR2313_CLOCKCTL1_PREDIVIDE_MASK 0x00003000
  1174. +#define AR2313_CLOCKCTL1_PREDIVIDE_SHIFT 12
  1175. +#define AR2313_CLOCKCTL1_MULTIPLIER_MASK 0x001f0000
  1176. +#define AR2313_CLOCKCTL1_MULTIPLIER_SHIFT 16
  1177. +#define AR2313_CLOCKCTL1_DOUBLER_MASK 0x00000000
  1178. +
  1179. +/* AR5312_ENABLE register bit field definitions */
  1180. +#define AR5312_ENABLE_WLAN0 0x00000001
  1181. +#define AR5312_ENABLE_ENET0 0x00000002
  1182. +#define AR5312_ENABLE_ENET1 0x00000004
  1183. +#define AR5312_ENABLE_UART_AND_WLAN1_PIO 0x00000008/* UART & WLAN1 PIO */
  1184. +#define AR5312_ENABLE_WLAN1_DMA 0x00000010/* WLAN1 DMAs */
  1185. +#define AR5312_ENABLE_WLAN1 (AR5312_ENABLE_UART_AND_WLAN1_PIO |\
  1186. + AR5312_ENABLE_WLAN1_DMA)
  1187. +
  1188. +/* AR5312_REV register bit field definitions */
  1189. +#define AR5312_REV_WMAC_MAJ 0x0000f000
  1190. +#define AR5312_REV_WMAC_MAJ_S 12
  1191. +#define AR5312_REV_WMAC_MIN 0x00000f00
  1192. +#define AR5312_REV_WMAC_MIN_S 8
  1193. +#define AR5312_REV_MAJ 0x000000f0
  1194. +#define AR5312_REV_MAJ_S 4
  1195. +#define AR5312_REV_MIN 0x0000000f
  1196. +#define AR5312_REV_MIN_S 0
  1197. +#define AR5312_REV_CHIP (AR5312_REV_MAJ|AR5312_REV_MIN)
  1198. +
  1199. +/* Major revision numbers, bits 7..4 of Revision ID register */
  1200. +#define AR5312_REV_MAJ_AR5312 0x4
  1201. +#define AR5312_REV_MAJ_AR2313 0x5
  1202. +
  1203. +/* Minor revision numbers, bits 3..0 of Revision ID register */
  1204. +#define AR5312_REV_MIN_DUAL 0x0 /* Dual WLAN version */
  1205. +#define AR5312_REV_MIN_SINGLE 0x1 /* Single WLAN version */
  1206. +
  1207. +/*
  1208. + * ARM Flash Controller -- 3 flash banks with either x8 or x16 devices
  1209. + */
  1210. +#define AR5312_FLASHCTL0 0x0000
  1211. +#define AR5312_FLASHCTL1 0x0004
  1212. +#define AR5312_FLASHCTL2 0x0008
  1213. +
  1214. +/* AR5312_FLASHCTL register bit field definitions */
  1215. +#define AR5312_FLASHCTL_IDCY 0x0000000f /* Idle cycle turnaround time */
  1216. +#define AR5312_FLASHCTL_IDCY_S 0
  1217. +#define AR5312_FLASHCTL_WST1 0x000003e0 /* Wait state 1 */
  1218. +#define AR5312_FLASHCTL_WST1_S 5
  1219. +#define AR5312_FLASHCTL_RBLE 0x00000400 /* Read byte lane enable */
  1220. +#define AR5312_FLASHCTL_WST2 0x0000f800 /* Wait state 2 */
  1221. +#define AR5312_FLASHCTL_WST2_S 11
  1222. +#define AR5312_FLASHCTL_AC 0x00070000 /* Flash addr check (added) */
  1223. +#define AR5312_FLASHCTL_AC_S 16
  1224. +#define AR5312_FLASHCTL_AC_128K 0x00000000
  1225. +#define AR5312_FLASHCTL_AC_256K 0x00010000
  1226. +#define AR5312_FLASHCTL_AC_512K 0x00020000
  1227. +#define AR5312_FLASHCTL_AC_1M 0x00030000
  1228. +#define AR5312_FLASHCTL_AC_2M 0x00040000
  1229. +#define AR5312_FLASHCTL_AC_4M 0x00050000
  1230. +#define AR5312_FLASHCTL_AC_8M 0x00060000
  1231. +#define AR5312_FLASHCTL_AC_RES 0x00070000 /* 16MB is not supported */
  1232. +#define AR5312_FLASHCTL_E 0x00080000 /* Flash bank enable (added) */
  1233. +#define AR5312_FLASHCTL_BUSERR 0x01000000 /* Bus transfer error flag */
  1234. +#define AR5312_FLASHCTL_WPERR 0x02000000 /* Write protect error flag */
  1235. +#define AR5312_FLASHCTL_WP 0x04000000 /* Write protect */
  1236. +#define AR5312_FLASHCTL_BM 0x08000000 /* Burst mode */
  1237. +#define AR5312_FLASHCTL_MW 0x30000000 /* Mem width */
  1238. +#define AR5312_FLASHCTL_MW8 0x00000000 /* Mem width x8 */
  1239. +#define AR5312_FLASHCTL_MW16 0x10000000 /* Mem width x16 */
  1240. +#define AR5312_FLASHCTL_MW32 0x20000000 /* Mem width x32 (not supp) */
  1241. +#define AR5312_FLASHCTL_ATNR 0x00000000 /* Access == no retry */
  1242. +#define AR5312_FLASHCTL_ATR 0x80000000 /* Access == retry every */
  1243. +#define AR5312_FLASHCTL_ATR4 0xc0000000 /* Access == retry every 4 */
  1244. +
  1245. +/*
  1246. + * ARM SDRAM Controller -- just enough to determine memory size
  1247. + */
  1248. +#define AR5312_MEM_CFG1 0x0004
  1249. +
  1250. +#define AR5312_MEM_CFG1_AC0_M 0x00000700 /* bank 0: SDRAM addr check */
  1251. +#define AR5312_MEM_CFG1_AC0_S 8
  1252. +#define AR5312_MEM_CFG1_AC1_M 0x00007000 /* bank 1: SDRAM addr check */
  1253. +#define AR5312_MEM_CFG1_AC1_S 12
  1254. +
  1255. +#endif /* __ASM_MACH_ATH25_AR5312_REGS_H */
  1256. --- /dev/null
  1257. +++ b/arch/mips/ath25/ar5312.c
  1258. @@ -0,0 +1,393 @@
  1259. +/*
  1260. + * This file is subject to the terms and conditions of the GNU General Public
  1261. + * License. See the file "COPYING" in the main directory of this archive
  1262. + * for more details.
  1263. + *
  1264. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1265. + * Copyright (C) 2006 FON Technology, SL.
  1266. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  1267. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  1268. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  1269. + */
  1270. +
  1271. +/*
  1272. + * Platform devices for Atheros AR5312 SoCs
  1273. + */
  1274. +
  1275. +#include <linux/init.h>
  1276. +#include <linux/kernel.h>
  1277. +#include <linux/bitops.h>
  1278. +#include <linux/irqdomain.h>
  1279. +#include <linux/interrupt.h>
  1280. +#include <linux/platform_device.h>
  1281. +#include <linux/mtd/physmap.h>
  1282. +#include <linux/reboot.h>
  1283. +#include <asm/bootinfo.h>
  1284. +#include <asm/reboot.h>
  1285. +#include <asm/time.h>
  1286. +
  1287. +#include <ath25_platform.h>
  1288. +
  1289. +#include "devices.h"
  1290. +#include "ar5312.h"
  1291. +#include "ar5312_regs.h"
  1292. +
  1293. +static void __iomem *ar5312_rst_base;
  1294. +static struct irq_domain *ar5312_misc_irq_domain;
  1295. +
  1296. +static inline u32 ar5312_rst_reg_read(u32 reg)
  1297. +{
  1298. + return __raw_readl(ar5312_rst_base + reg);
  1299. +}
  1300. +
  1301. +static inline void ar5312_rst_reg_write(u32 reg, u32 val)
  1302. +{
  1303. + __raw_writel(val, ar5312_rst_base + reg);
  1304. +}
  1305. +
  1306. +static inline void ar5312_rst_reg_mask(u32 reg, u32 mask, u32 val)
  1307. +{
  1308. + u32 ret = ar5312_rst_reg_read(reg);
  1309. +
  1310. + ret &= ~mask;
  1311. + ret |= val;
  1312. + ar5312_rst_reg_write(reg, ret);
  1313. +}
  1314. +
  1315. +static irqreturn_t ar5312_ahb_err_handler(int cpl, void *dev_id)
  1316. +{
  1317. + u32 proc1 = ar5312_rst_reg_read(AR5312_PROC1);
  1318. + u32 proc_addr = ar5312_rst_reg_read(AR5312_PROCADDR); /* clears error */
  1319. + u32 dma1 = ar5312_rst_reg_read(AR5312_DMA1);
  1320. + u32 dma_addr = ar5312_rst_reg_read(AR5312_DMAADDR); /* clears error */
  1321. +
  1322. + pr_emerg("AHB interrupt: PROCADDR=0x%8.8x PROC1=0x%8.8x DMAADDR=0x%8.8x DMA1=0x%8.8x\n",
  1323. + proc_addr, proc1, dma_addr, dma1);
  1324. +
  1325. + machine_restart("AHB error"); /* Catastrophic failure */
  1326. + return IRQ_HANDLED;
  1327. +}
  1328. +
  1329. +static struct irqaction ar5312_ahb_err_interrupt = {
  1330. + .handler = ar5312_ahb_err_handler,
  1331. + .name = "ar5312-ahb-error",
  1332. +};
  1333. +
  1334. +static void ar5312_misc_irq_handler(unsigned irq, struct irq_desc *desc)
  1335. +{
  1336. + u32 pending = ar5312_rst_reg_read(AR5312_ISR) &
  1337. + ar5312_rst_reg_read(AR5312_IMR);
  1338. + unsigned nr, misc_irq = 0;
  1339. +
  1340. + if (pending) {
  1341. + struct irq_domain *domain = irq_get_handler_data(irq);
  1342. +
  1343. + nr = __ffs(pending);
  1344. + misc_irq = irq_find_mapping(domain, nr);
  1345. + }
  1346. +
  1347. + if (misc_irq) {
  1348. + generic_handle_irq(misc_irq);
  1349. + if (nr == AR5312_MISC_IRQ_TIMER)
  1350. + ar5312_rst_reg_read(AR5312_TIMER);
  1351. + } else {
  1352. + spurious_interrupt();
  1353. + }
  1354. +}
  1355. +
  1356. +/* Enable the specified AR5312_MISC_IRQ interrupt */
  1357. +static void ar5312_misc_irq_unmask(struct irq_data *d)
  1358. +{
  1359. + ar5312_rst_reg_mask(AR5312_IMR, 0, BIT(d->hwirq));
  1360. +}
  1361. +
  1362. +/* Disable the specified AR5312_MISC_IRQ interrupt */
  1363. +static void ar5312_misc_irq_mask(struct irq_data *d)
  1364. +{
  1365. + ar5312_rst_reg_mask(AR5312_IMR, BIT(d->hwirq), 0);
  1366. + ar5312_rst_reg_read(AR5312_IMR); /* flush write buffer */
  1367. +}
  1368. +
  1369. +static struct irq_chip ar5312_misc_irq_chip = {
  1370. + .name = "ar5312-misc",
  1371. + .irq_unmask = ar5312_misc_irq_unmask,
  1372. + .irq_mask = ar5312_misc_irq_mask,
  1373. +};
  1374. +
  1375. +static int ar5312_misc_irq_map(struct irq_domain *d, unsigned irq,
  1376. + irq_hw_number_t hw)
  1377. +{
  1378. + irq_set_chip_and_handler(irq, &ar5312_misc_irq_chip, handle_level_irq);
  1379. + return 0;
  1380. +}
  1381. +
  1382. +static struct irq_domain_ops ar5312_misc_irq_domain_ops = {
  1383. + .map = ar5312_misc_irq_map,
  1384. +};
  1385. +
  1386. +static void ar5312_irq_dispatch(void)
  1387. +{
  1388. + u32 pending = read_c0_status() & read_c0_cause();
  1389. +
  1390. + if (pending & CAUSEF_IP2)
  1391. + do_IRQ(AR5312_IRQ_WLAN0);
  1392. + else if (pending & CAUSEF_IP5)
  1393. + do_IRQ(AR5312_IRQ_WLAN1);
  1394. + else if (pending & CAUSEF_IP6)
  1395. + do_IRQ(AR5312_IRQ_MISC);
  1396. + else if (pending & CAUSEF_IP7)
  1397. + do_IRQ(ATH25_IRQ_CPU_CLOCK);
  1398. + else
  1399. + spurious_interrupt();
  1400. +}
  1401. +
  1402. +void __init ar5312_arch_init_irq(void)
  1403. +{
  1404. + struct irq_domain *domain;
  1405. + unsigned irq;
  1406. +
  1407. + ath25_irq_dispatch = ar5312_irq_dispatch;
  1408. +
  1409. + domain = irq_domain_add_linear(NULL, AR5312_MISC_IRQ_COUNT,
  1410. + &ar5312_misc_irq_domain_ops, NULL);
  1411. + if (!domain)
  1412. + panic("Failed to add IRQ domain");
  1413. +
  1414. + irq = irq_create_mapping(domain, AR5312_MISC_IRQ_AHB_PROC);
  1415. + setup_irq(irq, &ar5312_ahb_err_interrupt);
  1416. +
  1417. + irq_set_chained_handler(AR5312_IRQ_MISC, ar5312_misc_irq_handler);
  1418. + irq_set_handler_data(AR5312_IRQ_MISC, domain);
  1419. +
  1420. + ar5312_misc_irq_domain = domain;
  1421. +}
  1422. +
  1423. +static struct physmap_flash_data ar5312_flash_data = {
  1424. + .width = 2,
  1425. +};
  1426. +
  1427. +static struct resource ar5312_flash_resource = {
  1428. + .start = AR5312_FLASH_BASE,
  1429. + .end = AR5312_FLASH_BASE + AR5312_FLASH_SIZE - 1,
  1430. + .flags = IORESOURCE_MEM,
  1431. +};
  1432. +
  1433. +static struct platform_device ar5312_physmap_flash = {
  1434. + .name = "physmap-flash",
  1435. + .id = 0,
  1436. + .dev.platform_data = &ar5312_flash_data,
  1437. + .resource = &ar5312_flash_resource,
  1438. + .num_resources = 1,
  1439. +};
  1440. +
  1441. +static void __init ar5312_flash_init(void)
  1442. +{
  1443. + void __iomem *flashctl_base;
  1444. + u32 ctl;
  1445. +
  1446. + flashctl_base = ioremap_nocache(AR5312_FLASHCTL_BASE,
  1447. + AR5312_FLASHCTL_SIZE);
  1448. +
  1449. + ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL0);
  1450. + ctl &= AR5312_FLASHCTL_MW;
  1451. +
  1452. + /* fixup flash width */
  1453. + switch (ctl) {
  1454. + case AR5312_FLASHCTL_MW16:
  1455. + ar5312_flash_data.width = 2;
  1456. + break;
  1457. + case AR5312_FLASHCTL_MW8:
  1458. + default:
  1459. + ar5312_flash_data.width = 1;
  1460. + break;
  1461. + }
  1462. +
  1463. + /*
  1464. + * Configure flash bank 0.
  1465. + * Assume 8M window size. Flash will be aliased if it's smaller
  1466. + */
  1467. + ctl |= AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC_8M | AR5312_FLASHCTL_RBLE;
  1468. + ctl |= 0x01 << AR5312_FLASHCTL_IDCY_S;
  1469. + ctl |= 0x07 << AR5312_FLASHCTL_WST1_S;
  1470. + ctl |= 0x07 << AR5312_FLASHCTL_WST2_S;
  1471. + __raw_writel(ctl, flashctl_base + AR5312_FLASHCTL0);
  1472. +
  1473. + /* Disable other flash banks */
  1474. + ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL1);
  1475. + ctl &= ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
  1476. + __raw_writel(ctl, flashctl_base + AR5312_FLASHCTL1);
  1477. + ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL2);
  1478. + ctl &= ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
  1479. + __raw_writel(ctl, flashctl_base + AR5312_FLASHCTL2);
  1480. +
  1481. + iounmap(flashctl_base);
  1482. +}
  1483. +
  1484. +void __init ar5312_init_devices(void)
  1485. +{
  1486. + struct ath25_boarddata *config;
  1487. +
  1488. + ar5312_flash_init();
  1489. +
  1490. + /* Locate board/radio config data */
  1491. + ath25_find_config(AR5312_FLASH_BASE, AR5312_FLASH_SIZE);
  1492. + config = ath25_board.config;
  1493. +
  1494. + /* AR2313 has CPU minor rev. 10 */
  1495. + if ((current_cpu_data.processor_id & 0xff) == 0x0a)
  1496. + ath25_soc = ATH25_SOC_AR2313;
  1497. +
  1498. + /* AR2312 shares the same Silicon ID as AR5312 */
  1499. + else if (config->flags & BD_ISCASPER)
  1500. + ath25_soc = ATH25_SOC_AR2312;
  1501. +
  1502. + /* Everything else is probably AR5312 or compatible */
  1503. + else
  1504. + ath25_soc = ATH25_SOC_AR5312;
  1505. +
  1506. + platform_device_register(&ar5312_physmap_flash);
  1507. +
  1508. + switch (ath25_soc) {
  1509. + case ATH25_SOC_AR5312:
  1510. + if (!ath25_board.radio)
  1511. + return;
  1512. +
  1513. + if (!(config->flags & BD_WLAN0))
  1514. + break;
  1515. +
  1516. + ath25_add_wmac(0, AR5312_WLAN0_BASE, AR5312_IRQ_WLAN0);
  1517. + break;
  1518. + case ATH25_SOC_AR2312:
  1519. + case ATH25_SOC_AR2313:
  1520. + if (!ath25_board.radio)
  1521. + return;
  1522. + break;
  1523. + default:
  1524. + break;
  1525. + }
  1526. +
  1527. + if (config->flags & BD_WLAN1)
  1528. + ath25_add_wmac(1, AR5312_WLAN1_BASE, AR5312_IRQ_WLAN1);
  1529. +}
  1530. +
  1531. +static void ar5312_restart(char *command)
  1532. +{
  1533. + /* reset the system */
  1534. + local_irq_disable();
  1535. + while (1)
  1536. + ar5312_rst_reg_write(AR5312_RESET, AR5312_RESET_SYSTEM);
  1537. +}
  1538. +
  1539. +/*
  1540. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  1541. + * to determine the predevisor value.
  1542. + */
  1543. +static unsigned clockctl1_predivide_table[4] __initdata = { 1, 2, 4, 5 };
  1544. +
  1545. +static unsigned __init ar5312_cpu_frequency(void)
  1546. +{
  1547. + u32 scratch, devid, clock_ctl1;
  1548. + u32 predivide_mask, multiplier_mask, doubler_mask;
  1549. + unsigned predivide_shift, multiplier_shift;
  1550. + unsigned predivide_select, predivisor, multiplier;
  1551. +
  1552. + /* Trust the bootrom's idea of cpu frequency. */
  1553. + scratch = ar5312_rst_reg_read(AR5312_SCRATCH);
  1554. + if (scratch)
  1555. + return scratch;
  1556. +
  1557. + devid = ar5312_rst_reg_read(AR5312_REV);
  1558. + devid = (devid & AR5312_REV_MAJ) >> AR5312_REV_MAJ_S;
  1559. + if (devid == AR5312_REV_MAJ_AR2313) {
  1560. + predivide_mask = AR2313_CLOCKCTL1_PREDIVIDE_MASK;
  1561. + predivide_shift = AR2313_CLOCKCTL1_PREDIVIDE_SHIFT;
  1562. + multiplier_mask = AR2313_CLOCKCTL1_MULTIPLIER_MASK;
  1563. + multiplier_shift = AR2313_CLOCKCTL1_MULTIPLIER_SHIFT;
  1564. + doubler_mask = AR2313_CLOCKCTL1_DOUBLER_MASK;
  1565. + } else { /* AR5312 and AR2312 */
  1566. + predivide_mask = AR5312_CLOCKCTL1_PREDIVIDE_MASK;
  1567. + predivide_shift = AR5312_CLOCKCTL1_PREDIVIDE_SHIFT;
  1568. + multiplier_mask = AR5312_CLOCKCTL1_MULTIPLIER_MASK;
  1569. + multiplier_shift = AR5312_CLOCKCTL1_MULTIPLIER_SHIFT;
  1570. + doubler_mask = AR5312_CLOCKCTL1_DOUBLER_MASK;
  1571. + }
  1572. +
  1573. + /*
  1574. + * Clocking is derived from a fixed 40MHz input clock.
  1575. + *
  1576. + * cpu_freq = input_clock * MULT (where MULT is PLL multiplier)
  1577. + * sys_freq = cpu_freq / 4 (used for APB clock, serial,
  1578. + * flash, Timer, Watchdog Timer)
  1579. + *
  1580. + * cnt_freq = cpu_freq / 2 (use for CPU count/compare)
  1581. + *
  1582. + * So, for example, with a PLL multiplier of 5, we have
  1583. + *
  1584. + * cpu_freq = 200MHz
  1585. + * sys_freq = 50MHz
  1586. + * cnt_freq = 100MHz
  1587. + *
  1588. + * We compute the CPU frequency, based on PLL settings.
  1589. + */
  1590. +
  1591. + clock_ctl1 = ar5312_rst_reg_read(AR5312_CLOCKCTL1);
  1592. + predivide_select = (clock_ctl1 & predivide_mask) >> predivide_shift;
  1593. + predivisor = clockctl1_predivide_table[predivide_select];
  1594. + multiplier = (clock_ctl1 & multiplier_mask) >> multiplier_shift;
  1595. +
  1596. + if (clock_ctl1 & doubler_mask)
  1597. + multiplier <<= 1;
  1598. +
  1599. + return (40000000 / predivisor) * multiplier;
  1600. +}
  1601. +
  1602. +static inline unsigned ar5312_sys_frequency(void)
  1603. +{
  1604. + return ar5312_cpu_frequency() / 4;
  1605. +}
  1606. +
  1607. +void __init ar5312_plat_time_init(void)
  1608. +{
  1609. + mips_hpt_frequency = ar5312_cpu_frequency() / 2;
  1610. +}
  1611. +
  1612. +void __init ar5312_plat_mem_setup(void)
  1613. +{
  1614. + void __iomem *sdram_base;
  1615. + u32 memsize, memcfg, bank0_ac, bank1_ac;
  1616. + u32 devid;
  1617. +
  1618. + /* Detect memory size */
  1619. + sdram_base = ioremap_nocache(AR5312_SDRAMCTL_BASE,
  1620. + AR5312_SDRAMCTL_SIZE);
  1621. + memcfg = __raw_readl(sdram_base + AR5312_MEM_CFG1);
  1622. + bank0_ac = ATH25_REG_MS(memcfg, AR5312_MEM_CFG1_AC0);
  1623. + bank1_ac = ATH25_REG_MS(memcfg, AR5312_MEM_CFG1_AC1);
  1624. + memsize = (bank0_ac ? (1 << (bank0_ac + 1)) : 0) +
  1625. + (bank1_ac ? (1 << (bank1_ac + 1)) : 0);
  1626. + memsize <<= 20;
  1627. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  1628. + iounmap(sdram_base);
  1629. +
  1630. + ar5312_rst_base = ioremap_nocache(AR5312_RST_BASE, AR5312_RST_SIZE);
  1631. +
  1632. + devid = ar5312_rst_reg_read(AR5312_REV);
  1633. + devid >>= AR5312_REV_WMAC_MIN_S;
  1634. + devid &= AR5312_REV_CHIP;
  1635. + ath25_board.devid = (u16)devid;
  1636. +
  1637. + /* Clear any lingering AHB errors */
  1638. + ar5312_rst_reg_read(AR5312_PROCADDR);
  1639. + ar5312_rst_reg_read(AR5312_DMAADDR);
  1640. + ar5312_rst_reg_write(AR5312_WDT_CTRL, AR5312_WDT_CTRL_IGNORE);
  1641. +
  1642. + _machine_restart = ar5312_restart;
  1643. +}
  1644. +
  1645. +void __init ar5312_arch_init(void)
  1646. +{
  1647. + unsigned irq = irq_create_mapping(ar5312_misc_irq_domain,
  1648. + AR5312_MISC_IRQ_UART0);
  1649. +
  1650. + ath25_serial_setup(AR5312_UART0_BASE, irq, ar5312_sys_frequency());
  1651. +}
  1652. --- /dev/null
  1653. +++ b/arch/mips/ath25/ar2315.c
  1654. @@ -0,0 +1,308 @@
  1655. +/*
  1656. + * This file is subject to the terms and conditions of the GNU General Public
  1657. + * License. See the file "COPYING" in the main directory of this archive
  1658. + * for more details.
  1659. + *
  1660. + * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
  1661. + * Copyright (C) 2006 FON Technology, SL.
  1662. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  1663. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  1664. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  1665. + */
  1666. +
  1667. +/*
  1668. + * Platform devices for Atheros AR2315 SoCs
  1669. + */
  1670. +
  1671. +#include <linux/init.h>
  1672. +#include <linux/kernel.h>
  1673. +#include <linux/bitops.h>
  1674. +#include <linux/irqdomain.h>
  1675. +#include <linux/interrupt.h>
  1676. +#include <linux/platform_device.h>
  1677. +#include <linux/reboot.h>
  1678. +#include <asm/bootinfo.h>
  1679. +#include <asm/reboot.h>
  1680. +#include <asm/time.h>
  1681. +
  1682. +#include <ath25_platform.h>
  1683. +
  1684. +#include "devices.h"
  1685. +#include "ar2315.h"
  1686. +#include "ar2315_regs.h"
  1687. +
  1688. +static void __iomem *ar2315_rst_base;
  1689. +static struct irq_domain *ar2315_misc_irq_domain;
  1690. +
  1691. +static inline u32 ar2315_rst_reg_read(u32 reg)
  1692. +{
  1693. + return __raw_readl(ar2315_rst_base + reg);
  1694. +}
  1695. +
  1696. +static inline void ar2315_rst_reg_write(u32 reg, u32 val)
  1697. +{
  1698. + __raw_writel(val, ar2315_rst_base + reg);
  1699. +}
  1700. +
  1701. +static inline void ar2315_rst_reg_mask(u32 reg, u32 mask, u32 val)
  1702. +{
  1703. + u32 ret = ar2315_rst_reg_read(reg);
  1704. +
  1705. + ret &= ~mask;
  1706. + ret |= val;
  1707. + ar2315_rst_reg_write(reg, ret);
  1708. +}
  1709. +
  1710. +static irqreturn_t ar2315_ahb_err_handler(int cpl, void *dev_id)
  1711. +{
  1712. + ar2315_rst_reg_write(AR2315_AHB_ERR0, AR2315_AHB_ERROR_DET);
  1713. + ar2315_rst_reg_read(AR2315_AHB_ERR1);
  1714. +
  1715. + pr_emerg("AHB fatal error\n");
  1716. + machine_restart("AHB error"); /* Catastrophic failure */
  1717. +
  1718. + return IRQ_HANDLED;
  1719. +}
  1720. +
  1721. +static struct irqaction ar2315_ahb_err_interrupt = {
  1722. + .handler = ar2315_ahb_err_handler,
  1723. + .name = "ar2315-ahb-error",
  1724. +};
  1725. +
  1726. +static void ar2315_misc_irq_handler(unsigned irq, struct irq_desc *desc)
  1727. +{
  1728. + u32 pending = ar2315_rst_reg_read(AR2315_ISR) &
  1729. + ar2315_rst_reg_read(AR2315_IMR);
  1730. + unsigned nr, misc_irq = 0;
  1731. +
  1732. + if (pending) {
  1733. + struct irq_domain *domain = irq_get_handler_data(irq);
  1734. +
  1735. + nr = __ffs(pending);
  1736. + misc_irq = irq_find_mapping(domain, nr);
  1737. + }
  1738. +
  1739. + if (misc_irq) {
  1740. + if (nr == AR2315_MISC_IRQ_GPIO)
  1741. + ar2315_rst_reg_write(AR2315_ISR, AR2315_ISR_GPIO);
  1742. + else if (nr == AR2315_MISC_IRQ_WATCHDOG)
  1743. + ar2315_rst_reg_write(AR2315_ISR, AR2315_ISR_WD);
  1744. + generic_handle_irq(misc_irq);
  1745. + } else {
  1746. + spurious_interrupt();
  1747. + }
  1748. +}
  1749. +
  1750. +static void ar2315_misc_irq_unmask(struct irq_data *d)
  1751. +{
  1752. + ar2315_rst_reg_mask(AR2315_IMR, 0, BIT(d->hwirq));
  1753. +}
  1754. +
  1755. +static void ar2315_misc_irq_mask(struct irq_data *d)
  1756. +{
  1757. + ar2315_rst_reg_mask(AR2315_IMR, BIT(d->hwirq), 0);
  1758. +}
  1759. +
  1760. +static struct irq_chip ar2315_misc_irq_chip = {
  1761. + .name = "ar2315-misc",
  1762. + .irq_unmask = ar2315_misc_irq_unmask,
  1763. + .irq_mask = ar2315_misc_irq_mask,
  1764. +};
  1765. +
  1766. +static int ar2315_misc_irq_map(struct irq_domain *d, unsigned irq,
  1767. + irq_hw_number_t hw)
  1768. +{
  1769. + irq_set_chip_and_handler(irq, &ar2315_misc_irq_chip, handle_level_irq);
  1770. + return 0;
  1771. +}
  1772. +
  1773. +static struct irq_domain_ops ar2315_misc_irq_domain_ops = {
  1774. + .map = ar2315_misc_irq_map,
  1775. +};
  1776. +
  1777. +/*
  1778. + * Called when an interrupt is received, this function
  1779. + * determines exactly which interrupt it was, and it
  1780. + * invokes the appropriate handler.
  1781. + *
  1782. + * Implicitly, we also define interrupt priority by
  1783. + * choosing which to dispatch first.
  1784. + */
  1785. +static void ar2315_irq_dispatch(void)
  1786. +{
  1787. + u32 pending = read_c0_status() & read_c0_cause();
  1788. +
  1789. + if (pending & CAUSEF_IP3)
  1790. + do_IRQ(AR2315_IRQ_WLAN0);
  1791. + else if (pending & CAUSEF_IP2)
  1792. + do_IRQ(AR2315_IRQ_MISC);
  1793. + else if (pending & CAUSEF_IP7)
  1794. + do_IRQ(ATH25_IRQ_CPU_CLOCK);
  1795. + else
  1796. + spurious_interrupt();
  1797. +}
  1798. +
  1799. +void __init ar2315_arch_init_irq(void)
  1800. +{
  1801. + struct irq_domain *domain;
  1802. + unsigned irq;
  1803. +
  1804. + ath25_irq_dispatch = ar2315_irq_dispatch;
  1805. +
  1806. + domain = irq_domain_add_linear(NULL, AR2315_MISC_IRQ_COUNT,
  1807. + &ar2315_misc_irq_domain_ops, NULL);
  1808. + if (!domain)
  1809. + panic("Failed to add IRQ domain");
  1810. +
  1811. + irq = irq_create_mapping(domain, AR2315_MISC_IRQ_AHB);
  1812. + setup_irq(irq, &ar2315_ahb_err_interrupt);
  1813. +
  1814. + irq_set_chained_handler(AR2315_IRQ_MISC, ar2315_misc_irq_handler);
  1815. + irq_set_handler_data(AR2315_IRQ_MISC, domain);
  1816. +
  1817. + ar2315_misc_irq_domain = domain;
  1818. +}
  1819. +
  1820. +void __init ar2315_init_devices(void)
  1821. +{
  1822. + /* Find board configuration */
  1823. + ath25_find_config(AR2315_SPI_READ_BASE, AR2315_SPI_READ_SIZE);
  1824. +
  1825. + ath25_add_wmac(0, AR2315_WLAN0_BASE, AR2315_IRQ_WLAN0);
  1826. +}
  1827. +
  1828. +static void ar2315_restart(char *command)
  1829. +{
  1830. + void (*mips_reset_vec)(void) = (void *)0xbfc00000;
  1831. +
  1832. + local_irq_disable();
  1833. +
  1834. + /* try reset the system via reset control */
  1835. + ar2315_rst_reg_write(AR2315_COLD_RESET, AR2317_RESET_SYSTEM);
  1836. +
  1837. + /* Cold reset does not work on the AR2315/6, use the GPIO reset bits
  1838. + * a workaround. Give it some time to attempt a gpio based hardware
  1839. + * reset (atheros reference design workaround) */
  1840. +
  1841. + /* TODO: implement the GPIO reset workaround */
  1842. +
  1843. + /* Some boards (e.g. Senao EOC-2610) don't implement the reset logic
  1844. + * workaround. Attempt to jump to the mips reset location -
  1845. + * the boot loader itself might be able to recover the system */
  1846. + mips_reset_vec();
  1847. +}
  1848. +
  1849. +/*
  1850. + * This table is indexed by bits 5..4 of the CLOCKCTL1 register
  1851. + * to determine the predevisor value.
  1852. + */
  1853. +static int clockctl1_predivide_table[4] __initdata = { 1, 2, 4, 5 };
  1854. +static int pllc_divide_table[5] __initdata = { 2, 3, 4, 6, 3 };
  1855. +
  1856. +static unsigned __init ar2315_sys_clk(u32 clock_ctl)
  1857. +{
  1858. + unsigned int pllc_ctrl, cpu_div;
  1859. + unsigned int pllc_out, refdiv, fdiv, divby2;
  1860. + unsigned int clk_div;
  1861. +
  1862. + pllc_ctrl = ar2315_rst_reg_read(AR2315_PLLC_CTL);
  1863. + refdiv = ATH25_REG_MS(pllc_ctrl, AR2315_PLLC_REF_DIV);
  1864. + refdiv = clockctl1_predivide_table[refdiv];
  1865. + fdiv = ATH25_REG_MS(pllc_ctrl, AR2315_PLLC_FDBACK_DIV);
  1866. + divby2 = ATH25_REG_MS(pllc_ctrl, AR2315_PLLC_ADD_FDBACK_DIV) + 1;
  1867. + pllc_out = (40000000 / refdiv) * (2 * divby2) * fdiv;
  1868. +
  1869. + /* clkm input selected */
  1870. + switch (clock_ctl & AR2315_CPUCLK_CLK_SEL_M) {
  1871. + case 0:
  1872. + case 1:
  1873. + clk_div = ATH25_REG_MS(pllc_ctrl, AR2315_PLLC_CLKM_DIV);
  1874. + clk_div = pllc_divide_table[clk_div];
  1875. + break;
  1876. + case 2:
  1877. + clk_div = ATH25_REG_MS(pllc_ctrl, AR2315_PLLC_CLKC_DIV);
  1878. + clk_div = pllc_divide_table[clk_div];
  1879. + break;
  1880. + default:
  1881. + pllc_out = 40000000;
  1882. + clk_div = 1;
  1883. + break;
  1884. + }
  1885. +
  1886. + cpu_div = ATH25_REG_MS(clock_ctl, AR2315_CPUCLK_CLK_DIV);
  1887. + cpu_div = cpu_div * 2 ?: 1;
  1888. +
  1889. + return pllc_out / (clk_div * cpu_div);
  1890. +}
  1891. +
  1892. +static inline unsigned ar2315_cpu_frequency(void)
  1893. +{
  1894. + return ar2315_sys_clk(ar2315_rst_reg_read(AR2315_CPUCLK));
  1895. +}
  1896. +
  1897. +static inline unsigned ar2315_apb_frequency(void)
  1898. +{
  1899. + return ar2315_sys_clk(ar2315_rst_reg_read(AR2315_AMBACLK));
  1900. +}
  1901. +
  1902. +void __init ar2315_plat_time_init(void)
  1903. +{
  1904. + mips_hpt_frequency = ar2315_cpu_frequency() / 2;
  1905. +}
  1906. +
  1907. +void __init ar2315_plat_mem_setup(void)
  1908. +{
  1909. + void __iomem *sdram_base;
  1910. + u32 memsize, memcfg;
  1911. + u32 devid;
  1912. + u32 config;
  1913. +
  1914. + /* Detect memory size */
  1915. + sdram_base = ioremap_nocache(AR2315_SDRAMCTL_BASE,
  1916. + AR2315_SDRAMCTL_SIZE);
  1917. + memcfg = __raw_readl(sdram_base + AR2315_MEM_CFG);
  1918. + memsize = 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_DATA_WIDTH);
  1919. + memsize <<= 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_COL_WIDTH);
  1920. + memsize <<= 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_ROW_WIDTH);
  1921. + memsize <<= 3;
  1922. + add_memory_region(0, memsize, BOOT_MEM_RAM);
  1923. + iounmap(sdram_base);
  1924. +
  1925. + ar2315_rst_base = ioremap_nocache(AR2315_RST_BASE, AR2315_RST_SIZE);
  1926. +
  1927. + /* Detect the hardware based on the device ID */
  1928. + devid = ar2315_rst_reg_read(AR2315_SREV) & AR2315_REV_CHIP;
  1929. + switch (devid) {
  1930. + case 0x91: /* Need to check */
  1931. + ath25_soc = ATH25_SOC_AR2318;
  1932. + break;
  1933. + case 0x90:
  1934. + ath25_soc = ATH25_SOC_AR2317;
  1935. + break;
  1936. + case 0x87:
  1937. + ath25_soc = ATH25_SOC_AR2316;
  1938. + break;
  1939. + case 0x86:
  1940. + default:
  1941. + ath25_soc = ATH25_SOC_AR2315;
  1942. + break;
  1943. + }
  1944. + ath25_board.devid = devid;
  1945. +
  1946. + /* Clear any lingering AHB errors */
  1947. + config = read_c0_config();
  1948. + write_c0_config(config & ~0x3);
  1949. + ar2315_rst_reg_write(AR2315_AHB_ERR0, AR2315_AHB_ERROR_DET);
  1950. + ar2315_rst_reg_read(AR2315_AHB_ERR1);
  1951. + ar2315_rst_reg_write(AR2315_WDT_CTRL, AR2315_WDT_CTRL_IGNORE);
  1952. +
  1953. + _machine_restart = ar2315_restart;
  1954. +}
  1955. +
  1956. +void __init ar2315_arch_init(void)
  1957. +{
  1958. + unsigned irq = irq_create_mapping(ar2315_misc_irq_domain,
  1959. + AR2315_MISC_IRQ_UART0);
  1960. +
  1961. + ath25_serial_setup(AR2315_UART0_BASE, irq, ar2315_apb_frequency());
  1962. +}
  1963. --- /dev/null
  1964. +++ b/arch/mips/ath25/ar2315.h
  1965. @@ -0,0 +1,22 @@
  1966. +#ifndef __AR2315_H
  1967. +#define __AR2315_H
  1968. +
  1969. +#ifdef CONFIG_SOC_AR2315
  1970. +
  1971. +void ar2315_arch_init_irq(void);
  1972. +void ar2315_init_devices(void);
  1973. +void ar2315_plat_time_init(void);
  1974. +void ar2315_plat_mem_setup(void);
  1975. +void ar2315_arch_init(void);
  1976. +
  1977. +#else
  1978. +
  1979. +static inline void ar2315_arch_init_irq(void) {}
  1980. +static inline void ar2315_init_devices(void) {}
  1981. +static inline void ar2315_plat_time_init(void) {}
  1982. +static inline void ar2315_plat_mem_setup(void) {}
  1983. +static inline void ar2315_arch_init(void) {}
  1984. +
  1985. +#endif
  1986. +
  1987. +#endif /* __AR2315_H */
  1988. --- /dev/null
  1989. +++ b/arch/mips/ath25/ar5312.h
  1990. @@ -0,0 +1,22 @@
  1991. +#ifndef __AR5312_H
  1992. +#define __AR5312_H
  1993. +
  1994. +#ifdef CONFIG_SOC_AR5312
  1995. +
  1996. +void ar5312_arch_init_irq(void);
  1997. +void ar5312_init_devices(void);
  1998. +void ar5312_plat_time_init(void);
  1999. +void ar5312_plat_mem_setup(void);
  2000. +void ar5312_arch_init(void);
  2001. +
  2002. +#else
  2003. +
  2004. +static inline void ar5312_arch_init_irq(void) {}
  2005. +static inline void ar5312_init_devices(void) {}
  2006. +static inline void ar5312_plat_time_init(void) {}
  2007. +static inline void ar5312_plat_mem_setup(void) {}
  2008. +static inline void ar5312_arch_init(void) {}
  2009. +
  2010. +#endif
  2011. +
  2012. +#endif /* __AR5312_H */
  2013. --- /dev/null
  2014. +++ b/arch/mips/ath25/devices.h
  2015. @@ -0,0 +1,43 @@
  2016. +#ifndef __ATH25_DEVICES_H
  2017. +#define __ATH25_DEVICES_H
  2018. +
  2019. +#include <linux/cpu.h>
  2020. +
  2021. +#define ATH25_REG_MS(_val, _field) (((_val) & _field##_M) >> _field##_S)
  2022. +
  2023. +#define ATH25_IRQ_CPU_CLOCK (MIPS_CPU_IRQ_BASE + 7) /* C0_CAUSE: 0x8000 */
  2024. +
  2025. +enum ath25_soc_type {
  2026. + /* handled by ar5312.c */
  2027. + ATH25_SOC_AR2312,
  2028. + ATH25_SOC_AR2313,
  2029. + ATH25_SOC_AR5312,
  2030. +
  2031. + /* handled by ar2315.c */
  2032. + ATH25_SOC_AR2315,
  2033. + ATH25_SOC_AR2316,
  2034. + ATH25_SOC_AR2317,
  2035. + ATH25_SOC_AR2318,
  2036. +
  2037. + ATH25_SOC_UNKNOWN
  2038. +};
  2039. +
  2040. +extern enum ath25_soc_type ath25_soc;
  2041. +extern struct ar231x_board_config ath25_board;
  2042. +extern void (*ath25_irq_dispatch)(void);
  2043. +
  2044. +int ath25_find_config(phys_addr_t offset, unsigned long size);
  2045. +void ath25_serial_setup(u32 mapbase, int irq, unsigned int uartclk);
  2046. +int ath25_add_wmac(int nr, u32 base, int irq);
  2047. +
  2048. +static inline bool is_ar2315(void)
  2049. +{
  2050. + return (current_cpu_data.cputype == CPU_4KEC);
  2051. +}
  2052. +
  2053. +static inline bool is_ar5312(void)
  2054. +{
  2055. + return !is_ar2315();
  2056. +}
  2057. +
  2058. +#endif
  2059. --- /dev/null
  2060. +++ b/arch/mips/ath25/devices.c
  2061. @@ -0,0 +1,125 @@
  2062. +#include <linux/kernel.h>
  2063. +#include <linux/init.h>
  2064. +#include <linux/serial_8250.h>
  2065. +#include <linux/platform_device.h>
  2066. +#include <asm/bootinfo.h>
  2067. +
  2068. +#include <ath25_platform.h>
  2069. +#include "devices.h"
  2070. +#include "ar5312.h"
  2071. +#include "ar2315.h"
  2072. +
  2073. +struct ar231x_board_config ath25_board;
  2074. +enum ath25_soc_type ath25_soc = ATH25_SOC_UNKNOWN;
  2075. +
  2076. +static struct resource ath25_wmac0_res[] = {
  2077. + {
  2078. + .name = "wmac0_membase",
  2079. + .flags = IORESOURCE_MEM,
  2080. + },
  2081. + {
  2082. + .name = "wmac0_irq",
  2083. + .flags = IORESOURCE_IRQ,
  2084. + }
  2085. +};
  2086. +
  2087. +static struct resource ath25_wmac1_res[] = {
  2088. + {
  2089. + .name = "wmac1_membase",
  2090. + .flags = IORESOURCE_MEM,
  2091. + },
  2092. + {
  2093. + .name = "wmac1_irq",
  2094. + .flags = IORESOURCE_IRQ,
  2095. + }
  2096. +};
  2097. +
  2098. +static struct platform_device ath25_wmac[] = {
  2099. + {
  2100. + .id = 0,
  2101. + .name = "ar231x-wmac",
  2102. + .resource = ath25_wmac0_res,
  2103. + .num_resources = ARRAY_SIZE(ath25_wmac0_res),
  2104. + .dev.platform_data = &ath25_board,
  2105. + },
  2106. + {
  2107. + .id = 1,
  2108. + .name = "ar231x-wmac",
  2109. + .resource = ath25_wmac1_res,
  2110. + .num_resources = ARRAY_SIZE(ath25_wmac1_res),
  2111. + .dev.platform_data = &ath25_board,
  2112. + },
  2113. +};
  2114. +
  2115. +static const char * const soc_type_strings[] = {
  2116. + [ATH25_SOC_AR5312] = "Atheros AR5312",
  2117. + [ATH25_SOC_AR2312] = "Atheros AR2312",
  2118. + [ATH25_SOC_AR2313] = "Atheros AR2313",
  2119. + [ATH25_SOC_AR2315] = "Atheros AR2315",
  2120. + [ATH25_SOC_AR2316] = "Atheros AR2316",
  2121. + [ATH25_SOC_AR2317] = "Atheros AR2317",
  2122. + [ATH25_SOC_AR2318] = "Atheros AR2318",
  2123. + [ATH25_SOC_UNKNOWN] = "Atheros (unknown)",
  2124. +};
  2125. +
  2126. +const char *get_system_type(void)
  2127. +{
  2128. + if ((ath25_soc >= ARRAY_SIZE(soc_type_strings)) ||
  2129. + !soc_type_strings[ath25_soc])
  2130. + return soc_type_strings[ATH25_SOC_UNKNOWN];
  2131. + return soc_type_strings[ath25_soc];
  2132. +}
  2133. +
  2134. +void __init ath25_serial_setup(u32 mapbase, int irq, unsigned int uartclk)
  2135. +{
  2136. + struct uart_port s;
  2137. +
  2138. + memset(&s, 0, sizeof(s));
  2139. +
  2140. + s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP;
  2141. + s.iotype = UPIO_MEM32;
  2142. + s.irq = irq;
  2143. + s.regshift = 2;
  2144. + s.mapbase = mapbase;
  2145. + s.uartclk = uartclk;
  2146. +
  2147. + early_serial_setup(&s);
  2148. +}
  2149. +
  2150. +int __init ath25_add_wmac(int nr, u32 base, int irq)
  2151. +{
  2152. + struct resource *res;
  2153. +
  2154. + ath25_wmac[nr].dev.platform_data = &ath25_board;
  2155. + res = &ath25_wmac[nr].resource[0];
  2156. + res->start = base;
  2157. + res->end = base + 0x10000 - 1;
  2158. + res++;
  2159. + res->start = irq;
  2160. + res->end = irq;
  2161. + return platform_device_register(&ath25_wmac[nr]);
  2162. +}
  2163. +
  2164. +static int __init ath25_register_devices(void)
  2165. +{
  2166. + if (is_ar5312())
  2167. + ar5312_init_devices();
  2168. + else
  2169. + ar2315_init_devices();
  2170. +
  2171. + return 0;
  2172. +}
  2173. +
  2174. +device_initcall(ath25_register_devices);
  2175. +
  2176. +static int __init ath25_arch_init(void)
  2177. +{
  2178. + if (is_ar5312())
  2179. + ar5312_arch_init();
  2180. + else
  2181. + ar2315_arch_init();
  2182. +
  2183. + return 0;
  2184. +}
  2185. +
  2186. +arch_initcall(ath25_arch_init);