drivers/i2c/muxes/i2c-mux-pinctrl.c
Source file repositories/reference/linux-study-clean/drivers/i2c/muxes/i2c-mux-pinctrl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/muxes/i2c-mux-pinctrl.c- Extension
.c- Size
- 4757 bytes
- Lines
- 197
- 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/i2c.hlinux/i2c-mux.hlinux/module.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/slab.hlinux/of.h../../pinctrl/core.h
Detected Declarations
struct i2c_mux_pinctrlfunction i2c_mux_pinctrl_selectfunction i2c_mux_pinctrl_deselectfunction list_for_each_entryfunction i2c_mux_pinctrl_probefunction i2c_mux_pinctrl_remove
Annotated Snippet
struct i2c_mux_pinctrl {
struct pinctrl *pinctrl;
struct pinctrl_state *states[];
};
static int i2c_mux_pinctrl_select(struct i2c_mux_core *muxc, u32 chan)
{
struct i2c_mux_pinctrl *mux = i2c_mux_priv(muxc);
return pinctrl_select_state(mux->pinctrl, mux->states[chan]);
}
static int i2c_mux_pinctrl_deselect(struct i2c_mux_core *muxc, u32 chan)
{
return i2c_mux_pinctrl_select(muxc, muxc->num_adapters);
}
static struct i2c_adapter *i2c_mux_pinctrl_root_adapter(
struct pinctrl_state *state)
{
struct i2c_adapter *root = NULL;
struct pinctrl_setting *setting;
struct i2c_adapter *pin_root;
list_for_each_entry(setting, &state->settings, node) {
pin_root = i2c_root_adapter(setting->pctldev->dev);
if (!pin_root)
return NULL;
if (!root)
root = pin_root;
else if (root != pin_root)
return NULL;
}
return root;
}
static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev)
{
struct device_node *np = dev->of_node;
struct device_node *parent_np;
struct i2c_adapter *parent;
parent_np = of_parse_phandle(np, "i2c-parent", 0);
if (!parent_np) {
dev_err(dev, "Cannot parse i2c-parent\n");
return ERR_PTR(-ENODEV);
}
parent = of_get_i2c_adapter_by_node(parent_np);
of_node_put(parent_np);
if (!parent)
return ERR_PTR(-EPROBE_DEFER);
return parent;
}
static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct i2c_mux_core *muxc;
struct i2c_mux_pinctrl *mux;
struct i2c_adapter *parent;
struct i2c_adapter *root;
int num_names, i, ret;
const char *name;
num_names = of_property_count_strings(np, "pinctrl-names");
if (num_names < 0) {
dev_err(dev, "Cannot parse pinctrl-names: %d\n",
num_names);
return num_names;
}
parent = i2c_mux_pinctrl_parent_adapter(dev);
if (IS_ERR(parent))
return PTR_ERR(parent);
muxc = i2c_mux_alloc(parent, dev, num_names,
struct_size(mux, states, num_names),
0, i2c_mux_pinctrl_select, NULL);
if (!muxc) {
ret = -ENOMEM;
goto err_put_parent;
}
mux = i2c_mux_priv(muxc);
platform_set_drvdata(pdev, muxc);
mux->pinctrl = devm_pinctrl_get(dev);
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/i2c-mux.h`, `linux/module.h`, `linux/pinctrl/consumer.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/of.h`, `../../pinctrl/core.h`.
- Detected declarations: `struct i2c_mux_pinctrl`, `function i2c_mux_pinctrl_select`, `function i2c_mux_pinctrl_deselect`, `function list_for_each_entry`, `function i2c_mux_pinctrl_probe`, `function i2c_mux_pinctrl_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.