device: move device power management state into common dynamic state
This avoids the need for distinct object that uses flash to store its initializer. Instead the state is initialized when the kernel is starting up, before anything can reference it. In future refactoring the PM state could be accessed directly without storing an extra pointer in the static device state. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
1cadd8b305
commit
8d771f1d8e
2 changed files with 21 additions and 15 deletions
|
@ -293,6 +293,10 @@ struct device_pm {
|
||||||
* before they are accessed.
|
* before they are accessed.
|
||||||
*/
|
*/
|
||||||
struct device_state {
|
struct device_state {
|
||||||
|
#ifdef CONFIG_PM_DEVICE
|
||||||
|
/* Power management data */
|
||||||
|
struct device_pm pm;
|
||||||
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,7 +756,6 @@ static inline int device_pm_put_sync(const struct device *dev) { return -ENOTSUP
|
||||||
|
|
||||||
#define Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, pm_control_fn, \
|
#define Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, pm_control_fn, \
|
||||||
data_ptr, cfg_ptr, level, prio, api_ptr) \
|
data_ptr, cfg_ptr, level, prio, api_ptr) \
|
||||||
Z_DEVICE_DEFINE_PM(dev_name) \
|
|
||||||
static struct device_state Z_DEVICE_STATE_NAME(dev_name); \
|
static struct device_state Z_DEVICE_STATE_NAME(dev_name); \
|
||||||
COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
|
COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
|
||||||
const Z_DECL_ALIGN(struct device) \
|
const Z_DECL_ALIGN(struct device) \
|
||||||
|
@ -771,23 +774,10 @@ static inline int device_pm_put_sync(const struct device *dev) { return -ENOTSUP
|
||||||
(&DEVICE_NAME_GET(dev_name)), level, prio)
|
(&DEVICE_NAME_GET(dev_name)), level, prio)
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
#define Z_DEVICE_DEFINE_PM(dev_name) \
|
|
||||||
static struct device_pm _CONCAT(__pm_, dev_name) __used = { \
|
|
||||||
.usage = ATOMIC_INIT(0), \
|
|
||||||
.lock = Z_SEM_INITIALIZER( \
|
|
||||||
_CONCAT(__pm_, dev_name).lock, 1, 1), \
|
|
||||||
.signal = K_POLL_SIGNAL_INITIALIZER( \
|
|
||||||
_CONCAT(__pm_, dev_name).signal), \
|
|
||||||
.event = K_POLL_EVENT_INITIALIZER( \
|
|
||||||
K_POLL_TYPE_SIGNAL, \
|
|
||||||
K_POLL_MODE_NOTIFY_ONLY, \
|
|
||||||
&_CONCAT(__pm_, dev_name).signal), \
|
|
||||||
};
|
|
||||||
#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) \
|
#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) \
|
||||||
.device_pm_control = (pm_control_fn), \
|
.device_pm_control = (pm_control_fn), \
|
||||||
.pm = &_CONCAT(__pm_, dev_name),
|
.pm = &Z_DEVICE_STATE_NAME(dev_name).pm,
|
||||||
#else
|
#else
|
||||||
#define Z_DEVICE_DEFINE_PM(dev_name)
|
|
||||||
#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn)
|
#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,21 @@ extern uint32_t __device_busy_end[];
|
||||||
#define DEVICE_BUSY_SIZE (__device_busy_end - __device_busy_start)
|
#define DEVICE_BUSY_SIZE (__device_busy_end - __device_busy_start)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline void device_pm_state_init(const struct device *dev)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_PM_DEVICE
|
||||||
|
*dev->pm = (struct device_pm){
|
||||||
|
.usage = ATOMIC_INIT(0),
|
||||||
|
.lock = Z_SEM_INITIALIZER(dev->pm->lock, 1, 1),
|
||||||
|
.signal = K_POLL_SIGNAL_INITIALIZER(dev->pm->signal),
|
||||||
|
.event = K_POLL_EVENT_INITIALIZER(
|
||||||
|
K_POLL_TYPE_SIGNAL,
|
||||||
|
K_POLL_MODE_NOTIFY_ONLY,
|
||||||
|
&dev->pm->signal),
|
||||||
|
};
|
||||||
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize state for all static devices.
|
* @brief Initialize state for all static devices.
|
||||||
*
|
*
|
||||||
|
@ -42,6 +57,7 @@ void z_device_state_init(void)
|
||||||
const struct device *dev = __device_start;
|
const struct device *dev = __device_start;
|
||||||
|
|
||||||
while (dev < __device_end) {
|
while (dev < __device_end) {
|
||||||
|
device_pm_state_init(dev);
|
||||||
z_object_init(dev);
|
z_object_init(dev);
|
||||||
++dev;
|
++dev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue