Skip to content

Commit be54d83

Browse files
committed
drivers: ethernet: sam_gmac: Use ethernet MAC configuration
Rework the Atmel SAM GMAC driver to read a MAC address from the provided NVMEM cell instead of using I2C commands directly. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 8a40281 commit be54d83

File tree

11 files changed

+75
-87
lines changed

11 files changed

+75
-87
lines changed

boards/atmel/sam/sam4e_xpro/sam4e_xpro.dts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
pinctrl-0 = <&gmac_mii>;
202202
pinctrl-names = "default";
203203

204+
/* Atmel OUI */
205+
local-mac-address = [00 04 25];
204206
zephyr,random-mac-address;
205207

206208
phy-handle = <&phy>;

boards/atmel/sam/sam_e70_xplained/Kconfig.defconfig

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ if ETH_SAM_GMAC
77

88
# Read MAC address from AT24MAC402 EEPROM
99

10-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
11-
default 0x9A
12-
13-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
14-
default 1
10+
config EEPROM
11+
default y
1512

16-
config ETH_SAM_GMAC_MAC_I2C_EEPROM
13+
config NVMEM
1714
default y
18-
select I2C
1915

2016
endif # ETH_SAM_GMAC
2117

boards/atmel/sam/sam_e70_xplained/sam_e70_xplained-common.dtsi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,23 @@
8181
pinctrl-names = "default";
8282

8383
eeprom: eeprom@5f {
84-
compatible = "atmel,24mac402";
84+
compatible = "atmel,at24", "atmel,24mac402";
8585
reg = <0x5f>;
86+
size = <256>;
87+
pagesize = <16>;
88+
address-width = <8>;
89+
timeout = <5>;
90+
91+
nvmem-layout {
92+
compatible = "fixed-layout";
93+
#address-cells = <1>;
94+
#size-cells = <1>;
95+
96+
mac_address: mac-address@9a {
97+
reg = <0x9a 6>;
98+
#nvmem-cell-cells = <0>;
99+
};
100+
};
86101
};
87102
};
88103

@@ -128,7 +143,8 @@ zephyr_udc0: &usbhs {
128143
pinctrl-0 = <&gmac_rmii>;
129144
pinctrl-names = "default";
130145

131-
mac-eeprom = <&eeprom>;
146+
nvmem-cells = <&mac_address>;
147+
nvmem-cell-names = "mac-address";
132148
phy-handle = <&phy>;
133149
};
134150

boards/atmel/sam/sam_v71_xult/Kconfig.defconfig

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ if ETH_SAM_GMAC
88

99
# Read MAC address from AT24MAC402 EEPROM
1010

11-
config ETH_SAM_GMAC_MAC_I2C_EEPROM
11+
config EEPROM
1212
default y
13-
select I2C
1413

15-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
16-
default 0x9A
17-
18-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
19-
default 1
14+
config NVMEM
15+
default y
2016

2117
endif # ETH_SAM_GMAC
2218

boards/atmel/sam/sam_v71_xult/sam_v71_xult-common.dtsi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,23 @@
198198
pinctrl-names = "default";
199199

200200
eeprom: eeprom@5f {
201-
compatible = "atmel,24mac402";
201+
compatible = "atmel,at24", "atmel,24mac402";
202202
reg = <0x5f>;
203+
size = <256>;
204+
pagesize = <16>;
205+
address-width = <8>;
206+
timeout = <5>;
207+
208+
nvmem-layout {
209+
compatible = "fixed-layout";
210+
#address-cells = <1>;
211+
#size-cells = <1>;
212+
213+
mac_address: mac-address@9a {
214+
reg = <0x9a 6>;
215+
#nvmem-cell-cells = <0>;
216+
};
217+
};
203218
};
204219
};
205220

@@ -253,7 +268,8 @@ zephyr_udc0: &usbhs {
253268
pinctrl-0 = <&gmac_rmii>;
254269
pinctrl-names = "default";
255270

256-
mac-eeprom = <&eeprom>;
271+
nvmem-cells = <&mac_address>;
272+
nvmem-cell-names = "mac-address";
257273
phy-handle = <&phy>;
258274
};
259275

boards/atmel/sam0/same54_xpro/Kconfig.defconfig

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ if ETH_SAM_GMAC
88

99
# Read MAC address from AT24MAC402 EEPROM
1010

11-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
12-
default 0x9A
13-
14-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
15-
default 1
11+
config EEPROM
12+
default y
1613

17-
config ETH_SAM_GMAC_MAC_I2C_EEPROM
14+
config NVMEM
1815
default y
19-
select I2C
2016

