drivers/iio/pressure/rohm-bm1390.c

Source file repositories/reference/linux-study-clean/drivers/iio/pressure/rohm-bm1390.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/pressure/rohm-bm1390.c
Extension
.c
Size
22768 bytes
Lines
914
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct bm1390_data_buf {
	u32 pressure;
	__be16 temp;
	aligned_s64 ts;
};

/* BM1390 has FIFO for 4 pressure samples */
#define BM1390_FIFO_LENGTH	4

struct bm1390_data {
	s64 timestamp, old_timestamp;
	struct iio_trigger *trig;
	struct regmap *regmap;
	struct device *dev;
	struct bm1390_data_buf buf;
	int irq;
	unsigned int state;
	bool trigger_enabled;
	u8 watermark;

	/* Prevent accessing sensor during FIFO read sequence */
	struct mutex mutex;
};

enum {
	BM1390_CHAN_PRESSURE,
	BM1390_CHAN_TEMP,
};

static const struct iio_chan_spec bm1390_channels[] = {
	{
		.type = IIO_PRESSURE,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		/*
		 * When IIR is used, we must fix amount of averaged samples.
		 * Thus we don't allow setting oversampling ratio.
		 */
		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
		.scan_index = BM1390_CHAN_PRESSURE,
		.scan_type = {
			.sign = 'u',
			.realbits = 22,
			.storagebits = 32,
			.endianness = IIO_LE,
		},
	},
	{
		.type = IIO_TEMP,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
		.scan_index = BM1390_CHAN_TEMP,
		.scan_type = {
			.sign = 's',
			.realbits = 16,
			.storagebits = 16,
			.endianness = IIO_BE,
		},
	},
	IIO_CHAN_SOFT_TIMESTAMP(2),
};

/*
 * We can't skip reading the pressure because the watermark IRQ is acked
 * only when the pressure data is read from the FIFO.
 */
static const unsigned long bm1390_scan_masks[] = {
	BIT(BM1390_CHAN_PRESSURE),
	BIT(BM1390_CHAN_PRESSURE) | BIT(BM1390_CHAN_TEMP),
	0
};

static int bm1390_read_temp(struct bm1390_data *data, int *temp)
{
	__be16 temp_raw;
	int ret;

	ret = regmap_bulk_read(data->regmap, BM1390_REG_TEMP_HI, &temp_raw,
			       sizeof(temp_raw));
	if (ret)
		return ret;

	*temp = be16_to_cpu(temp_raw);

	return 0;
}

static int bm1390_pressure_read(struct bm1390_data *data, u32 *pressure)
{
	/* Pressure data is in 3 8-bit registers */
	u8 raw[3];

Annotation

Implementation Notes