soc: Remove copyright notices
[coreboot.git] / src / soc / rockchip / rk3399 / gpio.c
blob1be9ceb0b33b48bb2bd8ac5da3e211cb46f99def
1 /*
2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <gpio.h>
16 #include <soc/addressmap.h>
17 #include <soc/gpio.h>
18 #include <soc/grf.h>
19 #include <soc/soc.h>
21 struct rockchip_gpio_regs *gpio_port[] = {
22 (struct rockchip_gpio_regs *)GPIO0_BASE,
23 (struct rockchip_gpio_regs *)GPIO1_BASE,
24 (struct rockchip_gpio_regs *)GPIO2_BASE,
25 (struct rockchip_gpio_regs *)GPIO3_BASE,
26 (struct rockchip_gpio_regs *)GPIO4_BASE,
29 #define PMU_GPIO_PORT0 0
30 #define PMU_GPIO_PORT1 1
32 int is_pmu_gpio(gpio_t gpio)
34 if (gpio.port == PMU_GPIO_PORT0 || gpio.port == PMU_GPIO_PORT1)
35 return 1;
36 return 0;
39 void *gpio_grf_reg(gpio_t gpio)
41 if (is_pmu_gpio(gpio))
42 return &rk3399_pmugrf->gpio0_p[gpio.port][gpio.bank];
43 /* There are two pmu gpio, 0 and 1, so " - 2" */
44 return &rk3399_grf->gpio2_p[(gpio.port - 2)][gpio.bank];
47 #define IS_GPIO_BANK(g, p, b) (g.port == p && g.bank == GPIO_##b)
49 enum {
50 PULLNONE_1V8 = 0,
51 PULLDOWN_1V8 = 1,
52 PULLUP_1V8 = 3,
55 u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull)
57 /* The default pull bias setting defined in soc/gpio.h */
58 u32 pull_val = pull;
60 /* GPIO0_A, GPIO0_B, GPIO2_C, GPIO2_D use the 1V8 pull bias setting.
61 * Defined in TRM V.03 Part1 Page 331 and Page 458
63 if (IS_GPIO_BANK(gpio, 0, A) || IS_GPIO_BANK(gpio, 0, B) ||
64 IS_GPIO_BANK(gpio, 2, C) || IS_GPIO_BANK(gpio, 2, D)) {
65 switch (pull) {
66 case GPIO_PULLUP:
67 pull_val = PULLUP_1V8;
68 break;
69 case GPIO_PULLDOWN:
70 pull_val = PULLDOWN_1V8;
71 break;
72 case GPIO_PULLNONE:
73 pull_val = PULLNONE_1V8;
77 return pull_val;