blob: 650958f94c26b65bf2be886ab18fe2c9842e96cb [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>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Alexey Brodkinc15be5b2018-01-24 21:37:14 +03009#include <malloc.h>
10#include <dwmmc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
Alexey Brodkinc15be5b2018-01-24 21:37:14 +030013#include <linux/libfdt.h>
14#include <fdtdec.h>
15
16#include <asm/arcregs.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
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)
Alexey Brodkin5e2151b2018-10-10 14:20:11 +030024#define RESET_REG (void *)(SYSCON_BASE + 0x18)
Alexey Brodkinc15be5b2018-01-24 21:37:14 +030025#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)
32
33#define PLL_MASK_0 0xffcfffff
34#define PLL_MASK_1 0xffcfff00
35#define PLL_MASK_2 0xfbcfff00
36
37#define CLKSEL_DEFAULT 0x5a690000
38
39static int set_cpu_freq(unsigned int clk)
40{
41 clk /= 1000000;
42
43 /* Set clk to ext Xtal (LSN value 0) */
44 writel(CLKSEL_DEFAULT, CLKSEL);
45
46 switch (clk) {
47 case 16:
48 /* Bypass mode */
49 return 0;
50
51 case 50:
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);
57 break;
58
59 case 72:
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);
65 break;
66
67 case 100:
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);
73 break;
74
Alexey Brodkin69060922018-10-10 15:53:45 +030075 case 136:
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);
81 break;
82
Alexey Brodkinc15be5b2018-01-24 21:37:14 +030083 case 144:
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);
89 break;
90
91 default:
92 return -EINVAL;
93 }
94
95 while (!(readl(CLKSTAT) & 0x4))
96 ;
97
98 /* Set clk from PLL on bus (LSN = 1) */
99 writel(CLKSEL_DEFAULT | BIT(0), CLKSEL);
100
101 return 0;
102}
103
104extern u8 __rom_end[];
105extern u8 __ram_start[];
106extern u8 __ram_end[];
107
108/*
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.
112 */
113int mach_cpu_init(void)
114{
Alexey Brodkin1c828422018-10-10 16:15:20 +0300115 int offset;
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300116
117 /* Don't relocate U-Boot */
118 gd->flags |= GD_FLG_SKIP_RELOC;
119
120 /* Copy data from ROM to RAM */
121 u8 *src = __rom_end;
122 u8 *dst = __ram_start;
123
124 while (dst < __ram_end)
125 *dst++ = *src++;
126
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);
131
132 offset = fdt_path_offset(gd->fdt_blob, "/cpu_card/core_clk");
133 if (offset < 0)
134 return offset;
135
Alexey Brodkin1c828422018-10-10 16:15:20 +0300136 gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0);
137 if (!gd->cpu_clk)
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300138 return -EINVAL;
139
140 /* If CPU freq > 100 MHz, divide eFLASH clock by 2 */
Alexey Brodkin1c828422018-10-10 16:15:20 +0300141 if (gd->cpu_clk > 100000000) {
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300142 u32 reg = readl(AHBCKDIV);
143
144 reg &= ~(0xF << 8);
145 reg |= 2 << 8;
146 writel(reg, AHBCKDIV);
147 }
148
Alexey Brodkin1c828422018-10-10 16:15:20 +0300149 return set_cpu_freq(gd->cpu_clk);
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300150}
151
Alexey Brodkin5e2151b2018-10-10 14:20:11 +0300152#define IOTDK_RESET_SEQ 0x55AA6699
153
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100154void reset_cpu(void)
Alexey Brodkin5e2151b2018-10-10 14:20:11 +0300155{
156 writel(IOTDK_RESET_SEQ, RESET_REG);
157}
158
Alexey Brodkinc15be5b2018-01-24 21:37:14 +0300159int checkboard(void)
160{
161 puts("Board: Synopsys IoT Development Kit\n");
162 return 0;
163};