drivers/i2c/i2c-mux.c
Source file repositories/reference/linux-study-clean/drivers/i2c/i2c-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/i2c-mux.c- Extension
.c- Size
- 12259 bytes
- Lines
- 442
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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.
- 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/acpi.hlinux/i2c.hlinux/i2c-mux.hlinux/kernel.hlinux/module.hlinux/of.hlinux/slab.hlinux/sysfs.h
Detected Declarations
struct i2c_mux_privfunction __i2c_mux_master_xferfunction i2c_mux_master_xferfunction __i2c_mux_smbus_xferfunction i2c_mux_smbus_xferfunction i2c_mux_functionalityfunction i2c_mux_lock_busfunction i2c_mux_trylock_busfunction i2c_mux_unlock_busfunction i2c_parent_lock_busfunction i2c_parent_trylock_busfunction i2c_parent_unlock_busfunction intfunction i2c_mux_add_adapterfunction i2c_mux_del_adaptersexport i2c_root_adapterexport i2c_mux_allocexport i2c_mux_add_adapterexport i2c_mux_del_adapters
Annotated Snippet
struct i2c_mux_priv {
struct i2c_adapter adap;
struct i2c_algorithm algo;
struct i2c_mux_core *muxc;
u32 chan_id;
};
static int __i2c_mux_master_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num)
{
struct i2c_mux_priv *priv = adap->algo_data;
struct i2c_mux_core *muxc = priv->muxc;
struct i2c_adapter *parent = muxc->parent;
int ret;
/* Switch to the right mux port and perform the transfer. */
ret = muxc->select(muxc, priv->chan_id);
if (ret >= 0)
ret = __i2c_transfer(parent, msgs, num);
if (muxc->deselect)
muxc->deselect(muxc, priv->chan_id);
return ret;
}
static int i2c_mux_master_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num)
{
struct i2c_mux_priv *priv = adap->algo_data;
struct i2c_mux_core *muxc = priv->muxc;
struct i2c_adapter *parent = muxc->parent;
int ret;
/* Switch to the right mux port and perform the transfer. */
ret = muxc->select(muxc, priv->chan_id);
if (ret >= 0)
ret = i2c_transfer(parent, msgs, num);
if (muxc->deselect)
muxc->deselect(muxc, priv->chan_id);
return ret;
}
static int __i2c_mux_smbus_xfer(struct i2c_adapter *adap,
u16 addr, unsigned short flags,
char read_write, u8 command,
int size, union i2c_smbus_data *data)
{
struct i2c_mux_priv *priv = adap->algo_data;
struct i2c_mux_core *muxc = priv->muxc;
struct i2c_adapter *parent = muxc->parent;
int ret;
/* Select the right mux port and perform the transfer. */
ret = muxc->select(muxc, priv->chan_id);
if (ret >= 0)
ret = __i2c_smbus_xfer(parent, addr, flags,
read_write, command, size, data);
if (muxc->deselect)
muxc->deselect(muxc, priv->chan_id);
return ret;
}
static int i2c_mux_smbus_xfer(struct i2c_adapter *adap,
u16 addr, unsigned short flags,
char read_write, u8 command,
int size, union i2c_smbus_data *data)
{
struct i2c_mux_priv *priv = adap->algo_data;
struct i2c_mux_core *muxc = priv->muxc;
struct i2c_adapter *parent = muxc->parent;
int ret;
/* Select the right mux port and perform the transfer. */
ret = muxc->select(muxc, priv->chan_id);
if (ret >= 0)
ret = i2c_smbus_xfer(parent, addr, flags,
read_write, command, size, data);
if (muxc->deselect)
muxc->deselect(muxc, priv->chan_id);
return ret;
}
/* Return the parent's functionality */
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/i2c.h`, `linux/i2c-mux.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`, `linux/sysfs.h`.
- Detected declarations: `struct i2c_mux_priv`, `function __i2c_mux_master_xfer`, `function i2c_mux_master_xfer`, `function __i2c_mux_smbus_xfer`, `function i2c_mux_smbus_xfer`, `function i2c_mux_functionality`, `function i2c_mux_lock_bus`, `function i2c_mux_trylock_bus`, `function i2c_mux_unlock_bus`, `function i2c_parent_lock_bus`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: integration 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.