drivers/iio/magnetometer/bmc150_magn.c

Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/bmc150_magn.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/magnetometer/bmc150_magn.c
Extension
.c
Size
26370 bytes
Lines
1038
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 bmc150_magn_trim_regs {
	s8 x1;
	s8 y1;
	__le16 reserved1;
	u8 reserved2;
	__le16 z4;
	s8 x2;
	s8 y2;
	__le16 reserved3;
	__le16 z2;
	__le16 z1;
	__le16 xyz1;
	__le16 z3;
	s8 xy2;
	u8 xy1;
} __packed;

struct bmc150_magn_data {
	struct device *dev;
	/*
	 * 1. Protect this structure.
	 * 2. Serialize sequences that power on/off the device and access HW.
	 */
	struct mutex mutex;
	struct regmap *regmap;
	struct regulator_bulk_data regulators[2];
	struct iio_mount_matrix orientation;
	/* Ensure timestamp is naturally aligned */
	struct {
		s32 chans[3];
		aligned_s64 timestamp;
	} scan;
	struct iio_trigger *dready_trig;
	bool dready_trigger_on;
	int max_odr;
	int irq;
};

static const struct {
	int freq;
	u8 reg_val;
} bmc150_magn_samp_freq_table[] = {
	{ 2, 0x01 },
	{ 6, 0x02 },
	{ 8, 0x03 },
	{ 10, 0x00 },
	{ 15, 0x04 },
	{ 20, 0x05 },
	{ 25, 0x06 },
	{ 30, 0x07 },
};

enum bmc150_magn_presets {
	LOW_POWER_PRESET,
	REGULAR_PRESET,
	ENHANCED_REGULAR_PRESET,
	HIGH_ACCURACY_PRESET
};

static const struct bmc150_magn_preset {
	u8 rep_xy;
	u8 rep_z;
	u8 odr;
} bmc150_magn_presets_table[] = {
	[LOW_POWER_PRESET] = { 3, 3, 10 },
	[REGULAR_PRESET] = { 9, 15, 10 },
	[ENHANCED_REGULAR_PRESET] = { 15, 27, 10 },
	[HIGH_ACCURACY_PRESET] = { 47, 83, 20 },
};

#define BMC150_MAGN_DEFAULT_PRESET REGULAR_PRESET

static bool bmc150_magn_is_writeable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMC150_MAGN_REG_POWER:
	case BMC150_MAGN_REG_OPMODE_ODR:
	case BMC150_MAGN_REG_INT:
	case BMC150_MAGN_REG_INT_DRDY:
	case BMC150_MAGN_REG_LOW_THRESH:
	case BMC150_MAGN_REG_HIGH_THRESH:
	case BMC150_MAGN_REG_REP_XY:
	case BMC150_MAGN_REG_REP_Z:
		return true;
	default:
		return false;
	}
}

static bool bmc150_magn_is_volatile_reg(struct device *dev, unsigned int reg)

Annotation

Implementation Notes