blob: 3d1b40b3ffc04fe9012879adab588ea65af14f51 [file] [log] [blame]
Caesar Wang3e3c5b02016-05-25 19:03:04 +08001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Caesar Wang3e3c5b02016-05-25 19:03:04 +08005 */
6
Caesar Wang3e3c5b02016-05-25 19:03:04 +08007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <string.h>
9
10#include <common/bl_common.h>
11#include <common/debug.h>
12#include <drivers/console.h>
13#include <drivers/gpio.h>
14#include <lib/coreboot.h>
15#include <lib/mmio.h>
16#include <plat/common/platform.h>
17
Caesar Wang3e3c5b02016-05-25 19:03:04 +080018#include <plat_params.h>
19#include <plat_private.h>
Caesar Wang3e3c5b02016-05-25 19:03:04 +080020
Caesar Wangef180072016-09-10 02:43:15 +080021static struct gpio_info param_reset;
22static struct gpio_info param_poweroff;
Caesar Wang5045a1c2016-09-10 02:47:53 +080023static struct bl31_apio_param param_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080024static struct gpio_info *rst_gpio;
25static struct gpio_info *poweroff_gpio;
Caesar Wangef180072016-09-10 02:43:15 +080026static struct gpio_info suspend_gpio[10];
27uint32_t suspend_gpio_cnt;
Caesar Wang5045a1c2016-09-10 02:47:53 +080028static struct apio_info *suspend_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080029
Caesar Wangef180072016-09-10 02:43:15 +080030struct gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080031{
32 return rst_gpio;
33}
34
Caesar Wangef180072016-09-10 02:43:15 +080035struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080036{
37 return poweroff_gpio;
38}
39
Caesar Wangef180072016-09-10 02:43:15 +080040struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
41{
42 *count = suspend_gpio_cnt;
43
44 return &suspend_gpio[0];
45}
46
Caesar Wang5045a1c2016-09-10 02:47:53 +080047struct apio_info *plat_get_rockchip_suspend_apio(void)
48{
49 return suspend_apio;
50}
51
Caesar Wang3e3c5b02016-05-25 19:03:04 +080052void params_early_setup(void *plat_param_from_bl2)
53{
Caesar Wang3e3c5b02016-05-25 19:03:04 +080054 struct bl31_plat_param *bl2_param;
55 struct bl31_gpio_param *gpio_param;
56
57 /* keep plat parameters for later processing if need */
58 bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
59 while (bl2_param) {
60 switch (bl2_param->type) {
61 case PARAM_RESET:
Caesar Wangef180072016-09-10 02:43:15 +080062 gpio_param = (struct bl31_gpio_param *)bl2_param;
63 memcpy(&param_reset, &gpio_param->gpio,
64 sizeof(struct gpio_info));
65 rst_gpio = &param_reset;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080066 break;
67 case PARAM_POWEROFF:
Caesar Wangef180072016-09-10 02:43:15 +080068 gpio_param = (struct bl31_gpio_param *)bl2_param;
69 memcpy(&param_poweroff, &gpio_param->gpio,
70 sizeof(struct gpio_info));
71 poweroff_gpio = &param_poweroff;
72 break;
73 case PARAM_SUSPEND_GPIO:
74 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
75 ERROR("exceed support suspend gpio number\n");
76 break;
77 }
78 gpio_param = (struct bl31_gpio_param *)bl2_param;
79 memcpy(&suspend_gpio[suspend_gpio_cnt],
80 &gpio_param->gpio,
81 sizeof(struct gpio_info));
82 suspend_gpio_cnt++;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080083 break;
Caesar Wang5045a1c2016-09-10 02:47:53 +080084 case PARAM_SUSPEND_APIO:
85 memcpy(&param_apio, bl2_param,
86 sizeof(struct bl31_apio_param));
87 suspend_apio = &param_apio.apio;
88 break;
Julius Wernerc7087782017-06-09 15:22:44 -070089#if COREBOOT
90 case PARAM_COREBOOT_TABLE:
91 coreboot_table_setup((void *)
92 ((struct bl31_u64_param *)bl2_param)->value);
93 break;
94#endif
Caesar Wang3e3c5b02016-05-25 19:03:04 +080095 default:
Masahiro Yamadae93a0f42018-02-02 15:09:36 +090096 ERROR("not expected type found %lld\n",
Caesar Wangef180072016-09-10 02:43:15 +080097 bl2_param->type);
98 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080099 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800100 bl2_param = bl2_param->next;
101 }
102}