blob: 646c1e133cc4432d06ab8add80edcb8f2d44acf5 [file] [log] [blame]
Caesar Wang3e3c5b02016-05-25 19:03:04 +08001/*
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
Caesar Wangef180072016-09-10 02:43:15 +080043static struct gpio_info param_reset;
44static struct gpio_info param_poweroff;
Caesar Wang5045a1c2016-09-10 02:47:53 +080045static struct bl31_apio_param param_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080046static struct gpio_info *rst_gpio;
47static struct gpio_info *poweroff_gpio;
Caesar Wangef180072016-09-10 02:43:15 +080048static struct gpio_info suspend_gpio[10];
49uint32_t suspend_gpio_cnt;
Caesar Wang5045a1c2016-09-10 02:47:53 +080050static struct apio_info *suspend_apio;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080051
Caesar Wangef180072016-09-10 02:43:15 +080052struct gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080053{
54 return rst_gpio;
55}
56
Caesar Wangef180072016-09-10 02:43:15 +080057struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080058{
59 return poweroff_gpio;
60}
61
Caesar Wangef180072016-09-10 02:43:15 +080062struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
63{
64 *count = suspend_gpio_cnt;
65
66 return &suspend_gpio[0];
67}
68
Caesar Wang5045a1c2016-09-10 02:47:53 +080069struct apio_info *plat_get_rockchip_suspend_apio(void)
70{
71 return suspend_apio;
72}
73
Caesar Wang3e3c5b02016-05-25 19:03:04 +080074void params_early_setup(void *plat_param_from_bl2)
75{
Caesar Wang3e3c5b02016-05-25 19:03:04 +080076 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:
Caesar Wangef180072016-09-10 02:43:15 +080084 gpio_param = (struct bl31_gpio_param *)bl2_param;
85 memcpy(&param_reset, &gpio_param->gpio,
86 sizeof(struct gpio_info));
87 rst_gpio = &param_reset;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080088 break;
89 case PARAM_POWEROFF:
Caesar Wangef180072016-09-10 02:43:15 +080090 gpio_param = (struct bl31_gpio_param *)bl2_param;
91 memcpy(&param_poweroff, &gpio_param->gpio,
92 sizeof(struct gpio_info));
93 poweroff_gpio = &param_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++;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800105 break;
Caesar Wang5045a1c2016-09-10 02:47:53 +0800106 case PARAM_SUSPEND_APIO:
107 memcpy(&param_apio, bl2_param,
108 sizeof(struct bl31_apio_param));
109 suspend_apio = &param_apio.apio;
110 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800111 default:
Caesar Wangef180072016-09-10 02:43:15 +0800112 ERROR("not expected type found %ld\n",
113 bl2_param->type);
114 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800115 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800116 bl2_param = bl2_param->next;
117 }
118}