Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 5da669d

Browse files
vamoiridgregkh
authored andcommitted
iio: pressure: bmp280: Use BME prefix for BME280 specifics
[ Upstream commit b23be4c ] Change the rest of the defines and function names that are used specifically by the BME280 humidity sensor to BME280 as it is done for the rest of the BMP{0,1,3,5}80 sensors. Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com> Link: https://lore.kernel.org/r/20240429190046.24252-3-vassilisamir@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Stable-dep-of: b9065b0 ("iio: pressure: bmp280: Fix regmap for BMP280 device") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b71b2d7 commit 5da669d

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

drivers/iio/pressure/bmp280-core.c

+18-19
Original file line numberDiff line numberDiff line change
@@ -234,29 +234,29 @@ static int bme280_read_calib(struct bmp280_data *data)
234234
* Humidity data is only available on BME280.
235235
*/
236236

237-
ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &tmp);
237+
ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp);
238238
if (ret < 0) {
239239
dev_err(dev, "failed to read H1 comp value\n");
240240
return ret;
241241
}
242242
calib->H1 = tmp;
243243

244-
ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2,
244+
ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2,
245245
&data->le16, sizeof(data->le16));
246246
if (ret < 0) {
247247
dev_err(dev, "failed to read H2 comp value\n");
248248
return ret;
249249
}
250250
calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15);
251251

252-
ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &tmp);
252+
ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp);
253253
if (ret < 0) {
254254
dev_err(dev, "failed to read H3 comp value\n");
255255
return ret;
256256
}
257257
calib->H3 = tmp;
258258

259-
ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4,
259+
ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4,
260260
&data->be16, sizeof(data->be16));
261261
if (ret < 0) {
262262
dev_err(dev, "failed to read H4 comp value\n");
@@ -265,15 +265,15 @@ static int bme280_read_calib(struct bmp280_data *data)
265265
calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) |
266266
(be16_to_cpu(data->be16) & 0xf), 11);
267267

268-
ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5,
268+
ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5,
269269
&data->le16, sizeof(data->le16));
270270
if (ret < 0) {
271271
dev_err(dev, "failed to read H5 comp value\n");
272272
return ret;
273273
}
274-
calib->H5 = sign_extend32(FIELD_GET(BMP280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11);
274+
calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11);
275275

