[U-Boot] [PATCH v2 10/22] STM32: gpio: group SOC-specific code to one ifdef/elif construct

Benjamin Tietz uboot at dresden.micronet24.de
Mon Jun 20 20:26:51 CEST 2016


From: Benjamin Tietz <benjamin at micronet24.de>

In the STM32 gpio driver, multiple family-dependent sections existed.
All but one just statically filled a datastructure. The following patch
creates these structure const-static within a single family-dependent
section.

This seperation improves the maintainability for further rework on the
driver.
---
 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);



More information about the U-Boot mailing list