@@ -141,10 +141,6 @@ static inline void dcache_clean(uint32_t addr, uint32_t size)
141141#endif
142142#endif /* !CONFIG_NET_TEST */
143143
144- BUILD_ASSERT (!(DT_ANY_INST_HAS_PROP_STATUS_OKAY (mac_eeprom ) &&
145- (DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) > 1 )),
146- "Only support one activated instance get MAC address from EEPROM" );
147-
148144/* if GMAC_UR_MIM_RGMII (new for sama7g5) is defined, the media interface mode
149145 * supported are: mii, rmii and gmii. Otherwise mii and rmii are supported.
150146 */
@@ -1693,41 +1689,6 @@ static int eth_initialize(const struct device *dev)
16931689 return retval ;
16941690}
16951691
1696- #if DT_INST_NODE_HAS_PROP (0 , mac_eeprom )
1697- static void get_mac_addr_from_i2c_eeprom (uint8_t mac_addr [6 ])
1698- {
1699- uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS ;
1700- int ret ;
1701- const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET (DT_INST_PHANDLE (0 , mac_eeprom ));
1702-
1703- if (!device_is_ready (i2c .bus )) {
1704- LOG_ERR ("Bus device is not ready" );
1705- return ;
1706- }
1707-
1708- ret = i2c_write_read_dt (& i2c ,
1709- & iaddr , CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE ,
1710- mac_addr , 6 );
1711-
1712- if (ret != 0 ) {
1713- LOG_ERR ("I2C: failed to read MAC addr" );
1714- return ;
1715- }
1716- }
1717- #endif
1718-
1719- static void generate_mac (uint8_t mac_addr [6 ], const struct eth_sam_dev_cfg * const cfg )
1720- {
1721- #if DT_INST_NODE_HAS_PROP (0 , mac_eeprom )
1722- ARG_UNUSED (cfg );
1723- get_mac_addr_from_i2c_eeprom (mac_addr );
1724- #else
1725- if (cfg -> random_mac_addr ) {
1726- gen_random_mac (mac_addr , ATMEL_OUI_B0 , ATMEL_OUI_B1 , ATMEL_OUI_B2 );
1727- }
1728- #endif
1729- }
1730-
17311692static void phy_link_state_changed (const struct device * pdev ,
17321693 struct phy_link_state * state ,
17331694 void * user_data )
@@ -1802,7 +1763,11 @@ static void eth_iface_init(struct net_if *iface)
18021763 return ;
18031764 }
18041765
1805- generate_mac (dev_data -> mac_addr , cfg );
1766+ result = net_eth_mac_load (& cfg -> mcfg , dev_data -> mac_addr );
1767+ if (result < 0 ) {
1768+ LOG_ERR ("Failed to load MAC (%d)" , result );
1769+ return ;
1770+ }
18061771
18071772 LOG_INF ("%s MAC: %02x:%02x:%02x:%02x:%02x:%02x" , dev -> name ,
18081773 dev_data -> mac_addr [0 ], dev_data -> mac_addr [1 ],
@@ -2136,7 +2101,7 @@ static const struct ethernet_api eth_api = {
21362101 .num_queues = DT_INST_PROP(n, num_queues), \
21372102 .phy_conn_type = DT_INST_ENUM_IDX(n, phy_connection_type), \
21382103 .ref_clk_source = DT_INST_ENUM_IDX(n, ref_clk_source), \
2139- .random_mac_addr = DT_INST_PROP(n, zephyr_random_mac_address), \
2104+ .mcfg = NET_ETH_MAC_DT_INST_CONFIG_INIT(n), \
21402105 };
21412106
21422107#define DEFN_RX_FLAG_LIST_0 (n ) \
0 commit comments