linux/drivers/iio/pressure/bmp280-core.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2010 Christoph Mair <[email protected]>
 * Copyright (c) 2012 Bosch Sensortec GmbH
 * Copyright (c) 2012 Unixphere AB
 * Copyright (c) 2014 Intel Corporation
 * Copyright (c) 2016 Linus Walleij <[email protected]>
 *
 * Driver for Bosch Sensortec BMP180 and BMP280 digital pressure sensor.
 *
 * Datasheet:
 * https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf
 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf
 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf
 *
 * Notice:
 * The link to the bmp180 datasheet points to an outdated version missing these changes:
 * - Changed document referral from ANP015 to BST-MPS-AN004-00 on page 26
 * - Updated equation for B3 param on section 3.5 to ((((long)AC1 * 4 + X3) << oss) + 2) / 4
 * - Updated RoHS directive to 2011/65/EU effective 8 June 2011 on page 26
 */

#define pr_fmt(fmt)

#include <linux/bitops.h>
#include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
#include <linux/irq.h> /* For irq_get_irq_data() */
#include <linux/module.h>
#include <linux/nvmem-provider.h>
#include <linux/pm_runtime.h>
#include <linux/random.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>

#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>

#include <linux/unaligned.h>

#include "bmp280.h"

/*
 * These enums are used for indexing into the array of calibration
 * coefficients for BMP180.
 */
enum {};

enum bmp380_odr {};

enum bmp580_odr {};

/*
 * These enums are used for indexing into the array of compensation
 * parameters for BMP280.
 */
enum {};

enum {};

enum bmp280_scan {};

static const struct iio_chan_spec bmp280_channels[] =;

static const struct iio_chan_spec bme280_channels[] =;

static const struct iio_chan_spec bmp380_channels[] =;

static const struct iio_chan_spec bmp580_channels[] =;

static int bmp280_read_calib(struct bmp280_data *data)
{}

static int bme280_read_calib(struct bmp280_data *data)
{}

static int bme280_read_humid_adc(struct bmp280_data *data, u16 *adc_humidity)
{}

/*
 * Returns humidity in percent, resolution is 0.01 percent. Output value of
 * "47445" represents 47445/1024 = 46.333 %RH.
 *
 * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula".
 */
static u32 bme280_compensate_humidity(struct bmp280_data *data,
				      u16 adc_humidity, s32 t_fine)
{}

static int bmp280_read_temp_adc(struct bmp280_data *data, u32 *adc_temp)
{}

/*
 * Returns temperature in DegC, resolution is 0.01 DegC.  Output value of
 * "5123" equals 51.23 DegC.  t_fine carries fine temperature as global
 * value.
 *
 * Taken from datasheet, Section 3.11.3, "Compensation formula".
 */
static s32 bmp280_calc_t_fine(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp280_get_t_fine(struct bmp280_data *data, s32 *t_fine)
{}

static s32 bmp280_compensate_temp(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp280_read_press_adc(struct bmp280_data *data, u32 *adc_press)
{}

/*
 * Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24
 * integer bits and 8 fractional bits).  Output value of "24674867"
 * represents 24674867/256 = 96386.2 Pa = 963.862 hPa
 *
 * Taken from datasheet, Section 3.11.3, "Compensation formula".
 */
static u32 bmp280_compensate_press(struct bmp280_data *data,
				   u32 adc_press, s32 t_fine)
{}

static int bmp280_read_temp(struct bmp280_data *data, s32 *comp_temp)
{}

static int bmp280_read_press(struct bmp280_data *data, u32 *comp_press)
{}

static int bme280_read_humid(struct bmp280_data *data, u32 *comp_humidity)
{}

static int bmp280_read_raw_impl(struct iio_dev *indio_dev,
				struct iio_chan_spec const *chan,
				int *val, int *val2, long mask)
{}

static int bmp280_read_raw(struct iio_dev *indio_dev,
			   struct iio_chan_spec const *chan,
			   int *val, int *val2, long mask)
{}

static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data,
						 int val)
{}

static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data,
						int val)
{}

static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data,
						 int val)
{}

