speedo-tegra20.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 CPU_SPEEDO_LSBIT 20
  22. #define CPU_SPEEDO_MSBIT 29
  23. #define CPU_SPEEDO_REDUND_LSBIT 30
  24. #define CPU_SPEEDO_REDUND_MSBIT 39
  25. #define CPU_SPEEDO_REDUND_OFFS (CPU_SPEEDO_REDUND_MSBIT - CPU_SPEEDO_MSBIT)
  26. #define SOC_SPEEDO_LSBIT 40
  27. #define SOC_SPEEDO_MSBIT 47
  28. #define SOC_SPEEDO_REDUND_LSBIT 48
  29. #define SOC_SPEEDO_REDUND_MSBIT 55
  30. #define SOC_SPEEDO_REDUND_OFFS (SOC_SPEEDO_REDUND_MSBIT - SOC_SPEEDO_MSBIT)
  31. #define SPEEDO_MULT 4
  32. #define PROCESS_CORNERS_NUM 4
  33. #define SPEEDO_ID_SELECT_0(rev) ((rev) <= 2)
  34. #define SPEEDO_ID_SELECT_1(sku) \
  35. (((sku) != 20) && ((sku) != 23) && ((sku) != 24) && \
  36. ((sku) != 27) && ((sku) != 28))
  37. enum {
  38. SPEEDO_ID_0,
  39. SPEEDO_ID_1,
  40. SPEEDO_ID_2,
  41. SPEEDO_ID_COUNT,
  42. };
  43. static const u32 __initconst cpu_process_speedos[][PROCESS_CORNERS_NUM] = {
  44. {315, 366, 420, UINT_MAX},
  45. {303, 368, 419, UINT_MAX},
  46. {316, 331, 383, UINT_MAX},
  47. };
  48. static const u32 __initconst soc_process_speedos[][PROCESS_CORNERS_NUM] = {
  49. {165, 195, 224, UINT_MAX},
  50. {165, 195, 224, UINT_MAX},
  51. {165, 195, 224, UINT_MAX},
  52. };
  53. void __init tegra20_init_speedo_data(struct tegra_sku_info *sku_info)
  54. {
  55. u32 reg;
  56. u32 val;
  57. int i;
  58. BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) != SPEEDO_ID_COUNT);
  59. BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) != SPEEDO_ID_COUNT);
  60. if (SPEEDO_ID_SELECT_0(sku_info->revision))
  61. sku_info->soc_speedo_id = SPEEDO_ID_0;
  62. else if (SPEEDO_ID_SELECT_1(sku_info->sku_id))
  63. sku_info->soc_speedo_id = SPEEDO_ID_1;
  64. else
  65. sku_info->soc_speedo_id = SPEEDO_ID_2;
  66. val = 0;
  67. for (i = CPU_SPEEDO_MSBIT; i >= CPU_SPEEDO_LSBIT; i--) {
  68. reg = tegra_fuse_read_spare(i) |
  69. tegra_fuse_read_spare(i + CPU_SPEEDO_REDUND_OFFS);
  70. val = (val << 1) | (reg & 0x1);
  71. }
  72. val = val * SPEEDO_MULT;
  73. pr_debug("Tegra CPU speedo value %u\n", val);
  74. for (i = 0; i < (PROCESS_CORNERS_NUM - 1); i++) {
  75. if (val <= cpu_process_speedos[sku_info->soc_speedo_id][i])
  76. break;
  77. }
  78. sku_info->cpu_process_id = i;
  79. val = 0;
  80. for (i = SOC_SPEEDO_MSBIT; i >= SOC_SPEEDO_LSBIT; i--) {
  81. reg = tegra_fuse_read_spare(i) |
  82. tegra_fuse_read_spare(i + SOC_SPEEDO_REDUND_OFFS);
  83. val = (val << 1) | (reg & 0x1);
  84. }
  85. val = val * SPEEDO_MULT;
  86. pr_debug("Core speedo value %u\n", val);
  87. for (i = 0; i < (PROCESS_CORNERS_NUM - 1); i++) {
  88. if (val <= soc_process_speedos[sku_info->soc_speedo_id][i])
  89. break;
  90. }
  91. sku_info->soc_process_id = i;
  92. }