fuse.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <linux/tegra-soc.h>
  23. #include "fuse.h"
  24. #include "iomap.h"
  25. #include "apbio.h"
  26. #define FUSE_UID_LOW 0x108
  27. #define FUSE_UID_HIGH 0x10c
  28. #define FUSE_SKU_INFO 0x110
  29. #define TEGRA20_FUSE_SPARE_BIT 0x200
  30. #define TEGRA30_FUSE_SPARE_BIT 0x244
  31. int tegra_sku_id;
  32. int tegra_cpu_process_id;
  33. int tegra_core_process_id;
  34. int tegra_chip_id;
  35. int tegra_cpu_speedo_id; /* only exist in Tegra30 and later */
  36. int tegra_soc_speedo_id;
  37. enum tegra_revision tegra_revision;
  38. static int tegra_fuse_spare_bit;
  39. static void (*tegra_init_speedo_data)(void);
  40. /* The BCT to use at boot is specified by board straps that can be read
  41. * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
  42. */
  43. int tegra_bct_strapping;
  44. #define STRAP_OPT 0x008
  45. #define GMI_AD0 (1 << 4)
  46. #define GMI_AD1 (1 << 5)
  47. #define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
  48. #define RAM_CODE_SHIFT 4
  49. static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
  50. [TEGRA_REVISION_UNKNOWN] = "unknown",
  51. [TEGRA_REVISION_A01] = "A01",
  52. [TEGRA_REVISION_A02] = "A02",
  53. [TEGRA_REVISION_A03] = "A03",
  54. [TEGRA_REVISION_A03p] = "A03 prime",
  55. [TEGRA_REVISION_A04] = "A04",
  56. };
  57. u32 tegra_fuse_readl(unsigned long offset)
  58. {
  59. return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
  60. }
  61. bool tegra_spare_fuse(int bit)
  62. {
  63. return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4);
  64. }
  65. static enum tegra_revision tegra_get_revision(u32 id)
  66. {
  67. u32 minor_rev = (id >> 16) & 0xf;
  68. switch (minor_rev) {
  69. case 1:
  70. return TEGRA_REVISION_A01;
  71. case 2:
  72. return TEGRA_REVISION_A02;
  73. case 3:
  74. if (tegra_chip_id == TEGRA20 &&
  75. (tegra_spare_fuse(18) || tegra_spare_fuse(19)))
  76. return TEGRA_REVISION_A03p;
  77. else
  78. return TEGRA_REVISION_A03;
  79. case 4:
  80. return TEGRA_REVISION_A04;
  81. default:
  82. return TEGRA_REVISION_UNKNOWN;
  83. }
  84. }
  85. static void tegra_get_process_id(void)
  86. {
  87. u32 reg;
  88. reg = tegra_fuse_readl(tegra_fuse_spare_bit);
  89. tegra_cpu_process_id = (reg >> 6) & 3;
  90. reg = tegra_fuse_readl(tegra_fuse_spare_bit);
  91. tegra_core_process_id = (reg >> 12) & 3;
  92. }
  93. u32 tegra_read_chipid(void)
  94. {
  95. return readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
  96. }
  97. void tegra_init_fuse(void)
  98. {
  99. u32 id;
  100. u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
  101. reg |= 1 << 28;
  102. writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
  103. reg = tegra_fuse_readl(FUSE_SKU_INFO);
  104. tegra_sku_id = reg & 0xFF;
  105. reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
  106. tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
  107. id = tegra_read_chipid();
  108. tegra_chip_id = (id >> 8) & 0xff;
  109. switch (tegra_chip_id) {
  110. case TEGRA20:
  111. tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
  112. tegra_init_speedo_data = &tegra20_init_speedo_data;
  113. break;
  114. case TEGRA30:
  115. tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT;
  116. tegra_init_speedo_data = &tegra30_init_speedo_data;
  117. break;
  118. default:
  119. pr_warn("Tegra: unknown chip id %d\n", tegra_chip_id);
  120. tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
  121. tegra_init_speedo_data = &tegra_get_process_id;
  122. }
  123. tegra_revision = tegra_get_revision(id);
  124. tegra_init_speedo_data();
  125. pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
  126. tegra_revision_name[tegra_revision],
  127. tegra_sku_id, tegra_cpu_process_id,
  128. tegra_core_process_id);
  129. }
  130. unsigned long long tegra_chip_uid(void)
  131. {
  132. unsigned long long lo, hi;
  133. lo = tegra_fuse_readl(FUSE_UID_LOW);
  134. hi = tegra_fuse_readl(FUSE_UID_HIGH);
  135. return (hi << 32ull) | lo;
  136. }
  137. EXPORT_SYMBOL(tegra_chip_uid);