From d9b23e26f0b663752e915763d6e2da2fd12fe4b2 Mon Sep 17 00:00:00 2001 From: Wenyou Yang Date: Fri, 1 Sep 2017 16:26:16 +0800 Subject: board: atmel: Create board/$(VENDOR)/common folder Create board/$(VENDOR)/common folder to accommodate the common code shared by other atmel boards, now put the code to set ethernet mac address from eeprom, which uses the i2c eeprom driver. Signed-off-by: Wenyou Yang Reviewed-by: Simon Glass --- board/atmel/common/mac_eeprom.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 board/atmel/common/mac_eeprom.c (limited to 'board/atmel/common/mac_eeprom.c') diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c new file mode 100644 index 0000000000..60ddf00d45 --- /dev/null +++ b/board/atmel/common/mac_eeprom.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Microchip + * Wenyou Yang + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +int at91_set_ethaddr(int offset) +{ + const int ETH_ADDR_LEN = 6; + unsigned char ethaddr[ETH_ADDR_LEN]; + const char *ETHADDR_NAME = "ethaddr"; + struct udevice *dev; + int ret; + + if (env_get(ETHADDR_NAME)) + return 0; + + ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); + if (ret) + return ret; + + ret = i2c_eeprom_read(dev, offset, ethaddr, 6); + if (ret) + return ret; + + if (is_valid_ethaddr(ethaddr)) + eth_env_set_enetaddr(ETHADDR_NAME, ethaddr); + + return 0; +} -- cgit