ap.c 3.6 KB

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