drivers/net/mdio/mdio-sun4i.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-sun4i.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-sun4i.c- Extension
.c- Size
- 4479 bytes
- Lines
- 179
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/of_address.hlinux/of_mdio.hlinux/phy.hlinux/platform_device.hlinux/regulator/consumer.h
Detected Declarations
struct sun4i_mdio_datafunction sun4i_mdio_readfunction sun4i_mdio_writefunction sun4i_mdio_probefunction sun4i_mdio_remove
Annotated Snippet
struct sun4i_mdio_data {
void __iomem *membase;
struct regulator *regulator;
};
static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{
struct sun4i_mdio_data *data = bus->priv;
unsigned long timeout_jiffies;
int value;
/* issue the phy address and reg */
writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
/* pull up the phy io line */
writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
/* Wait read complete */
timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_is_before_jiffies(timeout_jiffies))
return -ETIMEDOUT;
msleep(1);
}
/* push down the phy io line */
writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
/* and read data */
value = readl(data->membase + EMAC_MAC_MRDD_REG);
return value;
}
static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
u16 value)
{
struct sun4i_mdio_data *data = bus->priv;
unsigned long timeout_jiffies;
/* issue the phy address and reg */
writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
/* pull up the phy io line */
writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
/* Wait read complete */
timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_is_before_jiffies(timeout_jiffies))
return -ETIMEDOUT;
msleep(1);
}
/* push down the phy io line */
writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
/* and write data */
writel(value, data->membase + EMAC_MAC_MWTD_REG);
return 0;
}
static int sun4i_mdio_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct mii_bus *bus;
struct sun4i_mdio_data *data;
int ret;
bus = mdiobus_alloc_size(sizeof(*data));
if (!bus)
return -ENOMEM;
bus->name = "sun4i_mii_bus";
bus->read = &sun4i_mdio_read;
bus->write = &sun4i_mdio_write;
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
bus->parent = &pdev->dev;
data = bus->priv;
data->membase = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(data->membase)) {
ret = PTR_ERR(data->membase);
goto err_out_free_mdiobus;
}
data->regulator = devm_regulator_get(&pdev->dev, "phy");
if (IS_ERR(data->regulator)) {
if (PTR_ERR(data->regulator) == -EPROBE_DEFER) {
ret = -EPROBE_DEFER;
goto err_out_free_mdiobus;
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/of_address.h`, `linux/of_mdio.h`, `linux/phy.h`, `linux/platform_device.h`.
- Detected declarations: `struct sun4i_mdio_data`, `function sun4i_mdio_read`, `function sun4i_mdio_write`, `function sun4i_mdio_probe`, `function sun4i_mdio_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.