blob: 351d2136156ec485474f29bdf1eaed52c82f9a04 [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 Wang3e3c5b02016-05-25 19:03:04 +080045static struct gpio_info *rst_gpio;
46static struct gpio_info *poweroff_gpio;
Caesar Wangef180072016-09-10 02:43:15 +080047static struct gpio_info suspend_gpio[10];
48uint32_t suspend_gpio_cnt;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080049
Caesar Wangef180072016-09-10 02:43:15 +080050struct gpio_info *plat_get_rockchip_gpio_reset(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080051{
52 return rst_gpio;
53}
54
Caesar Wangef180072016-09-10 02:43:15 +080055struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
Caesar Wang3e3c5b02016-05-25 19:03:04 +080056{
57 return poweroff_gpio;
58}
59
Caesar Wangef180072016-09-10 02:43:15 +080060struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
61{
62 *count = suspend_gpio_cnt;
63
64 return &suspend_gpio[0];
65}
66
Caesar Wang3e3c5b02016-05-25 19:03:04 +080067void params_early_setup(void *plat_param_from_bl2)
68{
Caesar Wang3e3c5b02016-05-25 19:03:04 +080069 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:
Caesar Wangef180072016-09-10 02:43:15 +080077 gpio_param = (struct bl31_gpio_param *)bl2_param;
78 memcpy(&param_reset, &gpio_param->gpio,
79 sizeof(struct gpio_info));
80 rst_gpio = &param_reset;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080081 break;
82 case PARAM_POWEROFF:
Caesar Wangef180072016-09-10 02:43:15 +080083 gpio_param = (struct bl31_gpio_param *)bl2_param;
84 memcpy(&param_poweroff, &gpio_param->gpio,
85 sizeof(struct gpio_info));
86 poweroff_gpio = &param_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++;
Caesar Wang3e3c5b02016-05-25 19:03:04 +080098 break;
99 default:
Caesar Wangef180072016-09-10 02:43:15 +0800100 ERROR("not expected type found %ld\n",
101 bl2_param->type);
102 break;
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800103 }
Caesar Wang3e3c5b02016-05-25 19:03:04 +0800104 bl2_param = bl2_param->next;
105 }
106}