fuse-tegra30.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <linux/device.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/io.h>
  21. #include <linux/kernel.h>
  22. #include <linux/of_device.h>
  23. #include <linux/of_address.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/random.h>
  26. #include <soc/tegra/fuse.h>
  27. #include "fuse.h"
  28. #define FUSE_BEGIN 0x100
  29. /* Tegra30 and later */
  30. #define FUSE_VENDOR_CODE 0x100
  31. #define FUSE_FAB_CODE 0x104
  32. #define FUSE_LOT_CODE_0 0x108
  33. #define FUSE_LOT_CODE_1 0x10c
  34. #define FUSE_WAFER_ID 0x110
  35. #define FUSE_X_COORDINATE 0x114
  36. #define FUSE_Y_COORDINATE 0x118
  37. #define FUSE_HAS_REVISION_INFO BIT(0)
  38. #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
  39. defined(CONFIG_ARCH_TEGRA_114_SOC) || \
  40. defined(CONFIG_ARCH_TEGRA_124_SOC) || \
  41. defined(CONFIG_ARCH_TEGRA_132_SOC) || \
  42. defined(CONFIG_ARCH_TEGRA_210_SOC) || \
  43. defined(CONFIG_ARCH_TEGRA_186_SOC) || \
  44. defined(CONFIG_ARCH_TEGRA_194_SOC)
  45. static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
  46. {
  47. if (WARN_ON(!fuse->base))
  48. return 0;
  49. return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
  50. }
  51. static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
  52. {
  53. u32 value;
  54. int err;
  55. err = clk_prepare_enable(fuse->clk);
  56. if (err < 0) {
  57. dev_err(fuse->dev, "failed to enable FUSE clock: %d\n", err);
  58. return 0;
  59. }
  60. value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
  61. clk_disable_unprepare(fuse->clk);
  62. return value;
  63. }
  64. static void __init tegra30_fuse_add_randomness(void)
  65. {
  66. u32 randomness[12];
  67. randomness[0] = tegra_sku_info.sku_id;
  68. randomness[1] = tegra_read_straps();
  69. randomness[2] = tegra_read_chipid();
  70. randomness[3] = tegra_sku_info.cpu_process_id << 16;
  71. randomness[3] |= tegra_sku_info.soc_process_id;
  72. randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
  73. randomness[4] |= tegra_sku_info.soc_speedo_id;
  74. randomness[5] = tegra_fuse_read_early(FUSE_VENDOR_CODE);
  75. randomness[6] = tegra_fuse_read_early(FUSE_FAB_CODE);
  76. randomness[7] = tegra_fuse_read_early(FUSE_LOT_CODE_0);
  77. randomness[8] = tegra_fuse_read_early(FUSE_LOT_CODE_1);
  78. randomness[9] = tegra_fuse_read_early(FUSE_WAFER_ID);
  79. randomness[10] = tegra_fuse_read_early(FUSE_X_COORDINATE);
  80. randomness[11] = tegra_fuse_read_early(FUSE_Y_COORDINATE);
  81. add_device_randomness(randomness, sizeof(randomness));
  82. }
  83. static void __init tegra30_fuse_init(struct tegra_fuse *fuse)
  84. {
  85. fuse->read_early = tegra30_fuse_read_early;
  86. fuse->read = tegra30_fuse_read;
  87. tegra_init_revision();
  88. if (fuse->soc->speedo_init)
  89. fuse->soc->speedo_init(&tegra_sku_info);
  90. tegra30_fuse_add_randomness();
  91. }
  92. #endif
  93. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  94. static const struct tegra_fuse_info tegra30_fuse_info = {
  95. .read = tegra30_fuse_read,
  96. .size = 0x2a4,
  97. .spare = 0x144,
  98. };
  99. const struct tegra_fuse_soc tegra30_fuse_soc = {
  100. .init = tegra30_fuse_init,
  101. .speedo_init = tegra30_init_speedo_data,
  102. .info = &tegra30_fuse_info,
  103. };
  104. #endif
  105. #ifdef CONFIG_ARCH_TEGRA_114_SOC
  106. static const struct tegra_fuse_info tegra114_fuse_info = {
  107. .read = tegra30_fuse_read,
  108. .size = 0x2a0,
  109. .spare = 0x180,
  110. };
  111. const struct tegra_fuse_soc tegra114_fuse_soc = {
  112. .init = tegra30_fuse_init,
  113. .speedo_init = tegra114_init_speedo_data,
  114. .info = &tegra114_fuse_info,
  115. };
  116. #endif
  117. #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
  118. static const struct tegra_fuse_info tegra124_fuse_info = {
  119. .read = tegra30_fuse_read,
  120. .size = 0x300,
  121. .spare = 0x200,
  122. };
  123. const struct tegra_fuse_soc tegra124_fuse_soc = {
  124. .init = tegra30_fuse_init,
  125. .speedo_init = tegra124_init_speedo_data,
  126. .info = &tegra124_fuse_info,
  127. };
  128. #endif
  129. #if defined(CONFIG_ARCH_TEGRA_210_SOC)
  130. static const struct tegra_fuse_info tegra210_fuse_info = {
  131. .read = tegra30_fuse_read,
  132. .size = 0x300,
  133. .spare = 0x280,
  134. };
  135. const struct tegra_fuse_soc tegra210_fuse_soc = {
  136. .init = tegra30_fuse_init,
  137. .speedo_init = tegra210_init_speedo_data,
  138. .info = &tegra210_fuse_info,
  139. };
  140. #endif
  141. #if defined(CONFIG_ARCH_TEGRA_186_SOC)
  142. static const struct tegra_fuse_info tegra186_fuse_info = {
  143. .read = tegra30_fuse_read,
  144. .size = 0x300,
  145. .spare = 0x280,
  146. };
  147. const struct tegra_fuse_soc tegra186_fuse_soc = {
  148. .init = tegra30_fuse_init,
  149. .info = &tegra186_fuse_info,
  150. };
  151. #endif