tegra-apbmisc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "fuse.h"
  23. #define APBMISC_BASE 0x70000800
  24. #define APBMISC_SIZE 0x64
  25. #define FUSE_SKU_INFO 0x10
  26. #define PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT 4
  27. #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG \
  28. (0xf << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
  29. #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \
  30. (0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
  31. static void __iomem *apbmisc_base;
  32. static void __iomem *strapping_base;
  33. static bool long_ram_code;
  34. u32 tegra_read_chipid(void)
  35. {
  36. return readl_relaxed(apbmisc_base + 4);
  37. }
  38. u8 tegra_get_chip_id(void)
  39. {
  40. if (!apbmisc_base) {
  41. WARN(1, "Tegra Chip ID not yet available\n");
  42. return 0;
  43. }
  44. return (tegra_read_chipid() >> 8) & 0xff;
  45. }
  46. u32 tegra_read_straps(void)
  47. {
  48. if (strapping_base)
  49. return readl_relaxed(strapping_base);
  50. else
  51. return 0;
  52. }
  53. u32 tegra_read_ram_code(void)
  54. {
  55. u32 straps = tegra_read_straps();
  56. if (long_ram_code)
  57. straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG;
  58. else
  59. straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT;
  60. return straps >> PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT;
  61. }
  62. static const struct of_device_id apbmisc_match[] __initconst = {
  63. { .compatible = "nvidia,tegra20-apbmisc", },
  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 && (tegra20_spare_fuse_early(18) ||
  82. tegra20_spare_fuse_early(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. if (chip_id == TEGRA20)
  95. tegra_sku_info.sku_id = tegra20_fuse_early(FUSE_SKU_INFO);
  96. else
  97. tegra_sku_info.sku_id = tegra30_fuse_readl(FUSE_SKU_INFO);
  98. }
  99. void __init tegra_init_apbmisc(void)
  100. {
  101. struct device_node *np;
  102. np = of_find_matching_node(NULL, apbmisc_match);
  103. apbmisc_base = of_iomap(np, 0);
  104. if (!apbmisc_base) {
  105. pr_warn("ioremap tegra apbmisc failed. using %08x instead\n",
  106. APBMISC_BASE);
  107. apbmisc_base = ioremap(APBMISC_BASE, APBMISC_SIZE);
  108. }
  109. strapping_base = of_iomap(np, 1);
  110. if (!strapping_base)
  111. pr_err("ioremap tegra strapping_base failed\n");
  112. long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code");
  113. }