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 | |
| 6 | #include <common.h> |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | cb3ef68 | 2019-11-14 12:57:50 -0700 | [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> |
Michael Trimarchi | 59b01eb | 2019-11-15 22:07:24 +0100 | [diff] [blame] | 14 | #include <asm/arch-rockchip/bootrom.h> |
| 15 | #include <asm/io.h> |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 16 | |
| 17 | static int get_ethaddr_from_eeprom(u8 *addr) |
| 18 | { |
| 19 | int ret; |
| 20 | struct udevice *dev; |
| 21 | |
| 22 | ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); |
| 23 | if (ret) |
| 24 | return ret; |
| 25 | |
| 26 | return i2c_eeprom_read(dev, 0, addr, 6); |
| 27 | } |
| 28 | |
Kever Yang | 271318a | 2019-07-22 20:02:14 +0800 | [diff] [blame] | 29 | int rk3288_board_late_init(void) |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 30 | { |
| 31 | u8 ethaddr[6]; |
| 32 | |
| 33 | if (get_ethaddr_from_eeprom(ethaddr)) |
| 34 | return 0; |
| 35 | |
| 36 | if (is_valid_ethaddr(ethaddr)) |
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 37 | eth_env_set_enetaddr("ethaddr", ethaddr); |
Jonas Karlman | ecc3bd7 | 2017-04-22 08:57:54 +0000 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |
Michael Trimarchi | 59b01eb | 2019-11-15 22:07:24 +0100 | [diff] [blame] | 41 | |
| 42 | int mmc_get_env_dev(void) |
| 43 | { |
| 44 | u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR); |
| 45 | |
| 46 | if (bootdevice_brom_id == BROM_BOOTSOURCE_EMMC) |
| 47 | return 0; |
| 48 | |
| 49 | return 1; |
| 50 | } |