Skip to content

Commit

Permalink
drivers: regulator: add regulator_dt_get_supply()
Browse files Browse the repository at this point in the history
Implements regulator_dt_get_supply() API function for consumer
drivers to get a regulator supply using the driver device DT node
data. The function returns TEE_ERROR_DEFER_DRIVER_INIT when the
target supply exists but is yet not initialized.

Acked-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Co-developed-by: Pascal Paillet <p.paillet@foss.st.com>
Signed-off-by: Pascal Paillet <p.paillet@foss.st.com>
Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
  • Loading branch information
etienne-lms authored and jforissier committed Oct 11, 2023
1 parent 652d2ce commit 86ea47d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/drivers/regulator/regulator_dt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ static TEE_Result get_supply_phandle(const void *fdt, int node,
return TEE_SUCCESS;
}

TEE_Result regulator_dt_get_supply(const void *fdt, int node,
const char *supply_name,
struct regulator **regulator)
{
struct dt_driver_provider *provider = NULL;
TEE_Result res = TEE_ERROR_GENERIC;
uint32_t supply_phandle = 0;

res = get_supply_phandle(fdt, node, supply_name, &supply_phandle);
if (res)
return res;

provider = dt_driver_get_provider_by_phandle(supply_phandle,
DT_DRIVER_REGULATOR);
if (!provider)
return TEE_ERROR_DEFER_DRIVER_INIT;

*regulator = dt_driver_provider_priv_data(provider);
assert(*regulator);

return TEE_SUCCESS;
}

/* Helper function to register a regulator provider instance */
static TEE_Result regulator_register_provider(const void *fdt, int node,
struct regulator *regulator)
Expand Down
17 changes: 17 additions & 0 deletions core/include/drivers/regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ static inline void regulator_print_state(const char *message __unused)
#endif /*CFG_DRIVERS_REGULATOR*/

#if defined(CFG_DRIVERS_REGULATOR) && defined(CFG_DT)
/*
* regulator_dt_get_supply() - Get a regulator supply from name and DT node
* @fdt: FDT to work on
* @node: DT node of the regulator consumer
* @supply_name: Name of the supply in DT property xxx-supply
* @regulator: Output regulator upon success
*
* Upon success, this function provides the pointer to regulator
* defined by DT binding property @name-supply phandle reference.
*
* This function returns TEE_ERROR_DEFER_DRIVER_INIT if supply exists but is
* not yet initialized.
*/
TEE_Result regulator_dt_get_supply(const void *fdt, int node,
const char *supply_name,
struct regulator **regulator);

/*
* regulator_dt_register() - Register a regulator to related to a DT node
* @fdt: FDT to work on
Expand Down

0 comments on commit 86ea47d

Please sign in to comment.