Skip to content

Commit 3c35faa

Browse files
galakcarlescufi
authored andcommitted
drivers: ethernet: sam_gmac: Convert to using dts for I2C EEPROM
Introduce a simple binding for atmel,24mac402 EEPROM that the SAM GMAC ethernet driver can utilize to get MAC address out of. We introduce a 'mac-eeprom' phandle into GMAC ethernet devicetree node that will provide a pointer to the MAC eeprom to utilize. Signed-off-by: Kumar Gala <[email protected]>
1 parent f6a3da9 commit 3c35faa

File tree

8 files changed

+33
-34
lines changed

8 files changed

+33
-34
lines changed

boards/arm/sam_e70_xplained/Kconfig.defconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@ if ETH_SAM_GMAC
1212

1313
# Read MAC address from AT24MAC402 EEPROM
1414

15-
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
16-
default 0x5F
17-
1815
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
1916
default 0x9A
2017

2118
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
2219
default 1
2320

24-
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
25-
default "I2C_0"
26-
2721
config ETH_SAM_GMAC_MAC_I2C_EEPROM
2822
default y
2923
select I2C

boards/arm/sam_e70_xplained/sam_e70_xplained-common.dtsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575

7676
pinctrl-0 = <&twihs0_default>;
7777
pinctrl-names = "default";
78+
79+
eeprom: eeprom@5f {
80+
compatible = "atmel,24mac402";
81+
reg = <0x5f>;
82+
};
7883
};
7984

8085
&twihs2 {
@@ -116,6 +121,8 @@ zephyr_udc0: &usbhs {
116121
pinctrl-0 = <&gmac_rmii>;
117122
pinctrl-names = "default";
118123

124+
mac-eeprom = <&eeprom>;
125+
119126
phy: phy {
120127
compatible = "ethernet-phy";
121128
status = "okay";

boards/arm/sam_v71_xult/Kconfig.defconfig

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,14 @@ if ETH_SAM_GMAC
1515

1616
config ETH_SAM_GMAC_MAC_I2C_EEPROM
1717
default y
18-
19-
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
20-
default 0x5F
18+
select I2C
2119

2220
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
2321
default 0x9A
2422

2523
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
2624
default 1
2725

28-
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
29-
default "I2C_0"
30-
31-
config ETH_SAM_GMAC_MAC_I2C_EEPROM
32-
select I2C
33-
3426
endif # ETH_SAM_GMAC
3527

3628
if NETWORKING

boards/arm/sam_v71_xult/sam_v71_xult-common.dtsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@
174174

175175
pinctrl-0 = <&twihs0_default>;
176176
pinctrl-names = "default";
177+
178+
eeprom: eeprom@5f {
179+
compatible = "atmel,24mac402";
180+
reg = <0x5f>;
181+
};
177182
};
178183

179184
&twihs2 {
@@ -224,6 +229,8 @@ zephyr_udc0: &usbhs {
224229
pinctrl-0 = <&gmac_rmii>;
225230
pinctrl-names = "default";
226231

232+
mac-eeprom = <&eeprom>;
233+
227234
phy: phy {
228235
compatible = "ethernet-phy";
229236
status = "okay";

drivers/ethernet/Kconfig.sam_gmac

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ config ETH_SAM_GMAC_MAC_I2C_EEPROM
7676

7777
if ETH_SAM_GMAC_MAC_I2C_EEPROM
7878

79-
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
80-
hex "I2C 7-bit EEPROM chip address"
81-
range 0 0xff
82-
help
83-
I2C 7-bit address of the EEPROM chip.
84-
8579
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
8680
hex "I2C EEPROM internal address"
8781
range 0 0xffffffff
@@ -97,12 +91,6 @@ config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
9791
help
9892
Size (in bytes) of the internal EEPROM address.
9993

100-
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
101-
string "I2C bus driver device name"
102-
help
103-
Device name, e.g. I2C_0, of an I2C bus driver device. It is required to
104-
obtain handle to the I2C device object.
105-
10694
endif # ETH_SAM_GMAC_MAC_I2C_EEPROM
10795

10896
config PTP_CLOCK_SAM_GMAC

drivers/ethernet/eth_sam_gmac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,20 +1787,19 @@ static int eth_initialize(const struct device *dev)
17871787
return retval;
17881788
}
17891789

1790-
#ifdef CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM
1790+
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
17911791
static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
17921792
{
1793-
const struct device *dev;
17941793
uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS;
17951794
int ret;
1795+
const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET(DT_INST_PHANDLE(0, mac_eeprom));
17961796

1797-
dev = device_get_binding(CONFIG_ETH_SAM_GMAC_MAC_I2C_DEV_NAME);
1798-
if (!dev) {
1799-
LOG_ERR("I2C: Device not found");
1797+
if (!device_is_ready(i2c.bus)) {
1798+
LOG_ERR("Bus device is not ready");
18001799
return;
18011800
}
18021801

1803-
ret = i2c_write_read(dev, CONFIG_ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS,
1802+
ret = i2c_write_read_dt(&i2c,
18041803
&iaddr, CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE,
18051804
mac_addr, 6);
18061805

@@ -1813,7 +1812,7 @@ static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
18131812

18141813
static void generate_mac(uint8_t mac_addr[6])
18151814
{
1816-
#if defined(CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM)
1815+
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
18171816
get_mac_addr_from_i2c_eeprom(mac_addr);
18181817
#elif DT_INST_PROP(0, zephyr_random_mac_address)
18191818
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);

dts/bindings/ethernet/atmel,gmac-common.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ properties:
5252
represents Reduced Media-Independent Interface (RMII) mode.
5353
5454
This property must be used with pinctrl-0.
55+
56+
mac-eeprom:
57+
type: phandle
58+
description: phandle to I2C eeprom device node.

dts/bindings/mtd/atmel,24mac402.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2022, Kumar Gala <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Atmel AT24 (or compatible) I2C EEPROM
5+
6+
compatible: "atmel,at24mac402"
7+
8+
include: [i2c-device.yaml]

0 commit comments

Comments
 (0)