@@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
33
33
34
34
#include <zephyr/kernel.h>
35
35
#include <zephyr/device.h>
36
+ #include <zephyr/nvmem.h>
36
37
#include <zephyr/sys/__assert.h>
37
38
#include <zephyr/sys/barrier.h>
38
39
#include <zephyr/sys/util.h>
@@ -1729,38 +1730,6 @@ static int eth_initialize(const struct device *dev)
1729
1730
return retval ;
1730
1731
}
1731
1732
1732
- #if DT_INST_NODE_HAS_PROP (0 , mac_eeprom )
1733
- static void get_mac_addr_from_i2c_eeprom (uint8_t mac_addr [6 ])
1734
- {
1735
- uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS ;
1736
- int ret ;
1737
- const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET (DT_INST_PHANDLE (0 , mac_eeprom ));
1738
-
1739
- if (!device_is_ready (i2c .bus )) {
1740
- LOG_ERR ("Bus device is not ready" );
1741
- return ;
1742
- }
1743
-
1744
- ret = i2c_write_read_dt (& i2c ,
1745
- & iaddr , CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE ,
1746
- mac_addr , 6 );
1747
-
1748
- if (ret != 0 ) {
1749
- LOG_ERR ("I2C: failed to read MAC addr" );
1750
- return ;
1751
- }
1752
- }
1753
- #endif
1754
-
1755
- static void generate_mac (uint8_t mac_addr [6 ])
1756
- {
1757
- #if DT_INST_NODE_HAS_PROP (0 , mac_eeprom )
1758
- get_mac_addr_from_i2c_eeprom (mac_addr );
1759
- #elif DT_INST_PROP (0 , zephyr_random_mac_address )
1760
- gen_random_mac (mac_addr , ATMEL_OUI_B0 , ATMEL_OUI_B1 , ATMEL_OUI_B2 );
1761
- #endif
1762
- }
1763
-
1764
1733
static void phy_link_state_changed (const struct device * pdev ,
1765
1734
struct phy_link_state * state ,
1766
1735
void * user_data )
@@ -1836,7 +1805,11 @@ static void eth0_iface_init(struct net_if *iface)
1836
1805
return ;
1837
1806
}
1838
1807
1839
- generate_mac (dev_data -> mac_addr );
1808
+ result = net_eth_mac_load (cfg -> mcfg , dev_data -> mac_addr );
1809
+ if (result < 0 ) {
1810
+ LOG_ERR ("Failed to load MAC (%d)" , result );
1811
+ return ;
1812
+ }
1840
1813
1841
1814
LOG_INF ("MAC: %02x:%02x:%02x:%02x:%02x:%02x" ,
1842
1815
dev_data -> mac_addr [0 ], dev_data -> mac_addr [1 ],
@@ -2153,6 +2126,7 @@ static void eth0_irq_config(void)
2153
2126
}
2154
2127
2155
2128
PINCTRL_DT_INST_DEFINE (0 );
2129
+ NET_ETH_MAC_DT_INST_DEFINE (0 );
2156
2130
2157
2131
static const struct eth_sam_dev_cfg eth0_config = {
2158
2132
.regs = (Gmac * )DT_REG_ADDR (DT_INST_PARENT (0 )),
@@ -2161,7 +2135,8 @@ static const struct eth_sam_dev_cfg eth0_config = {
2161
2135
.clock_cfg = SAM_DT_CLOCK_PMC_CFG (0 , DT_INST_PARENT (0 )),
2162
2136
#endif
2163
2137
.config_func = eth0_irq_config ,
2164
- .phy_dev = DEVICE_DT_GET (DT_INST_PHANDLE (0 , phy_handle ))
2138
+ .phy_dev = DEVICE_DT_GET (DT_INST_PHANDLE (0 , phy_handle )),
2139
+ .mcfg = NET_ETH_MAC_DT_INST_DEV_CONFIG_GET (0 ),
2165
2140
};
2166
2141
2167
2142
static struct eth_sam_dev_data eth0_data = {
0 commit comments