drivers/pinmux: stm32: Get remap functions visible across family

Move pinctrl remap functions out of stm32f1 definition in order
to get it available to all series.
Allows use of more IS_ENABLED macros in calling drivers and make
code more readable.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2020-10-16 14:28:48 +02:00 committed by Kumar Gala
commit f44e931b0c
6 changed files with 62 additions and 51 deletions

View file

@ -412,17 +412,18 @@ static int can_stm32_init(const struct device *dev)
/* configure pinmux */
if (cfg->pinctrl_len != 0U) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
int remap;
/* Check that remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl,
cfg->pinctrl_len);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->can, remap);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
if (IS_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl))) {
int remap;
/* Check remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl,
cfg->pinctrl_len);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->can, remap);
}
stm32_dt_pinctrl_configure(cfg->pinctrl, cfg->pinctrl_len);
}

View file

@ -189,17 +189,18 @@ static int i2c_stm32_init(const struct device *dev)
#endif
if (cfg->pinctrl_list_size != 0) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
int remap;
/* Check that remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl_list,
cfg->pinctrl_list_size);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->i2c, remap);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
if (IS_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl))) {
int remap;
/* Check remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl_list,
cfg->pinctrl_list_size);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->i2c, remap);
}
stm32_dt_pinctrl_configure(cfg->pinctrl_list,
cfg->pinctrl_list_size);

View file

@ -180,7 +180,6 @@ void stm32_dt_pinctrl_configure(const struct soc_gpio_pinctrl *pinctrl,
}
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
/**
* @brief Helper function to check provided pinctrl remap configuration (Pin
* remapping configuration should be the same on all pins)
@ -194,6 +193,7 @@ void stm32_dt_pinctrl_configure(const struct soc_gpio_pinctrl *pinctrl,
int stm32_dt_pinctrl_remap_check(const struct soc_gpio_pinctrl *pinctrl,
size_t list_size)
{
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
int remap;
uint32_t mux;
@ -210,10 +210,14 @@ int stm32_dt_pinctrl_remap_check(const struct soc_gpio_pinctrl *pinctrl,
}
return remap;
#else
return 0;
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
}
void stm32_dt_pinctrl_remap_set(uint32_t base, int remap)
{
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
/* A valid remapping configuration is provided */
/* Apply remapping before proceeding with pin configuration */
@ -420,6 +424,7 @@ void stm32_dt_pinctrl_remap_set(uint32_t base, int remap)
}
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
}
/**
* @brief pin setup

View file

@ -283,20 +283,21 @@ static int pwm_stm32_init(const struct device *dev)
/* configure pinmux */
if (cfg->pinctrl_len != 0U) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
/* apply F1 series remaps */
int remap;
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl,
cfg->pinctrl_len);
if (remap < 0) {
LOG_ERR("pinctrl remap check failed (%d)", remap);
return remap;
if (IS_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl))) {
int remap;
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl,
cfg->pinctrl_len);
if (remap < 0) {
LOG_ERR("pinctrl remap check failed (%d)",
remap);
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->timer, remap);
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->timer, remap);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
stm32_dt_pinctrl_configure(cfg->pinctrl, cfg->pinctrl_len);
}

View file

@ -680,17 +680,19 @@ static int uart_stm32_init(const struct device *dev)
/* Configure dt provided device signals when available */
if (config->pinctrl_list_size != 0) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
int remap;
/* Check that remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(config->pinctrl_list,
if (IS_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl))) {
int remap;
/* Check remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(
config->pinctrl_list,
config->pinctrl_list_size);
if (remap < 0) {
return remap;
}
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)UART_STRUCT(dev), remap);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
stm32_dt_pinctrl_remap_set((uint32_t)UART_STRUCT(dev),
remap);
}
stm32_dt_pinctrl_configure(config->pinctrl_list,
config->pinctrl_list_size);

View file

@ -800,17 +800,18 @@ static int spi_stm32_init(const struct device *dev)
/* Configure dt provided device signals when available */
if (cfg->pinctrl_list_size != 0) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl)
int remap;
/* Check that remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl_list,
cfg->pinctrl_list_size);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->spi, remap);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl) */
if (IS_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32f1_pinctrl))) {
int remap;
/* Check remap configuration is coherent across pins */
remap = stm32_dt_pinctrl_remap_check(cfg->pinctrl_list,
cfg->pinctrl_list_size);
if (remap < 0) {
return remap;
}
stm32_dt_pinctrl_remap_set((uint32_t)cfg->spi, remap);
}
stm32_dt_pinctrl_configure(cfg->pinctrl_list,
cfg->pinctrl_list_size);