blob: 7ff1ec7462f4dcb3a9d0a299b2dfa0b8908a605e [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>
Alex Kiernan9c215492018-04-01 09:22:38 +00009#include <environment.h>
Wenyou Yanga3b84f42017-09-01 16:26:16 +080010#include <i2c_eeprom.h>
11#include <netdev.h>
12
13int at91_set_ethaddr(int offset)
14{
15 const int ETH_ADDR_LEN = 6;
16 unsigned char ethaddr[ETH_ADDR_LEN];
17 const char *ETHADDR_NAME = "ethaddr";
18 struct udevice *dev;
19 int ret;
20
21 if (env_get(ETHADDR_NAME))
22 return 0;
23
24 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
25 if (ret)
26 return ret;
27
28 ret = i2c_eeprom_read(dev, offset, ethaddr, 6);
29 if (ret)
30 return ret;
31
32 if (is_valid_ethaddr(ethaddr))
33 eth_env_set_enetaddr(ETHADDR_NAME, ethaddr);
34
35 return 0;
36}