blob: dbbaed659e9c9b483108076c9d6d2871c138d334 [file] [log] [blame]
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +02001/*
Toshiyuki Ogasaharadebafb82020-11-30 14:52:19 +09002 * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +02003 * 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
Marek Vasut4ae342c2019-01-05 13:56:03 +010017#if (RCAR_LSI == RCAR_D3)
18#define BOARD_DEFAULT (BOARD_DRAAK << BOARD_CODE_SHIFT)
19#elif (RCAR_LSI == RCAR_E3)
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020020#define BOARD_DEFAULT (BOARD_EBISU << BOARD_CODE_SHIFT)
Valentine Barshakf2184142018-10-30 02:06:17 +030021#elif (RCAR_LSI == RCAR_V3M)
22#define BOARD_DEFAULT (BOARD_EAGLE << BOARD_CODE_SHIFT)
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020023#else
24#define BOARD_DEFAULT (BOARD_SALVATOR_X << BOARD_CODE_SHIFT)
25#endif
26#endif
27
28#define BOARD_CODE_MASK (0xF8)
29#define BOARD_REV_MASK (0x07)
30#define BOARD_CODE_SHIFT (0x03)
31#define BOARD_ID_UNKNOWN (0xFF)
32
Toshiyuki Ogasaharadebafb82020-11-30 14:52:19 +090033#define SXS_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020034#define SX_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Toshiyuki Ogasaharadebafb82020-11-30 14:52:19 +090035#define SKP_ID { 0x10U, 0x10U, 0x20U, 0x21U, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Yusuke Goda94ea41b2019-11-28 13:30:58 +090036#define SK_ID { 0x10U, 0x30U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020037#define EB4_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
38#define EB_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Marek Vasut4ae342c2019-01-05 13:56:03 +010039#define DR_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Valentine Barshakf2184142018-10-30 02:06:17 +030040#define EA_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020041#define KK_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU }
42
43const char *g_board_tbl[] = {
44 [BOARD_STARTER_KIT_PRE] = "Starter Kit Premier",
45 [BOARD_STARTER_KIT] = "Starter Kit",
46 [BOARD_SALVATOR_XS] = "Salvator-XS",
47 [BOARD_SALVATOR_X] = "Salvator-X",
48 [BOARD_EBISU_4D] = "Ebisu-4D",
49 [BOARD_KRIEK] = "Kriek",
50 [BOARD_EBISU] = "Ebisu",
Marek Vasut4ae342c2019-01-05 13:56:03 +010051 [BOARD_DRAAK] = "Draak",
Valentine Barshakf2184142018-10-30 02:06:17 +030052 [BOARD_EAGLE] = "Eagle",
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020053 [BOARD_UNKNOWN] = "unknown"
54};
55
56int32_t rcar_get_board_type(uint32_t *type, uint32_t *rev)
57{
58 int32_t ret = 0;
59 const uint8_t board_tbl[][8] = {
60 [BOARD_STARTER_KIT_PRE] = SKP_ID,
61 [BOARD_SALVATOR_XS] = SXS_ID,
62 [BOARD_STARTER_KIT] = SK_ID,
63 [BOARD_SALVATOR_X] = SX_ID,
64 [BOARD_EBISU_4D] = EB4_ID,
65 [BOARD_EBISU] = EB_ID,
Marek Vasut4ae342c2019-01-05 13:56:03 +010066 [BOARD_DRAAK] = DR_ID,
Valentine Barshakf2184142018-10-30 02:06:17 +030067 [BOARD_EAGLE] = EA_ID,
Jorge Ramirez-Ortiz268162f2018-09-23 09:39:11 +020068 [BOARD_KRIEK] = KK_ID,
69 };
70 static uint8_t board_id = BOARD_ID_UNKNOWN;
71
72 if (board_id != BOARD_ID_UNKNOWN)
73 goto get_type;
74
75#if PMIC_ROHM_BD9571
76 /* Board ID detection from EEPROM */
77 ret = rcar_iic_dvfs_receive(EEPROM, BOARD_ID, &board_id);
78 if (ret) {
79 board_id = BOARD_ID_UNKNOWN;
80 goto get_type;
81 }
82
83 if (board_id == BOARD_ID_UNKNOWN)
84 board_id = BOARD_DEFAULT;
85#else
86 board_id = BOARD_DEFAULT;
87#endif
88
89get_type:
90 *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
91
92 if (*type >= ARRAY_SIZE(board_tbl)) {
93 /* no revision information, set Rev0.0. */
94 *rev = 0;
95 return ret;
96 }
97
98 *rev = board_tbl[*type][(uint8_t) (board_id & BOARD_REV_MASK)];
99
100 return ret;
101}