183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
209f455dcSMasahiro Yamada /*
37aaa5a60STom Warren * (C) Copyright 2010-2015
409f455dcSMasahiro Yamada * NVIDIA Corporation <www.nvidia.com>
509f455dcSMasahiro Yamada */
609f455dcSMasahiro Yamada
709f455dcSMasahiro Yamada /* Tegra AP (Application Processor) code */
809f455dcSMasahiro Yamada
909f455dcSMasahiro Yamada #include <common.h>
1084b8bf6dSMasahiro Yamada #include <linux/bug.h>
1109f455dcSMasahiro Yamada #include <asm/io.h>
1209f455dcSMasahiro Yamada #include <asm/arch/gp_padctrl.h>
1373169874SIan Campbell #include <asm/arch/mc.h>
1409f455dcSMasahiro Yamada #include <asm/arch-tegra/ap.h>
1509f455dcSMasahiro Yamada #include <asm/arch-tegra/clock.h>
1609f455dcSMasahiro Yamada #include <asm/arch-tegra/fuse.h>
1709f455dcSMasahiro Yamada #include <asm/arch-tegra/pmc.h>
1809f455dcSMasahiro Yamada #include <asm/arch-tegra/scu.h>
1909f455dcSMasahiro Yamada #include <asm/arch-tegra/tegra.h>
2009f455dcSMasahiro Yamada #include <asm/arch-tegra/warmboot.h>
2109f455dcSMasahiro Yamada
tegra_get_chip(void)2209f455dcSMasahiro Yamada int tegra_get_chip(void)
2309f455dcSMasahiro Yamada {
2409f455dcSMasahiro Yamada int rev;
2509f455dcSMasahiro Yamada struct apb_misc_gp_ctlr *gp =
2609f455dcSMasahiro Yamada (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
2709f455dcSMasahiro Yamada
2809f455dcSMasahiro Yamada /*
2909f455dcSMasahiro Yamada * This is undocumented, Chip ID is bits 15:8 of the register
3009f455dcSMasahiro Yamada * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
3109f455dcSMasahiro Yamada * Tegra30, 0x35 for T114, and 0x40 for Tegra124.
3209f455dcSMasahiro Yamada */
3309f455dcSMasahiro Yamada rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
3409f455dcSMasahiro Yamada debug("%s: CHIPID is 0x%02X\n", __func__, rev);
3509f455dcSMasahiro Yamada
3609f455dcSMasahiro Yamada return rev;
3709f455dcSMasahiro Yamada }
3809f455dcSMasahiro Yamada
tegra_get_sku_info(void)3909f455dcSMasahiro Yamada int tegra_get_sku_info(void)
4009f455dcSMasahiro Yamada {
4109f455dcSMasahiro Yamada int sku_id;
4209f455dcSMasahiro Yamada struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
4309f455dcSMasahiro Yamada
4409f455dcSMasahiro Yamada sku_id = readl(&fuse->sku_info) & 0xff;
4509f455dcSMasahiro Yamada debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id);
4609f455dcSMasahiro Yamada
4709f455dcSMasahiro Yamada return sku_id;
4809f455dcSMasahiro Yamada }
4909f455dcSMasahiro Yamada
tegra_get_chip_sku(void)5009f455dcSMasahiro Yamada int tegra_get_chip_sku(void)
5109f455dcSMasahiro Yamada {
5209f455dcSMasahiro Yamada uint sku_id, chip_id;
5309f455dcSMasahiro Yamada
5409f455dcSMasahiro Yamada chip_id = tegra_get_chip();
5509f455dcSMasahiro Yamada sku_id = tegra_get_sku_info();
5609f455dcSMasahiro Yamada
5709f455dcSMasahiro Yamada switch (chip_id) {
5809f455dcSMasahiro Yamada case CHIPID_TEGRA20:
5909f455dcSMasahiro Yamada switch (sku_id) {
6009f455dcSMasahiro Yamada case SKU_ID_T20_7:
6109f455dcSMasahiro Yamada case SKU_ID_T20:
6209f455dcSMasahiro Yamada return TEGRA_SOC_T20;
6309f455dcSMasahiro Yamada case SKU_ID_T25SE:
6409f455dcSMasahiro Yamada case SKU_ID_AP25:
6509f455dcSMasahiro Yamada case SKU_ID_T25:
6609f455dcSMasahiro Yamada case SKU_ID_AP25E:
6709f455dcSMasahiro Yamada case SKU_ID_T25E:
6809f455dcSMasahiro Yamada return TEGRA_SOC_T25;
6909f455dcSMasahiro Yamada }
7009f455dcSMasahiro Yamada break;
7109f455dcSMasahiro Yamada case CHIPID_TEGRA30:
7209f455dcSMasahiro Yamada switch (sku_id) {
7309f455dcSMasahiro Yamada case SKU_ID_T33:
7409f455dcSMasahiro Yamada case SKU_ID_T30:
7509f455dcSMasahiro Yamada case SKU_ID_TM30MQS_P_A3:
7609f455dcSMasahiro Yamada default:
7709f455dcSMasahiro Yamada return TEGRA_SOC_T30;
7809f455dcSMasahiro Yamada }
7909f455dcSMasahiro Yamada break;
8009f455dcSMasahiro Yamada case CHIPID_TEGRA114:
8109f455dcSMasahiro Yamada switch (sku_id) {
8209f455dcSMasahiro Yamada case SKU_ID_T114_ENG:
8309f455dcSMasahiro Yamada case SKU_ID_T114_1:
8409f455dcSMasahiro Yamada default:
8509f455dcSMasahiro Yamada return TEGRA_SOC_T114;
8609f455dcSMasahiro Yamada }
8709f455dcSMasahiro Yamada break;
8809f455dcSMasahiro Yamada case CHIPID_TEGRA124:
8909f455dcSMasahiro Yamada switch (sku_id) {
9009f455dcSMasahiro Yamada case SKU_ID_T124_ENG:
9109f455dcSMasahiro Yamada default:
9209f455dcSMasahiro Yamada return TEGRA_SOC_T124;
9309f455dcSMasahiro Yamada }
9409f455dcSMasahiro Yamada break;
957aaa5a60STom Warren case CHIPID_TEGRA210:
967aaa5a60STom Warren switch (sku_id) {
977aaa5a60STom Warren case SKU_ID_T210_ENG:
987aaa5a60STom Warren default:
997aaa5a60STom Warren return TEGRA_SOC_T210;
1007aaa5a60STom Warren }
1017aaa5a60STom Warren break;
10209f455dcSMasahiro Yamada }
10309f455dcSMasahiro Yamada
10409f455dcSMasahiro Yamada /* unknown chip/sku id */
10509f455dcSMasahiro Yamada printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n",
10609f455dcSMasahiro Yamada __func__, chip_id, sku_id);
10709f455dcSMasahiro Yamada return TEGRA_SOC_UNKNOWN;
10809f455dcSMasahiro Yamada }
10909f455dcSMasahiro Yamada
1107aaa5a60STom Warren #ifndef CONFIG_ARM64
enable_scu(void)11109f455dcSMasahiro Yamada static void enable_scu(void)
11209f455dcSMasahiro Yamada {
11309f455dcSMasahiro Yamada struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
11409f455dcSMasahiro Yamada u32 reg;
11509f455dcSMasahiro Yamada
11609f455dcSMasahiro Yamada /* Only enable the SCU on T20/T25 */
11709f455dcSMasahiro Yamada if (tegra_get_chip() != CHIPID_TEGRA20)
11809f455dcSMasahiro Yamada return;
11909f455dcSMasahiro Yamada
12009f455dcSMasahiro Yamada /* If SCU already setup/enabled, return */
12109f455dcSMasahiro Yamada if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
12209f455dcSMasahiro Yamada return;
12309f455dcSMasahiro Yamada
12409f455dcSMasahiro Yamada /* Invalidate all ways for all processors */
12509f455dcSMasahiro Yamada writel(0xFFFF, &scu->scu_inv_all);
12609f455dcSMasahiro Yamada
12709f455dcSMasahiro Yamada /* Enable SCU - bit 0 */
12809f455dcSMasahiro Yamada reg = readl(&scu->scu_ctrl);
12909f455dcSMasahiro Yamada reg |= SCU_CTRL_ENABLE;
13009f455dcSMasahiro Yamada writel(reg, &scu->scu_ctrl);
13109f455dcSMasahiro Yamada }
13209f455dcSMasahiro Yamada
get_odmdata(void)13309f455dcSMasahiro Yamada static u32 get_odmdata(void)
13409f455dcSMasahiro Yamada {
13509f455dcSMasahiro Yamada /*
13609f455dcSMasahiro Yamada * ODMDATA is stored in the BCT in IRAM by the BootROM.
13709f455dcSMasahiro Yamada * The BCT start and size are stored in the BIT in IRAM.
13809f455dcSMasahiro Yamada * Read the data @ bct_start + (bct_size - 12). This works
13909f455dcSMasahiro Yamada * on BCTs for currently supported SoCs, which are locked down.
14009f455dcSMasahiro Yamada * If this changes in new chips, we can revisit this algorithm.
14109f455dcSMasahiro Yamada */
142f49357baSThierry Reding unsigned long bct_start;
143f49357baSThierry Reding u32 odmdata;
14409f455dcSMasahiro Yamada
14509f455dcSMasahiro Yamada bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
14609f455dcSMasahiro Yamada odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
14709f455dcSMasahiro Yamada
14809f455dcSMasahiro Yamada return odmdata;
14909f455dcSMasahiro Yamada }
15009f455dcSMasahiro Yamada
init_pmc_scratch(void)15109f455dcSMasahiro Yamada static void init_pmc_scratch(void)
15209f455dcSMasahiro Yamada {
15309f455dcSMasahiro Yamada struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
15409f455dcSMasahiro Yamada u32 odmdata;
15509f455dcSMasahiro Yamada int i;
15609f455dcSMasahiro Yamada
15709f455dcSMasahiro Yamada /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
158*3d186cf3SStephen Warren #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
159*3d186cf3SStephen Warren if (!tegra_cpu_is_non_secure())
160*3d186cf3SStephen Warren #endif
161*3d186cf3SStephen Warren {
16209f455dcSMasahiro Yamada for (i = 0; i < 23; i++)
16309f455dcSMasahiro Yamada writel(0, &pmc->pmc_scratch1 + i);
164*3d186cf3SStephen Warren }
16509f455dcSMasahiro Yamada
16609f455dcSMasahiro Yamada /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
16709f455dcSMasahiro Yamada odmdata = get_odmdata();
16809f455dcSMasahiro Yamada writel(odmdata, &pmc->pmc_scratch20);
16909f455dcSMasahiro Yamada }
17009f455dcSMasahiro Yamada
17173169874SIan Campbell #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
protect_secure_section(void)17273169874SIan Campbell void protect_secure_section(void)
17373169874SIan Campbell {
17473169874SIan Campbell struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
17573169874SIan Campbell
17673169874SIan Campbell /* Must be MB aligned */
17773169874SIan Campbell BUILD_BUG_ON(CONFIG_ARMV7_SECURE_BASE & 0xFFFFF);
17873169874SIan Campbell BUILD_BUG_ON(CONFIG_ARMV7_SECURE_RESERVE_SIZE & 0xFFFFF);
17973169874SIan Campbell
18073169874SIan Campbell writel(CONFIG_ARMV7_SECURE_BASE, &mc->mc_security_cfg0);
18173169874SIan Campbell writel(CONFIG_ARMV7_SECURE_RESERVE_SIZE >> 20, &mc->mc_security_cfg1);
18273169874SIan Campbell }
18373169874SIan Campbell #endif
18473169874SIan Campbell
18579cf644eSThierry Reding #if defined(CONFIG_ARMV7_NONSEC)
smmu_flush(struct mc_ctlr * mc)18679cf644eSThierry Reding static void smmu_flush(struct mc_ctlr *mc)
18779cf644eSThierry Reding {
18879cf644eSThierry Reding (void)readl(&mc->mc_smmu_config);
18979cf644eSThierry Reding }
19079cf644eSThierry Reding
smmu_enable(void)19179cf644eSThierry Reding static void smmu_enable(void)
19279cf644eSThierry Reding {
19379cf644eSThierry Reding struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
19479cf644eSThierry Reding u32 value;
19579cf644eSThierry Reding
19679cf644eSThierry Reding /*
19779cf644eSThierry Reding * Enable translation for all clients since access to this register
19879cf644eSThierry Reding * is restricted to TrustZone-secured requestors. The kernel will use
19979cf644eSThierry Reding * the per-SWGROUP enable bits to enable or disable translations.
20079cf644eSThierry Reding */
20179cf644eSThierry Reding writel(0xffffffff, &mc->mc_smmu_translation_enable_0);
20279cf644eSThierry Reding writel(0xffffffff, &mc->mc_smmu_translation_enable_1);
20379cf644eSThierry Reding writel(0xffffffff, &mc->mc_smmu_translation_enable_2);
20479cf644eSThierry Reding writel(0xffffffff, &mc->mc_smmu_translation_enable_3);
20579cf644eSThierry Reding
20679cf644eSThierry Reding /*
20779cf644eSThierry Reding * Enable SMMU globally since access to this register is restricted
20879cf644eSThierry Reding * to TrustZone-secured requestors.
20979cf644eSThierry Reding */
21079cf644eSThierry Reding value = readl(&mc->mc_smmu_config);
21179cf644eSThierry Reding value |= TEGRA_MC_SMMU_CONFIG_ENABLE;
21279cf644eSThierry Reding writel(value, &mc->mc_smmu_config);
21379cf644eSThierry Reding
21479cf644eSThierry Reding smmu_flush(mc);
21579cf644eSThierry Reding }
21679cf644eSThierry Reding #else
smmu_enable(void)21779cf644eSThierry Reding static void smmu_enable(void)
21879cf644eSThierry Reding {
21979cf644eSThierry Reding }
22079cf644eSThierry Reding #endif
22179cf644eSThierry Reding
s_init(void)22209f455dcSMasahiro Yamada void s_init(void)
22309f455dcSMasahiro Yamada {
22409f455dcSMasahiro Yamada /* Init PMC scratch memory */
22509f455dcSMasahiro Yamada init_pmc_scratch();
22609f455dcSMasahiro Yamada
22709f455dcSMasahiro Yamada enable_scu();
22809f455dcSMasahiro Yamada
22909f455dcSMasahiro Yamada /* init the cache */
23009f455dcSMasahiro Yamada config_cache();
23109f455dcSMasahiro Yamada
23279cf644eSThierry Reding /* enable SMMU */
23379cf644eSThierry Reding smmu_enable();
23409f455dcSMasahiro Yamada }
2357aaa5a60STom Warren #endif
236