From 4fe345a510ac6a34736f855da941c4e3415b6551 Mon Sep 17 00:00:00 2001 From: Benoit Leforestier Date: Thu, 9 May 2019 11:19:58 +0200 Subject: [PATCH] Driver: gpio: Add support of Open Drain GPIO for STM32 Add ability to configure an output GPIO as Open Drain. Add GPIO_OPEN_DRAIN flags for use with gpio_pin_configure. Signed-off-by: Benoit Leforestier --- drivers/gpio/gpio_stm32.c | 5 +++++ drivers/gpio/gpio_stm32.h | 7 +++++-- include/dt-bindings/gpio/gpio.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 7e87081600601..7b8850fc5e7b4 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -50,6 +50,11 @@ const int gpio_stm32_flags_to_conf(int flags, int *pincfg) if (direction == GPIO_DIR_OUT) { *pincfg = STM32_PINCFG_MODE_OUTPUT; + if (pud == GPIO_OPEN_DRAIN) { + *pincfg |= STM32_PINCFG_OPEN_DRAIN; + } else { + *pincfg |= STM32_PINCFG_PUSH_PULL; + } } else { /* pull-{up,down} maybe? */ *pincfg = STM32_PINCFG_MODE_INPUT; diff --git a/drivers/gpio/gpio_stm32.h b/drivers/gpio/gpio_stm32.h index 970d9c68667ef..38c870adc676e 100644 --- a/drivers/gpio/gpio_stm32.h +++ b/drivers/gpio/gpio_stm32.h @@ -137,8 +137,9 @@ #ifdef CONFIG_SOC_SERIES_STM32F1X #define STM32_PINCFG_MODE_OUTPUT (STM32_MODE_OUTPUT \ - | STM32_CNF_GP_OUTPUT \ - | STM32_CNF_PUSH_PULL) + | STM32_CNF_GP_OUTPUT) +#define STM32_PINCFG_PUSH_PULL STM32_CNF_PUSH_PULL +#define STM32_PINCFG_OPEN_DRAIN STM32_CNF_OPEN_DRAIN #define STM32_PINCFG_MODE_INPUT STM32_MODE_INPUT #define STM32_PINCFG_PULL_UP (STM32_CNF_IN_PUPD | STM32_PUPD_PULL_UP) #define STM32_PINCFG_PULL_DOWN (STM32_CNF_IN_PUPD | \ @@ -147,6 +148,8 @@ STM32_PUPD_NO_PULL) #else #define STM32_PINCFG_MODE_OUTPUT STM32_MODER_OUTPUT_MODE +#define STM32_PINCFG_PUSH_PULL STM32_OTYPER_PUSH_PULL +#define STM32_PINCFG_OPEN_DRAIN STM32_OTYPER_OPEN_DRAIN #define STM32_PINCFG_MODE_INPUT STM32_MODER_INPUT_MODE #define STM32_PINCFG_PULL_UP STM32_PUPDR_PULL_UP #define STM32_PINCFG_PULL_DOWN STM32_PUPDR_PULL_DOWN diff --git a/include/dt-bindings/gpio/gpio.h b/include/dt-bindings/gpio/gpio.h index c365d449e347b..d42bcb327b7c3 100644 --- a/include/dt-bindings/gpio/gpio.h +++ b/include/dt-bindings/gpio/gpio.h @@ -97,6 +97,9 @@ /** Enable GPIO pin pull-down. */ #define GPIO_PUD_PULL_DOWN (2 << GPIO_PUD_POS) +/** Enable GPIO pin open drain. */ +#define GPIO_OPEN_DRAIN (3 << GPIO_PUD_POS) + /** @cond INTERNAL_HIDDEN */ #define GPIO_PUD_MASK (3 << GPIO_PUD_POS) /** @endcond */