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