blob: dda98d962bb68e85293fd09e365b2c80fa3283bc [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>
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010014#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/coreboot.h>
16#include <lib/mmio.h>
17#include <plat/common/platform.h>
18
Caesar Wang3e3c5b02016-05-25 19:03:04 +080019#include <plat_params.h>
20#include <plat_private.h>
Caesar Wang3e3c5b02016-05-25 19:03:04 +080021
Caesar Wangef180072016-09-10 02:43:15 +080022static struct gpio_info param_reset;
23static struct gpio_info param_poweroff;
Caesar Wang5045a1c2016-09-10 02:47:53 +080024static struct bl31_apio_param param_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080025static struct gpio_info *rst_gpio;
26static struct gpio_info *poweroff_gpio;
Caesar Wangef180072016-09-10 02:43:15 +080027static struct gpio_info suspend_gpio[10];
28uint32_t suspend_gpio_cnt;
Caesar Wang5045a1c2016-09-10 02:47:53 +080029static struct apio_info *suspend_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080030
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010031static uint8_t fdt_buffer[0x10000];
32
33void *plat_get_fdt(void)
34{
35 return &fdt_buffer[0];
36}
37
Caesar Wangef180072016-09-10 02:43:15 +080038struct gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080039{
40 return rst_gpio;
41}
42
Caesar Wangef180072016-09-10 02:43:15 +080043struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080044{
45 return poweroff_gpio;
46}
47
Caesar Wangef180072016-09-10 02:43:15 +080048struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
49{
50 *count = suspend_gpio_cnt;
51
52 return &suspend_gpio[0];
53}
54
Caesar Wang5045a1c2016-09-10 02:47:53 +080055struct apio_info *plat_get_rockchip_suspend_apio(void)
56{
57 return suspend_apio;
58}
59
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010060static int dt_process_fdt(void *blob)
61{
62 void *fdt = plat_get_fdt();
63 int ret;
64
65 ret = fdt_open_into(blob, fdt, 0x10000);
66 if (ret < 0)
67 return ret;
68
69 return 0;
70}
71
Caesar Wang3e3c5b02016-05-25 19:03:04 +080072void params_early_setup(void *plat_param_from_bl2)
73{
Caesar Wang3e3c5b02016-05-25 19:03:04 +080074 struct bl31_plat_param *bl2_param;
75 struct bl31_gpio_param *gpio_param;
76
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010077 /*
78 * Test if this is a FDT passed as a platform-specific parameter
79 * block.
80 */
81 if (!dt_process_fdt(plat_param_from_bl2))
82 return;
83
Caesar Wang3e3c5b02016-05-25 19:03:04 +080084 /* keep plat parameters for later processing if need */
85 bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
86 while (bl2_param) {
87 switch (bl2_param->type) {
88 case PARAM_RESET:
Caesar Wangef180072016-09-10 02:43:15 +080089 gpio_param = (struct bl31_gpio_param *)bl2_param;
90 memcpy(&param_reset, &gpio_param->gpio,
91 sizeof(struct gpio_info));
92 rst_gpio = &param_reset;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080093 break;
94 case PARAM_POWEROFF:
Caesar Wangef180072016-09-10 02:43:15 +080095 gpio_param = (struct bl31_gpio_param *)bl2_param;
96 memcpy(&param_poweroff, &gpio_param->gpio,
97 sizeof(struct gpio_info));
98 poweroff_gpio = &param_poweroff;
99 break;
100 case PARAM_SUSPEND_GPIO:
101 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
102 ERROR("exceed support suspend gpio number\n");
103 break;
104 }
105 gpio_param = (struct bl31_gpio_param *)bl2_param;
106 memcpy(&suspend_gpio[suspend_gpio_cnt],
107 &gpio_param->gpio,
108 sizeof(struct gpio_info));
109 suspend_gpio_cnt++;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800110 break;
Caesar Wang5045a1c2016-09-10 02:47:53 +0800111 case PARAM_SUSPEND_APIO:
112 memcpy(&param_apio, bl2_param,
113 sizeof(struct bl31_apio_param));
114 suspend_apio = &param_apio.apio;
115 break;
Julius Wernerc7087782017-06-09 15:22:44 -0700116#if COREBOOT
117 case PARAM_COREBOOT_TABLE:
118 coreboot_table_setup((void *)
119 ((struct bl31_u64_param *)bl2_param)->value);
120 break;
121#endif
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800122 default:
Masahiro Yamadae93a0f42018-02-02 15:09:36 +0900123 ERROR("not expected type found %lld\n",
Caesar Wangef180072016-09-10 02:43:15 +0800124 bl2_param->type);
125 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800126 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800127 bl2_param = bl2_param->next;
128 }
129}