2021-03-02 22:00:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2021 Gateworks Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <cpu_func.h>
|
|
|
|
#include <hang.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <spl.h>
|
|
|
|
#include <asm/mach-imx/gpio.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/imx8mm_pins.h>
|
2022-02-11 18:48:56 +00:00
|
|
|
#include <asm/arch/imx8mn_pins.h>
|
2022-04-13 18:31:09 +00:00
|
|
|
#include <asm/arch/imx8mp_pins.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/mach-imx/boot_mode.h>
|
|
|
|
#include <asm/arch/ddr.h>
|
|
|
|
#include <asm-generic/gpio.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <dm/device.h>
|
2022-04-13 15:56:40 +00:00
|
|
|
#include <linux/delay.h>
|
2021-06-30 23:50:02 +00:00
|
|
|
#include <power/bd71837.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
#include <power/mp5416.h>
|
2022-04-13 18:31:09 +00:00
|
|
|
#include <power/pca9450.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
|
2022-04-13 15:56:40 +00:00
|
|
|
#include "eeprom.h"
|
2021-03-02 22:00:21 +00:00
|
|
|
#include "lpddr4_timing.h"
|
|
|
|
|
|
|
|
#define PCIE_RSTN IMX_GPIO_NR(4, 6)
|
|
|
|
|
|
|
|
static void spl_dram_init(int size)
|
|
|
|
{
|
|
|
|
struct dram_timing_info *dram_timing;
|
|
|
|
|
|
|
|
switch (size) {
|
2022-02-11 18:48:56 +00:00
|
|
|
#ifdef CONFIG_IMX8MM
|
2022-02-18 23:19:33 +00:00
|
|
|
case 512:
|
|
|
|
dram_timing = &dram_timing_512mb;
|
|
|
|
break;
|
|
|
|
case 1024:
|
2021-03-02 22:00:21 +00:00
|
|
|
dram_timing = &dram_timing_1gb;
|
|
|
|
break;
|
2022-02-18 23:19:33 +00:00
|
|
|
case 2048:
|
2021-07-27 22:19:41 +00:00
|
|
|
dram_timing = &dram_timing_2gb;
|
|
|
|
break;
|
2022-02-18 23:19:33 +00:00
|
|
|
case 4096:
|
2021-03-02 22:00:21 +00:00
|
|
|
dram_timing = &dram_timing_4gb;
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-18 23:19:33 +00:00
|
|
|
printf("Unknown DDR configuration: %d MiB\n", size);
|
2021-03-02 22:00:21 +00:00
|
|
|
dram_timing = &dram_timing_1gb;
|
2022-02-18 23:19:33 +00:00
|
|
|
size = 1024;
|
2022-04-13 18:31:09 +00:00
|
|
|
#elif CONFIG_IMX8MN
|
2022-02-18 23:19:33 +00:00
|
|
|
case 1024:
|
2022-02-11 18:48:56 +00:00
|
|
|
dram_timing = &dram_timing_1gb_single_die;
|
|
|
|
break;
|
2022-02-18 23:19:33 +00:00
|
|
|
case 2048:
|
2022-04-13 15:56:40 +00:00
|
|
|
if (!strcmp(eeprom_get_model(), "GW7902-SP466-A") ||
|
|
|
|
!strcmp(eeprom_get_model(), "GW7902-SP466-B")) {
|
2022-02-11 18:48:56 +00:00
|
|
|
dram_timing = &dram_timing_2gb_dual_die;
|
|
|
|
} else {
|
|
|
|
dram_timing = &dram_timing_2gb_single_die;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-18 23:19:33 +00:00
|
|
|
printf("Unknown DDR configuration: %d MiB\n", size);
|
2022-02-11 18:48:56 +00:00
|
|
|
dram_timing = &dram_timing_2gb_dual_die;
|
2022-02-18 23:19:33 +00:00
|
|
|
size = 2048;
|
2022-04-13 18:31:09 +00:00
|
|
|
#elif CONFIG_IMX8MP
|
|
|
|
case 4096:
|
|
|
|
dram_timing = &dram_timing_4gb_dual_die;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Unknown DDR configuration: %d GiB\n", size);
|
|
|
|
dram_timing = &dram_timing_4gb_dual_die;
|
|
|
|
size = 4096;
|
2022-02-11 18:48:56 +00:00
|
|
|
#endif
|
2021-03-02 22:00:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 23:19:33 +00:00
|
|
|
printf("DRAM : LPDDR4 ");
|
|
|
|
if (size > 512)
|
|
|
|
printf("%d GiB\n", size / 1024);
|
|
|
|
else
|
|
|
|
printf("%d MiB\n", size);
|
2021-03-02 22:00:21 +00:00
|
|
|
ddr_init(dram_timing);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Model specific PMIC adjustments necessary prior to DRAM init
|
|
|
|
*
|
|
|
|
* Note that we can not use pmic dm drivers here as we have a generic
|
|
|
|
* venice dt that does not have board-specific pmic's defined.
|
|
|
|
*
|
2021-06-30 23:50:02 +00:00
|
|
|
* Instead we must use dm_i2c so we a helpers to give us
|
|
|
|
* clrsetbit functions we would otherwise have if we could use PMIC dm
|
|
|
|
* drivers.
|
2021-03-02 22:00:21 +00:00
|
|
|
*/
|
2021-06-30 23:50:02 +00:00
|
|
|
static int dm_i2c_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
ret = dm_i2c_read(dev, reg, &val, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
val = (val & ~clr) | set;
|
|
|
|
|
|
|
|
return dm_i2c_write(dev, reg, &val, 1);
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
static int power_init_board(void)
|
|
|
|
{
|
2022-04-13 15:56:40 +00:00
|
|
|
const char *model = eeprom_get_model();
|
2021-03-02 22:00:21 +00:00
|
|
|
struct udevice *bus;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((!strncmp(model, "GW71", 4)) ||
|
|
|
|
(!strncmp(model, "GW72", 4)) ||
|
|
|
|
(!strncmp(model, "GW73", 4))) {
|
2021-07-27 22:19:38 +00:00
|
|
|
ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
|
2021-03-02 22:00:21 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed I2C1 probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = dm_i2c_probe(bus, 0x69, 0, &dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
puts("PMIC : MP5416\n");
|
|
|
|
|
|
|
|
/* set VDD_ARM SW3 to 0.92V for 1.6GHz */
|
|
|
|
dm_i2c_reg_write(dev, MP5416_VSET_SW3,
|
|
|
|
BIT(7) | MP5416_VSET_SW3_SVAL(920000));
|
|
|
|
}
|
|
|
|
|
2022-04-13 18:31:09 +00:00
|
|
|
else if (!strncmp(model, "GW74", 4)) {
|
|
|
|
ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
|
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed I2C1 probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = dm_i2c_probe(bus, 0x25, 0, &dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
puts("PMIC : PCA9450\n");
|
|
|
|
|
|
|
|
/* BUCKxOUT_DVS0/1 control BUCK123 output */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
|
|
|
|
|
|
|
|
/* Buck 1 DVS control through PMIC_STBY_REQ */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
|
|
|
|
|
|
|
|
/* Set DVS1 to 0.8v for suspend */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
|
|
|
|
|
|
|
|
/* increase VDD_DRAM to 0.95v for 3Ghz DDR */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
|
|
|
|
|
|
|
|
/* VDD_DRAM off in suspend: B1_ENMODE=10 */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
|
|
|
|
|
|
|
|
/* set VDD_SNVS_0V8 from default 0.85V */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
|
|
|
|
|
|
|
|
/* set WDOG_B_CFG to cold reset */
|
|
|
|
dm_i2c_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
|
|
|
|
}
|
|
|
|
|
2021-07-27 22:19:41 +00:00
|
|
|
else if ((!strncmp(model, "GW7901", 6)) ||
|
|
|
|
(!strncmp(model, "GW7902", 6))) {
|
|
|
|
if (!strncmp(model, "GW7901", 6))
|
|
|
|
ret = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
|
|
|
|
else
|
|
|
|
ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
|
2021-06-30 23:50:02 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed I2C2 probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = dm_i2c_probe(bus, 0x4b, 0, &dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("PMIC : failed probe: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
puts("PMIC : BD71847\n");
|
|
|
|
|
|
|
|
/* unlock the PMIC regs */
|
|
|
|
dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x1);
|
|
|
|
|
|
|
|
/* set switchers to forced PWM mode */
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_BUCK1_CTRL, 0, 0x8);
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_BUCK2_CTRL, 0, 0x8);
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_1ST_NODVS_BUCK_CTRL, 0, 0x8);
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_2ND_NODVS_BUCK_CTRL, 0, 0x8);
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_3RD_NODVS_BUCK_CTRL, 0, 0x8);
|
|
|
|
dm_i2c_clrsetbits(dev, BD718XX_4TH_NODVS_BUCK_CTRL, 0, 0x8);
|
|
|
|
|
|
|
|
/* increase VDD_0P95 (VDD_GPU/VPU/DRAM) to 0.975v for 1.5Ghz DDR */
|
|
|
|
dm_i2c_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
|
|
|
|
|
|
|
|
/* increase VDD_SOC to 0.85v before first DRAM access */
|
|
|
|
dm_i2c_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
|
|
|
|
|
|
|
|
/* increase VDD_ARM to 0.92v for 800 and 1600Mhz */
|
|
|
|
dm_i2c_reg_write(dev, BD718XX_BUCK2_VOLT_RUN, 0x16);
|
|
|
|
|
|
|
|
/* Lock the PMIC regs */
|
|
|
|
dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x11);
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void board_init_f(ulong dummy)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
int dram_sz;
|
|
|
|
|
|
|
|
arch_cpu_init();
|
|
|
|
|
|
|
|
init_uart_clk(1);
|
|
|
|
|
|
|
|
timer_init();
|
|
|
|
|
|
|
|
/* Clear the BSS. */
|
|
|
|
memset(__bss_start, 0, __bss_end - __bss_start);
|
|
|
|
|
|
|
|
ret = spl_early_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("spl_early_init() failed: %d\n", ret);
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2022-04-29 19:36:25 +00:00
|
|
|
preloader_console_init();
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
enable_tzc380();
|
|
|
|
|
|
|
|
/* need to hold PCIe switch in reset otherwise it can lock i2c bus EEPROM is on */
|
|
|
|
gpio_request(PCIE_RSTN, "perst#");
|
|
|
|
gpio_direction_output(PCIE_RSTN, 0);
|
|
|
|
|
2022-04-13 15:56:40 +00:00
|
|
|
/*
|
|
|
|
* probe GSC device
|
|
|
|
*
|
|
|
|
* On a board with a missing/depleted backup battery for GSC, the
|
|
|
|
* board may be ready to probe the GSC before its firmware is
|
|
|
|
* running. We will wait here indefinately for the GSC EEPROM.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_IMX8MN
|
|
|
|
/*
|
|
|
|
* IMX8MN boots quicker than IMX8MM and exposes issue
|
|
|
|
* where because GSC I2C state machine isn't running and its
|
|
|
|
* SCL/SDA are driven low the I2C driver spams 'Arbitration lost'
|
|
|
|
* I2C errors.
|
|
|
|
*
|
|
|
|
* TODO: Put a loop here that somehow waits for I2C CLK/DAT to be high
|
|
|
|
*/
|
|
|
|
mdelay(50);
|
|
|
|
#endif
|
|
|
|
while (1) {
|
|
|
|
if (!uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(gsc), &dev))
|
|
|
|
break;
|
|
|
|
mdelay(1);
|
|
|
|
}
|
|
|
|
dram_sz = eeprom_init(0);
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
/* PMIC */
|
|
|
|
power_init_board();
|
|
|
|
|
|
|
|
/* DDR initialization */
|
|
|
|
spl_dram_init(dram_sz);
|
|
|
|
|
|
|
|
board_init_r(NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine prioritized order of boot devices to load U-Boot from */
|
|
|
|
void board_boot_order(u32 *spl_boot_list)
|
|
|
|
{
|
2022-04-13 18:31:09 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
/*
|
|
|
|
* If the SPL was loaded via serial loader, we try to get
|
|
|
|
* U-Boot proper via USB SDP.
|
|
|
|
*/
|
2022-04-13 18:31:09 +00:00
|
|
|
if (spl_boot_device() == BOOT_DEVICE_BOARD) {
|
|
|
|
#ifdef CONFIG_IMX8MM
|
|
|
|
spl_boot_list[i++] = BOOT_DEVICE_BOARD;
|
|
|
|
#else
|
|
|
|
spl_boot_list[i++] = BOOT_DEVICE_BOOTROM;
|
|
|
|
#endif
|
|
|
|
}
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
/* we have only eMMC in default venice dt */
|
2022-04-13 18:31:09 +00:00
|
|
|
spl_boot_list[i++] = BOOT_DEVICE_MMC1;
|
2021-03-02 22:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return boot device based on where the SPL was loaded from */
|
|
|
|
int spl_board_boot_device(enum boot_device boot_dev_spl)
|
|
|
|
{
|
|
|
|
switch (boot_dev_spl) {
|
|
|
|
case USB_BOOT:
|
|
|
|
return BOOT_DEVICE_BOARD;
|
|
|
|
/* SDHC2 */
|
|
|
|
case SD2_BOOT:
|
|
|
|
case MMC2_BOOT:
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
/* SDHC3 */
|
|
|
|
case SD3_BOOT:
|
|
|
|
case MMC3_BOOT:
|
|
|
|
return BOOT_DEVICE_MMC2;
|
|
|
|
default:
|
|
|
|
return BOOT_DEVICE_NONE;
|
|
|
|
}
|
|
|
|
}
|
2022-03-08 18:45:39 +00:00
|
|
|
|
|
|
|
const char *spl_board_loader_name(u32 boot_device)
|
|
|
|
{
|
|
|
|
switch (boot_device) {
|
|
|
|
/* SDHC2 */
|
|
|
|
case BOOT_DEVICE_MMC1:
|
|
|
|
return "eMMC";
|
|
|
|
/* SDHC3 */
|
|
|
|
case BOOT_DEVICE_MMC2:
|
|
|
|
return "SD card";
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|