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