Skip to content

Commit

Permalink
drivers: regulator: use mutex_pm_aware
Browse files Browse the repository at this point in the history
Use newly introduced struct mutex_pm_aware semaphore to protect
regulator accesses.

Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
  • Loading branch information
etienne-lms authored and jforissier committed Mar 20, 2024
1 parent 9a3248f commit c80790f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
27 changes: 6 additions & 21 deletions core/drivers/regulator/regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <keep.h>
#include <kernel/boot.h>
#include <kernel/delay.h>
#include <kernel/mutex.h>
#include <kernel/mutex_pm_aware.h>
#include <kernel/panic.h>
#include <kernel/pm.h>
#include <kernel/tee_time.h>
Expand All @@ -26,32 +26,15 @@
static SLIST_HEAD(, regulator) regulator_device_list =
SLIST_HEAD_INITIALIZER(regulator);

/* Access protection mutex complying the power state transitions context */
static void lock_regulator(struct regulator *regulator)
{
/*
* Regulator operation may occur at runtime and during specific
* system power transition: power off, PM suspend and resume.
* These operate upon fastcall entries, under PSCI services
* execution, where non-secure world is not operational. In these
* cases we cannot take a mutex and will expect the mutex is
* unlocked.
*/
if (thread_get_id_may_fail() == THREAD_ID_INVALID) {
assert(!regulator->lock.state);
return;
}

mutex_lock(&regulator->lock);
mutex_pm_aware_lock(&regulator->mutex);
}

static void unlock_regulator(struct regulator *regulator)
{
if (thread_get_id_may_fail() == THREAD_ID_INVALID) {
/* Path for PM sequences when with local Monitor */
return;
}

mutex_unlock(&regulator->lock);
mutex_pm_aware_unlock(&regulator->mutex);
}

static TEE_Result set_state(struct regulator *regulator, bool on_not_off)
Expand Down Expand Up @@ -268,6 +251,8 @@ TEE_Result regulator_register(struct regulator *regulator)
regulator->flags & ~REGULATOR_FLAGS_MASK)
return TEE_ERROR_BAD_PARAMETERS;

mutex_pm_aware_init(&regulator->mutex);

regulator_get_range(regulator, &min_uv, &max_uv);
if (min_uv > max_uv)
return TEE_ERROR_BAD_PARAMETERS;
Expand Down
6 changes: 3 additions & 3 deletions core/include/drivers/regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <assert.h>
#include <bitstring.h>
#include <kernel/mutex.h>
#include <kernel/mutex_pm_aware.h>
#include <sys/queue.h>
#include <tee_api_types.h>
#include <stdbool.h>
Expand Down Expand Up @@ -87,7 +87,7 @@ struct regulator_voltages_desc {
* @max_uv: Max possible voltage level in microvolt (uV)
* @flags: REGULATOR_* property flags
* @refcount: Regulator enable request reference counter
* @lock: Mutex for concurrent access protection
* @mutex: Concurrent access protection considering PM context sequences
* @voltages_fallback: Default supported voltage range description
* @link: Link in initialized regulator list
*/
Expand All @@ -102,7 +102,7 @@ struct regulator {
/* Fields internal to regulator framework */
unsigned int flags;
unsigned int refcount;
struct mutex lock; /* Concurrent access protection */
struct mutex_pm_aware mutex;
struct voltages_fallback {
struct regulator_voltages_desc desc;
int levels[3];
Expand Down

0 comments on commit c80790f

Please sign in to comment.