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> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 8 | #include <env.h> |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 9 | #include <i2c_eeprom.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 12 | #include <netdev.h> |
| 13 | |
| 14 | static int get_ethaddr_from_eeprom(u8 *addr) |
| 15 | { |
| 16 | int ret; |
| 17 | struct udevice *dev; |
| 18 | |
| 19 | ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); |
| 20 | if (ret) |
| 21 | return ret; |
| 22 | |
| 23 | return i2c_eeprom_read(dev, 0, addr, 6); |
| 24 | } |
| 25 | |
Kever Yang | b7da271 | 2019-07-22 20:02:14 +0800 | [diff] [blame] | 26 | int rk3288_board_late_init(void) |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 27 | { |
| 28 | u8 ethaddr[6]; |
| 29 | |
| 30 | if (get_ethaddr_from_eeprom(ethaddr)) |
| 31 | return 0; |
| 32 | |
| 33 | if (is_valid_ethaddr(ethaddr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 34 | eth_env_set_enetaddr("ethaddr", ethaddr); |
Jonas Karlman | 269a37f | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |