iio: light: ltr501: Use devm_regulator_bulk_get_enable()
This driver only turns the power for some regulators on at probe and off via a custom devm_add_action_or_reset() callback. The new devm_regulator_bulk_get_enable() replaces all this boilerplate code. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20221016163409.320197-11-jic23@kernel.org
This commit is contained in:
parent
2c97f7b404
commit
c437c977c1
|
@ -153,7 +153,6 @@ struct ltr501_chip_info {
|
|||
|
||||
struct ltr501_data {
|
||||
struct i2c_client *client;
|
||||
struct regulator_bulk_data regulators[2];
|
||||
struct mutex lock_als, lock_ps;
|
||||
const struct ltr501_chip_info *chip_info;
|
||||
u8 als_contr, ps_contr;
|
||||
|
@ -1415,13 +1414,6 @@ static const struct regmap_config ltr501_regmap_config = {
|
|||
.volatile_reg = ltr501_is_volatile_reg,
|
||||
};
|
||||
|
||||
static void ltr501_disable_regulators(void *d)
|
||||
{
|
||||
struct ltr501_data *data = d;
|
||||
|
||||
regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
|
||||
}
|
||||
|
||||
static int ltr501_powerdown(struct ltr501_data *data)
|
||||
{
|
||||
return ltr501_write_contr(data, data->als_contr &
|
||||
|
@ -1443,6 +1435,7 @@ static const char *ltr501_match_acpi_device(struct device *dev, int *chip_idx)
|
|||
static int ltr501_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
static const char * const regulator_names[] = { "vdd", "vddio" };
|
||||
struct ltr501_data *data;
|
||||
struct iio_dev *indio_dev;
|
||||
struct regmap *regmap;
|
||||
|
@ -1466,25 +1459,13 @@ static int ltr501_probe(struct i2c_client *client,
|
|||
mutex_init(&data->lock_als);
|
||||
mutex_init(&data->lock_ps);
|
||||
|
||||
data->regulators[0].supply = "vdd";
|
||||
data->regulators[1].supply = "vddio";
|
||||
ret = devm_regulator_bulk_get(&client->dev,
|
||||
ARRAY_SIZE(data->regulators),
|
||||
data->regulators);
|
||||
ret = devm_regulator_bulk_get_enable(&client->dev,
|
||||
ARRAY_SIZE(regulator_names),
|
||||
regulator_names);
|
||||
if (ret)
|
||||
return dev_err_probe(&client->dev, ret,
|
||||
"Failed to get regulators\n");
|
||||
|
||||
ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
|
||||
data->regulators);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = devm_add_action_or_reset(&client->dev,
|
||||
ltr501_disable_regulators, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
data->reg_it = devm_regmap_field_alloc(&client->dev, regmap,
|
||||
reg_field_it);
|
||||
if (IS_ERR(data->reg_it)) {
|
||||
|
|
Loading…
Reference in New Issue