blob: cfbb0471941e42883f1c7a4f8bf4bd9e083d6417 [file] [log] [blame]
Biju Das40e80732020-12-07 16:29:22 +00001/*
2 * Copyright (c) 2020, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdint.h>
8
9#include <lib/mmio.h>
10#include <lib/utils_def.h>
11
12#include "board.h"
13#include "rcar_def.h"
14
15#ifndef BOARD_DEFAULT
16#define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2M << BOARD_CODE_SHIFT)
17#endif /* BOARD_DEFAULT */
18
19#define BOARD_CODE_MASK (0xF8U)
20#define BOARD_REV_MASK (0x07U)
21#define BOARD_CODE_SHIFT (0x03)
22#define BOARD_ID_UNKNOWN (0xFFU)
23
24#define GPIO_INDT5 0xE605500C
25#define GP5_19_BIT (0x01U << 19)
26#define GP5_21_BIT (0x01U << 21)
27#define GP5_25_BIT (0x01U << 25)
28
29#define HM_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
30
31const char *g_board_tbl[] = {
32 [BOARD_HIHOPE_RZ_G2M] = "HiHope RZ/G2M",
33 [BOARD_UNKNOWN] = "unknown"
34};
35
36void rzg_get_board_type(uint32_t *type, uint32_t *rev)
37{
38 static uint8_t board_id = BOARD_ID_UNKNOWN;
39 const uint8_t board_tbl[][8] = {
40 [BOARD_HIHOPE_RZ_G2M] = HM_ID,
41 };
42 uint32_t reg, boardInfo;
43
44 if (board_id == BOARD_ID_UNKNOWN) {
45 board_id = BOARD_DEFAULT;
46 }
47
48 *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
49
50 if (*type >= ARRAY_SIZE(board_tbl)) {
51 /* no revision information, set Rev0.0. */
52 *rev = 0;
53 } else {
54 reg = mmio_read_32(RCAR_PRR);
55 if ((reg & PRR_CUT_MASK) == RCAR_M3_CUT_VER11) {
56 *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
57 } else {
58 boardInfo = mmio_read_32(GPIO_INDT5) &
59 (GP5_19_BIT | GP5_21_BIT);
60 *rev = (((boardInfo & GP5_19_BIT) >> 14) |
61 ((boardInfo & GP5_21_BIT) >> 17)) + 0x30U;
62 }
63 }
64}