Commit 1372d1a1 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Jonathan Cameron

iio: pressure: bmp280: use bulk regulator ops

The vddd and vdda supplies are always operated on together. We can
shrink the code a bit by using the bulk regulator helpers.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 84e5ddd5
...@@ -74,6 +74,12 @@ struct bmp280_calib { ...@@ -74,6 +74,12 @@ struct bmp280_calib {
s8 H6; s8 H6;
}; };
static const char *const bmp280_supply_names[] = {
"vddd", "vdda"
};
#define BMP280_NUM_SUPPLIES ARRAY_SIZE(bmp280_supply_names)
struct bmp280_data { struct bmp280_data {
struct device *dev; struct device *dev;
struct mutex lock; struct mutex lock;
...@@ -85,8 +91,7 @@ struct bmp280_data { ...@@ -85,8 +91,7 @@ struct bmp280_data {
struct bmp180_calib bmp180; struct bmp180_calib bmp180;
struct bmp280_calib bmp280; struct bmp280_calib bmp280;
} calib; } calib;
struct regulator *vddd; struct regulator_bulk_data supplies[BMP280_NUM_SUPPLIES];
struct regulator *vdda;
unsigned int start_up_time; /* in microseconds */ unsigned int start_up_time; /* in microseconds */
/* log of base 2 of oversampling rate */ /* log of base 2 of oversampling rate */
...@@ -1035,27 +1040,23 @@ int bmp280_common_probe(struct device *dev, ...@@ -1035,27 +1040,23 @@ int bmp280_common_probe(struct device *dev,
} }
/* Bring up regulators */ /* Bring up regulators */
data->vddd = devm_regulator_get(dev, "vddd"); regulator_bulk_set_supply_names(data->supplies,
if (IS_ERR(data->vddd)) { bmp280_supply_names,
dev_err(dev, "failed to get VDDD regulator\n"); BMP280_NUM_SUPPLIES);
return PTR_ERR(data->vddd);
} ret = devm_regulator_bulk_get(dev,
ret = regulator_enable(data->vddd); BMP280_NUM_SUPPLIES, data->supplies);
if (ret) { if (ret) {
dev_err(dev, "failed to enable VDDD regulator\n"); dev_err(dev, "failed to get regulators\n");
return ret; return ret;
} }
data->vdda = devm_regulator_get(dev, "vdda");
if (IS_ERR(data->vdda)) { ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies);
dev_err(dev, "failed to get VDDA regulator\n");
ret = PTR_ERR(data->vdda);
goto out_disable_vddd;
}
ret = regulator_enable(data->vdda);
if (ret) { if (ret) {
dev_err(dev, "failed to enable VDDA regulator\n"); dev_err(dev, "failed to enable regulators\n");
goto out_disable_vddd; return ret;
} }
/* Wait to make sure we started up properly */ /* Wait to make sure we started up properly */
usleep_range(data->start_up_time, data->start_up_time + 100); usleep_range(data->start_up_time, data->start_up_time + 100);
...@@ -1070,17 +1071,17 @@ int bmp280_common_probe(struct device *dev, ...@@ -1070,17 +1071,17 @@ int bmp280_common_probe(struct device *dev,
data->regmap = regmap; data->regmap = regmap;
ret = regmap_read(regmap, BMP280_REG_ID, &chip_id); ret = regmap_read(regmap, BMP280_REG_ID, &chip_id);
if (ret < 0) if (ret < 0)
goto out_disable_vdda; goto out_disable_regulators;
if (chip_id != chip) { if (chip_id != chip) {
dev_err(dev, "bad chip id: expected %x got %x\n", dev_err(dev, "bad chip id: expected %x got %x\n",
chip, chip_id); chip, chip_id);
ret = -EINVAL; ret = -EINVAL;
goto out_disable_vdda; goto out_disable_regulators;
} }
ret = data->chip_info->chip_config(data); ret = data->chip_info->chip_config(data);
if (ret < 0) if (ret < 0)
goto out_disable_vdda; goto out_disable_regulators;
dev_set_drvdata(dev, indio_dev); dev_set_drvdata(dev, indio_dev);
...@@ -1094,14 +1095,14 @@ int bmp280_common_probe(struct device *dev, ...@@ -1094,14 +1095,14 @@ int bmp280_common_probe(struct device *dev,
if (ret < 0) { if (ret < 0) {
dev_err(data->dev, dev_err(data->dev,
"failed to read calibration coefficients\n"); "failed to read calibration coefficients\n");
goto out_disable_vdda; goto out_disable_regulators;
} }
} else if (chip_id == BMP280_CHIP_ID || chip_id == BME280_CHIP_ID) { } else if (chip_id == BMP280_CHIP_ID || chip_id == BME280_CHIP_ID) {
ret = bmp280_read_calib(data, &data->calib.bmp280, chip_id); ret = bmp280_read_calib(data, &data->calib.bmp280, chip_id);
if (ret < 0) { if (ret < 0) {
dev_err(data->dev, dev_err(data->dev,
"failed to read calibration coefficients\n"); "failed to read calibration coefficients\n");
goto out_disable_vdda; goto out_disable_regulators;
} }
} }
...@@ -1113,7 +1114,7 @@ int bmp280_common_probe(struct device *dev, ...@@ -1113,7 +1114,7 @@ int bmp280_common_probe(struct device *dev,
if (irq > 0 || (chip_id == BMP180_CHIP_ID)) { if (irq > 0 || (chip_id == BMP180_CHIP_ID)) {
ret = bmp085_fetch_eoc_irq(dev, name, irq, data); ret = bmp085_fetch_eoc_irq(dev, name, irq, data);
if (ret) if (ret)
goto out_disable_vdda; goto out_disable_regulators;
} }
/* Enable runtime PM */ /* Enable runtime PM */
...@@ -1138,10 +1139,8 @@ int bmp280_common_probe(struct device *dev, ...@@ -1138,10 +1139,8 @@ int bmp280_common_probe(struct device *dev,
pm_runtime_get_sync(data->dev); pm_runtime_get_sync(data->dev);
pm_runtime_put_noidle(data->dev); pm_runtime_put_noidle(data->dev);
pm_runtime_disable(data->dev); pm_runtime_disable(data->dev);
out_disable_vdda: out_disable_regulators:
regulator_disable(data->vdda); regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
out_disable_vddd:
regulator_disable(data->vddd);
return ret; return ret;
} }
EXPORT_SYMBOL(bmp280_common_probe); EXPORT_SYMBOL(bmp280_common_probe);
...@@ -1155,8 +1154,7 @@ int bmp280_common_remove(struct device *dev) ...@@ -1155,8 +1154,7 @@ int bmp280_common_remove(struct device *dev)
pm_runtime_get_sync(data->dev); pm_runtime_get_sync(data->dev);
pm_runtime_put_noidle(data->dev); pm_runtime_put_noidle(data->dev);
pm_runtime_disable(data->dev); pm_runtime_disable(data->dev);
regulator_disable(data->vdda); regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
regulator_disable(data->vddd);
return 0; return 0;
} }
EXPORT_SYMBOL(bmp280_common_remove); EXPORT_SYMBOL(bmp280_common_remove);
...@@ -1166,12 +1164,8 @@ static int bmp280_runtime_suspend(struct device *dev) ...@@ -1166,12 +1164,8 @@ static int bmp280_runtime_suspend(struct device *dev)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmp280_data *data = iio_priv(indio_dev); struct bmp280_data *data = iio_priv(indio_dev);
int ret;
ret = regulator_disable(data->vdda); return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
if (ret)
return ret;
return regulator_disable(data->vddd);
} }
static int bmp280_runtime_resume(struct device *dev) static int bmp280_runtime_resume(struct device *dev)
...@@ -1180,10 +1174,7 @@ static int bmp280_runtime_resume(struct device *dev) ...@@ -1180,10 +1174,7 @@ static int bmp280_runtime_resume(struct device *dev)
struct bmp280_data *data = iio_priv(indio_dev); struct bmp280_data *data = iio_priv(indio_dev);
int ret; int ret;
ret = regulator_enable(data->vddd); ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies);
if (ret)
return ret;
ret = regulator_enable(data->vdda);
if (ret) if (ret)
return ret; return ret;
usleep_range(data->start_up_time, data->start_up_time + 100); usleep_range(data->start_up_time, data->start_up_time + 100);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment