Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/bitops.h>
0003 #include <linux/device.h>
0004 #include <linux/regmap.h>
0005 
0006 /* BMP280 specific registers */
0007 #define BMP280_REG_HUMIDITY_LSB     0xFE
0008 #define BMP280_REG_HUMIDITY_MSB     0xFD
0009 #define BMP280_REG_TEMP_XLSB        0xFC
0010 #define BMP280_REG_TEMP_LSB     0xFB
0011 #define BMP280_REG_TEMP_MSB     0xFA
0012 #define BMP280_REG_PRESS_XLSB       0xF9
0013 #define BMP280_REG_PRESS_LSB        0xF8
0014 #define BMP280_REG_PRESS_MSB        0xF7
0015 
0016 #define BMP280_REG_CONFIG       0xF5
0017 #define BMP280_REG_CTRL_MEAS        0xF4
0018 #define BMP280_REG_STATUS       0xF3
0019 #define BMP280_REG_CTRL_HUMIDITY    0xF2
0020 
0021 /* Due to non linear mapping, and data sizes we can't do a bulk read */
0022 #define BMP280_REG_COMP_H1      0xA1
0023 #define BMP280_REG_COMP_H2      0xE1
0024 #define BMP280_REG_COMP_H3      0xE3
0025 #define BMP280_REG_COMP_H4      0xE4
0026 #define BMP280_REG_COMP_H5      0xE5
0027 #define BMP280_REG_COMP_H6      0xE7
0028 
0029 #define BMP280_REG_COMP_TEMP_START  0x88
0030 #define BMP280_COMP_TEMP_REG_COUNT  6
0031 
0032 #define BMP280_REG_COMP_PRESS_START 0x8E
0033 #define BMP280_COMP_PRESS_REG_COUNT 18
0034 
0035 #define BMP280_FILTER_MASK      (BIT(4) | BIT(3) | BIT(2))
0036 #define BMP280_FILTER_OFF       0
0037 #define BMP280_FILTER_2X        BIT(2)
0038 #define BMP280_FILTER_4X        BIT(3)
0039 #define BMP280_FILTER_8X        (BIT(3) | BIT(2))
0040 #define BMP280_FILTER_16X       BIT(4)
0041 
0042 #define BMP280_OSRS_HUMIDITY_MASK   (BIT(2) | BIT(1) | BIT(0))
0043 #define BMP280_OSRS_HUMIDITIY_X(osrs_h) ((osrs_h) << 0)
0044 #define BMP280_OSRS_HUMIDITY_SKIP   0
0045 #define BMP280_OSRS_HUMIDITY_1X     BMP280_OSRS_HUMIDITIY_X(1)
0046 #define BMP280_OSRS_HUMIDITY_2X     BMP280_OSRS_HUMIDITIY_X(2)
0047 #define BMP280_OSRS_HUMIDITY_4X     BMP280_OSRS_HUMIDITIY_X(3)
0048 #define BMP280_OSRS_HUMIDITY_8X     BMP280_OSRS_HUMIDITIY_X(4)
0049 #define BMP280_OSRS_HUMIDITY_16X    BMP280_OSRS_HUMIDITIY_X(5)
0050 
0051 #define BMP280_OSRS_TEMP_MASK       (BIT(7) | BIT(6) | BIT(5))
0052 #define BMP280_OSRS_TEMP_SKIP       0
0053 #define BMP280_OSRS_TEMP_X(osrs_t)  ((osrs_t) << 5)
0054 #define BMP280_OSRS_TEMP_1X     BMP280_OSRS_TEMP_X(1)
0055 #define BMP280_OSRS_TEMP_2X     BMP280_OSRS_TEMP_X(2)
0056 #define BMP280_OSRS_TEMP_4X     BMP280_OSRS_TEMP_X(3)
0057 #define BMP280_OSRS_TEMP_8X     BMP280_OSRS_TEMP_X(4)
0058 #define BMP280_OSRS_TEMP_16X        BMP280_OSRS_TEMP_X(5)
0059 
0060 #define BMP280_OSRS_PRESS_MASK      (BIT(4) | BIT(3) | BIT(2))
0061 #define BMP280_OSRS_PRESS_SKIP      0
0062 #define BMP280_OSRS_PRESS_X(osrs_p) ((osrs_p) << 2)
0063 #define BMP280_OSRS_PRESS_1X        BMP280_OSRS_PRESS_X(1)
0064 #define BMP280_OSRS_PRESS_2X        BMP280_OSRS_PRESS_X(2)
0065 #define BMP280_OSRS_PRESS_4X        BMP280_OSRS_PRESS_X(3)
0066 #define BMP280_OSRS_PRESS_8X        BMP280_OSRS_PRESS_X(4)
0067 #define BMP280_OSRS_PRESS_16X       BMP280_OSRS_PRESS_X(5)
0068 
0069 #define BMP280_MODE_MASK        (BIT(1) | BIT(0))
0070 #define BMP280_MODE_SLEEP       0
0071 #define BMP280_MODE_FORCED      BIT(0)
0072 #define BMP280_MODE_NORMAL      (BIT(1) | BIT(0))
0073 
0074 /* BMP180 specific registers */
0075 #define BMP180_REG_OUT_XLSB     0xF8
0076 #define BMP180_REG_OUT_LSB      0xF7
0077 #define BMP180_REG_OUT_MSB      0xF6
0078 
0079 #define BMP180_REG_CALIB_START      0xAA
0080 #define BMP180_REG_CALIB_COUNT      22
0081 
0082 #define BMP180_MEAS_SCO         BIT(5)
0083 #define BMP180_MEAS_TEMP        (0x0E | BMP180_MEAS_SCO)
0084 #define BMP180_MEAS_PRESS_X(oss)    ((oss) << 6 | 0x14 | BMP180_MEAS_SCO)
0085 #define BMP180_MEAS_PRESS_1X        BMP180_MEAS_PRESS_X(0)
0086 #define BMP180_MEAS_PRESS_2X        BMP180_MEAS_PRESS_X(1)
0087 #define BMP180_MEAS_PRESS_4X        BMP180_MEAS_PRESS_X(2)
0088 #define BMP180_MEAS_PRESS_8X        BMP180_MEAS_PRESS_X(3)
0089 
0090 /* BMP180 and BMP280 common registers */
0091 #define BMP280_REG_CTRL_MEAS        0xF4
0092 #define BMP280_REG_RESET        0xE0
0093 #define BMP280_REG_ID           0xD0
0094 
0095 #define BMP180_CHIP_ID          0x55
0096 #define BMP280_CHIP_ID          0x58
0097 #define BME280_CHIP_ID          0x60
0098 #define BMP280_SOFT_RESET_VAL       0xB6
0099 
0100 /* BMP280 register skipped special values */
0101 #define BMP280_TEMP_SKIPPED     0x80000
0102 #define BMP280_PRESS_SKIPPED        0x80000
0103 #define BMP280_HUMIDITY_SKIPPED     0x8000
0104 
0105 /* Regmap configurations */
0106 extern const struct regmap_config bmp180_regmap_config;
0107 extern const struct regmap_config bmp280_regmap_config;
0108 
0109 /* Probe called from different transports */
0110 int bmp280_common_probe(struct device *dev,
0111             struct regmap *regmap,
0112             unsigned int chip,
0113             const char *name,
0114             int irq);
0115 
0116 /* PM ops */
0117 extern const struct dev_pm_ops bmp280_dev_pm_ops;