Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 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> |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 14 | #include <libfdt.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <lib/coreboot.h> |
| 16 | #include <lib/mmio.h> |
| 17 | #include <plat/common/platform.h> |
| 18 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 19 | #include <plat_params.h> |
| 20 | #include <plat_private.h> |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 21 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 22 | static struct gpio_info param_reset; |
| 23 | static struct gpio_info param_poweroff; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 24 | static struct bl31_apio_param param_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 25 | static struct gpio_info *rst_gpio; |
| 26 | static struct gpio_info *poweroff_gpio; |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 27 | static struct gpio_info suspend_gpio[10]; |
| 28 | uint32_t suspend_gpio_cnt; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 29 | static struct apio_info *suspend_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 30 | |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 31 | static uint8_t fdt_buffer[0x10000]; |
| 32 | |
| 33 | void *plat_get_fdt(void) |
| 34 | { |
| 35 | return &fdt_buffer[0]; |
| 36 | } |
| 37 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 38 | struct gpio_info *plat_get_rockchip_gpio_reset(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 39 | { |
| 40 | return rst_gpio; |
| 41 | } |
| 42 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 43 | struct gpio_info *plat_get_rockchip_gpio_poweroff(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 44 | { |
| 45 | return poweroff_gpio; |
| 46 | } |
| 47 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 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 | |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 55 | struct apio_info *plat_get_rockchip_suspend_apio(void) |
| 56 | { |
| 57 | return suspend_apio; |
| 58 | } |
| 59 | |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 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 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 72 | void params_early_setup(void *plat_param_from_bl2) |
| 73 | { |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 74 | struct bl31_plat_param *bl2_param; |
| 75 | struct bl31_gpio_param *gpio_param; |
| 76 | |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 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 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 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: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 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; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 93 | break; |
| 94 | case PARAM_POWEROFF: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 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++; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 110 | break; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 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; |
Julius Werner | c708778 | 2017-06-09 15:22:44 -0700 | [diff] [blame] | 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 |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 122 | default: |
Masahiro Yamada | e93a0f4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 123 | ERROR("not expected type found %lld\n", |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 124 | bl2_param->type); |
| 125 | break; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 126 | } |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 127 | bl2_param = bl2_param->next; |
| 128 | } |
| 129 | } |