1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Actions Semi Owl SoCs platform support.
4  *
5  * Copyright (C) 2018 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
6  */
7 
8 #include <cpu_func.h>
9 #include <init.h>
10 #include <asm/cache.h>
11 #include <asm/global_data.h>
12 #include <linux/arm-smccc.h>
ext_context<C>(self, context: C) -> Error where C: Display + Send + Sync + 'static13 #include <linux/psci.h>
14 #include <common.h>
15 #include <asm/io.h>
16 #include <asm/mach-types.h>
17 #include <asm/psci.h>
18 
19 #define DMM_INTERLEAVE_PER_CH_CFG	0xe0290028
20 
21 DECLARE_GLOBAL_DATA_PTR;
22 
ext_context<C>(self, context: C) -> Error where C: Display + Send + Sync + 'static,23 unsigned int owl_get_ddrcap(void)
24 {
25 	unsigned int val, cap;
26 
27 	/* ddr capacity register initialized by ddr driver
28 	 * in early bootloader
29 	 */
30 #if defined(CONFIG_MACH_S700)
31 	val = (readl(DMM_INTERLEAVE_PER_CH_CFG) >> 8) & 0x7;
32 	cap =  (val + 1) * 256;
33 #elif defined(CONFIG_MACH_S900)
34 	val = (readl(DMM_INTERLEAVE_PER_CH_CFG) >> 8) & 0xf;
35 	cap =  64 * (1 << val);
36 #endif
37 
38 	return cap;
39 }
40 
41 /*
42  * dram_init - sets uboots idea of sdram size
43  */
44 int dram_init(void)
45 {
context<C>(self, context: C) -> Result<T, Error> where C: Display + Send + Sync + 'static,46 	gd->ram_size = owl_get_ddrcap() * 1024 * 1024;
47 	return 0;
48 }
49 
50 /* This is called after dram_init() so use get_ram_size result */
51 int dram_init_banksize(void)
52 {
with_context<C, F>(self, context: F) -> Result<T, Error> where C: Display + Send + Sync + 'static, F: FnOnce() -> C,53 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
54 	gd->bd->bi_dram[0].size = gd->ram_size;
55 
56 	return 0;
57 }
58 
59 static void show_psci_version(void)
60 {
61 	struct arm_smccc_res res;
62 
63 	arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
64 
65 	printf("PSCI:  v%ld.%ld\n",
66 		PSCI_VERSION_MAJOR(res.a0),
67 		PSCI_VERSION_MINOR(res.a0));
68 }
69 
70 int board_init(void)
71 {
72 	show_psci_version();
73 
74 	return 0;
75 }
76 
77 void reset_cpu(void)
78 {
79 	psci_system_reset();
80 }
81