Skip to content

Commit

Permalink
drivers: drop few redundant guard around pm_policy_state_lock_*
Browse files Browse the repository at this point in the history
The pm_policy_state_lock_put and pm_policy_state_lock_put functions
already become a no-op if CONFIG_PM is not enabled. Drop the guards
around it in few different drivers.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Nov 22, 2023
1 parent 2a6cec0 commit 939b90b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 43 deletions.
18 changes: 7 additions & 11 deletions drivers/display/display_rm67162.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,14 @@ static int rm67162_write(const struct device *dev, const uint16_t x,
* give to the TE semaphore) before sending the frame
*/
if (config->te_gpio.port != NULL) {
if (IS_ENABLED(CONFIG_PM)) {
/* Block sleep state until next TE interrupt
* so we can send frame during that interval
*/
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
}
/* Block sleep state until next TE interrupt so we can send
* frame during that interval
*/
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
k_sem_take(&data->te_sem, K_FOREVER);
if (IS_ENABLED(CONFIG_PM)) {
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
}
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
}
src = buf;
first_cmd = true;
Expand Down
12 changes: 6 additions & 6 deletions drivers/dma/dma_mcux_smartdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ static int dma_mcux_smartdma_start(const struct device *dev, uint32_t channel)
{
const struct dma_mcux_smartdma_config *config = dev->config;

#ifdef CONFIG_PM
/* Block PM transition until DMA completes */
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

/* Kick off SMARTDMA */
config->base->CTRL = SMARTDMA_MAGIC | SMARTDMA_BOOT;

return 0;
}

Expand All @@ -162,12 +162,13 @@ static int dma_mcux_smartdma_stop(const struct device *dev, uint32_t channel)
{
ARG_UNUSED(dev);
ARG_UNUSED(channel);

/* Stop DMA */
SMARTDMA_Reset();
#ifdef CONFIG_PM

/* Release PM lock */
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

return 0;
}

Expand Down Expand Up @@ -195,10 +196,9 @@ static void dma_mcux_smartdma_irq(const struct device *dev)
if (data->callback) {
data->callback(dev, data->user_data, 0, 0);
}
#ifdef CONFIG_PM

/* Release PM lock */
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
}

/**
Expand Down
11 changes: 3 additions & 8 deletions drivers/eeprom/eeprom_mchp_xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ static int eeprom_xec_read(const struct device *dev, off_t offset,
}

k_mutex_lock(&data->lock_mtx, K_FOREVER);
#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

/* EEPROM HW READ */
for (chunk_idx = 0; chunk_idx < len; chunk_idx += XEC_EEPROM_TRANSFER_SIZE_READ) {
if ((len-chunk_idx) < XEC_EEPROM_TRANSFER_SIZE_READ) {
Expand All @@ -252,9 +251,7 @@ static int eeprom_xec_read(const struct device *dev, off_t offset,
eeprom_xec_data_read_32_bytes(regs, &data_buf[chunk_idx],
chunk_size, (offset+chunk_idx));
}
#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
k_mutex_unlock(&data->lock_mtx);

return 0;
Expand All @@ -280,9 +277,8 @@ static int eeprom_xec_write(const struct device *dev, off_t offset,
}

k_mutex_lock(&data->lock_mtx, K_FOREVER);
#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

/* EEPROM HW WRITE */
for (chunk_idx = 0; chunk_idx < len; chunk_idx += XEC_EEPROM_TRANSFER_SIZE_WRITE) {
if ((len-chunk_idx) < XEC_EEPROM_TRANSFER_SIZE_WRITE) {
Expand All @@ -291,9 +287,8 @@ static int eeprom_xec_write(const struct device *dev, off_t offset,
eeprom_xec_data_write_32_bytes(regs, &data_buf[chunk_idx],
chunk_size, (offset+chunk_idx));
}
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
k_mutex_unlock(&data->lock_mtx);

return 0;
Expand Down
6 changes: 2 additions & 4 deletions drivers/kscan/kscan_mchp_xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,8 @@ void polling_task(const struct device *dev, void *dummy2, void *dummy3)
drive_keyboard_column(dev, KEYBOARD_COLUMN_DRIVE_ALL);

k_sem_take(&data->poll_lock, K_FOREVER);
#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

uint32_t start_poll_cycles = k_cycle_get_32();

while (atomic_get(&data->enable_scan) == 1U) {
Expand Down Expand Up @@ -416,9 +415,8 @@ void polling_task(const struct device *dev, void *dummy2, void *dummy3)
/* Allow other threads to run while we sleep */
k_usleep(wait_period);
}
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
}
}

Expand Down
16 changes: 6 additions & 10 deletions drivers/ps2/ps2_mchp_xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ static int ps2_xec_write(const struct device *dev, uint8_t value)
LOG_DBG("PS2 write timed out");
return -ETIMEDOUT;
}
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

/* Inhibit ps2 controller and clear status register */
regs->CTRL = 0x00;

Expand Down Expand Up @@ -306,33 +306,29 @@ static void ps2_xec_isr(const struct device *dev)
ps2_xec_girq_clr(config->girq_id, config->girq_bit);

if (status & MCHP_PS2_STATUS_RXD_RDY) {
#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

regs->CTRL = 0x00;
if (data->callback_isr) {
data->callback_isr(dev, regs->TRX_BUFF);
}
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
} else if (status &
(MCHP_PS2_STATUS_TX_TMOUT | MCHP_PS2_STATUS_TX_ST_TMOUT)) {
/* Clear sticky bits and go to read mode */
regs->STATUS = MCHP_PS2_STATUS_RW1C_MASK;
LOG_ERR("TX time out: %0x", status);
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
} else if (status &
(MCHP_PS2_STATUS_RX_TMOUT | MCHP_PS2_STATUS_PE | MCHP_PS2_STATUS_FE)) {
/* catch and clear rx error if any */
regs->STATUS = MCHP_PS2_STATUS_RW1C_MASK;
} else if (status & MCHP_PS2_STATUS_TX_IDLE) {
/* Transfer completed, release the lock to enter low per mode */
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
}

/* The control register reverts to RX automatically after
Expand Down
7 changes: 3 additions & 4 deletions drivers/sensor/mchp_tach_xec/tach_mchp_xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ int tach_xec_sample_fetch(const struct device *dev, enum sensor_channel chan)
struct tach_regs * const tach = cfg->regs;
uint8_t poll_count = 0;

#ifdef CONFIG_PM_DEVICE
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

while (poll_count < PIN_STS_TIMEOUT) {
/* See whether internal counter is already latched */
if (tach->STATUS & MCHP_TACH_STS_CNT_RDY) {
Expand All @@ -74,9 +73,9 @@ int tach_xec_sample_fetch(const struct device *dev, enum sensor_channel chan)
/* Allow other threads to run while we sleep */
k_usleep(USEC_PER_MSEC);
}
#ifdef CONFIG_PM_DEVICE

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif

if (poll_count == PIN_STS_TIMEOUT) {
return -EINVAL;
}
Expand Down

0 comments on commit 939b90b

Please sign in to comment.