From 86ea47da554cb6fb2e41d8aad30410c21f2e17a7 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Tue, 26 Sep 2023 19:58:11 +0200 Subject: [PATCH] drivers: regulator: add regulator_dt_get_supply() 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 Co-developed-by: Pascal Paillet Signed-off-by: Pascal Paillet Signed-off-by: Etienne Carriere --- core/drivers/regulator/regulator_dt.c | 23 +++++++++++++++++++++++ core/include/drivers/regulator.h | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/core/drivers/regulator/regulator_dt.c b/core/drivers/regulator/regulator_dt.c index f66cdc19cc3..54f11b1ded7 100644 --- a/core/drivers/regulator/regulator_dt.c +++ b/core/drivers/regulator/regulator_dt.c @@ -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) diff --git a/core/include/drivers/regulator.h b/core/include/drivers/regulator.h index 5b206218ab3..9287c3a6205 100644 --- a/core/include/drivers/regulator.h +++ b/core/include/drivers/regulator.h @@ -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