drivers/iio/magnetometer/mmc5633.c
Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/mmc5633.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/magnetometer/mmc5633.c- Extension
.c- Size
- 14372 bytes
- Lines
- 587
- 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.
- 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.
- 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/array_size.hlinux/bitfield.hlinux/bits.hlinux/cleanup.hlinux/delay.hlinux/device.hlinux/dev_printk.hlinux/err.hlinux/errno.hlinux/i2c.hlinux/i3c/device.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/init.hlinux/iopoll.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/pm.hlinux/regmap.hlinux/time.hlinux/types.hlinux/unaligned.h
Detected Declarations
struct mmc5633_dataenum mmc5633_axisfunction mmc5633_get_samp_freq_indexfunction mmc5633_initfunction mmc5633_take_measurementfunction mmc5633_is_support_hdrfunction mmc5633_read_measurementfunction mmc5633_get_rawfunction mmc5633_read_rawfunction scoped_guardfunction mmc5633_write_rawfunction mmc5633_read_availfunction mmc5633_is_writeable_regfunction mmc5633_is_readable_regfunction mmc5633_is_volatile_regfunction mmc5633_common_probefunction mmc5633_suspendfunction mmc5633_resumefunction mmc5633_i2c_probefunction mmc5633_i3c_probe
Annotated Snippet
struct mmc5633_data {
struct regmap *regmap;
struct i3c_device *i3cdev;
struct mutex mutex; /* protect to finish one whole measurement */
};
static int mmc5633_samp_freq[][2] = {
{ 1, 200000 },
{ 2, 0 },
{ 3, 500000 },
{ 6, 600000 },
};
#define MMC5633_CHANNEL(_axis) { \
.type = IIO_MAGN, \
.modified = 1, \
.channel2 = IIO_MOD_ ## _axis, \
.address = MMC5633_AXIS_ ## _axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
BIT(IIO_CHAN_INFO_SCALE), \
}
static const struct iio_chan_spec mmc5633_channels[] = {
MMC5633_CHANNEL(X),
MMC5633_CHANNEL(Y),
MMC5633_CHANNEL(Z),
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_OFFSET),
.address = MMC5633_TEMPERATURE,
},
};
static int mmc5633_get_samp_freq_index(struct mmc5633_data *data,
int val, int val2)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(mmc5633_samp_freq); i++)
if (mmc5633_samp_freq[i][0] == val &&
mmc5633_samp_freq[i][1] == val2)
return i;
return -EINVAL;
}
static int mmc5633_init(struct mmc5633_data *data)
{
unsigned int reg_id;
int ret;
ret = regmap_read(data->regmap, MMC5633_REG_ID, ®_id);
if (ret)
return dev_err_probe(regmap_get_device(data->regmap), ret,
"Error reading product id\n");
/*
* Make sure we restore sensor characteristics, by doing
* a SET/RESET sequence, the axis polarity being naturally
* aligned after RESET.
*/
ret = regmap_write(data->regmap, MMC5633_REG_CTRL0, MMC5633_CTRL0_SET);
if (ret)
return ret;
/*
* Minimum time interval between SET or RESET to other operations is
* 1ms according to Operating Timing Diagram in datasheet.
*/
fsleep(MMC5633_WAIT_SET_RESET_US);
ret = regmap_write(data->regmap, MMC5633_REG_CTRL0, MMC5633_CTRL0_RESET);
if (ret)
return ret;
/* set default sampling frequency */
return regmap_update_bits(data->regmap, MMC5633_REG_CTRL1,
MMC5633_CTRL1_BW_MASK,
FIELD_PREP(MMC5633_CTRL1_BW_MASK, 0));
}
static int mmc5633_take_measurement(struct mmc5633_data *data, int address)
{
unsigned int reg_status, val;
int ret;
val = (address == MMC5633_TEMPERATURE) ? MMC5633_CTRL0_MEAS_T : MMC5633_CTRL0_MEAS_M;
ret = regmap_write(data->regmap, MMC5633_REG_CTRL0, val);
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/device.h`, `linux/dev_printk.h`, `linux/err.h`.
- Detected declarations: `struct mmc5633_data`, `enum mmc5633_axis`, `function mmc5633_get_samp_freq_index`, `function mmc5633_init`, `function mmc5633_take_measurement`, `function mmc5633_is_support_hdr`, `function mmc5633_read_measurement`, `function mmc5633_get_raw`, `function mmc5633_read_raw`, `function scoped_guard`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.