blob: 3460dcc249437a70e779d5dda3294f671469df6e [file] [log] [blame]
Fabien Parentdef2fc02019-03-24 16:46:38 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 * Copyright (C) 2019 BayLibre, SAS
5 * Author: Fabien Parent <fparent@baylibre.com>
6 */
7
8#include <clk.h>
9#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -070010#include <cpu_func.h>
Fabien Parentdef2fc02019-03-24 16:46:38 +010011#include <dm.h>
12#include <fdtdec.h>
Simon Glass691d7192020-05-10 11:40:02 -060013#include <init.h>
Fabien Parentdef2fc02019-03-24 16:46:38 +010014#include <ram.h>
15#include <asm/arch/misc.h>
16#include <asm/armv8/mmu.h>
Simon Glass90526e92020-05-10 11:39:56 -060017#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060018#include <asm/global_data.h>
Fabien Parentdef2fc02019-03-24 16:46:38 +010019#include <asm/sections.h>
20#include <dm/uclass.h>
Fabien Parentdef2fc02019-03-24 16:46:38 +010021#include <dt-bindings/clock/mt8516-clk.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
Fabien Parentdef2fc02019-03-24 16:46:38 +010025int dram_init(void)
26{
27 int ret;
28
29 ret = fdtdec_setup_memory_banksize();
30 if (ret)
31 return ret;
32
33 return fdtdec_setup_mem_size_base();
34}
35
36int dram_init_banksize(void)
37{
38 gd->bd->bi_dram[0].start = gd->ram_base;
39 gd->bd->bi_dram[0].size = gd->ram_size;
40
41 return 0;
42}
43
44int mtk_pll_early_init(void)
45{
46 unsigned long pll_rates[] = {
47 [CLK_APMIXED_ARMPLL] = 1300000000,
48 [CLK_APMIXED_MAINPLL] = 1501000000,
49 [CLK_APMIXED_UNIVPLL] = 1248000000,
50 [CLK_APMIXED_MMPLL] = 380000000,
51 };
52 struct udevice *dev;
53 int ret, i;
54
55 ret = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65e25be2020-12-28 20:34:56 -070056 DM_DRIVER_GET(mtk_clk_apmixedsys), &dev);
Fabien Parentdef2fc02019-03-24 16:46:38 +010057 if (ret)
58 return ret;
59
60 /* configure default rate then enable apmixedsys */
61 for (i = 0; i < ARRAY_SIZE(pll_rates); i++) {
62 struct clk clk = { .id = i, .dev = dev };
63
64 ret = clk_set_rate(&clk, pll_rates[i]);
65 if (ret)
66 return ret;
67
68 ret = clk_enable(&clk);
69 if (ret)
70 return ret;
71 }
72
73 return 0;
74}
75
76int mtk_soc_early_init(void)
77{
78 int ret;
79
80 /* initialize early clocks */
81 ret = mtk_pll_early_init();
82 if (ret)
83 return ret;
84
85 return 0;
86}
87
Harald Seiler35b65dd2020-12-15 16:47:52 +010088void reset_cpu(void)
Fabien Parentdef2fc02019-03-24 16:46:38 +010089{
Fabien Parent47f30aa2019-05-06 16:17:56 +020090 psci_system_reset();
Fabien Parentdef2fc02019-03-24 16:46:38 +010091}
92
93int print_cpuinfo(void)
94{
95 printf("CPU: MediaTek MT8516\n");
96 return 0;
97}
98
99static struct mm_region mt8516_mem_map[] = {
100 {
101 /* DDR */
102 .virt = 0x40000000UL,
103 .phys = 0x40000000UL,
104 .size = 0x20000000UL,
105 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
106 }, {
107 .virt = 0x00000000UL,
108 .phys = 0x00000000UL,
109 .size = 0x20000000UL,
110 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
111 PTE_BLOCK_NON_SHARE |
112 PTE_BLOCK_PXN | PTE_BLOCK_UXN
113 }, {
114 0,
115 }
116};
117struct mm_region *mem_map = mt8516_mem_map;