blob: 76363722891264c590e7170a35ff5efe88556786 [file] [log] [blame]
Biju Das40e80732020-12-07 16:29:22 +00001/*
Lad Prabhakare1c0f742020-12-21 13:51:58 +00002 * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights reserved.
Biju Das40e80732020-12-07 16:29:22 +00003 *
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
Lad Prabhakare1c0f742020-12-21 13:51:58 +000016#if (RCAR_LSI == RZ_G2H)
17#define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2H << BOARD_CODE_SHIFT)
Lad Prabhakar21d04f02021-03-19 12:01:00 +000018#elif (RCAR_LSI == RZ_G2N)
19#define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2N << BOARD_CODE_SHIFT)
Lad Prabhakarea647342021-03-19 12:14:01 +000020#elif (RCAR_LSI == RZ_G2E)
21#define BOARD_DEFAULT (BOARD_EK874_RZ_G2E << BOARD_CODE_SHIFT)
Lad Prabhakare1c0f742020-12-21 13:51:58 +000022#else
Biju Das40e80732020-12-07 16:29:22 +000023#define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2M << BOARD_CODE_SHIFT)
Lad Prabhakare1c0f742020-12-21 13:51:58 +000024#endif /* RCAR_LSI == RZ_G2H */
Biju Das40e80732020-12-07 16:29:22 +000025#endif /* BOARD_DEFAULT */
26
27#define BOARD_CODE_MASK (0xF8U)
28#define BOARD_REV_MASK (0x07U)
29#define BOARD_CODE_SHIFT (0x03)
30#define BOARD_ID_UNKNOWN (0xFFU)
31
32#define GPIO_INDT5 0xE605500C
33#define GP5_19_BIT (0x01U << 19)
34#define GP5_21_BIT (0x01U << 21)
35#define GP5_25_BIT (0x01U << 25)
36
37#define HM_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Lad Prabhakare1c0f742020-12-21 13:51:58 +000038#define HH_ID HM_ID
Lad Prabhakar21d04f02021-03-19 12:01:00 +000039#define HN_ID { 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Lad Prabhakarea647342021-03-19 12:14:01 +000040#define EK_ID HM_ID
Biju Das40e80732020-12-07 16:29:22 +000041
42const char *g_board_tbl[] = {
43 [BOARD_HIHOPE_RZ_G2M] = "HiHope RZ/G2M",
Lad Prabhakare1c0f742020-12-21 13:51:58 +000044 [BOARD_HIHOPE_RZ_G2H] = "HiHope RZ/G2H",
Lad Prabhakar21d04f02021-03-19 12:01:00 +000045 [BOARD_HIHOPE_RZ_G2N] = "HiHope RZ/G2N",
Lad Prabhakarea647342021-03-19 12:14:01 +000046 [BOARD_EK874_RZ_G2E] = "EK874 RZ/G2E",
Biju Das40e80732020-12-07 16:29:22 +000047 [BOARD_UNKNOWN] = "unknown"
48};
49
50void rzg_get_board_type(uint32_t *type, uint32_t *rev)
51{
52 static uint8_t board_id = BOARD_ID_UNKNOWN;
53 const uint8_t board_tbl[][8] = {
54 [BOARD_HIHOPE_RZ_G2M] = HM_ID,
Lad Prabhakare1c0f742020-12-21 13:51:58 +000055 [BOARD_HIHOPE_RZ_G2H] = HH_ID,
Lad Prabhakar21d04f02021-03-19 12:01:00 +000056 [BOARD_HIHOPE_RZ_G2N] = HN_ID,
Lad Prabhakarea647342021-03-19 12:14:01 +000057 [BOARD_EK874_RZ_G2E] = EK_ID,
Biju Das40e80732020-12-07 16:29:22 +000058 };
Lad Prabhakarea647342021-03-19 12:14:01 +000059 uint32_t reg;
60#if (RCAR_LSI != RZ_G2E)
61 uint32_t boardInfo;
62#endif /* RCAR_LSI == RZ_G2E */
Biju Das40e80732020-12-07 16:29:22 +000063
64 if (board_id == BOARD_ID_UNKNOWN) {
65 board_id = BOARD_DEFAULT;
66 }
67
68 *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
69
70 if (*type >= ARRAY_SIZE(board_tbl)) {
71 /* no revision information, set Rev0.0. */
72 *rev = 0;
Lad Prabhakare1c0f742020-12-21 13:51:58 +000073 return;
74 }
75
76 reg = mmio_read_32(RCAR_PRR);
Lad Prabhakarea647342021-03-19 12:14:01 +000077#if (RCAR_LSI == RZ_G2E)
78 if (reg & RCAR_MINOR_MASK) {
79 *rev = 0x30U;
80 } else {
81 *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
82 }
83#else
Lad Prabhakare1c0f742020-12-21 13:51:58 +000084 if ((reg & PRR_CUT_MASK) == RCAR_M3_CUT_VER11) {
85 *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
Biju Das40e80732020-12-07 16:29:22 +000086 } else {
Lad Prabhakare1c0f742020-12-21 13:51:58 +000087 reg = mmio_read_32(GPIO_INDT5);
Lad Prabhakar21d04f02021-03-19 12:01:00 +000088 if (reg & GP5_25_BIT) {
89 *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
90 } else {
91 boardInfo = reg & (GP5_19_BIT | GP5_21_BIT);
92 *rev = (((boardInfo & GP5_19_BIT) >> 14) |
93 ((boardInfo & GP5_21_BIT) >> 17)) + 0x30U;
94 }
Biju Das40e80732020-12-07 16:29:22 +000095 }
Lad Prabhakarea647342021-03-19 12:14:01 +000096#endif /* RCAR_LSI == RZ_G2E */
Biju Das40e80732020-12-07 16:29:22 +000097}