board.c 2.71 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights
 * reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>
9
10
11

#include <lib/utils_def.h>

12
#include <iic_dvfs.h>
13

14
15
16
#include "board.h"

#ifndef BOARD_DEFAULT
17
18
19
#if (RCAR_LSI == RCAR_D3)
#define BOARD_DEFAULT		(BOARD_DRAAK << BOARD_CODE_SHIFT)
#elif (RCAR_LSI == RCAR_E3)
20
#define BOARD_DEFAULT		(BOARD_EBISU << BOARD_CODE_SHIFT)
21
22
#elif (RCAR_LSI == RCAR_V3M)
#define BOARD_DEFAULT		(BOARD_EAGLE << BOARD_CODE_SHIFT)
23
24
25
26
27
28
29
30
31
32
33
34
#else
#define BOARD_DEFAULT		(BOARD_SALVATOR_X << BOARD_CODE_SHIFT)
#endif
#endif

#define BOARD_CODE_MASK		(0xF8)
#define BOARD_REV_MASK		(0x07)
#define BOARD_CODE_SHIFT	(0x03)
#define BOARD_ID_UNKNOWN	(0xFF)

#define SXS_ID	{ 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
#define SX_ID	{ 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
35
#define SKP_ID	{ 0x10U, 0x10U, 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
36
37
38
#define SK_ID	{ 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
#define EB4_ID	{ 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
#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
42
43
44
45
46
47
48
49
50
#define KK_ID	{ 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }

const char *g_board_tbl[] = {
	[BOARD_STARTER_KIT_PRE] = "Starter Kit Premier",
	[BOARD_STARTER_KIT] = "Starter Kit",
	[BOARD_SALVATOR_XS] = "Salvator-XS",
	[BOARD_SALVATOR_X] = "Salvator-X",
	[BOARD_EBISU_4D] = "Ebisu-4D",
	[BOARD_KRIEK] = "Kriek",
	[BOARD_EBISU] = "Ebisu",
51
	[BOARD_DRAAK] = "Draak",
52
	[BOARD_EAGLE] = "Eagle",
53
54
55
56
57
58
59
60
61
62
63
64
65
	[BOARD_UNKNOWN] = "unknown"
};

int32_t rcar_get_board_type(uint32_t *type, uint32_t *rev)
{
	int32_t ret = 0;
	const uint8_t board_tbl[][8] = {
		[BOARD_STARTER_KIT_PRE] = SKP_ID,
		[BOARD_SALVATOR_XS] = SXS_ID,
		[BOARD_STARTER_KIT] = SK_ID,
		[BOARD_SALVATOR_X] = SX_ID,
		[BOARD_EBISU_4D] = EB4_ID,
		[BOARD_EBISU] = EB_ID,
66
		[BOARD_DRAAK] = DR_ID,
67
		[BOARD_EAGLE] = EA_ID,
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
		[BOARD_KRIEK] = KK_ID,
	};
	static uint8_t board_id = BOARD_ID_UNKNOWN;

	if (board_id != BOARD_ID_UNKNOWN)
		goto get_type;

#if PMIC_ROHM_BD9571
	/* Board ID detection from EEPROM */
	ret = rcar_iic_dvfs_receive(EEPROM, BOARD_ID, &board_id);
	if (ret) {
		board_id = BOARD_ID_UNKNOWN;
		goto get_type;
	}

	if (board_id == BOARD_ID_UNKNOWN)
		board_id = BOARD_DEFAULT;
#else
	board_id = BOARD_DEFAULT;
#endif

get_type:
	*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;
		return ret;
	}

	*rev = board_tbl[*type][(uint8_t) (board_id & BOARD_REV_MASK)];

	return ret;
}