blob: 098892802bbc21714701bdfaa8f04819c2a7fdae [file] [log] [blame]
developerf4a079c2018-11-15 10:07:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
5 */
6
7#include <clk.h>
8#include <common.h>
9#include <dm.h>
10#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
developerf4a079c2018-11-15 10:07:52 +080012#include <ram.h>
13#include <asm/arch/misc.h>
14#include <asm/sections.h>
15#include <dm/uclass.h>
16#include <linux/io.h>
17
18#include <dt-bindings/clock/mt7629-clk.h>
19
20#define L2_CFG_BASE 0x10200000
21#define L2_CFG_SIZE 0x1000
22#define L2_SHARE_CFG_MP0 0x7f0
23#define L2_SHARE_MODE_OFF BIT(8)
24
25DECLARE_GLOBAL_DATA_PTR;
26
27int mtk_pll_early_init(void)
28{
29 unsigned long pll_rates[] = {
30 [CLK_APMIXED_ARMPLL] = 1250000000,
31 [CLK_APMIXED_MAINPLL] = 1120000000,
32 [CLK_APMIXED_UNIV2PLL] = 1200000000,
33 [CLK_APMIXED_ETH1PLL] = 500000000,
34 [CLK_APMIXED_ETH2PLL] = 700000000,
35 [CLK_APMIXED_SGMIPLL] = 650000000,
36 };
37 struct udevice *dev;
38 int ret, i;
39
40 ret = uclass_get_device_by_driver(UCLASS_CLK,
41 DM_GET_DRIVER(mtk_clk_apmixedsys), &dev);
42 if (ret)
43 return ret;
44
45 /* configure default rate then enable apmixedsys */
46 for (i = 0; i < ARRAY_SIZE(pll_rates); i++) {
47 struct clk clk = { .id = i, .dev = dev };
48
49 ret = clk_set_rate(&clk, pll_rates[i]);
50 if (ret)
51 return ret;
52
53 ret = clk_enable(&clk);
54 if (ret)
55 return ret;
56 }
57
58 /* setup mcu bus */
59 ret = uclass_get_device_by_driver(UCLASS_SYSCON,
60 DM_GET_DRIVER(mtk_mcucfg), &dev);
61 if (ret)
62 return ret;
63
64 return 0;
65}
66
67int mtk_soc_early_init(void)
68{
69 struct udevice *dev;
70 int ret;
71
72 /* initialize early clocks */
73 ret = mtk_pll_early_init();
74 if (ret)
75 return ret;
76
77 ret = uclass_first_device_err(UCLASS_RAM, &dev);
78 if (ret)
79 return ret;
80
81 return 0;
82}
83
84int mach_cpu_init(void)
85{
86 void __iomem *base;
87
88 base = ioremap(L2_CFG_BASE, L2_CFG_SIZE);
89
90 /* disable L2C shared mode */
91 writel(L2_SHARE_MODE_OFF, base + L2_SHARE_CFG_MP0);
92
93 return 0;
94}
95
96int dram_init(void)
97{
98 struct ram_info ram;
99 struct udevice *dev;
100 int ret;
101
102 ret = uclass_first_device_err(UCLASS_RAM, &dev);
103 if (ret)
104 return ret;
105
106 ret = ram_get_info(dev, &ram);
107 if (ret)
108 return ret;
109
110 debug("RAM init base=%lx, size=%x\n", ram.base, ram.size);
111
112 gd->ram_size = ram.size;
113
114 return 0;
115}
116
117int print_cpuinfo(void)
118{
119 void __iomem *chipid;
120 u32 hwcode, swver;
121
122 chipid = ioremap(VER_BASE, VER_SIZE);
123 hwcode = readl(chipid + APHW_CODE);
124 swver = readl(chipid + APSW_VER);
125
126 printf("CPU: MediaTek MT%04x E%d\n", hwcode, (swver & 0xf) + 1);
127
128 return 0;
129}