276-
ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp);
276+
ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp);
277277
if (ret < 0) {
278278
dev_err(dev, "failed to read H6 comp value\n");
279279
return ret;
@@ -289,7 +289,7 @@ static int bme280_read_calib(struct bmp280_data *data)
289289
*
290290
* Taken from BME280 datasheet, Section 4.2.3, "Compensation formula".
291291
*/
292-
static u32 bmp280_compensate_humidity(struct bmp280_data *data,
292+
static u32 bme280_compensate_humidity(struct bmp280_data *data,
293293
s32 adc_humidity)
294294
{
295295
struct bmp280_calib *calib = &data->calib.bmp280;
@@ -429,7 +429,7 @@ static int bmp280_read_press(struct bmp280_data *data,
429429
return IIO_VAL_FRACTIONAL;
430430
}
431431

432-
static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
432+
static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2)
433433
{
434434
u32 comp_humidity;
435435
s32 adc_humidity;
@@ -440,7 +440,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
440440
if (ret < 0)
441441
return ret;
442442

443-
ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB,
443+
ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB,
444444
&data->be16, sizeof(data->be16));
445445
if (ret < 0) {
446446
dev_err(data->dev, "failed to read humidity\n");
@@ -453,7 +453,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
453453
dev_err(data->dev, "reading humidity skipped\n");
454454
return -EIO;
455455
}
456-
comp_humidity = bmp280_compensate_humidity(data, adc_humidity);
456+
comp_humidity = bme280_compensate_humidity(data, adc_humidity);
457457

458458
*val = comp_humidity * 1000 / 1024;
459459

@@ -537,7 +537,7 @@ static int bmp280_read_raw(struct iio_dev *indio_dev,
537537
return ret;
538538
}
539539

540-
static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data,
540+
static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data,
541541
int val)
542542
{
543543
const int *avail = data->chip_info->oversampling_humid_avail;
@@ -681,7 +681,7 @@ static int bmp280_write_raw(struct iio_dev *indio_dev,
681681
mutex_lock(&data->lock);
682682
switch (chan->type) {
683683
case IIO_HUMIDITYRELATIVE:
684-
ret = bmp280_write_oversampling_ratio_humid(data, val);
684+
ret = bme280_write_oversampling_ratio_humid(data, val);
685685
break;
686686
case IIO_PRESSURE:
687687
ret = bmp280_write_oversampling_ratio_press(data, val);
@@ -831,16 +831,15 @@ EXPORT_SYMBOL_NS(bmp280_chip_info, IIO_BMP280);
831831

832832
static int bme280_chip_config(struct bmp280_data *data)
833833
{
834-
u8 osrs = FIELD_PREP(BMP280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1);
834+
u8 osrs = FIELD_PREP(BME280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1);
835835
int ret;
836836

837837
/*
838838
* Oversampling of humidity must be set before oversampling of
839839
* temperature/pressure is set to become effective.
840840
*/
841-
ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
842-
BMP280_OSRS_HUMIDITY_MASK, osrs);
843-
841+
ret = regmap_update_bits(data->regmap, BME280_REG_CTRL_HUMIDITY,
842+
BME280_OSRS_HUMIDITY_MASK, osrs);
844843
if (ret < 0)
845844
return ret;
846845

@@ -868,12 +867,12 @@ const struct bmp280_chip_info bme280_chip_info = {
868867

869868
.oversampling_humid_avail = bmp280_oversampling_avail,
870869
.num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail),
871-
.oversampling_humid_default = BMP280_OSRS_HUMIDITY_16X - 1,
870+
.oversampling_humid_default = BME280_OSRS_HUMIDITY_16X - 1,
872871

873872
.chip_config = bme280_chip_config,
874873
.read_temp = bmp280_read_temp,
875874
.read_press = bmp280_read_press,
876-
.read_humid = bmp280_read_humid,
875+
.read_humid = bme280_read_humid,
877876
.read_calib = bme280_read_calib,
878877
};
879878
EXPORT_SYMBOL_NS(bme280_chip_info, IIO_BMP280);

drivers/iio/pressure/bmp280-regmap.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
4545
{
4646
switch (reg) {
4747
case BMP280_REG_CONFIG:
48-
case BMP280_REG_CTRL_HUMIDITY:
48+
case BME280_REG_CTRL_HUMIDITY:
4949
case BMP280_REG_CTRL_MEAS:
5050
case BMP280_REG_RESET:
5151
return true;
@@ -57,8 +57,8 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
5757
static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
5858
{
5959
switch (reg) {
60-
case BMP280_REG_HUMIDITY_LSB:
61-
case BMP280_REG_HUMIDITY_MSB:
60+
case BME280_REG_HUMIDITY_LSB:
61+
case BME280_REG_HUMIDITY_MSB:
6262
case BMP280_REG_TEMP_XLSB:
6363
case BMP280_REG_TEMP_LSB:
6464
case BMP280_REG_TEMP_MSB:
@@ -167,7 +167,7 @@ const struct regmap_config bmp280_regmap_config = {
167167
.reg_bits = 8,
168168
.val_bits = 8,
169169

170-
.max_register = BMP280_REG_HUMIDITY_LSB,
170+
.max_register = BME280_REG_HUMIDITY_LSB,
171171
.cache_type = REGCACHE_RBTREE,
172172

173173
.writeable_reg = bmp280_is_writeable_reg,

drivers/iio/pressure/bmp280.h

+24-21
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@
192192
#define BMP380_PRESS_SKIPPED 0x800000
193193

194194
/* BMP280 specific registers */
195-
#define BMP280_REG_HUMIDITY_LSB 0xFE
196-
#define BMP280_REG_HUMIDITY_MSB 0xFD
197195
#define BMP280_REG_TEMP_XLSB 0xFC
198196
#define BMP280_REG_TEMP_LSB 0xFB
199197
#define BMP280_REG_TEMP_MSB 0xFA
@@ -207,24 +205,13 @@
207205
#define BMP280_REG_CONFIG 0xF5
208206
#define BMP280_REG_CTRL_MEAS 0xF4
209207
#define BMP280_REG_STATUS 0xF3
210-
#define BMP280_REG_CTRL_HUMIDITY 0xF2
211-
212-
/* Due to non linear mapping, and data sizes we can't do a bulk read */
213-
#define BMP280_REG_COMP_H1 0xA1
214-
#define BMP280_REG_COMP_H2 0xE1
215-
#define BMP280_REG_COMP_H3 0xE3
216-
#define BMP280_REG_COMP_H4 0xE4
217-
#define BMP280_REG_COMP_H5 0xE5
218-
#define BMP280_REG_COMP_H6 0xE7
219208

220209
#define BMP280_REG_COMP_TEMP_START 0x88
221210
#define BMP280_COMP_TEMP_REG_COUNT 6
222211

223212
#define BMP280_REG_COMP_PRESS_START 0x8E
224213
#define BMP280_COMP_PRESS_REG_COUNT 18
225214

226-
#define BMP280_COMP_H5_MASK GENMASK(15, 4)
227-
228215
#define BMP280_CONTIGUOUS_CALIB_REGS (BMP280_COMP_TEMP_REG_COUNT + \
229216
BMP280_COMP_PRESS_REG_COUNT)
230217

@@ -235,14 +222,6 @@
235222
#define BMP280_FILTER_8X 3
236223
#define BMP280_FILTER_16X 4
237224

238-
#define BMP280_OSRS_HUMIDITY_MASK GENMASK(2, 0)
239-
#define BMP280_OSRS_HUMIDITY_SKIP 0
240-
#define BMP280_OSRS_HUMIDITY_1X 1
241-
#define BMP280_OSRS_HUMIDITY_2X 2
242-
#define BMP280_OSRS_HUMIDITY_4X 3
243-
#define BMP280_OSRS_HUMIDITY_8X 4
244-
#define BMP280_OSRS_HUMIDITY_16X 5
245-
246225
#define BMP280_OSRS_TEMP_MASK GENMASK(7, 5)
247226
#define BMP280_OSRS_TEMP_SKIP 0
248227
#define BMP280_OSRS_TEMP_1X 1
@@ -264,6 +243,30 @@
264243
#define BMP280_MODE_FORCED 1
265244
#define BMP280_MODE_NORMAL 3
266245

246+
/* BME280 specific registers */
247+
#define BME280_REG_HUMIDITY_LSB 0xFE
248+
#define BME280_REG_HUMIDITY_MSB 0xFD
249+
250+
#define BME280_REG_CTRL_HUMIDITY 0xF2
251+
252+
/* Due to non linear mapping, and data sizes we can't do a bulk read */
253+
#define BME280_REG_COMP_H1 0xA1
254+
#define BME280_REG_COMP_H2 0xE1
255+
#define BME280_REG_COMP_H3 0xE3
256+
#define BME280_REG_COMP_H4 0xE4
257+
#define BME280_REG_COMP_H5 0xE5
258+
#define BME280_REG_COMP_H6 0xE7
259+
260+
#define BME280_COMP_H5_MASK GENMASK(15, 4)
261+
262+
#define BME280_OSRS_HUMIDITY_MASK GENMASK(2, 0)
263+
#define BME280_OSRS_HUMIDITY_SKIP 0
264+
#define BME280_OSRS_HUMIDITY_1X 1
265+
#define BME280_OSRS_HUMIDITY_2X 2
266+
#define BME280_OSRS_HUMIDITY_4X 3
267+
#define BME280_OSRS_HUMIDITY_8X 4
268+
#define BME280_OSRS_HUMIDITY_16X 5
269+
267270
/* BMP180 specific registers */
268271
#define BMP180_REG_OUT_XLSB 0xF8
269272
#define BMP180_REG_OUT_LSB 0xF7

0 commit comments

Comments
 (0)