1 /* 2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #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 <libfdt.h> 15 #include <lib/coreboot.h> 16 #include <lib/mmio.h> 17 #include <plat/common/platform.h> 18 19 #include <plat_params.h> 20 #include <plat_private.h> 21 22 static struct gpio_info param_reset; 23 static struct gpio_info param_poweroff; 24 static struct bl31_apio_param param_apio; 25 static struct gpio_info *rst_gpio; 26 static struct gpio_info *poweroff_gpio; 27 static struct gpio_info suspend_gpio[10]; 28 uint32_t suspend_gpio_cnt; 29 static struct apio_info *suspend_apio; 30 31 static uint8_t fdt_buffer[0x10000]; 32 33 void *plat_get_fdt(void) 34 { 35 return &fdt_buffer[0]; 36 } 37 38 struct gpio_info *plat_get_rockchip_gpio_reset(void) 39 { 40 return rst_gpio; 41 } 42 43 struct gpio_info *plat_get_rockchip_gpio_poweroff(void) 44 { 45 return poweroff_gpio; 46 } 47 48 struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) 49 { 50 *count = suspend_gpio_cnt; 51 52 return &suspend_gpio[0]; 53 } 54 55 struct apio_info *plat_get_rockchip_suspend_apio(void) 56 { 57 return suspend_apio; 58 } 59 60 static 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 72 void params_early_setup(void *plat_param_from_bl2) 73 { 74 struct bl31_plat_param *bl2_param; 75 struct bl31_gpio_param *gpio_param; 76 77 /* 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 84 /* 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: 89 gpio_param = (struct bl31_gpio_param *)bl2_param; 90 memcpy(¶m_reset, &gpio_param->gpio, 91 sizeof(struct gpio_info)); 92 rst_gpio = ¶m_reset; 93 break; 94 case PARAM_POWEROFF: 95 gpio_param = (struct bl31_gpio_param *)bl2_param; 96 memcpy(¶m_poweroff, &gpio_param->gpio, 97 sizeof(struct gpio_info)); 98 poweroff_gpio = ¶m_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++; 110 break; 111 case PARAM_SUSPEND_APIO: 112 memcpy(¶m_apio, bl2_param, 113 sizeof(struct bl31_apio_param)); 114 suspend_apio = ¶m_apio.apio; 115 break; 116 #if COREBOOT 117 case PARAM_COREBOOT_TABLE: 118 coreboot_table_setup((void *) 119 ((struct bl31_u64_param *)bl2_param)->value); 120 break; 121 #endif 122 default: 123 ERROR("not expected type found %lld\n", 124 bl2_param->type); 125 break; 126 } 127 bl2_param = bl2_param->next; 128 } 129 } 130