drivers: gpio: stm32: introduce gpio_stm32_configure_raw
Make gpio32_stm32_configure use runtime PM API (so that it can be used externally without further effort). The raw version of the function (no PM put/get) has been introduced for internal use. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
a7a6a86505
commit
a9ae700695
|
@ -114,7 +114,8 @@ static inline uint32_t stm32_pinval_get(int pin)
|
|||
/**
|
||||
* @brief Configure the hardware.
|
||||
*/
|
||||
void gpio_stm32_configure(const struct device *dev, int pin, int conf, int altf)
|
||||
static void gpio_stm32_configure_raw(const struct device *dev, int pin,
|
||||
int conf, int altf)
|
||||
{
|
||||
const struct gpio_stm32_config *cfg = dev->config;
|
||||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)cfg->base;
|
||||
|
@ -223,6 +224,20 @@ void gpio_stm32_configure(const struct device *dev, int pin, int conf, int altf)
|
|||
|
||||
}
|
||||
|
||||
int gpio_stm32_configure(const struct device *dev, int pin, int conf, int altf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = pm_device_runtime_get(dev);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpio_stm32_configure_raw(dev, pin, conf, altf);
|
||||
|
||||
return pm_device_runtime_put(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO port clock handling
|
||||
*/
|
||||
|
@ -477,7 +492,7 @@ static int gpio_stm32_config(const struct device *dev,
|
|||
}
|
||||
}
|
||||
|
||||
gpio_stm32_configure(dev, pin, pincfg, 0);
|
||||
gpio_stm32_configure_raw(dev, pin, pincfg, 0);
|
||||
|
||||
/* Release clock only if configuration doesn't require bank writes */
|
||||
if ((flags & GPIO_OUTPUT) == 0) {
|
||||
|
|
|
@ -238,8 +238,10 @@ struct gpio_stm32_data {
|
|||
* @param pin IO pin
|
||||
* @param conf GPIO mode
|
||||
* @param altf Alternate function
|
||||
*
|
||||
* @return 0 on success, negative errno code on failure
|
||||
*/
|
||||
void gpio_stm32_configure(const struct device *dev, int pin, int conf, int altf);
|
||||
int gpio_stm32_configure(const struct device *dev, int pin, int conf, int altf);
|
||||
|
||||
/**
|
||||
* @brief Enable / disable GPIO port clock.
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <drivers/clock_control/stm32_clock_control.h>
|
||||
#include <drivers/pinctrl.h>
|
||||
#include <gpio/gpio_stm32.h>
|
||||
#include <pm/device_runtime.h>
|
||||
|
||||
#include <stm32_ll_bus.h>
|
||||
#include <stm32_ll_gpio.h>
|
||||
|
@ -146,7 +145,6 @@ static int stm32_pins_remap(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt)
|
|||
static int stm32_pin_configure(uint32_t pin, uint32_t func, uint32_t altf)
|
||||
{
|
||||
const struct device *port_device;
|
||||
int ret;
|
||||
|
||||
if (STM32_PORT(pin) >= gpio_ports_cnt) {
|
||||
return -EINVAL;
|
||||
|
@ -158,14 +156,7 @@ static int stm32_pin_configure(uint32_t pin, uint32_t func, uint32_t altf)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = pm_device_runtime_get(port_device);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpio_stm32_configure(port_device, STM32_PIN(pin), func, altf);
|
||||
|
||||
return pm_device_runtime_put(port_device);
|
||||
return gpio_stm32_configure(port_device, STM32_PIN(pin), func, altf);
|
||||
}
|
||||
|
||||
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <gpio/gpio_stm32.h>
|
||||
#include <drivers/clock_control/stm32_clock_control.h>
|
||||
#include <pinmux/pinmux_stm32.h>
|
||||
#include <pm/device_runtime.h>
|
||||
|
||||
const struct device * const gpio_ports[STM32_PORTS_MAX] = {
|
||||
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpioa)),
|
||||
|
@ -92,7 +91,6 @@ SYS_INIT(stm32_pinmux_init_remap, PRE_KERNEL_1,
|
|||
static int stm32_pin_configure(uint32_t pin, uint32_t func, uint32_t altf)
|
||||
{
|
||||
const struct device *port_device;
|
||||
int ret;
|
||||
|
||||
if (STM32_PORT(pin) >= STM32_PORTS_MAX) {
|
||||
return -EINVAL;
|
||||
|
@ -104,14 +102,7 @@ static int stm32_pin_configure(uint32_t pin, uint32_t func, uint32_t altf)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = pm_device_runtime_get(port_device);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpio_stm32_configure(port_device, STM32_PIN(pin), func, altf);
|
||||
|
||||
return pm_device_runtime_put(port_device);
|
||||
return gpio_stm32_configure(port_device, STM32_PIN(pin), func, altf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue