blob: 8a743bfee2901a62cfe039db737c5410f54d7c97 [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>
Heiko Stuebner6fd5b942019-04-24 20:26:51 +02008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
11#include <common/bl_common.h>
12#include <common/debug.h>
13#include <drivers/console.h>
14#include <drivers/gpio.h>
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010015#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <lib/coreboot.h>
17#include <lib/mmio.h>
18#include <plat/common/platform.h>
19
Caesar Wang3e3c5b02016-05-25 19:03:04 +080020#include <plat_params.h>
21#include <plat_private.h>
Caesar Wang3e3c5b02016-05-25 19:03:04 +080022
Caesar Wangef180072016-09-10 02:43:15 +080023static struct gpio_info param_reset;
24static struct gpio_info param_poweroff;
Caesar Wang5045a1c2016-09-10 02:47:53 +080025static struct bl31_apio_param param_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080026static struct gpio_info *rst_gpio;
27static struct gpio_info *poweroff_gpio;
Caesar Wangef180072016-09-10 02:43:15 +080028static struct gpio_info suspend_gpio[10];
29uint32_t suspend_gpio_cnt;
Caesar Wang5045a1c2016-09-10 02:47:53 +080030static struct apio_info *suspend_apio;
Christoph Müllnercb9204a2019-04-19 14:16:27 +020031static uint32_t rk_uart_base = PLAT_RK_UART_BASE;
32
33uint32_t rockchip_get_uart_base(void)
34{
35 return rk_uart_base;
36}
Caesar Wang3e3c5b02016-05-25 19:03:04 +080037
Heiko Stuebner6fd5b942019-04-24 20:26:51 +020038#if COREBOOT
39static int dt_process_fdt(void *blob)
40{
41 return -ENODEV;
42}
43#else
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +010044static uint8_t fdt_buffer[0x10000];
45
46void *plat_get_fdt(void)
47{
48 return &fdt_buffer[0];
49}
50
Christoph Müllnercb9204a2019-04-19 14:16:27 +020051static void plat_rockchip_dt_process_fdt_uart(void *fdt)
52{
53 const char *path_name = "/chosen";
54 const char *prop_name = "stdout-path";
55 int node_offset;
56 int stdout_path_len;
57 const char *stdout_path;
58 char serial_char;
59 int serial_no;
60 uint32_t uart_base;
61
62 node_offset = fdt_path_offset(fdt, path_name);
63 if (node_offset < 0)
64 return;
65
66 stdout_path = fdt_getprop(fdt, node_offset, prop_name,
67 &stdout_path_len);
68 if (stdout_path == NULL)
69 return;
70
71 /*
72 * We expect something like:
73 * "serial0:...""
74 */
75 if (strncmp("serial", stdout_path, 6) != 0)
76 return;
77
78 serial_char = stdout_path[6];
79 serial_no = serial_char - '0';
80
81 switch (serial_no) {
82 case 0:
83 uart_base = UART0_BASE;
84 break;
85 case 1:
86 uart_base = UART1_BASE;
87 break;
88 case 2:
89 uart_base = UART2_BASE;
90 break;
91#ifdef UART3_BASE
92 case 3:
93 uart_base = UART3_BASE;
94 break;
95#endif
96#ifdef UART4_BASE
97 case 4:
98 uart_base = UART4_BASE;
99 break;
100#endif
101 default:
102 return;
103 }
104
105 rk_uart_base = uart_base;
106}
107
Heiko Stuebner6fd5b942019-04-24 20:26:51 +0200108static int dt_process_fdt(void *blob)
109{
110 void *fdt = plat_get_fdt();
111 int ret;
112
113 ret = fdt_open_into(blob, fdt, 0x10000);
114 if (ret < 0)
115 return ret;
116
Christoph Müllnercb9204a2019-04-19 14:16:27 +0200117 plat_rockchip_dt_process_fdt_uart(fdt);
118
Heiko Stuebner6fd5b942019-04-24 20:26:51 +0200119 return 0;
120}
121#endif
122
Caesar Wangef180072016-09-10 02:43:15 +0800123struct gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800124{
125 return rst_gpio;
126}
127
Caesar Wangef180072016-09-10 02:43:15 +0800128struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800129{
130 return poweroff_gpio;
131}
132
Caesar Wangef180072016-09-10 02:43:15 +0800133struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
134{
135 *count = suspend_gpio_cnt;
136
137 return &suspend_gpio[0];
138}
139
Caesar Wang5045a1c2016-09-10 02:47:53 +0800140struct apio_info *plat_get_rockchip_suspend_apio(void)
141{
142 return suspend_apio;
143}
144
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800145void params_early_setup(void *plat_param_from_bl2)
146{
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800147 struct bl31_plat_param *bl2_param;
148 struct bl31_gpio_param *gpio_param;
149
Heiko Stuebnerbbd0f5a2019-03-07 08:07:11 +0100150 /*
151 * Test if this is a FDT passed as a platform-specific parameter
152 * block.
153 */
154 if (!dt_process_fdt(plat_param_from_bl2))
155 return;
156
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800157 /* keep plat parameters for later processing if need */
158 bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
159 while (bl2_param) {
160 switch (bl2_param->type) {
161 case PARAM_RESET:
Caesar Wangef180072016-09-10 02:43:15 +0800162 gpio_param = (struct bl31_gpio_param *)bl2_param;
163 memcpy(&param_reset, &gpio_param->gpio,
164 sizeof(struct gpio_info));
165 rst_gpio = &param_reset;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800166 break;
167 case PARAM_POWEROFF:
Caesar Wangef180072016-09-10 02:43:15 +0800168 gpio_param = (struct bl31_gpio_param *)bl2_param;
169 memcpy(&param_poweroff, &gpio_param->gpio,
170 sizeof(struct gpio_info));
171 poweroff_gpio = &param_poweroff;
172 break;
173 case PARAM_SUSPEND_GPIO:
174 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
175 ERROR("exceed support suspend gpio number\n");
176 break;
177 }
178 gpio_param = (struct bl31_gpio_param *)bl2_param;
179 memcpy(&suspend_gpio[suspend_gpio_cnt],
180 &gpio_param->gpio,
181 sizeof(struct gpio_info));
182 suspend_gpio_cnt++;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800183 break;
Caesar Wang5045a1c2016-09-10 02:47:53 +0800184 case PARAM_SUSPEND_APIO:
185 memcpy(&param_apio, bl2_param,
186 sizeof(struct bl31_apio_param));
187 suspend_apio = &param_apio.apio;
188 break;
Julius Wernerc7087782017-06-09 15:22:44 -0700189#if COREBOOT
190 case PARAM_COREBOOT_TABLE:
191 coreboot_table_setup((void *)
192 ((struct bl31_u64_param *)bl2_param)->value);
193 break;
194#endif
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800195 default:
Masahiro Yamadae93a0f42018-02-02 15:09:36 +0900196 ERROR("not expected type found %lld\n",
Caesar Wangef180072016-09-10 02:43:15 +0800197 bl2_param->type);
198 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800199 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800200 bl2_param = bl2_param->next;
201 }
202}