fuse.c 3.9 KB

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