2117
endif # ETH_SAM_GMAC
2218

boards/atmel/sam0/same54_xpro/same54_xpro.dts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,23 @@
116116
pinctrl-names = "default";
117117

118118
eeprom: eeprom@5e {
119-
compatible = "atmel,24mac402";
119+
compatible = "atmel,at24", "atmel,24mac402";
120120
reg = <0x5e>;
121+
size = <256>;
122+
pagesize = <16>;
123+
address-width = <8>;
124+
timeout = <5>;
125+
126+
nvmem-layout {
127+
compatible = "fixed-layout";
128+
#address-cells = <1>;
129+
#size-cells = <1>;
130+
131+
mac_address: mac-address@9a {
132+
reg = <0x9a 6>;
133+
#nvmem-cell-cells = <0>;
134+
};
135+
};
121136
};
122137
};
123138

@@ -158,7 +173,8 @@ zephyr_udc0: &usb0 {
158173
pinctrl-0 = <&gmac_rmii>;
159174
pinctrl-names = "default";
160175

161-
mac-eeprom = <&eeprom>;
176+
nvmem-cells = <&mac_address>;
177+
nvmem-cell-names = "mac-address";
162178
phy-handle = <&phy>;
163179
};
164180

drivers/ethernet/Kconfig.sam_gmac

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,6 @@ config ETH_SAM_GMAC_BUF_RX_COUNT
7272
fit at least two Ethernet frames: one being received by the GMAC module
7373
and the other being processed by the higher layer networking stack.
7474

75-
config ETH_SAM_GMAC_MAC_I2C_EEPROM
76-
bool "Read from an I2C EEPROM"
77-
help
78-
Read MAC address from an I2C EEPROM.
79-
80-
if ETH_SAM_GMAC_MAC_I2C_EEPROM
81-
82-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
83-
hex "I2C EEPROM internal address"
84-
range 0 0xffffffff
85-
help
86-
Internal address of the EEPROM chip where the MAC address is stored.
87-
Chips with 1 to 4 byte internal address size are supported. Address
88-
size has to be configured in a separate Kconfig option.
89-
90-
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
91-
int "I2C EEPROM internal address size"
92-
default 1
93-
range 1 4
94-
help
95-
Size (in bytes) of the internal EEPROM address.
96-
97-
endif # ETH_SAM_GMAC_MAC_I2C_EEPROM
98-
9975
config PTP_CLOCK_SAM_GMAC
10076
bool "SAM GMAC PTP clock driver support"
10177
default y

drivers/ethernet/eth_sam_gmac.c

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
3333

3434
#include <zephyr/kernel.h>
3535
#include <zephyr/device.h>
36+
#include <zephyr/nvmem.h>
3637
#include <zephyr/sys/__assert.h>
3738
#include <zephyr/sys/barrier.h>
3839
#include <zephyr/sys/util.h>
@@ -1729,38 +1730,6 @@ static int eth_initialize(const struct device *dev)
17291730
return retval;
17301731
}
17311732

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-
17641733
static void phy_link_state_changed(const struct device *pdev,
17651734
struct phy_link_state *state,
17661735
void *user_data)
@@ -1836,7 +1805,11 @@ static void eth0_iface_init(struct net_if *iface)
18361805
return;
18371806
}
18381807

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+
}
18401813

18411814
LOG_INF("MAC: %02x:%02x:%02x:%02x:%02x:%02x",
18421815
dev_data->mac_addr[0], dev_data->mac_addr[1],
@@ -2153,6 +2126,7 @@ static void eth0_irq_config(void)
21532126
}
21542127

21552128
PINCTRL_DT_INST_DEFINE(0);
2129+
NET_ETH_MAC_DT_INST_DEFINE(0);
21562130

21572131
static const struct eth_sam_dev_cfg eth0_config = {
21582132
.regs = (Gmac *)DT_REG_ADDR(DT_INST_PARENT(0)),
@@ -2161,7 +2135,8 @@ static const struct eth_sam_dev_cfg eth0_config = {
21612135
.clock_cfg = SAM_DT_CLOCK_PMC_CFG(0, DT_INST_PARENT(0)),
21622136
#endif
21632137
.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),
21652140
};
21662141

21672142
static struct eth_sam_dev_data eth0_data = {

drivers/ethernet/eth_sam_gmac_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct eth_sam_dev_cfg {
263263
const struct pinctrl_dev_config *pcfg;
264264
void (*config_func)(void);
265265
const struct device *phy_dev;
266+
const struct net_eth_mac_config *mcfg;
266267
};
267268

268269
/* Device run time data */

0 commit comments

Comments
 (0)