drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c- Extension
.c- Size
- 5334 bytes
- Lines
- 183
- 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/mod_devicetable.hlinux/platform_device.hlinux/property.hlinux/mfd/syscon.hlinux/regmap.hstmmac_platform.h
Detected Declarations
struct starfive_dwmac_datastruct starfive_dwmacfunction starfive_dwmac_set_modefunction stmmac_starfive_sgmii_set_clk_ratefunction starfive_dwmac_probe
Annotated Snippet
struct starfive_dwmac_data {
unsigned int gtxclk_dlychain;
};
struct starfive_dwmac {
struct device *dev;
const struct starfive_dwmac_data *data;
struct clk *sgmii_rx;
};
static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
{
struct starfive_dwmac *dwmac = plat_dat->bsp_priv;
struct regmap *regmap;
unsigned int args[2];
int phy_intf_sel;
int err;
phy_intf_sel = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
if (phy_intf_sel != PHY_INTF_SEL_RGMII &&
phy_intf_sel != PHY_INTF_SEL_RMII) {
dev_err(dwmac->dev, "unsupported interface %s\n",
phy_modes(plat_dat->phy_interface));
return phy_intf_sel < 0 ? phy_intf_sel : -EINVAL;
}
regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node,
"starfive,syscon",
2, args);
if (IS_ERR(regmap))
return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "getting the regmap failed\n");
/* args[0]:offset args[1]: shift */
err = regmap_update_bits(regmap, args[0],
STARFIVE_DWMAC_PHY_INFT_FIELD << args[1],
phy_intf_sel << args[1]);
if (err)
return dev_err_probe(dwmac->dev, err, "error setting phy mode\n");
if (dwmac->data) {
err = regmap_write(regmap, JH7100_SYSMAIN_REGISTER49_DLYCHAIN,
dwmac->data->gtxclk_dlychain);
if (err)
return dev_err_probe(dwmac->dev, err,
"error selecting gtxclk delay chain\n");
}
return 0;
}
static int stmmac_starfive_sgmii_set_clk_rate(void *bsp_priv, struct clk *clk_tx_i,
phy_interface_t __maybe_unused interface,
int speed)
{
struct starfive_dwmac *dwmac = bsp_priv;
long rate = rgmii_clock(speed);
int ret;
/* MAC clock rate the same as RGMII */
if (rate < 0)
return -EINVAL;
ret = clk_set_rate(clk_tx_i, rate);
if (ret)
return ret;
return clk_set_rate(dwmac->sgmii_rx, rate);
}
static int starfive_dwmac_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
struct stmmac_resources stmmac_res;
struct starfive_dwmac *dwmac;
struct clk *clk_gtx;
int err;
err = stmmac_get_platform_resources(pdev, &stmmac_res);
if (err)
return dev_err_probe(&pdev->dev, err,
"failed to get resources\n");
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat),
"dt configuration failed\n");
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
if (!dwmac)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/property.h`, `linux/mfd/syscon.h`, `linux/regmap.h`, `stmmac_platform.h`.
- Detected declarations: `struct starfive_dwmac_data`, `struct starfive_dwmac`, `function starfive_dwmac_set_mode`, `function stmmac_starfive_sgmii_set_clk_rate`, `function starfive_dwmac_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.