blob: 36aa8f6ae55466103a6b2c007a7d127d5a3dfade [file] [log] [blame]
Alexey Brodkinc15be5b2018-01-24 21:37:14 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 */
5
6#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07007#include <cpu_func.h>
Alexey Brodkinc15be5b2018-01-24 21:37:14 +03008#include <malloc.h>
9#include <dwmmc.h>
10#include <linux/libfdt.h>
11#include <fdtdec.h>
12
13#include <asm/arcregs.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17#define SYSCON_BASE 0xf000a000
18#define AHBCKDIV (void *)(SYSCON_BASE + 0x04)
19#define APBCKDIV (void *)(SYSCON_BASE + 0x08)
20#define APBCKEN (void *)(SYSCON_BASE + 0x0C)
Alexey Brodkin5e2151b2018-10-10 14:20:11 +030021#define RESET_REG (void *)(SYSCON_BASE + 0x18)
Alexey Brodkinc15be5b2018-01-24 21:37:14 +030022#define CLKSEL (void *)(SYSCON_BASE + 0x24)
23#define CLKSTAT (void *)(SYSCON_BASE + 0x28)
24#define PLLCON (void *)(SYSCON_BASE + 0x2C)
25#define APBCKSEL (void *)(SYSCON_BASE + 0x30)
26#define AHBCKEN (void *)(SYSCON_BASE + 0x34)
27#define USBPHY_PLL (void *)(SYSCON_BASE + 0x78)
28#define USBCFG (void *)(SYSCON_BASE + 0x7c)
29
30#define PLL_MASK_0 0xffcfffff
31#define PLL_MASK_1 0xffcfff00
32#define PLL_MASK_2 0xfbcfff00
33
34#define CLKSEL_DEFAULT 0x5a690000
35
36static int set_cpu_freq(unsigned int clk)
37{
38 clk /= 1000000;
39
40 /* Set clk to ext Xtal (LSN value 0) */
41 writel(CLKSEL_DEFAULT, CLKSEL);
42
43 switch (clk) {
44 case 16:
45 /* Bypass mode */
46 return 0;
47
48 case 50:
49 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
50 /* pll_off=1, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
51 writel((readl(PLLCON) & PLL_MASK_1) | 0x300191, PLLCON);
52 /* pll_off=0, M=25, N=1, OD=3, PLL_OUT_CLK=50M */
53 writel((readl(PLLCON) & PLL_MASK_2) | 0x300191, PLLCON);
54 break;
55
56 case 72:
57 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
58 /* pll_off=1, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
59 writel((readl(PLLCON) & PLL_MASK_1) | 0x200121, PLLCON);
60 /* pll_off=0, M=18, N=1, OD=2, PLL_OUT_CLK=72M */
61 writel((readl(PLLCON) & PLL_MASK_2) | 0x200121, PLLCON);
62 break;
63
64 case 100:
65 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
66 /* pll_off=1,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
67 writel((readl(PLLCON) & PLL_MASK_1) | 0x200191, PLLCON);
68 /* pll_off=0,M=25, N=1, OD=2, PLL_OUT_CLK=100M */
69 writel((readl(PLLCON) & PLL_MASK_2) | 0x200191, PLLCON);
70 break;
71
Alexey Brodkin69060922018-10-10 15:53:45 +030072 case 136:
73 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
74 /* pll_off=1, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
75 writel((readl(PLLCON) & PLL_MASK_1) | 0x100111, PLLCON);
76 /* pll_off=0, M=17, N=1, OD=1, PLL_OUT_CLK=136M */
77 writel((readl(PLLCON) & PLL_MASK_2) | 0x100111, PLLCON);
78 break;
79
Alexey Brodkinc15be5b2018-01-24 21:37:14 +030080 case 144:
81 writel(readl(PLLCON) & PLL_MASK_0, PLLCON);
82 /* pll_off=1, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
83 writel((readl(PLLCON) & PLL_MASK_1) | 0x100121, PLLCON);
84 /* pll_off=0, M=18, N=1, OD=1, PLL_OUT_CLK=144M */
85 writel((readl(PLLCON) & PLL_MASK_2) | 0x100121, PLLCON);
86 break;
87
88 default:
89 return -EINVAL;
90 }
91
92 while (!(readl(CLKSTAT) & 0x4))
93 ;
94
95 /* Set clk from PLL on bus (LSN = 1) */
96 writel(CLKSEL_DEFAULT | BIT(0), CLKSEL);
97
98 return 0;
99}
100
101extern u8 __rom_end[];
102extern u8 __ram_start[];
103extern u8 __ram_end[];
104
105/*
106 * Use mach_cpu_init() for .data section copy as board_early_init_f() will be
107 * too late: initf_dm() will use a value of "av_" variable from not yet
108 * initialized (by copy) area.
109 */
110int mach_cpu_init(void)
111{
Alexey Brodkin1c828422018-10-10 16:15:20 +0300112 int offset;
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300113
114 /* Don't relocate U-Boot */
115 gd->flags |= GD_FLG_SKIP_RELOC;
116
117 /* Copy data from ROM to RAM */
118 u8 *src = __rom_end;
119 u8 *dst = __ram_start;
120
121 while (dst < __ram_end)
122 *dst++ = *src++;
123
124 /* Enable debug uart */
125#define DEBUG_UART_BASE 0x80014000
126#define DEBUG_UART_DLF_OFFSET 0xc0
127 write_aux_reg(DEBUG_UART_BASE + DEBUG_UART_DLF_OFFSET, 1);
128
129 offset = fdt_path_offset(gd->fdt_blob, "/cpu_card/core_clk");
130 if (offset < 0)
131 return offset;
132
Alexey Brodkin1c828422018-10-10 16:15:20 +0300133 gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0);
134 if (!gd->cpu_clk)
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300135 return -EINVAL;
136
137 /* If CPU freq > 100 MHz, divide eFLASH clock by 2 */
Alexey Brodkin1c828422018-10-10 16:15:20 +0300138 if (gd->cpu_clk > 100000000) {
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300139 u32 reg = readl(AHBCKDIV);
140
141 reg &= ~(0xF << 8);
142 reg |= 2 << 8;
143 writel(reg, AHBCKDIV);
144 }
145
Alexey Brodkin1c828422018-10-10 16:15:20 +0300146 return set_cpu_freq(gd->cpu_clk);
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300147}
148
Alexey Brodkin5e2151b2018-10-10 14:20:11 +0300149#define IOTDK_RESET_SEQ 0x55AA6699
150
151void reset_cpu(ulong addr)
152{
153 writel(IOTDK_RESET_SEQ, RESET_REG);
154}
155
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300156int checkboard(void)
157{
158 puts("Board: Synopsys IoT Development Kit\n");
159 return 0;
160};