tegra-apbmisc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/io.h>
  21. #include <soc/tegra/fuse.h>
  22. #include <soc/tegra/common.h>
  23. #include "fuse.h"
  24. #define FUSE_SKU_INFO 0x10
  25. #define PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT 4
  26. #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG \
  27. (0xf << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
  28. #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \
  29. (0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
  30. static void __iomem *apbmisc_base;
  31. static void __iomem *strapping_base;
  32. static bool long_ram_code;
  33. u32 tegra_read_chipid(void)
  34. {
  35. return readl_relaxed(apbmisc_base + 4);
  36. }
  37. u8 tegra_get_chip_id(void)
  38. {
  39. if (!apbmisc_base) {
  40. WARN(1, "Tegra Chip ID not yet available\n");
  41. return 0;
  42. }
  43. return (tegra_read_chipid() >> 8) & 0xff;
  44. }
  45. u32 tegra_read_straps(void)
  46. {
  47. if (strapping_base)
  48. return readl_relaxed(strapping_base);
  49. else
  50. return 0;
  51. }
  52. u32 tegra_read_ram_code(void)
  53. {
  54. u32 straps = tegra_read_straps();
  55. if (long_ram_code)
  56. straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG;
  57. else
  58. straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT;
  59. return straps >> PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT;
  60. }
  61. static const struct of_device_id apbmisc_match[] __initconst = {
  62. { .compatible = "nvidia,tegra20-apbmisc", },
  63. {},
  64. };
  65. void __init tegra_init_revision(void)
  66. {
  67. u32 id, chip_id, minor_rev;
  68. int rev;
  69. id = tegra_read_chipid();
  70. chip_id = (id >> 8) & 0xff;
  71. minor_rev = (id >> 16) & 0xf;
  72. switch (minor_rev) {
  73. case 1:
  74. rev = TEGRA_REVISION_A01;
  75. break;
  76. case 2:
  77. rev = TEGRA_REVISION_A02;
  78. break;
  79. case 3:
  80. if (chip_id == TEGRA20 && (tegra_fuse_read_spare(18) ||
  81. tegra_fuse_read_spare(19)))
  82. rev = TEGRA_REVISION_A03p;
  83. else
  84. rev = TEGRA_REVISION_A03;
  85. break;
  86. case 4:
  87. rev = TEGRA_REVISION_A04;
  88. break;
  89. default:
  90. rev = TEGRA_REVISION_UNKNOWN;
  91. }
  92. tegra_sku_info.revision = rev;
  93. tegra_sku_info.sku_id = tegra_fuse_read_early(FUSE_SKU_INFO);
  94. }
  95. void __init tegra_init_apbmisc(void)
  96. {
  97. struct resource apbmisc, straps;
  98. struct device_node *np;
  99. np = of_find_matching_node(NULL, apbmisc_match);
  100. if (!np) {
  101. /*
  102. * Fall back to legacy initialization for 32-bit ARM only. All
  103. * 64-bit ARM device tree files for Tegra are required to have
  104. * an APBMISC node.
  105. *
  106. * This is for backwards-compatibility with old device trees
  107. * that didn't contain an APBMISC node.
  108. */
  109. if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
  110. /* APBMISC registers (chip revision, ...) */
  111. apbmisc.start = 0x70000800;
  112. apbmisc.end = 0x70000863;
  113. apbmisc.flags = IORESOURCE_MEM;
  114. /* strapping options */
  115. if (tegra_get_chip_id() == TEGRA124) {
  116. straps.start = 0x7000e864;
  117. straps.end = 0x7000e867;
  118. } else {
  119. straps.start = 0x70000008;
  120. straps.end = 0x7000000b;
  121. }
  122. straps.flags = IORESOURCE_MEM;
  123. pr_warn("Using APBMISC region %pR\n", &apbmisc);
  124. pr_warn("Using strapping options registers %pR\n",
  125. &straps);
  126. } else {
  127. /*
  128. * At this point we're not running on Tegra, so play
  129. * nice with multi-platform kernels.
  130. */
  131. return;
  132. }
  133. } else {
  134. /*
  135. * Extract information from the device tree if we've found a
  136. * matching node.
  137. */
  138. if (of_address_to_resource(np, 0, &apbmisc) < 0) {
  139. pr_err("failed to get APBMISC registers\n");
  140. return;
  141. }
  142. if (of_address_to_resource(np, 1, &straps) < 0) {
  143. pr_err("failed to get strapping options registers\n");
  144. return;
  145. }
  146. }
  147. apbmisc_base = ioremap_nocache(apbmisc.start, resource_size(&apbmisc));
  148. if (!apbmisc_base)
  149. pr_err("failed to map APBMISC registers\n");
  150. strapping_base = ioremap_nocache(straps.start, resource_size(&straps));
  151. if (!strapping_base)
  152. pr_err("failed to map strapping options registers\n");
  153. long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code");
  154. }