speedo-tegra210.c 5.1 KB

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