Skip to content

Commit

Permalink
iio: proximity: sx_common: Use devm_regulator_bulk_get_enable()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Gwendal Grignou <[email protected]>
Reviewed-by: Stephen Boyd <[email protected]>
Reviewed-by: Matti Vaittinen <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
jic23 committed Nov 23, 2022
1 parent b620be5 commit 1db9614
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
23 changes: 3 additions & 20 deletions drivers/iio/proximity/sx_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,6 @@ static const struct iio_buffer_setup_ops sx_common_buffer_setup_ops = {
.postdisable = sx_common_buffer_postdisable,
};

static void sx_common_regulator_disable(void *_data)
{
struct sx_common_data *data = _data;

regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
}

#define SX_COMMON_SOFT_RESET 0xde

static int sx_common_init_device(struct device *dev, struct iio_dev *indio_dev)
Expand Down Expand Up @@ -474,6 +467,7 @@ int sx_common_probe(struct i2c_client *client,
const struct sx_common_chip_info *chip_info,
const struct regmap_config *regmap_config)
{
static const char * const regulator_names[] = { "vdd", "svdd" };
struct device *dev = &client->dev;
struct iio_dev *indio_dev;
struct sx_common_data *data;
Expand All @@ -487,8 +481,6 @@ int sx_common_probe(struct i2c_client *client,

data->chip_info = chip_info;
data->client = client;
data->supplies[0].supply = "vdd";
data->supplies[1].supply = "svdd";
mutex_init(&data->mutex);
init_completion(&data->completion);

Expand All @@ -497,23 +489,14 @@ int sx_common_probe(struct i2c_client *client,
return dev_err_probe(dev, PTR_ERR(data->regmap),
"Could init register map\n");

ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
data->supplies);
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
regulator_names);
if (ret)
return dev_err_probe(dev, ret, "Unable to get regulators\n");

ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies);
if (ret)
return dev_err_probe(dev, ret, "Unable to enable regulators\n");

/* Must wait for Tpor time after initial power up */
usleep_range(1000, 1100);

ret = devm_add_action_or_reset(dev, sx_common_regulator_disable, data);
if (ret)
return dev_err_probe(dev, ret,
"Unable to register regulators deleter\n");

ret = data->chip_info->ops.check_whoami(dev, indio_dev);
if (ret)
return dev_err_probe(dev, ret, "error reading WHOAMI\n");
Expand Down
2 changes: 0 additions & 2 deletions drivers/iio/proximity/sx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ struct sx_common_chip_info {
* @trig: IIO trigger object.
* @regmap: Register map.
* @num_default_regs: Number of default registers to set at init.
* @supplies: Power supplies object.
* @chan_prox_stat: Last reading of the proximity status for each channel.
* We only send an event to user space when this changes.
* @trigger_enabled: True when the device trigger is enabled.
Expand All @@ -120,7 +119,6 @@ struct sx_common_data {
struct iio_trigger *trig;
struct regmap *regmap;

struct regulator_bulk_data supplies[2];
unsigned long chan_prox_stat;
bool trigger_enabled;

Expand Down

0 comments on commit 1db9614

Please sign in to comment.