blob: 91b86e0c622d9ba7db46d4f5f897823883c7b986 [file] [log] [blame]
Wenyou Yanga3b84f42017-09-01 16:26:16 +08001/*
2 * Copyright (C) 2017 Microchip
3 * Wenyou Yang <wenyou.yang@microchip.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
Alex Kiernan9c215492018-04-01 09:22:38 +000010#include <environment.h>
Wenyou Yanga3b84f42017-09-01 16:26:16 +080011#include <i2c_eeprom.h>
12#include <netdev.h>
13
14int at91_set_ethaddr(int offset)
15{
16 const int ETH_ADDR_LEN = 6;
17 unsigned char ethaddr[ETH_ADDR_LEN];
18 const char *ETHADDR_NAME = "ethaddr";
19 struct udevice *dev;
20 int ret;
21
22 if (env_get(ETHADDR_NAME))
23 return 0;
24
25 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
26 if (ret)
27 return ret;
28
29 ret = i2c_eeprom_read(dev, offset, ethaddr, 6);
30 if (ret)
31 return ret;
32
33 if (is_valid_ethaddr(ethaddr))
34 eth_env_set_enetaddr(ETHADDR_NAME, ethaddr);
35
36 return 0;
37}