| 1 |
|
| 2 |
|
| 3 |
#include <gpio.h> |
| 4 |
#include <soc/addressmap.h> |
| 5 |
#include <soc/grf.h> |
| 6 |
#include <soc/soc.h> |
| 7 |
|
| 8 |
struct 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 |
|
| 19 |
int 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 |
|
| 26 |
void *gpio_grf_reg(gpio_t gpio) |
| 27 |
{ |
| 28 |
if (is_pmu_gpio(gpio)) |
| 29 |
return &rk3399_pmugrf->gpio0_p[gpio.port][gpio.bank]; |
| 30 |
|
| 31 |
return &rk3399_grf->gpio2_p[(gpio.port - 2)][gpio.bank]; |
| 32 |
} |
| 33 |
|
| 34 |
#define IS_GPIO_BANK(g, p, b) (g.port == p && g.bank == GPIO_##b) |
| 35 |
|
| 36 |
enum { |
| 37 |
PULLNONE_1V8 = 0, |
| 38 |
PULLDOWN_1V8 = 1, |
| 39 |
PULLUP_1V8 = 3, |
| 40 |
}; |
| 41 |
|
| 42 |
u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull) |
| 43 |
{ |
| 44 |
|
| 45 |
u32 pull_val = pull; |
| 46 |
|
| 47 |
|
| 48 |
|
| 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) { |
| 53 |
case GPIO_PULLUP: |
| 54 |
pull_val = PULLUP_1V8; |
| 55 |
break; |
| 56 |
case GPIO_PULLDOWN: |
| 57 |
pull_val = PULLDOWN_1V8; |
| 58 |
break; |
| 59 |
case GPIO_PULLNONE: |
| 60 |
pull_val = PULLNONE_1V8; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return pull_val; |
| 65 |
} |