linux-stable/include/linux/regulator
Douglas Anderson 1de452a0ed
regulator: core: Allow drivers to define their init data as const
Drivers tend to want to define the names of their regulators somewhere
in their source file as "static const". This means, inevitable, that
every driver out there open codes something like this:

static const char * const supply_names[] = {
 "vcc", "vccl",
};

static int get_regulators(struct my_data *data)
{
  int i;

  data->supplies = devm_kzalloc(...)
  if (!data->supplies)
    return -ENOMEM;

  for (i = 0; i < ARRAY_SIZE(supply_names); i++)
    data->supplies[i].supply = supply_names[i];

  return devm_regulator_bulk_get(data->dev,
                                 ARRAY_SIZE(supply_names),
				 data->supplies);
}

Let's make this more convenient by doing providing a helper that does
the copy.

I have chosen to have the "const" input structure here be the exact
same structure as the normal one passed to
devm_regulator_bulk_get(). This is slightly inefficent since the input
data can't possibly have anything useful for "ret" or consumer and
thus we waste 8 bytes per structure. This seems an OK tradeoff for not
introducing an extra structure.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20220726103631.v2.6.I38fc508a73135a5c1b873851f3553ff2a3a625f5@changeid
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-07-27 13:47:30 +01:00
..
act8865.h
arizona-ldo1.h
arizona-micsupp.h
consumer.h regulator: core: Allow drivers to define their init data as const 2022-07-27 13:47:30 +01:00
coupler.h
da9121.h
da9211.h
db8500-prcmu.h
driver.h
fan53555.h
fixed.h
gpio-regulator.h
lp872x.h
lp3971.h
lp3972.h
machine.h
max1586.h
max8649.h
max8660.h
max8952.h
max8973-regulator.h
mt6311.h
mt6315-regulator.h
mt6323-regulator.h
mt6358-regulator.h
mt6359-regulator.h
mt6380-regulator.h
mt6397-regulator.h
of_regulator.h
pca9450.h regulator: pca9450: Make I2C Level Translator configurable 2022-05-03 13:47:36 +01:00
pfuze100.h
tps6507x.h
tps51632-regulator.h
tps62360.h
userspace-consumer.h