blob: e966e9f201abbb3ae8cd5e2c15a11d00ddba442d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Xu Ziyuan535b3dc2016-08-01 08:46:19 +08002/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
Xu Ziyuan535b3dc2016-08-01 08:46:19 +08004 */
5
Jonas Karlman269a37f2017-04-22 08:57:54 +00006#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06007#include <env.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +00008#include <i2c_eeprom.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +000011#include <netdev.h>
12
13static int get_ethaddr_from_eeprom(u8 *addr)
14{
15 int ret;
16 struct udevice *dev;
17
18 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
19 if (ret)
20 return ret;
21
22 return i2c_eeprom_read(dev, 0, addr, 6);
23}
24
Kever Yangb7da2712019-07-22 20:02:14 +080025int rk3288_board_late_init(void)
Jonas Karlman269a37f2017-04-22 08:57:54 +000026{
27 u8 ethaddr[6];
28
29 if (get_ethaddr_from_eeprom(ethaddr))
30 return 0;
31
32 if (is_valid_ethaddr(ethaddr))
Simon Glass8551d552017-08-03 12:22:11 -060033 eth_env_set_enetaddr("ethaddr", ethaddr);
Jonas Karlman269a37f2017-04-22 08:57:54 +000034
35 return 0;
36}