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