2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-06-09 17:28:45 +00:00
|
|
|
/*
|
2022-06-01 15:17:06 +00:00
|
|
|
* Copyright (C) 2017 Marek Behún <kabel@kernel.org>
|
2017-06-09 17:28:45 +00:00
|
|
|
* Copyright (C) 2016 Tomas Hlavacek <tomas.hlavacek@nic.cz>
|
|
|
|
*
|
|
|
|
* Derived from the code for
|
|
|
|
* Marvell/db-88f6820-gp by Stefan Roese <sr@denx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:47 +00:00
|
|
|
#include <env.h>
|
2017-06-09 17:28:45 +00:00
|
|
|
#include <i2c.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-06-09 17:28:45 +00:00
|
|
|
#include <miiphy.h>
|
2021-07-15 17:21:02 +00:00
|
|
|
#include <mtd.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2017-06-09 17:28:45 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
|
|
|
#include <asm/arch/soc.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <fdt_support.h>
|
|
|
|
#include <time.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2017-06-09 17:28:45 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
|
2017-06-09 17:28:45 +00:00
|
|
|
#include <../serdes/a38x/high_speed_env_spec.h>
|
2022-04-08 14:30:12 +00:00
|
|
|
#include "../turris_atsha_otp.h"
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2021-07-15 17:21:02 +00:00
|
|
|
#define OMNIA_SPI_NOR_PATH "/soc/spi@10600/spi-nor@0"
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
#define OMNIA_I2C_BUS_NAME "i2c@11000->i2cmux@70->i2c@0"
|
|
|
|
|
|
|
|
#define OMNIA_I2C_MCU_CHIP_ADDR 0x2a
|
|
|
|
#define OMNIA_I2C_MCU_CHIP_LEN 1
|
|
|
|
|
|
|
|
#define OMNIA_I2C_EEPROM_CHIP_ADDR 0x54
|
|
|
|
#define OMNIA_I2C_EEPROM_CHIP_LEN 2
|
2017-06-09 17:28:45 +00:00
|
|
|
#define OMNIA_I2C_EEPROM_MAGIC 0x0341a034
|
|
|
|
|
2022-04-29 11:53:25 +00:00
|
|
|
#define A385_SYS_RSTOUT_MASK MVEBU_REGISTER(0x18260)
|
|
|
|
#define A385_SYS_RSTOUT_MASK_WD BIT(10)
|
2021-11-09 16:14:02 +00:00
|
|
|
|
|
|
|
#define A385_WDT_GLOBAL_CTRL MVEBU_REGISTER(0x20300)
|
|
|
|
#define A385_WDT_GLOBAL_RATIO_MASK GENMASK(18, 16)
|
|
|
|
#define A385_WDT_GLOBAL_RATIO_SHIFT 16
|
|
|
|
#define A385_WDT_GLOBAL_25MHZ BIT(10)
|
|
|
|
#define A385_WDT_GLOBAL_ENABLE BIT(8)
|
|
|
|
|
|
|
|
#define A385_WDT_GLOBAL_STATUS MVEBU_REGISTER(0x20304)
|
|
|
|
#define A385_WDT_GLOBAL_EXPIRED BIT(31)
|
|
|
|
|
|
|
|
#define A385_WDT_DURATION MVEBU_REGISTER(0x20334)
|
|
|
|
|
|
|
|
#define A385_WD_RSTOUT_UNMASK MVEBU_REGISTER(0x20704)
|
|
|
|
#define A385_WD_RSTOUT_UNMASK_GLOBAL BIT(8)
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
enum mcu_commands {
|
|
|
|
CMD_GET_STATUS_WORD = 0x01,
|
|
|
|
CMD_GET_RESET = 0x09,
|
|
|
|
CMD_WATCHDOG_STATE = 0x0b,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum status_word_bits {
|
|
|
|
CARD_DET_STSBIT = 0x0010,
|
|
|
|
MSATA_IND_STSBIT = 0x0020,
|
|
|
|
};
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Those values and defines are taken from the Marvell U-Boot version
|
|
|
|
* "u-boot-2013.01-2014_T3.0"
|
|
|
|
*/
|
|
|
|
#define OMNIA_GPP_OUT_ENA_LOW \
|
|
|
|
(~(BIT(1) | BIT(4) | BIT(6) | BIT(7) | BIT(8) | BIT(9) | \
|
|
|
|
BIT(10) | BIT(11) | BIT(19) | BIT(22) | BIT(23) | BIT(25) | \
|
|
|
|
BIT(26) | BIT(27) | BIT(29) | BIT(30) | BIT(31)))
|
|
|
|
#define OMNIA_GPP_OUT_ENA_MID \
|
|
|
|
(~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(15) | \
|
|
|
|
BIT(16) | BIT(17) | BIT(18)))
|
|
|
|
|
|
|
|
#define OMNIA_GPP_OUT_VAL_LOW 0x0
|
|
|
|
#define OMNIA_GPP_OUT_VAL_MID 0x0
|
|
|
|
#define OMNIA_GPP_POL_LOW 0x0
|
|
|
|
#define OMNIA_GPP_POL_MID 0x0
|
|
|
|
|
2022-03-02 11:47:54 +00:00
|
|
|
static struct serdes_map board_serdes_map[] = {
|
2017-06-09 17:28:45 +00:00
|
|
|
{PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
|
|
|
|
{USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
|
|
|
|
{PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
|
|
|
|
{USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
|
|
|
|
{PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
|
|
|
|
{SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0}
|
|
|
|
};
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
static struct udevice *omnia_get_i2c_chip(const char *name, uint addr,
|
|
|
|
uint offset_len)
|
2017-06-09 17:28:45 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
2019-05-02 14:53:30 +00:00
|
|
|
int ret;
|
2017-06-09 17:28:45 +00:00
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
ret = uclass_get_device_by_name(UCLASS_I2C, OMNIA_I2C_BUS_NAME, &bus);
|
|
|
|
if (ret) {
|
|
|
|
printf("Cannot get I2C bus %s: uclass_get_device_by_name failed: %i\n",
|
|
|
|
OMNIA_I2C_BUS_NAME, ret);
|
|
|
|
return NULL;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
ret = i2c_get_chip(bus, addr, offset_len, &dev);
|
2017-06-09 17:28:45 +00:00
|
|
|
if (ret) {
|
2019-05-02 14:53:30 +00:00
|
|
|
printf("Cannot get %s I2C chip: i2c_get_chip failed: %i\n",
|
|
|
|
name, ret);
|
|
|
|
return NULL;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omnia_mcu_read(u8 cmd, void *buf, int len)
|
|
|
|
{
|
|
|
|
struct udevice *chip;
|
|
|
|
|
|
|
|
chip = omnia_get_i2c_chip("MCU", OMNIA_I2C_MCU_CHIP_ADDR,
|
|
|
|
OMNIA_I2C_MCU_CHIP_LEN);
|
|
|
|
if (!chip)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return dm_i2c_read(chip, cmd, buf, len);
|
|
|
|
}
|
2017-08-04 13:28:25 +00:00
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
static int omnia_mcu_write(u8 cmd, const void *buf, int len)
|
|
|
|
{
|
|
|
|
struct udevice *chip;
|
|
|
|
|
|
|
|
chip = omnia_get_i2c_chip("MCU", OMNIA_I2C_MCU_CHIP_ADDR,
|
|
|
|
OMNIA_I2C_MCU_CHIP_LEN);
|
|
|
|
if (!chip)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return dm_i2c_write(chip, cmd, buf, len);
|
|
|
|
}
|
|
|
|
|
2021-11-09 16:14:02 +00:00
|
|
|
static void enable_a385_watchdog(unsigned int timeout_minutes)
|
|
|
|
{
|
|
|
|
struct sar_freq_modes sar_freq;
|
|
|
|
u32 watchdog_freq;
|
|
|
|
|
|
|
|
printf("Enabling A385 watchdog with %u minutes timeout...\n",
|
|
|
|
timeout_minutes);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use NBCLK clock (a.k.a. L2 clock) as watchdog input clock with
|
|
|
|
* its maximal ratio 7 instead of default fixed 25 MHz clock.
|
|
|
|
* It allows to set watchdog duration up to the 22 minutes.
|
|
|
|
*/
|
|
|
|
clrsetbits_32(A385_WDT_GLOBAL_CTRL,
|
|
|
|
A385_WDT_GLOBAL_25MHZ | A385_WDT_GLOBAL_RATIO_MASK,
|
|
|
|
7 << A385_WDT_GLOBAL_RATIO_SHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate watchdog clock frequency. It is defined by formula:
|
|
|
|
* freq = NBCLK / 2 / (2 ^ ratio)
|
|
|
|
* We set ratio to the maximal possible value 7.
|
|
|
|
*/
|
|
|
|
get_sar_freq(&sar_freq);
|
|
|
|
watchdog_freq = sar_freq.nb_clk * 1000000 / 2 / (1 << 7);
|
|
|
|
|
|
|
|
/* Set watchdog duration */
|
|
|
|
writel(timeout_minutes * 60 * watchdog_freq, A385_WDT_DURATION);
|
|
|
|
|
|
|
|
/* Clear the watchdog expiration bit */
|
|
|
|
clrbits_32(A385_WDT_GLOBAL_STATUS, A385_WDT_GLOBAL_EXPIRED);
|
|
|
|
|
|
|
|
/* Enable watchdog timer */
|
|
|
|
setbits_32(A385_WDT_GLOBAL_CTRL, A385_WDT_GLOBAL_ENABLE);
|
|
|
|
|
|
|
|
/* Enable reset on watchdog */
|
|
|
|
setbits_32(A385_WD_RSTOUT_UNMASK, A385_WD_RSTOUT_UNMASK_GLOBAL);
|
|
|
|
|
|
|
|
/* Unmask reset for watchdog */
|
2022-04-29 11:53:25 +00:00
|
|
|
clrbits_32(A385_SYS_RSTOUT_MASK, A385_SYS_RSTOUT_MASK_WD);
|
2021-11-09 16:14:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
static bool disable_mcu_watchdog(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
puts("Disabling MCU watchdog... ");
|
|
|
|
|
|
|
|
ret = omnia_mcu_write(CMD_WATCHDOG_STATE, "\x00", 1);
|
|
|
|
if (ret) {
|
|
|
|
printf("omnia_mcu_write failed: %i\n", ret);
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
puts("disabled\n");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:55 +00:00
|
|
|
static bool omnia_detect_sata(const char *msata_slot)
|
2019-05-02 14:53:30 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u16 stsword;
|
|
|
|
|
|
|
|
puts("MiniPCIe/mSATA card detection... ");
|
|
|
|
|
2022-03-02 11:47:55 +00:00
|
|
|
if (msata_slot) {
|
|
|
|
if (strcmp(msata_slot, "pcie") == 0) {
|
|
|
|
puts("forced to MiniPCIe via env\n");
|
|
|
|
return false;
|
|
|
|
} else if (strcmp(msata_slot, "sata") == 0) {
|
|
|
|
puts("forced to mSATA via env\n");
|
|
|
|
return true;
|
|
|
|
} else if (strcmp(msata_slot, "auto") != 0) {
|
|
|
|
printf("unsupported env value '%s', fallback to... ", msata_slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &stsword, sizeof(stsword));
|
|
|
|
if (ret) {
|
|
|
|
printf("omnia_mcu_read failed: %i, defaulting to MiniPCIe card\n",
|
|
|
|
ret);
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
if (!(stsword & CARD_DET_STSBIT)) {
|
|
|
|
puts("none\n");
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-02 14:53:30 +00:00
|
|
|
|
|
|
|
if (stsword & MSATA_IND_STSBIT)
|
|
|
|
puts("mSATA\n");
|
|
|
|
else
|
|
|
|
puts("MiniPCIe\n");
|
|
|
|
|
|
|
|
return stsword & MSATA_IND_STSBIT ? true : false;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:58 +00:00
|
|
|
static bool omnia_detect_wwan_usb3(const char *wwan_slot)
|
|
|
|
{
|
|
|
|
puts("WWAN slot configuration... ");
|
|
|
|
|
|
|
|
if (wwan_slot && strcmp(wwan_slot, "usb3") == 0) {
|
|
|
|
puts("USB3.0\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wwan_slot && strcmp(wwan_slot, "pcie") != 0)
|
|
|
|
printf("unsupported env value '%s', fallback to... ", wwan_slot);
|
|
|
|
|
|
|
|
puts("PCIe+USB2.0\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:52 +00:00
|
|
|
void *env_sf_get_env_addr(void)
|
|
|
|
{
|
|
|
|
/* SPI Flash is mapped to address 0xD4000000 only in SPL */
|
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
return (void *)0xD4000000 + CONFIG_ENV_OFFSET;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-06-09 17:28:45 +00:00
|
|
|
int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
|
|
|
|
{
|
2022-03-02 11:47:55 +00:00
|
|
|
#ifdef CONFIG_SPL_ENV_SUPPORT
|
|
|
|
/* Do not use env_load() as malloc() pool is too small at this stage */
|
|
|
|
bool has_env = (env_init() == 0);
|
|
|
|
#endif
|
|
|
|
const char *env_value = NULL;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_ENV_SUPPORT
|
|
|
|
/* beware that env_get() returns static allocated memory */
|
|
|
|
env_value = has_env ? env_get("omnia_msata_slot") : NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (omnia_detect_sata(env_value)) {
|
2022-03-02 11:47:54 +00:00
|
|
|
/* Change SerDes for first mPCIe port (mSATA) from PCIe to SATA */
|
|
|
|
board_serdes_map[0].serdes_type = SATA0;
|
|
|
|
board_serdes_map[0].serdes_speed = SERDES_SPEED_6_GBPS;
|
|
|
|
board_serdes_map[0].serdes_mode = SERDES_DEFAULT_MODE;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:58 +00:00
|
|
|
#ifdef CONFIG_SPL_ENV_SUPPORT
|
|
|
|
/* beware that env_get() returns static allocated memory */
|
|
|
|
env_value = has_env ? env_get("omnia_wwan_slot") : NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (omnia_detect_wwan_usb3(env_value)) {
|
|
|
|
/* Disable SerDes for USB 3.0 pins on the front USB-A port */
|
|
|
|
board_serdes_map[1].serdes_type = DEFAULT_SERDES;
|
|
|
|
/* Change SerDes for third mPCIe port (WWAN) from PCIe to USB 3.0 */
|
|
|
|
board_serdes_map[4].serdes_type = USB3_HOST0;
|
|
|
|
board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
|
|
|
|
board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
|
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:54 +00:00
|
|
|
*serdes_map_array = board_serdes_map;
|
|
|
|
*count = ARRAY_SIZE(board_serdes_map);
|
|
|
|
|
2017-06-09 17:28:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct omnia_eeprom {
|
|
|
|
u32 magic;
|
|
|
|
u32 ramsize;
|
|
|
|
char region[4];
|
|
|
|
u32 crc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool omnia_read_eeprom(struct omnia_eeprom *oep)
|
|
|
|
{
|
2019-05-02 14:53:30 +00:00
|
|
|
struct udevice *chip;
|
|
|
|
u32 crc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
chip = omnia_get_i2c_chip("EEPROM", OMNIA_I2C_EEPROM_CHIP_ADDR,
|
|
|
|
OMNIA_I2C_EEPROM_CHIP_LEN);
|
2017-06-09 17:28:45 +00:00
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
if (!chip)
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
ret = dm_i2c_read(chip, 0, (void *)oep, sizeof(*oep));
|
2017-06-09 17:28:45 +00:00
|
|
|
if (ret) {
|
2019-05-02 14:53:30 +00:00
|
|
|
printf("dm_i2c_read failed: %i, cannot read EEPROM\n", ret);
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
if (oep->magic != OMNIA_I2C_EEPROM_MAGIC) {
|
|
|
|
printf("bad EEPROM magic number (%08x, should be %08x)\n",
|
|
|
|
oep->magic, OMNIA_I2C_EEPROM_MAGIC);
|
|
|
|
return false;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:30 +00:00
|
|
|
crc = crc32(0, (void *)oep, sizeof(*oep) - 4);
|
|
|
|
if (crc != oep->crc) {
|
|
|
|
printf("bad EEPROM CRC (stored %08x, computed %08x)\n",
|
|
|
|
oep->crc, crc);
|
2017-06-09 17:28:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:53:33 +00:00
|
|
|
static int omnia_get_ram_size_gb(void)
|
|
|
|
{
|
|
|
|
static int ram_size;
|
|
|
|
struct omnia_eeprom oep;
|
|
|
|
|
|
|
|
if (!ram_size) {
|
|
|
|
/* Get the board config from EEPROM */
|
|
|
|
if (omnia_read_eeprom(&oep)) {
|
|
|
|
debug("Memory config in EEPROM: 0x%02x\n", oep.ramsize);
|
|
|
|
|
|
|
|
if (oep.ramsize == 0x2)
|
|
|
|
ram_size = 2;
|
|
|
|
else
|
|
|
|
ram_size = 1;
|
|
|
|
} else {
|
|
|
|
/* Hardcoded fallback */
|
|
|
|
puts("Memory config from EEPROM read failed!\n");
|
|
|
|
puts("Falling back to default 1 GiB!\n");
|
|
|
|
ram_size = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ram_size;
|
|
|
|
}
|
|
|
|
|
2017-06-09 17:28:45 +00:00
|
|
|
/*
|
|
|
|
* Define the DDR layout / topology here in the board file. This will
|
|
|
|
* be used by the DDR3 init code in the SPL U-Boot version to configure
|
|
|
|
* the DDR3 controller.
|
|
|
|
*/
|
2018-05-10 01:28:29 +00:00
|
|
|
static struct mv_ddr_topology_map board_topology_map_1g = {
|
|
|
|
DEBUG_LEVEL_ERROR,
|
2017-06-09 17:28:45 +00:00
|
|
|
0x1, /* active interfaces */
|
|
|
|
/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
|
|
|
|
{ { { {0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0} },
|
|
|
|
SPEED_BIN_DDR_1600K, /* speed_bin */
|
2018-05-10 01:28:29 +00:00
|
|
|
MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
|
|
|
|
MV_DDR_DIE_CAP_4GBIT, /* mem_size */
|
2018-12-03 01:26:49 +00:00
|
|
|
MV_DDR_FREQ_800, /* frequency */
|
2017-11-28 21:38:34 +00:00
|
|
|
0, 0, /* cas_wl cas_l */
|
2018-05-10 01:28:30 +00:00
|
|
|
MV_DDR_TEMP_NORMAL, /* temperature */
|
|
|
|
MV_DDR_TIM_2T} }, /* timing */
|
2018-05-10 01:28:29 +00:00
|
|
|
BUS_MASK_32BIT, /* Busses mask */
|
|
|
|
MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
|
2021-02-19 16:11:19 +00:00
|
|
|
NOT_COMBINED, /* ddr twin-die combined */
|
2018-05-10 01:28:29 +00:00
|
|
|
{ {0} }, /* raw spd data */
|
|
|
|
{0} /* timing parameters */
|
2017-06-09 17:28:45 +00:00
|
|
|
};
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
static struct mv_ddr_topology_map board_topology_map_2g = {
|
|
|
|
DEBUG_LEVEL_ERROR,
|
2017-06-09 17:28:45 +00:00
|
|
|
0x1, /* active interfaces */
|
|
|
|
/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
|
|
|
|
{ { { {0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0},
|
|
|
|
{0x1, 0, 0, 0} },
|
|
|
|
SPEED_BIN_DDR_1600K, /* speed_bin */
|
2018-05-10 01:28:29 +00:00
|
|
|
MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
|
|
|
|
MV_DDR_DIE_CAP_8GBIT, /* mem_size */
|
2018-12-03 01:26:49 +00:00
|
|
|
MV_DDR_FREQ_800, /* frequency */
|
2017-11-28 21:38:34 +00:00
|
|
|
0, 0, /* cas_wl cas_l */
|
2018-05-10 01:28:30 +00:00
|
|
|
MV_DDR_TEMP_NORMAL, /* temperature */
|
|
|
|
MV_DDR_TIM_2T} }, /* timing */
|
2018-05-10 01:28:29 +00:00
|
|
|
BUS_MASK_32BIT, /* Busses mask */
|
|
|
|
MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
|
2021-02-19 16:11:19 +00:00
|
|
|
NOT_COMBINED, /* ddr twin-die combined */
|
2018-05-10 01:28:29 +00:00
|
|
|
{ {0} }, /* raw spd data */
|
|
|
|
{0} /* timing parameters */
|
2017-06-09 17:28:45 +00:00
|
|
|
};
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
|
2017-06-09 17:28:45 +00:00
|
|
|
{
|
2019-05-02 14:53:33 +00:00
|
|
|
if (omnia_get_ram_size_gb() == 2)
|
2017-06-09 17:28:45 +00:00
|
|
|
return &board_topology_map_2g;
|
2019-05-02 14:53:33 +00:00
|
|
|
else
|
|
|
|
return &board_topology_map_1g;
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int set_regdomain(void)
|
|
|
|
{
|
|
|
|
struct omnia_eeprom oep;
|
|
|
|
char rd[3] = {' ', ' ', 0};
|
|
|
|
|
|
|
|
if (omnia_read_eeprom(&oep))
|
|
|
|
memcpy(rd, &oep.region, 2);
|
|
|
|
else
|
|
|
|
puts("EEPROM regdomain read failed.\n");
|
|
|
|
|
|
|
|
printf("Regdomain set to %s\n", rd);
|
2017-08-03 18:22:09 +00:00
|
|
|
return env_set("regdomain", rd);
|
2017-06-09 17:28:45 +00:00
|
|
|
}
|
2019-05-02 14:53:37 +00:00
|
|
|
|
|
|
|
static void handle_reset_button(void)
|
|
|
|
{
|
2021-06-14 14:45:58 +00:00
|
|
|
const char * const vars[1] = { "bootcmd_rescue", };
|
2019-05-02 14:53:37 +00:00
|
|
|
int ret;
|
|
|
|
u8 reset_status;
|
|
|
|
|
2021-06-14 14:45:58 +00:00
|
|
|
/*
|
|
|
|
* Ensure that bootcmd_rescue has always stock value, so that running
|
|
|
|
* run bootcmd_rescue
|
|
|
|
* always works correctly.
|
|
|
|
*/
|
|
|
|
env_set_default_vars(1, (char * const *)vars, 0);
|
|
|
|
|
2019-05-02 14:53:37 +00:00
|
|
|
ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1);
|
|
|
|
if (ret) {
|
|
|
|
printf("omnia_mcu_read failed: %i, reset status unknown!\n",
|
|
|
|
ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
env_set_ulong("omnia_reset", reset_status);
|
|
|
|
|
|
|
|
if (reset_status) {
|
2021-06-14 14:45:58 +00:00
|
|
|
const char * const vars[2] = {
|
2021-05-28 08:00:49 +00:00
|
|
|
"bootcmd",
|
|
|
|
"distro_bootcmd",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the above envs to their default values, in case the user
|
|
|
|
* managed to break them.
|
|
|
|
*/
|
2021-06-14 14:45:58 +00:00
|
|
|
env_set_default_vars(2, (char * const *)vars, 0);
|
2021-05-28 08:00:49 +00:00
|
|
|
|
|
|
|
/* Ensure bootcmd_rescue is used by distroboot */
|
|
|
|
env_set("boot_targets", "rescue");
|
|
|
|
|
2022-04-06 09:39:32 +00:00
|
|
|
printf("RESET button was pressed, overwriting boot_targets!\n");
|
2021-05-28 08:00:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* In case the user somehow managed to save environment with
|
|
|
|
* boot_targets=rescue, reset boot_targets to default value.
|
|
|
|
* This could happen in subsequent commands if bootcmd_rescue
|
|
|
|
* failed.
|
|
|
|
*/
|
|
|
|
if (!strcmp(env_get("boot_targets"), "rescue")) {
|
|
|
|
const char * const vars[1] = {
|
|
|
|
"boot_targets",
|
|
|
|
};
|
|
|
|
|
|
|
|
env_set_default_vars(1, (char * const *)vars, 0);
|
|
|
|
}
|
2019-05-02 14:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
int board_early_init_f(void)
|
|
|
|
{
|
|
|
|
/* Configure MPP */
|
|
|
|
writel(0x11111111, MVEBU_MPP_BASE + 0x00);
|
|
|
|
writel(0x11111111, MVEBU_MPP_BASE + 0x04);
|
|
|
|
writel(0x11244011, MVEBU_MPP_BASE + 0x08);
|
|
|
|
writel(0x22222111, MVEBU_MPP_BASE + 0x0c);
|
|
|
|
writel(0x22200002, MVEBU_MPP_BASE + 0x10);
|
|
|
|
writel(0x30042022, MVEBU_MPP_BASE + 0x14);
|
|
|
|
writel(0x55550555, MVEBU_MPP_BASE + 0x18);
|
|
|
|
writel(0x00005550, MVEBU_MPP_BASE + 0x1c);
|
|
|
|
|
|
|
|
/* Set GPP Out value */
|
|
|
|
writel(OMNIA_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
|
|
|
|
writel(OMNIA_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
|
|
|
|
|
|
|
|
/* Set GPP Polarity */
|
|
|
|
writel(OMNIA_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
|
|
|
|
writel(OMNIA_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
|
|
|
|
|
|
|
|
/* Set GPP Out Enable */
|
|
|
|
writel(OMNIA_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
|
|
|
|
writel(OMNIA_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-16 13:19:39 +00:00
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If booting from UART, disable MCU watchdog in SPL, since uploading
|
2021-11-09 16:14:02 +00:00
|
|
|
* U-Boot proper can take too much time and trigger it. Instead enable
|
|
|
|
* A385 watchdog with very high timeout (10 minutes) to prevent hangup.
|
2021-08-16 13:19:39 +00:00
|
|
|
*/
|
2021-11-09 16:14:02 +00:00
|
|
|
if (get_boot_device() == BOOT_DEVICE_UART) {
|
|
|
|
enable_a385_watchdog(10);
|
2021-08-16 13:19:39 +00:00
|
|
|
disable_mcu_watchdog();
|
2021-11-09 16:14:02 +00:00
|
|
|
}
|
2021-08-16 13:19:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 10:47:18 +00:00
|
|
|
#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) || IS_ENABLED(CONFIG_OF_BOARD_SETUP)
|
|
|
|
|
2022-03-02 11:47:56 +00:00
|
|
|
static void disable_sata_node(void *blob)
|
2022-01-10 10:47:18 +00:00
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
2022-03-02 11:47:56 +00:00
|
|
|
fdt_for_each_node_by_compatible(node, blob, -1, "marvell,armada-380-ahci") {
|
|
|
|
if (!fdtdec_get_is_enabled(blob, node))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fdt_status_disabled(blob, node) < 0)
|
|
|
|
printf("Cannot disable SATA DT node!\n");
|
|
|
|
else
|
|
|
|
debug("Disabled SATA DT node\n");
|
|
|
|
|
2022-03-02 11:47:57 +00:00
|
|
|
return;
|
2022-03-02 11:47:56 +00:00
|
|
|
}
|
2022-03-02 11:47:57 +00:00
|
|
|
|
|
|
|
printf("Cannot find SATA DT node!\n");
|
2022-03-02 11:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_pcie_node(void *blob, int port)
|
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
|
|
|
fdt_for_each_node_by_compatible(node, blob, -1, "marvell,armada-370-pcie") {
|
|
|
|
int port_node;
|
|
|
|
|
|
|
|
if (!fdtdec_get_is_enabled(blob, node))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fdt_for_each_subnode (port_node, blob, node) {
|
|
|
|
if (!fdtdec_get_is_enabled(blob, port_node))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fdtdec_get_int(blob, port_node, "marvell,pcie-port", -1) != port)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fdt_status_disabled(blob, port_node) < 0)
|
|
|
|
printf("Cannot disable PCIe port %d DT node!\n", port);
|
|
|
|
else
|
|
|
|
debug("Disabled PCIe port %d DT node\n", port);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 11:47:57 +00:00
|
|
|
|
|
|
|
printf("Cannot find PCIe port %d DT node!\n", port);
|
2022-03-02 11:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fixup_msata_port_nodes(void *blob)
|
|
|
|
{
|
|
|
|
bool mode_sata;
|
|
|
|
|
2022-01-10 10:47:18 +00:00
|
|
|
/*
|
|
|
|
* Determine if SerDes 0 is configured to SATA mode.
|
|
|
|
* We do this instead of calling omnia_detect_sata() to avoid another
|
|
|
|
* call to the MCU. By this time the common PHYs are initialized (it is
|
|
|
|
* done in SPL), so we can read this common PHY register.
|
|
|
|
*/
|
|
|
|
mode_sata = (readl(MVEBU_REGISTER(0x183fc)) & GENMASK(3, 0)) == 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're either adding status = "disabled" property, or changing
|
|
|
|
* status = "okay" to status = "disabled". In both cases we'll need more
|
|
|
|
* space. Increase the size a little.
|
|
|
|
*/
|
|
|
|
if (fdt_increase_size(blob, 32) < 0) {
|
|
|
|
printf("Cannot increase FDT size!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mode_sata) {
|
2022-03-02 11:47:56 +00:00
|
|
|
/* If mSATA card is not present, disable SATA DT node */
|
|
|
|
disable_sata_node(blob);
|
|
|
|
} else {
|
|
|
|
/* Otherwise disable PCIe port 0 DT node (MiniPCIe / mSATA port) */
|
|
|
|
disable_pcie_node(blob, 0);
|
2022-01-10 10:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 11:47:58 +00:00
|
|
|
static void fixup_wwan_port_nodes(void *blob)
|
|
|
|
{
|
|
|
|
bool mode_usb3;
|
|
|
|
|
|
|
|
/* Determine if SerDes 4 is configured to USB3 mode */
|
|
|
|
mode_usb3 = ((readl(MVEBU_REGISTER(0x183fc)) & GENMASK(19, 16)) >> 16) == 4;
|
|
|
|
|
|
|
|
/* If SerDes 4 is not configured to USB3 mode then nothing is needed to fixup */
|
|
|
|
if (!mode_usb3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're either adding status = "disabled" property, or changing
|
|
|
|
* status = "okay" to status = "disabled". In both cases we'll need more
|
|
|
|
* space. Increase the size a little.
|
|
|
|
*/
|
|
|
|
if (fdt_increase_size(blob, 32) < 0) {
|
|
|
|
printf("Cannot increase FDT size!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable PCIe port 2 DT node (WWAN) */
|
|
|
|
disable_pcie_node(blob, 2);
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:47:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP)
|
|
|
|
int board_fix_fdt(void *blob)
|
|
|
|
{
|
2022-03-02 11:47:56 +00:00
|
|
|
fixup_msata_port_nodes(blob);
|
2022-03-02 11:47:58 +00:00
|
|
|
fixup_wwan_port_nodes(blob);
|
2022-01-10 10:47:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-09 17:28:45 +00:00
|
|
|
int board_init(void)
|
|
|
|
{
|
2019-05-02 14:53:31 +00:00
|
|
|
/* address of boot parameters */
|
2017-06-09 17:28:45 +00:00
|
|
|
gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
|
|
|
|
|
2021-08-16 13:19:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2021-08-16 13:19:39 +00:00
|
|
|
/*
|
|
|
|
* If not booting from UART, MCU watchdog was not disabled in SPL,
|
|
|
|
* disable it now.
|
|
|
|
*/
|
|
|
|
if (get_boot_device() != BOOT_DEVICE_UART)
|
|
|
|
disable_mcu_watchdog();
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
set_regdomain();
|
2019-05-02 14:53:37 +00:00
|
|
|
handle_reset_button();
|
2019-05-24 12:57:53 +00:00
|
|
|
pci_init();
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-09 17:33:44 +00:00
|
|
|
int show_board_info(void)
|
2017-06-09 17:28:45 +00:00
|
|
|
{
|
|
|
|
u32 version_num, serial_num;
|
2022-04-08 14:30:12 +00:00
|
|
|
int err;
|
2017-06-09 17:28:45 +00:00
|
|
|
|
2022-04-08 14:30:12 +00:00
|
|
|
err = turris_atsha_otp_get_serial_number(&version_num, &serial_num);
|
2021-10-09 17:33:44 +00:00
|
|
|
printf("Model: Turris Omnia\n");
|
2019-05-02 14:53:34 +00:00
|
|
|
printf(" RAM size: %i MiB\n", omnia_get_ram_size_gb() * 1024);
|
2017-06-09 17:28:45 +00:00
|
|
|
if (err)
|
2019-05-02 14:53:34 +00:00
|
|
|
printf(" Serial Number: unknown\n");
|
2017-06-09 17:28:45 +00:00
|
|
|
else
|
2019-05-02 14:53:34 +00:00
|
|
|
printf(" Serial Number: %08X%08X\n", be32_to_cpu(version_num),
|
|
|
|
be32_to_cpu(serial_num));
|
2017-06-09 17:28:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
2022-04-08 14:30:14 +00:00
|
|
|
turris_atsha_otp_init_mac_addresses(1);
|
2017-06-09 17:28:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:21:02 +00:00
|
|
|
#if defined(CONFIG_OF_BOARD_SETUP)
|
|
|
|
/*
|
|
|
|
* I plan to generalize this function and move it to common/fdt_support.c.
|
|
|
|
* This will require some more work on multiple boards, though, so for now leave
|
|
|
|
* it here.
|
|
|
|
*/
|
|
|
|
static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
struct mtd_info *slave;
|
|
|
|
int parts;
|
|
|
|
|
|
|
|
parts = fdt_subnode_offset(blob, offset, "partitions");
|
|
|
|
if (parts < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_del_node(blob, parts) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
parts = fdt_add_subnode(blob, offset, "partitions");
|
|
|
|
if (parts < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_setprop_u32(blob, parts, "#address-cells", 1) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_setprop_u32(blob, parts, "#size-cells", 1) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_setprop_string(blob, parts, "compatible",
|
|
|
|
"fixed-partitions") < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mtd_probe_devices();
|
|
|
|
|
2021-10-21 15:55:48 +00:00
|
|
|
list_for_each_entry_reverse(slave, &mtd->partitions, node) {
|
2021-07-15 17:21:02 +00:00
|
|
|
char name[32];
|
|
|
|
int part;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "partition@%llx", slave->offset);
|
|
|
|
part = fdt_add_subnode(blob, parts, name);
|
|
|
|
if (part < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_setprop_u32(blob, part, "reg", slave->offset) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_appendprop_u32(blob, part, "reg", slave->size) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fdt_setprop_string(blob, part, "label", slave->name) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(slave->flags & MTD_WRITEABLE))
|
|
|
|
if (fdt_setprop_empty(blob, part, "read-only") < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (slave->flags & MTD_POWERUP_LOCK)
|
|
|
|
if (fdt_setprop_empty(blob, part, "lock") < 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:47:18 +00:00
|
|
|
static void fixup_spi_nor_partitions(void *blob)
|
2021-07-15 17:21:02 +00:00
|
|
|
{
|
|
|
|
struct mtd_info *mtd;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
mtd = get_mtd_device_nm(OMNIA_SPI_NOR_PATH);
|
|
|
|
if (IS_ERR_OR_NULL(mtd))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
node = fdt_path_offset(blob, OMNIA_SPI_NOR_PATH);
|
|
|
|
if (node < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!fixup_mtd_partitions(blob, node, mtd))
|
|
|
|
goto fail;
|
|
|
|
|
2021-09-25 00:49:18 +00:00
|
|
|
put_mtd_device(mtd);
|
2022-01-10 10:47:18 +00:00
|
|
|
return;
|
2021-07-15 17:21:02 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
printf("Failed fixing SPI NOR partitions!\n");
|
2021-09-25 00:49:18 +00:00
|
|
|
if (!IS_ERR_OR_NULL(mtd))
|
|
|
|
put_mtd_device(mtd);
|
2022-01-10 10:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
|
|
|
{
|
|
|
|
fixup_spi_nor_partitions(blob);
|
2022-03-02 11:47:56 +00:00
|
|
|
fixup_msata_port_nodes(blob);
|
2022-03-02 11:47:58 +00:00
|
|
|
fixup_wwan_port_nodes(blob);
|
2022-01-10 10:47:18 +00:00
|
|
|
|
2021-07-15 17:21:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|