drivers/iio/accel/mc3230.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/mc3230.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/mc3230.c- Extension
.c- Size
- 6302 bytes
- Lines
- 262
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/module.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct mc3230_chip_infostruct mc3230_datafunction mc3230_get_mount_matrixfunction mc3230_set_opconfunction mc3230_read_rawfunction mc3230_probefunction mc3230_removefunction mc3230_suspendfunction mc3230_resume
Annotated Snippet
struct mc3230_chip_info {
const char *name;
const u8 chip_id;
const u8 product_code;
const int scale;
};
static const struct mc3230_chip_info mc3230_chip_info = {
.name = "mc3230",
.chip_id = 0x01,
.product_code = 0x19,
/* (1.5 + 1.5) * 9.81 / (2^8 - 1) = 0.115411765 */
.scale = 115411765,
};
static const struct mc3230_chip_info mc3510c_chip_info = {
.name = "mc3510c",
.chip_id = 0x23,
.product_code = 0x10,
/* Was obtained empirically */
.scale = 625000000,
};
#define MC3230_CHANNEL(reg, axis) { \
.type = IIO_ACCEL, \
.address = reg, \
.modified = 1, \
.channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.ext_info = mc3230_ext_info, \
}
struct mc3230_data {
const struct mc3230_chip_info *chip_info;
struct i2c_client *client;
struct iio_mount_matrix orientation;
};
static const struct iio_mount_matrix *
mc3230_get_mount_matrix(const struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
struct mc3230_data *data = iio_priv(indio_dev);
return &data->orientation;
}
static const struct iio_chan_spec_ext_info mc3230_ext_info[] = {
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mc3230_get_mount_matrix),
{ }
};
static const struct iio_chan_spec mc3230_channels[] = {
MC3230_CHANNEL(MC3230_REG_XOUT, X),
MC3230_CHANNEL(MC3230_REG_YOUT, Y),
MC3230_CHANNEL(MC3230_REG_ZOUT, Z),
};
static int mc3230_set_opcon(struct mc3230_data *data, int opcon)
{
int ret;
struct i2c_client *client = data->client;
ret = i2c_smbus_read_byte_data(client, MC3230_REG_MODE);
if (ret < 0) {
dev_err(&client->dev, "failed to read mode reg: %d\n", ret);
return ret;
}
ret &= ~MC3230_MODE_OPCON_MASK;
ret |= opcon;
ret = i2c_smbus_write_byte_data(client, MC3230_REG_MODE, ret);
if (ret < 0) {
dev_err(&client->dev, "failed to write mode reg: %d\n", ret);
return ret;
}
return 0;
}
static int mc3230_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct mc3230_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/module.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct mc3230_chip_info`, `struct mc3230_data`, `function mc3230_get_mount_matrix`, `function mc3230_set_opcon`, `function mc3230_read_raw`, `function mc3230_probe`, `function mc3230_remove`, `function mc3230_suspend`, `function mc3230_resume`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.