summaryrefslogtreecommitdiff
path: root/drivers/iio/pressure/bmp280-regmap.c
blob: c98c67970265480aabea6c93e0d3e770cd2c008a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// SPDX-License-Identifier: GPL-2.0
#include <linux/device.h>
#include <linux/module.h>
#include <linux/regmap.h>

#include "bmp280.h"

static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP280_REG_CTRL_MEAS:
	case BMP280_REG_RESET:
		return true;
	default:
		return false;
	}
}

static bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP180_REG_OUT_XLSB:
	case BMP180_REG_OUT_LSB:
	case BMP180_REG_OUT_MSB:
	case BMP280_REG_CTRL_MEAS:
		return true;
	default:
		return false;
	}
}

const struct regmap_config bmp180_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = BMP180_REG_OUT_XLSB,
	.cache_type = REGCACHE_RBTREE,

	.writeable_reg = bmp180_is_writeable_reg,
	.volatile_reg = bmp180_is_volatile_reg,
};
EXPORT_SYMBOL_NS(bmp180_regmap_config, IIO_BMP280);

static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP280_REG_CONFIG:
	case BMP280_REG_CTRL_HUMIDITY:
	case BMP280_REG_CTRL_MEAS:
	case BMP280_REG_RESET:
		return true;
	default:
		return false;
	}
}

static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP280_REG_HUMIDITY_LSB:
	case BMP280_REG_HUMIDITY_MSB:
	case BMP280_REG_TEMP_XLSB:
	case BMP280_REG_TEMP_LSB:
	case BMP280_REG_TEMP_MSB:
	case BMP280_REG_PRESS_XLSB:
	case BMP280_REG_PRESS_LSB:
	case BMP280_REG_PRESS_MSB:
	case BMP280_REG_STATUS:
		return true;
	default:
		return false;
	}
}

static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP380_REG_CMD:
	case BMP380_REG_CONFIG:
	case BMP380_REG_FIFO_CONFIG_1:
	case BMP380_REG_FIFO_CONFIG_2:
	case BMP380_REG_FIFO_WATERMARK_LSB:
	case BMP380_REG_FIFO_WATERMARK_MSB:
	case BMP380_REG_POWER_CONTROL:
	case BMP380_REG_INT_CONTROL:
	case BMP380_REG_IF_CONFIG:
	case BMP380_REG_ODR:
	case BMP380_REG_OSR:
		return true;
	default:
		return false;
	}
}

static bool bmp380_is_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMP380_REG_TEMP_XLSB:
	case BMP380_REG_TEMP_LSB:
	case BMP380_REG_TEMP_MSB:
	case BMP380_REG_PRESS_XLSB:
	case BMP380_REG_PRESS_LSB:
	case BMP380_REG_PRESS_MSB:
	case BMP380_REG_SENSOR_TIME_XLSB:
	case BMP380_REG_SENSOR_TIME_LSB:
	case BMP380_REG_SENSOR_TIME_MSB:
	case BMP380_REG_INT_STATUS:
	case BMP380_REG_FIFO_DATA:
	case BMP380_REG_STATUS:
	case BMP380_REG_ERROR:
	case BMP380_REG_EVENT:
		return true;
	default:
		return false;
	}
}

const struct regmap_config bmp280_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = BMP280_REG_HUMIDITY_LSB,
	.cache_type = REGCACHE_RBTREE,

	.writeable_reg = bmp280_is_writeable_reg,
	.volatile_reg = bmp280_is_volatile_reg,
};
EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280);

const struct regmap_config bmp380_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = BMP380_REG_CMD,
	.cache_type = REGCACHE_RBTREE,

	.writeable_reg = bmp380_is_writeable_reg,
	.volatile_reg = bmp380_is_volatile_reg,
};
EXPORT_SYMBOL_NS(bmp380_regmap_config, IIO_BMP280);