board.c 2.11 KB
Newer Older
1
/*
2
 * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>

#include <lib/mmio.h>
#include <lib/utils_def.h>

#include "board.h"
#include "rcar_def.h"

#ifndef BOARD_DEFAULT
16
17
#if (RCAR_LSI == RZ_G2H)
#define BOARD_DEFAULT		(BOARD_HIHOPE_RZ_G2H << BOARD_CODE_SHIFT)
18
19
#elif (RCAR_LSI == RZ_G2N)
#define BOARD_DEFAULT		(BOARD_HIHOPE_RZ_G2N << BOARD_CODE_SHIFT)
20
#else
21
#define BOARD_DEFAULT		(BOARD_HIHOPE_RZ_G2M << BOARD_CODE_SHIFT)
22
#endif /* RCAR_LSI == RZ_G2H */
23
24
25
26
27
28
29
30
31
32
33
34
35
#endif /* BOARD_DEFAULT */

#define BOARD_CODE_MASK		(0xF8U)
#define BOARD_REV_MASK		(0x07U)
#define BOARD_CODE_SHIFT	(0x03)
#define BOARD_ID_UNKNOWN	(0xFFU)

#define GPIO_INDT5	0xE605500C
#define GP5_19_BIT	(0x01U << 19)
#define GP5_21_BIT	(0x01U << 21)
#define GP5_25_BIT	(0x01U << 25)

#define HM_ID	{ 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
36
#define HH_ID	HM_ID
37
#define HN_ID	{ 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
38
39
40

const char *g_board_tbl[] = {
	[BOARD_HIHOPE_RZ_G2M] = "HiHope RZ/G2M",
41
	[BOARD_HIHOPE_RZ_G2H] = "HiHope RZ/G2H",
42
	[BOARD_HIHOPE_RZ_G2N] = "HiHope RZ/G2N",
43
44
45
46
47
48
49
50
	[BOARD_UNKNOWN] = "unknown"
};

void rzg_get_board_type(uint32_t *type, uint32_t *rev)
{
	static uint8_t board_id = BOARD_ID_UNKNOWN;
	const uint8_t board_tbl[][8] = {
		[BOARD_HIHOPE_RZ_G2M] = HM_ID,
51
		[BOARD_HIHOPE_RZ_G2H] = HH_ID,
52
		[BOARD_HIHOPE_RZ_G2N] = HN_ID,
53
54
55
56
57
58
59
60
61
62
63
64
	};
	uint32_t reg, boardInfo;

	if (board_id == BOARD_ID_UNKNOWN) {
		board_id = BOARD_DEFAULT;
	}

	*type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;

	if (*type >= ARRAY_SIZE(board_tbl)) {
		/* no revision information, set Rev0.0. */
		*rev = 0;
65
66
67
68
69
70
		return;
	}

	reg = mmio_read_32(RCAR_PRR);
	if ((reg & PRR_CUT_MASK) == RCAR_M3_CUT_VER11) {
		*rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
71
	} else {
72
		reg = mmio_read_32(GPIO_INDT5);
73
74
75
76
77
78
79
		if (reg & GP5_25_BIT) {
			*rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)];
		} else {
			boardInfo = reg & (GP5_19_BIT | GP5_21_BIT);
			*rev = (((boardInfo & GP5_19_BIT) >> 14) |
				((boardInfo & GP5_21_BIT) >> 17)) + 0x30U;
		}
80
81
	}
}