tegra-apbmisc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. if (!apbmisc_base) {
  36. WARN(1, "Tegra Chip ID not yet available\n");
  37. return 0;
  38. }
  39. return readl_relaxed(apbmisc_base + 4);
  40. }
  41. u8 tegra_get_chip_id(void)
  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. { .compatible = "nvidia,tegra186-misc", },
  64. {},
  65. };
  66. void __init tegra_init_revision(void)
  67. {
  68. u32 id, chip_id, minor_rev;
  69. int rev;
  70. id = tegra_read_chipid();
  71. chip_id = (id >> 8) & 0xff;
  72. minor_rev = (id >> 16) & 0xf;
  73. switch (minor_rev) {
  74. case 1:
  75. rev = TEGRA_REVISION_A01;
  76. break;
  77. case 2:
  78. rev = TEGRA_REVISION_A02;
  79. break;
  80. case 3:
  81. if (chip_id == TEGRA20 && (tegra_fuse_read_spare(18) ||
  82. tegra_fuse_read_spare(19)))
  83. rev = TEGRA_REVISION_A03p;
  84. else
  85. rev = TEGRA_REVISION_A03;
  86. break;
  87. case 4:
  88. rev = TEGRA_REVISION_A04;
  89. break;
  90. default:
  91. rev = TEGRA_REVISION_UNKNOWN;
  92. }
  93. tegra_sku_info.revision = rev;
  94. tegra_sku_info.sku_id = tegra_fuse_read_early(FUSE_SKU_INFO);
  95. }
  96. void __init tegra_init_apbmisc(void)
  97. {
  98. struct resource apbmisc, straps;
  99. struct device_node *np;
  100. np = of_find_matching_node(NULL, apbmisc_match);
  101. if (!np) {
  102. /*
  103. * Fall back to legacy initialization for 32-bit ARM only. All
  104. * 64-bit ARM device tree files for Tegra are required to have
  105. * an APBMISC node.
  106. *
  107. * This is for backwards-compatibility with old device trees
  108. * that didn't contain an APBMISC node.
  109. */
  110. if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
  111. /* APBMISC registers (chip revision, ...) */
  112. apbmisc.start = 0x70000800;
  113. apbmisc.end = 0x70000863;
  114. apbmisc.flags = IORESOURCE_MEM;
  115. /* strapping options */
  116. if (of_machine_is_compatible("nvidia,tegra124")) {
  117. straps.start = 0x7000e864;
  118. straps.end = 0x7000e867;
  119. } else {
  120. straps.start = 0x70000008;
  121. straps.end = 0x7000000b;
  122. }
  123. straps.flags = IORESOURCE_MEM;
  124. pr_warn("Using APBMISC region %pR\n", &apbmisc);
  125. pr_warn("Using strapping options registers %pR\n",
  126. &straps);
  127. } else {
  128. /*
  129. * At this point we're not running on Tegra, so play
  130. * nice with multi-platform kernels.
  131. */
  132. return;
  133. }
  134. } else {
  135. /*
  136. * Extract information from the device tree if we've found a
  137. * matching node.
  138. */
  139. if (of_address_to_resource(np, 0, &apbmisc) < 0) {
  140. pr_err("failed to get APBMISC registers\n");
  141. return;
  142. }
  143. if (of_address_to_resource(np, 1, &straps) < 0) {
  144. pr_err("failed to get strapping options registers\n");
  145. return;
  146. }
  147. }
  148. apbmisc_base = ioremap_nocache(apbmisc.start, resource_size(&apbmisc));
  149. if (!apbmisc_base)
  150. pr_err("failed to map APBMISC registers\n");
  151. strapping_base = ioremap_nocache(straps.start, resource_size(&straps));
  152. if (!strapping_base)
  153. pr_err("failed to map strapping options registers\n");
  154. long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code");
  155. }