Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arm_gic.h> |
| 8 | #include <assert.h> |
| 9 | #include <bl_common.h> |
| 10 | #include <console.h> |
Julius Werner | 3c250b9 | 2017-06-09 15:22:44 -0700 | [diff] [blame] | 11 | #include <coreboot.h> |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 12 | #include <debug.h> |
| 13 | #include <gpio.h> |
| 14 | #include <mmio.h> |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 15 | #include <plat_params.h> |
| 16 | #include <plat_private.h> |
Isla Mitchell | ee1ebbd | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 17 | #include <platform.h> |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 18 | #include <string.h> |
| 19 | |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 20 | static struct gpio_info param_reset; |
| 21 | static struct gpio_info param_poweroff; |
Caesar Wang | 2bff35b | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 22 | static struct bl31_apio_param param_apio; |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 23 | static struct gpio_info *rst_gpio; |
| 24 | static struct gpio_info *poweroff_gpio; |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 25 | static struct gpio_info suspend_gpio[10]; |
| 26 | uint32_t suspend_gpio_cnt; |
Caesar Wang | 2bff35b | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 27 | static struct apio_info *suspend_apio; |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 28 | |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 29 | struct gpio_info *plat_get_rockchip_gpio_reset(void) |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 30 | { |
| 31 | return rst_gpio; |
| 32 | } |
| 33 | |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 34 | struct gpio_info *plat_get_rockchip_gpio_poweroff(void) |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 35 | { |
| 36 | return poweroff_gpio; |
| 37 | } |
| 38 | |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 39 | struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) |
| 40 | { |
| 41 | *count = suspend_gpio_cnt; |
| 42 | |
| 43 | return &suspend_gpio[0]; |
| 44 | } |
| 45 | |
Caesar Wang | 2bff35b | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 46 | struct apio_info *plat_get_rockchip_suspend_apio(void) |
| 47 | { |
| 48 | return suspend_apio; |
| 49 | } |
| 50 | |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 51 | void params_early_setup(void *plat_param_from_bl2) |
| 52 | { |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 53 | struct bl31_plat_param *bl2_param; |
| 54 | struct bl31_gpio_param *gpio_param; |
| 55 | |
| 56 | /* keep plat parameters for later processing if need */ |
| 57 | bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; |
| 58 | while (bl2_param) { |
| 59 | switch (bl2_param->type) { |
| 60 | case PARAM_RESET: |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 61 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 62 | memcpy(¶m_reset, &gpio_param->gpio, |
| 63 | sizeof(struct gpio_info)); |
| 64 | rst_gpio = ¶m_reset; |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 65 | break; |
| 66 | case PARAM_POWEROFF: |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 67 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 68 | memcpy(¶m_poweroff, &gpio_param->gpio, |
| 69 | sizeof(struct gpio_info)); |
| 70 | poweroff_gpio = ¶m_poweroff; |
| 71 | break; |
| 72 | case PARAM_SUSPEND_GPIO: |
| 73 | if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { |
| 74 | ERROR("exceed support suspend gpio number\n"); |
| 75 | break; |
| 76 | } |
| 77 | gpio_param = (struct bl31_gpio_param *)bl2_param; |
| 78 | memcpy(&suspend_gpio[suspend_gpio_cnt], |
| 79 | &gpio_param->gpio, |
| 80 | sizeof(struct gpio_info)); |
| 81 | suspend_gpio_cnt++; |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 82 | break; |
Caesar Wang | 2bff35b | 2016-09-10 02:47:53 +0800 | [diff] [blame] | 83 | case PARAM_SUSPEND_APIO: |
| 84 | memcpy(¶m_apio, bl2_param, |
| 85 | sizeof(struct bl31_apio_param)); |
| 86 | suspend_apio = ¶m_apio.apio; |
| 87 | break; |
Julius Werner | 3c250b9 | 2017-06-09 15:22:44 -0700 | [diff] [blame] | 88 | #if COREBOOT |
| 89 | case PARAM_COREBOOT_TABLE: |
| 90 | coreboot_table_setup((void *) |
| 91 | ((struct bl31_u64_param *)bl2_param)->value); |
| 92 | break; |
| 93 | #endif |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 94 | default: |
Masahiro Yamada | 0a2d5b4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 95 | ERROR("not expected type found %lld\n", |
Caesar Wang | e550c63 | 2016-09-10 02:43:15 +0800 | [diff] [blame] | 96 | bl2_param->type); |
| 97 | break; |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 98 | } |
Caesar Wang | 68ff45f | 2016-05-25 19:03:04 +0800 | [diff] [blame] | 99 | bl2_param = bl2_param->next; |
| 100 | } |
| 101 | } |