Skip to content

Commit dfb5a31

Browse files
maass-hamburgkartben
authored andcommitted
drivers: ethernet: phy: add dt prop for default speeds
add dt prop for default speeds, that the phy is configured on init by default. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent 5170a4d commit dfb5a31

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

drivers/ethernet/phy/phy_mii.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct phy_mii_dev_config {
2626
bool no_reset;
2727
bool fixed;
2828
int fixed_speed;
29+
enum phy_link_speed default_speeds;
2930
const struct device * const mdio;
3031
};
3132

@@ -610,13 +611,8 @@ static int phy_mii_initialize_dynamic_link(const struct device *dev)
610611
k_work_init_delayable(&data->monitor_work, monitor_work_handler);
611612
k_work_init_delayable(&data->autoneg_work, autoneg_work_handler);
612613

613-
/* Advertise all speeds */
614-
phy_mii_cfg_link(dev, LINK_HALF_10BASE |
615-
LINK_FULL_10BASE |
616-
LINK_HALF_100BASE |
617-
LINK_FULL_100BASE |
618-
LINK_HALF_1000BASE |
619-
LINK_FULL_1000BASE);
614+
/* Advertise default speeds */
615+
phy_mii_cfg_link(dev, cfg->default_speeds);
620616

621617
monitor_work_handler(&data->monitor_work.work);
622618

@@ -636,12 +632,24 @@ static DEVICE_API(ethphy, phy_mii_driver_api) = {
636632
#endif
637633
};
638634

635+
#define PHY_MII_GENERATE_DEFAULT_SPEEDS(n) \
636+
((DT_INST_ENUM_HAS_VALUE(n, default_speeds, 10base_half_duplex) ? LINK_HALF_10BASE : 0) | \
637+
(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 10base_full_duplex) ? LINK_FULL_10BASE : 0) | \
638+
(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 100base_half_duplex) ? LINK_HALF_100BASE : 0) | \
639+
(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 100base_full_duplex) ? LINK_FULL_100BASE : 0) | \
640+
(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 1000base_half_duplex) ? LINK_HALF_1000BASE : 0) | \
641+
(DT_INST_ENUM_HAS_VALUE(n, default_speeds, 1000base_full_duplex) ? LINK_FULL_1000BASE : 0))
642+
639643
#define PHY_MII_CONFIG(n) \
644+
BUILD_ASSERT(PHY_MII_GENERATE_DEFAULT_SPEEDS(n) != 0, \
645+
"At least one valid speed must be configured for this driver"); \
646+
\
640647
static const struct phy_mii_dev_config phy_mii_dev_config_##n = { \
641648
.phy_addr = DT_INST_REG_ADDR(n), \
642649
.no_reset = DT_INST_PROP(n, no_reset), \
643650
.fixed = IS_FIXED_LINK(n), \
644651
.fixed_speed = DT_INST_ENUM_IDX_OR(n, fixed_link, 0), \
652+
.default_speeds = PHY_MII_GENERATE_DEFAULT_SPEEDS(n), \
645653
.mdio = UTIL_AND(UTIL_NOT(IS_FIXED_LINK(n)), \
646654
DEVICE_DT_GET(DT_INST_BUS(n))) \
647655
};

dts/bindings/ethernet/phy/ethernet-phy.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ properties:
2626
- "100BASE-T Full-Duplex"
2727
- "1000BASE-T Half-Duplex"
2828
- "1000BASE-T Full-Duplex"
29+
default-speeds:
30+
type: string-array
31+
description: The selected speeds are used to configure the PHY during initialization
32+
enum:
33+
- "10BASE Half-Duplex"
34+
- "10BASE Full-Duplex"
35+
- "100BASE Half-Duplex"
36+
- "100BASE Full-Duplex"
37+
- "1000BASE Half-Duplex"
38+
- "1000BASE Full-Duplex"
39+
default: ["10BASE Half-Duplex", "10BASE Full-Duplex", "100BASE Half-Duplex",
40+
"100BASE Full-Duplex", "1000BASE Half-Duplex", "1000BASE Full-Duplex"]

0 commit comments

Comments
 (0)