fuse.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * arch/arm/mach-tegra/fuse.c
  3. *
  4. * Copyright (C) 2010 Google, Inc.
  5. * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
  6. *
  7. * Author:
  8. * Colin Cross <ccross@android.com>
  9. *
  10. * This software is licensed under the terms of the GNU General Public
  11. * License version 2, as published by the Free Software Foundation, and
  12. * may be copied, distributed, and modified under those terms.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/io.h>
  22. #include <linux/export.h>
  23. #include <linux/tegra-soc.h>
  24. #include "fuse.h"
  25. #include "iomap.h"
  26. #include "apbio.h"
  27. #define FUSE_UID_LOW 0x108
  28. #define FUSE_UID_HIGH 0x10c
  29. #define FUSE_SKU_INFO 0x110
  30. #define TEGRA20_FUSE_SPARE_BIT 0x200
  31. #define TEGRA30_FUSE_SPARE_BIT 0x244
  32. int tegra_sku_id;
  33. int tegra_cpu_process_id;
  34. int tegra_core_process_id;
  35. int tegra_chip_id;
  36. int tegra_cpu_speedo_id; /* only exist in Tegra30 and later */
  37. int tegra_soc_speedo_id;
  38. enum tegra_revision tegra_revision;
  39. static int tegra_fuse_spare_bit;
  40. static void (*tegra_init_speedo_data)(void);
  41. /* The BCT to use at boot is specified by board straps that can be read
  42. * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
  43. */
  44. int tegra_bct_strapping;
  45. #define STRAP_OPT 0x008
  46. #define GMI_AD0 (1 << 4)
  47. #define GMI_AD1 (1 << 5)
  48. #define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
  49. #define RAM_CODE_SHIFT 4
  50. static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
  51. [TEGRA_REVISION_UNKNOWN] = "unknown",
  52. [TEGRA_REVISION_A01] = "A01",
  53. [TEGRA_REVISION_A02] = "A02",
  54. [TEGRA_REVISION_A03] = "A03",
  55. [TEGRA_REVISION_A03p] = "A03 prime",
  56. [TEGRA_REVISION_A04] = "A04",
  57. };
  58. u32 tegra_fuse_readl(unsigned long offset)
  59. {
  60. return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
  61. }
  62. bool tegra_spare_fuse(int bit)
  63. {
  64. return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4);
  65. }
  66. static enum tegra_revision tegra_get_revision(u32 id)
  67. {
  68. u32 minor_rev = (id >> 16) & 0xf;
  69. switch (minor_rev) {
  70. case 1:
  71. return TEGRA_REVISION_A01;
  72. case 2:
  73. return TEGRA_REVISION_A02;
  74. case 3:
  75. if (tegra_chip_id == TEGRA20 &&
  76. (tegra_spare_fuse(18) || tegra_spare_fuse(19)))
  77. return TEGRA_REVISION_A03p;
  78. else
  79. return TEGRA_REVISION_A03;
  80. case 4:
  81. return TEGRA_REVISION_A04;
  82. default:
  83. return TEGRA_REVISION_UNKNOWN;
  84. }
  85. }
  86. static void tegra_get_process_id(void)
  87. {
  88. u32 reg;
  89. reg = tegra_fuse_readl(tegra_fuse_spare_bit);
  90. tegra_cpu_process_id = (reg >> 6) & 3;
  91. reg = tegra_fuse_readl(tegra_fuse_spare_bit);
  92. tegra_core_process_id = (reg >> 12) & 3;
  93. }
  94. u32 tegra_read_chipid(void)
  95. {
  96. return readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
  97. }
  98. void tegra_init_fuse(void)
  99. {
  100. u32 id;
  101. u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
  102. reg |= 1 << 28;
  103. writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
  104. reg = tegra_fuse_readl(FUSE_SKU_INFO);
  105. tegra_sku_id = reg & 0xFF;
  106. reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
  107. tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
  108. id = tegra_read_chipid();
  109. tegra_chip_id = (id >> 8) & 0xff;
  110. switch (tegra_chip_id) {
  111. case TEGRA20:
  112. tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
  113. tegra_init_speedo_data = &tegra20_init_speedo_data;
  114. break;
  115. case TEGRA30:
  116. tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT;
  117. tegra_init_speedo_data = &tegra30_init_speedo_data;
  118. break;
  119. case TEGRA114:
  120. tegra_init_speedo_data = &tegra114_init_speedo_data;
  121. break;
  122. default:
  123. pr_warn("Tegra: unknown chip id %d\n", tegra_chip_id);
  124. tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
  125. tegra_init_speedo_data = &tegra_get_process_id;
  126. }
  127. tegra_revision = tegra_get_revision(id);
  128. tegra_init_speedo_data();
  129. pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
  130. tegra_revision_name[tegra_revision],
  131. tegra_sku_id, tegra_cpu_process_id,
  132. tegra_core_process_id);
  133. }
  134. unsigned long long tegra_chip_uid(void)
  135. {
  136. unsigned long long lo, hi;
  137. lo = tegra_fuse_readl(FUSE_UID_LOW);
  138. hi = tegra_fuse_readl(FUSE_UID_HIGH);
  139. return (hi << 32ull) | lo;
  140. }
  141. EXPORT_SYMBOL(tegra_chip_uid);