blob: 2205dd30f8fef9c774c501d35e7a308e5774ad2f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wenyou Yanga3b84f42017-09-01 16:26:16 +08002/*
3 * Copyright (C) 2017 Microchip
4 * Wenyou Yang <wenyou.yang@microchip.com>
Wenyou Yanga3b84f42017-09-01 16:26:16 +08005 */
6
7#include <common.h>
8#include <dm.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -07009#include <eeprom.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Wenyou Yanga3b84f42017-09-01 16:26:16 +080011#include <i2c_eeprom.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Wenyou Yanga3b84f42017-09-01 16:26:16 +080013#include <netdev.h>
14
15int at91_set_ethaddr(int offset)
16{
17 const int ETH_ADDR_LEN = 6;
18 unsigned char ethaddr[ETH_ADDR_LEN];
19 const char *ETHADDR_NAME = "ethaddr";
20 struct udevice *dev;
21 int ret;
22
23 if (env_get(ETHADDR_NAME))
24 return 0;
25
26 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
27 if (ret)
28 return ret;
29
30 ret = i2c_eeprom_read(dev, offset, ethaddr, 6);
31 if (ret)
32 return ret;
33
34 if (is_valid_ethaddr(ethaddr))
35 eth_env_set_enetaddr(ETHADDR_NAME, ethaddr);
36
37 return 0;
38}