pm: device: remove usage of local states
The device PM subsystem already holds the device state, so there is no need to keep duplicates inside the device. The pm_device_state_get has been refactored to just return the device state. Note that this is still not safe, but the same applied to the previous implementation. This problem will be addressed later. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
1c0ed94601
commit
c2cf1ad203
48 changed files with 198 additions and 715 deletions
|
@ -33,9 +33,6 @@ struct spi_cc13xx_cc26xx_config {
|
|||
|
||||
struct spi_cc13xx_cc26xx_data {
|
||||
struct spi_context ctx;
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
enum pm_device_state pm_state;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
|
||||
|
@ -215,22 +212,23 @@ static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
enum pm_device_state new_state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state state;
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) &&
|
||||
(new_state != get_dev_data(dev)->pm_state)) {
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
||||
if (get_dev_config(dev)->base ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
|
||||
} else {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
|
||||
}
|
||||
get_dev_data(dev)->pm_state = new_state;
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
if (get_dev_data(dev)->pm_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
SSIDisable(get_dev_config(dev)->base);
|
||||
/*
|
||||
* Release power dependency
|
||||
|
@ -243,7 +241,6 @@ static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
Power_releaseDependency(
|
||||
PowerCC26XX_PERIPH_SSI1);
|
||||
}
|
||||
get_dev_data(dev)->pm_state = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,15 +254,12 @@ static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
|||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *state;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
if (new_state != get_dev_data(dev)->pm_state) {
|
||||
ret = spi_cc13xx_cc26xx_set_power_state(dev,
|
||||
new_state);
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (*state != curr_state) {
|
||||
ret = spi_cc13xx_cc26xx_set_power_state(dev, *state);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -331,20 +325,9 @@ static const struct spi_driver_api spi_cc13xx_cc26xx_driver_api = {
|
|||
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
|
||||
&spi_cc13xx_cc26xx_driver_api)
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
#define SPI_CC13XX_CC26XX_INIT_PM_STATE \
|
||||
do { \
|
||||
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE; \
|
||||
} while (0)
|
||||
#else
|
||||
#define SPI_CC13XX_CC26XX_INIT_PM_STATE
|
||||
#endif
|
||||
|
||||
#define SPI_CC13XX_CC26XX_INIT_FUNC(n) \
|
||||
static int spi_cc13xx_cc26xx_init_##n(const struct device *dev) \
|
||||
{ \
|
||||
SPI_CC13XX_CC26XX_INIT_PM_STATE; \
|
||||
\
|
||||
SPI_CC13XX_CC26XX_POWER_SPI(n); \
|
||||
\
|
||||
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx);\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue