drivers/iio/magnetometer/af8133j.c
Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/af8133j.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/magnetometer/af8133j.c- Extension
.c- Size
- 12587 bytes
- Lines
- 528
- 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/delay.hlinux/gpio/consumer.hlinux/i2c.hlinux/module.hlinux/pm_runtime.hlinux/regmap.hlinux/regulator/consumer.hlinux/iio/iio.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct af8133j_dataenum af8133j_axisfunction af8133j_get_mount_matrixfunction af8133j_product_checkfunction af8133j_resetfunction af8133j_power_downfunction af8133j_power_upfunction af8133j_take_measurementfunction af8133j_read_measurementfunction scoped_guardfunction af8133j_read_rawfunction af8133j_read_availfunction af8133j_set_scalefunction af8133j_write_rawfunction af8133j_write_raw_get_fmtfunction af8133j_trigger_handlerfunction af8133j_power_down_actionfunction af8133j_probefunction af8133j_runtime_suspendfunction af8133j_runtime_resume
Annotated Snippet
struct af8133j_data {
struct i2c_client *client;
struct regmap *regmap;
/*
* Protect device internal state between starting a measurement
* and reading the result.
*/
struct mutex mutex;
struct iio_mount_matrix orientation;
struct gpio_desc *reset_gpiod;
struct regulator_bulk_data supplies[ARRAY_SIZE(af8133j_supply_names)];
u8 range;
};
enum af8133j_axis {
AXIS_X = 0,
AXIS_Y,
AXIS_Z,
};
static struct iio_mount_matrix *
af8133j_get_mount_matrix(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
struct af8133j_data *data = iio_priv(indio_dev);
return &data->orientation;
}
static const struct iio_chan_spec_ext_info af8133j_ext_info[] = {
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, af8133j_get_mount_matrix),
{ }
};
#define AF8133J_CHANNEL(_si, _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_SCALE), \
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \
.ext_info = af8133j_ext_info, \
.scan_index = _si, \
.scan_type = { \
.sign = 's', \
.realbits = 16, \
.storagebits = 16, \
.endianness = IIO_LE, \
}, \
}
static const struct iio_chan_spec af8133j_channels[] = {
AF8133J_CHANNEL(0, X),
AF8133J_CHANNEL(1, Y),
AF8133J_CHANNEL(2, Z),
IIO_CHAN_SOFT_TIMESTAMP(3),
};
static int af8133j_product_check(struct af8133j_data *data)
{
struct device *dev = &data->client->dev;
unsigned int val;
int ret;
ret = regmap_read(data->regmap, AF8133J_REG_PCODE, &val);
if (ret) {
dev_err(dev, "Error reading product code (%d)\n", ret);
return ret;
}
if (val != AF8133J_REG_PCODE_VAL) {
dev_warn(dev, "Invalid product code (0x%02x)\n", val);
return 0; /* Allow unknown ID so fallback compatibles work */
}
return 0;
}
static int af8133j_reset(struct af8133j_data *data)
{
struct device *dev = &data->client->dev;
int ret;
if (data->reset_gpiod) {
/* If we have GPIO reset line, use it */
gpiod_set_value_cansleep(data->reset_gpiod, 1);
udelay(10);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/module.h`, `linux/pm_runtime.h`, `linux/regmap.h`, `linux/regulator/consumer.h`, `linux/iio/iio.h`.
- Detected declarations: `struct af8133j_data`, `enum af8133j_axis`, `function af8133j_get_mount_matrix`, `function af8133j_product_check`, `function af8133j_reset`, `function af8133j_power_down`, `function af8133j_power_up`, `function af8133j_take_measurement`, `function af8133j_read_measurement`, `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.