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 <galak@kernel.org>
This commit is contained in:
Kumar Gala 2022-07-13 11:20:22 -05:00 committed by Carles Cufí
parent f6a3da9c21
commit 3c35faae36
8 changed files with 33 additions and 34 deletions

View file

@ -12,18 +12,12 @@ if ETH_SAM_GMAC
# Read MAC address from AT24MAC402 EEPROM
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
default 0x5F
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
default 0x9A
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
default 1
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
default "I2C_0"
config ETH_SAM_GMAC_MAC_I2C_EEPROM
default y
select I2C

View file

@ -75,6 +75,11 @@
pinctrl-0 = <&twihs0_default>;
pinctrl-names = "default";
eeprom: eeprom@5f {
compatible = "atmel,24mac402";
reg = <0x5f>;
};
};
&twihs2 {
@ -116,6 +121,8 @@ zephyr_udc0: &usbhs {
pinctrl-0 = <&gmac_rmii>;
pinctrl-names = "default";
mac-eeprom = <&eeprom>;
phy: phy {
compatible = "ethernet-phy";
status = "okay";

View file

@ -15,9 +15,7 @@ if ETH_SAM_GMAC
config ETH_SAM_GMAC_MAC_I2C_EEPROM
default y
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
default 0x5F
select I2C
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
default 0x9A
@ -25,12 +23,6 @@ config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
default 1
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
default "I2C_0"
config ETH_SAM_GMAC_MAC_I2C_EEPROM
select I2C
endif # ETH_SAM_GMAC
if NETWORKING

View file

@ -174,6 +174,11 @@
pinctrl-0 = <&twihs0_default>;
pinctrl-names = "default";
eeprom: eeprom@5f {
compatible = "atmel,24mac402";
reg = <0x5f>;
};
};
&twihs2 {
@ -224,6 +229,8 @@ zephyr_udc0: &usbhs {
pinctrl-0 = <&gmac_rmii>;
pinctrl-names = "default";
mac-eeprom = <&eeprom>;
phy: phy {
compatible = "ethernet-phy";
status = "okay";

View file

@ -76,12 +76,6 @@ config ETH_SAM_GMAC_MAC_I2C_EEPROM
if ETH_SAM_GMAC_MAC_I2C_EEPROM
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
hex "I2C 7-bit EEPROM chip address"
range 0 0xff
help
I2C 7-bit address of the EEPROM chip.
config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
hex "I2C EEPROM internal address"
range 0 0xffffffff
@ -97,12 +91,6 @@ config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
help
Size (in bytes) of the internal EEPROM address.
config ETH_SAM_GMAC_MAC_I2C_DEV_NAME
string "I2C bus driver device name"
help
Device name, e.g. I2C_0, of an I2C bus driver device. It is required to
obtain handle to the I2C device object.
endif # ETH_SAM_GMAC_MAC_I2C_EEPROM
config PTP_CLOCK_SAM_GMAC

View file

@ -1787,20 +1787,19 @@ static int eth_initialize(const struct device *dev)
return retval;
}
#ifdef CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
{
const struct device *dev;
uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS;
int ret;
const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET(DT_INST_PHANDLE(0, mac_eeprom));
dev = device_get_binding(CONFIG_ETH_SAM_GMAC_MAC_I2C_DEV_NAME);
if (!dev) {
LOG_ERR("I2C: Device not found");
if (!device_is_ready(i2c.bus)) {
LOG_ERR("Bus device is not ready");
return;
}
ret = i2c_write_read(dev, CONFIG_ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS,
ret = i2c_write_read_dt(&i2c,
&iaddr, CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE,
mac_addr, 6);
@ -1813,7 +1812,7 @@ static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
static void generate_mac(uint8_t mac_addr[6])
{
#if defined(CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM)
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
get_mac_addr_from_i2c_eeprom(mac_addr);
#elif DT_INST_PROP(0, zephyr_random_mac_address)
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);

View file

@ -52,3 +52,7 @@ properties:
represents Reduced Media-Independent Interface (RMII) mode.
This property must be used with pinctrl-0.
mac-eeprom:
type: phandle
description: phandle to I2C eeprom device node.

View file

@ -0,0 +1,8 @@
# Copyright (c) 2022, Kumar Gala <galak@kernel.org>
# SPDX-License-Identifier: Apache-2.0
description: Atmel AT24 (or compatible) I2C EEPROM
compatible: "atmel,at24mac402"
include: [i2c-device.yaml]