blob: 8c6698757824b5426237317856af8431bae8d897 [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>
Vadim Bendebury92c2f5e2016-04-04 16:57:05 -07005#include <soc/grf.h>
6#include <soc/soc.h>
Vadim Bendebury92c2f5e2016-04-04 16:57:05 -07007
8struct rockchip_gpio_regs *gpio_port[] = {
9 (struct rockchip_gpio_regs *)GPIO0_BASE,
10 (struct rockchip_gpio_regs *)GPIO1_BASE,
11 (struct rockchip_gpio_regs *)GPIO2_BASE,
12 (struct rockchip_gpio_regs *)GPIO3_BASE,
13 (struct rockchip_gpio_regs *)GPIO4_BASE,
14};
15
16#define PMU_GPIO_PORT0 0
17#define PMU_GPIO_PORT1 1
18
19int is_pmu_gpio(gpio_t gpio)
20{
21 if (gpio.port == PMU_GPIO_PORT0 || gpio.port == PMU_GPIO_PORT1)
22 return 1;
23 return 0;
24}
25
26void *gpio_grf_reg(gpio_t gpio)
27{
28 if (is_pmu_gpio(gpio))
29 return &rk3399_pmugrf->gpio0_p[gpio.port][gpio.bank];
30 /* There are two pmu gpio, 0 and 1, so " - 2" */
31 return &rk3399_grf->gpio2_p[(gpio.port - 2)][gpio.bank];
32}
Shunqian Zheng74bb4122016-05-17 14:00:04 +080033
34#define IS_GPIO_BANK(g, p, b) (g.port == p && g.bank == GPIO_##b)
35
36enum {
37 PULLNONE_1V8 = 0,
38 PULLDOWN_1V8 = 1,
39 PULLUP_1V8 = 3,
40};
41
Julius Werner2768a112016-09-01 22:55:58 -070042u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull)
Shunqian Zheng74bb4122016-05-17 14:00:04 +080043{
44 /* The default pull bias setting defined in soc/gpio.h */
45 u32 pull_val = pull;
46
47 /* GPIO0_A, GPIO0_B, GPIO2_C, GPIO2_D use the 1V8 pull bias setting.
48 * Defined in TRM V.03 Part1 Page 331 and Page 458
49 */
50 if (IS_GPIO_BANK(gpio, 0, A) || IS_GPIO_BANK(gpio, 0, B) ||
51 IS_GPIO_BANK(gpio, 2, C) || IS_GPIO_BANK(gpio, 2, D)) {
52 switch (pull) {
Julius Werner2768a112016-09-01 22:55:58 -070053 case GPIO_PULLUP:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080054 pull_val = PULLUP_1V8;
55 break;
Julius Werner2768a112016-09-01 22:55:58 -070056 case GPIO_PULLDOWN:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080057 pull_val = PULLDOWN_1V8;
58 break;
Julius Werner2768a112016-09-01 22:55:58 -070059 case GPIO_PULLNONE:
Shunqian Zheng74bb4122016-05-17 14:00:04 +080060 pull_val = PULLNONE_1V8;
61 }
62 }
63
64 return pull_val;
65}