Skip to content

Commit d0087e7

Browse files
brglbroonie
authored andcommitted
regulator: provide regulator_bulk_set_supply_names()
There are many regulator consumers who - before using the regulator bulk functions - set the supply names in regulator_bulk_data using a for loop. Let's provide a simple helper in the consumer API that allows users to do the same with a single function call. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20190830071740.4267-2-brgl@bgdev.pl Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent baedad4 commit d0087e7

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎drivers/regulator/helpers.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,24 @@ int regulator_get_current_limit_regmap(struct regulator_dev *rdev)
860860
return -EINVAL;
861861
}
862862
EXPORT_SYMBOL_GPL(regulator_get_current_limit_regmap);
863+
864+
/**
865+
* regulator_bulk_set_supply_names - initialize the 'supply' fields in an array
866+
* of regulator_bulk_data structs
867+
*
868+
* @consumers: array of regulator_bulk_data entries to initialize
869+
* @supply_names: array of supply name strings
870+
* @num_supplies: number of supply names to initialize
871+
*
872+
* Note: the 'consumers' array must be the size of 'num_supplies'.
873+
*/
874+
void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
875+
const char *const *supply_names,
876+
unsigned int num_supplies)
877+
{
878+
unsigned int i;
879+
880+
for (i = 0; i < num_supplies; i++)
881+
consumers[i].supply = supply_names[i];
882+
}
883+
EXPORT_SYMBOL_GPL(regulator_bulk_set_supply_names);

‎include/linux/regulator/consumer.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ void devm_regulator_unregister_notifier(struct regulator *regulator,
281281
void *regulator_get_drvdata(struct regulator *regulator);
282282
void regulator_set_drvdata(struct regulator *regulator, void *data);
283283

284+
/* misc helpers */
285+
286+
void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
287+
const char *const *supply_names,
288+
unsigned int num_supplies);
289+
284290
#else
285291

286292
/*
@@ -580,6 +586,12 @@ static inline int regulator_list_voltage(struct regulator *regulator, unsigned s
580586
return -EINVAL;
581587
}
582588

589+
void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
590+
const char *const *supply_names,
591+
unsigned int num_supplies)
592+
{
593+
}
594+
583595
#endif
584596

585597
static inline int regulator_set_voltage_triplet(struct regulator *regulator,

0 commit comments

Comments
 (0)