speedo-tegra114.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #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 2
  22. #define CPU_PROCESS_CORNERS 2
  23. enum {
  24. THRESHOLD_INDEX_0,
  25. THRESHOLD_INDEX_1,
  26. THRESHOLD_INDEX_COUNT,
  27. };
  28. static const u32 __initconst soc_process_speedos[][SOC_PROCESS_CORNERS] = {
  29. {1123, UINT_MAX},
  30. {0, UINT_MAX},
  31. };
  32. static const u32 __initconst cpu_process_speedos[][CPU_PROCESS_CORNERS] = {
  33. {1695, UINT_MAX},
  34. {0, UINT_MAX},
  35. };
  36. static void __init rev_sku_to_speedo_ids(struct tegra_sku_info *sku_info,
  37. int *threshold)
  38. {
  39. u32 tmp;
  40. u32 sku = sku_info->sku_id;
  41. enum tegra_revision rev = sku_info->revision;
  42. switch (sku) {
  43. case 0x00:
  44. case 0x10:
  45. case 0x05:
  46. case 0x06:
  47. sku_info->cpu_speedo_id = 1;
  48. sku_info->soc_speedo_id = 0;
  49. *threshold = THRESHOLD_INDEX_0;
  50. break;
  51. case 0x03:
  52. case 0x04:
  53. sku_info->cpu_speedo_id = 2;
  54. sku_info->soc_speedo_id = 1;
  55. *threshold = THRESHOLD_INDEX_1;
  56. break;
  57. default:
  58. pr_err("Tegra Unknown SKU %d\n", sku);
  59. sku_info->cpu_speedo_id = 0;
  60. sku_info->soc_speedo_id = 0;
  61. *threshold = THRESHOLD_INDEX_0;
  62. break;
  63. }
  64. if (rev == TEGRA_REVISION_A01) {
  65. tmp = tegra_fuse_read_early(0x270) << 1;
  66. tmp |= tegra_fuse_read_early(0x26c);
  67. if (!tmp)
  68. sku_info->cpu_speedo_id = 0;
  69. }
  70. }
  71. void __init tegra114_init_speedo_data(struct tegra_sku_info *sku_info)
  72. {
  73. u32 cpu_speedo_val;
  74. u32 soc_speedo_val;
  75. int threshold;
  76. int i;
  77. BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) !=
  78. THRESHOLD_INDEX_COUNT);
  79. BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) !=
  80. THRESHOLD_INDEX_COUNT);
  81. rev_sku_to_speedo_ids(sku_info, &threshold);
  82. cpu_speedo_val = tegra_fuse_read_early(0x12c) + 1024;
  83. soc_speedo_val = tegra_fuse_read_early(0x134);
  84. for (i = 0; i < CPU_PROCESS_CORNERS; i++)
  85. if (cpu_speedo_val < cpu_process_speedos[threshold][i])
  86. break;
  87. sku_info->cpu_process_id = i;
  88. for (i = 0; i < SOC_PROCESS_CORNERS; i++)
  89. if (soc_speedo_val < soc_process_speedos[threshold][i])
  90. break;
  91. sku_info->soc_process_id = i;
  92. }