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