speedo-tegra114.c 2.1 KB

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