aboutsummaryrefslogtreecommitdiff
path: root/src/soc/rockchip/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc/rockchip/common')
-rw-r--r--src/soc/rockchip/common/gpio.c21
-rw-r--r--src/soc/rockchip/common/include/soc/gpio.h15
2 files changed, 25 insertions, 11 deletions
diff --git a/src/soc/rockchip/common/gpio.c b/src/soc/rockchip/common/gpio.c
index 6ea38d4d5f..1ff0bc9012 100644
--- a/src/soc/rockchip/common/gpio.c
+++ b/src/soc/rockchip/common/gpio.c
@@ -21,10 +21,15 @@
#include <soc/soc.h>
#include <stdlib.h>
-static void __gpio_input(gpio_t gpio, u32 pull)
+static void gpio_set_dir(gpio_t gpio, enum gpio_dir dir)
+{
+ clrsetbits_le32(&gpio_port[gpio.port]->swporta_ddr,
+ 1 << gpio.num, dir << gpio.num);
+}
+
+static void gpio_set_pull(gpio_t gpio, enum gpio_pull pull)
{
u32 pull_val = gpio_get_pull_val(gpio, pull);
- clrbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num);
if (is_pmu_gpio(gpio))
clrsetbits_le32(gpio_grf_reg(gpio), 3 << (gpio.idx * 2),
pull_val << (gpio.idx * 2));
@@ -35,17 +40,20 @@ static void __gpio_input(gpio_t gpio, u32 pull)
void gpio_input(gpio_t gpio)
{
- __gpio_input(gpio, PULLNONE);
+ gpio_set_pull(gpio, GPIO_PULLNONE);
+ gpio_set_dir(gpio, GPIO_INPUT);
}
void gpio_input_pulldown(gpio_t gpio)
{
- __gpio_input(gpio, PULLDOWN);
+ gpio_set_pull(gpio, GPIO_PULLDOWN);
+ gpio_set_dir(gpio, GPIO_INPUT);
}
void gpio_input_pullup(gpio_t gpio)
{
- __gpio_input(gpio, PULLUP);
+ gpio_set_pull(gpio, GPIO_PULLUP);
+ gpio_set_dir(gpio, GPIO_INPUT);
}
int gpio_get(gpio_t gpio)
@@ -55,7 +63,8 @@ int gpio_get(gpio_t gpio)
void gpio_output(gpio_t gpio, int value)
{
- setbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num);
clrsetbits_le32(&gpio_port[gpio.port]->swporta_dr, 1 << gpio.num,
!!value << gpio.num);
+ gpio_set_dir(gpio, GPIO_OUTPUT);
+ gpio_set_pull(gpio, GPIO_PULLNONE);
}
diff --git a/src/soc/rockchip/common/include/soc/gpio.h b/src/soc/rockchip/common/include/soc/gpio.h
index 2c72435065..a888635f72 100644
--- a/src/soc/rockchip/common/include/soc/gpio.h
+++ b/src/soc/rockchip/common/include/soc/gpio.h
@@ -73,13 +73,18 @@ int is_pmu_gpio(gpio_t gpio);
/* Return the io addr of gpio register */
void *gpio_grf_reg(gpio_t gpio);
-enum {
- PULLNONE = 0,
- PULLUP,
- PULLDOWN
+enum gpio_pull {
+ GPIO_PULLNONE = 0,
+ GPIO_PULLUP = 1,
+ GPIO_PULLDOWN = 2,
+};
+
+enum gpio_dir {
+ GPIO_INPUT = 0,
+ GPIO_OUTPUT = 1,
};
/* The gpio pull bias setting may be different between SoCs */
-u32 gpio_get_pull_val(gpio_t gpio, u32 pull);
+u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull);
#endif