drivers/net/mdio/mdio-regmap.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-regmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-regmap.c- Extension
.c- Size
- 2170 bytes
- Lines
- 94
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/delay.hlinux/mdio.hlinux/module.hlinux/of.hlinux/of_mdio.hlinux/phy.hlinux/platform_device.hlinux/regmap.hlinux/mdio/mdio-regmap.h
Detected Declarations
struct mdio_regmap_privfunction mdio_regmap_read_c22function mdio_regmap_write_c22export devm_mdio_regmap_register
Annotated Snippet
struct mdio_regmap_priv {
struct regmap *regmap;
u8 valid_addr;
};
static int mdio_regmap_read_c22(struct mii_bus *bus, int addr, int regnum)
{
struct mdio_regmap_priv *ctx = bus->priv;
unsigned int val;
int ret;
if (ctx->valid_addr != addr)
return -ENODEV;
ret = regmap_read(ctx->regmap, regnum, &val);
if (ret < 0)
return ret;
return val;
}
static int mdio_regmap_write_c22(struct mii_bus *bus, int addr, int regnum,
u16 val)
{
struct mdio_regmap_priv *ctx = bus->priv;
if (ctx->valid_addr != addr)
return -ENODEV;
return regmap_write(ctx->regmap, regnum, val);
}
struct mii_bus *devm_mdio_regmap_register(struct device *dev,
const struct mdio_regmap_config *config)
{
struct mdio_regmap_priv *mr;
struct mii_bus *mii;
int rc;
if (!config->parent)
return ERR_PTR(-EINVAL);
mii = devm_mdiobus_alloc_size(config->parent, sizeof(*mr));
if (!mii)
return ERR_PTR(-ENOMEM);
mr = mii->priv;
mr->regmap = config->regmap;
mr->valid_addr = config->valid_addr;
mii->name = DRV_NAME;
strscpy(mii->id, config->name, MII_BUS_ID_SIZE);
mii->parent = config->parent;
mii->read = mdio_regmap_read_c22;
mii->write = mdio_regmap_write_c22;
if (config->autoscan)
mii->phy_mask = ~BIT(config->valid_addr);
else
mii->phy_mask = ~0;
rc = devm_mdiobus_register(dev, mii);
if (rc) {
dev_err(config->parent, "Cannot register MDIO bus![%s] (%d)\n", mii->id, rc);
return ERR_PTR(rc);
}
return mii;
}
EXPORT_SYMBOL_GPL(devm_mdio_regmap_register);
MODULE_DESCRIPTION("MDIO API over regmap");
MODULE_AUTHOR("Maxime Chevallier <maxime.chevallier@bootlin.com>");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/mdio.h`, `linux/module.h`, `linux/of.h`, `linux/of_mdio.h`, `linux/phy.h`, `linux/platform_device.h`.
- Detected declarations: `struct mdio_regmap_priv`, `function mdio_regmap_read_c22`, `function mdio_regmap_write_c22`, `export devm_mdio_regmap_register`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.