blob: a17dfd1e225ed39bfa58795bf1529bf7f825fc2f [file] [log] [blame]
Tom Warren74652cf2011-04-14 12:18:06 +00001/*
Tom Warren2f5dac92014-01-24 12:46:16 -07002* (C) Copyright 2010-2014
Tom Warren74652cf2011-04-14 12:18:06 +00003* NVIDIA Corporation <www.nvidia.com>
4*
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Tom Warren74652cf2011-04-14 12:18:06 +00006*/
Tom Warrenb2871032012-12-11 13:34:15 +00007
8/* Tegra AP (Application Processor) code */
9
Tom Warren74652cf2011-04-14 12:18:06 +000010#include <common.h>
Tom Warren150c2492012-09-19 15:50:56 -070011#include <asm/io.h>
12#include <asm/arch/gp_padctrl.h>
13#include <asm/arch-tegra/ap.h>
Tom Warrenb2871032012-12-11 13:34:15 +000014#include <asm/arch-tegra/clock.h>
Tom Warren150c2492012-09-19 15:50:56 -070015#include <asm/arch-tegra/fuse.h>
16#include <asm/arch-tegra/pmc.h>
17#include <asm/arch-tegra/scu.h>
Tom Warrene23bb6a2013-01-28 13:32:10 +000018#include <asm/arch-tegra/tegra.h>
Tom Warren150c2492012-09-19 15:50:56 -070019#include <asm/arch-tegra/warmboot.h>
Tom Warren74652cf2011-04-14 12:18:06 +000020
Tom Warren49493cb2013-04-10 10:32:32 -070021int tegra_get_chip(void)
Simon Glassd5153622012-04-02 13:18:50 +000022{
Tom Warren49493cb2013-04-10 10:32:32 -070023 int rev;
24 struct apb_misc_gp_ctlr *gp =
25 (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
Simon Glassd5153622012-04-02 13:18:50 +000026
27 /*
28 * This is undocumented, Chip ID is bits 15:8 of the register
29 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
Tom Warren2f5dac92014-01-24 12:46:16 -070030 * Tegra30, 0x35 for T114, and 0x40 for Tegra124.
Simon Glassd5153622012-04-02 13:18:50 +000031 */
Simon Glassd5153622012-04-02 13:18:50 +000032 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
Tom Warren49493cb2013-04-10 10:32:32 -070033 debug("%s: CHIPID is 0x%02X\n", __func__, rev);
Simon Glassd5153622012-04-02 13:18:50 +000034
Tom Warren49493cb2013-04-10 10:32:32 -070035 return rev;
36}
Simon Glassd5153622012-04-02 13:18:50 +000037
Tom Warren49493cb2013-04-10 10:32:32 -070038int tegra_get_sku_info(void)
39{
40 int sku_id;
41 struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
42
43 sku_id = readl(&fuse->sku_info) & 0xff;
44 debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id);
45
46 return sku_id;
47}
48
49int tegra_get_chip_sku(void)
50{
51 uint sku_id, chip_id;
52
53 chip_id = tegra_get_chip();
54 sku_id = tegra_get_sku_info();
55
56 switch (chip_id) {
Allen Martin00a27492012-08-31 08:30:00 +000057 case CHIPID_TEGRA20:
Tom Warren49493cb2013-04-10 10:32:32 -070058 switch (sku_id) {
Stephen Warren20583d02013-05-17 14:10:15 +000059 case SKU_ID_T20_7:
Simon Glassd5153622012-04-02 13:18:50 +000060 case SKU_ID_T20:
61 return TEGRA_SOC_T20;
62 case SKU_ID_T25SE:
63 case SKU_ID_AP25:
64 case SKU_ID_T25:
65 case SKU_ID_AP25E:
66 case SKU_ID_T25E:
67 return TEGRA_SOC_T25;
68 }
69 break;
Tom Warrenb2871032012-12-11 13:34:15 +000070 case CHIPID_TEGRA30:
Tom Warren49493cb2013-04-10 10:32:32 -070071 switch (sku_id) {
Stephen Warreneb222d12013-03-27 09:37:02 +000072 case SKU_ID_T33:
Tom Warrenb2871032012-12-11 13:34:15 +000073 case SKU_ID_T30:
Alban Bedel3346cbb2013-11-13 17:27:18 +010074 case SKU_ID_TM30MQS_P_A3:
Stephen Warren86b65782014-01-21 17:19:19 -070075 default:
Tom Warrenb2871032012-12-11 13:34:15 +000076 return TEGRA_SOC_T30;
77 }
78 break;
Tom Warrene23bb6a2013-01-28 13:32:10 +000079 case CHIPID_TEGRA114:
Tom Warren49493cb2013-04-10 10:32:32 -070080 switch (sku_id) {
Tom Warrene23bb6a2013-01-28 13:32:10 +000081 case SKU_ID_T114_ENG:
Stephen Warren840167c2013-05-17 14:10:14 +000082 case SKU_ID_T114_1:
Stephen Warren86b65782014-01-21 17:19:19 -070083 default:
Tom Warrene23bb6a2013-01-28 13:32:10 +000084 return TEGRA_SOC_T114;
85 }
86 break;
Tom Warren2f5dac92014-01-24 12:46:16 -070087 case CHIPID_TEGRA124:
88 switch (sku_id) {
89 case SKU_ID_T124_ENG:
90 default:
91 return TEGRA_SOC_T124;
92 }
93 break;
Simon Glassd5153622012-04-02 13:18:50 +000094 }
Tom Warren2f5dac92014-01-24 12:46:16 -070095
Tom Warren49493cb2013-04-10 10:32:32 -070096 /* unknown chip/sku id */
97 printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n",
98 __func__, chip_id, sku_id);
Simon Glassd5153622012-04-02 13:18:50 +000099 return TEGRA_SOC_UNKNOWN;
100}
101
Allen Martin12b7b702012-08-31 08:30:12 +0000102static void enable_scu(void)
Tom Warren74652cf2011-04-14 12:18:06 +0000103{
104 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
105 u32 reg;
106
Tom Warrendbc000b2013-05-23 12:26:18 +0000107 /* Only enable the SCU on T20/T25 */
108 if (tegra_get_chip() != CHIPID_TEGRA20)
109 return;
110
Tom Warren74652cf2011-04-14 12:18:06 +0000111 /* If SCU already setup/enabled, return */
112 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
113 return;
114
115 /* Invalidate all ways for all processors */
116 writel(0xFFFF, &scu->scu_inv_all);
117
118 /* Enable SCU - bit 0 */
119 reg = readl(&scu->scu_ctrl);
120 reg |= SCU_CTRL_ENABLE;
121 writel(reg, &scu->scu_ctrl);
122}
123
Tom Warren76e350b2012-05-30 14:06:09 -0700124static u32 get_odmdata(void)
125{
126 /*
127 * ODMDATA is stored in the BCT in IRAM by the BootROM.
128 * The BCT start and size are stored in the BIT in IRAM.
129 * Read the data @ bct_start + (bct_size - 12). This works
Tom Warren2f5dac92014-01-24 12:46:16 -0700130 * on BCTs for currently supported SoCs, which are locked down.
131 * If this changes in new chips, we can revisit this algorithm.
Tom Warren76e350b2012-05-30 14:06:09 -0700132 */
133
134 u32 bct_start, odmdata;
135
Tom Warrenb2871032012-12-11 13:34:15 +0000136 bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
Tom Warren76e350b2012-05-30 14:06:09 -0700137 odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
138
139 return odmdata;
140}
141
Allen Martin12b7b702012-08-31 08:30:12 +0000142static void init_pmc_scratch(void)
Tom Warren74652cf2011-04-14 12:18:06 +0000143{
Tom Warren29f3e3f2012-09-04 17:00:24 -0700144 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
Tom Warren76e350b2012-05-30 14:06:09 -0700145 u32 odmdata;
Tom Warren74652cf2011-04-14 12:18:06 +0000146 int i;
147
148 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
149 for (i = 0; i < 23; i++)
150 writel(0, &pmc->pmc_scratch1+i);
151
152 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
Tom Warren76e350b2012-05-30 14:06:09 -0700153 odmdata = get_odmdata();
154 writel(odmdata, &pmc->pmc_scratch20);
Tom Warren74652cf2011-04-14 12:18:06 +0000155}
156
Allen Martin12b7b702012-08-31 08:30:12 +0000157void s_init(void)
Tom Warren74652cf2011-04-14 12:18:06 +0000158{
Simon Glass210576f2011-11-05 03:56:50 +0000159 /* Init PMC scratch memory */
160 init_pmc_scratch();
Tom Warren74652cf2011-04-14 12:18:06 +0000161
Simon Glass210576f2011-11-05 03:56:50 +0000162 enable_scu();
163
Tom Warrend0edce42013-03-25 16:22:26 -0700164 /* init the cache */
165 config_cache();
Bryan Wudf3443d2014-06-24 11:45:29 +0900166
167 /* init vpr */
168 config_vpr();
Tom Warren74652cf2011-04-14 12:18:06 +0000169}