drivers/i2c/muxes/i2c-mux-reg.c
Source file repositories/reference/linux-study-clean/drivers/i2c/muxes/i2c-mux-reg.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/muxes/i2c-mux-reg.c- Extension
.c- Size
- 5996 bytes
- Lines
- 249
- 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.
- 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/i2c.hlinux/i2c-mux.hlinux/init.hlinux/io.hlinux/module.hlinux/platform_data/i2c-mux-reg.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct regmuxfunction i2c_mux_reg_setfunction i2c_mux_reg_selectfunction i2c_mux_reg_deselectfunction i2c_mux_reg_probe_fwfunction device_for_each_child_nodefunction i2c_mux_reg_probefunction i2c_mux_reg_remove
Annotated Snippet
struct regmux {
struct i2c_mux_reg_platform_data data;
};
static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id)
{
if (!mux->data.reg)
return -EINVAL;
/*
* Write to the register, followed by a read to ensure the write is
* completed on a "posted" bus, for example PCI or write buffers.
* The endianness of reading doesn't matter and the return data
* is not used.
*/
switch (mux->data.reg_size) {
case 4:
if (mux->data.little_endian)
iowrite32(chan_id, mux->data.reg);
else
iowrite32be(chan_id, mux->data.reg);
if (!mux->data.write_only)
ioread32(mux->data.reg);
break;
case 2:
if (mux->data.little_endian)
iowrite16(chan_id, mux->data.reg);
else
iowrite16be(chan_id, mux->data.reg);
if (!mux->data.write_only)
ioread16(mux->data.reg);
break;
case 1:
iowrite8(chan_id, mux->data.reg);
if (!mux->data.write_only)
ioread8(mux->data.reg);
break;
}
return 0;
}
static int i2c_mux_reg_select(struct i2c_mux_core *muxc, u32 chan)
{
struct regmux *mux = i2c_mux_priv(muxc);
return i2c_mux_reg_set(mux, chan);
}
static int i2c_mux_reg_deselect(struct i2c_mux_core *muxc, u32 chan)
{
struct regmux *mux = i2c_mux_priv(muxc);
if (mux->data.idle_in_use)
return i2c_mux_reg_set(mux, mux->data.idle);
return 0;
}
static int i2c_mux_reg_probe_fw(struct regmux *mux, struct device *dev)
{
struct fwnode_handle *fwnode, *child;
struct i2c_adapter *adapter;
unsigned *values;
int ret, i = 0;
if (!dev_fwnode(dev))
return -ENODEV;
fwnode = fwnode_find_reference(dev_fwnode(dev), "i2c-parent", 0);
if (IS_ERR(fwnode)) {
dev_err(dev, "missing 'i2c-parent' property\n");
return -ENODEV;
}
adapter = i2c_find_adapter_by_fwnode(fwnode);
fwnode_handle_put(fwnode);
if (!adapter)
return -EPROBE_DEFER;
mux->data.parent = i2c_adapter_id(adapter);
put_device(&adapter->dev);
mux->data.n_values = device_get_child_node_count(dev);
if (device_property_read_bool(dev, "little-endian")) {
mux->data.little_endian = true;
} else if (device_property_read_bool(dev, "big-endian")) {
mux->data.little_endian = false;
} else {
#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/i2c-mux.h`, `linux/init.h`, `linux/io.h`, `linux/module.h`, `linux/platform_data/i2c-mux-reg.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct regmux`, `function i2c_mux_reg_set`, `function i2c_mux_reg_select`, `function i2c_mux_reg_deselect`, `function i2c_mux_reg_probe_fw`, `function device_for_each_child_node`, `function i2c_mux_reg_probe`, `function i2c_mux_reg_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.