drivers/smartbond: Remove atomic flags from drivers

Remove atomic flags from drivers that use balanced calls
for PM locking.

Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
This commit is contained in:
Ioannis Damigos 2024-06-19 10:24:05 +03:00 committed by Anas Nashif
parent 94f7a60d3b
commit b9dab49b13
4 changed files with 51 additions and 99 deletions

View file

@ -157,10 +157,6 @@ struct dma_smartbond_data {
ATOMIC_DEFINE(channels_atomic, DMA_CHANNELS_COUNT);
#if defined(CONFIG_PM_DEVICE)
ATOMIC_DEFINE(pm_policy_state_flag, 1);
#endif
/* User callbacks and data to be stored per channel */
struct dma_channel_data channel_data[DMA_CHANNELS_COUNT];
};
@ -182,26 +178,17 @@ static bool dma_smartbond_is_dma_active(void)
return false;
}
static inline void dma_smartbond_pm_policy_state_lock_get(const struct device *dev)
static inline void dma_smartbond_pm_policy_state_lock_get(void)
{
#if defined(CONFIG_PM_DEVICE)
struct dma_smartbond_data *data = dev->data;
if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) {
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
#endif
}
static inline void dma_smartbond_pm_policy_state_lock_put(const struct device *dev)
static inline void dma_smartbond_pm_policy_state_lock_put(void)
{
#if defined(CONFIG_PM_DEVICE)
struct dma_smartbond_data *data = dev->data;
/* Make PM lock put has a matched PM lock get invocation */
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) {
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
#endif
}
@ -223,7 +210,7 @@ static void dma_smartbond_set_channel_status(const struct device *dev,
if (!irq_is_enabled(SMARTBOND_IRQN)) {
irq_enable(SMARTBOND_IRQN);
/* Prevent sleep as long as DMA operations are ongoing */
dma_smartbond_pm_policy_state_lock_get(dev);
dma_smartbond_pm_policy_state_lock_get();
}
DMA_CTRL_REG_SET_FIELD(DMA_ON, regs->DMA_CTRL_REG, 0x1);
@ -246,7 +233,7 @@ static void dma_smartbond_set_channel_status(const struct device *dev,
if (!dma_smartbond_is_dma_active()) {
irq_disable(SMARTBOND_IRQN);
/* Allow entering sleep once all DMA channels are inactive */
dma_smartbond_pm_policy_state_lock_put(dev);
dma_smartbond_pm_policy_state_lock_put();
}
}

View file

@ -46,10 +46,6 @@ struct entropy_smartbond_dev_data {
RNG_POOL_DEFINE(isr, CONFIG_ENTROPY_SMARTBOND_ISR_POOL_SIZE);
RNG_POOL_DEFINE(thr, CONFIG_ENTROPY_SMARTBOND_THR_POOL_SIZE);
#if defined(CONFIG_PM_DEVICE)
ATOMIC_DEFINE(pm_policy_state_flag, 1);
#endif
};
static struct entropy_smartbond_dev_data entropy_smartbond_data;
@ -61,30 +57,22 @@ static struct entropy_smartbond_dev_data entropy_smartbond_data;
#define FIFO_COUNT_MASK \
(TRNG_TRNG_FIFOLVL_REG_TRNG_FIFOFULL_Msk | TRNG_TRNG_FIFOLVL_REG_TRNG_FIFOLVL_Msk)
static inline void entropy_smartbond_pm_policy_state_lock_get(const struct device *dev)
static inline void entropy_smartbond_pm_policy_state_lock_get(void)
{
#if defined(CONFIG_PM_DEVICE)
struct entropy_smartbond_dev_data *data = dev->data;
if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) {
/*
* Prevent the SoC from etering the normal sleep state as PDC does not support
* waking up the application core following TRNG events.
*/
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
/*
* Prevent the SoC from etering the normal sleep state as PDC does not support
* waking up the application core following TRNG events.
*/
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
#endif
}
static inline void entropy_smartbond_pm_policy_state_lock_put(const struct device *dev)
static inline void entropy_smartbond_pm_policy_state_lock_put(void)
{
#if defined(CONFIG_PM_DEVICE)
struct entropy_smartbond_dev_data *data = dev->data;
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) {
/* Allow the SoC to enter the nornmal sleep state once TRNG is inactive */
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
/* Allow the SoC to enter the nornmal sleep state once TRNG is inactive */
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
#endif
}
@ -101,12 +89,12 @@ static void trng_enable(bool enable)
* Sleep is not allowed as long as the ISR and thread SW FIFOs
* are being filled with random numbers.
*/
entropy_smartbond_pm_policy_state_lock_get(DEVICE_DT_INST_GET(0));
entropy_smartbond_pm_policy_state_lock_get();
} else {
CRG_TOP->CLK_AMBA_REG &= ~CRG_TOP_CLK_AMBA_REG_TRNG_CLK_ENABLE_Msk;
TRNG->TRNG_CTRL_REG = 0;
entropy_smartbond_pm_policy_state_lock_put(DEVICE_DT_INST_GET(0));
entropy_smartbond_pm_policy_state_lock_put();
}
irq_unlock(key);
}