static int bmp280_write_sampling_frequency(struct bmp280_data *data,
					   int val, int val2)
{}

static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val)
{}

static int bmp280_write_raw_impl(struct iio_dev *indio_dev,
				 struct iio_chan_spec const *chan,
				 int val, int val2, long mask)
{}

static int bmp280_write_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan,
			    int val, int val2, long mask)
{}

static int bmp280_read_avail(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan,
			     const int **vals, int *type, int *length,
			     long mask)
{}

static const struct iio_info bmp280_info =;

static const unsigned long bmp280_avail_scan_masks[] =;

static const unsigned long bme280_avail_scan_masks[] =;

static int bmp280_chip_config(struct bmp280_data *data)
{}

static irqreturn_t bmp280_trigger_handler(int irq, void *p)
{}

static const int bmp280_oversampling_avail[] =;
static const u8 bmp280_chip_ids[] =;
static const int bmp280_temp_coeffs[] =;
static const int bmp280_press_coeffs[] =;

const struct bmp280_chip_info bmp280_chip_info =;
EXPORT_SYMBOL_NS();

static int bme280_chip_config(struct bmp280_data *data)
{}

static irqreturn_t bme280_trigger_handler(int irq, void *p)
{}

static const u8 bme280_chip_ids[] =;
static const int bme280_humid_coeffs[] =;

const struct bmp280_chip_info bme280_chip_info =;
EXPORT_SYMBOL_NS();

/*
 * Helper function to send a command to BMP3XX sensors.
 *
 * Sensor processes commands written to the CMD register and signals
 * execution result through "cmd_rdy" and "cmd_error" flags available on
 * STATUS and ERROR registers.
 */
static int bmp380_cmd(struct bmp280_data *data, u8 cmd)
{}

static int bmp380_read_temp_adc(struct bmp280_data *data, u32 *adc_temp)
{}

/*
 * Returns temperature in Celsius degrees, resolution is 0.01º C. Output value
 * of "5123" equals 51.2º C. t_fine carries fine temperature as global value.
 *
 * Taken from datasheet, Section Appendix 9, "Compensation formula" and repo
 * https://github.com/BoschSensortec/BMP3-Sensor-API.
 */
static s32 bmp380_calc_t_fine(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp380_get_t_fine(struct bmp280_data *data, s32 *t_fine)
{}

static int bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp380_read_press_adc(struct bmp280_data *data, u32 *adc_press)
{}

/*
 * Returns pressure in Pa as an unsigned 32 bit integer in fractional Pascal.
 * Output value of "9528709" represents 9528709/100 = 95287.09 Pa = 952.8709 hPa.
 *
 * Taken from datasheet, Section 9.3. "Pressure compensation" and repository
 * https://github.com/BoschSensortec/BMP3-Sensor-API.
 */
static u32 bmp380_compensate_press(struct bmp280_data *data,
				   u32 adc_press, s32 t_fine)
{}

static int bmp380_read_temp(struct bmp280_data *data, s32 *comp_temp)
{}

static int bmp380_read_press(struct bmp280_data *data, u32 *comp_press)
{}

static int bmp380_read_calib(struct bmp280_data *data)
{}

static const int bmp380_odr_table[][2] =;

static int bmp380_preinit(struct bmp280_data *data)
{}

static int bmp380_chip_config(struct bmp280_data *data)
{}

static irqreturn_t bmp380_trigger_handler(int irq, void *p)
{}

static const int bmp380_oversampling_avail[] =;
static const int bmp380_iir_filter_coeffs_avail[] =;
static const u8 bmp380_chip_ids[] =;
static const int bmp380_temp_coeffs[] =;
static const int bmp380_press_coeffs[] =;

const struct bmp280_chip_info bmp380_chip_info =;
EXPORT_SYMBOL_NS();

static int bmp580_soft_reset(struct bmp280_data *data)
{}

/**
 * bmp580_nvm_operation() - Helper function to commit NVM memory operations
 * @data: sensor data struct
 * @is_write: flag to signal write operation
 */
static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write)
{}

