drivers/i2c/muxes/i2c-mux-mlxcpld.c
Source file repositories/reference/linux-study-clean/drivers/i2c/muxes/i2c-mux-mlxcpld.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/muxes/i2c-mux-mlxcpld.c- Extension
.c- Size
- 5250 bytes
- Lines
- 194
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/i2c.hlinux/i2c-mux.hlinux/io.hlinux/init.hlinux/module.hlinux/platform_data/mlxcpld.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct mlxcpld_muxfunction spacefunction mlxcpld_mux_select_chanfunction mlxcpld_mux_deselectfunction mlxcpld_mux_probefunction mlxcpld_mux_remove
Annotated Snippet
struct mlxcpld_mux {
int last_val;
struct i2c_client *client;
struct mlxcpld_mux_plat_data pdata;
};
/* MUX logic description.
* Driver can support different mux control logic, according to CPLD
* implementation.
*
* Connectivity schema.
*
* i2c-mlxcpld Digital Analog
* driver
* *--------* * -> mux1 (virt bus2) -> mux -> |
* | I2CLPC | i2c physical * -> mux2 (virt bus3) -> mux -> |
* | bridge | bus 1 *---------* |
* | logic |---------------------> * mux reg * |
* | in CPLD| *---------* |
* *--------* i2c-mux-mlxpcld ^ * -> muxn (virt busn) -> mux -> |
* | driver | |
* | *---------------* | Devices
* | * CPLD (i2c bus)* select |
* | * registers for *--------*
* | * mux selection * deselect
* | *---------------*
* | |
* <--------> <----------->
* i2c cntrl Board cntrl reg
* reg space space (mux select,
* IO, LED, WD, info)
*
*/
/* Write to mux register. Don't use i2c_transfer() and i2c_smbus_xfer()
* for this as they will try to lock adapter a second time.
*/
static int mlxcpld_mux_reg_write(struct i2c_adapter *adap,
struct mlxcpld_mux *mux, u32 val)
{
struct i2c_client *client = mux->client;
union i2c_smbus_data data;
struct i2c_msg msg;
u8 buf[3];
switch (mux->pdata.reg_size) {
case 1:
data.byte = val;
return __i2c_smbus_xfer(adap, client->addr, client->flags,
I2C_SMBUS_WRITE, mux->pdata.sel_reg_addr,
I2C_SMBUS_BYTE_DATA, &data);
case 2:
buf[0] = mux->pdata.sel_reg_addr >> 8;
buf[1] = mux->pdata.sel_reg_addr;
buf[2] = val;
msg.addr = client->addr;
msg.buf = buf;
msg.len = mux->pdata.reg_size + 1;
msg.flags = 0;
return __i2c_transfer(adap, &msg, 1);
default:
return -EINVAL;
}
}
static int mlxcpld_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
{
struct mlxcpld_mux *mux = i2c_mux_priv(muxc);
u32 regval = chan;
int err = 0;
if (mux->pdata.reg_size == 1)
regval += 1;
/* Only select the channel if its different from the last channel */
if (mux->last_val != regval) {
err = mlxcpld_mux_reg_write(muxc->parent, mux, regval);
mux->last_val = err < 0 ? -1 : regval;
}
return err;
}
static int mlxcpld_mux_deselect(struct i2c_mux_core *muxc, u32 chan)
{
struct mlxcpld_mux *mux = i2c_mux_priv(muxc);
/* Deselect active channel */
mux->last_val = -1;
Annotation
- Immediate include surface: `linux/device.h`, `linux/i2c.h`, `linux/i2c-mux.h`, `linux/io.h`, `linux/init.h`, `linux/module.h`, `linux/platform_data/mlxcpld.h`, `linux/platform_device.h`.
- Detected declarations: `struct mlxcpld_mux`, `function space`, `function mlxcpld_mux_select_chan`, `function mlxcpld_mux_deselect`, `function mlxcpld_mux_probe`, `function mlxcpld_mux_remove`.
- Atlas domain: Driver Families / drivers/i2c.
- 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.