Commit 2f4292a8 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Jonathan Cameron

iio: pressure: bmp280: use devm action and remove labels from probe

We can drop some duplicate code if we use devm_action for disabling
regulators and pm and the managed variant of iio_device_register().

This allows us to completely remove all remove() callbacks from both
i2c and spi code.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 1372d1a1
...@@ -986,6 +986,22 @@ static int bmp085_fetch_eoc_irq(struct device *dev, ...@@ -986,6 +986,22 @@ static int bmp085_fetch_eoc_irq(struct device *dev,
return 0; return 0;
} }
static void bmp280_pm_disable(void *data)
{
struct device *dev = data;
pm_runtime_get_sync(dev);
pm_runtime_put_noidle(dev);
pm_runtime_disable(dev);
}
static void bmp280_regulators_disable(void *data)
{
struct regulator_bulk_data *supplies = data;
regulator_bulk_disable(BMP280_NUM_SUPPLIES, supplies);
}
int bmp280_common_probe(struct device *dev, int bmp280_common_probe(struct device *dev,
struct regmap *regmap, struct regmap *regmap,
unsigned int chip, unsigned int chip,
...@@ -1057,6 +1073,11 @@ int bmp280_common_probe(struct device *dev, ...@@ -1057,6 +1073,11 @@ int bmp280_common_probe(struct device *dev,
return ret; return ret;
} }
ret = devm_add_action_or_reset(dev, bmp280_regulators_disable,
data->supplies);
if (ret)
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);
...@@ -1071,17 +1092,16 @@ int bmp280_common_probe(struct device *dev, ...@@ -1071,17 +1092,16 @@ 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_regulators; return ret;
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; return -EINVAL;
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_regulators; return ret;
dev_set_drvdata(dev, indio_dev); dev_set_drvdata(dev, indio_dev);
...@@ -1095,14 +1115,14 @@ int bmp280_common_probe(struct device *dev, ...@@ -1095,14 +1115,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_regulators; return ret;
} }
} 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_regulators; return ret;
} }
} }
...@@ -1114,7 +1134,7 @@ int bmp280_common_probe(struct device *dev, ...@@ -1114,7 +1134,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_regulators; return ret;
} }
/* Enable runtime PM */ /* Enable runtime PM */
...@@ -1129,36 +1149,14 @@ int bmp280_common_probe(struct device *dev, ...@@ -1129,36 +1149,14 @@ int bmp280_common_probe(struct device *dev,
pm_runtime_use_autosuspend(dev); pm_runtime_use_autosuspend(dev);
pm_runtime_put(dev); pm_runtime_put(dev);
ret = iio_device_register(indio_dev); ret = devm_add_action_or_reset(dev, bmp280_pm_disable, dev);
if (ret) if (ret)
goto out_runtime_pm_disable; return ret;
return 0;
out_runtime_pm_disable: return devm_iio_device_register(dev, indio_dev);
pm_runtime_get_sync(data->dev);
pm_runtime_put_noidle(data->dev);
pm_runtime_disable(data->dev);
out_disable_regulators:
regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
return ret;
} }
EXPORT_SYMBOL(bmp280_common_probe); EXPORT_SYMBOL(bmp280_common_probe);
int bmp280_common_remove(struct device *dev)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmp280_data *data = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
pm_runtime_get_sync(data->dev);
pm_runtime_put_noidle(data->dev);
pm_runtime_disable(data->dev);
regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
return 0;
}
EXPORT_SYMBOL(bmp280_common_remove);
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int bmp280_runtime_suspend(struct device *dev) static int bmp280_runtime_suspend(struct device *dev)
{ {
......
...@@ -38,11 +38,6 @@ static int bmp280_i2c_probe(struct i2c_client *client, ...@@ -38,11 +38,6 @@ static int bmp280_i2c_probe(struct i2c_client *client,
client->irq); client->irq);
} }
static int bmp280_i2c_remove(struct i2c_client *client)
{
return bmp280_common_remove(&client->dev);
}
static const struct acpi_device_id bmp280_acpi_i2c_match[] = { static const struct acpi_device_id bmp280_acpi_i2c_match[] = {
{"BMP0280", BMP280_CHIP_ID }, {"BMP0280", BMP280_CHIP_ID },
{"BMP0180", BMP180_CHIP_ID }, {"BMP0180", BMP180_CHIP_ID },
...@@ -82,7 +77,6 @@ static struct i2c_driver bmp280_i2c_driver = { ...@@ -82,7 +77,6 @@ static struct i2c_driver bmp280_i2c_driver = {
.pm = &bmp280_dev_pm_ops, .pm = &bmp280_dev_pm_ops,
}, },
.probe = bmp280_i2c_probe, .probe = bmp280_i2c_probe,
.remove = bmp280_i2c_remove,
.id_table = bmp280_i2c_id, .id_table = bmp280_i2c_id,
}; };
module_i2c_driver(bmp280_i2c_driver); module_i2c_driver(bmp280_i2c_driver);
......
...@@ -86,11 +86,6 @@ static int bmp280_spi_probe(struct spi_device *spi) ...@@ -86,11 +86,6 @@ static int bmp280_spi_probe(struct spi_device *spi)
spi->irq); spi->irq);
} }
static int bmp280_spi_remove(struct spi_device *spi)
{
return bmp280_common_remove(&spi->dev);
}
static const struct of_device_id bmp280_of_spi_match[] = { static const struct of_device_id bmp280_of_spi_match[] = {
{ .compatible = "bosch,bmp085", }, { .compatible = "bosch,bmp085", },
{ .compatible = "bosch,bmp180", }, { .compatible = "bosch,bmp180", },
...@@ -118,7 +113,6 @@ static struct spi_driver bmp280_spi_driver = { ...@@ -118,7 +113,6 @@ static struct spi_driver bmp280_spi_driver = {
}, },
.id_table = bmp280_spi_id, .id_table = bmp280_spi_id,
.probe = bmp280_spi_probe, .probe = bmp280_spi_probe,
.remove = bmp280_spi_remove,
}; };
module_spi_driver(bmp280_spi_driver); module_spi_driver(bmp280_spi_driver);
......
...@@ -112,7 +112,6 @@ int bmp280_common_probe(struct device *dev, ...@@ -112,7 +112,6 @@ int bmp280_common_probe(struct device *dev,
unsigned int chip, unsigned int chip,
const char *name, const char *name,
int irq); int irq);
int bmp280_common_remove(struct device *dev);
/* PM ops */ /* PM ops */
extern const struct dev_pm_ops bmp280_dev_pm_ops; extern const struct dev_pm_ops bmp280_dev_pm_ops;
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