1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
11 #include <asm/global_data.h>
12 #include <linux/bitops.h>
13 #include <linux/libfdt.h>
16 #include <asm/arcregs.h>
18 DECLARE_GLOBAL_DATA_PTR;
20 #define SYSCON_BASE 0xf000a000
21 #define AHBCKDIV (void *)(SYSCON_BASE + 0x04)
22 #define APBCKDIV (void *)(SYSCON_BASE + 0x08)
23 #define APBCKEN (void *)(SYSCON_BASE + 0x0C)
24 #define RESET_REG (void *)(SYSCON_BASE + 0x18)
25 #define CLKSEL (void *)(SYSCON_BASE + 0x24)
26 #define CLKSTAT (void *)(SYSCON_BASE + 0x28)
27 #define PLLCON (void *)(SYSCON_BASE + 0x2C)
28 #define APBCKSEL (void *)(SYSCON_BASE + 0x30)
29 #define AHBCKEN (void *)(SYSCON_BASE + 0x34)
30 #define USBPHY_PLL (void *)(SYSCON_BASE + 0x78)
31 #define USBCFG (void *)(SYSCON_BASE + 0x7c)
33 #define PLL_MASK_0 0xffcfffff
34 #define PLL_MASK_1 0xffcfff00
35 #define PLL_MASK_2 0xfbcfff00
37 #define CLKSEL_DEFAULT 0x5a690000
39 static int set_cpu_freq(unsigned int clk)
43 /* Set clk to ext Xtal (LSN value 0) */
44 writel(CLKSEL_DEFAULT, CLKSEL);
52 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
53 /* pll_off=1, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
54 writel((readl(PLLCON) & PLL_MASK_1) | 0x300191, PLLCON);
55 /* pll_off=0, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
56 writel((readl(PLLCON) & PLL_MASK_2) | 0x300191, PLLCON);
60 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
61 /* pll_off=1, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
62 writel((readl(PLLCON) & PLL_MASK_1) | 0x200121, PLLCON);
63 /* pll_off=0, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
64 writel((readl(PLLCON) & PLL_MASK_2) | 0x200121, PLLCON);
68 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
69 /* pll_off=1,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
70 writel((readl(PLLCON) & PLL_MASK_1) | 0x200191, PLLCON);
71 /* pll_off=0,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
72 writel((readl(PLLCON) & PLL_MASK_2) | 0x200191, PLLCON);
76 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
77 /* pll_off=1, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
78 writel((readl(PLLCON) & PLL_MASK_1) | 0x100111, PLLCON);
79 /* pll_off=0, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
80 writel((readl(PLLCON) & PLL_MASK_2) | 0x100111, PLLCON);
84 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
85 /* pll_off=1, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
86 writel((readl(PLLCON) & PLL_MASK_1) | 0x100121, PLLCON);
87 /* pll_off=0, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
88 writel((readl(PLLCON) & PLL_MASK_2) | 0x100121, PLLCON);
95 while (!(readl(CLKSTAT) & 0x4))
98 /* Set clk from PLL on bus (LSN = 1) */
99 writel(CLKSEL_DEFAULT | BIT(0), CLKSEL);
104 extern u8 __rom_end[];
105 extern u8 __ram_start[];
106 extern u8 __ram_end[];
109 * Use mach_cpu_init() for .data section copy as board_early_init_f() will be
110 * too late: initf_dm() will use a value of "av_" variable from not yet
111 * initialized (by copy) area.
113 int mach_cpu_init(void)
117 /* Don't relocate U-Boot */
118 gd->flags |= GD_FLG_SKIP_RELOC;
120 /* Copy data from ROM to RAM */
122 u8 *dst = __ram_start;
124 while (dst < __ram_end)
127 /* Enable debug uart */
128 #define DEBUG_UART_BASE 0x80014000
129 #define DEBUG_UART_DLF_OFFSET 0xc0
130 write_aux_reg(DEBUG_UART_BASE + DEBUG_UART_DLF_OFFSET, 1);
132 offset = fdt_path_offset(gd->fdt_blob, "/cpu_card/core_clk");
136 gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0);
140 /* If CPU freq > 100 MHz, divide eFLASH clock by 2 */
141 if (gd->cpu_clk > 100000000) {
142 u32 reg = readl(AHBCKDIV);
146 writel(reg, AHBCKDIV);
149 return set_cpu_freq(gd->cpu_clk);
152 #define IOTDK_RESET_SEQ 0x55AA6699
156 writel(IOTDK_RESET_SEQ, RESET_REG);
161 puts("Board: Synopsys IoT Development Kit\n");