speedo-tegra210.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2013-2015, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <linux/device.h>
  6. #include <linux/kernel.h>
  7. #include <linux/bug.h>
  8. #include <soc/tegra/fuse.h>
  9. #include "fuse.h"
  10. #define CPU_PROCESS_CORNERS 2
  11. #define GPU_PROCESS_CORNERS 2
  12. #define SOC_PROCESS_CORNERS 3
  13. #define FUSE_CPU_SPEEDO_0 0x014
  14. #define FUSE_CPU_SPEEDO_1 0x02c
  15. #define FUSE_CPU_SPEEDO_2 0x030
  16. #define FUSE_SOC_SPEEDO_0 0x034
  17. #define FUSE_SOC_SPEEDO_1 0x038
  18. #define FUSE_SOC_SPEEDO_2 0x03c
  19. #define FUSE_CPU_IDDQ 0x018
  20. #define FUSE_SOC_IDDQ 0x040
  21. #define FUSE_GPU_IDDQ 0x128
  22. #define FUSE_FT_REV 0x028
  23. enum {
  24. THRESHOLD_INDEX_0,
  25. THRESHOLD_INDEX_1,
  26. THRESHOLD_INDEX_COUNT,
  27. };
  28. static const u32 __initconst cpu_process_speedos[][CPU_PROCESS_CORNERS] = {
  29. { 2119, UINT_MAX },
  30. { 2119, UINT_MAX },
  31. };
  32. static const u32 __initconst gpu_process_speedos[][GPU_PROCESS_CORNERS] = {
  33. { UINT_MAX, UINT_MAX },
  34. { UINT_MAX, UINT_MAX },
  35. };
  36. static const u32 __initconst soc_process_speedos[][SOC_PROCESS_CORNERS] = {
  37. { 1950, 2100, UINT_MAX },
  38. { 1950, 2100, UINT_MAX },
  39. };
  40. static u8 __init get_speedo_revision(void)
  41. {
  42. return tegra_fuse_read_spare(4) << 2 |
  43. tegra_fuse_read_spare(3) << 1 |
  44. tegra_fuse_read_spare(2) << 0;
  45. }
  46. static void __init rev_sku_to_speedo_ids(struct tegra_sku_info *sku_info,
  47. u8 speedo_rev, int *threshold)
  48. {
  49. int sku = sku_info->sku_id;
  50. /* Assign to default */
  51. sku_info->cpu_speedo_id = 0;
  52. sku_info->soc_speedo_id = 0;
  53. sku_info->gpu_speedo_id = 0;
  54. *threshold = THRESHOLD_INDEX_0;
  55. switch (sku) {
  56. case 0x00: /* Engineering SKU */
  57. case 0x01: /* Engineering SKU */
  58. case 0x07:
  59. case 0x17:
  60. case 0x27:
  61. if (speedo_rev >= 2)
  62. sku_info->gpu_speedo_id = 1;
  63. break;
  64. case 0x13:
  65. if (speedo_rev >= 2)
  66. sku_info->gpu_speedo_id = 1;
  67. sku_info->cpu_speedo_id = 1;
  68. break;
  69. default:
  70. pr_err("Tegra210: unknown SKU %#04x\n", sku);
  71. /* Using the default for the error case */
  72. break;
  73. }
  74. }
  75. static int get_process_id(int value, const u32 *speedos, unsigned int num)
  76. {
  77. unsigned int i;
  78. for (i = 0; i < num; i++)
  79. if (value < speedos[i])
  80. return i;
  81. return -EINVAL;
  82. }
  83. void __init tegra210_init_speedo_data(struct tegra_sku_info *sku_info)
  84. {
  85. int cpu_speedo[3], soc_speedo[3], cpu_iddq, gpu_iddq, soc_iddq;
  86. unsigned int index;
  87. u8 speedo_revision;
  88. BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) !=
  89. THRESHOLD_INDEX_COUNT);
  90. BUILD_BUG_ON(ARRAY_SIZE(gpu_process_speedos) !=
  91. THRESHOLD_INDEX_COUNT);
  92. BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) !=
  93. THRESHOLD_INDEX_COUNT);
  94. /* Read speedo/IDDQ fuses */
  95. cpu_speedo[0] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_0);
  96. cpu_speedo[1] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_1);
  97. cpu_speedo[2] = tegra_fuse_read_early(FUSE_CPU_SPEEDO_2);
  98. soc_speedo[0] = tegra_fuse_read_early(FUSE_SOC_SPEEDO_0);
  99. soc_speedo[1] = tegra_fuse_read_early(FUSE_SOC_SPEEDO_1);
  100. soc_speedo[2] = tegra_fuse_read_early(FUSE_SOC_SPEEDO_2);
  101. cpu_iddq = tegra_fuse_read_early(FUSE_CPU_IDDQ) * 4;
  102. soc_iddq = tegra_fuse_read_early(FUSE_SOC_IDDQ) * 4;
  103. gpu_iddq = tegra_fuse_read_early(FUSE_GPU_IDDQ) * 5;
  104. /*
  105. * Determine CPU, GPU and SoC speedo values depending on speedo fusing
  106. * revision. Note that GPU speedo value is fused in CPU_SPEEDO_2.
  107. */
  108. speedo_revision = get_speedo_revision();
  109. pr_info("Speedo Revision %u\n", speedo_revision);
  110. if (speedo_revision >= 3) {
  111. sku_info->cpu_speedo_value = cpu_speedo[0];
  112. sku_info->gpu_speedo_value = cpu_speedo[2];
  113. sku_info->soc_speedo_value = soc_speedo[0];
  114. } else if (speedo_revision == 2) {
  115. sku_info->cpu_speedo_value = (-1938 + (1095 * cpu_speedo[0] / 100)) / 10;
  116. sku_info->gpu_speedo_value = (-1662 + (1082 * cpu_speedo[2] / 100)) / 10;
  117. sku_info->soc_speedo_value = ( -705 + (1037 * soc_speedo[0] / 100)) / 10;
  118. } else {
  119. sku_info->cpu_speedo_value = 2100;
  120. sku_info->gpu_speedo_value = cpu_speedo[2] - 75;
  121. sku_info->soc_speedo_value = 1900;
  122. }
  123. if ((sku_info->cpu_speedo_value <= 0) ||
  124. (sku_info->gpu_speedo_value <= 0) ||
  125. (sku_info->soc_speedo_value <= 0)) {
  126. WARN(1, "speedo value not fused\n");
  127. return;
  128. }
  129. rev_sku_to_speedo_ids(sku_info, speedo_revision, &index);
  130. sku_info->gpu_process_id = get_process_id(sku_info->gpu_speedo_value,
  131. gpu_process_speedos[index],
  132. GPU_PROCESS_CORNERS);
  133. sku_info->cpu_process_id = get_process_id(sku_info->cpu_speedo_value,
  134. cpu_process_speedos[index],
  135. CPU_PROCESS_CORNERS);
  136. sku_info->soc_process_id = get_process_id(sku_info->soc_speedo_value,
  137. soc_process_speedos[index],
  138. SOC_PROCESS_CORNERS);
  139. pr_debug("Tegra GPU Speedo ID=%d, Speedo Value=%d\n",
  140. sku_info->gpu_speedo_id, sku_info->gpu_speedo_value);
  141. }