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> |
Heiko Stuebner | 6fd5b94 | 2019-04-24 20:26:51 +0200 | [diff] [blame^] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #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 Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 15 | #include <libfdt.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <lib/coreboot.h> |
| 17 | #include <lib/mmio.h> |
| 18 | #include <plat/common/platform.h> |
| 19 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 20 | #include <plat_params.h> |
| 21 | #include <plat_private.h> |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 22 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 23 | static struct gpio_info param_reset; |
| 24 | static struct gpio_info param_poweroff; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 25 | static struct bl31_apio_param param_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 26 | static struct gpio_info *rst_gpio; |
| 27 | static struct gpio_info *poweroff_gpio; |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 28 | static struct gpio_info suspend_gpio[10]; |
| 29 | uint32_t suspend_gpio_cnt; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 30 | static struct apio_info *suspend_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 31 | |
Heiko Stuebner | 6fd5b94 | 2019-04-24 20:26:51 +0200 | [diff] [blame^] | 32 | #if COREBOOT |
| 33 | static int dt_process_fdt(void *blob) |
| 34 | { |
| 35 | return -ENODEV; |
| 36 | } |
| 37 | #else |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 38 | static uint8_t fdt_buffer[0x10000]; |
| 39 | |
| 40 | void *plat_get_fdt(void) |
| 41 | { |
| 42 | return &fdt_buffer[0]; |
| 43 | } |
| 44 | |
Heiko Stuebner | 6fd5b94 | 2019-04-24 20:26:51 +0200 | [diff] [blame^] | 45 | static int dt_process_fdt(void *blob) |
| 46 | { |
| 47 | void *fdt = plat_get_fdt(); |
| 48 | int ret; |
| 49 | |
| 50 | ret = fdt_open_into(blob, fdt, 0x10000); |
| 51 | if (ret < 0) |
| 52 | return ret; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | #endif |
| 57 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 58 | struct gpio_info *plat_get_rockchip_gpio_reset(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 59 | { |
| 60 | return rst_gpio; |
| 61 | } |
| 62 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 63 | struct gpio_info *plat_get_rockchip_gpio_poweroff(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 64 | { |
| 65 | return poweroff_gpio; |
| 66 | } |
| 67 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 68 | struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) |
| 69 | { |
| 70 | *count = suspend_gpio_cnt; |
| 71 | |
| 72 | return &suspend_gpio[0]; |
| 73 | } |
| 74 | |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 75 | struct apio_info *plat_get_rockchip_suspend_apio(void) |
| 76 | { |
| 77 | return suspend_apio; |
| 78 | } |
| 79 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 80 | void params_early_setup(void *plat_param_from_bl2) |
| 81 | { |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 82 | struct bl31_plat_param *bl2_param; |
| 83 | struct bl31_gpio_param *gpio_param; |
| 84 | |
Heiko Stuebner | bbd0f5a | 2019-03-07 08:07:11 +0100 | [diff] [blame] | 85 | /* |
| 86 | * Test if this is a FDT passed as a platform-specific parameter |
| 87 | * block. |
| 88 | */ |
| 89 | if (!dt_process_fdt(plat_param_from_bl2)) |
| 90 | return; |
| 91 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 92 | /* keep plat parameters for later processing if need */ |
| 93 | bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; |
| 94 | while (bl2_param) { |
| 95 | switch (bl2_param->type) { |
| 96 | case PARAM_RESET: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 97 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 98 | memcpy(¶m_reset, &gpio_param->gpio, |
| 99 | sizeof(struct gpio_info)); |
| 100 | rst_gpio = ¶m_reset; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 101 | break; |
| 102 | case PARAM_POWEROFF: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 103 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 104 | memcpy(¶m_poweroff, &gpio_param->gpio, |
| 105 | sizeof(struct gpio_info)); |
| 106 | poweroff_gpio = ¶m_poweroff; |
| 107 | break; |
| 108 | case PARAM_SUSPEND_GPIO: |
| 109 | if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { |
| 110 | ERROR("exceed support suspend gpio number\n"); |
| 111 | break; |
| 112 | } |
| 113 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 114 | memcpy(&suspend_gpio[suspend_gpio_cnt], |
| 115 | &gpio_param->gpio, |
| 116 | sizeof(struct gpio_info)); |
| 117 | suspend_gpio_cnt++; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 118 | break; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 119 | case PARAM_SUSPEND_APIO: |
| 120 | memcpy(¶m_apio, bl2_param, |
| 121 | sizeof(struct bl31_apio_param)); |
| 122 | suspend_apio = ¶m_apio.apio; |
| 123 | break; |
Julius Werner | c708778 | 2017-06-09 15:22:44 -0700 | [diff] [blame] | 124 | #if COREBOOT |
| 125 | case PARAM_COREBOOT_TABLE: |
| 126 | coreboot_table_setup((void *) |
| 127 | ((struct bl31_u64_param *)bl2_param)->value); |
| 128 | break; |
| 129 | #endif |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 130 | default: |
Masahiro Yamada | e93a0f4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 131 | ERROR("not expected type found %lld\n", |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 132 | bl2_param->type); |
| 133 | break; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 134 | } |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 135 | bl2_param = bl2_param->next; |
| 136 | } |
| 137 | } |