board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights
  3. * reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <stdint.h>
  8. #include <lib/utils_def.h>
  9. #include <iic_dvfs.h>
  10. #include "board.h"
  11. #ifndef BOARD_DEFAULT
  12. #if (RCAR_LSI == RCAR_D3)
  13. #define BOARD_DEFAULT (BOARD_DRAAK << BOARD_CODE_SHIFT)
  14. #elif (RCAR_LSI == RCAR_E3)
  15. #define BOARD_DEFAULT (BOARD_EBISU << BOARD_CODE_SHIFT)
  16. #elif (RCAR_LSI == RCAR_V3M)
  17. #define BOARD_DEFAULT (BOARD_EAGLE << BOARD_CODE_SHIFT)
  18. #else
  19. #define BOARD_DEFAULT (BOARD_SALVATOR_X << BOARD_CODE_SHIFT)
  20. #endif
  21. #endif
  22. #define BOARD_CODE_MASK (0xF8)
  23. #define BOARD_REV_MASK (0x07)
  24. #define BOARD_CODE_SHIFT (0x03)
  25. #define BOARD_ID_UNKNOWN (0xFF)
  26. #define SXS_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  27. #define SX_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  28. #define SKP_ID { 0x10U, 0x10U, 0x20U, 0x21U, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  29. #define SK_ID { 0x10U, 0x30U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  30. #define EB4_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  31. #define EB_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  32. #define DR_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  33. #define EA_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  34. #define KK_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
  35. const char *g_board_tbl[] = {
  36. [BOARD_STARTER_KIT_PRE] = "Starter Kit Premier",
  37. [BOARD_STARTER_KIT] = "Starter Kit",
  38. [BOARD_SALVATOR_XS] = "Salvator-XS",
  39. [BOARD_SALVATOR_X] = "Salvator-X",
  40. [BOARD_EBISU_4D] = "Ebisu-4D",
  41. [BOARD_KRIEK] = "Kriek",
  42. [BOARD_EBISU] = "Ebisu",
  43. [BOARD_DRAAK] = "Draak",
  44. [BOARD_EAGLE] = "Eagle",
  45. [BOARD_UNKNOWN] = "unknown"
  46. };
  47. int32_t rcar_get_board_type(uint32_t *type, uint32_t *rev)
  48. {
  49. int32_t ret = 0;
  50. const uint8_t board_tbl[][8] = {
  51. [BOARD_STARTER_KIT_PRE] = SKP_ID,
  52. [BOARD_SALVATOR_XS] = SXS_ID,
  53. [BOARD_STARTER_KIT] = SK_ID,
  54. [BOARD_SALVATOR_X] = SX_ID,
  55. [BOARD_EBISU_4D] = EB4_ID,
  56. [BOARD_EBISU] = EB_ID,
  57. [BOARD_DRAAK] = DR_ID,
  58. [BOARD_EAGLE] = EA_ID,
  59. [BOARD_KRIEK] = KK_ID,
  60. };
  61. static uint8_t board_id = BOARD_ID_UNKNOWN;
  62. if (board_id != BOARD_ID_UNKNOWN)
  63. goto get_type;
  64. #if PMIC_ROHM_BD9571
  65. /* Board ID detection from EEPROM */
  66. ret = rcar_iic_dvfs_receive(EEPROM, BOARD_ID, &board_id);
  67. if (ret) {
  68. board_id = BOARD_ID_UNKNOWN;
  69. goto get_type;
  70. }
  71. if (board_id == BOARD_ID_UNKNOWN)
  72. board_id = BOARD_DEFAULT;
  73. #else
  74. board_id = BOARD_DEFAULT;
  75. #endif
  76. get_type:
  77. *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
  78. if (*type >= ARRAY_SIZE(board_tbl)) {
  79. /* no revision information, set Rev0.0. */
  80. *rev = 0;
  81. return ret;
  82. }
  83. *rev = board_tbl[*type][(uint8_t) (board_id & BOARD_REV_MASK)];
  84. return ret;
  85. }