arm-trusted-firmware/plat/socionext/uniphier/uniphier_boot_device.c
Antonio Nino Diaz 09d40e0e08 Sanitise includes across codebase
Enforce full include path for includes. Deprecate old paths.

The following folders inside include/lib have been left unchanged:

- include/lib/cpus/${ARCH}
- include/lib/el3_runtime/${ARCH}

The reason for this change is that having a global namespace for
includes isn't a good idea. It defeats one of the advantages of having
folders and it introduces problems that are sometimes subtle (because
you may not know the header you are actually including if there are two
of them).

For example, this patch had to be created because two headers were
called the same way: e0ea0928d5 ("Fix gpio includes of mt8173 platform
to avoid collision."). More recently, this patch has had similar
problems: 46f9b2c3a2 ("drivers: add tzc380 support").

This problem was introduced in commit 4ecca33988 ("Move include and
source files to logical locations"). At that time, there weren't too
many headers so it wasn't a real issue. However, time has shown that
this creates problems.

Platforms that want to preserve the way they include headers may add the
removed paths to PLAT_INCLUDES, but this is discouraged.

Change-Id: I39dc53ed98f9e297a5966e723d1936d6ccf2fc8f
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2019-01-04 10:43:17 +00:00

165 lines
4 KiB
C

/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <lib/mmio.h>
#include <lib/utils_def.h>
#include "uniphier.h"
#define UNIPHIER_PINMON0 0x5f900100
#define UNIPHIER_PINMON2 0x5f900108
static int uniphier_ld11_is_usb_boot(uint32_t pinmon)
{
return !!(~pinmon & 0x00000080);
}
static int uniphier_ld20_is_usb_boot(uint32_t pinmon)
{
return !!(~pinmon & 0x00000780);
}
static int uniphier_pxs3_is_usb_boot(uint32_t pinmon)
{
uint32_t pinmon2 = mmio_read_32(UNIPHIER_PINMON2);
return !!(pinmon2 & BIT(31));
}
static const unsigned int uniphier_ld11_boot_device_table[] = {
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_NOR,
};
static unsigned int uniphier_ld11_get_boot_device(uint32_t pinmon)
{
unsigned int boot_sel = (pinmon >> 1) & 0x1f;
assert(boot_sel < ARRAY_SIZE(uniphier_ld11_boot_device_table));
return uniphier_ld11_boot_device_table[boot_sel];
}
static const unsigned int uniphier_pxs3_boot_device_table[] = {
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_EMMC,
UNIPHIER_BOOT_DEVICE_NAND,
UNIPHIER_BOOT_DEVICE_NAND,
};
static unsigned int uniphier_pxs3_get_boot_device(uint32_t pinmon)
{
unsigned int boot_sel = (pinmon >> 1) & 0xf;
assert(boot_sel < ARRAY_SIZE(uniphier_pxs3_boot_device_table));
return uniphier_pxs3_boot_device_table[boot_sel];
}
struct uniphier_boot_device_info {
int (*is_usb_boot)(uint32_t pinmon);
unsigned int (*get_boot_device)(uint32_t pinmon);
};
static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
[UNIPHIER_SOC_LD11] = {
.is_usb_boot = uniphier_ld11_is_usb_boot,
.get_boot_device = uniphier_ld11_get_boot_device,
},
[UNIPHIER_SOC_LD20] = {
.is_usb_boot = uniphier_ld20_is_usb_boot,
.get_boot_device = uniphier_ld11_get_boot_device,
},
[UNIPHIER_SOC_PXS3] = {
.is_usb_boot = uniphier_pxs3_is_usb_boot,
.get_boot_device = uniphier_pxs3_get_boot_device,
},
};
unsigned int uniphier_get_boot_device(unsigned int soc)
{
const struct uniphier_boot_device_info *info;
uint32_t pinmon;
assert(soc < ARRAY_SIZE(uniphier_boot_device_info));
info = &uniphier_boot_device_info[soc];
pinmon = mmio_read_32(UNIPHIER_PINMON0);
if (!(pinmon & BIT(29)))
return UNIPHIER_BOOT_DEVICE_NOR;
if (info->is_usb_boot(pinmon))
return UNIPHIER_BOOT_DEVICE_USB;
return info->get_boot_device(pinmon);
}
static const bool uniphier_have_onchip_scp[] = {
[UNIPHIER_SOC_LD11] = true,
[UNIPHIER_SOC_LD20] = true,
[UNIPHIER_SOC_PXS3] = false,
};
unsigned int uniphier_get_boot_master(unsigned int soc)
{
assert(soc < ARRAY_SIZE(uniphier_have_onchip_scp));
if (uniphier_have_onchip_scp[soc]) {
if (mmio_read_32(UNIPHIER_PINMON0) & BIT(27))
return UNIPHIER_BOOT_MASTER_THIS;
else
return UNIPHIER_BOOT_MASTER_SCP;
} else {
return UNIPHIER_BOOT_MASTER_EXT;
}
}