coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <gpio.h>
4 #include <soc/addressmap.h>
5 #include <soc/gpio.h>
6 #include <soc/grf.h>
7 #include <soc/soc.h>
8 
15 };
16 
17 #define PMU_GPIO_PORT0 0
18 #define PMU_GPIO_PORT1 1
19 
21 {
22  if (gpio.port == PMU_GPIO_PORT0 || gpio.port == PMU_GPIO_PORT1)
23  return 1;
24  return 0;
25 }
26 
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 }
34 
35 #define IS_GPIO_BANK(g, p, b) (g.port == p && g.bank == GPIO_##b)
36 
37 enum {
41 };
42 
44 {
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) {
54  case GPIO_PULLUP:
55  pull_val = PULLUP_1V8;
56  break;
57  case GPIO_PULLDOWN:
58  pull_val = PULLDOWN_1V8;
59  break;
60  case GPIO_PULLNONE:
61  pull_val = PULLNONE_1V8;
62  }
63  }
64 
65  return pull_val;
66 }
#define pull
Definition: asmlib.h:26
gpio_pull
Definition: gpio_common.h:61
static struct rk3399_pmugrf_regs *const rk3399_pmugrf
Definition: grf.h:320
static struct rk3399_grf_regs *const rk3399_grf
Definition: grf.h:319
@ GPIO_PULLNONE
Definition: gpio.h:62
@ GPIO_PULLDOWN
Definition: gpio.h:64
@ GPIO_PULLUP
Definition: gpio.h:63
int is_pmu_gpio(gpio_t gpio)
Definition: gpio.c:24
u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull)
Definition: gpio.c:39
void * gpio_grf_reg(gpio_t gpio)
Definition: gpio.c:31
struct rockchip_gpio_regs * gpio_port[]
Definition: gpio.c:10
#define GPIO1_BASE
Definition: addressmap.h:54
#define GPIO0_BASE
Definition: addressmap.h:51
#define GPIO3_BASE
Definition: addressmap.h:56
#define GPIO2_BASE
Definition: addressmap.h:55
#define GPIO4_BASE
Definition: addressmap.h:57
#define PMU_GPIO_PORT0
Definition: gpio.c:17
#define PMU_GPIO_PORT1
Definition: gpio.c:18
#define IS_GPIO_BANK(g, p, b)
Definition: gpio.c:35
@ PULLUP_1V8
Definition: gpio.c:40
@ PULLNONE_1V8
Definition: gpio.c:38
@ PULLDOWN_1V8
Definition: gpio.c:39
uint32_t u32
Definition: stdint.h:51
Definition: pinmux.c:36
u32 gpio2_p[3][4]
Definition: grf.h:145
u32 gpio0_p[2][4]
Definition: grf.h:216