fuse.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <mach/iomap.h>
  23. #include "fuse.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 FUSE_SPARE_BIT 0x200
  29. int tegra_sku_id;
  30. int tegra_cpu_process_id;
  31. int tegra_core_process_id;
  32. int tegra_chip_id;
  33. enum tegra_revision tegra_revision;
  34. /* The BCT to use at boot is specified by board straps that can be read
  35. * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
  36. */
  37. int tegra_bct_strapping;
  38. #define STRAP_OPT 0x008
  39. #define GMI_AD0 (1 << 4)
  40. #define GMI_AD1 (1 << 5)
  41. #define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
  42. #define RAM_CODE_SHIFT 4
  43. static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
  44. [TEGRA_REVISION_UNKNOWN] = "unknown",
  45. [TEGRA_REVISION_A01] = "A01",
  46. [TEGRA_REVISION_A02] = "A02",
  47. [TEGRA_REVISION_A03] = "A03",
  48. [TEGRA_REVISION_A03p] = "A03 prime",
  49. [TEGRA_REVISION_A04] = "A04",
  50. };
  51. static inline u32 tegra_fuse_readl(unsigned long offset)
  52. {
  53. return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
  54. }
  55. static inline bool get_spare_fuse(int bit)
  56. {
  57. return tegra_fuse_readl(FUSE_SPARE_BIT + bit * 4);
  58. }
  59. static enum tegra_revision tegra_get_revision(u32 id)
  60. {
  61. u32 minor_rev = (id >> 16) & 0xf;
  62. switch (minor_rev) {
  63. case 1:
  64. return TEGRA_REVISION_A01;
  65. case 2:
  66. return TEGRA_REVISION_A02;
  67. case 3:
  68. if (tegra_chip_id == TEGRA20 &&
  69. (get_spare_fuse(18) || get_spare_fuse(19)))
  70. return TEGRA_REVISION_A03p;
  71. else
  72. return TEGRA_REVISION_A03;
  73. case 4:
  74. return TEGRA_REVISION_A04;
  75. default:
  76. return TEGRA_REVISION_UNKNOWN;
  77. }
  78. }
  79. void tegra_init_fuse(void)
  80. {
  81. u32 id;
  82. u32 reg = readl(IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
  83. reg |= 1 << 28;
  84. writel(reg, IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
  85. reg = tegra_fuse_readl(FUSE_SKU_INFO);
  86. tegra_sku_id = reg & 0xFF;
  87. reg = tegra_fuse_readl(FUSE_SPARE_BIT);
  88. tegra_cpu_process_id = (reg >> 6) & 3;
  89. reg = tegra_fuse_readl(FUSE_SPARE_BIT);
  90. tegra_core_process_id = (reg >> 12) & 3;
  91. reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
  92. tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
  93. id = readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
  94. tegra_chip_id = (id >> 8) & 0xff;
  95. tegra_revision = tegra_get_revision(id);
  96. pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
  97. tegra_revision_name[tegra_revision],
  98. tegra_sku_id, tegra_cpu_process_id,
  99. tegra_core_process_id);
  100. }
  101. unsigned long long tegra_chip_uid(void)
  102. {
  103. unsigned long long lo, hi;
  104. lo = tegra_fuse_readl(FUSE_UID_LOW);
  105. hi = tegra_fuse_readl(FUSE_UID_HIGH);
  106. return (hi << 32ull) | lo;
  107. }
  108. EXPORT_SYMBOL(tegra_chip_uid);