drivers/net/mdio/mdio-mux-bcm-iproc.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-mux-bcm-iproc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-mux-bcm-iproc.c- Extension
.c- Size
- 8867 bytes
- Lines
- 353
- 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/align.hlinux/clk.hlinux/delay.hlinux/device.hlinux/iopoll.hlinux/mdio-mux.hlinux/module.hlinux/of_mdio.hlinux/phy.hlinux/platform_device.hlinux/sizes.h
Detected Declarations
struct iproc_mdiomux_descfunction mdio_mux_iproc_configfunction iproc_mdio_wait_for_idlefunction start_miim_opsfunction iproc_mdiomux_read_c22function iproc_mdiomux_read_c45function iproc_mdiomux_write_c22function iproc_mdiomux_write_c45function mdio_mux_iproc_switch_fnfunction mdio_mux_iproc_probefunction mdio_mux_iproc_removefunction mdio_mux_iproc_suspendfunction mdio_mux_iproc_resume
Annotated Snippet
struct iproc_mdiomux_desc {
void *mux_handle;
void __iomem *base;
struct device *dev;
struct mii_bus *mii_bus;
struct clk *core_clk;
};
static void mdio_mux_iproc_config(struct iproc_mdiomux_desc *md)
{
u32 divisor;
u32 val;
/* Disable external mdio master access */
val = readl(md->base + MDIO_SCAN_CTRL_OFFSET);
val |= BIT(MDIO_SCAN_CTRL_OVRIDE_EXT_MSTR);
writel(val, md->base + MDIO_SCAN_CTRL_OFFSET);
if (md->core_clk) {
/* use rate adjust regs to derive the mdio's operating
* frequency from the specified core clock
*/
divisor = clk_get_rate(md->core_clk) / MDIO_OPERATING_FREQUENCY;
divisor = divisor / (MDIO_RATE_ADJ_DIVIDENT + 1);
val = divisor;
val |= MDIO_RATE_ADJ_DIVIDENT << MDIO_RATE_ADJ_DIVIDENT_SHIFT;
writel(val, md->base + MDIO_RATE_ADJ_EXT_OFFSET);
writel(val, md->base + MDIO_RATE_ADJ_INT_OFFSET);
}
}
static int iproc_mdio_wait_for_idle(void __iomem *base, bool result)
{
u32 val;
return readl_poll_timeout(base + MDIO_STAT_OFFSET, val,
(val & MDIO_STAT_DONE) == result,
2000, 1000000);
}
/* start_miim_ops- Program and start MDIO transaction over mdio bus.
* @base: Base address
* @phyid: phyid of the selected bus.
* @reg: register offset to be read/written.
* @val :0 if read op else value to be written in @reg;
* @op: Operation that need to be carried out.
* MDIO_CTRL_READ_OP: Read transaction.
* MDIO_CTRL_WRITE_OP: Write transaction.
*
* Return value: Successful Read operation returns read reg values and write
* operation returns 0. Failure operation returns negative error code.
*/
static int start_miim_ops(void __iomem *base, bool c45,
u16 phyid, u32 reg, u16 val, u32 op)
{
u32 param;
int ret;
writel(0, base + MDIO_CTRL_OFFSET);
ret = iproc_mdio_wait_for_idle(base, 0);
if (ret)
goto err;
param = readl(base + MDIO_PARAM_OFFSET);
param |= phyid << MDIO_PARAM_PHY_ID;
param |= val << MDIO_PARAM_PHY_DATA;
if (c45)
param |= BIT(MDIO_PARAM_C45_SEL);
writel(param, base + MDIO_PARAM_OFFSET);
writel(reg, base + MDIO_ADDR_OFFSET);
writel(op, base + MDIO_CTRL_OFFSET);
ret = iproc_mdio_wait_for_idle(base, 1);
if (ret)
goto err;
if (op == MDIO_CTRL_READ_OP)
ret = readl(base + MDIO_READ_OFFSET) & MDIO_READ_DATA_MASK;
err:
return ret;
}
static int iproc_mdiomux_read_c22(struct mii_bus *bus, int phyid, int reg)
{
struct iproc_mdiomux_desc *md = bus->priv;
int ret;
Annotation
- Immediate include surface: `linux/align.h`, `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/iopoll.h`, `linux/mdio-mux.h`, `linux/module.h`, `linux/of_mdio.h`.
- Detected declarations: `struct iproc_mdiomux_desc`, `function mdio_mux_iproc_config`, `function iproc_mdio_wait_for_idle`, `function start_miim_ops`, `function iproc_mdiomux_read_c22`, `function iproc_mdiomux_read_c45`, `function iproc_mdiomux_write_c22`, `function iproc_mdiomux_write_c45`, `function mdio_mux_iproc_switch_fn`, `function mdio_mux_iproc_probe`.
- 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.