board.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <lib/mmio.h>
  8. #include <lib/utils_def.h>
  9. #include "board.h"
  10. #include "rcar_def.h"
  11. #ifndef BOARD_DEFAULT
  12. #if (RCAR_LSI == RZ_G2H)
  13. #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2H << BOARD_CODE_SHIFT)
  14. #elif (RCAR_LSI == RZ_G2N)
  15. #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2N << BOARD_CODE_SHIFT)
  16. #elif (RCAR_LSI == RZ_G2E)
  17. #define BOARD_DEFAULT (BOARD_EK874_RZ_G2E << BOARD_CODE_SHIFT)
  18. #else
  19. #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2M << BOARD_CODE_SHIFT)
  20. #endif /* RCAR_LSI == RZ_G2H */
  21. #endif /* BOARD_DEFAULT */
  22. #define BOARD_CODE_MASK (0xF8U)
  23. #define BOARD_REV_MASK (0x07U)
  24. #define BOARD_CODE_SHIFT (0x03)
  25. #define BOARD_ID_UNKNOWN (0xFFU)
  26. #define GPIO_INDT5 0xE605500C
  27. #define GP5_19_BIT (0x01U << 19)
  28. #define GP5_21_BIT (0x01U << 21)
  29. #define GP5_25_BIT (0x01U << 25)
  30. #define HM_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  31. #define HH_ID HM_ID
  32. #define HN_ID { 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  33. #define EK_ID HM_ID
  34. const char *g_board_tbl[] = {
  35. [BOARD_HIHOPE_RZ_G2M] = "HiHope RZ/G2M",
  36. [BOARD_HIHOPE_RZ_G2H] = "HiHope RZ/G2H",
  37. [BOARD_HIHOPE_RZ_G2N] = "HiHope RZ/G2N",
  38. [BOARD_EK874_RZ_G2E] = "EK874 RZ/G2E",
  39. [BOARD_UNKNOWN] = "unknown"
  40. };
  41. void rzg_get_board_type(uint32_t *type, uint32_t *rev)
  42. {
  43. static uint8_t board_id = BOARD_ID_UNKNOWN;
  44. const uint8_t board_tbl[][8] = {
  45. [BOARD_HIHOPE_RZ_G2M] = HM_ID,
  46. [BOARD_HIHOPE_RZ_G2H] = HH_ID,
  47. [BOARD_HIHOPE_RZ_G2N] = HN_ID,
  48. [BOARD_EK874_RZ_G2E] = EK_ID,
  49. };
  50. uint32_t reg;
  51. #if (RCAR_LSI != RZ_G2E)
  52. uint32_t boardInfo;
  53. #endif /* RCAR_LSI == RZ_G2E */
  54. if (board_id == BOARD_ID_UNKNOWN) {
  55. board_id = BOARD_DEFAULT;
  56. }
  57. *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
  58. if (*type >= ARRAY_SIZE(board_tbl)) {
  59. /* no revision information, set Rev0.0. */
  60. *rev = 0;
  61. return;
  62. }
  63. reg = mmio_read_32(RCAR_PRR);
  64. #if (RCAR_LSI == RZ_G2E)
  65. if (reg & RCAR_MINOR_MASK) {
  66. *rev = 0x30U;
  67. } else {
  68. *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
  69. }
  70. #else
  71. if ((reg & PRR_CUT_MASK) == RCAR_M3_CUT_VER11) {
  72. *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
  73. } else {
  74. reg = mmio_read_32(GPIO_INDT5);
  75. if (reg & GP5_25_BIT) {
  76. *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
  77. } else {
  78. boardInfo = reg & (GP5_19_BIT | GP5_21_BIT);
  79. *rev = (((boardInfo & GP5_19_BIT) >> 14) |
  80. ((boardInfo & GP5_21_BIT) >> 17)) + 0x30U;
  81. }
  82. }
  83. #endif /* RCAR_LSI == RZ_G2E */
  84. }