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 gpio_info *rst_gpio; 46 static struct gpio_info *poweroff_gpio; 47 static struct gpio_info suspend_gpio[10]; 48 uint32_t suspend_gpio_cnt; 49 50 struct gpio_info *plat_get_rockchip_gpio_reset(void) 51 { 52 return rst_gpio; 53 } 54 55 struct gpio_info *plat_get_rockchip_gpio_poweroff(void) 56 { 57 return poweroff_gpio; 58 } 59 60 struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) 61 { 62 *count = suspend_gpio_cnt; 63 64 return &suspend_gpio[0]; 65 } 66 67 void params_early_setup(void *plat_param_from_bl2) 68 { 69 struct bl31_plat_param *bl2_param; 70 struct bl31_gpio_param *gpio_param; 71 72 /* keep plat parameters for later processing if need */ 73 bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; 74 while (bl2_param) { 75 switch (bl2_param->type) { 76 case PARAM_RESET: 77 gpio_param = (struct bl31_gpio_param *)bl2_param; 78 memcpy(¶m_reset, &gpio_param->gpio, 79 sizeof(struct gpio_info)); 80 rst_gpio = ¶m_reset; 81 break; 82 case PARAM_POWEROFF: 83 gpio_param = (struct bl31_gpio_param *)bl2_param; 84 memcpy(¶m_poweroff, &gpio_param->gpio, 85 sizeof(struct gpio_info)); 86 poweroff_gpio = ¶m_poweroff; 87 break; 88 case PARAM_SUSPEND_GPIO: 89 if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { 90 ERROR("exceed support suspend gpio number\n"); 91 break; 92 } 93 gpio_param = (struct bl31_gpio_param *)bl2_param; 94 memcpy(&suspend_gpio[suspend_gpio_cnt], 95 &gpio_param->gpio, 96 sizeof(struct gpio_info)); 97 suspend_gpio_cnt++; 98 break; 99 default: 100 ERROR("not expected type found %ld\n", 101 bl2_param->type); 102 break; 103 } 104 bl2_param = bl2_param->next; 105 } 106 } 107