View file

@ -35,34 +35,27 @@ struct i2c_smartbond_data {
uint32_t transmit_cnt, receive_cnt;
i2c_callback_t cb;
void *userdata;
#if defined(CONFIG_PM_DEVICE)
ATOMIC_DEFINE(pm_policy_state_flag, 1);
#endif
#ifdef CONFIG_I2C_CALLBACK
k_spinlock_key_t spinlock_key;
#endif
};
#if defined(CONFIG_PM_DEVICE)
static inline void i2c_smartbond_pm_prevent_system_sleep(struct i2c_smartbond_data *data)
static inline void i2c_smartbond_pm_prevent_system_sleep(void)
{
if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) {
/*
* Prevent the SoC from etering the normal sleep state as PDC does not support
* waking up the application core following I2C events.
*/
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
/*
* Prevent the SoC from etering the normal sleep state as PDC does not support
* waking up the application core following I2C events.
*/
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
static inline void i2c_smartbond_pm_allow_system_sleep(struct i2c_smartbond_data *data)
static inline void i2c_smartbond_pm_allow_system_sleep(void)
{
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) {
/*
* Allow the SoC to enter the nornmal sleep state once I2C transactions are done.
*/
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
/*
* Allow the SoC to enter the nornmal sleep state once I2C transactions are done.
*/
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
#endif
@ -72,7 +65,8 @@ static inline void i2c_smartbond_pm_policy_state_lock_get(const struct device *d
#ifdef CONFIG_PM_DEVICE_RUNTIME
pm_device_runtime_get(dev);
#else
i2c_smartbond_pm_prevent_system_sleep(dev->data);
ARG_UNUSED(dev);
i2c_smartbond_pm_prevent_system_sleep();
#endif
#endif
}
@ -83,7 +77,8 @@ static inline void i2c_smartbond_pm_policy_state_lock_put(const struct device *d
#ifdef CONFIG_PM_DEVICE_RUNTIME
pm_device_runtime_put(dev);
#else
i2c_smartbond_pm_allow_system_sleep(dev->data);
ARG_UNUSED(dev);
i2c_smartbond_pm_allow_system_sleep();
#endif
#endif
}
@ -613,7 +608,7 @@ static int i2c_smartbond_pm_action(const struct device *dev,
switch (action) {
case PM_DEVICE_ACTION_RESUME:
#ifdef CONFIG_PM_DEVICE_RUNTIME
i2c_smartbond_pm_prevent_system_sleep(dev->data);
i2c_smartbond_pm_prevent_system_sleep();
#endif
/*
* Although the GPIO driver should already be initialized, make sure PD_COM
@ -630,7 +625,7 @@ static int i2c_smartbond_pm_action(const struct device *dev,
*/
da1469x_pd_release(MCU_PD_DOMAIN_COM);
#ifdef CONFIG_PM_DEVICE_RUNTIME
i2c_smartbond_pm_allow_system_sleep(dev->data);
i2c_smartbond_pm_allow_system_sleep();
#endif
break;
default:

View file

@ -94,12 +94,6 @@ struct uart_smartbond_runtime_cfg {
uint8_t ier_reg_val;
};
enum uart_smartbond_pm_policy_state_flag {
UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG,
UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG,
UART_SMARTBOND_PM_POLICY_STATE_FLAG_COUNT,
};
struct uart_smartbond_data {
struct uart_config current_config;
struct uart_smartbond_runtime_cfg runtime_cfg;
@ -116,44 +110,38 @@ struct uart_smartbond_data {
struct gpio_callback rx_wake_cb;
int rx_wake_timeout;
struct k_work_delayable rx_timeout_work;
ATOMIC_DEFINE(pm_policy_state_flag, UART_SMARTBOND_PM_POLICY_STATE_FLAG_COUNT);
#endif
#endif
};
#ifdef CONFIG_PM_DEVICE
static inline void uart_smartbond_pm_prevent_system_sleep(struct uart_smartbond_data *data,
int flag)
static inline void uart_smartbond_pm_prevent_system_sleep(void)
{
if (atomic_test_and_set_bit(data->pm_policy_state_flag, flag) == 0) {
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
static inline void uart_smartbond_pm_allow_system_sleep(struct uart_smartbond_data *data,
int flag)
static inline void uart_smartbond_pm_allow_system_sleep(void)
{
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, flag) == 1) {
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
}
static void uart_smartbond_pm_policy_state_lock_get(const struct device *dev, int flag)
static void uart_smartbond_pm_policy_state_lock_get(const struct device *dev)
{
#ifdef CONFIG_PM_DEVICE_RUNTIME
pm_device_runtime_get(dev);
#else
uart_smartbond_pm_prevent_system_sleep(dev->data, flag);
ARG_UNUSED(dev);
uart_smartbond_pm_prevent_system_sleep();
#endif
}
static void uart_smartbond_pm_policy_state_lock_put(const struct device *dev, int flag)
static void uart_smartbond_pm_policy_state_lock_put(const struct device *dev)
{
#ifdef CONFIG_PM_DEVICE_RUNTIME
pm_device_runtime_put(dev);
#else
uart_smartbond_pm_allow_system_sleep(dev->data, flag);
ARG_UNUSED(dev);
uart_smartbond_pm_allow_system_sleep();
#endif
}
@ -162,7 +150,7 @@ static void uart_smartbond_rx_refresh_timeout(struct k_work *work)
struct uart_smartbond_data *data = CONTAINER_OF(work, struct uart_smartbond_data,
rx_timeout_work.work);
uart_smartbond_pm_policy_state_lock_put(data->dev, UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG);
uart_smartbond_pm_policy_state_lock_put(data->dev);
}
#endif
@ -353,8 +341,7 @@ static void uart_smartbond_wake_handler(const struct device *gpio, struct gpio_c
GPIO_INT_DISABLE);
/* Refresh console expired time */
if (data->rx_wake_timeout) {
uart_smartbond_pm_policy_state_lock_get(data->dev,
UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG);
uart_smartbond_pm_policy_state_lock_get(data->dev);
k_work_reschedule(&data->rx_timeout_work, K_MSEC(data->rx_wake_timeout));
}
}
@ -367,11 +354,9 @@ static void uart_smartbond_dtr_handler(const struct device *gpio, struct gpio_ca
int pin = find_lsb_set(pins) - 1;
if (gpio_pin_get(gpio, pin) == 1) {
uart_smartbond_pm_policy_state_lock_put(data->dev,
UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG);
uart_smartbond_pm_policy_state_lock_put(data->dev);
} else {
uart_smartbond_pm_policy_state_lock_get(data->dev,
UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG);
uart_smartbond_pm_policy_state_lock_get(data->dev);
}
}
@ -420,8 +405,7 @@ static int uart_smartbond_init(const struct device *dev)
GPIO_INT_TRIG_BOTH);
/* Check if DTR is already active (low), if so lock power state */
if (gpio_pin_get(config->dtr_gpio.port, config->dtr_gpio.pin) == 0) {
uart_smartbond_pm_policy_state_lock_get(dev,
UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG);
uart_smartbond_pm_policy_state_lock_get(dev);
}
}
}
@ -717,8 +701,7 @@ static int uart_smartbond_pm_action(const struct device *dev,
switch (action) {
case PM_DEVICE_ACTION_RESUME:
#ifdef CONFIG_PM_DEVICE_RUNTIME
uart_smartbond_pm_prevent_system_sleep(dev->data,
UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG);
uart_smartbond_pm_prevent_system_sleep();
#endif
da1469x_pd_acquire(MCU_PD_DOMAIN_COM);
apply_runtime_config(dev);
@ -732,8 +715,7 @@ static int uart_smartbond_pm_action(const struct device *dev,
GPIO_INT_TRIG_LOW);
}
#ifdef CONFIG_PM_DEVICE_RUNTIME
uart_smartbond_pm_allow_system_sleep(dev->data,
UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG);
uart_smartbond_pm_allow_system_sleep();
#endif
break;
default: