blob: d0fea4ffa6500dd91d3a69bf539a5fa62fb02e99 [file] [log] [blame]
Caesar Wang3e3c5b02016-05-25 19:03:04 +08001/*
Julius Werner65d52672019-05-24 20:37:58 -07002 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
Caesar Wang3e3c5b02016-05-25 19:03:04 +08003 *
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>
Heiko Stuebner6fd5b942019-04-24 20:26:51 +02008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
Julius Werner65d52672019-05-24 20:37:58 -070011#include <lib/bl_aux_params/bl_aux_params.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <common/bl_common.h>
13#include <common/debug.h>
14#include <drivers/console.h>
15#include <drivers/gpio.h>
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010016#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <lib/coreboot.h>
18#include <lib/mmio.h>
19#include <plat/common/platform.h>
20
Caesar Wang3e3c5b02016-05-25 19:03:04 +080021#include <plat_params.h>
22#include <plat_private.h>
Caesar Wang3e3c5b02016-05-25 19:03:04 +080023
Julius Werner65d52672019-05-24 20:37:58 -070024static struct bl_aux_gpio_info rst_gpio;
25static struct bl_aux_gpio_info poweroff_gpio;
26static struct bl_aux_gpio_info suspend_gpio[10];
Caesar Wangef180072016-09-10 02:43:15 +080027uint32_t suspend_gpio_cnt;
Julius Werner65d52672019-05-24 20:37:58 -070028static struct bl_aux_rk_apio_info suspend_apio;
Christoph Müllnercb9204a2019-04-19 14:16:27 +020029static uint32_t rk_uart_base = PLAT_RK_UART_BASE;
30
31uint32_t rockchip_get_uart_base(void)
32{
33 return rk_uart_base;
34}
Caesar Wang3e3c5b02016-05-25 19:03:04 +080035
Heiko Stuebner6fd5b942019-04-24 20:26:51 +020036#if COREBOOT
Julius Werner65d52672019-05-24 20:37:58 -070037static int dt_process_fdt(u_register_t param_from_bl2)
Heiko Stuebner6fd5b942019-04-24 20:26:51 +020038{
39 return -ENODEV;
40}
41#else
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010042static uint8_t fdt_buffer[0x10000];
43
44void *plat_get_fdt(void)
45{
46 return &fdt_buffer[0];
47}
48
Christoph Müllnercb9204a2019-04-19 14:16:27 +020049static void plat_rockchip_dt_process_fdt_uart(void *fdt)
50{
51 const char *path_name = "/chosen";
52 const char *prop_name = "stdout-path";
53 int node_offset;
54 int stdout_path_len;
55 const char *stdout_path;
56 char serial_char;
57 int serial_no;
58 uint32_t uart_base;
59
60 node_offset = fdt_path_offset(fdt, path_name);
61 if (node_offset < 0)
62 return;
63
64 stdout_path = fdt_getprop(fdt, node_offset, prop_name,
65 &stdout_path_len);
66 if (stdout_path == NULL)
67 return;
68
69 /*
70 * We expect something like:
71 * "serial0:...""
72 */
73 if (strncmp("serial", stdout_path, 6) != 0)
74 return;
75
76 serial_char = stdout_path[6];
77 serial_no = serial_char - '0';
78
79 switch (serial_no) {
80 case 0:
81 uart_base = UART0_BASE;
82 break;
83 case 1:
84 uart_base = UART1_BASE;
85 break;
86 case 2:
87 uart_base = UART2_BASE;
88 break;
89#ifdef UART3_BASE
90 case 3:
91 uart_base = UART3_BASE;
92 break;
93#endif
94#ifdef UART4_BASE
95 case 4:
96 uart_base = UART4_BASE;
97 break;
98#endif
99 default:
100 return;
101 }
102
103 rk_uart_base = uart_base;
104}
105
Julius Werner65d52672019-05-24 20:37:58 -0700106static int dt_process_fdt(u_register_t param_from_bl2)
Heiko Stuebner6fd5b942019-04-24 20:26:51 +0200107{
108 void *fdt = plat_get_fdt();
109 int ret;
110
Julius Werner65d52672019-05-24 20:37:58 -0700111 ret = fdt_open_into((void *)param_from_bl2, fdt, 0x10000);
Heiko Stuebner6fd5b942019-04-24 20:26:51 +0200112 if (ret < 0)
113 return ret;
114
Christoph Müllnercb9204a2019-04-19 14:16:27 +0200115 plat_rockchip_dt_process_fdt_uart(fdt);
116
Heiko Stuebner6fd5b942019-04-24 20:26:51 +0200117 return 0;
118}
119#endif
120
Julius Werner65d52672019-05-24 20:37:58 -0700121struct bl_aux_gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800122{
Julius Werner65d52672019-05-24 20:37:58 -0700123 return &rst_gpio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800124}
125
Julius Werner65d52672019-05-24 20:37:58 -0700126struct bl_aux_gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800127{
Julius Werner65d52672019-05-24 20:37:58 -0700128 return &poweroff_gpio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800129}
130
Julius Werner65d52672019-05-24 20:37:58 -0700131struct bl_aux_gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
Caesar Wangef180072016-09-10 02:43:15 +0800132{
133 *count = suspend_gpio_cnt;
134
135 return &suspend_gpio[0];
136}
137
Julius Werner65d52672019-05-24 20:37:58 -0700138struct bl_aux_rk_apio_info *plat_get_rockchip_suspend_apio(void)
Caesar Wang5045a1c2016-09-10 02:47:53 +0800139{
Julius Werner65d52672019-05-24 20:37:58 -0700140 return &suspend_apio;
Caesar Wang5045a1c2016-09-10 02:47:53 +0800141}
142
Julius Werner65d52672019-05-24 20:37:58 -0700143static bool rk_aux_param_handler(struct bl_aux_param_header *param)
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800144{
Julius Werner65d52672019-05-24 20:37:58 -0700145 /* Store platform parameters for later processing if needed. */
146 switch (param->type) {
147 case BL_AUX_PARAM_RK_RESET_GPIO:
148 rst_gpio = ((struct bl_aux_param_gpio *)param)->gpio;
149 return true;
150 case BL_AUX_PARAM_RK_POWEROFF_GPIO:
151 poweroff_gpio = ((struct bl_aux_param_gpio *)param)->gpio;
152 return true;
153 case BL_AUX_PARAM_RK_SUSPEND_GPIO:
154 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
155 ERROR("Exceeded the supported suspend GPIO number.\n");
156 return true;
157 }
158 suspend_gpio[suspend_gpio_cnt++] =
159 ((struct bl_aux_param_gpio *)param)->gpio;
160 return true;
161 case BL_AUX_PARAM_RK_SUSPEND_APIO:
162 suspend_apio = ((struct bl_aux_param_rk_apio *)param)->apio;
163 return true;
164 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800165
Julius Werner65d52672019-05-24 20:37:58 -0700166 return false;
167}
168
169void params_early_setup(u_register_t plat_param_from_bl2)
170{
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +0100171 /*
172 * Test if this is a FDT passed as a platform-specific parameter
173 * block.
174 */
175 if (!dt_process_fdt(plat_param_from_bl2))
176 return;
177
Julius Werner65d52672019-05-24 20:37:58 -0700178 bl_aux_params_parse(plat_param_from_bl2, rk_aux_param_handler);
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800179}