1 /* 2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of ARM nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <arm_gic.h> 32 #include <assert.h> 33 #include <bl_common.h> 34 #include <console.h> 35 #include <debug.h> 36 #include <gpio.h> 37 #include <mmio.h> 38 #include <platform.h> 39 #include <plat_params.h> 40 #include <plat_private.h> 41 #include <string.h> 42 43 static struct gpio_info param_reset; 44 static struct gpio_info param_poweroff; 45 static struct bl31_apio_param param_apio; 46 static struct gpio_info *rst_gpio; 47 static struct gpio_info *poweroff_gpio; 48 static struct gpio_info suspend_gpio[10]; 49 uint32_t suspend_gpio_cnt; 50 static struct apio_info *suspend_apio; 51 52 struct gpio_info *plat_get_rockchip_gpio_reset(void) 53 { 54 return rst_gpio; 55 } 56 57 struct gpio_info *plat_get_rockchip_gpio_poweroff(void) 58 { 59 return poweroff_gpio; 60 } 61 62 struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) 63 { 64 *count = suspend_gpio_cnt; 65 66 return &suspend_gpio[0]; 67 } 68 69 struct apio_info *plat_get_rockchip_suspend_apio(void) 70 { 71 return suspend_apio; 72 } 73 74 void params_early_setup(void *plat_param_from_bl2) 75 { 76 struct bl31_plat_param *bl2_param; 77 struct bl31_gpio_param *gpio_param; 78 79 /* keep plat parameters for later processing if need */ 80 bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; 81 while (bl2_param) { 82 switch (bl2_param->type) { 83 case PARAM_RESET: 84 gpio_param = (struct bl31_gpio_param *)bl2_param; 85 memcpy(¶m_reset, &gpio_param->gpio, 86 sizeof(struct gpio_info)); 87 rst_gpio = ¶m_reset; 88 break; 89 case PARAM_POWEROFF: 90 gpio_param = (struct bl31_gpio_param *)bl2_param; 91 memcpy(¶m_poweroff, &gpio_param->gpio, 92 sizeof(struct gpio_info)); 93 poweroff_gpio = ¶m_poweroff; 94 break; 95 case PARAM_SUSPEND_GPIO: 96 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { 97 ERROR("exceed support suspend gpio number\n"); 98 break; 99 } 100 gpio_param = (struct bl31_gpio_param *)bl2_param; 101 memcpy(&suspend_gpio[suspend_gpio_cnt], 102 &gpio_param->gpio, 103 sizeof(struct gpio_info)); 104 suspend_gpio_cnt++; 105 break; 106 case PARAM_SUSPEND_APIO: 107 memcpy(¶m_apio, bl2_param, 108 sizeof(struct bl31_apio_param)); 109 suspend_apio = ¶m_apio.apio; 110 break; 111 default: 112 ERROR("not expected type found %ld\n", 113 bl2_param->type); 114 break; 115 } 116 bl2_param = bl2_param->next; 117 } 118 } 119