Skip to content

Commit eca0040

Browse files
Declan Snydernordic-krch
authored andcommitted
[nrf fromtree] pm: Extend pm notifier to be able to report substate
I am surprised this notifier didn't already report the substate id, it seems important since different substate obviously are defined for a reason, they can be having a different effect on the system. Signed-off-by: Declan Snyder <[email protected]> (cherry picked from commit ae1f131)
1 parent 3b0588e commit eca0040

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

include/zephyr/pm/pm.h

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,33 @@ extern "C" {
5555
*/
5656
struct pm_notifier {
5757
sys_snode_t _node;
58-
/**
59-
* Application defined function for doing any target specific operations
60-
* for power state entry.
61-
*/
62-
void (*state_entry)(enum pm_state state);
63-
/**
64-
* Application defined function for doing any target specific operations
65-
* for power state exit.
66-
*/
67-
void (*state_exit)(enum pm_state state);
58+
union {
59+
struct {
60+
/**
61+
* Application defined function for doing any target specific operations
62+
* for power state entry.
63+
*/
64+
void (*state_entry)(enum pm_state state);
65+
/**
66+
* Application defined function for doing any target specific operations
67+
* for power state exit.
68+
*/
69+
void (*state_exit)(enum pm_state state);
70+
};
71+
struct {
72+
/**
73+
* Application defined function for doing any target specific operations
74+
* for power state entry. Reports the substate id additionally.
75+
*/
76+
void (*substate_entry)(enum pm_state state, uint8_t substate_id);
77+
/**
78+
* Application defined function for doing any target specific operations
79+
* for power state exit. Reports the substate id additionally.
80+
*/
81+
void (*substate_exit)(enum pm_state state, uint8_t substate_id);
82+
};
83+
};
84+
bool report_substate; /* 0 is for backwards compatibility that didn't report substates */
6885
};
6986

7087
#if defined(CONFIG_PM) || defined(__DOXYGEN__)

subsys/pm/pm.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,29 @@ static inline void pm_state_notify(bool entering_state)
4747
{
4848
struct pm_notifier *notifier;
4949
k_spinlock_key_t pm_notifier_key;
50-
void (*callback)(enum pm_state state);
50+
union {
51+
void (*without_substate)(enum pm_state state);
52+
void (*with_substate)(enum pm_state state, uint8_t substate_id);
53+
} callback;
5154

5255
pm_notifier_key = k_spin_lock(&pm_notifier_lock);
5356
SYS_SLIST_FOR_EACH_CONTAINER(&pm_notifiers, notifier, _node) {
5457
if (entering_state) {
55-
callback = notifier->state_entry;
58+
/* should be equivalent to also setting the "with substate" */
59+
callback.without_substate = notifier->state_entry;
5660
} else {
57-
callback = notifier->state_exit;
61+
/* should be equivalent to also setting the "with substate" */
62+
callback.without_substate = notifier->state_exit;
5863
}
5964

60-
if (callback) {
61-
callback(z_cpus_pm_state[CPU_ID]->state);
62-
}
65+
if (callback.with_substate && notifier->report_substate) {
66+
callback.with_substate(z_cpus_pm_state[CPU_ID]->state,
67+
z_cpus_pm_state[CPU_ID]->substate_id);
68+
} else if (callback.without_substate) {
69+
callback.without_substate(z_cpus_pm_state[CPU_ID]->state);
70+
} else {
71+
/* intentionally empty */
72+
};
6373
}
6474
k_spin_unlock(&pm_notifier_lock, pm_notifier_key);
6575
}

0 commit comments

Comments
 (0)