blob: 6c022d8f59d4413cabc71776c40acd2131fa9bd7 [file] [log] [blame]
Angel Ponsbbc99cf2020-04-04 18:51:23 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vadim Bendebury92c2f5e2016-04-04 16:57:05 -07002
Vadim Bendebury92c2f5e2016-04-04 16:57:05 -07003#include <gpio.h>
4#include <soc/addressmap.h>
5#include <soc/gpio.h>
6#include <soc/grf.h>
7#include <soc/soc.h>
Vadim Bendebury92c2f5e2016-04-04 16:57:05 -07008
9struct rockchip_gpio_regs *gpio_port[] = {
10 (struct rockchip_gpio_regs *)GPIO0_BASE,
11 (struct rockchip_gpio_regs *)GPIO1_BASE,
12 (struct rockchip_gpio_regs *)GPIO2_BASE,
13 (struct rockchip_gpio_regs *)GPIO3_BASE,
14 (struct rockchip_gpio_regs *)GPIO4_BASE,
15};
16
17#define PMU_GPIO_PORT0 0
18#define PMU_GPIO_PORT1 1
19
20int is_pmu_gpio(gpio_t gpio)
21{
22 if (gpio.port == PMU_GPIO_PORT0 || gpio.port == PMU_GPIO_PORT1)
23 return 1;
24 return 0;
25}
26
27void *gpio_grf_reg(gpio_t gpio)
28{
29 if (is_pmu_gpio(gpio))
30 return &rk3399_pmugrf->gpio0_p[gpio.port][gpio.bank];
31 /* There are two pmu gpio, 0 and 1, so " - 2" */
32 return &rk3399_grf->gpio2_p[(gpio.port - 2)][gpio.bank];
33}
Shunqian Zheng74bb4122016-05-17 14:00:04 +080034
35#define IS_GPIO_BANK(g, p, b) (g.port == p && g.bank == GPIO_##b)
36
37enum {
38 PULLNONE_1V8 = 0,
39 PULLDOWN_1V8 = 1,
40 PULLUP_1V8 = 3,
41};
42
Julius Werner2768a112016-09-01 22:55:58 -070043u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull)
Shunqian Zheng74bb4122016-05-17 14:00:04 +080044{
45 /* The default pull bias setting defined in soc/gpio.h */
46 u32 pull_val = pull;
47
48 /* GPIO0_A, GPIO0_B, GPIO2_C, GPIO2_D use the 1V8 pull bias setting.
49 * Defined in TRM V.03 Part1 Page 331 and Page 458
50 */
51 if (IS_GPIO_BANK(gpio, 0, A) || IS_GPIO_BANK(gpio, 0, B) ||
52 IS_GPIO_BANK(gpio, 2, C) || IS_GPIO_BANK(gpio, 2, D)) {
53 switch (pull) {
Julius Werner2768a112016-09-01 22:55:58 -070054 case GPIO_PULLUP:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080055 pull_val = PULLUP_1V8;
56 break;
Julius Werner2768a112016-09-01 22:55:58 -070057 case GPIO_PULLDOWN:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080058 pull_val = PULLDOWN_1V8;
59 break;
Julius Werner2768a112016-09-01 22:55:58 -070060 case GPIO_PULLNONE:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080061 pull_val = PULLNONE_1V8;
62 }
63 }
64
65 return pull_val;
66}