Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Xu Ziyuan | 535b3dc | 2016-08-01 08:46:19 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
Xu Ziyuan | 535b3dc | 2016-08-01 08:46:19 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 7 | #include <dm.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 8 | #include <environment.h> |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 9 | #include <i2c_eeprom.h> |
| 10 | #include <netdev.h> |
| 11 | |
| 12 | static int get_ethaddr_from_eeprom(u8 *addr) |
| 13 | { |
| 14 | int ret; |
| 15 | struct udevice *dev; |
| 16 | |
| 17 | ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); |
| 18 | if (ret) |
| 19 | return ret; |
| 20 | |
| 21 | return i2c_eeprom_read(dev, 0, addr, 6); |
| 22 | } |
| 23 | |
| 24 | int rk_board_late_init(void) |
| 25 | { |
| 26 | u8 ethaddr[6]; |
| 27 | |
| 28 | if (get_ethaddr_from_eeprom(ethaddr)) |
| 29 | return 0; |
| 30 | |
| 31 | if (is_valid_ethaddr(ethaddr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 32 | eth_env_set_enetaddr("ethaddr", ethaddr); |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 33 | |
| 34 | return 0; |
| 35 | } |