/*
 * Contrary to previous sensors families, compensation algorithm is builtin.
 * We are only required to read the register raw data and adapt the ranges
 * for what is expected on IIO ABI.
 */

static int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp)
{}

static int bmp580_read_press(struct bmp280_data *data, u32 *raw_press)
{}

static const int bmp580_odr_table[][2] =;

static const int bmp580_nvmem_addrs[] =;

static int bmp580_nvmem_read_impl(void *priv, unsigned int offset, void *val,
				  size_t bytes)
{}

static int bmp580_nvmem_read(void *priv, unsigned int offset, void *val,
			     size_t bytes)
{}

static int bmp580_nvmem_write_impl(void *priv, unsigned int offset, void *val,
				   size_t bytes)
{}

static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val,
			      size_t bytes)
{}

static int bmp580_preinit(struct bmp280_data *data)
{}

static int bmp580_chip_config(struct bmp280_data *data)
{}

static irqreturn_t bmp580_trigger_handler(int irq, void *p)
{}

static const int bmp580_oversampling_avail[] =;
static const u8 bmp580_chip_ids[] =;
/* Instead of { 1000, 16 } we do this, to avoid overflow issues */
static const int bmp580_temp_coeffs[] =;
static const int bmp580_press_coeffs[] =;

const struct bmp280_chip_info bmp580_chip_info =;
EXPORT_SYMBOL_NS();

static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas)
{}

static int bmp180_read_temp_adc(struct bmp280_data *data, u32 *adc_temp)
{}

static int bmp180_read_calib(struct bmp280_data *data)
{}

/*
 * Returns temperature in DegC, resolution is 0.1 DegC.
 * t_fine carries fine temperature as global value.
 *
 * Taken from datasheet, Section 3.5, "Calculating pressure and temperature".
 */

static s32 bmp180_calc_t_fine(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp180_get_t_fine(struct bmp280_data *data, s32 *t_fine)
{}

static s32 bmp180_compensate_temp(struct bmp280_data *data, u32 adc_temp)
{}

static int bmp180_read_temp(struct bmp280_data *data, s32 *comp_temp)
{}

static int bmp180_read_press_adc(struct bmp280_data *data, u32 *adc_press)
{}

/*
 * Returns pressure in Pa, resolution is 1 Pa.
 *
 * Taken from datasheet, Section 3.5, "Calculating pressure and temperature".
 */
static u32 bmp180_compensate_press(struct bmp280_data *data, u32 adc_press,
				   s32 t_fine)
{}

static int bmp180_read_press(struct bmp280_data *data, u32 *comp_press)
{}

static int bmp180_chip_config(struct bmp280_data *data)
{}

static irqreturn_t bmp180_trigger_handler(int irq, void *p)
{}

static const int bmp180_oversampling_temp_avail[] =;
static const int bmp180_oversampling_press_avail[] =;
static const u8 bmp180_chip_ids[] =;
static const int bmp180_temp_coeffs[] =;
static const int bmp180_press_coeffs[] =;

const struct bmp280_chip_info bmp180_chip_info =;
EXPORT_SYMBOL_NS();

static irqreturn_t bmp085_eoc_irq(int irq, void *d)
{}

static int bmp085_fetch_eoc_irq(struct device *dev,
				const char *name,
				int irq,
				struct bmp280_data *data)
{}

static int bmp280_buffer_preenable(struct iio_dev *indio_dev)
{}

static int bmp280_buffer_postdisable(struct iio_dev *indio_dev)
{}

static const struct iio_buffer_setup_ops bmp280_buffer_setup_ops =;

static void bmp280_pm_disable(void *data)
{}

static void bmp280_regulators_disable(void *data)
{}

int bmp280_common_probe(struct device *dev,
			struct regmap *regmap,
			const struct bmp280_chip_info *chip_info,
			const char *name,
			int irq)
{}
EXPORT_SYMBOL_NS();

static int bmp280_runtime_suspend(struct device *dev)
{}

static int bmp280_runtime_resume(struct device *dev)
{}

EXPORT_RUNTIME_DEV_PM_OPS();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();