1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2022 Marek Vasut <marex@denx.de>
7 #include <asm/arch/clock.h>
8 #include <asm/arch/sys_proto.h>
10 #include <asm/mach-imx/boot_mode.h>
12 #include <dm/device-internal.h>
13 #include <i2c_eeprom.h>
18 #include "lpddr4_timing.h"
20 DECLARE_GLOBAL_DATA_PTR;
22 int mach_cpu_init(void)
28 int board_phys_sdram_size(phys_size_t *size)
30 u8 memcfg = dmo_get_memcfg();
32 *size = (4ULL >> ((memcfg >> 1) & 0x3)) * SZ_1G;
37 /* IMX8M SNVS registers needed for the bootcount functionality */
38 #define SNVS_BASE_ADDR 0x30370000
39 #define SNVS_LPSR 0x4c
40 #define SNVS_LPLVDR 0x64
41 #define SNVS_LPPGDR_INIT 0x41736166
43 static void setup_snvs(void)
45 /* Enable SNVS clock */
46 clock_enable(CCGR_SNVS, 1);
47 /* Initialize glitch detect */
48 writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
49 /* Clear interrupt status */
50 writel(0xffffffff, SNVS_BASE_ADDR + SNVS_LPSR);
53 static void setup_mac_address(void)
55 unsigned char enetaddr[6];
59 ret = eth_env_get_enetaddr("ethaddr", enetaddr);
60 if (ret) /* ethaddr is already set */
63 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
65 printf("%s: No eeprom0 path offset\n", __func__);
69 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
71 printf("Cannot find EEPROM!\n");
75 ret = i2c_eeprom_read(dev, 0xb0, enetaddr, 0x6);
77 printf("Error reading configuration EEPROM!\n");
81 if (is_valid_ethaddr(enetaddr))
82 eth_env_set_enetaddr("ethaddr", enetaddr);
85 static void setup_boot_device(void)
87 int boot_device = get_boot_device();
90 devnum = env_get("devnum");
91 if (devnum) /* devnum is already set */
94 if (boot_device == MMC3_BOOT) /* eMMC */
95 env_set_ulong("devnum", 0);
97 env_set_ulong("devnum", 1);
106 int board_late_init(void)
114 ret = uclass_get_device_by_name(UCLASS_MISC, "usb-hub@2c", &dev);
116 printf("Error bringing up USB hub (%d)\n", ret);