Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Bartosz Golaszewski and committed by
Mark Brown
d0087e72 baedad4c

+33
+21
drivers/regulator/helpers.c
··· 860 860 return -EINVAL; 861 861 } 862 862 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);
+12
include/linux/regulator/consumer.h
··· 281 281 void *regulator_get_drvdata(struct regulator *regulator); 282 282 void regulator_set_drvdata(struct regulator *regulator, void *data); 283 283 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 + 284 290 #else 285 291 286 292 /* ··· 584 578 static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector) 585 579 { 586 580 return -EINVAL; 581 + } 582 + 583 + void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers, 584 + const char *const *supply_names, 585 + unsigned int num_supplies) 586 + { 587 587 } 588 588 589 589 #endif