| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2010 Christoph Mair <christoph.mair@gmail.com> |
|---|
| 3 | 4 | * Copyright (c) 2012 Bosch Sensortec GmbH |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (c) 2016 Linus Walleij <linus.walleij@linaro.org> |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Driver for Bosch Sensortec BMP180 and BMP280 digital pressure sensor. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | * |
|---|
| 14 | 11 | * Datasheet: |
|---|
| 15 | 12 | * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP180-DS000-121.pdf |
|---|
| .. | .. |
|---|
| 77 | 74 | s8 H6; |
|---|
| 78 | 75 | }; |
|---|
| 79 | 76 | |
|---|
| 77 | +static const char *const bmp280_supply_names[] = { |
|---|
| 78 | + "vddd", "vdda" |
|---|
| 79 | +}; |
|---|
| 80 | + |
|---|
| 81 | +#define BMP280_NUM_SUPPLIES ARRAY_SIZE(bmp280_supply_names) |
|---|
| 82 | + |
|---|
| 80 | 83 | struct bmp280_data { |
|---|
| 81 | 84 | struct device *dev; |
|---|
| 82 | 85 | struct mutex lock; |
|---|
| .. | .. |
|---|
| 88 | 91 | struct bmp180_calib bmp180; |
|---|
| 89 | 92 | struct bmp280_calib bmp280; |
|---|
| 90 | 93 | } calib; |
|---|
| 91 | | - struct regulator *vddd; |
|---|
| 92 | | - struct regulator *vdda; |
|---|
| 94 | + struct regulator_bulk_data supplies[BMP280_NUM_SUPPLIES]; |
|---|
| 93 | 95 | unsigned int start_up_time; /* in microseconds */ |
|---|
| 94 | 96 | |
|---|
| 95 | 97 | /* log of base 2 of oversampling rate */ |
|---|
| .. | .. |
|---|
| 151 | 153 | { |
|---|
| 152 | 154 | int ret; |
|---|
| 153 | 155 | unsigned int tmp; |
|---|
| 156 | + __le16 l16; |
|---|
| 157 | + __be16 b16; |
|---|
| 154 | 158 | struct device *dev = data->dev; |
|---|
| 155 | 159 | __le16 t_buf[BMP280_COMP_TEMP_REG_COUNT / 2]; |
|---|
| 156 | 160 | __le16 p_buf[BMP280_COMP_PRESS_REG_COUNT / 2]; |
|---|
| .. | .. |
|---|
| 164 | 168 | return ret; |
|---|
| 165 | 169 | } |
|---|
| 166 | 170 | |
|---|
| 171 | + /* Toss the temperature calibration data into the entropy pool */ |
|---|
| 172 | + add_device_randomness(t_buf, sizeof(t_buf)); |
|---|
| 173 | + |
|---|
| 167 | 174 | calib->T1 = le16_to_cpu(t_buf[T1]); |
|---|
| 168 | 175 | calib->T2 = le16_to_cpu(t_buf[T2]); |
|---|
| 169 | 176 | calib->T3 = le16_to_cpu(t_buf[T3]); |
|---|
| .. | .. |
|---|
| 176 | 183 | "failed to read pressure calibration parameters\n"); |
|---|
| 177 | 184 | return ret; |
|---|
| 178 | 185 | } |
|---|
| 186 | + |
|---|
| 187 | + /* Toss the pressure calibration data into the entropy pool */ |
|---|
| 188 | + add_device_randomness(p_buf, sizeof(p_buf)); |
|---|
| 179 | 189 | |
|---|
| 180 | 190 | calib->P1 = le16_to_cpu(p_buf[P1]); |
|---|
| 181 | 191 | calib->P2 = le16_to_cpu(p_buf[P2]); |
|---|
| .. | .. |
|---|
| 204 | 214 | } |
|---|
| 205 | 215 | calib->H1 = tmp; |
|---|
| 206 | 216 | |
|---|
| 207 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, &tmp, 2); |
|---|
| 217 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, &l16, 2); |
|---|
| 208 | 218 | if (ret < 0) { |
|---|
| 209 | 219 | dev_err(dev, "failed to read H2 comp value\n"); |
|---|
| 210 | 220 | return ret; |
|---|
| 211 | 221 | } |
|---|
| 212 | | - calib->H2 = sign_extend32(le16_to_cpu(tmp), 15); |
|---|
| 222 | + calib->H2 = sign_extend32(le16_to_cpu(l16), 15); |
|---|
| 213 | 223 | |
|---|
| 214 | 224 | ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &tmp); |
|---|
| 215 | 225 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 218 | 228 | } |
|---|
| 219 | 229 | calib->H3 = tmp; |
|---|
| 220 | 230 | |
|---|
| 221 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, &tmp, 2); |
|---|
| 231 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, &b16, 2); |
|---|
| 222 | 232 | if (ret < 0) { |
|---|
| 223 | 233 | dev_err(dev, "failed to read H4 comp value\n"); |
|---|
| 224 | 234 | return ret; |
|---|
| 225 | 235 | } |
|---|
| 226 | | - calib->H4 = sign_extend32(((be16_to_cpu(tmp) >> 4) & 0xff0) | |
|---|
| 227 | | - (be16_to_cpu(tmp) & 0xf), 11); |
|---|
| 236 | + calib->H4 = sign_extend32(((be16_to_cpu(b16) >> 4) & 0xff0) | |
|---|
| 237 | + (be16_to_cpu(b16) & 0xf), 11); |
|---|
| 228 | 238 | |
|---|
| 229 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, &tmp, 2); |
|---|
| 239 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, &l16, 2); |
|---|
| 230 | 240 | if (ret < 0) { |
|---|
| 231 | 241 | dev_err(dev, "failed to read H5 comp value\n"); |
|---|
| 232 | 242 | return ret; |
|---|
| 233 | 243 | } |
|---|
| 234 | | - calib->H5 = sign_extend32(((le16_to_cpu(tmp) >> 4) & 0xfff), 11); |
|---|
| 244 | + calib->H5 = sign_extend32(((le16_to_cpu(l16) >> 4) & 0xfff), 11); |
|---|
| 235 | 245 | |
|---|
| 236 | 246 | ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp); |
|---|
| 237 | 247 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 329 | 339 | __be32 tmp = 0; |
|---|
| 330 | 340 | s32 adc_temp, comp_temp; |
|---|
| 331 | 341 | |
|---|
| 332 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, |
|---|
| 333 | | - (u8 *) &tmp, 3); |
|---|
| 342 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, &tmp, 3); |
|---|
| 334 | 343 | if (ret < 0) { |
|---|
| 335 | 344 | dev_err(data->dev, "failed to read temperature\n"); |
|---|
| 336 | 345 | return ret; |
|---|
| .. | .. |
|---|
| 369 | 378 | if (ret < 0) |
|---|
| 370 | 379 | return ret; |
|---|
| 371 | 380 | |
|---|
| 372 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, |
|---|
| 373 | | - (u8 *) &tmp, 3); |
|---|
| 381 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, &tmp, 3); |
|---|
| 374 | 382 | if (ret < 0) { |
|---|
| 375 | 383 | dev_err(data->dev, "failed to read pressure\n"); |
|---|
| 376 | 384 | return ret; |
|---|
| .. | .. |
|---|
| 392 | 400 | |
|---|
| 393 | 401 | static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) |
|---|
| 394 | 402 | { |
|---|
| 403 | + __be16 tmp; |
|---|
| 395 | 404 | int ret; |
|---|
| 396 | | - __be16 tmp = 0; |
|---|
| 397 | 405 | s32 adc_humidity; |
|---|
| 398 | 406 | u32 comp_humidity; |
|---|
| 399 | 407 | |
|---|
| .. | .. |
|---|
| 402 | 410 | if (ret < 0) |
|---|
| 403 | 411 | return ret; |
|---|
| 404 | 412 | |
|---|
| 405 | | - ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, |
|---|
| 406 | | - (u8 *) &tmp, 2); |
|---|
| 413 | + ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, &tmp, 2); |
|---|
| 407 | 414 | if (ret < 0) { |
|---|
| 408 | 415 | dev_err(data->dev, "failed to read humidity\n"); |
|---|
| 409 | 416 | return ret; |
|---|
| .. | .. |
|---|
| 567 | 574 | return ret; |
|---|
| 568 | 575 | } |
|---|
| 569 | 576 | |
|---|
| 570 | | -static ssize_t bmp280_show_avail(char *buf, const int *vals, const int n) |
|---|
| 577 | +static int bmp280_read_avail(struct iio_dev *indio_dev, |
|---|
| 578 | + struct iio_chan_spec const *chan, |
|---|
| 579 | + const int **vals, int *type, int *length, |
|---|
| 580 | + long mask) |
|---|
| 571 | 581 | { |
|---|
| 572 | | - size_t len = 0; |
|---|
| 573 | | - int i; |
|---|
| 582 | + struct bmp280_data *data = iio_priv(indio_dev); |
|---|
| 574 | 583 | |
|---|
| 575 | | - for (i = 0; i < n; i++) |
|---|
| 576 | | - len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", vals[i]); |
|---|
| 577 | | - |
|---|
| 578 | | - buf[len - 1] = '\n'; |
|---|
| 579 | | - |
|---|
| 580 | | - return len; |
|---|
| 584 | + switch (mask) { |
|---|
| 585 | + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: |
|---|
| 586 | + switch (chan->type) { |
|---|
| 587 | + case IIO_PRESSURE: |
|---|
| 588 | + *vals = data->chip_info->oversampling_press_avail; |
|---|
| 589 | + *length = data->chip_info->num_oversampling_press_avail; |
|---|
| 590 | + break; |
|---|
| 591 | + case IIO_TEMP: |
|---|
| 592 | + *vals = data->chip_info->oversampling_temp_avail; |
|---|
| 593 | + *length = data->chip_info->num_oversampling_temp_avail; |
|---|
| 594 | + break; |
|---|
| 595 | + default: |
|---|
| 596 | + return -EINVAL; |
|---|
| 597 | + } |
|---|
| 598 | + *type = IIO_VAL_INT; |
|---|
| 599 | + return IIO_AVAIL_LIST; |
|---|
| 600 | + default: |
|---|
| 601 | + return -EINVAL; |
|---|
| 602 | + } |
|---|
| 581 | 603 | } |
|---|
| 582 | | - |
|---|
| 583 | | -static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev, |
|---|
| 584 | | - struct device_attribute *attr, char *buf) |
|---|
| 585 | | -{ |
|---|
| 586 | | - struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 587 | | - |
|---|
| 588 | | - return bmp280_show_avail(buf, data->chip_info->oversampling_temp_avail, |
|---|
| 589 | | - data->chip_info->num_oversampling_temp_avail); |
|---|
| 590 | | -} |
|---|
| 591 | | - |
|---|
| 592 | | -static ssize_t bmp280_show_press_oversampling_avail(struct device *dev, |
|---|
| 593 | | - struct device_attribute *attr, char *buf) |
|---|
| 594 | | -{ |
|---|
| 595 | | - struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 596 | | - |
|---|
| 597 | | - return bmp280_show_avail(buf, data->chip_info->oversampling_press_avail, |
|---|
| 598 | | - data->chip_info->num_oversampling_press_avail); |
|---|
| 599 | | -} |
|---|
| 600 | | - |
|---|
| 601 | | -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available, |
|---|
| 602 | | - S_IRUGO, bmp280_show_temp_oversampling_avail, NULL, 0); |
|---|
| 603 | | - |
|---|
| 604 | | -static IIO_DEVICE_ATTR(in_pressure_oversampling_ratio_available, |
|---|
| 605 | | - S_IRUGO, bmp280_show_press_oversampling_avail, NULL, 0); |
|---|
| 606 | | - |
|---|
| 607 | | -static struct attribute *bmp280_attributes[] = { |
|---|
| 608 | | - &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr, |
|---|
| 609 | | - &iio_dev_attr_in_pressure_oversampling_ratio_available.dev_attr.attr, |
|---|
| 610 | | - NULL, |
|---|
| 611 | | -}; |
|---|
| 612 | | - |
|---|
| 613 | | -static const struct attribute_group bmp280_attrs_group = { |
|---|
| 614 | | - .attrs = bmp280_attributes, |
|---|
| 615 | | -}; |
|---|
| 616 | 604 | |
|---|
| 617 | 605 | static const struct iio_info bmp280_info = { |
|---|
| 618 | 606 | .read_raw = &bmp280_read_raw, |
|---|
| 607 | + .read_avail = &bmp280_read_avail, |
|---|
| 619 | 608 | .write_raw = &bmp280_write_raw, |
|---|
| 620 | | - .attrs = &bmp280_attrs_group, |
|---|
| 621 | 609 | }; |
|---|
| 622 | 610 | |
|---|
| 623 | 611 | static int bmp280_chip_config(struct bmp280_data *data) |
|---|
| .. | .. |
|---|
| 744 | 732 | |
|---|
| 745 | 733 | static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) |
|---|
| 746 | 734 | { |
|---|
| 735 | + __be16 tmp; |
|---|
| 747 | 736 | int ret; |
|---|
| 748 | | - __be16 tmp = 0; |
|---|
| 749 | 737 | |
|---|
| 750 | 738 | ret = bmp180_measure(data, BMP180_MEAS_TEMP); |
|---|
| 751 | 739 | if (ret) |
|---|
| 752 | 740 | return ret; |
|---|
| 753 | 741 | |
|---|
| 754 | | - ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 2); |
|---|
| 742 | + ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 2); |
|---|
| 755 | 743 | if (ret) |
|---|
| 756 | 744 | return ret; |
|---|
| 757 | 745 | |
|---|
| .. | .. |
|---|
| 848 | 836 | if (ret) |
|---|
| 849 | 837 | return ret; |
|---|
| 850 | 838 | |
|---|
| 851 | | - ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 3); |
|---|
| 839 | + ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 3); |
|---|
| 852 | 840 | if (ret) |
|---|
| 853 | 841 | return ret; |
|---|
| 854 | 842 | |
|---|
| .. | .. |
|---|
| 957 | 945 | |
|---|
| 958 | 946 | irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); |
|---|
| 959 | 947 | if (irq_trig != IRQF_TRIGGER_RISING) { |
|---|
| 960 | | - dev_err(dev, "non-rising trigger given for EOC interrupt, " |
|---|
| 961 | | - "trying to enforce it\n"); |
|---|
| 948 | + dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n"); |
|---|
| 962 | 949 | irq_trig = IRQF_TRIGGER_RISING; |
|---|
| 963 | 950 | } |
|---|
| 964 | 951 | |
|---|
| .. | .. |
|---|
| 981 | 968 | return 0; |
|---|
| 982 | 969 | } |
|---|
| 983 | 970 | |
|---|
| 971 | +static void bmp280_pm_disable(void *data) |
|---|
| 972 | +{ |
|---|
| 973 | + struct device *dev = data; |
|---|
| 974 | + |
|---|
| 975 | + pm_runtime_get_sync(dev); |
|---|
| 976 | + pm_runtime_put_noidle(dev); |
|---|
| 977 | + pm_runtime_disable(dev); |
|---|
| 978 | +} |
|---|
| 979 | + |
|---|
| 980 | +static void bmp280_regulators_disable(void *data) |
|---|
| 981 | +{ |
|---|
| 982 | + struct regulator_bulk_data *supplies = data; |
|---|
| 983 | + |
|---|
| 984 | + regulator_bulk_disable(BMP280_NUM_SUPPLIES, supplies); |
|---|
| 985 | +} |
|---|
| 986 | + |
|---|
| 984 | 987 | int bmp280_common_probe(struct device *dev, |
|---|
| 985 | 988 | struct regmap *regmap, |
|---|
| 986 | 989 | unsigned int chip, |
|---|
| .. | .. |
|---|
| 1001 | 1004 | mutex_init(&data->lock); |
|---|
| 1002 | 1005 | data->dev = dev; |
|---|
| 1003 | 1006 | |
|---|
| 1004 | | - indio_dev->dev.parent = dev; |
|---|
| 1005 | 1007 | indio_dev->name = name; |
|---|
| 1006 | 1008 | indio_dev->channels = bmp280_channels; |
|---|
| 1007 | 1009 | indio_dev->info = &bmp280_info; |
|---|
| .. | .. |
|---|
| 1035 | 1037 | } |
|---|
| 1036 | 1038 | |
|---|
| 1037 | 1039 | /* Bring up regulators */ |
|---|
| 1038 | | - data->vddd = devm_regulator_get(dev, "vddd"); |
|---|
| 1039 | | - if (IS_ERR(data->vddd)) { |
|---|
| 1040 | | - dev_err(dev, "failed to get VDDD regulator\n"); |
|---|
| 1041 | | - return PTR_ERR(data->vddd); |
|---|
| 1042 | | - } |
|---|
| 1043 | | - ret = regulator_enable(data->vddd); |
|---|
| 1040 | + regulator_bulk_set_supply_names(data->supplies, |
|---|
| 1041 | + bmp280_supply_names, |
|---|
| 1042 | + BMP280_NUM_SUPPLIES); |
|---|
| 1043 | + |
|---|
| 1044 | + ret = devm_regulator_bulk_get(dev, |
|---|
| 1045 | + BMP280_NUM_SUPPLIES, data->supplies); |
|---|
| 1044 | 1046 | if (ret) { |
|---|
| 1045 | | - dev_err(dev, "failed to enable VDDD regulator\n"); |
|---|
| 1047 | + dev_err(dev, "failed to get regulators\n"); |
|---|
| 1046 | 1048 | return ret; |
|---|
| 1047 | 1049 | } |
|---|
| 1048 | | - data->vdda = devm_regulator_get(dev, "vdda"); |
|---|
| 1049 | | - if (IS_ERR(data->vdda)) { |
|---|
| 1050 | | - dev_err(dev, "failed to get VDDA regulator\n"); |
|---|
| 1051 | | - ret = PTR_ERR(data->vdda); |
|---|
| 1052 | | - goto out_disable_vddd; |
|---|
| 1053 | | - } |
|---|
| 1054 | | - ret = regulator_enable(data->vdda); |
|---|
| 1050 | + |
|---|
| 1051 | + ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); |
|---|
| 1055 | 1052 | if (ret) { |
|---|
| 1056 | | - dev_err(dev, "failed to enable VDDA regulator\n"); |
|---|
| 1057 | | - goto out_disable_vddd; |
|---|
| 1053 | + dev_err(dev, "failed to enable regulators\n"); |
|---|
| 1054 | + return ret; |
|---|
| 1058 | 1055 | } |
|---|
| 1056 | + |
|---|
| 1057 | + ret = devm_add_action_or_reset(dev, bmp280_regulators_disable, |
|---|
| 1058 | + data->supplies); |
|---|
| 1059 | + if (ret) |
|---|
| 1060 | + return ret; |
|---|
| 1061 | + |
|---|
| 1059 | 1062 | /* Wait to make sure we started up properly */ |
|---|
| 1060 | 1063 | usleep_range(data->start_up_time, data->start_up_time + 100); |
|---|
| 1061 | 1064 | |
|---|
| 1062 | 1065 | /* Bring chip out of reset if there is an assigned GPIO line */ |
|---|
| 1063 | | - gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); |
|---|
| 1066 | + gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); |
|---|
| 1064 | 1067 | /* Deassert the signal */ |
|---|
| 1065 | | - if (!IS_ERR(gpiod)) { |
|---|
| 1068 | + if (gpiod) { |
|---|
| 1066 | 1069 | dev_info(dev, "release reset\n"); |
|---|
| 1067 | 1070 | gpiod_set_value(gpiod, 0); |
|---|
| 1068 | 1071 | } |
|---|
| .. | .. |
|---|
| 1070 | 1073 | data->regmap = regmap; |
|---|
| 1071 | 1074 | ret = regmap_read(regmap, BMP280_REG_ID, &chip_id); |
|---|
| 1072 | 1075 | if (ret < 0) |
|---|
| 1073 | | - goto out_disable_vdda; |
|---|
| 1076 | + return ret; |
|---|
| 1074 | 1077 | if (chip_id != chip) { |
|---|
| 1075 | 1078 | dev_err(dev, "bad chip id: expected %x got %x\n", |
|---|
| 1076 | 1079 | chip, chip_id); |
|---|
| 1077 | | - ret = -EINVAL; |
|---|
| 1078 | | - goto out_disable_vdda; |
|---|
| 1080 | + return -EINVAL; |
|---|
| 1079 | 1081 | } |
|---|
| 1080 | 1082 | |
|---|
| 1081 | 1083 | ret = data->chip_info->chip_config(data); |
|---|
| 1082 | 1084 | if (ret < 0) |
|---|
| 1083 | | - goto out_disable_vdda; |
|---|
| 1085 | + return ret; |
|---|
| 1084 | 1086 | |
|---|
| 1085 | 1087 | dev_set_drvdata(dev, indio_dev); |
|---|
| 1086 | 1088 | |
|---|
| .. | .. |
|---|
| 1094 | 1096 | if (ret < 0) { |
|---|
| 1095 | 1097 | dev_err(data->dev, |
|---|
| 1096 | 1098 | "failed to read calibration coefficients\n"); |
|---|
| 1097 | | - goto out_disable_vdda; |
|---|
| 1099 | + return ret; |
|---|
| 1098 | 1100 | } |
|---|
| 1099 | 1101 | } else if (chip_id == BMP280_CHIP_ID || chip_id == BME280_CHIP_ID) { |
|---|
| 1100 | 1102 | ret = bmp280_read_calib(data, &data->calib.bmp280, chip_id); |
|---|
| 1101 | 1103 | if (ret < 0) { |
|---|
| 1102 | 1104 | dev_err(data->dev, |
|---|
| 1103 | 1105 | "failed to read calibration coefficients\n"); |
|---|
| 1104 | | - goto out_disable_vdda; |
|---|
| 1106 | + return ret; |
|---|
| 1105 | 1107 | } |
|---|
| 1106 | 1108 | } |
|---|
| 1107 | 1109 | |
|---|
| .. | .. |
|---|
| 1113 | 1115 | if (irq > 0 || (chip_id == BMP180_CHIP_ID)) { |
|---|
| 1114 | 1116 | ret = bmp085_fetch_eoc_irq(dev, name, irq, data); |
|---|
| 1115 | 1117 | if (ret) |
|---|
| 1116 | | - goto out_disable_vdda; |
|---|
| 1118 | + return ret; |
|---|
| 1117 | 1119 | } |
|---|
| 1118 | 1120 | |
|---|
| 1119 | 1121 | /* Enable runtime PM */ |
|---|
| .. | .. |
|---|
| 1128 | 1130 | pm_runtime_use_autosuspend(dev); |
|---|
| 1129 | 1131 | pm_runtime_put(dev); |
|---|
| 1130 | 1132 | |
|---|
| 1131 | | - ret = iio_device_register(indio_dev); |
|---|
| 1133 | + ret = devm_add_action_or_reset(dev, bmp280_pm_disable, dev); |
|---|
| 1132 | 1134 | if (ret) |
|---|
| 1133 | | - goto out_runtime_pm_disable; |
|---|
| 1135 | + return ret; |
|---|
| 1134 | 1136 | |
|---|
| 1135 | | - |
|---|
| 1136 | | - return 0; |
|---|
| 1137 | | - |
|---|
| 1138 | | -out_runtime_pm_disable: |
|---|
| 1139 | | - pm_runtime_get_sync(data->dev); |
|---|
| 1140 | | - pm_runtime_put_noidle(data->dev); |
|---|
| 1141 | | - pm_runtime_disable(data->dev); |
|---|
| 1142 | | -out_disable_vdda: |
|---|
| 1143 | | - regulator_disable(data->vdda); |
|---|
| 1144 | | -out_disable_vddd: |
|---|
| 1145 | | - regulator_disable(data->vddd); |
|---|
| 1146 | | - return ret; |
|---|
| 1137 | + return devm_iio_device_register(dev, indio_dev); |
|---|
| 1147 | 1138 | } |
|---|
| 1148 | 1139 | EXPORT_SYMBOL(bmp280_common_probe); |
|---|
| 1149 | | - |
|---|
| 1150 | | -int bmp280_common_remove(struct device *dev) |
|---|
| 1151 | | -{ |
|---|
| 1152 | | - struct iio_dev *indio_dev = dev_get_drvdata(dev); |
|---|
| 1153 | | - struct bmp280_data *data = iio_priv(indio_dev); |
|---|
| 1154 | | - |
|---|
| 1155 | | - iio_device_unregister(indio_dev); |
|---|
| 1156 | | - pm_runtime_get_sync(data->dev); |
|---|
| 1157 | | - pm_runtime_put_noidle(data->dev); |
|---|
| 1158 | | - pm_runtime_disable(data->dev); |
|---|
| 1159 | | - regulator_disable(data->vdda); |
|---|
| 1160 | | - regulator_disable(data->vddd); |
|---|
| 1161 | | - return 0; |
|---|
| 1162 | | -} |
|---|
| 1163 | | -EXPORT_SYMBOL(bmp280_common_remove); |
|---|
| 1164 | 1140 | |
|---|
| 1165 | 1141 | #ifdef CONFIG_PM |
|---|
| 1166 | 1142 | static int bmp280_runtime_suspend(struct device *dev) |
|---|
| 1167 | 1143 | { |
|---|
| 1168 | 1144 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
|---|
| 1169 | 1145 | struct bmp280_data *data = iio_priv(indio_dev); |
|---|
| 1170 | | - int ret; |
|---|
| 1171 | 1146 | |
|---|
| 1172 | | - ret = regulator_disable(data->vdda); |
|---|
| 1173 | | - if (ret) |
|---|
| 1174 | | - return ret; |
|---|
| 1175 | | - return regulator_disable(data->vddd); |
|---|
| 1147 | + return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); |
|---|
| 1176 | 1148 | } |
|---|
| 1177 | 1149 | |
|---|
| 1178 | 1150 | static int bmp280_runtime_resume(struct device *dev) |
|---|
| .. | .. |
|---|
| 1181 | 1153 | struct bmp280_data *data = iio_priv(indio_dev); |
|---|
| 1182 | 1154 | int ret; |
|---|
| 1183 | 1155 | |
|---|
| 1184 | | - ret = regulator_enable(data->vddd); |
|---|
| 1185 | | - if (ret) |
|---|
| 1186 | | - return ret; |
|---|
| 1187 | | - ret = regulator_enable(data->vdda); |
|---|
| 1156 | + ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); |
|---|
| 1188 | 1157 | if (ret) |
|---|
| 1189 | 1158 | return ret; |
|---|
| 1190 | 1159 | usleep_range(data->start_up_time, data->start_up_time + 100); |
|---|