drivers/i2c/busses/i2c-mlxcpld.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-mlxcpld.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-mlxcpld.c- Extension
.c- Size
- 15485 bytes
- Lines
- 606
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/i2c.hlinux/init.hlinux/io.hlinux/kernel.hlinux/module.hlinux/platform_data/mlxreg.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct mlxcpld_i2c_curr_xferstruct mlxcpld_i2c_privenum mlxcpld_i2c_frequencyfunction mlxcpld_i2c_lpc_write_buffunction mlxcpld_i2c_lpc_read_buffunction mlxcpld_i2c_read_commfunction mlxcpld_i2c_write_commfunction mlxcpld_i2c_check_msg_paramsfunction mlxcpld_i2c_check_statusfunction mlxcpld_i2c_set_transf_datafunction mlxcpld_i2c_resetfunction mlxcpld_i2c_check_busyfunction mlxcpld_i2c_wait_for_freefunction errorfunction mlxcpld_i2c_xfer_msgfunction errorfunction mlxcpld_i2c_funcfunction mlxcpld_i2c_set_frequencyfunction mlxcpld_i2c_probefunction mlxcpld_i2c_remove
Annotated Snippet
struct mlxcpld_i2c_curr_xfer {
u8 cmd;
u8 addr_width;
u8 data_len;
u8 msg_num;
struct i2c_msg *msg;
};
struct mlxcpld_i2c_priv {
struct i2c_adapter adap;
u32 base_addr;
struct mutex lock;
struct mlxcpld_i2c_curr_xfer xfer;
struct device *dev;
bool smbus_block;
int polling_time;
};
static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr)
{
int i;
for (i = 0; i < len - len % 4; i += 4)
outl(*(u32 *)(data + i), addr + i);
for (; i < len; ++i)
outb(*(data + i), addr + i);
}
static void mlxcpld_i2c_lpc_read_buf(u8 *data, u8 len, u32 addr)
{
int i;
for (i = 0; i < len - len % 4; i += 4)
*(u32 *)(data + i) = inl(addr + i);
for (; i < len; ++i)
*(data + i) = inb(addr + i);
}
static void mlxcpld_i2c_read_comm(struct mlxcpld_i2c_priv *priv, u8 offs,
u8 *data, u8 datalen)
{
u32 addr = priv->base_addr + offs;
switch (datalen) {
case 1:
*(data) = inb(addr);
break;
case 2:
*((u16 *)data) = inw(addr);
break;
case 3:
*((u16 *)data) = inw(addr);
*(data + 2) = inb(addr + 2);
break;
case 4:
*((u32 *)data) = inl(addr);
break;
default:
mlxcpld_i2c_lpc_read_buf(data, datalen, addr);
break;
}
}
static void mlxcpld_i2c_write_comm(struct mlxcpld_i2c_priv *priv, u8 offs,
u8 *data, u8 datalen)
{
u32 addr = priv->base_addr + offs;
switch (datalen) {
case 1:
outb(*(data), addr);
break;
case 2:
outw(*((u16 *)data), addr);
break;
case 3:
outw(*((u16 *)data), addr);
outb(*(data + 2), addr + 2);
break;
case 4:
outl(*((u32 *)data), addr);
break;
default:
mlxcpld_i2c_lpc_write_buf(data, datalen, addr);
break;
}
}
/*
* Check validity of received i2c messages parameters.
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/init.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/platform_data/mlxreg.h`, `linux/platform_device.h`.
- Detected declarations: `struct mlxcpld_i2c_curr_xfer`, `struct mlxcpld_i2c_priv`, `enum mlxcpld_i2c_frequency`, `function mlxcpld_i2c_lpc_write_buf`, `function mlxcpld_i2c_lpc_read_buf`, `function mlxcpld_i2c_read_comm`, `function mlxcpld_i2c_write_comm`, `function mlxcpld_i2c_check_msg_params`, `function mlxcpld_i2c_check_status`, `function mlxcpld_i2c_set_transf_data`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.