2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-05-05 10:52:26 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net>
|
|
|
|
* (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2007-2011
|
|
|
|
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
|
|
|
|
* Tom Cubie <tangliang@allwinnertech.com>
|
|
|
|
*
|
|
|
|
* Some board init for the Allwinner A10-evb board.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-05-07 07:33:36 +00:00
|
|
|
#include <dm.h>
|
2014-10-02 19:13:54 +00:00
|
|
|
#include <mmc.h>
|
2015-10-03 13:18:33 +00:00
|
|
|
#include <axp_pmic.h>
|
2018-05-07 07:33:36 +00:00
|
|
|
#include <generic-phy.h>
|
|
|
|
#include <phy-sun4i-usb.h>
|
2014-05-05 10:52:26 +00:00
|
|
|
#include <asm/arch/clock.h>
|
2014-06-14 06:59:09 +00:00
|
|
|
#include <asm/arch/cpu.h>
|
2014-08-13 05:55:07 +00:00
|
|
|
#include <asm/arch/display.h>
|
2014-05-05 10:52:26 +00:00
|
|
|
#include <asm/arch/dram.h>
|
2014-05-05 13:42:31 +00:00
|
|
|
#include <asm/arch/gpio.h>
|
|
|
|
#include <asm/arch/mmc.h>
|
2016-07-09 07:56:56 +00:00
|
|
|
#include <asm/arch/spl.h>
|
2016-03-29 15:29:10 +00:00
|
|
|
#ifndef CONFIG_ARM64
|
|
|
|
#include <asm/armv7.h>
|
|
|
|
#endif
|
2015-04-23 21:23:50 +00:00
|
|
|
#include <asm/gpio.h>
|
2014-06-14 06:59:09 +00:00
|
|
|
#include <asm/io.h>
|
2018-11-25 18:22:18 +00:00
|
|
|
#include <u-boot/crc.h>
|
2016-07-09 07:56:56 +00:00
|
|
|
#include <environment.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2015-08-15 09:55:26 +00:00
|
|
|
#include <nand.h>
|
2014-06-14 06:59:09 +00:00
|
|
|
#include <net.h>
|
2017-08-23 08:08:29 +00:00
|
|
|
#include <spl.h>
|
2016-02-23 17:47:19 +00:00
|
|
|
#include <sy8106a.h>
|
2017-05-17 14:23:00 +00:00
|
|
|
#include <asm/setup.h>
|
2014-05-05 10:52:26 +00:00
|
|
|
|
2015-02-16 16:23:25 +00:00
|
|
|
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
|
|
|
|
/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
|
|
|
|
int soft_i2c_gpio_sda;
|
|
|
|
int soft_i2c_gpio_scl;
|
2015-04-23 21:23:50 +00:00
|
|
|
|
|
|
|
static int soft_i2c_board_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
|
|
|
|
if (soft_i2c_gpio_sda < 0) {
|
|
|
|
printf("Error invalid soft i2c sda pin: '%s', err %d\n",
|
|
|
|
CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
|
|
|
|
return soft_i2c_gpio_sda;
|
|
|
|
}
|
|
|
|
ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
|
|
|
|
if (ret) {
|
|
|
|
printf("Error requesting soft i2c sda pin: '%s', err %d\n",
|
|
|
|
CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
|
|
|
|
if (soft_i2c_gpio_scl < 0) {
|
|
|
|
printf("Error invalid soft i2c scl pin: '%s', err %d\n",
|
|
|
|
CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
|
|
|
|
return soft_i2c_gpio_scl;
|
|
|
|
}
|
|
|
|
ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
|
|
|
|
if (ret) {
|
|
|
|
printf("Error requesting soft i2c scl pin: '%s', err %d\n",
|
|
|
|
CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int soft_i2c_board_init(void) { return 0; }
|
2015-02-16 16:23:25 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-04-26 22:03:35 +00:00
|
|
|
void i2c_init_board(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_I2C0_ENABLE
|
|
|
|
#if defined(CONFIG_MACH_SUN4I) || \
|
|
|
|
defined(CONFIG_MACH_SUN5I) || \
|
|
|
|
defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
|
|
|
|
clock_twi_onoff(0, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
|
|
|
|
clock_twi_onoff(0, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN8I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
|
|
|
|
clock_twi_onoff(0, 1);
|
2019-01-08 10:04:30 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN50I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(0), SUN50I_GPH_TWI0);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(1), SUN50I_GPH_TWI0);
|
|
|
|
clock_twi_onoff(0, 1);
|
2017-04-26 22:03:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C1_ENABLE
|
|
|
|
#if defined(CONFIG_MACH_SUN4I) || \
|
|
|
|
defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
|
|
|
|
clock_twi_onoff(1, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN5I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
|
|
|
|
clock_twi_onoff(1, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
|
|
|
|
clock_twi_onoff(1, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN8I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
|
|
|
|
clock_twi_onoff(1, 1);
|
2019-01-08 10:04:30 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN50I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN50I_GPH_TWI1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN50I_GPH_TWI1);
|
|
|
|
clock_twi_onoff(1, 1);
|
2017-04-26 22:03:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C2_ENABLE
|
|
|
|
#if defined(CONFIG_MACH_SUN4I) || \
|
|
|
|
defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
|
|
|
|
clock_twi_onoff(2, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN5I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
|
|
|
|
clock_twi_onoff(2, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
|
|
|
|
clock_twi_onoff(2, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN8I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
|
|
|
|
clock_twi_onoff(2, 1);
|
2019-01-08 10:04:30 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN50I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPE(14), SUN50I_GPE_TWI2);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPE(15), SUN50I_GPE_TWI2);
|
|
|
|
clock_twi_onoff(2, 1);
|
2017-04-26 22:03:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C3_ENABLE
|
|
|
|
#if defined(CONFIG_MACH_SUN6I)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
|
|
|
|
clock_twi_onoff(3, 1);
|
|
|
|
#elif defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
|
|
|
|
clock_twi_onoff(3, 1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C4_ENABLE
|
|
|
|
#if defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
|
|
|
|
clock_twi_onoff(4, 1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_R_I2C_ENABLE
|
2018-11-06 04:24:30 +00:00
|
|
|
#ifdef CONFIG_MACH_SUN50I
|
|
|
|
clock_twi_onoff(5, 1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPL(8), SUN50I_GPL_R_TWI);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPL(9), SUN50I_GPL_R_TWI);
|
|
|
|
#else
|
2017-04-26 22:03:35 +00:00
|
|
|
clock_twi_onoff(5, 1);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI);
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI);
|
|
|
|
#endif
|
2018-11-06 04:24:30 +00:00
|
|
|
#endif
|
2017-04-26 22:03:35 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 20:17:03 +00:00
|
|
|
#if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
|
|
|
|
enum env_location env_get_location(enum env_operation op, int prio)
|
|
|
|
{
|
|
|
|
switch (prio) {
|
|
|
|
case 0:
|
|
|
|
return ENVL_FAT;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return ENVL_MMC;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ENVL_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-29 15:54:14 +00:00
|
|
|
#ifdef CONFIG_DM_MMC
|
|
|
|
static void mmc_pinmux_setup(int sdc);
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
/* add board specific code here */
|
|
|
|
int board_init(void)
|
|
|
|
{
|
2017-04-02 10:59:10 +00:00
|
|
|
__maybe_unused int id_pfr1, ret, satapwr_pin, macpwr_pin;
|
2014-05-05 10:52:26 +00:00
|
|
|
|
|
|
|
gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
|
|
|
|
|
2016-03-29 15:29:10 +00:00
|
|
|
#ifndef CONFIG_ARM64
|
2014-05-05 10:52:26 +00:00
|
|
|
asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
|
|
|
|
debug("id_pfr1: 0x%08x\n", id_pfr1);
|
|
|
|
/* Generic Timer Extension available? */
|
2016-03-29 15:29:10 +00:00
|
|
|
if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) {
|
|
|
|
uint32_t freq;
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
debug("Setting CNTFRQ\n");
|
2016-03-29 15:29:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CNTFRQ is a secure register, so we will crash if we try to
|
|
|
|
* write this from the non-secure world (read is OK, though).
|
|
|
|
* In case some bootcode has already set the correct value,
|
|
|
|
* we avoid the risk of writing to it.
|
|
|
|
*/
|
|
|
|
asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq));
|
2017-02-16 01:20:19 +00:00
|
|
|
if (freq != COUNTER_FREQUENCY) {
|
2016-03-29 15:29:10 +00:00
|
|
|
debug("arch timer frequency is %d Hz, should be %d, fixing ...\n",
|
2017-02-16 01:20:19 +00:00
|
|
|
freq, COUNTER_FREQUENCY);
|
2016-03-29 15:29:10 +00:00
|
|
|
#ifdef CONFIG_NON_SECURE
|
|
|
|
printf("arch timer frequency is wrong, but cannot adjust it\n");
|
|
|
|
#else
|
|
|
|
asm volatile("mcr p15, 0, %0, c14, c0, 0"
|
2017-02-16 01:20:19 +00:00
|
|
|
: : "r"(COUNTER_FREQUENCY));
|
2016-03-29 15:29:10 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-05-05 10:52:26 +00:00
|
|
|
}
|
2016-03-29 15:29:10 +00:00
|
|
|
#endif /* !CONFIG_ARM64 */
|
2014-05-05 10:52:26 +00:00
|
|
|
|
2015-04-25 15:25:14 +00:00
|
|
|
ret = axp_gpio_init();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-03-22 19:10:30 +00:00
|
|
|
#ifdef CONFIG_SATAPWR
|
2017-04-02 10:59:09 +00:00
|
|
|
satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
|
|
|
|
gpio_request(satapwr_pin, "satapwr");
|
|
|
|
gpio_direction_output(satapwr_pin, 1);
|
2017-11-10 13:44:20 +00:00
|
|
|
/* Give attached sata device time to power-up to avoid link timeouts */
|
|
|
|
mdelay(500);
|
2016-03-22 19:10:30 +00:00
|
|
|
#endif
|
2016-03-17 12:53:03 +00:00
|
|
|
#ifdef CONFIG_MACPWR
|
2017-04-02 10:59:10 +00:00
|
|
|
macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
|
|
|
|
gpio_request(macpwr_pin, "macpwr");
|
|
|
|
gpio_direction_output(macpwr_pin, 1);
|
2016-03-17 12:53:03 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-26 22:03:36 +00:00
|
|
|
#ifdef CONFIG_DM_I2C
|
|
|
|
/*
|
|
|
|
* Temporary workaround for enabling I2C clocks until proper sunxi DM
|
|
|
|
* clk, reset and pinctrl drivers land.
|
|
|
|
*/
|
|
|
|
i2c_init_board();
|
|
|
|
#endif
|
|
|
|
|
2019-01-29 15:54:14 +00:00
|
|
|
#ifdef CONFIG_DM_MMC
|
|
|
|
/*
|
|
|
|
* Temporary workaround for enabling MMC clocks until a sunxi DM
|
|
|
|
* pinctrl driver lands.
|
|
|
|
*/
|
|
|
|
mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
|
|
|
|
#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
|
|
|
|
mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_DM_MMC */
|
|
|
|
|
2015-04-23 21:23:50 +00:00
|
|
|
/* Uses dm gpio code so do this here and not in i2c_init_board() */
|
|
|
|
return soft_i2c_board_init();
|
2014-05-05 10:52:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 09:23:04 +00:00
|
|
|
/*
|
|
|
|
* On older SoCs the SPL is actually at address zero, so using NULL as
|
|
|
|
* an error value does not work.
|
|
|
|
*/
|
|
|
|
#define INVALID_SPL_HEADER ((void *)~0UL)
|
|
|
|
|
|
|
|
static struct boot_file_head * get_spl_header(uint8_t req_version)
|
|
|
|
{
|
|
|
|
struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
|
|
|
|
uint8_t spl_header_version = spl->spl_signature[3];
|
|
|
|
|
|
|
|
/* Is there really the SPL header (still) there? */
|
|
|
|
if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
|
|
|
|
return INVALID_SPL_HEADER;
|
|
|
|
|
|
|
|
if (spl_header_version < req_version) {
|
|
|
|
printf("sunxi SPL version mismatch: expected %u, got %u\n",
|
|
|
|
req_version, spl_header_version);
|
|
|
|
return INVALID_SPL_HEADER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return spl;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
sunxi: store DRAM size in SPL header
At the moment we rely on the infamous get_ram_size() function to learn
the actual DRAM size in U-Boot proper. This function has two issues:
1) It only works if the DRAM size is a power of two. We start to see
boards which have 3GB of (usable) DRAM, so this does not fit anymore.
2) As U-Boot has no notion of reserved memory so far, it will happily
ride through the DRAM, possibly stepping on secure-only memory. This
could be a region of DRAM reserved for OP-TEE or some other secure
payload, for instance. It will most likely crash in that case.
As the SPL DRAM init routine has very accurate knowledge of the actual
DRAM size, lets propagate this wisdom to U-Boot proper.
We re-purpose a currently reserved word in our SPL header for that.
The SPL itself stores the detected DRAM size there, and bumps the SPL
header version number in that case. U-Boot proper checks for a valid
SPL header and a high enough version number, then uses the DRAM size
from there. If the SPL header field is not sufficient, we fall back to
the old DRAM scanning routine.
Part of the DRAM might be present and probed by SPL, but not accessible
by the CPU. They're restricted in the main U-Boot binary, when accessing
the DRAM size from SPL header.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
2018-10-25 09:23:07 +00:00
|
|
|
struct boot_file_head *spl = get_spl_header(SPL_DRAM_HEADER_VERSION);
|
|
|
|
|
|
|
|
if (spl == INVALID_SPL_HEADER)
|
|
|
|
gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0,
|
|
|
|
PHYS_SDRAM_0_SIZE);
|
|
|
|
else
|
|
|
|
gd->ram_size = (phys_addr_t)spl->dram_size << 20;
|
|
|
|
|
|
|
|
if (gd->ram_size > CONFIG_SUNXI_DRAM_MAX_SIZE)
|
|
|
|
gd->ram_size = CONFIG_SUNXI_DRAM_MAX_SIZE;
|
2014-05-05 10:52:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-15 19:09:23 +00:00
|
|
|
#if defined(CONFIG_NAND_SUNXI)
|
2015-07-23 12:33:01 +00:00
|
|
|
static void nand_pinmux_setup(void)
|
|
|
|
{
|
|
|
|
unsigned int pin;
|
|
|
|
|
2015-08-15 11:17:49 +00:00
|
|
|
for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++)
|
2015-07-23 12:33:01 +00:00
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
|
|
|
|
|
2015-08-15 11:17:49 +00:00
|
|
|
#if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I
|
|
|
|
for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++)
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
|
|
|
|
#endif
|
|
|
|
/* sun4i / sun7i do have a PC23, but it is not used for nand,
|
|
|
|
* only sun7i has a PC24 */
|
|
|
|
#ifdef CONFIG_MACH_SUN7I
|
2015-07-23 12:33:01 +00:00
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND);
|
2015-08-15 11:17:49 +00:00
|
|
|
#endif
|
2015-07-23 12:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nand_clock_setup(void)
|
|
|
|
{
|
|
|
|
struct sunxi_ccm_reg *const ccm =
|
|
|
|
(struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
|
2015-08-15 09:58:03 +00:00
|
|
|
|
2015-07-23 12:33:01 +00:00
|
|
|
setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
|
2018-02-28 19:51:53 +00:00
|
|
|
#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I || \
|
|
|
|
defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I
|
|
|
|
setbits_le32(&ccm->ahb_reset0_cfg, (1 << AHB_GATE_OFFSET_NAND0));
|
2015-08-15 09:58:03 +00:00
|
|
|
#endif
|
2015-07-23 12:33:01 +00:00
|
|
|
setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
|
|
|
|
}
|
2015-08-15 09:55:26 +00:00
|
|
|
|
|
|
|
void board_nand_init(void)
|
|
|
|
{
|
|
|
|
nand_pinmux_setup();
|
|
|
|
nand_clock_setup();
|
2016-06-15 19:09:23 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
sunxi_nand_init();
|
|
|
|
#endif
|
2015-08-15 09:55:26 +00:00
|
|
|
}
|
2015-07-23 12:33:01 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-09 11:31:39 +00:00
|
|
|
#ifdef CONFIG_MMC
|
2014-05-05 13:42:31 +00:00
|
|
|
static void mmc_pinmux_setup(int sdc)
|
|
|
|
{
|
|
|
|
unsigned int pin;
|
2015-03-22 17:12:23 +00:00
|
|
|
__maybe_unused int pins;
|
2014-05-05 13:42:31 +00:00
|
|
|
|
|
|
|
switch (sdc) {
|
|
|
|
case 0:
|
2015-03-22 17:12:23 +00:00
|
|
|
/* SDC0: PF0-PF5 */
|
2014-05-05 13:42:31 +00:00
|
|
|
for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
|
2015-03-22 17:12:22 +00:00
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
|
2014-05-05 13:42:31 +00:00
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2015-03-22 17:12:23 +00:00
|
|
|
pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
|
|
|
|
|
2016-11-30 08:28:34 +00:00
|
|
|
#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
2015-03-22 17:12:23 +00:00
|
|
|
if (pins == SUNXI_GPIO_H) {
|
|
|
|
/* SDC1: PH22-PH-27 */
|
|
|
|
for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* SDC1: PG0-PG5 */
|
|
|
|
for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_MACH_SUN5I)
|
|
|
|
/* SDC1: PG3-PG8 */
|
2014-10-03 14:44:57 +00:00
|
|
|
for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
|
2015-03-22 17:12:22 +00:00
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
|
2014-05-05 13:42:31 +00:00
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
2015-03-22 17:12:23 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
/* SDC1: PG0-PG5 */
|
|
|
|
for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_MACH_SUN8I)
|
|
|
|
if (pins == SUNXI_GPIO_D) {
|
|
|
|
/* SDC1: PD2-PD7 */
|
|
|
|
for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* SDC1: PG0-PG5 */
|
|
|
|
for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-05-05 13:42:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2015-03-22 17:12:23 +00:00
|
|
|
pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
|
|
|
|
|
|
|
|
#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
|
|
|
|
/* SDC2: PC6-PC11 */
|
2014-05-05 13:42:31 +00:00
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
|
2015-03-22 17:12:22 +00:00
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
2014-05-05 13:42:31 +00:00
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
2015-03-22 17:12:23 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN5I)
|
|
|
|
if (pins == SUNXI_GPIO_E) {
|
|
|
|
/* SDC2: PE4-PE9 */
|
|
|
|
for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* SDC2: PC6-PC15 */
|
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
if (pins == SUNXI_GPIO_A) {
|
|
|
|
/* SDC2: PA9-PA14 */
|
|
|
|
for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* SDC2: PC6-PC15, PC24 */
|
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
|
|
|
|
}
|
2016-11-30 08:28:34 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN8I_R40)
|
|
|
|
/* SDC2: PC6-PC15, PC24 */
|
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
|
2016-03-29 15:29:10 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I)
|
2015-03-22 17:12:23 +00:00
|
|
|
/* SDC2: PC5-PC6, PC8-PC16 */
|
|
|
|
for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
2018-07-21 08:20:29 +00:00
|
|
|
}
|
|
|
|
#elif defined(CONFIG_MACH_SUN50I_H6)
|
|
|
|
/* SDC2: PC4-PC14 */
|
|
|
|
for (pin = SUNXI_GPC(4); pin <= SUNXI_GPC(14); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
2015-03-22 17:12:23 +00:00
|
|
|
}
|
2016-10-28 10:21:33 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN9I)
|
|
|
|
/* SDC2: PC6-PC16 */
|
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
2015-03-22 17:12:23 +00:00
|
|
|
#endif
|
2014-05-05 13:42:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2015-03-22 17:12:23 +00:00
|
|
|
pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
|
|
|
|
|
2016-11-30 08:28:34 +00:00
|
|
|
#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
|
|
|
|
defined(CONFIG_MACH_SUN8I_R40)
|
2015-03-22 17:12:23 +00:00
|
|
|
/* SDC3: PI4-PI9 */
|
2014-05-05 13:42:31 +00:00
|
|
|
for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
|
2015-03-22 17:12:23 +00:00
|
|
|
sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
|
2014-05-05 13:42:31 +00:00
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
2015-03-22 17:12:23 +00:00
|
|
|
#elif defined(CONFIG_MACH_SUN6I)
|
|
|
|
if (pins == SUNXI_GPIO_A) {
|
|
|
|
/* SDC3: PA9-PA14 */
|
|
|
|
for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* SDC3: PC6-PC15, PC24 */
|
|
|
|
for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
|
|
|
|
sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
|
|
|
|
sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(pin, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
|
|
|
|
sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
|
|
|
|
sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
|
|
|
|
}
|
|
|
|
#endif
|
2014-05-05 13:42:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_mmc_init(bd_t *bis)
|
|
|
|
{
|
2014-10-02 19:13:54 +00:00
|
|
|
__maybe_unused struct mmc *mmc0, *mmc1;
|
|
|
|
|
2014-05-05 13:42:31 +00:00
|
|
|
mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
|
2014-10-02 19:13:54 +00:00
|
|
|
mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
|
|
|
|
if (!mmc0)
|
|
|
|
return -1;
|
|
|
|
|
2014-10-02 18:43:50 +00:00
|
|
|
#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
|
2014-05-05 13:42:31 +00:00
|
|
|
mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
|
2014-10-02 19:13:54 +00:00
|
|
|
mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
|
|
|
|
if (!mmc1)
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 13:42:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
sunxi: store DRAM size in SPL header
At the moment we rely on the infamous get_ram_size() function to learn
the actual DRAM size in U-Boot proper. This function has two issues:
1) It only works if the DRAM size is a power of two. We start to see
boards which have 3GB of (usable) DRAM, so this does not fit anymore.
2) As U-Boot has no notion of reserved memory so far, it will happily
ride through the DRAM, possibly stepping on secure-only memory. This
could be a region of DRAM reserved for OP-TEE or some other secure
payload, for instance. It will most likely crash in that case.
As the SPL DRAM init routine has very accurate knowledge of the actual
DRAM size, lets propagate this wisdom to U-Boot proper.
We re-purpose a currently reserved word in our SPL header for that.
The SPL itself stores the detected DRAM size there, and bumps the SPL
header version number in that case. U-Boot proper checks for a valid
SPL header and a high enough version number, then uses the DRAM size
from there. If the SPL header field is not sufficient, we fall back to
the old DRAM scanning routine.
Part of the DRAM might be present and probed by SPL, but not accessible
by the CPU. They're restricted in the main U-Boot binary, when accessing
the DRAM size from SPL header.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
2018-10-25 09:23:07 +00:00
|
|
|
|
|
|
|
static void sunxi_spl_store_dram_size(phys_addr_t dram_size)
|
|
|
|
{
|
|
|
|
struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
|
|
|
|
|
|
|
|
if (spl == INVALID_SPL_HEADER)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Promote the header version for U-Boot proper, if needed. */
|
|
|
|
if (spl->spl_signature[3] < SPL_DRAM_HEADER_VERSION)
|
|
|
|
spl->spl_signature[3] = SPL_DRAM_HEADER_VERSION;
|
|
|
|
|
|
|
|
spl->dram_size = dram_size >> 20;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:52:26 +00:00
|
|
|
void sunxi_board_init(void)
|
|
|
|
{
|
2014-06-13 20:55:50 +00:00
|
|
|
int power_failed = 0;
|
2014-05-05 10:52:26 +00:00
|
|
|
|
2016-02-23 17:47:19 +00:00
|
|
|
#ifdef CONFIG_SY8106A_POWER
|
|
|
|
power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
|
|
|
|
#endif
|
|
|
|
|
2015-11-28 17:07:22 +00:00
|
|
|
#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
|
2016-05-02 02:28:15 +00:00
|
|
|
defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
|
|
|
|
defined CONFIG_AXP818_POWER
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed = axp_init();
|
|
|
|
|
2016-05-02 02:28:15 +00:00
|
|
|
#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
|
|
|
|
defined CONFIG_AXP818_POWER
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
|
2014-06-13 20:55:51 +00:00
|
|
|
#endif
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT);
|
|
|
|
power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT);
|
2015-11-28 17:07:22 +00:00
|
|
|
#if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER)
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT);
|
2013-07-26 10:56:58 +00:00
|
|
|
#endif
|
2016-05-02 02:28:15 +00:00
|
|
|
#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
|
|
|
|
defined CONFIG_AXP818_POWER
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT);
|
2014-06-13 20:55:50 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-02 02:28:15 +00:00
|
|
|
#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
|
|
|
|
defined CONFIG_AXP818_POWER
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT);
|
|
|
|
#endif
|
|
|
|
power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT);
|
2016-01-12 06:42:40 +00:00
|
|
|
#if !defined(CONFIG_AXP152_POWER)
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AXP209_POWER
|
|
|
|
power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT);
|
|
|
|
#endif
|
|
|
|
|
2016-05-02 02:28:15 +00:00
|
|
|
#if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \
|
|
|
|
defined(CONFIG_AXP818_POWER)
|
2016-01-12 06:42:37 +00:00
|
|
|
power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
|
|
|
|
power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
|
2016-05-02 02:28:15 +00:00
|
|
|
#if !defined CONFIG_AXP809_POWER
|
2016-01-12 06:42:37 +00:00
|
|
|
power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
|
|
|
|
power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
|
2016-05-02 02:28:15 +00:00
|
|
|
#endif
|
2015-10-03 13:18:33 +00:00
|
|
|
power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
|
|
|
|
power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
|
|
|
|
power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
|
|
|
|
#endif
|
2016-03-29 16:26:48 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_AXP818_POWER
|
|
|
|
power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT);
|
|
|
|
power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT);
|
|
|
|
power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT);
|
2016-05-02 02:28:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
|
2016-05-02 02:28:12 +00:00
|
|
|
power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON));
|
2016-03-29 16:26:48 +00:00
|
|
|
#endif
|
2015-10-03 13:18:33 +00:00
|
|
|
#endif
|
2018-12-19 13:00:39 +00:00
|
|
|
printf("DRAM:");
|
|
|
|
gd->ram_size = sunxi_dram_init();
|
|
|
|
printf(" %d MiB\n", (int)(gd->ram_size >> 20));
|
|
|
|
if (!gd->ram_size)
|
|
|
|
hang();
|
|
|
|
|
|
|
|
sunxi_spl_store_dram_size(gd->ram_size);
|
sunxi: store DRAM size in SPL header
At the moment we rely on the infamous get_ram_size() function to learn
the actual DRAM size in U-Boot proper. This function has two issues:
1) It only works if the DRAM size is a power of two. We start to see
boards which have 3GB of (usable) DRAM, so this does not fit anymore.
2) As U-Boot has no notion of reserved memory so far, it will happily
ride through the DRAM, possibly stepping on secure-only memory. This
could be a region of DRAM reserved for OP-TEE or some other secure
payload, for instance. It will most likely crash in that case.
As the SPL DRAM init routine has very accurate knowledge of the actual
DRAM size, lets propagate this wisdom to U-Boot proper.
We re-purpose a currently reserved word in our SPL header for that.
The SPL itself stores the detected DRAM size there, and bumps the SPL
header version number in that case. U-Boot proper checks for a valid
SPL header and a high enough version number, then uses the DRAM size
from there. If the SPL header field is not sufficient, we fall back to
the old DRAM scanning routine.
Part of the DRAM might be present and probed by SPL, but not accessible
by the CPU. They're restricted in the main U-Boot binary, when accessing
the DRAM size from SPL header.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
2018-10-25 09:23:07 +00:00
|
|
|
|
2014-06-13 20:55:50 +00:00
|
|
|
/*
|
|
|
|
* Only clock up the CPU to full speed if we are reasonably
|
|
|
|
* assured it's being powered with suitable core voltage
|
|
|
|
*/
|
|
|
|
if (!power_failed)
|
2015-03-28 10:26:38 +00:00
|
|
|
clock_set_pll1(CONFIG_SYS_CLK_FREQ);
|
2014-06-13 20:55:50 +00:00
|
|
|
else
|
2018-12-19 13:00:39 +00:00
|
|
|
printf("Failed to set core voltage! Can't set CPU frequency\n");
|
2014-05-05 10:52:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-06-14 06:59:09 +00:00
|
|
|
|
2015-03-22 17:07:13 +00:00
|
|
|
#ifdef CONFIG_USB_GADGET
|
|
|
|
int g_dnl_board_usb_cable_connected(void)
|
|
|
|
{
|
2018-05-07 07:33:36 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
struct phy phy;
|
|
|
|
int ret;
|
|
|
|
|
2018-11-29 09:52:46 +00:00
|
|
|
ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, 0, &dev);
|
2018-05-07 07:33:36 +00:00
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: Cannot find USB device\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = generic_phy_get_by_name(dev, "usb", &phy);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("failed to get %s USB PHY\n", dev->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = generic_phy_init(&phy);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("failed to init %s USB PHY\n", dev->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sun4i_usb_phy_vbus_detect(&phy);
|
|
|
|
if (ret == 1) {
|
|
|
|
pr_err("A charger is plugged into the OTG\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-03-22 17:07:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-28 17:35:36 +00:00
|
|
|
#ifdef CONFIG_SERIAL_TAG
|
|
|
|
void get_board_serial(struct tag_serialnr *serialnr)
|
|
|
|
{
|
|
|
|
char *serial_string;
|
|
|
|
unsigned long long serial;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
serial_string = env_get("serial#");
|
2015-03-28 17:35:36 +00:00
|
|
|
|
|
|
|
if (serial_string) {
|
|
|
|
serial = simple_strtoull(serial_string, NULL, 16);
|
|
|
|
|
|
|
|
serialnr->high = (unsigned int) (serial >> 32);
|
|
|
|
serialnr->low = (unsigned int) (serial & 0xffffffff);
|
|
|
|
} else {
|
|
|
|
serialnr->high = 0;
|
|
|
|
serialnr->low = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-17 16:52:52 +00:00
|
|
|
/*
|
|
|
|
* Check the SPL header for the "sunxi" variant. If found: parse values
|
|
|
|
* that might have been passed by the loader ("fel" utility), and update
|
|
|
|
* the environment accordingly.
|
|
|
|
*/
|
|
|
|
static void parse_spl_header(const uint32_t spl_addr)
|
|
|
|
{
|
2018-10-25 09:23:04 +00:00
|
|
|
struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
|
2016-06-09 05:37:35 +00:00
|
|
|
|
2018-10-25 09:23:04 +00:00
|
|
|
if (spl == INVALID_SPL_HEADER)
|
2016-06-09 05:37:35 +00:00
|
|
|
return;
|
2018-10-25 09:23:04 +00:00
|
|
|
|
2016-06-09 05:37:35 +00:00
|
|
|
if (!spl->fel_script_address)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (spl->fel_uEnv_length != 0) {
|
|
|
|
/*
|
|
|
|
* data is expected in uEnv.txt compatible format, so "env
|
|
|
|
* import -t" the string(s) at fel_script_address right away.
|
|
|
|
*/
|
2016-09-05 00:32:41 +00:00
|
|
|
himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address,
|
2016-06-09 05:37:35 +00:00
|
|
|
spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
|
|
|
|
return;
|
2015-09-17 16:52:52 +00:00
|
|
|
}
|
2016-06-09 05:37:35 +00:00
|
|
|
/* otherwise assume .scr format (mkimage-type script) */
|
2017-08-03 18:22:10 +00:00
|
|
|
env_set_hex("fel_scriptaddr", spl->fel_script_address);
|
2015-09-17 16:52:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 11:34:42 +00:00
|
|
|
/*
|
|
|
|
* Note this function gets called multiple times.
|
|
|
|
* It must not make any changes to env variables which already exist.
|
|
|
|
*/
|
|
|
|
static void setup_environment(const void *fdt)
|
2014-06-14 06:59:09 +00:00
|
|
|
{
|
2015-03-28 17:35:35 +00:00
|
|
|
char serial_string[17] = { 0 };
|
2014-11-25 23:04:24 +00:00
|
|
|
unsigned int sid[4];
|
2015-03-28 17:35:35 +00:00
|
|
|
uint8_t mac_addr[6];
|
2016-06-26 11:34:42 +00:00
|
|
|
char ethaddr[16];
|
|
|
|
int i, ret;
|
2015-09-17 16:52:52 +00:00
|
|
|
|
2015-03-28 17:35:35 +00:00
|
|
|
ret = sunxi_get_sid(sid);
|
2016-07-29 09:47:03 +00:00
|
|
|
if (ret == 0 && sid[0] != 0) {
|
|
|
|
/*
|
|
|
|
* The single words 1 - 3 of the SID have quite a few bits
|
|
|
|
* which are the same on many models, so we take a crc32
|
|
|
|
* of all 3 words, to get a more unique value.
|
|
|
|
*
|
|
|
|
* Note we only do this on newer SoCs as we cannot change
|
|
|
|
* the algorithm on older SoCs since those have been using
|
|
|
|
* fixed mac-addresses based on only using word 3 for a
|
|
|
|
* long time and changing a fixed mac-address with an
|
|
|
|
* u-boot update is not good.
|
|
|
|
*/
|
|
|
|
#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
|
|
|
|
!defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
|
|
|
|
!defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
|
|
|
|
sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
|
|
|
|
#endif
|
|
|
|
|
2016-07-27 15:58:06 +00:00
|
|
|
/* Ensure the NIC specific bytes of the mac are not all 0 */
|
|
|
|
if ((sid[3] & 0xffffff) == 0)
|
|
|
|
sid[3] |= 0x800000;
|
|
|
|
|
2016-06-26 11:34:42 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
sprintf(ethaddr, "ethernet%d", i);
|
|
|
|
if (!fdt_get_alias(fdt, ethaddr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
strcpy(ethaddr, "ethaddr");
|
|
|
|
else
|
|
|
|
sprintf(ethaddr, "eth%daddr", i);
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (env_get(ethaddr))
|
2016-06-26 11:34:42 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-28 17:35:35 +00:00
|
|
|
/* Non OUI / registered MAC address */
|
2016-06-26 11:34:42 +00:00
|
|
|
mac_addr[0] = (i << 4) | 0x02;
|
2015-03-28 17:35:35 +00:00
|
|
|
mac_addr[1] = (sid[0] >> 0) & 0xff;
|
|
|
|
mac_addr[2] = (sid[3] >> 24) & 0xff;
|
|
|
|
mac_addr[3] = (sid[3] >> 16) & 0xff;
|
|
|
|
mac_addr[4] = (sid[3] >> 8) & 0xff;
|
|
|
|
mac_addr[5] = (sid[3] >> 0) & 0xff;
|
|
|
|
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr(ethaddr, mac_addr);
|
2015-03-28 17:35:35 +00:00
|
|
|
}
|
2014-06-14 06:59:09 +00:00
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("serial#")) {
|
2015-03-28 17:35:35 +00:00
|
|
|
snprintf(serial_string, sizeof(serial_string),
|
|
|
|
"%08x%08x", sid[0], sid[3]);
|
2014-06-14 06:59:09 +00:00
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("serial#", serial_string);
|
2015-03-28 17:35:35 +00:00
|
|
|
}
|
2014-06-14 06:59:09 +00:00
|
|
|
}
|
2016-06-26 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
2017-08-23 08:08:29 +00:00
|
|
|
uint boot;
|
2016-06-26 11:34:42 +00:00
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fel_booted", NULL);
|
|
|
|
env_set("fel_scriptaddr", NULL);
|
sunxi: Remove the MMC index hack
The current code, if there's both an eMMC and an MMC slot available on the
board, will swap the MMC indices based on whether we booted from the eMMC
or the MMC. This way, the MMC we're supposed to boot on will always have
the index 0.
However, this causes various issues, for example when using other
components that base their behaviour on the MMC index, such as fastboot.
Let's remove that hack, and take the opposite approach. The MMC will always
have the same index, but the bootcmd will pick the same device than the one
we booted from. This is done through the introduction of the mmc_bootdev
environment variable that will be filled by the board code based on the
boot device informations we can get from the SoC.
In order to not introduce regressions, we also need to adjust the fastboot
MMC device and the environment device in order to set it to the eMMC, over
the MMC, like it used to be the case.
Tested-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-08-23 08:12:22 +00:00
|
|
|
env_set("mmc_bootdev", NULL);
|
2017-08-23 08:08:29 +00:00
|
|
|
|
|
|
|
boot = sunxi_get_boot_device();
|
2016-06-26 11:34:42 +00:00
|
|
|
/* determine if we are running in FEL mode */
|
2017-08-23 08:08:29 +00:00
|
|
|
if (boot == BOOT_DEVICE_BOARD) {
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("fel_booted", "1");
|
2016-06-26 11:34:42 +00:00
|
|
|
parse_spl_header(SPL_ADDR);
|
sunxi: Remove the MMC index hack
The current code, if there's both an eMMC and an MMC slot available on the
board, will swap the MMC indices based on whether we booted from the eMMC
or the MMC. This way, the MMC we're supposed to boot on will always have
the index 0.
However, this causes various issues, for example when using other
components that base their behaviour on the MMC index, such as fastboot.
Let's remove that hack, and take the opposite approach. The MMC will always
have the same index, but the bootcmd will pick the same device than the one
we booted from. This is done through the introduction of the mmc_bootdev
environment variable that will be filled by the board code based on the
boot device informations we can get from the SoC.
In order to not introduce regressions, we also need to adjust the fastboot
MMC device and the environment device in order to set it to the eMMC, over
the MMC, like it used to be the case.
Tested-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-08-23 08:12:22 +00:00
|
|
|
/* or if we booted from MMC, and which one */
|
|
|
|
} else if (boot == BOOT_DEVICE_MMC1) {
|
|
|
|
env_set("mmc_bootdev", "0");
|
|
|
|
} else if (boot == BOOT_DEVICE_MMC2) {
|
|
|
|
env_set("mmc_bootdev", "1");
|
2016-06-26 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_environment(gd->fdt_blob);
|
2014-06-14 06:59:09 +00:00
|
|
|
|
2017-09-28 14:16:38 +00:00
|
|
|
#ifdef CONFIG_USB_ETHER
|
2017-09-06 20:25:03 +00:00
|
|
|
usb_ether_init();
|
2017-09-28 14:16:38 +00:00
|
|
|
#endif
|
2017-09-06 20:25:03 +00:00
|
|
|
|
2014-06-14 06:59:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-08-13 05:55:07 +00:00
|
|
|
|
|
|
|
int ft_board_setup(void *blob, bd_t *bd)
|
|
|
|
{
|
2016-03-22 21:51:52 +00:00
|
|
|
int __maybe_unused r;
|
|
|
|
|
2016-06-26 11:34:42 +00:00
|
|
|
/*
|
|
|
|
* Call setup_environment again in case the boot fdt has
|
|
|
|
* ethernet aliases the u-boot copy does not have.
|
|
|
|
*/
|
|
|
|
setup_environment(blob);
|
|
|
|
|
2014-08-13 05:55:07 +00:00
|
|
|
#ifdef CONFIG_VIDEO_DT_SIMPLEFB
|
2016-03-22 21:51:52 +00:00
|
|
|
r = sunxi_simplefb_setup(blob);
|
|
|
|
if (r)
|
|
|
|
return r;
|
2014-08-13 05:55:07 +00:00
|
|
|
#endif
|
2016-03-22 21:51:52 +00:00
|
|
|
return 0;
|
2014-08-13 05:55:07 +00:00
|
|
|
}
|
2017-04-26 00:32:44 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_LOAD_FIT
|
|
|
|
int board_fit_config_name_match(const char *name)
|
|
|
|
{
|
2018-10-25 09:23:04 +00:00
|
|
|
struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
|
|
|
|
const char *cmp_str = (const char *)spl;
|
2017-04-26 00:32:44 +00:00
|
|
|
|
2017-04-26 00:32:50 +00:00
|
|
|
/* Check if there is a DT name stored in the SPL header and use that. */
|
2018-10-25 09:23:04 +00:00
|
|
|
if (spl != INVALID_SPL_HEADER && spl->dt_name_offset) {
|
2017-04-26 00:32:50 +00:00
|
|
|
cmp_str += spl->dt_name_offset;
|
|
|
|
} else {
|
2017-04-26 00:32:44 +00:00
|
|
|
#ifdef CONFIG_DEFAULT_DEVICE_TREE
|
2017-04-26 00:32:50 +00:00
|
|
|
cmp_str = CONFIG_DEFAULT_DEVICE_TREE;
|
2017-04-26 00:32:44 +00:00
|
|
|
#else
|
2017-04-26 00:32:50 +00:00
|
|
|
return 0;
|
2017-04-26 00:32:44 +00:00
|
|
|
#endif
|
2017-04-26 00:32:50 +00:00
|
|
|
};
|
2017-04-26 00:32:44 +00:00
|
|
|
|
2018-10-25 09:23:02 +00:00
|
|
|
#ifdef CONFIG_PINE64_DT_SELECTION
|
2017-04-26 00:32:44 +00:00
|
|
|
/* Differentiate the two Pine64 board DTs by their DRAM size. */
|
|
|
|
if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) {
|
|
|
|
if ((gd->ram_size > 512 * 1024 * 1024))
|
|
|
|
return !strstr(name, "plus");
|
|
|
|
else
|
|
|
|
return !!strstr(name, "plus");
|
|
|
|
} else {
|
|
|
|
return strcmp(name, cmp_str);
|
|
|
|
}
|
2018-10-25 09:23:02 +00:00
|
|
|
#endif
|
|
|
|
return strcmp(name, cmp_str);
|
2017-04-26 00:32:44 +00:00
|
|
|
}
|
|
|
|
#endif
|