blob: f85209c6498dc54f764897617da5b67c24182133 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Xu Ziyuan1c62d992016-08-01 08:46:19 +08002/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
Xu Ziyuan1c62d992016-08-01 08:46:19 +08004 */
5
6#include <common.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +00007#include <dm.h>
Simon Glasscb3ef682019-11-14 12:57:50 -07008#include <eeprom.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06009#include <env.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000010#include <i2c_eeprom.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <net.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000013#include <netdev.h>
Michael Trimarchi59b01eb2019-11-15 22:07:24 +010014#include <asm/arch-rockchip/bootrom.h>
15#include <asm/io.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000016
17static 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 Yang271318a2019-07-22 20:02:14 +080029int rk3288_board_late_init(void)
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000030{
31 u8 ethaddr[6];
32
33 if (get_ethaddr_from_eeprom(ethaddr))
34 return 0;
35
36 if (is_valid_ethaddr(ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -060037 eth_env_set_enetaddr("ethaddr", ethaddr);
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000038
39 return 0;
40}
Michael Trimarchi59b01eb2019-11-15 22:07:24 +010041
42int 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}