]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/tegra-common/ap.c
Merge branch 'next'
[karo-tx-uboot.git] / arch / arm / cpu / tegra-common / ap.c
1 /*
2 * (C) Copyright 2010-2011
3 * NVIDIA Corporation <www.nvidia.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 /* Tegra AP (Application Processor) code */
25
26 #include <common.h>
27 #include <asm/io.h>
28 #include <asm/arch/gp_padctrl.h>
29 #include <asm/arch-tegra/ap.h>
30 #include <asm/arch-tegra/clock.h>
31 #include <asm/arch-tegra/fuse.h>
32 #include <asm/arch-tegra/pmc.h>
33 #include <asm/arch-tegra/scu.h>
34 #include <asm/arch-tegra/tegra.h>
35 #include <asm/arch-tegra/warmboot.h>
36
37 int tegra_get_chip(void)
38 {
39         int rev;
40         struct apb_misc_gp_ctlr *gp =
41                 (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
42
43         /*
44          * This is undocumented, Chip ID is bits 15:8 of the register
45          * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
46          * Tegra30, and 0x35 for T114.
47          */
48         rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
49         debug("%s: CHIPID is 0x%02X\n", __func__, rev);
50
51         return rev;
52 }
53
54 int tegra_get_sku_info(void)
55 {
56         int sku_id;
57         struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
58
59         sku_id = readl(&fuse->sku_info) & 0xff;
60         debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id);
61
62         return sku_id;
63 }
64
65 int tegra_get_chip_sku(void)
66 {
67         uint sku_id, chip_id;
68
69         chip_id = tegra_get_chip();
70         sku_id = tegra_get_sku_info();
71
72         switch (chip_id) {
73         case CHIPID_TEGRA20:
74                 switch (sku_id) {
75                 case SKU_ID_T20:
76                         return TEGRA_SOC_T20;
77                 case SKU_ID_T25SE:
78                 case SKU_ID_AP25:
79                 case SKU_ID_T25:
80                 case SKU_ID_AP25E:
81                 case SKU_ID_T25E:
82                         return TEGRA_SOC_T25;
83                 }
84                 break;
85         case CHIPID_TEGRA30:
86                 switch (sku_id) {
87                 case SKU_ID_T33:
88                 case SKU_ID_T30:
89                         return TEGRA_SOC_T30;
90                 }
91                 break;
92         case CHIPID_TEGRA114:
93                 switch (sku_id) {
94                 case SKU_ID_T114_ENG:
95                         return TEGRA_SOC_T114;
96                 }
97                 break;
98         }
99         /* unknown chip/sku id */
100         printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n",
101                 __func__, chip_id, sku_id);
102         return TEGRA_SOC_UNKNOWN;
103 }
104
105 static void enable_scu(void)
106 {
107         struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
108         u32 reg;
109
110         /* If SCU already setup/enabled, return */
111         if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
112                 return;
113
114         /* Invalidate all ways for all processors */
115         writel(0xFFFF, &scu->scu_inv_all);
116
117         /* Enable SCU - bit 0 */
118         reg = readl(&scu->scu_ctrl);
119         reg |= SCU_CTRL_ENABLE;
120         writel(reg, &scu->scu_ctrl);
121 }
122
123 static u32 get_odmdata(void)
124 {
125         /*
126          * ODMDATA is stored in the BCT in IRAM by the BootROM.
127          * The BCT start and size are stored in the BIT in IRAM.
128          * Read the data @ bct_start + (bct_size - 12). This works
129          * on T20 and T30 BCTs, which are locked down. If this changes
130          * in new chips (T114, etc.), we can revisit this algorithm.
131          */
132
133         u32 bct_start, odmdata;
134
135         bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
136         odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
137
138         return odmdata;
139 }
140
141 static void init_pmc_scratch(void)
142 {
143         struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
144         u32 odmdata;
145         int i;
146
147         /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
148         for (i = 0; i < 23; i++)
149                 writel(0, &pmc->pmc_scratch1+i);
150
151         /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
152         odmdata = get_odmdata();
153         writel(odmdata, &pmc->pmc_scratch20);
154 }
155
156 void s_init(void)
157 {
158         /* Init PMC scratch memory */
159         init_pmc_scratch();
160
161         enable_scu();
162
163         /* init the cache */
164         config_cache();
165 }