drivers/iio/gyro/bmg160_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/gyro/bmg160_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/gyro/bmg160_core.c- Extension
.c- Size
- 30611 bytes
- Lines
- 1268
- 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/interrupt.hlinux/delay.hlinux/slab.hlinux/pm.hlinux/pm_runtime.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/trigger.hlinux/iio/events.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/regmap.hlinux/regulator/consumer.hbmg160.h
Detected Declarations
struct bmg160_dataenum bmg160_axisfunction bmg160_set_modefunction bmg160_convert_freq_to_bitfunction bmg160_set_bwfunction bmg160_get_filterfunction bmg160_set_filterfunction bmg160_chip_initfunction bmg160_set_power_statefunction bmg160_setup_any_motion_interruptfunction bmg160_setup_new_data_interruptfunction bmg160_get_bwfunction bmg160_set_scalefunction bmg160_get_tempfunction bmg160_get_axisfunction bmg160_read_rawfunction bmg160_write_rawfunction bmg160_read_eventfunction bmg160_write_eventfunction bmg160_read_event_configfunction bmg160_write_event_configfunction bmg160_get_mount_matrixfunction bmg160_trigger_handlerfunction bmg160_trig_reenfunction bmg160_data_rdy_trigger_set_statefunction bmg160_event_handlerfunction bmg160_data_rdy_trig_pollfunction bmg160_buffer_preenablefunction bmg160_buffer_postdisablefunction bmg160_core_probefunction bmg160_core_removefunction bmg160_suspendfunction bmg160_resumefunction bmg160_runtime_suspendfunction bmg160_runtime_resumeexport bmg160_core_probeexport bmg160_core_removeexport bmg160_pm_ops
Annotated Snippet
struct bmg160_data {
struct regmap *regmap;
struct iio_trigger *dready_trig;
struct iio_trigger *motion_trig;
struct iio_mount_matrix orientation;
struct mutex mutex;
/* Ensure naturally aligned timestamp */
struct {
s16 chans[3];
aligned_s64 timestamp;
} scan;
u32 dps_range;
int ev_enable_state;
int slope_thres;
bool dready_trigger_on;
bool motion_trigger_on;
int irq;
};
enum bmg160_axis {
AXIS_X,
AXIS_Y,
AXIS_Z,
AXIS_MAX,
};
static const struct {
int odr;
int filter;
int bw_bits;
} bmg160_samp_freq_table[] = { {100, 32, 0x07},
{200, 64, 0x06},
{100, 12, 0x05},
{200, 23, 0x04},
{400, 47, 0x03},
{1000, 116, 0x02},
{2000, 230, 0x01} };
static const struct {
int scale;
int dps_range;
} bmg160_scale_table[] = { { 1065, BMG160_RANGE_2000DPS},
{ 532, BMG160_RANGE_1000DPS},
{ 266, BMG160_RANGE_500DPS},
{ 133, BMG160_RANGE_250DPS},
{ 66, BMG160_RANGE_125DPS} };
static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
{
struct device *dev = regmap_get_device(data->regmap);
int ret;
ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
if (ret < 0) {
dev_err(dev, "Error writing reg_pmu_lpw\n");
return ret;
}
return 0;
}
static int bmg160_convert_freq_to_bit(int val)
{
int i;
for (i = 0; i < ARRAY_SIZE(bmg160_samp_freq_table); ++i) {
if (bmg160_samp_freq_table[i].odr == val)
return bmg160_samp_freq_table[i].bw_bits;
}
return -EINVAL;
}
static int bmg160_set_bw(struct bmg160_data *data, int val)
{
struct device *dev = regmap_get_device(data->regmap);
int ret;
int bw_bits;
bw_bits = bmg160_convert_freq_to_bit(val);
if (bw_bits < 0)
return bw_bits;
ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
if (ret < 0) {
dev_err(dev, "Error writing reg_pmu_bw\n");
return ret;
}
return 0;
Annotation
- Immediate include surface: `linux/module.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/slab.h`, `linux/pm.h`, `linux/pm_runtime.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct bmg160_data`, `enum bmg160_axis`, `function bmg160_set_mode`, `function bmg160_convert_freq_to_bit`, `function bmg160_set_bw`, `function bmg160_get_filter`, `function bmg160_set_filter`, `function bmg160_chip_init`, `function bmg160_set_power_state`, `function bmg160_setup_any_motion_interrupt`.
- 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.