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 <debug.h>
12 #include <gpio.h>
13 #include <mmio.h>
14 #include <plat_params.h>
15 #include <plat_private.h>
16 #include <platform.h>
17 #include <string.h>
18 
19 static struct gpio_info param_reset;
20 static struct gpio_info param_poweroff;
21 static struct bl31_apio_param param_apio;
22 static struct gpio_info *rst_gpio;
23 static struct gpio_info *poweroff_gpio;
24 static struct gpio_info suspend_gpio[10];
25 uint32_t suspend_gpio_cnt;
26 static struct apio_info *suspend_apio;
27 
plat_get_rockchip_gpio_reset(void)28 struct gpio_info *plat_get_rockchip_gpio_reset(void)
29 {
30 	return rst_gpio;
31 }
32 
plat_get_rockchip_gpio_poweroff(void)33 struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
34 {
35 	return poweroff_gpio;
36 }
37 
plat_get_rockchip_suspend_gpio(uint32_t * count)38 struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
39 {
40 	*count = suspend_gpio_cnt;
41 
42 	return &suspend_gpio[0];
43 }
44 
plat_get_rockchip_suspend_apio(void)45 struct apio_info *plat_get_rockchip_suspend_apio(void)
46 {
47 	return suspend_apio;
48 }
49 
params_early_setup(void * plat_param_from_bl2)50 void params_early_setup(void *plat_param_from_bl2)
51 {
52 	struct bl31_plat_param *bl2_param;
53 	struct bl31_gpio_param *gpio_param;
54 
55 	/* keep plat parameters for later processing if need */
56 	bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
57 	while (bl2_param) {
58 		switch (bl2_param->type) {
59 		case PARAM_RESET:
60 			gpio_param = (struct bl31_gpio_param *)bl2_param;
61 			memcpy(&param_reset, &gpio_param->gpio,
62 			       sizeof(struct gpio_info));
63 			rst_gpio = &param_reset;
64 			break;
65 		case PARAM_POWEROFF:
66 			gpio_param = (struct bl31_gpio_param *)bl2_param;
67 			memcpy(&param_poweroff, &gpio_param->gpio,
68 				sizeof(struct gpio_info));
69 			poweroff_gpio = &param_poweroff;
70 			break;
71 		case PARAM_SUSPEND_GPIO:
72 			if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
73 				ERROR("exceed support suspend gpio number\n");
74 				break;
75 			}
76 			gpio_param = (struct bl31_gpio_param *)bl2_param;
77 			memcpy(&suspend_gpio[suspend_gpio_cnt],
78 			       &gpio_param->gpio,
79 			       sizeof(struct gpio_info));
80 			suspend_gpio_cnt++;
81 			break;
82 		case PARAM_SUSPEND_APIO:
83 			memcpy(&param_apio, bl2_param,
84 			       sizeof(struct bl31_apio_param));
85 			suspend_apio = &param_apio.apio;
86 			break;
87 		default:
88 			ERROR("not expected type found %ld\n",
89 			      bl2_param->type);
90 			break;
91 		}
92 		bl2_param = bl2_param->next;
93 	}
94 }
95