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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/i2c.hlinux/interrupt.hlinux/cleanup.hlinux/delay.hlinux/slab.hlinux/pm.hlinux/pm_runtime.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/events.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/regmap.hlinux/regulator/consumer.hbmc150_magn.h
Detected Declarations
struct bmc150_magn_trim_regsstruct bmc150_magn_dataenum bmc150_magn_axisenum bmc150_magn_power_modesenum bmc150_magn_presetsfunction bmc150_magn_is_writeable_regfunction bmc150_magn_is_volatile_regfunction bmc150_magn_set_power_modefunction bmc150_magn_set_power_mode_lockedfunction bmc150_magn_set_power_statefunction bmc150_magn_get_odrfunction bmc150_magn_set_odrfunction bmc150_magn_set_max_odrfunction bmc150_magn_compensate_xfunction bmc150_magn_compensate_yfunction bmc150_magn_compensate_zfunction bmc150_magn_read_xyzfunction bmc150_magn_read_rawfunction bmc150_magn_write_rawfunction bmc150_magn_show_samp_freq_availfunction bmc150_magn_get_mount_matrixfunction bmc150_magn_trigger_handlerfunction bmc150_magn_initfunction bmc150_magn_reset_intrfunction bmc150_magn_trig_reenfunction bmc150_magn_data_rdy_trigger_set_statefunction bmc150_magn_buffer_preenablefunction bmc150_magn_buffer_postdisablefunction bmc150_magn_probefunction bmc150_magn_removefunction bmc150_magn_runtime_suspendfunction bmc150_magn_runtime_resumefunction bmc150_magn_suspendfunction bmc150_magn_resume
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
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/slab.h`, `linux/pm.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct bmc150_magn_trim_regs`, `struct bmc150_magn_data`, `enum bmc150_magn_axis`, `enum bmc150_magn_power_modes`, `enum bmc150_magn_presets`, `function bmc150_magn_is_writeable_reg`, `function bmc150_magn_is_volatile_reg`, `function bmc150_magn_set_power_mode`, `function bmc150_magn_set_power_mode_locked`, `function bmc150_magn_set_power_state`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.