Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: bmp280: Use bulk read for humidity calibration data

Convert individual reads to a bulk read for the humidity calibration data.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20240902184222.24874-2-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Vasileios Amoiridis and committed by
Jonathan Cameron
61809f18 ee113a9e

+28 -41
+22 -41
drivers/iio/pressure/bmp280-core.c
··· 340 340 return 0; 341 341 } 342 342 343 + /* 344 + * These enums are used for indexing into the array of humidity parameters 345 + * for BME280. Due to some weird indexing, unaligned BE/LE accesses co-exist in 346 + * order to prepare the FIELD_{GET/PREP}() fields. Table 16 in Section 4.2.2 of 347 + * the datasheet. 348 + */ 349 + enum { H2 = 0, H3 = 2, H4 = 3, H5 = 4, H6 = 6 }; 350 + 343 351 static int bme280_read_calib(struct bmp280_data *data) 344 352 { 345 353 struct bmp280_calib *calib = &data->calib.bmp280; 346 354 struct device *dev = data->dev; 355 + s16 h4_upper, h4_lower, tmp_1, tmp_2, tmp_3; 347 356 unsigned int tmp; 348 357 int ret; 349 358 ··· 360 351 ret = bmp280_read_calib(data); 361 352 if (ret) 362 353 return ret; 363 - 364 - /* 365 - * Read humidity calibration values. 366 - * Due to some odd register addressing we cannot just 367 - * do a big bulk read. Instead, we have to read each Hx 368 - * value separately and sometimes do some bit shifting... 369 - * Humidity data is only available on BME280. 370 - */ 371 354 372 355 ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); 373 356 if (ret) { ··· 369 368 calib->H1 = tmp; 370 369 371 370 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, 372 - &data->le16, sizeof(data->le16)); 371 + data->bme280_humid_cal_buf, 372 + sizeof(data->bme280_humid_cal_buf)); 373 373 if (ret) { 374 - dev_err(dev, "failed to read H2 comp value\n"); 374 + dev_err(dev, "failed to read humidity calibration values\n"); 375 375 return ret; 376 376 } 377 - calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); 378 377 379 - ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp); 380 - if (ret) { 381 - dev_err(dev, "failed to read H3 comp value\n"); 382 - return ret; 383 - } 384 - calib->H3 = tmp; 385 - 386 - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4, 387 - &data->be16, sizeof(data->be16)); 388 - if (ret) { 389 - dev_err(dev, "failed to read H4 comp value\n"); 390 - return ret; 391 - } 392 - calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | 393 - (be16_to_cpu(data->be16) & 0xf), 11); 394 - 395 - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5, 396 - &data->le16, sizeof(data->le16)); 397 - if (ret) { 398 - dev_err(dev, "failed to read H5 comp value\n"); 399 - return ret; 400 - } 401 - calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); 402 - 403 - ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp); 404 - if (ret) { 405 - dev_err(dev, "failed to read H6 comp value\n"); 406 - return ret; 407 - } 408 - calib->H6 = sign_extend32(tmp, 7); 378 + calib->H2 = get_unaligned_le16(&data->bme280_humid_cal_buf[H2]); 379 + calib->H3 = data->bme280_humid_cal_buf[H3]; 380 + tmp_1 = get_unaligned_be16(&data->bme280_humid_cal_buf[H4]); 381 + tmp_2 = FIELD_GET(BME280_COMP_H4_GET_MASK_UP, tmp_1); 382 + h4_upper = FIELD_PREP(BME280_COMP_H4_PREP_MASK_UP, tmp_2); 383 + h4_lower = FIELD_GET(BME280_COMP_H4_MASK_LOW, tmp_1); 384 + calib->H4 = sign_extend32(h4_upper | h4_lower, 11); 385 + tmp_3 = get_unaligned_le16(&data->bme280_humid_cal_buf[H5]); 386 + calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, tmp_3), 11); 387 + calib->H6 = data->bme280_humid_cal_buf[H6]; 409 388 410 389 return 0; 411 390 }
+6
drivers/iio/pressure/bmp280.h
··· 257 257 #define BME280_REG_COMP_H5 0xE5 258 258 #define BME280_REG_COMP_H6 0xE7 259 259 260 + #define BME280_COMP_H4_GET_MASK_UP GENMASK(15, 8) 261 + #define BME280_COMP_H4_PREP_MASK_UP GENMASK(11, 4) 262 + #define BME280_COMP_H4_MASK_LOW GENMASK(3, 0) 260 263 #define BME280_COMP_H5_MASK GENMASK(15, 4) 264 + 265 + #define BME280_CONTIGUOUS_CALIB_REGS 7 261 266 262 267 #define BME280_OSRS_HUMIDITY_MASK GENMASK(2, 0) 263 268 #define BME280_OSRS_HUMIDITY_SKIP 0 ··· 428 423 /* Calibration data buffers */ 429 424 __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; 430 425 __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; 426 + u8 bme280_humid_cal_buf[BME280_CONTIGUOUS_CALIB_REGS]; 431 427 u8 bmp380_cal_buf[BMP380_CALIB_REG_COUNT]; 432 428 /* Miscellaneous, endianness-aware data buffers */ 433 429 __le16 le16;