fuse.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <mach/iomap.h>
  22. #include "fuse.h"
  23. #include "apbio.h"
  24. #define FUSE_UID_LOW 0x108
  25. #define FUSE_UID_HIGH 0x10c
  26. #define FUSE_SKU_INFO 0x110
  27. #define FUSE_SPARE_BIT 0x200
  28. int tegra_sku_id;
  29. int tegra_cpu_process_id;
  30. int tegra_core_process_id;
  31. enum tegra_revision tegra_revision;
  32. static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
  33. [TEGRA_REVISION_UNKNOWN] = "unknown",
  34. [TEGRA_REVISION_A01] = "A01",
  35. [TEGRA_REVISION_A02] = "A02",
  36. [TEGRA_REVISION_A03] = "A03",
  37. [TEGRA_REVISION_A03p] = "A03 prime",
  38. [TEGRA_REVISION_A04] = "A04",
  39. };
  40. static inline u32 tegra_fuse_readl(unsigned long offset)
  41. {
  42. return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
  43. }
  44. static inline bool get_spare_fuse(int bit)
  45. {
  46. return tegra_fuse_readl(FUSE_SPARE_BIT + bit * 4);
  47. }
  48. static enum tegra_revision tegra_get_revision(void)
  49. {
  50. void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804;
  51. u32 id = readl(chip_id);
  52. u32 minor_rev = (id >> 16) & 0xf;
  53. u32 chipid = (id >> 8) & 0xff;
  54. switch (minor_rev) {
  55. case 1:
  56. return TEGRA_REVISION_A01;
  57. case 2:
  58. return TEGRA_REVISION_A02;
  59. case 3:
  60. if (chipid == 0x20 && (get_spare_fuse(18) || get_spare_fuse(19)))
  61. return TEGRA_REVISION_A03p;
  62. else
  63. return TEGRA_REVISION_A03;
  64. case 4:
  65. return TEGRA_REVISION_A04;
  66. default:
  67. return TEGRA_REVISION_UNKNOWN;
  68. }
  69. }
  70. void tegra_init_fuse(void)
  71. {
  72. u32 reg = readl(IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
  73. reg |= 1 << 28;
  74. writel(reg, IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
  75. reg = tegra_fuse_readl(FUSE_SKU_INFO);
  76. tegra_sku_id = reg & 0xFF;
  77. reg = tegra_fuse_readl(FUSE_SPARE_BIT);
  78. tegra_cpu_process_id = (reg >> 6) & 3;
  79. reg = tegra_fuse_readl(FUSE_SPARE_BIT);
  80. tegra_core_process_id = (reg >> 12) & 3;
  81. tegra_revision = tegra_get_revision();
  82. pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
  83. tegra_revision_name[tegra_get_revision()],
  84. tegra_sku_id, tegra_cpu_process_id,
  85. tegra_core_process_id);
  86. }
  87. unsigned long long tegra_chip_uid(void)
  88. {
  89. unsigned long long lo, hi;
  90. lo = tegra_fuse_readl(FUSE_UID_LOW);
  91. hi = tegra_fuse_readl(FUSE_UID_HIGH);
  92. return (hi << 32ull) | lo;
  93. }