2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2003 Atheros Communications, Inc., All Rights Reserved.
7 * Copyright (C) 2006 FON Technology, SL.
8 * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
9 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
13 * Platform devices for Atheros SoCs
16 #include <linux/autoconf.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/platform_device.h>
22 #include <linux/kernel.h>
23 #include <linux/reboot.h>
24 #include <asm/bootinfo.h>
25 #include <asm/reboot.h>
31 static struct resource ar5315_eth_res
[] = {
33 .name
= "eth_membase",
34 .flags
= IORESOURCE_MEM
,
35 .start
= AR5315_ENET0
,
36 .end
= AR5315_ENET0
+ 0x2000,
40 .flags
= IORESOURCE_IRQ
,
41 .start
= AR5315_IRQ_ENET0_INTRS
,
42 .end
= AR5315_IRQ_ENET0_INTRS
,
46 static struct ar531x_eth ar5315_eth_data
= {
49 .reset_base
= AR5315_RESET
,
50 .reset_mac
= AR5315_RESET_ENET0
,
51 .reset_phy
= AR5315_RESET_EPHY0
,
54 static struct platform_device ar5315_eth
= {
57 .dev
.platform_data
= &ar5315_eth_data
,
58 .resource
= ar5315_eth_res
,
59 .num_resources
= ARRAY_SIZE(ar5315_eth_res
)
62 static struct platform_device ar5315_wmac
= {
64 .name
= "ar531x-wmac",
65 /* FIXME: add resources */
68 static struct resource ar5315_spiflash_res
[] = {
71 .flags
= IORESOURCE_MEM
,
72 .start
= KSEG1ADDR(AR5315_SPI_READ
),
73 .end
= KSEG1ADDR(AR5315_SPI_READ
) + 0x800000,
77 .flags
= IORESOURCE_MEM
,
83 static struct platform_device ar5315_spiflash
= {
86 .resource
= ar5315_spiflash_res
,
87 .num_resources
= ARRAY_SIZE(ar5315_spiflash_res
)
90 static __initdata
struct platform_device
*ar5315_devs
[4];
94 static void *flash_regs
;
96 static inline __u32
spiflash_regread32(int reg
)
98 volatile __u32
*data
= (__u32
*)(flash_regs
+ reg
);
103 static inline void spiflash_regwrite32(int reg
, __u32 data
)
105 volatile __u32
*addr
= (__u32
*)(flash_regs
+ reg
);
110 #define SPI_FLASH_CTL 0x00
111 #define SPI_FLASH_OPCODE 0x04
112 #define SPI_FLASH_DATA 0x08
114 static __u8
spiflash_probe(void)
119 reg
= spiflash_regread32(SPI_FLASH_CTL
);
120 } while (reg
& SPI_CTL_BUSY
);
122 spiflash_regwrite32(SPI_FLASH_OPCODE
, 0xab);
124 reg
= (reg
& ~SPI_CTL_TX_RX_CNT_MASK
) | 4 |
125 (1 << 4) | SPI_CTL_START
;
127 spiflash_regwrite32(SPI_FLASH_CTL
, reg
);
130 reg
= spiflash_regread32(SPI_FLASH_CTL
);
131 } while (reg
& SPI_CTL_BUSY
);
133 reg
= (__u32
) spiflash_regread32(SPI_FLASH_DATA
);
140 #define STM_8MBIT_SIGNATURE 0x13
141 #define STM_16MBIT_SIGNATURE 0x14
142 #define STM_32MBIT_SIGNATURE 0x15
143 #define STM_64MBIT_SIGNATURE 0x16
146 static char __init
*ar5315_flash_limit(void)
151 /* probe the flash chip size */
152 flash_regs
= ioremap_nocache(ar5315_spiflash_res
[1].start
, ar5315_spiflash_res
[1].end
- ar5315_spiflash_res
[1].start
);
153 sig
= spiflash_probe();
157 case STM_8MBIT_SIGNATURE
:
158 flash_size
= 0x00100000;
160 case STM_16MBIT_SIGNATURE
:
161 flash_size
= 0x00200000;
163 case STM_32MBIT_SIGNATURE
:
164 flash_size
= 0x00400000;
166 case STM_64MBIT_SIGNATURE
:
167 flash_size
= 0x00800000;
171 ar5315_spiflash_res
[0].end
= ar5315_spiflash_res
[0].start
+ flash_size
;
172 return (char *) ar5315_spiflash_res
[0].end
;
175 int __init
ar5315_init_devices(void)
177 struct ar531x_config
*config
;
180 if (mips_machtype
!= MACH_ATHEROS_AR5315
)
183 ar531x_find_config(ar5315_flash_limit());
185 config
= (struct ar531x_config
*) kzalloc(sizeof(struct ar531x_config
), GFP_KERNEL
);
186 config
->board
= board_config
;
187 config
->radio
= radio_config
;
189 config
->tag
= (u_int16_t
) (sysRegRead(AR5315_SREV
) & REV_CHIP
);
191 ar5315_eth_data
.board_config
= board_config
;
192 ar5315_wmac
.dev
.platform_data
= config
;
194 ar5315_devs
[dev
++] = &ar5315_eth
;
195 ar5315_devs
[dev
++] = &ar5315_wmac
;
196 ar5315_devs
[dev
++] = &ar5315_spiflash
;
198 return platform_add_devices(ar5315_devs
, dev
);
203 * Called when an interrupt is received, this function
204 * determines exactly which interrupt it was, and it
205 * invokes the appropriate handler.
207 * Implicitly, we also define interrupt priority by
208 * choosing which to dispatch first.
210 asmlinkage
void ar5315_irq_dispatch(void)
212 int pending
= read_c0_status() & read_c0_cause();
214 if (pending
& CAUSEF_IP3
)
215 do_IRQ(AR5315_IRQ_WLAN0_INTRS
);
216 else if (pending
& CAUSEF_IP4
)
217 do_IRQ(AR5315_IRQ_ENET0_INTRS
);
218 else if (pending
& CAUSEF_IP2
) {
219 unsigned int ar531x_misc_intrs
= sysRegRead(AR5315_ISR
) & sysRegRead(AR5315_IMR
);
221 if (ar531x_misc_intrs
& AR5315_ISR_TIMER
)
222 do_IRQ(AR531X_MISC_IRQ_TIMER
);
223 else if (ar531x_misc_intrs
& AR5315_ISR_AHB
)
224 do_IRQ(AR531X_MISC_IRQ_AHB_PROC
);
225 else if (ar531x_misc_intrs
& AR5315_ISR_GPIO
) {
226 sysRegWrite(AR5315_ISR
, sysRegRead(AR5315_IMR
) | ~AR5315_ISR_GPIO
);
227 } else if (ar531x_misc_intrs
& AR5315_ISR_UART0
)
228 do_IRQ(AR531X_MISC_IRQ_UART0
);
229 else if (ar531x_misc_intrs
& AR5315_ISR_WD
)
230 do_IRQ(AR531X_MISC_IRQ_WATCHDOG
);
232 do_IRQ(AR531X_MISC_IRQ_NONE
);
233 } else if (pending
& CAUSEF_IP7
)
234 do_IRQ(AR531X_IRQ_CPU_CLOCK
);
236 do_IRQ(AR531X_IRQ_NONE
);
239 static void ar5315_halt(void)
244 static void ar5315_power_off(void)
250 static void ar5315_restart(char *command
)
255 /* reset the system */
256 sysRegWrite(AR5315_COLD_RESET
,AR5317_RESET_SYSTEM
);
259 * Cold reset does not work on the AR2315/6, use the GPIO reset bits a workaround.
262 reg
= sysRegRead(AR5315_GPIO_DO
);
263 reg
&= ~(1 << AR5315_RESET_GPIO
);
264 sysRegWrite(AR5315_GPIO_DO
, reg
);
265 (void)sysRegRead(AR5315_GPIO_DO
); /* flush write to hardware */
271 * This table is indexed by bits 5..4 of the CLOCKCTL1 register
272 * to determine the predevisor value.
274 static int __initdata CLOCKCTL1_PREDIVIDE_TABLE
[4] = {
281 static int __initdata PLLC_DIVIDE_TABLE
[5] = {
289 static unsigned int __init
290 ar5315_sys_clk(unsigned int clockCtl
)
292 unsigned int pllcCtrl
,cpuDiv
;
293 unsigned int pllcOut
,refdiv
,fdiv
,divby2
;
296 pllcCtrl
= sysRegRead(AR5315_PLLC_CTL
);
297 refdiv
= (pllcCtrl
& PLLC_REF_DIV_M
) >> PLLC_REF_DIV_S
;
298 refdiv
= CLOCKCTL1_PREDIVIDE_TABLE
[refdiv
];
299 fdiv
= (pllcCtrl
& PLLC_FDBACK_DIV_M
) >> PLLC_FDBACK_DIV_S
;
300 divby2
= (pllcCtrl
& PLLC_ADD_FDBACK_DIV_M
) >> PLLC_ADD_FDBACK_DIV_S
;
302 pllcOut
= (40000000/refdiv
)*(2*divby2
)*fdiv
;
305 /* clkm input selected */
306 switch(clockCtl
& CPUCLK_CLK_SEL_M
) {
309 clkDiv
= PLLC_DIVIDE_TABLE
[(pllcCtrl
& PLLC_CLKM_DIV_M
) >> PLLC_CLKM_DIV_S
];
312 clkDiv
= PLLC_DIVIDE_TABLE
[(pllcCtrl
& PLLC_CLKC_DIV_M
) >> PLLC_CLKC_DIV_S
];
319 cpuDiv
= (clockCtl
& CPUCLK_CLK_DIV_M
) >> CPUCLK_CLK_DIV_S
;
320 cpuDiv
= cpuDiv
* 2 ?: 1;
321 return (pllcOut
/(clkDiv
* cpuDiv
));
324 static inline unsigned int ar5315_cpu_frequency(void)
326 return ar5315_sys_clk(sysRegRead(AR5315_CPUCLK
));
329 static inline unsigned int ar5315_apb_frequency(void)
331 return ar5315_sys_clk(sysRegRead(AR5315_AMBACLK
));
334 static void __init
ar5315_time_init(void)
336 mips_hpt_frequency
= ar5315_cpu_frequency() / 2;
341 /* Enable the specified AR531X_MISC_IRQ interrupt */
343 ar5315_misc_intr_enable(unsigned int irq
)
347 imr
= sysRegRead(AR5315_IMR
);
350 case AR531X_MISC_IRQ_TIMER
:
351 imr
|= AR5315_ISR_TIMER
;
354 case AR531X_MISC_IRQ_AHB_PROC
:
355 imr
|= AR5315_ISR_AHB
;
358 case AR531X_MISC_IRQ_AHB_DMA
:
362 case AR531X_MISC_IRQ_GPIO
:
363 imr
|= AR5315_ISR_GPIO
;
366 case AR531X_MISC_IRQ_UART0
:
367 imr
|= AR5315_ISR_UART0
;
371 case AR531X_MISC_IRQ_WATCHDOG
:
372 imr
|= AR5315_ISR_WD
;
375 case AR531X_MISC_IRQ_LOCAL
:
380 sysRegWrite(AR5315_IMR
, imr
);
381 imr
=sysRegRead(AR5315_IMR
); /* flush write buffer */
382 //printk("enable Interrupt irq 0x%x imr 0x%x \n",irq,imr);
386 /* Disable the specified AR531X_MISC_IRQ interrupt */
388 ar5315_misc_intr_disable(unsigned int irq
)
392 imr
= sysRegRead(AR5315_IMR
);
395 case AR531X_MISC_IRQ_TIMER
:
396 imr
&= (~AR5315_ISR_TIMER
);
399 case AR531X_MISC_IRQ_AHB_PROC
:
400 imr
&= (~AR5315_ISR_AHB
);
403 case AR531X_MISC_IRQ_AHB_DMA
:
407 case AR531X_MISC_IRQ_GPIO
:
408 imr
&= ~AR5315_ISR_GPIO
;
411 case AR531X_MISC_IRQ_UART0
:
412 imr
&= (~AR5315_ISR_UART0
);
415 case AR531X_MISC_IRQ_WATCHDOG
:
416 imr
&= (~AR5315_ISR_WD
);
419 case AR531X_MISC_IRQ_LOCAL
:
424 sysRegWrite(AR5315_IMR
, imr
);
425 sysRegRead(AR5315_IMR
); /* flush write buffer */
428 /* Turn on the specified AR531X_MISC_IRQ interrupt */
430 ar5315_misc_intr_startup(unsigned int irq
)
432 ar5315_misc_intr_enable(irq
);
436 /* Turn off the specified AR531X_MISC_IRQ interrupt */
438 ar5315_misc_intr_shutdown(unsigned int irq
)
440 ar5315_misc_intr_disable(irq
);
444 ar5315_misc_intr_ack(unsigned int irq
)
446 ar5315_misc_intr_disable(irq
);
450 ar5315_misc_intr_end(unsigned int irq
)
452 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
453 ar5315_misc_intr_enable(irq
);
456 static struct irq_chip ar5315_misc_intr_controller
= {
457 .typename
= "AR5315 misc",
458 .startup
= ar5315_misc_intr_startup
,
459 .shutdown
= ar5315_misc_intr_shutdown
,
460 .enable
= ar5315_misc_intr_enable
,
461 .disable
= ar5315_misc_intr_disable
,
462 .ack
= ar5315_misc_intr_ack
,
463 .end
= ar5315_misc_intr_end
,
466 static irqreturn_t
ar5315_ahb_proc_handler(int cpl
, void *dev_id
)
468 sysRegWrite(AR5315_AHB_ERR0
,AHB_ERROR_DET
);
469 sysRegRead(AR5315_AHB_ERR1
);
471 printk("AHB fatal error\n");
472 machine_restart("AHB error"); /* Catastrophic failure */
477 static struct irqaction ar5315_ahb_proc_interrupt
= {
478 .handler
= ar5315_ahb_proc_handler
,
479 .flags
= SA_INTERRUPT
,
480 .name
= "ar5315_ahb_proc_interrupt",
484 static struct irqaction cascade
= {
485 .handler
= no_action
,
486 .flags
= SA_INTERRUPT
,
490 void ar5315_misc_intr_init(int irq_base
)
494 for (i
= irq_base
; i
< irq_base
+ AR531X_MISC_IRQ_COUNT
; i
++) {
495 irq_desc
[i
].status
= IRQ_DISABLED
;
496 irq_desc
[i
].action
= NULL
;
497 irq_desc
[i
].depth
= 1;
498 irq_desc
[i
].chip
= &ar5315_misc_intr_controller
;
500 setup_irq(AR531X_MISC_IRQ_AHB_PROC
, &ar5315_ahb_proc_interrupt
);
501 setup_irq(AR5315_IRQ_MISC_INTRS
, &cascade
);
504 void __init
ar5315_plat_setup(void)
506 unsigned int config
= read_c0_config();
508 /* Clear any lingering AHB errors */
509 write_c0_config(config
& ~0x3);
510 sysRegWrite(AR5315_AHB_ERR0
,AHB_ERROR_DET
);
511 sysRegRead(AR5315_AHB_ERR1
);
512 sysRegWrite(AR5315_WDC
, WDC_IGNORE_EXPIRATION
);
514 board_time_init
= ar5315_time_init
;
516 _machine_restart
= ar5315_restart
;
517 _machine_halt
= ar5315_halt
;
518 pm_power_off
= ar5315_power_off
;
520 serial_setup(KSEG1ADDR(AR5315_UART0
), ar5315_apb_frequency());
523 arch_initcall(ar5315_init_devices
);