Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Xu Ziyuan | 1c62d99 | 2016-08-01 08:46:19 +0800 | [diff] [blame] | 2 | /* |
3 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd | ||||
Xu Ziyuan | 1c62d99 | 2016-08-01 08:46:19 +0800 | [diff] [blame] | 4 | */ |
5 | |||||
Tom Rini | d678a59 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 7 | #include <dm.h> |
Tom Rini | d678a59 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 8 | #include <eeprom.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 9 | #include <env.h> |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 10 | #include <i2c_eeprom.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <net.h> |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 13 | #include <netdev.h> |
14 | |||||
15 | static int get_ethaddr_from_eeprom(u8 *addr) | ||||
16 | { | ||||
17 | int ret; | ||||
18 | struct udevice *dev; | ||||
19 | |||||
20 | ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); | ||||
21 | if (ret) | ||||
22 | return ret; | ||||
23 | |||||
24 | return i2c_eeprom_read(dev, 0, addr, 6); | ||||
25 | } | ||||
26 | |||||
Kever Yang | 271318a | 2019-07-22 20:02:14 +0800 | [diff] [blame] | 27 | int rk3288_board_late_init(void) |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 28 | { |
29 | u8 ethaddr[6]; | ||||
30 | |||||
31 | if (get_ethaddr_from_eeprom(ethaddr)) | ||||
32 | return 0; | ||||
33 | |||||
34 | if (is_valid_ethaddr(ethaddr)) | ||||
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 35 | eth_env_set_enetaddr("ethaddr", ethaddr); |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 36 | |
37 | return 0; | ||||
38 | } |