xref: /rk3399_ARM-atf/plat/rockchip/common/params_setup.c (revision ff2743e544f0f82381ebb9dff8f14eacb837d2e0)
1 /*
2  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arm_gic.h>
8 #include <assert.h>
9 #include <bl_common.h>
10 #include <console.h>
11 #include <coreboot.h>
12 #include <debug.h>
13 #include <gpio.h>
14 #include <mmio.h>
15 #include <plat_params.h>
16 #include <plat_private.h>
17 #include <platform.h>
18 #include <string.h>
19 
20 static struct gpio_info param_reset;
21 static struct gpio_info param_poweroff;
22 static struct bl31_apio_param param_apio;
23 static struct gpio_info *rst_gpio;
24 static struct gpio_info *poweroff_gpio;
25 static struct gpio_info suspend_gpio[10];
26 uint32_t suspend_gpio_cnt;
27 static struct apio_info *suspend_apio;
28 
29 struct gpio_info *plat_get_rockchip_gpio_reset(void)
30 {
31 	return rst_gpio;
32 }
33 
34 struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
35 {
36 	return poweroff_gpio;
37 }
38 
39 struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
40 {
41 	*count = suspend_gpio_cnt;
42 
43 	return &suspend_gpio[0];
44 }
45 
46 struct apio_info *plat_get_rockchip_suspend_apio(void)
47 {
48 	return suspend_apio;
49 }
50 
51 void params_early_setup(void *plat_param_from_bl2)
52 {
53 	struct bl31_plat_param *bl2_param;
54 	struct bl31_gpio_param *gpio_param;
55 
56 	/* keep plat parameters for later processing if need */
57 	bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
58 	while (bl2_param) {
59 		switch (bl2_param->type) {
60 		case PARAM_RESET:
61 			gpio_param = (struct bl31_gpio_param *)bl2_param;
62 			memcpy(&param_reset, &gpio_param->gpio,
63 			       sizeof(struct gpio_info));
64 			rst_gpio = &param_reset;
65 			break;
66 		case PARAM_POWEROFF:
67 			gpio_param = (struct bl31_gpio_param *)bl2_param;
68 			memcpy(&param_poweroff, &gpio_param->gpio,
69 				sizeof(struct gpio_info));
70 			poweroff_gpio = &param_poweroff;
71 			break;
72 		case PARAM_SUSPEND_GPIO:
73 			if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
74 				ERROR("exceed support suspend gpio number\n");
75 				break;
76 			}
77 			gpio_param = (struct bl31_gpio_param *)bl2_param;
78 			memcpy(&suspend_gpio[suspend_gpio_cnt],
79 			       &gpio_param->gpio,
80 			       sizeof(struct gpio_info));
81 			suspend_gpio_cnt++;
82 			break;
83 		case PARAM_SUSPEND_APIO:
84 			memcpy(&param_apio, bl2_param,
85 			       sizeof(struct bl31_apio_param));
86 			suspend_apio = &param_apio.apio;
87 			break;
88 #if COREBOOT
89 		case PARAM_COREBOOT_TABLE:
90 			coreboot_table_setup((void *)
91 				((struct bl31_u64_param *)bl2_param)->value);
92 			break;
93 #endif
94 		default:
95 			ERROR("not expected type found %lld\n",
96 			      bl2_param->type);
97 			break;
98 		}
99 		bl2_param = bl2_param->next;
100 	}
101 }
102