summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/system-x1000.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-04-15 03:00:04 +0100
committerAidan MacDonald <amachronic@protonmail.com>2021-04-17 20:24:07 +0000
commit01d1eb425874813864d12d72c93e6e74ab92ac1f (patch)
treee4bc6171342e1ef4160b2e32653f5668f9be3d69 /firmware/target/mips/ingenic_x1000/system-x1000.c
parente123c5d2f27e9efbef8b4264f1576e4e10ba7b82 (diff)
downloadrockbox-01d1eb425874813864d12d72c93e6e74ab92ac1f.tar.gz
rockbox-01d1eb425874813864d12d72c93e6e74ab92ac1f.zip
FiiO M3K/X1000: Do system clock initialization in the SPL
Initializing the clocks in the SPL brings Rockbox in line with how the FiiO M3K's original SPL works. It's likely other X1000 devices do this too. There was a logic error in the previous setup: the code falsely assumed that DDR memory would always be running from MPLL, but it would be switched to APLL by the bootloader. Rockbox would then try to re-init APLL, albeit with the same parameters. Maybe this was the cause of the boot hang on some units. Change-Id: I64064585e491bbdf1e95fe9428c91a9314f2a917
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/system-x1000.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/system-x1000.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/firmware/target/mips/ingenic_x1000/system-x1000.c b/firmware/target/mips/ingenic_x1000/system-x1000.c
index 54513cffb2..d841a274ed 100644
--- a/firmware/target/mips/ingenic_x1000/system-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/system-x1000.c
@@ -40,40 +40,6 @@ int __cpu_idle_cur = 0;
40uint32_t __cpu_idle_ticks = 0; 40uint32_t __cpu_idle_ticks = 0;
41uint32_t __cpu_idle_reftick = 0; 41uint32_t __cpu_idle_reftick = 0;
42 42
43static void system_init_clk(void)
44{
45 /* Gate all clocks except CPU/bus/memory/RTC */
46 REG_CPM_CLKGR = ~jz_orm(CPM_CLKGR, CPU_BIT, DDR, AHB0, APB0, RTC);
47
48 /* Switch to EXCLK */
49 clk_set_ccr_mux(CLKMUX_SCLK_A(EXCLK) | CLKMUX_CPU(SCLK_A) |
50 CLKMUX_AHB0(SCLK_A) | CLKMUX_AHB2(SCLK_A));
51 clk_set_ccr_div(1, 1, 1, 1, 1);
52
53#ifdef FIIO_M3K
54 /* Nominal clock configuration
55 * ---------------------------
56 * APLL at 1 GHz, MPLL disabled
57 * CPU at 1 GHz, L2 cache at 500 MHz
58 * AHB0 and AHB2 at 200 MHz
59 * PCLK at 100 MHz
60 * DDR at 200 MHz
61 */
62 jz_writef(CPM_APCR, BS(1), PLLM(41), PLLN(0), PLLOD(0), ENABLE(1));
63 while(jz_readf(CPM_APCR, ON) == 0);
64
65 clk_set_ccr_div(1, 2, 5, 5, 10);
66 clk_set_ccr_mux(CLKMUX_SCLK_A(APLL) | CLKMUX_CPU(SCLK_A) |
67 CLKMUX_AHB0(SCLK_A) | CLKMUX_AHB2(SCLK_A));
68 clk_set_ddr(X1000_CLK_SCLK_A, 5);
69
70 /* Shut off MPLL, since nobody should be using it now */
71 jz_writef(CPM_MPCR, ENABLE(0));
72#else
73# error "Please define system clock configuration for target"
74#endif
75}
76
77/* Prepare the CPU to process interrupts, but don't enable them yet */ 43/* Prepare the CPU to process interrupts, but don't enable them yet */
78static void system_init_irq(void) 44static void system_init_irq(void)
79{ 45{
@@ -94,8 +60,8 @@ static void system_init_irq(void)
94/* First thing called from Rockbox main() */ 60/* First thing called from Rockbox main() */
95void system_init(void) 61void system_init(void)
96{ 62{
97 /* Setup system clocks */ 63 /* Gate all clocks except CPU/bus/memory/RTC */
98 system_init_clk(); 64 REG_CPM_CLKGR = ~jz_orm(CPM_CLKGR, CPU_BIT, DDR, AHB0, APB0, RTC);
99 65
100 /* Ungate timers and turn them all off by default */ 66 /* Ungate timers and turn them all off by default */
101 jz_writef(CPM_CLKGR, TCU(0), OST(0)); 67 jz_writef(CPM_CLKGR, TCU(0), OST(0));