set_reg(AR7240_USB_PLL_CONFIG, CPU_PLL_SETTLE_TIME_VAL)
nop
-pll_unlock_handler:
+/* read GPIO_SET register */
+ li t0, KSEG1ADDR(AR7240_GPIO_IN)
+ lw t1, 0(t0)
+ and t1, t1, (1 << GPIO_RST_BUTTON_BIT)
+ beq t1, (1 << GPIO_RST_BUTTON_BIT), pll_default_unlock_handler
+ nop
+pll_unlock_handler:
/* set nint, frac, refdiv, outdiv, range in CPU PLL configuration resiter */
set_reg(AR7240_CPU_PLL_CONFIG, CPU_PLL_CONFIG_VAL1)
+ j wait_loop2
+ nop
+
+pll_default_unlock_handler:
+/* set nint, frac, refdiv, outdiv, range in CPU PLL configuration resiter */
+ set_reg(AR7240_CPU_PLL_CONFIG, CPU_PLL_CONFIG_VAL1_DEFAULT)
nop
wait_loop2:
set_reg(AR7240_PCIE_PLL_CONFIG, CPU_PLL_DITHER_FRAC_VAL)
nop
+/* read GPIO_SET register */
+ li t0, KSEG1ADDR(AR7240_GPIO_IN)
+ lw t1, 0(t0)
+ and t1, t1, (1 << GPIO_RST_BUTTON_BIT)
+ beq t1, (1 << GPIO_RST_BUTTON_BIT), pll_default_lock_handler
+ nop
+
+pll_lock_handler:
/* clear PLL power down bit in CPU PLLl configuration */
set_reg(AR7240_CPU_PLL_CONFIG, CPU_PLL_CONFIG_VAL2)
+ j wait_loop3
+ nop
+
+pll_default_lock_handler:
+/* clear PLL power down bit in CPU PLLl configuration */
+ set_reg(AR7240_CPU_PLL_CONFIG, CPU_PLL_CONFIG_VAL2_DEFAULT)
nop
+
wait_loop3:
li t6, KSEG1ADDR(AR7240_CPU_PLL_CONFIG)
lw t7, 0(t6)
extern void led_toggle(void);
extern void all_led_off(void);
+extern int reset_button_status(void);
/*
* globals
// spi flash clock
ar7240_reg_wr(AR7240_SPI_FS, 0x01);
- ar7240_reg_wr(AR7240_SPI_CLOCK, AR7240_SPI_CONTROL);
+
+ // if reset button is pressed -> write default CLOCK_DIVIDER for SPI CLOCK
+ if(reset_button_status()){
+ ar7240_reg_wr(AR7240_SPI_CLOCK, AR7240_SPI_CONTROL_DEFAULT);
+ } else {
+ ar7240_reg_wr(AR7240_SPI_CLOCK, AR7240_SPI_CONTROL);
+ }
+
ar7240_reg_wr(AR7240_SPI_FS, 0x0);
// get flash id
#undef CPU_CLK_CONTROL_VAL2
// CPU-RAM-AHB frequency setting
-#define CFG_PLL_FREQ CFG_PLL_400_400_200
+//#define CFG_PLL_FREQ CFG_PLL_400_400_200
+#define CFG_PLL_FREQ CFG_PLL_525_525_262 // only for test!
/*
* MIPS32 24K Processor Core Family Software User's Manual
*
*/
+/*
+ * Default values (400/400/200 MHz) for O/C recovery mode
+ */
+
+// CPU_DIV = 1, RAM_DIV = 1, AHB_DIV = 2
+#define CPU_CLK_CONTROL_VAL1_DEFAULT 0x00018004
+#define CPU_CLK_CONTROL_VAL2_DEFAULT 0x00008000
+
+#if CONFIG_40MHZ_XTAL_SUPPORT
+ // DIV_INT = 20 (40 MHz * 20/2 = 400 MHz)
+ // REFDIV = 1
+ // RANGE = 0
+ // OUTDIV = 1
+ #define CPU_PLL_CONFIG_VAL1_DEFAULT 0x40815000
+ #define CPU_PLL_CONFIG_VAL2_DEFAULT 0x00815000
+#else
+ // DIV_INT = 32 (25 MHz * 32/2 = 400 MHz)
+ // REFDIV = 1
+ // RANGE = 0
+ // OUTDIV = 1
+ #define CPU_PLL_CONFIG_VAL1_DEFAULT 0x40818000
+ #define CPU_PLL_CONFIG_VAL2_DEFAULT 0x00818000
+#endif
+
+// CLOCK_DIVIDER = 2 (SPI clock = 200 / 6 ~ 33 MHz)
+#define AR7240_SPI_CONTROL_DEFAULT 0x42
+
#if (CFG_PLL_FREQ == CFG_PLL_400_400_200)
#define CFG_HZ (400000000LU/2)
// CLOCK_DIVIDER = 1 (SPI clock = 131 / 4 ~ 32,8 MHz)
#define AR7240_SPI_CONTROL 0x41
+#elif (CFG_PLL_FREQ == CFG_PLL_525_525_262)
+
+ #define CFG_HZ (525000000LU/2)
+
+ // CPU_DIV = 1, RAM_DIV = 1, AHB_DIV = 2
+ #define CPU_CLK_CONTROL_VAL1 0x00008004
+ #define CPU_CLK_CONTROL_VAL2 0x00008000
+
+ // DIV_INT = 42 (25 MHz * 42/2 = 525 MHz)
+ // REFDIV = 1
+ // RANGE = 0
+ // OUTDIV = 1
+ #define CPU_PLL_CONFIG_VAL1 0x4081A800
+ #define CPU_PLL_CONFIG_VAL2 0x0081A800
+
+ // CLOCK_DIVIDER = 1 (SPI clock = 131 / 4 ~ 32,8 MHz)
+ #define AR7240_SPI_CONTROL 0x41
+
#endif
/*
#define CFG_PLL_500_250_250 10
#define CFG_PLL_562_281_140 11
#define CFG_PLL_525_262_131 12
+#define CFG_PLL_525_525_262 13
// WASP
#define CFG_PLL_566_400_200 0x31