drivers/iio/accel/mma9551_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/mma9551_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/mma9551_core.c- Extension
.c- Size
- 21820 bytes
- Lines
- 804
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/i2c.hlinux/delay.hlinux/iio/iio.hlinux/pm_runtime.hmma9551_core.h
Detected Declarations
struct mma9551_mbox_requeststruct mma9551_mbox_responsestruct mma9551_version_infofunction mma9551_transferfunction mma9551_read_config_bytefunction mma9551_write_config_bytefunction mma9551_read_status_bytefunction mma9551_read_config_wordfunction mma9551_write_config_wordfunction mma9551_read_status_wordfunction mma9551_read_config_wordsfunction mma9551_read_status_wordsfunction mma9551_write_config_wordsfunction mma9551_update_config_bitsfunction mma9551_gpio_configfunction mma9551_read_versionfunction mma9551_set_device_statefunction mma9551_set_power_statefunction mma9551_sleepfunction mma9551_read_accel_chanfunction mma9551_read_accel_scalefunction mma9551_app_reset
Annotated Snippet
struct mma9551_mbox_request {
u8 start_mbox; /* Always 0. */
u8 app_id;
/*
* See Section 5.3.1 of the MMA955xL Software Reference Manual.
*
* Bit 7: reserved, always 0
* Bits 6-4: command
* Bits 3-0: upper bits of register offset
*/
u8 cmd_off;
u8 lower_off;
u8 nbytes;
u8 buf[MMA9551_MAX_MAILBOX_DATA_REGS - 1];
} __packed;
struct mma9551_mbox_response {
u8 app_id;
/*
* See Section 5.3.3 of the MMA955xL Software Reference Manual.
*
* Bit 7: COCO
* Bits 6-0: Error code.
*/
u8 coco_err;
u8 nbytes;
u8 req_bytes;
u8 buf[MMA9551_MAX_MAILBOX_DATA_REGS];
} __packed;
struct mma9551_version_info {
__be32 device_id;
u8 rom_version[2];
u8 fw_version[2];
u8 hw_version[2];
u8 fw_build[2];
};
static int mma9551_transfer(struct i2c_client *client,
u8 app_id, u8 command, u16 offset,
u8 *inbytes, int num_inbytes,
u8 *outbytes, int num_outbytes)
{
struct mma9551_mbox_request req;
struct mma9551_mbox_response rsp;
struct i2c_msg in, out;
u8 req_len, err_code;
int ret, retries;
if (offset >= 1 << 12) {
dev_err(&client->dev, "register offset too large\n");
return -EINVAL;
}
req_len = 1 + MMA9551_MAILBOX_CTRL_REGS + num_inbytes;
req.start_mbox = 0;
req.app_id = app_id;
req.cmd_off = command | (offset >> 8);
req.lower_off = offset;
if (command == MMA9551_CMD_WRITE_CONFIG)
req.nbytes = num_inbytes;
else
req.nbytes = num_outbytes;
if (num_inbytes)
memcpy(req.buf, inbytes, num_inbytes);
out.addr = client->addr;
out.flags = 0;
out.len = req_len;
out.buf = (u8 *)&req;
ret = i2c_transfer(client->adapter, &out, 1);
if (ret < 0) {
dev_err(&client->dev, "i2c write failed\n");
return ret;
}
retries = MMA9551_I2C_READ_RETRIES;
do {
udelay(MMA9551_I2C_READ_DELAY);
in.addr = client->addr;
in.flags = I2C_M_RD;
in.len = sizeof(rsp);
in.buf = (u8 *)&rsp;
ret = i2c_transfer(client->adapter, &in, 1);
if (ret < 0) {
dev_err(&client->dev, "i2c read failed\n");
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/delay.h`, `linux/iio/iio.h`, `linux/pm_runtime.h`, `mma9551_core.h`.
- Detected declarations: `struct mma9551_mbox_request`, `struct mma9551_mbox_response`, `struct mma9551_version_info`, `function mma9551_transfer`, `function mma9551_read_config_byte`, `function mma9551_write_config_byte`, `function mma9551_read_status_byte`, `function mma9551_read_config_word`, `function mma9551_write_config_word`, `function mma9551_read_status_word`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration 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.