blob: 7af39e10cd5b3b6d1b79c4e8933877f4fac8f5ff [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
6#include <common.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +00007#include <dm.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -07008#include <eeprom.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +000010#include <i2c_eeprom.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +000012#include <netdev.h>
Michael Trimarchi0ae07f62019-11-15 22:07:24 +010013#include <asm/arch-rockchip/bootrom.h>
14#include <asm/io.h>
Jonas Karlman269a37f2017-04-22 08:57:54 +000015
16static int get_ethaddr_from_eeprom(u8 *addr)
17{
18 int ret;
19 struct udevice *dev;
20
21 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
22 if (ret)
23 return ret;
24
25 return i2c_eeprom_read(dev, 0, addr, 6);
26}
27
Kever Yangb7da2712019-07-22 20:02:14 +080028int rk3288_board_late_init(void)
Jonas Karlman269a37f2017-04-22 08:57:54 +000029{
30 u8 ethaddr[6];
31
32 if (get_ethaddr_from_eeprom(ethaddr))
33 return 0;
34
35 if (is_valid_ethaddr(ethaddr))
Simon Glass8551d552017-08-03 12:22:11 -060036 eth_env_set_enetaddr("ethaddr", ethaddr);
Jonas Karlman269a37f2017-04-22 08:57:54 +000037
38 return 0;
39}
Michael Trimarchi0ae07f62019-11-15 22:07:24 +010040
41int mmc_get_env_dev(void)
42{
43 u32 bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
44
45 if (bootdevice_brom_id == BROM_BOOTSOURCE_EMMC)
46 return 0;
47
48 return 1;
49}