ap.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /* Tegra AP (Application Processor) code */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/gp_padctrl.h>
  27. #include <asm/arch-tegra/ap.h>
  28. #include <asm/arch-tegra/clock.h>
  29. #include <asm/arch-tegra/fuse.h>
  30. #include <asm/arch-tegra/pmc.h>
  31. #include <asm/arch-tegra/scu.h>
  32. #include <asm/arch-tegra/tegra.h>
  33. #include <asm/arch-tegra/warmboot.h>
  34. int tegra_get_chip_type(void)
  35. {
  36. struct apb_misc_gp_ctlr *gp;
  37. struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
  38. uint tegra_sku_id, rev;
  39. /*
  40. * This is undocumented, Chip ID is bits 15:8 of the register
  41. * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
  42. * Tegra30, and 0x35 for T114.
  43. */
  44. gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
  45. rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
  46. tegra_sku_id = readl(&fuse->sku_info) & 0xff;
  47. switch (rev) {
  48. case CHIPID_TEGRA20:
  49. switch (tegra_sku_id) {
  50. case SKU_ID_T20:
  51. return TEGRA_SOC_T20;
  52. case SKU_ID_T25SE:
  53. case SKU_ID_AP25:
  54. case SKU_ID_T25:
  55. case SKU_ID_AP25E:
  56. case SKU_ID_T25E:
  57. return TEGRA_SOC_T25;
  58. }
  59. break;
  60. case CHIPID_TEGRA30:
  61. switch (tegra_sku_id) {
  62. case SKU_ID_T30:
  63. return TEGRA_SOC_T30;
  64. }
  65. break;
  66. case CHIPID_TEGRA114:
  67. switch (tegra_sku_id) {
  68. case SKU_ID_T114_ENG:
  69. return TEGRA_SOC_T114;
  70. }
  71. break;
  72. }
  73. /* unknown sku id */
  74. return TEGRA_SOC_UNKNOWN;
  75. }
  76. static void enable_scu(void)
  77. {
  78. struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
  79. u32 reg;
  80. /* If SCU already setup/enabled, return */
  81. if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
  82. return;
  83. /* Invalidate all ways for all processors */
  84. writel(0xFFFF, &scu->scu_inv_all);
  85. /* Enable SCU - bit 0 */
  86. reg = readl(&scu->scu_ctrl);
  87. reg |= SCU_CTRL_ENABLE;
  88. writel(reg, &scu->scu_ctrl);
  89. }
  90. static u32 get_odmdata(void)
  91. {
  92. /*
  93. * ODMDATA is stored in the BCT in IRAM by the BootROM.
  94. * The BCT start and size are stored in the BIT in IRAM.
  95. * Read the data @ bct_start + (bct_size - 12). This works
  96. * on T20 and T30 BCTs, which are locked down. If this changes
  97. * in new chips (T114, etc.), we can revisit this algorithm.
  98. */
  99. u32 bct_start, odmdata;
  100. bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
  101. odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
  102. return odmdata;
  103. }
  104. static void init_pmc_scratch(void)
  105. {
  106. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  107. u32 odmdata;
  108. int i;
  109. /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
  110. for (i = 0; i < 23; i++)
  111. writel(0, &pmc->pmc_scratch1+i);
  112. /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
  113. odmdata = get_odmdata();
  114. writel(odmdata, &pmc->pmc_scratch20);
  115. }
  116. void s_init(void)
  117. {
  118. /* Init PMC scratch memory */
  119. init_pmc_scratch();
  120. enable_scu();
  121. /* enable SMP mode and FW for CPU0, by writing to Auxiliary Ctl reg */
  122. asm volatile(
  123. "mrc p15, 0, r0, c1, c0, 1\n"
  124. "orr r0, r0, #0x41\n"
  125. "mcr p15, 0, r0, c1, c0, 1\n");
  126. /* FIXME: should have SoC's L2 disabled too? */
  127. }