drivers/net/mdio/mdio-mux-multiplexer.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-mux-multiplexer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-mux-multiplexer.c- Extension
.c- Size
- 3143 bytes
- Lines
- 118
- Domain
- Driver Families
- Bucket
- drivers/net
- 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/mdio-mux.hlinux/module.hlinux/mux/consumer.hlinux/platform_device.h
Detected Declarations
struct mdio_mux_multiplexer_statefunction mdio_mux_initfunction mdio_mux_multiplexer_probefunction mdio_mux_multiplexer_remove
Annotated Snippet
struct mdio_mux_multiplexer_state {
struct mux_control *muxc;
bool do_deselect;
void *mux_handle;
};
/**
* mdio_mux_multiplexer_switch_fn - This function is called by the mdio-mux
* layer when it thinks the mdio bus
* multiplexer needs to switch.
* @current_child: current value of the mux register.
* @desired_child: value of the 'reg' property of the target child MDIO node.
* @data: Private data used by this switch_fn passed to mdio_mux_init function
* via mdio_mux_init(.., .., .., .., data, ..).
*
* The first time this function is called, current_child == -1.
* If current_child == desired_child, then the mux is already set to the
* correct bus.
*/
static int mdio_mux_multiplexer_switch_fn(int current_child, int desired_child,
void *data)
{
struct platform_device *pdev;
struct mdio_mux_multiplexer_state *s;
int ret = 0;
pdev = (struct platform_device *)data;
s = platform_get_drvdata(pdev);
if (!(current_child ^ desired_child))
return 0;
if (s->do_deselect)
ret = mux_control_deselect(s->muxc);
if (ret) {
dev_err(&pdev->dev, "mux_control_deselect failed in %s: %d\n",
__func__, ret);
return ret;
}
ret = mux_control_select(s->muxc, desired_child);
if (!ret) {
dev_dbg(&pdev->dev, "%s %d -> %d\n", __func__, current_child,
desired_child);
s->do_deselect = true;
} else {
s->do_deselect = false;
}
return ret;
}
static int mdio_mux_multiplexer_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct mdio_mux_multiplexer_state *s;
int ret = 0;
s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
if (!s)
return -ENOMEM;
s->muxc = devm_mux_control_get(dev, NULL);
if (IS_ERR(s->muxc))
return dev_err_probe(&pdev->dev, PTR_ERR(s->muxc),
"Failed to get mux\n");
platform_set_drvdata(pdev, s);
ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node,
mdio_mux_multiplexer_switch_fn, &s->mux_handle,
pdev, NULL);
return ret;
}
static void mdio_mux_multiplexer_remove(struct platform_device *pdev)
{
struct mdio_mux_multiplexer_state *s = platform_get_drvdata(pdev);
mdio_mux_uninit(s->mux_handle);
if (s->do_deselect)
mux_control_deselect(s->muxc);
}
static const struct of_device_id mdio_mux_multiplexer_match[] = {
{ .compatible = "mdio-mux-multiplexer", },
{},
};
Annotation
- Immediate include surface: `linux/mdio-mux.h`, `linux/module.h`, `linux/mux/consumer.h`, `linux/platform_device.h`.
- Detected declarations: `struct mdio_mux_multiplexer_state`, `function mdio_mux_init`, `function mdio_mux_multiplexer_probe`, `function mdio_mux_multiplexer_remove`.
- Atlas domain: Driver Families / drivers/net.
- 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.