ap.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * (C) Copyright 2010-2014
  3. * NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* Tegra AP (Application Processor) code */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/gp_padctrl.h>
  11. #include <asm/arch/mc.h>
  12. #include <asm/arch-tegra/ap.h>
  13. #include <asm/arch-tegra/clock.h>
  14. #include <asm/arch-tegra/fuse.h>
  15. #include <asm/arch-tegra/pmc.h>
  16. #include <asm/arch-tegra/scu.h>
  17. #include <asm/arch-tegra/tegra.h>
  18. #include <asm/arch-tegra/warmboot.h>
  19. int tegra_get_chip(void)
  20. {
  21. int rev;
  22. struct apb_misc_gp_ctlr *gp =
  23. (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
  24. /*
  25. * This is undocumented, Chip ID is bits 15:8 of the register
  26. * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
  27. * Tegra30, 0x35 for T114, and 0x40 for Tegra124.
  28. */
  29. rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
  30. debug("%s: CHIPID is 0x%02X\n", __func__, rev);
  31. return rev;
  32. }
  33. int tegra_get_sku_info(void)
  34. {
  35. int sku_id;
  36. struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
  37. sku_id = readl(&fuse->sku_info) & 0xff;
  38. debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id);
  39. return sku_id;
  40. }
  41. int tegra_get_chip_sku(void)
  42. {
  43. uint sku_id, chip_id;
  44. chip_id = tegra_get_chip();
  45. sku_id = tegra_get_sku_info();
  46. switch (chip_id) {
  47. case CHIPID_TEGRA20:
  48. switch (sku_id) {
  49. case SKU_ID_T20_7:
  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 (sku_id) {
  62. case SKU_ID_T33:
  63. case SKU_ID_T30:
  64. case SKU_ID_TM30MQS_P_A3:
  65. default:
  66. return TEGRA_SOC_T30;
  67. }
  68. break;
  69. case CHIPID_TEGRA114:
  70. switch (sku_id) {
  71. case SKU_ID_T114_ENG:
  72. case SKU_ID_T114_1:
  73. default:
  74. return TEGRA_SOC_T114;
  75. }
  76. break;
  77. case CHIPID_TEGRA124:
  78. switch (sku_id) {
  79. case SKU_ID_T124_ENG:
  80. default:
  81. return TEGRA_SOC_T124;
  82. }
  83. break;
  84. }
  85. /* unknown chip/sku id */
  86. printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n",
  87. __func__, chip_id, sku_id);
  88. return TEGRA_SOC_UNKNOWN;
  89. }
  90. static void enable_scu(void)
  91. {
  92. struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
  93. u32 reg;
  94. /* Only enable the SCU on T20/T25 */
  95. if (tegra_get_chip() != CHIPID_TEGRA20)
  96. return;
  97. /* If SCU already setup/enabled, return */
  98. if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
  99. return;
  100. /* Invalidate all ways for all processors */
  101. writel(0xFFFF, &scu->scu_inv_all);
  102. /* Enable SCU - bit 0 */
  103. reg = readl(&scu->scu_ctrl);
  104. reg |= SCU_CTRL_ENABLE;
  105. writel(reg, &scu->scu_ctrl);
  106. }
  107. static u32 get_odmdata(void)
  108. {
  109. /*
  110. * ODMDATA is stored in the BCT in IRAM by the BootROM.
  111. * The BCT start and size are stored in the BIT in IRAM.
  112. * Read the data @ bct_start + (bct_size - 12). This works
  113. * on BCTs for currently supported SoCs, which are locked down.
  114. * If this changes in new chips, we can revisit this algorithm.
  115. */
  116. u32 bct_start, odmdata;
  117. bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
  118. odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
  119. return odmdata;
  120. }
  121. static void init_pmc_scratch(void)
  122. {
  123. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  124. u32 odmdata;
  125. int i;
  126. /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
  127. for (i = 0; i < 23; i++)
  128. writel(0, &pmc->pmc_scratch1+i);
  129. /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
  130. odmdata = get_odmdata();
  131. writel(odmdata, &pmc->pmc_scratch20);
  132. }
  133. #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
  134. void protect_secure_section(void)
  135. {
  136. struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
  137. /* Must be MB aligned */
  138. BUILD_BUG_ON(CONFIG_ARMV7_SECURE_BASE & 0xFFFFF);
  139. BUILD_BUG_ON(CONFIG_ARMV7_SECURE_RESERVE_SIZE & 0xFFFFF);
  140. writel(CONFIG_ARMV7_SECURE_BASE, &mc->mc_security_cfg0);
  141. writel(CONFIG_ARMV7_SECURE_RESERVE_SIZE >> 20, &mc->mc_security_cfg1);
  142. }
  143. #endif
  144. void s_init(void)
  145. {
  146. /* Init PMC scratch memory */
  147. init_pmc_scratch();
  148. enable_scu();
  149. /* init the cache */
  150. config_cache();
  151. /* init vpr */
  152. config_vpr();
  153. }