18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#include <linux/bitops.h>
38c2ecf20Sopenharmony_ci#include <linux/device.h>
48c2ecf20Sopenharmony_ci#include <linux/regmap.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* BMP280 specific registers */
78c2ecf20Sopenharmony_ci#define BMP280_REG_HUMIDITY_LSB		0xFE
88c2ecf20Sopenharmony_ci#define BMP280_REG_HUMIDITY_MSB		0xFD
98c2ecf20Sopenharmony_ci#define BMP280_REG_TEMP_XLSB		0xFC
108c2ecf20Sopenharmony_ci#define BMP280_REG_TEMP_LSB		0xFB
118c2ecf20Sopenharmony_ci#define BMP280_REG_TEMP_MSB		0xFA
128c2ecf20Sopenharmony_ci#define BMP280_REG_PRESS_XLSB		0xF9
138c2ecf20Sopenharmony_ci#define BMP280_REG_PRESS_LSB		0xF8
148c2ecf20Sopenharmony_ci#define BMP280_REG_PRESS_MSB		0xF7
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define BMP280_REG_CONFIG		0xF5
178c2ecf20Sopenharmony_ci#define BMP280_REG_CTRL_MEAS		0xF4
188c2ecf20Sopenharmony_ci#define BMP280_REG_STATUS		0xF3
198c2ecf20Sopenharmony_ci#define BMP280_REG_CTRL_HUMIDITY	0xF2
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Due to non linear mapping, and data sizes we can't do a bulk read */
228c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H1		0xA1
238c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H2		0xE1
248c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H3		0xE3
258c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H4		0xE4
268c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H5		0xE5
278c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_H6		0xE7
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_TEMP_START	0x88
308c2ecf20Sopenharmony_ci#define BMP280_COMP_TEMP_REG_COUNT	6
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define BMP280_REG_COMP_PRESS_START	0x8E
338c2ecf20Sopenharmony_ci#define BMP280_COMP_PRESS_REG_COUNT	18
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define BMP280_FILTER_MASK		(BIT(4) | BIT(3) | BIT(2))
368c2ecf20Sopenharmony_ci#define BMP280_FILTER_OFF		0
378c2ecf20Sopenharmony_ci#define BMP280_FILTER_2X		BIT(2)
388c2ecf20Sopenharmony_ci#define BMP280_FILTER_4X		BIT(3)
398c2ecf20Sopenharmony_ci#define BMP280_FILTER_8X		(BIT(3) | BIT(2))
408c2ecf20Sopenharmony_ci#define BMP280_FILTER_16X		BIT(4)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_MASK	(BIT(2) | BIT(1) | BIT(0))
438c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITIY_X(osrs_h)	((osrs_h) << 0)
448c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_SKIP	0
458c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_1X		BMP280_OSRS_HUMIDITIY_X(1)
468c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_2X		BMP280_OSRS_HUMIDITIY_X(2)
478c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_4X		BMP280_OSRS_HUMIDITIY_X(3)
488c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_8X		BMP280_OSRS_HUMIDITIY_X(4)
498c2ecf20Sopenharmony_ci#define BMP280_OSRS_HUMIDITY_16X	BMP280_OSRS_HUMIDITIY_X(5)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_MASK		(BIT(7) | BIT(6) | BIT(5))
528c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_SKIP		0
538c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_X(osrs_t)	((osrs_t) << 5)
548c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_1X		BMP280_OSRS_TEMP_X(1)
558c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_2X		BMP280_OSRS_TEMP_X(2)
568c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_4X		BMP280_OSRS_TEMP_X(3)
578c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_8X		BMP280_OSRS_TEMP_X(4)
588c2ecf20Sopenharmony_ci#define BMP280_OSRS_TEMP_16X		BMP280_OSRS_TEMP_X(5)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_MASK		(BIT(4) | BIT(3) | BIT(2))
618c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_SKIP		0
628c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_X(osrs_p)	((osrs_p) << 2)
638c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_1X		BMP280_OSRS_PRESS_X(1)
648c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_2X		BMP280_OSRS_PRESS_X(2)
658c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_4X		BMP280_OSRS_PRESS_X(3)
668c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_8X		BMP280_OSRS_PRESS_X(4)
678c2ecf20Sopenharmony_ci#define BMP280_OSRS_PRESS_16X		BMP280_OSRS_PRESS_X(5)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define BMP280_MODE_MASK		(BIT(1) | BIT(0))
708c2ecf20Sopenharmony_ci#define BMP280_MODE_SLEEP		0
718c2ecf20Sopenharmony_ci#define BMP280_MODE_FORCED		BIT(0)
728c2ecf20Sopenharmony_ci#define BMP280_MODE_NORMAL		(BIT(1) | BIT(0))
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* BMP180 specific registers */
758c2ecf20Sopenharmony_ci#define BMP180_REG_OUT_XLSB		0xF8
768c2ecf20Sopenharmony_ci#define BMP180_REG_OUT_LSB		0xF7
778c2ecf20Sopenharmony_ci#define BMP180_REG_OUT_MSB		0xF6
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define BMP180_REG_CALIB_START		0xAA
808c2ecf20Sopenharmony_ci#define BMP180_REG_CALIB_COUNT		22
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define BMP180_MEAS_SCO			BIT(5)
838c2ecf20Sopenharmony_ci#define BMP180_MEAS_TEMP		(0x0E | BMP180_MEAS_SCO)
848c2ecf20Sopenharmony_ci#define BMP180_MEAS_PRESS_X(oss)	((oss) << 6 | 0x14 | BMP180_MEAS_SCO)
858c2ecf20Sopenharmony_ci#define BMP180_MEAS_PRESS_1X		BMP180_MEAS_PRESS_X(0)
868c2ecf20Sopenharmony_ci#define BMP180_MEAS_PRESS_2X		BMP180_MEAS_PRESS_X(1)
878c2ecf20Sopenharmony_ci#define BMP180_MEAS_PRESS_4X		BMP180_MEAS_PRESS_X(2)
888c2ecf20Sopenharmony_ci#define BMP180_MEAS_PRESS_8X		BMP180_MEAS_PRESS_X(3)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* BMP180 and BMP280 common registers */
918c2ecf20Sopenharmony_ci#define BMP280_REG_CTRL_MEAS		0xF4
928c2ecf20Sopenharmony_ci#define BMP280_REG_RESET		0xE0
938c2ecf20Sopenharmony_ci#define BMP280_REG_ID			0xD0
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define BMP180_CHIP_ID			0x55
968c2ecf20Sopenharmony_ci#define BMP280_CHIP_ID			0x58
978c2ecf20Sopenharmony_ci#define BME280_CHIP_ID			0x60
988c2ecf20Sopenharmony_ci#define BMP280_SOFT_RESET_VAL		0xB6
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* BMP280 register skipped special values */
1018c2ecf20Sopenharmony_ci#define BMP280_TEMP_SKIPPED		0x80000
1028c2ecf20Sopenharmony_ci#define BMP280_PRESS_SKIPPED		0x80000
1038c2ecf20Sopenharmony_ci#define BMP280_HUMIDITY_SKIPPED		0x8000
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* Regmap configurations */
1068c2ecf20Sopenharmony_ciextern const struct regmap_config bmp180_regmap_config;
1078c2ecf20Sopenharmony_ciextern const struct regmap_config bmp280_regmap_config;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* Probe called from different transports */
1108c2ecf20Sopenharmony_ciint bmp280_common_probe(struct device *dev,
1118c2ecf20Sopenharmony_ci			struct regmap *regmap,
1128c2ecf20Sopenharmony_ci			unsigned int chip,
1138c2ecf20Sopenharmony_ci			const char *name,
1148c2ecf20Sopenharmony_ci			int irq);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* PM ops */
1178c2ecf20Sopenharmony_ciextern const struct dev_pm_ops bmp280_dev_pm_ops;
118