From dfb5a31b3e03b690f7fac0cf9f8a973d18150150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Mon, 28 Apr 2025 17:17:09 +0200 Subject: [PATCH] drivers: ethernet: phy: add dt prop for default speeds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add dt prop for default speeds, that the phy is configured on init by default. Signed-off-by: Fin Maaß --- drivers/ethernet/phy/phy_mii.c | 22 ++++++++++++++------- dts/bindings/ethernet/phy/ethernet-phy.yaml | 12 +++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/ethernet/phy/phy_mii.c b/drivers/ethernet/phy/phy_mii.c index 5a6522a9c5b..2f7654a4f14 100644 --- a/drivers/ethernet/phy/phy_mii.c +++ b/drivers/ethernet/phy/phy_mii.c @@ -26,6 +26,7 @@ struct phy_mii_dev_config { bool no_reset; bool fixed; int fixed_speed; + enum phy_link_speed default_speeds; const struct device * const mdio; }; @@ -610,13 +611,8 @@ static int phy_mii_initialize_dynamic_link(const struct device *dev) k_work_init_delayable(&data->monitor_work, monitor_work_handler); k_work_init_delayable(&data->autoneg_work, autoneg_work_handler); - /* Advertise all speeds */ - phy_mii_cfg_link(dev, LINK_HALF_10BASE | - LINK_FULL_10BASE | - LINK_HALF_100BASE | - LINK_FULL_100BASE | - LINK_HALF_1000BASE | - LINK_FULL_1000BASE); + /* Advertise default speeds */ + phy_mii_cfg_link(dev, cfg->default_speeds); monitor_work_handler(&data->monitor_work.work); @@ -636,12 +632,24 @@ static DEVICE_API(ethphy, phy_mii_driver_api) = { #endif }; +#define PHY_MII_GENERATE_DEFAULT_SPEEDS(n) \ +((DT_INST_ENUM_HAS_VALUE(n, default_speeds, 10base_half_duplex) ? LINK_HALF_10BASE : 0) | \ +(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 10base_full_duplex) ? LINK_FULL_10BASE : 0) | \ +(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 100base_half_duplex) ? LINK_HALF_100BASE : 0) | \ +(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 100base_full_duplex) ? LINK_FULL_100BASE : 0) | \ +(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 1000base_half_duplex) ? LINK_HALF_1000BASE : 0) | \ +(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 1000base_full_duplex) ? LINK_FULL_1000BASE : 0)) + #define PHY_MII_CONFIG(n) \ +BUILD_ASSERT(PHY_MII_GENERATE_DEFAULT_SPEEDS(n) != 0, \ + "At least one valid speed must be configured for this driver"); \ + \ static const struct phy_mii_dev_config phy_mii_dev_config_##n = { \ .phy_addr = DT_INST_REG_ADDR(n), \ .no_reset = DT_INST_PROP(n, no_reset), \ .fixed = IS_FIXED_LINK(n), \ .fixed_speed = DT_INST_ENUM_IDX_OR(n, fixed_link, 0), \ + .default_speeds = PHY_MII_GENERATE_DEFAULT_SPEEDS(n), \ .mdio = UTIL_AND(UTIL_NOT(IS_FIXED_LINK(n)), \ DEVICE_DT_GET(DT_INST_BUS(n))) \ }; diff --git a/dts/bindings/ethernet/phy/ethernet-phy.yaml b/dts/bindings/ethernet/phy/ethernet-phy.yaml index 2f9398e59e9..22704da0d40 100644 --- a/dts/bindings/ethernet/phy/ethernet-phy.yaml +++ b/dts/bindings/ethernet/phy/ethernet-phy.yaml @@ -26,3 +26,15 @@ properties: - "100BASE-T Full-Duplex" - "1000BASE-T Half-Duplex" - "1000BASE-T Full-Duplex" + default-speeds: + type: string-array + description: The selected speeds are used to configure the PHY during initialization + enum: + - "10BASE Half-Duplex" + - "10BASE Full-Duplex" + - "100BASE Half-Duplex" + - "100BASE Full-Duplex" + - "1000BASE Half-Duplex" + - "1000BASE Full-Duplex" + default: ["10BASE Half-Duplex", "10BASE Full-Duplex", "100BASE Half-Duplex", + "100BASE Full-Duplex", "1000BASE Half-Duplex", "1000BASE Full-Duplex"]