2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-13 16:24:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015-2017 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*/
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2017-02-13 16:24:26 +00:00
|
|
|
#include <spl.h>
|
2017-10-13 10:21:55 +00:00
|
|
|
#include <stdio.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-10 17:40:08 +00:00
|
|
|
#include <linux/bug.h>
|
2020-05-20 03:31:27 +00:00
|
|
|
#include <linux/errno.h>
|
2019-07-10 11:07:34 +00:00
|
|
|
#include <linux/io.h>
|
2017-02-13 16:24:26 +00:00
|
|
|
#include <linux/log2.h>
|
|
|
|
|
|
|
|
#include "../init.h"
|
|
|
|
#include "../sbc/sbc-regs.h"
|
|
|
|
#include "../sg-regs.h"
|
|
|
|
#include "../soc-info.h"
|
|
|
|
#include "boot-device.h"
|
|
|
|
|
|
|
|
struct uniphier_boot_device_info {
|
|
|
|
unsigned int soc_id;
|
|
|
|
unsigned int boot_device_sel_shift;
|
|
|
|
const struct uniphier_boot_device *boot_device_table;
|
|
|
|
const unsigned int *boot_device_count;
|
2019-07-10 11:07:39 +00:00
|
|
|
int (*boot_device_is_sd)(u32 pinmon);
|
2017-02-13 16:24:26 +00:00
|
|
|
int (*boot_device_is_usb)(u32 pinmon);
|
|
|
|
unsigned int (*boot_device_fixup)(unsigned int mode);
|
2019-07-10 11:07:38 +00:00
|
|
|
int (*boot_is_swapped)(void);
|
2019-07-10 11:07:33 +00:00
|
|
|
bool have_internal_stm;
|
2017-02-13 16:24:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD4)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD4_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_ld4_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_ld4_boot_device_count,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = true,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_PRO4_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_ld4_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_ld4_boot_device_count,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = false,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_SLD8_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_ld4_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_ld4_boot_device_count,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = true,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_PRO5_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_pro5_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_pro5_boot_device_count,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = false,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_PXS2_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_pxs2_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_pxs2_boot_device_count,
|
|
|
|
.boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
|
|
|
|
.boot_device_fixup = uniphier_pxs2_boot_device_fixup,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = false,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD6B_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_pxs2_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_pxs2_boot_device_count,
|
|
|
|
.boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
|
|
|
|
.boot_device_fixup = uniphier_pxs2_boot_device_fixup,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = true, /* STM on A-chip */
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD11)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD11_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_ld11_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_ld11_boot_device_count,
|
|
|
|
.boot_device_is_usb = uniphier_ld11_boot_device_is_usb,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = true,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_LD20)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD20_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_ld11_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_ld11_boot_device_count,
|
|
|
|
.boot_device_is_usb = uniphier_ld20_boot_device_is_usb,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = true,
|
2017-02-13 16:24:26 +00:00
|
|
|
},
|
|
|
|
#endif
|
2017-05-15 05:26:33 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER_PXS3)
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_PXS3_ID,
|
|
|
|
.boot_device_sel_shift = 1,
|
|
|
|
.boot_device_table = uniphier_pxs3_boot_device_table,
|
|
|
|
.boot_device_count = &uniphier_pxs3_boot_device_count,
|
|
|
|
.boot_device_is_usb = uniphier_pxs3_boot_device_is_usb,
|
2019-07-10 11:07:38 +00:00
|
|
|
.boot_is_swapped = uniphier_sbc_boot_is_swapped,
|
2019-07-10 11:07:33 +00:00
|
|
|
.have_internal_stm = false,
|
2017-05-15 05:26:33 +00:00
|
|
|
},
|
|
|
|
#endif
|
2017-02-13 16:24:26 +00:00
|
|
|
};
|
|
|
|
UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_boot_device_info,
|
|
|
|
uniphier_boot_device_info)
|
|
|
|
|
|
|
|
static unsigned int __uniphier_boot_device_raw(
|
|
|
|
const struct uniphier_boot_device_info *info)
|
|
|
|
{
|
|
|
|
u32 pinmon;
|
|
|
|
unsigned int boot_sel;
|
|
|
|
|
2019-07-10 11:07:38 +00:00
|
|
|
if (info->boot_is_swapped && info->boot_is_swapped())
|
2017-02-13 16:24:26 +00:00
|
|
|
return BOOT_DEVICE_NOR;
|
|
|
|
|
2019-07-10 11:07:40 +00:00
|
|
|
pinmon = readl(sg_base + SG_PINMON0);
|
2017-02-13 16:24:26 +00:00
|
|
|
|
2019-07-10 11:07:39 +00:00
|
|
|
if (info->boot_device_is_sd && info->boot_device_is_sd(pinmon))
|
|
|
|
return BOOT_DEVICE_MMC2;
|
|
|
|
|
2017-02-13 16:24:26 +00:00
|
|
|
if (info->boot_device_is_usb && info->boot_device_is_usb(pinmon))
|
|
|
|
return BOOT_DEVICE_USB;
|
|
|
|
|
|
|
|
boot_sel = pinmon >> info->boot_device_sel_shift;
|
|
|
|
|
|
|
|
BUG_ON(!is_power_of_2(*info->boot_device_count));
|
|
|
|
boot_sel &= *info->boot_device_count - 1;
|
|
|
|
|
|
|
|
return info->boot_device_table[boot_sel].boot_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int uniphier_boot_device_raw(void)
|
|
|
|
{
|
|
|
|
const struct uniphier_boot_device_info *info;
|
|
|
|
|
|
|
|
info = uniphier_get_boot_device_info();
|
|
|
|
if (!info) {
|
|
|
|
pr_err("unsupported SoC\n");
|
|
|
|
return BOOT_DEVICE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return __uniphier_boot_device_raw(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
|
|
|
const struct uniphier_boot_device_info *info;
|
|
|
|
u32 raw_mode;
|
|
|
|
|
|
|
|
info = uniphier_get_boot_device_info();
|
|
|
|
if (!info) {
|
|
|
|
pr_err("unsupported SoC\n");
|
|
|
|
return BOOT_DEVICE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_mode = __uniphier_boot_device_raw(info);
|
|
|
|
|
|
|
|
return info->boot_device_fixup ?
|
|
|
|
info->boot_device_fixup(raw_mode) : raw_mode;
|
|
|
|
}
|
|
|
|
|
2017-04-20 07:54:43 +00:00
|
|
|
int uniphier_have_internal_stm(void)
|
|
|
|
{
|
|
|
|
const struct uniphier_boot_device_info *info;
|
|
|
|
|
|
|
|
info = uniphier_get_boot_device_info();
|
|
|
|
if (!info) {
|
|
|
|
pr_err("unsupported SoC\n");
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info->have_internal_stm;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uniphier_boot_from_backend(void)
|
|
|
|
{
|
2019-07-10 11:07:40 +00:00
|
|
|
return !!(readl(sg_base + SG_PINMON0) & BIT(27));
|
2017-04-20 07:54:43 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 16:24:26 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_pinmon(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2017-02-13 16:24:26 +00:00
|
|
|
{
|
|
|
|
const struct uniphier_boot_device_info *info;
|
|
|
|
u32 pinmon;
|
|
|
|
unsigned int boot_device_count, boot_sel;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
info = uniphier_get_boot_device_info();
|
|
|
|
if (!info) {
|
|
|
|
pr_err("unsupported SoC\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-04-20 07:54:43 +00:00
|
|
|
if (uniphier_have_internal_stm())
|
|
|
|
printf("STB Micon: %s\n",
|
|
|
|
uniphier_boot_from_backend() ? "OFF" : "ON");
|
|
|
|
|
2019-07-10 11:07:38 +00:00
|
|
|
if (info->boot_is_swapped)
|
|
|
|
printf("Boot Swap: %s\n",
|
|
|
|
info->boot_is_swapped() ? "ON" : "OFF");
|
2017-02-13 16:24:26 +00:00
|
|
|
|
2019-07-10 11:07:40 +00:00
|
|
|
pinmon = readl(sg_base + SG_PINMON0);
|
2017-02-13 16:24:26 +00:00
|
|
|
|
2019-07-10 11:07:39 +00:00
|
|
|
if (info->boot_device_is_sd)
|
|
|
|
printf("SD Boot: %s\n",
|
|
|
|
info->boot_device_is_sd(pinmon) ? "ON" : "OFF");
|
|
|
|
|
2017-02-13 16:24:26 +00:00
|
|
|
if (info->boot_device_is_usb)
|
2017-04-20 07:54:43 +00:00
|
|
|
printf("USB Boot: %s\n",
|
2017-02-13 16:24:26 +00:00
|
|
|
info->boot_device_is_usb(pinmon) ? "ON" : "OFF");
|
|
|
|
|
|
|
|
boot_device_count = *info->boot_device_count;
|
|
|
|
|
|
|
|
boot_sel = pinmon >> info->boot_device_sel_shift;
|
|
|
|
boot_sel &= boot_device_count - 1;
|
|
|
|
|
2017-04-20 07:54:43 +00:00
|
|
|
printf("\nBoot Mode Sel:\n");
|
2017-02-13 16:24:26 +00:00
|
|
|
for (i = 0; i < boot_device_count; i++)
|
|
|
|
printf(" %c %02x %s\n", i == boot_sel ? '*' : ' ', i,
|
|
|
|
info->boot_device_table[i].desc);
|
|
|
|
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
pinmon, 1, 1, do_pinmon,
|
|
|
|
"pin monitor",
|
|
|
|
""
|
|
|
|
);
|
|
|
|
|
|
|
|
#endif /* !CONFIG_SPL_BUILD */
|