speedo-tegra20.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2014, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <linux/bug.h>
  6. #include <linux/device.h>
  7. #include <linux/kernel.h>
  8. #include <soc/tegra/fuse.h>
  9. #include "fuse.h"
  10. #define CPU_SPEEDO_LSBIT 20
  11. #define CPU_SPEEDO_MSBIT 29
  12. #define CPU_SPEEDO_REDUND_LSBIT 30
  13. #define CPU_SPEEDO_REDUND_MSBIT 39
  14. #define CPU_SPEEDO_REDUND_OFFS (CPU_SPEEDO_REDUND_MSBIT - CPU_SPEEDO_MSBIT)
  15. #define SOC_SPEEDO_LSBIT 40
  16. #define SOC_SPEEDO_MSBIT 47
  17. #define SOC_SPEEDO_REDUND_LSBIT 48
  18. #define SOC_SPEEDO_REDUND_MSBIT 55
  19. #define SOC_SPEEDO_REDUND_OFFS (SOC_SPEEDO_REDUND_MSBIT - SOC_SPEEDO_MSBIT)
  20. #define SPEEDO_MULT 4
  21. #define PROCESS_CORNERS_NUM 4
  22. #define SPEEDO_ID_SELECT_0(rev) ((rev) <= 2)
  23. #define SPEEDO_ID_SELECT_1(sku) \
  24. (((sku) != 20) && ((sku) != 23) && ((sku) != 24) && \
  25. ((sku) != 27) && ((sku) != 28))
  26. enum {
  27. SPEEDO_ID_0,
  28. SPEEDO_ID_1,
  29. SPEEDO_ID_2,
  30. SPEEDO_ID_COUNT,
  31. };
  32. static const u32 __initconst cpu_process_speedos[][PROCESS_CORNERS_NUM] = {
  33. {315, 366, 420, UINT_MAX},
  34. {303, 368, 419, UINT_MAX},
  35. {316, 331, 383, UINT_MAX},
  36. };
  37. static const u32 __initconst soc_process_speedos[][PROCESS_CORNERS_NUM] = {
  38. {165, 195, 224, UINT_MAX},
  39. {165, 195, 224, UINT_MAX},
  40. {165, 195, 224, UINT_MAX},
  41. };
  42. void __init tegra20_init_speedo_data(struct tegra_sku_info *sku_info)
  43. {
  44. u32 reg;
  45. u32 val;
  46. int i;
  47. BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) != SPEEDO_ID_COUNT);
  48. BUILD_BUG_ON(ARRAY_SIZE(soc_process_speedos) != SPEEDO_ID_COUNT);
  49. if (SPEEDO_ID_SELECT_0(sku_info->revision))
  50. sku_info->soc_speedo_id = SPEEDO_ID_0;
  51. else if (SPEEDO_ID_SELECT_1(sku_info->sku_id))
  52. sku_info->soc_speedo_id = SPEEDO_ID_1;
  53. else
  54. sku_info->soc_speedo_id = SPEEDO_ID_2;
  55. val = 0;
  56. for (i = CPU_SPEEDO_MSBIT; i >= CPU_SPEEDO_LSBIT; i--) {
  57. reg = tegra_fuse_read_spare(i) |
  58. tegra_fuse_read_spare(i + CPU_SPEEDO_REDUND_OFFS);
  59. val = (val << 1) | (reg & 0x1);
  60. }
  61. val = val * SPEEDO_MULT;
  62. pr_debug("Tegra CPU speedo value %u\n", val);
  63. for (i = 0; i < (PROCESS_CORNERS_NUM - 1); i++) {
  64. if (val <= cpu_process_speedos[sku_info->soc_speedo_id][i])
  65. break;
  66. }
  67. sku_info->cpu_process_id = i;
  68. val = 0;
  69. for (i = SOC_SPEEDO_MSBIT; i >= SOC_SPEEDO_LSBIT; i--) {
  70. reg = tegra_fuse_read_spare(i) |
  71. tegra_fuse_read_spare(i + SOC_SPEEDO_REDUND_OFFS);
  72. val = (val << 1) | (reg & 0x1);
  73. }
  74. val = val * SPEEDO_MULT;
  75. pr_debug("Core speedo value %u\n", val);
  76. for (i = 0; i < (PROCESS_CORNERS_NUM - 1); i++) {
  77. if (val <= soc_process_speedos[sku_info->soc_speedo_id][i])
  78. break;
  79. }
  80. sku_info->soc_process_id = i;
  81. }