1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
11 #include <linux/libfdt.h>
14 #include <asm/arcregs.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 #define SYSCON_BASE 0xf000a000
19 #define AHBCKDIV (void *)(SYSCON_BASE + 0x04)
20 #define APBCKDIV (void *)(SYSCON_BASE + 0x08)
21 #define APBCKEN (void *)(SYSCON_BASE + 0x0C)
22 #define RESET_REG (void *)(SYSCON_BASE + 0x18)
23 #define CLKSEL (void *)(SYSCON_BASE + 0x24)
24 #define CLKSTAT (void *)(SYSCON_BASE + 0x28)
25 #define PLLCON (void *)(SYSCON_BASE + 0x2C)
26 #define APBCKSEL (void *)(SYSCON_BASE + 0x30)
27 #define AHBCKEN (void *)(SYSCON_BASE + 0x34)
28 #define USBPHY_PLL (void *)(SYSCON_BASE + 0x78)
29 #define USBCFG (void *)(SYSCON_BASE + 0x7c)
31 #define PLL_MASK_0 0xffcfffff
32 #define PLL_MASK_1 0xffcfff00
33 #define PLL_MASK_2 0xfbcfff00
35 #define CLKSEL_DEFAULT 0x5a690000
37 static int set_cpu_freq(unsigned int clk)
41 /* Set clk to ext Xtal (LSN value 0) */
42 writel(CLKSEL_DEFAULT, CLKSEL);
50 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
51 /* pll_off=1, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
52 writel((readl(PLLCON) & PLL_MASK_1) | 0x300191, PLLCON);
53 /* pll_off=0, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
54 writel((readl(PLLCON) & PLL_MASK_2) | 0x300191, PLLCON);
58 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
59 /* pll_off=1, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
60 writel((readl(PLLCON) & PLL_MASK_1) | 0x200121, PLLCON);
61 /* pll_off=0, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
62 writel((readl(PLLCON) & PLL_MASK_2) | 0x200121, PLLCON);
66 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
67 /* pll_off=1,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
68 writel((readl(PLLCON) & PLL_MASK_1) | 0x200191, PLLCON);
69 /* pll_off=0,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
70 writel((readl(PLLCON) & PLL_MASK_2) | 0x200191, PLLCON);
74 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
75 /* pll_off=1, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
76 writel((readl(PLLCON) & PLL_MASK_1) | 0x100111, PLLCON);
77 /* pll_off=0, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
78 writel((readl(PLLCON) & PLL_MASK_2) | 0x100111, PLLCON);
82 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
83 /* pll_off=1, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
84 writel((readl(PLLCON) & PLL_MASK_1) | 0x100121, PLLCON);
85 /* pll_off=0, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
86 writel((readl(PLLCON) & PLL_MASK_2) | 0x100121, PLLCON);
93 while (!(readl(CLKSTAT) & 0x4))
96 /* Set clk from PLL on bus (LSN = 1) */
97 writel(CLKSEL_DEFAULT | BIT(0), CLKSEL);
102 extern u8 __rom_end[];
103 extern u8 __ram_start[];
104 extern u8 __ram_end[];
107 * Use mach_cpu_init() for .data section copy as board_early_init_f() will be
108 * too late: initf_dm() will use a value of "av_" variable from not yet
109 * initialized (by copy) area.
111 int mach_cpu_init(void)
115 /* Don't relocate U-Boot */
116 gd->flags |= GD_FLG_SKIP_RELOC;
118 /* Copy data from ROM to RAM */
120 u8 *dst = __ram_start;
122 while (dst < __ram_end)
125 /* Enable debug uart */
126 #define DEBUG_UART_BASE 0x80014000
127 #define DEBUG_UART_DLF_OFFSET 0xc0
128 write_aux_reg(DEBUG_UART_BASE + DEBUG_UART_DLF_OFFSET, 1);
130 offset = fdt_path_offset(gd->fdt_blob, "/cpu_card/core_clk");
134 gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0);
138 /* If CPU freq > 100 MHz, divide eFLASH clock by 2 */
139 if (gd->cpu_clk > 100000000) {
140 u32 reg = readl(AHBCKDIV);
144 writel(reg, AHBCKDIV);
147 return set_cpu_freq(gd->cpu_clk);
150 #define IOTDK_RESET_SEQ 0x55AA6699
152 void reset_cpu(ulong addr)
154 writel(IOTDK_RESET_SEQ, RESET_REG);
159 puts("Board: Synopsys IoT Development Kit\n");