diff options
Diffstat (limited to 'src/soc/intel/apollolake/gpio.c')
-rw-r--r-- | src/soc/intel/apollolake/gpio.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/soc/intel/apollolake/gpio.c b/src/soc/intel/apollolake/gpio.c index 3a7be07d0d..06db8c965a 100644 --- a/src/soc/intel/apollolake/gpio.c +++ b/src/soc/intel/apollolake/gpio.c @@ -16,6 +16,7 @@ */ #include <assert.h> +#include <gpio.h> #include <soc/gpio.h> #include <soc/iosf.h> @@ -66,3 +67,50 @@ void gpio_configure_pads(const struct pad_config *cfg, size_t num_pads) for (i = 0; i < num_pads; i++) gpio_configure_pad(cfg + i); } + +void gpio_input_pulldown(gpio_t gpio) +{ + struct pad_config cfg = PAD_CFG_GPI(gpio, DN_5K, DEEP); + gpio_configure_pad(&cfg); +} + +void gpio_input_pullup(gpio_t gpio) +{ + struct pad_config cfg = PAD_CFG_GPI(gpio, UP_5K, DEEP); + gpio_configure_pad(&cfg); +} + +void gpio_input(gpio_t gpio) +{ + struct pad_config cfg = PAD_CFG_GPI(gpio, NONE, DEEP); + gpio_configure_pad(&cfg); +} + +void gpio_output(gpio_t gpio, int value) +{ + struct pad_config cfg = PAD_CFG_GPO(gpio, value, DEEP); + gpio_configure_pad(&cfg); +} + +int gpio_get(gpio_t gpio_num) +{ + uint32_t reg; + const struct pad_community *comm = gpio_get_community(gpio_num); + uint16_t config_offset = PAD_CFG_OFFSET(gpio_num - comm->first_pad); + + reg = iosf_read(comm->port, config_offset); + + return !!(reg & PAD_CFG0_RX_STATE); +} + +void gpio_set(gpio_t gpio_num, int value) +{ + uint32_t reg; + const struct pad_community *comm = gpio_get_community(gpio_num); + uint16_t config_offset = PAD_CFG_OFFSET(gpio_num - comm->first_pad); + + reg = iosf_read(comm->port, config_offset); + reg &= ~PAD_CFG0_TX_STATE; + reg |= !!value & PAD_CFG0_TX_STATE; + iosf_write(comm->port, config_offset, reg); +} |