cpu_info.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  4. * (C) Copyright 2012-2021 Renesas Solutions Corp.
  5. */
  6. #include <common.h>
  7. #include <cpu_func.h>
  8. #include <asm/cache.h>
  9. #include <init.h>
  10. #include <asm/io.h>
  11. #include <env.h>
  12. #include <linux/ctype.h>
  13. #ifdef CONFIG_ARCH_CPU_INIT
  14. int arch_cpu_init(void)
  15. {
  16. icache_enable();
  17. return 0;
  18. }
  19. #endif
  20. /* R-Car Gen3 D-cache is enabled in memmap-gen3.c */
  21. #ifndef CONFIG_RCAR_GEN3
  22. #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  23. void enable_caches(void)
  24. {
  25. dcache_enable();
  26. }
  27. #endif
  28. #endif
  29. #ifdef CONFIG_DISPLAY_CPUINFO
  30. #ifndef CONFIG_RZA1
  31. __weak const u8 *rzg_get_cpu_name(void)
  32. {
  33. return 0;
  34. }
  35. static u32 __rmobile_get_cpu_type(void)
  36. {
  37. return 0x0;
  38. }
  39. u32 rmobile_get_cpu_type(void)
  40. __attribute__((weak, alias("__rmobile_get_cpu_type")));
  41. static u32 __rmobile_get_cpu_rev_integer(void)
  42. {
  43. return 0;
  44. }
  45. u32 rmobile_get_cpu_rev_integer(void)
  46. __attribute__((weak, alias("__rmobile_get_cpu_rev_integer")));
  47. static u32 __rmobile_get_cpu_rev_fraction(void)
  48. {
  49. return 0;
  50. }
  51. u32 rmobile_get_cpu_rev_fraction(void)
  52. __attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
  53. /* CPU information table */
  54. static const struct {
  55. u16 cpu_type;
  56. u8 cpu_name[10];
  57. } rmobile_cpuinfo[] = {
  58. { RMOBILE_CPU_TYPE_SH73A0, "SH73A0" },
  59. { RMOBILE_CPU_TYPE_R8A7740, "R8A7740" },
  60. { RMOBILE_CPU_TYPE_R8A7790, "R8A7790" },
  61. { RMOBILE_CPU_TYPE_R8A7791, "R8A7791" },
  62. { RMOBILE_CPU_TYPE_R8A7792, "R8A7792" },
  63. { RMOBILE_CPU_TYPE_R8A7793, "R8A7793" },
  64. { RMOBILE_CPU_TYPE_R8A7794, "R8A7794" },
  65. { RMOBILE_CPU_TYPE_R8A7795, "R8A7795" },
  66. { RMOBILE_CPU_TYPE_R8A7796, "R8A7796" },
  67. { RMOBILE_CPU_TYPE_R8A77965, "R8A77965" },
  68. { RMOBILE_CPU_TYPE_R8A77970, "R8A77970" },
  69. { RMOBILE_CPU_TYPE_R8A77980, "R8A77980" },
  70. { RMOBILE_CPU_TYPE_R8A77990, "R8A77990" },
  71. { RMOBILE_CPU_TYPE_R8A77995, "R8A77995" },
  72. { 0x0, "CPU" },
  73. };
  74. static int rmobile_cpuinfo_idx(void)
  75. {
  76. int i = 0;
  77. u32 cpu_type = rmobile_get_cpu_type();
  78. for (; i < ARRAY_SIZE(rmobile_cpuinfo); i++)
  79. if (rmobile_cpuinfo[i].cpu_type == cpu_type)
  80. break;
  81. return i;
  82. }
  83. static const u8 *get_cpu_name(int idx)
  84. {
  85. const u8 *cpu_name = rzg_get_cpu_name();
  86. return cpu_name ? cpu_name : rmobile_cpuinfo[idx].cpu_name;
  87. }
  88. #ifdef CONFIG_ARCH_MISC_INIT
  89. int arch_misc_init(void)
  90. {
  91. int i, idx = rmobile_cpuinfo_idx();
  92. const u8 *cpu_name = get_cpu_name(idx);
  93. char cpu[10] = { 0 };
  94. for (i = 0; i < sizeof(cpu); i++)
  95. cpu[i] = tolower(cpu_name[i]);
  96. env_set("platform", cpu);
  97. return 0;
  98. }
  99. #endif
  100. int print_cpuinfo(void)
  101. {
  102. int i = rmobile_cpuinfo_idx();
  103. printf("CPU: Renesas Electronics %s rev %d.%d\n",
  104. get_cpu_name(i), rmobile_get_cpu_rev_integer(),
  105. rmobile_get_cpu_rev_fraction());
  106. return 0;
  107. }
  108. #else
  109. int print_cpuinfo(void)
  110. {
  111. printf("CPU: Renesas Electronics RZ/A1\n");
  112. return 0;
  113. }
  114. #endif
  115. #endif /* CONFIG_DISPLAY_CPUINFO */