drivers/iio/magnetometer/mmc35240.c
Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/mmc35240.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/magnetometer/mmc35240.c- Extension
.c- Size
- 14232 bytes
- Lines
- 584
- 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.
- 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/mod_devicetable.hlinux/init.hlinux/i2c.hlinux/delay.hlinux/regmap.hlinux/pm.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct mmc35240_dataenum mmc35240_resolutionenum mmc35240_axisfunction mmc35240_get_samp_freq_indexfunction mmc35240_hw_setfunction mmc35240_initfunction mmc35240_take_measurementfunction mmc35240_read_measurementfunction mmc35240_raw_to_mgaussfunction mmc35240_read_rawfunction mmc35240_write_rawfunction mmc35240_is_writeable_regfunction mmc35240_is_readable_regfunction mmc35240_is_volatile_regfunction mmc35240_probefunction mmc35240_suspendfunction mmc35240_resume
Annotated Snippet
struct mmc35240_data {
struct i2c_client *client;
struct mutex mutex;
struct regmap *regmap;
enum mmc35240_resolution res;
/* OTP compensation */
int axis_coef[3];
int axis_scale[3];
};
static const struct {
int val;
int val2;
} mmc35240_samp_freq[] = { {1, 500000},
{13, 0},
{25, 0},
{50, 0} };
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("1.5 13 25 50");
#define MMC35240_CHANNEL(_axis) { \
.type = IIO_MAGN, \
.modified = 1, \
.channel2 = IIO_MOD_ ## _axis, \
.address = 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 mmc35240_channels[] = {
MMC35240_CHANNEL(X),
MMC35240_CHANNEL(Y),
MMC35240_CHANNEL(Z),
};
static struct attribute *mmc35240_attributes[] = {
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
NULL
};
static const struct attribute_group mmc35240_attribute_group = {
.attrs = mmc35240_attributes,
};
static int mmc35240_get_samp_freq_index(struct mmc35240_data *data,
int val, int val2)
{
int i;
for (i = 0; i < ARRAY_SIZE(mmc35240_samp_freq); i++)
if (mmc35240_samp_freq[i].val == val &&
mmc35240_samp_freq[i].val2 == val2)
return i;
return -EINVAL;
}
static int mmc35240_hw_set(struct mmc35240_data *data, bool set)
{
int ret;
u8 coil_bit;
/*
* Recharge the capacitor at VCAP pin, requested to be issued
* before a SET/RESET command.
*/
ret = regmap_set_bits(data->regmap, MMC35240_REG_CTRL0,
MMC35240_CTRL0_REFILL_BIT);
if (ret < 0)
return ret;
usleep_range(MMC35240_WAIT_CHARGE_PUMP, MMC35240_WAIT_CHARGE_PUMP + 1);
if (set)
coil_bit = MMC35240_CTRL0_SET_BIT;
else
coil_bit = MMC35240_CTRL0_RESET_BIT;
return regmap_set_bits(data->regmap, MMC35240_REG_CTRL0, coil_bit);
}
static int mmc35240_init(struct mmc35240_data *data)
{
int ret, y_convert, z_convert;
unsigned int reg_id;
u8 otp_data[6];
ret = regmap_read(data->regmap, MMC35240_REG_ID, ®_id);
if (ret < 0) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/init.h`, `linux/i2c.h`, `linux/delay.h`, `linux/regmap.h`, `linux/pm.h`, `linux/iio/iio.h`.
- Detected declarations: `struct mmc35240_data`, `enum mmc35240_resolution`, `enum mmc35240_axis`, `function mmc35240_get_samp_freq_index`, `function mmc35240_hw_set`, `function mmc35240_init`, `function mmc35240_take_measurement`, `function mmc35240_read_measurement`, `function mmc35240_raw_to_mgauss`, `function mmc35240_read_raw`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source 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.