drivers/iio/magnetometer/hmc5843_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/hmc5843_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/magnetometer/hmc5843_core.c- Extension
.c- Size
- 18247 bytes
- Lines
- 689
- 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/regmap.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger_consumer.hlinux/iio/buffer.hlinux/iio/triggered_buffer.hlinux/delay.hhmc5843.h
Detected Declarations
struct hmc5843_chip_infofunction hmc5843_set_modefunction hmc5843_wait_measurementfunction hmc5843_read_measurementfunction hmc5843_set_meas_conffunction hmc5843_show_measurement_configurationfunction hmc5843_set_measurement_configurationfunction hmc5843_get_mount_matrixfunction hmc5843_show_samp_freq_availfunction hmc5843_set_samp_freqfunction hmc5843_get_samp_freq_indexfunction hmc5843_set_range_gainfunction hmc5843_show_scale_availfunction hmc5843_get_scale_indexfunction hmc5843_read_rawfunction hmc5843_write_rawfunction hmc5843_write_raw_get_fmtfunction hmc5843_trigger_handlerfunction hmc5843_initfunction hmc5843_common_suspendfunction hmc5843_common_resumefunction hmc5843_common_probefunction hmc5843_common_remove
Annotated Snippet
struct hmc5843_chip_info {
const struct iio_chan_spec *channels;
const int (*regval_to_samp_freq)[2];
const int n_regval_to_samp_freq;
const int *regval_to_nanoscale;
const int n_regval_to_nanoscale;
};
/* The lower two bits contain the current conversion mode */
static s32 hmc5843_set_mode(struct hmc5843_data *data, u8 operating_mode)
{
int ret;
mutex_lock(&data->lock);
ret = regmap_update_bits(data->regmap, HMC5843_MODE_REG,
HMC5843_MODE_MASK, operating_mode);
mutex_unlock(&data->lock);
return ret;
}
static int hmc5843_wait_measurement(struct hmc5843_data *data)
{
int tries = 150;
unsigned int val;
int ret;
while (tries-- > 0) {
ret = regmap_read(data->regmap, HMC5843_STATUS_REG, &val);
if (ret < 0)
return ret;
if (val & HMC5843_DATA_READY)
break;
msleep(20);
}
if (tries < 0) {
dev_err(data->dev, "data not ready\n");
return -EIO;
}
return 0;
}
/* Return the measurement value from the specified channel */
static int hmc5843_read_measurement(struct hmc5843_data *data,
int idx, int *val)
{
__be16 values[3];
int ret;
mutex_lock(&data->lock);
ret = hmc5843_wait_measurement(data);
if (ret < 0) {
mutex_unlock(&data->lock);
return ret;
}
ret = regmap_bulk_read(data->regmap, HMC5843_DATA_OUT_MSB_REGS,
values, sizeof(values));
mutex_unlock(&data->lock);
if (ret < 0)
return ret;
*val = sign_extend32(be16_to_cpu(values[idx]), 15);
return IIO_VAL_INT;
}
static int hmc5843_set_meas_conf(struct hmc5843_data *data, u8 meas_conf)
{
int ret;
mutex_lock(&data->lock);
ret = regmap_update_bits(data->regmap, HMC5843_CONFIG_REG_A,
HMC5843_MEAS_CONF_MASK, meas_conf);
mutex_unlock(&data->lock);
return ret;
}
static
int hmc5843_show_measurement_configuration(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
struct hmc5843_data *data = iio_priv(indio_dev);
unsigned int val;
int ret;
ret = regmap_read(data->regmap, HMC5843_CONFIG_REG_A, &val);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/module.h`, `linux/regmap.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/iio/trigger_consumer.h`, `linux/iio/buffer.h`, `linux/iio/triggered_buffer.h`, `linux/delay.h`.
- Detected declarations: `struct hmc5843_chip_info`, `function hmc5843_set_mode`, `function hmc5843_wait_measurement`, `function hmc5843_read_measurement`, `function hmc5843_set_meas_conf`, `function hmc5843_show_measurement_configuration`, `function hmc5843_set_measurement_configuration`, `function hmc5843_get_mount_matrix`, `function hmc5843_show_samp_freq_avail`, `function hmc5843_set_samp_freq`.
- 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.