diff --git a/drivers/power/pm.h b/drivers/power/pm.h index ec718ea53ca..338238bf620 100644 --- a/drivers/power/pm.h +++ b/drivers/power/pm.h @@ -144,10 +144,6 @@ struct pm_domain_s struct pm_global_s { - /* The activity/state information for each PM domain */ - - struct pm_domain_s domain[CONFIG_PM_NDOMAINS]; - /* This semaphore manages mutually exclusive access to the power management * registry. It must be initialized to the value 1. */ @@ -160,6 +156,10 @@ struct pm_global_s */ dq_queue_t registry; + + /* The activity/state information for each PM domain */ + + struct pm_domain_s domain[CONFIG_PM_NDOMAINS]; }; /**************************************************************************** diff --git a/drivers/power/pm_initialize.c b/drivers/power/pm_initialize.c index 968ae64246d..c520edfe078 100644 --- a/drivers/power/pm_initialize.c +++ b/drivers/power/pm_initialize.c @@ -54,7 +54,16 @@ /* All PM global data: */ -struct pm_global_s g_pmglobals; +/* Initialize the registry and the PM global data structures. The PM + * global data structure resides in .data which is zeroed at boot time. So + * it is only required to initialize non-zero elements of the PM global + * data structure here. + */ + +struct pm_global_s g_pmglobals = +{ + SEM_INITIALIZER(1) +}; /**************************************************************************** * Public Functions @@ -80,14 +89,6 @@ struct pm_global_s g_pmglobals; void pm_initialize(void) { - /* Initialize the registry and the PM global data structures. The PM - * global data structure resides in .bss which is zeroed at boot time. So - * it is only required to initialize non-zero elements of the PM global - * data structure here. - */ - - dq_init(&g_pmglobals.registry); - nxsem_init(&g_pmglobals.regsem, 0, 1); } #endif /* CONFIG_PM */ diff --git a/drivers/power/pm_register.c b/drivers/power/pm_register.c index bebc739dc0c..6153ce2cf5b 100644 --- a/drivers/power/pm_register.c +++ b/drivers/power/pm_register.c @@ -42,6 +42,7 @@ #include #include +#include #include #include "pm.h" @@ -76,11 +77,19 @@ int pm_register(FAR struct pm_callback_s *callbacks) /* Add the new entry to the end of the list of registered callbacks */ - ret = pm_lock(); - if (ret == OK) + if (OSINIT_OSREADY()) + { + ret = pm_lock(); + if (ret == OK) + { + dq_addlast(&callbacks->entry, &g_pmglobals.registry); + pm_unlock(); + } + } + else { dq_addlast(&callbacks->entry, &g_pmglobals.registry); - pm_unlock(); + ret = OK; } return ret;