speedo-tegra30.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Copyright (c) 2012-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. #include <linux/bug.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel.h>
  19. #include <soc/tegra/fuse.h>
  20. #include "fuse.h"
  21. #define SOC_PROCESS_CORNERS 1
  22. #define CPU_PROCESS_CORNERS 6
  23. #define FUSE_SPEEDO_CALIB_0 0x14
  24. #define FUSE_PACKAGE_INFO 0XFC
  25. #define FUSE_TEST_PROG_VER 0X28
  26. #define G_SPEEDO_BIT_MINUS1 58
  27. #define G_SPEEDO_BIT_MINUS1_R 59
  28. #define G_SPEEDO_BIT_MINUS2 60
  29. #define G_SPEEDO_BIT_MINUS2_R 61
  30. #define LP_SPEEDO_BIT_MINUS1 62
  31. #define LP_SPEEDO_BIT_MINUS1_R 63
  32. #define LP_SPEEDO_BIT_MINUS2 64
  33. #define LP_SPEEDO_BIT_MINUS2_R 65
  34. enum {
  35. THRESHOLD_INDEX_0,
  36. THRESHOLD_INDEX_1,
  37. THRESHOLD_INDEX_2,
  38. THRESHOLD_INDEX_3,
  39. THRESHOLD_INDEX_4,
  40. THRESHOLD_INDEX_5,
  41. THRESHOLD_INDEX_6,
  42. THRESHOLD_INDEX_7,
  43. THRESHOLD_INDEX_8,
  44. THRESHOLD_INDEX_9,
  45. THRESHOLD_INDEX_10,
  46. THRESHOLD_INDEX_11,
  47. THRESHOLD_INDEX_COUNT,
  48. };
  49. static const u32 __initconst soc_process_speedos[][SOC_PROCESS_CORNERS] = {
  50. {180},
  51. {170},
  52. {195},
  53. {180},
  54. {168},
  55. {192},
  56. {180},
  57. {170},
  58. {195},
  59. {180},
  60. {180},
  61. {180},
  62. };
  63. static const u32 __initconst cpu_process_speedos[][CPU_PROCESS_CORNERS] = {
  64. {306, 338, 360, 376, UINT_MAX},
  65. {295, 336, 358, 375, UINT_MAX},
  66. {325, 325, 358, 375, UINT_MAX},
  67. {325, 325, 358, 375, UINT_MAX},
  68. {292, 324, 348, 364, UINT_MAX},
  69. {324, 324, 348, 364, UINT_MAX},
  70. {324, 324, 348, 364, UINT_MAX},
  71. {295, 336, 358, 375, UINT_MAX},
  72. {358, 358, 358, 358, 397, UINT_MAX},
  73. {364, 364, 364, 364, 397, UINT_MAX},
  74. {295, 336, 358, 375, 391, UINT_MAX},
  75. {295, 336, 358, 375, 391, UINT_MAX},
  76. };
  77. static int threshold_index __initdata;
  78. static void __init fuse_speedo_calib(u32 *speedo_g, u32 *speedo_lp)
  79. {
  80. u32 reg;
  81. int ate_ver;
  82. int bit_minus1;
  83. int bit_minus2;
  84. reg = tegra_fuse_read_early(FUSE_SPEEDO_CALIB_0);
  85. *speedo_lp = (reg & 0xFFFF) * 4;
  86. *speedo_g = ((reg >> 16) & 0xFFFF) * 4;
  87. ate_ver = tegra_fuse_read_early(FUSE_TEST_PROG_VER);
  88. pr_debug("Tegra ATE prog ver %d.%d\n", ate_ver/10, ate_ver%10);
  89. if (ate_ver >= 26) {
  90. bit_minus1 = tegra_fuse_read_spare(LP_SPEEDO_BIT_MINUS1);
  91. bit_minus1 |= tegra_fuse_read_spare(LP_SPEEDO_BIT_MINUS1_R);
  92. bit_minus2 = tegra_fuse_read_spare(LP_SPEEDO_BIT_MINUS2);
  93. bit_minus2 |= tegra_fuse_read_spare(LP_SPEEDO_BIT_MINUS2_R);
  94. *speedo_lp |= (bit_minus1 << 1) | bit_minus2;
  95. bit_minus1 = tegra_fuse_read_spare(G_SPEEDO_BIT_MINUS1);
  96. bit_minus1 |= tegra_fuse_read_spare(G_SPEEDO_BIT_MINUS1_R);
  97. bit_minus2 = tegra_fuse_read_spare(G_SPEEDO_BIT_MINUS2);
  98. bit_minus2 |= tegra_fuse_read_spare(G_SPEEDO_BIT_MINUS2_R);
  99. *speedo_g |= (bit_minus1 << 1) | bit_minus2;
  100. } else {
  101. *speedo_lp |= 0x3;
  102. *speedo_g |= 0x3;
  103. }
  104. }
  105. static void __init rev_sku_to_speedo_ids(struct tegra_sku_info *sku_info)
  106. {
  107. int package_id = tegra_fuse_read_early(FUSE_PACKAGE_INFO) & 0x0F;
  108. switch (sku_info->revision) {
  109. case TEGRA_REVISION_A01:
  110. sku_info->cpu_speedo_id = 0;
  111. sku_info->soc_speedo_id = 0;
  112. threshold_index = THRESHOLD_INDEX_0;
  113. break;
  114. case TEGRA_REVISION_A02:
  115. case TEGRA_REVISION_A03:
  116. switch (sku_info->sku_id) {
  117. case 0x87:
  118. case 0x82:
  119. sku_info->cpu_speedo_id = 1;
  120. sku_info->soc_speedo_id = 1;
  121. threshold_index = THRESHOLD_INDEX_1;
  122. break;
  123. case 0x81:
  124. switch (package_id) {
  125. case 1:
  126. sku_info->cpu_speedo_id = 2;
  127. sku_info->soc_speedo_id = 2;
  128. threshold_index = THRESHOLD_INDEX_2;
  129. break;
  130. case 2:
  131. sku_info->cpu_speedo_id = 4;
  132. sku_info->soc_speedo_id = 1;
  133. threshold_index = THRESHOLD_INDEX_7;
  134. break;
  135. default:
  136. pr_err("Tegra Unknown pkg %d\n", package_id);
  137. break;
  138. }
  139. break;
  140. case 0x80:
  141. switch (package_id) {
  142. case 1:
  143. sku_info->cpu_speedo_id = 5;
  144. sku_info->soc_speedo_id = 2;
  145. threshold_index = THRESHOLD_INDEX_8;
  146. break;
  147. case 2:
  148. sku_info->cpu_speedo_id = 6;
  149. sku_info->soc_speedo_id = 2;
  150. threshold_index = THRESHOLD_INDEX_9;
  151. break;
  152. default:
  153. pr_err("Tegra Unknown pkg %d\n", package_id);
  154. break;
  155. }
  156. break;
  157. case 0x83:
  158. switch (package_id) {
  159. case 1:
  160. sku_info->cpu_speedo_id = 7;
  161. sku_info->soc_speedo_id = 1;
  162. threshold_index = THRESHOLD_INDEX_10;
  163. break;
  164. case 2:
  165. sku_info->cpu_speedo_id = 3;
  166. sku_info->soc_speedo_id = 2;
  167. threshold_index = THRESHOLD_INDEX_3;
  168. break;
  169. default:
  170. pr_err("Tegra Unknown pkg %d\n", package_id);
  171. break;
  172. }
  173. break;
  174. case 0x8F:
  175. sku_info->cpu_speedo_id = 8;
  176. sku_info->soc_speedo_id = 1;
  177. threshold_index = THRESHOLD_INDEX_11;
  178. break;
  179. case 0x08:
  180. sku_info->cpu_speedo_id = 1;
  181. sku_info->soc_speedo_id = 1;
  182. threshold_index = THRESHOLD_INDEX_4;
  183. break;
  184. case 0x02:
  185. sku_info->cpu_speedo_id = 2;
  186. sku_info->soc_speedo_id = 2;
  187. threshold_index = THRESHOLD_INDEX_5;
  188. break;
  189. case 0x04:
  190. sku_info->cpu_speedo_id = 3;
  191. sku_info->soc_speedo_id = 2;
  192. threshold_index = THRESHOLD_INDEX_6;
  193. break;
  194. case 0:
  195. switch (package_id) {
  196. case 1:
  197. sku_info->cpu_speedo_id = 2;
  198. sku_info->soc_speedo_id = 2;
  199. threshold_index = THRESHOLD_INDEX_2;
  200. break;
  201. case 2:
  202. sku_info->cpu_speedo_id = 3;
  203. sku_info->soc_speedo_id = 2;
  204. threshold_index = THRESHOLD_INDEX_3;
  205. break;
  206. default:
  207. pr_err("Tegra Unknown pkg %d\n", package_id);
  208. break;
  209. }
  210. break;
  211. default:
  212. pr_warn("Tegra Unknown SKU %d\n", sku_info->sku_id);
  213. sku_info->cpu_speedo_id = 0;
  214. sku_info->soc_speedo_id = 0;
  215. threshold_index = THRESHOLD_INDEX_0;
  216. break;
  217. }
  218. break;
  219. default:
  220. pr_warn("Tegra Unknown chip rev %d\n", sku_info->revision);
  221. sku_info->cpu_speedo_id = 0;
  222. sku_info->soc_speedo_id = 0;
  223. threshold_index = THRESHOLD_INDEX_0;
  224. break;
  225. }
  226. }
  227. void __init tegra30_init_speedo_data(struct tegra_sku_info *sku_info)
  228. {
  229. u32 cpu_speedo_val;
  230. u32 soc_speedo_val;
  231. int i;
  232. BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) !=
  233. THRESHOLD_INDEX_COUNT);
  234. BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) !=
  235. THRESHOLD_INDEX_COUNT);
  236. rev_sku_to_speedo_ids(sku_info);
  237. fuse_speedo_calib(&cpu_speedo_val, &soc_speedo_val);
  238. pr_debug("Tegra CPU speedo value %u\n", cpu_speedo_val);
  239. pr_debug("Tegra Core speedo value %u\n", soc_speedo_val);
  240. for (i = 0; i < CPU_PROCESS_CORNERS; i++) {
  241. if (cpu_speedo_val < cpu_process_speedos[threshold_index][i])
  242. break;
  243. }
  244. sku_info->cpu_process_id = i - 1;
  245. if (sku_info->cpu_process_id == -1) {
  246. pr_warn("Tegra CPU speedo value %3d out of range",
  247. cpu_speedo_val);
  248. sku_info->cpu_process_id = 0;
  249. sku_info->cpu_speedo_id = 1;
  250. }
  251. for (i = 0; i < SOC_PROCESS_CORNERS; i++) {
  252. if (soc_speedo_val < soc_process_speedos[threshold_index][i])
  253. break;
  254. }
  255. sku_info->soc_process_id = i - 1;
  256. if (sku_info->soc_process_id == -1) {
  257. pr_warn("Tegra SoC speedo value %3d out of range",
  258. soc_speedo_val);
  259. sku_info->soc_process_id = 0;
  260. sku_info->soc_speedo_id = 1;
  261. }
  262. }