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> |
| 14 | #include <lib/coreboot.h> |
| 15 | #include <lib/mmio.h> |
| 16 | #include <plat/common/platform.h> |
| 17 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 18 | #include <plat_params.h> |
| 19 | #include <plat_private.h> |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 20 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 21 | static struct gpio_info param_reset; |
| 22 | static struct gpio_info param_poweroff; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 23 | static struct bl31_apio_param param_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 24 | static struct gpio_info *rst_gpio; |
| 25 | static struct gpio_info *poweroff_gpio; |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 26 | static struct gpio_info suspend_gpio[10]; |
| 27 | uint32_t suspend_gpio_cnt; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 28 | static struct apio_info *suspend_apio; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 29 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 30 | struct gpio_info *plat_get_rockchip_gpio_reset(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 31 | { |
| 32 | return rst_gpio; |
| 33 | } |
| 34 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 35 | struct gpio_info *plat_get_rockchip_gpio_poweroff(void) |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 36 | { |
| 37 | return poweroff_gpio; |
| 38 | } |
| 39 | |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 40 | struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) |
| 41 | { |
| 42 | *count = suspend_gpio_cnt; |
| 43 | |
| 44 | return &suspend_gpio[0]; |
| 45 | } |
| 46 | |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 47 | struct apio_info *plat_get_rockchip_suspend_apio(void) |
| 48 | { |
| 49 | return suspend_apio; |
| 50 | } |
| 51 | |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 52 | void params_early_setup(void *plat_param_from_bl2) |
| 53 | { |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 54 | struct bl31_plat_param *bl2_param; |
| 55 | struct bl31_gpio_param *gpio_param; |
| 56 | |
| 57 | /* keep plat parameters for later processing if need */ |
| 58 | bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; |
| 59 | while (bl2_param) { |
| 60 | switch (bl2_param->type) { |
| 61 | case PARAM_RESET: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 62 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 63 | memcpy(¶m_reset, &gpio_param->gpio, |
| 64 | sizeof(struct gpio_info)); |
| 65 | rst_gpio = ¶m_reset; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 66 | break; |
| 67 | case PARAM_POWEROFF: |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 68 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 69 | memcpy(¶m_poweroff, &gpio_param->gpio, |
| 70 | sizeof(struct gpio_info)); |
| 71 | poweroff_gpio = ¶m_poweroff; |
| 72 | break; |
| 73 | case PARAM_SUSPEND_GPIO: |
| 74 | if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { |
| 75 | ERROR("exceed support suspend gpio number\n"); |
| 76 | break; |
| 77 | } |
| 78 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 79 | memcpy(&suspend_gpio[suspend_gpio_cnt], |
| 80 | &gpio_param->gpio, |
| 81 | sizeof(struct gpio_info)); |
| 82 | suspend_gpio_cnt++; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 83 | break; |
Caesar Wang | 5045a1c | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 84 | case PARAM_SUSPEND_APIO: |
| 85 | memcpy(¶m_apio, bl2_param, |
| 86 | sizeof(struct bl31_apio_param)); |
| 87 | suspend_apio = ¶m_apio.apio; |
| 88 | break; |
Julius Werner | c708778 | 2017-06-09 15:22:44 -0700 | [diff] [blame] | 89 | #if COREBOOT |
| 90 | case PARAM_COREBOOT_TABLE: |
| 91 | coreboot_table_setup((void *) |
| 92 | ((struct bl31_u64_param *)bl2_param)->value); |
| 93 | break; |
| 94 | #endif |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 95 | default: |
Masahiro Yamada | e93a0f4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 96 | ERROR("not expected type found %lld\n", |
Caesar Wang | ef18007 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 97 | bl2_param->type); |
| 98 | break; |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 99 | } |
Caesar Wang | 3e3c5b0 | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 100 | bl2_param = bl2_param->next; |
| 101 | } |
| 102 | } |