From: Benjamin Tietz <benja...@micronet24.de>

---
 drivers/gpio/stm32_gpio.c |   66 +++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)
From: Benjamin Tietz <benja...@micronet24.de>


---
 drivers/gpio/stm32_gpio.c |   66 +++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index 516dfcc..be662c3 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -74,6 +74,23 @@ int stm32_gpio_config(const struct stm32_gpio_dsc *dsc,
 out:
        return rv;
 }
+
+static struct stm32_gpio_ctl ctl_in = {
+       .af = STM32_GPIO_AF0,
+       .mode = STM32_GPIO_MODE_IN,
+       .otype = STM32_GPIO_OTYPE_PP,
+       .pupd = STM32_GPIO_PUPD_NO,
+       .speed = STM32_GPIO_SPEED_50M,
+};
+
+static struct stm32_gpio_ctl ctl_out = {
+       .af = STM32_GPIO_AF0,
+       .mode = STM32_GPIO_MODE_OUT,
+       .otype = STM32_GPIO_OTYPE_PP,
+       .pupd = STM32_GPIO_PUPD_NO,
+       .speed = STM32_GPIO_SPEED_50M,
+};
+
 #elif defined(CONFIG_STM32F1)
 static const unsigned long io_base[] = {
        STM32_GPIOA_BASE, STM32_GPIOB_BASE, STM32_GPIOC_BASE,
@@ -146,6 +163,21 @@ int stm32_gpio_config(const struct stm32_gpio_dsc *dsc,
 out:
        return rv;
 }
+
+static struct stm32_gpio_ctl ctl_in = {
+       .mode = STM32_GPIO_MODE_IN,
+       .icnf = STM32_GPIO_ICNF_IN_FLT,
+       .ocnf = STM32_GPIO_OCNF_GP_PP,  /* ignored for input */
+       .pupd = STM32_GPIO_PUPD_UP,     /* ignored for floating */
+};
+
+static struct stm32_gpio_ctl ctl_out = {
+       .mode = STM32_GPIO_MODE_OUT_50M,
+       .ocnf = STM32_GPIO_OCNF_GP_PP,
+       .icnf = STM32_GPIO_ICNF_IN_FLT, /* ignored for output */
+       .pupd = STM32_GPIO_PUPD_UP,     /* ignored for output */
+};
+
 #else
 #error STM32 family not supported
 #endif
@@ -203,52 +235,22 @@ int gpio_free(unsigned gpio)
 int gpio_direction_input(unsigned gpio)
 {
        struct stm32_gpio_dsc dsc;
-       struct stm32_gpio_ctl ctl;
 
        dsc.port = stm32_gpio_to_port(gpio);
        dsc.pin = stm32_gpio_to_pin(gpio);
-#if defined(CONFIG_STM32F4) || defined(CONFIG_STM32F7)
-       ctl.af = STM32_GPIO_AF0;
-       ctl.mode = STM32_GPIO_MODE_IN;
-       ctl.otype = STM32_GPIO_OTYPE_PP;
-       ctl.pupd = STM32_GPIO_PUPD_NO;
-       ctl.speed = STM32_GPIO_SPEED_50M;
-#elif defined(CONFIG_STM32F1)
-       ctl.mode = STM32_GPIO_MODE_IN;
-       ctl.icnf = STM32_GPIO_ICNF_IN_FLT;
-       ctl.ocnf = STM32_GPIO_OCNF_GP_PP;       /* ignored for input */
-       ctl.pupd = STM32_GPIO_PUPD_UP;          /* ignored for floating */
-#else
-#error STM32 family not supported
-#endif
 
-       return stm32_gpio_config(&dsc, &ctl);
+       return stm32_gpio_config(&dsc, &ctl_in);
 }
 
 int gpio_direction_output(unsigned gpio, int value)
 {
        struct stm32_gpio_dsc dsc;
-       struct stm32_gpio_ctl ctl;
        int res;
 
        dsc.port = stm32_gpio_to_port(gpio);
        dsc.pin = stm32_gpio_to_pin(gpio);
-#if defined(CONFIG_STM32F4) || defined(CONFIG_STM32F7)
-       ctl.af = STM32_GPIO_AF0;
-       ctl.mode = STM32_GPIO_MODE_OUT;
-       ctl.otype = STM32_GPIO_OTYPE_PP;
-       ctl.pupd = STM32_GPIO_PUPD_NO;
-       ctl.speed = STM32_GPIO_SPEED_50M;
-#elif defined(CONFIG_STM32F1)
-       ctl.mode = STM32_GPIO_MODE_OUT_50M;
-       ctl.ocnf = STM32_GPIO_OCNF_GP_PP;
-       ctl.icnf = STM32_GPIO_ICNF_IN_FLT;      /* ignored for output */
-       ctl.pupd = STM32_GPIO_PUPD_UP;          /* ignored for output */
-#else
-#error STM32 family not supported
-#endif
 
-       res = stm32_gpio_config(&dsc, &ctl);
+       res = stm32_gpio_config(&dsc, &ctl_out);
        if (res < 0)
                goto out;
        res = stm32_gpout_set(&dsc, value);
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to