diff --git a/plat/renesas/rcar/bl2_rcar_setup.c b/plat/renesas/rcar/bl2_rcar_setup.c index 52cb5dc905..aace1bfbc2 100755 --- a/plat/renesas/rcar/bl2_rcar_setup.c +++ b/plat/renesas/rcar/bl2_rcar_setup.c @@ -341,8 +341,6 @@ void bl2_early_platform_setup(meminfo_t *mem_layout) uint32_t modemr; uint32_t modemr_boot_dev; int32_t ret; - uint32_t board_type; - uint32_t board_rev; uint32_t prr_val; char msg[128]; const char *str; @@ -439,24 +437,12 @@ void bl2_early_platform_setup(meminfo_t *mem_layout) + RCAR_MAJOR_OFFSET, (prr_val & RCAR_MINOR_MASK)); NOTICE("%s", msg); - /* Board ID detection */ - (void)get_board_type(&board_type, &board_rev); - - switch (board_type) { - case BOARD_SALVATOR_X: - case BOARD_SALVATOR_XS: - case BOARD_KRIEK: - case BOARD_STARTER_KIT: - /* Do nothing. */ - break; - default: - board_type = BOARD_UNKNOWN; - break; - } - - (void)sprintf(msg, "BL2: Board is %s Rev%d.%d\n", - GET_BOARD_NAME(board_type), GET_BOARD_MAJOR(board_rev), - GET_BOARD_MINOR(board_rev)); + board_id_init(); + + (void)sprintf(msg, "BL2: Board %s Rev%d.%d\n", + get_board_name(), + get_board_rev_major(), + get_board_rev_minor()); NOTICE("%s", msg); #if RCAR_LSI != RCAR_AUTO @@ -830,8 +816,9 @@ void bl2_init_generic_timer(void) 12500000U, /* MD14/MD13 : 0b10 */ 16666600U}; /* MD14/MD13 : 0b11 */ uint32_t reg_cntfid; - uint32_t board_type; - uint32_t board_rev; + + /* board id initialization before bl2_early_platform_setup */ + board_id_init(); modemr = mmio_read_32(RCAR_MODEMR); modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK); @@ -841,10 +828,8 @@ void bl2_init_generic_timer(void) reg = mmio_read_32(RCAR_PRR) & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK); switch (modemr_pll) { case MD14_MD13_TYPE_0: - (void)get_board_type(&board_type, &board_rev); - if (BOARD_SALVATOR_XS == board_type) { + if (board_is(BOARD_SALVATOR_XS)) reg_cntfid = 8320000U; - } break; case MD14_MD13_TYPE_3: if (RCAR_PRODUCT_H3_CUT10 == reg) { @@ -863,4 +848,3 @@ void bl2_init_generic_timer(void) (uint32_t)CNTCR_EN); } - diff --git a/plat/renesas/rcar/drivers/board/board.c b/plat/renesas/rcar/drivers/board/board.c index 7b7c8c7885..2c473489ed 100644 --- a/plat/renesas/rcar/drivers/board/board.c +++ b/plat/renesas/rcar/drivers/board/board.c @@ -27,83 +27,104 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "board.h" +static uint8_t board_id = BOARD_ID_UNKNOWN; -/************************************************************************ - * Defines - ************************************************************************/ -#ifndef BOARD_DEFAULT -#define BOARD_DEFAULT (BOARD_SALVATOR_X << BOARD_CODE_SHIFT) +void board_id_init() +{ + uint8_t id = BOARD_ID_UNKNOWN; +#if PMIC_ON_BOARD && !defined(BOARD_ID) + int ret; #endif -#define SLAVE_ADDR_EEPROM (0x50U) -#define REG_ADDR_BOARD_ID (0x70U) + /* board detection and validation had been done already */ + if (board_id != BOARD_ID_UNKNOWN) + return; -#define BOARD_CODE_MASK (0xF8U) -#define BOARD_REV_MASK (0x07U) -#define BOARD_CODE_SHIFT (3U) +#if PMIC_ON_BOARD && !defined(BOARD_ID) + /* Board ID detection from EEPROM */ + ret = rcar_iic_dvfs_recieve(PMIC_EEPROM_SLAVE_ADDR, + PMIC_EEPROM_BOARD_ID_REG_ADDR, &id); + if (ret != 0) + id = BOARD_ID_UNKNOWN; +#endif -#define BOARD_ID_UNKNOWN (0xFFU) +#ifdef BOARD_ID + id = BOARD_ID; +#endif + if (id == BOARD_ID_UNKNOWN) + id = BOARD_ID_DEFAULT; + switch (id >> BOARD_ID_NAME_SHIFT) { + case BOARD_SALVATOR_X: + case BOARD_KRIEK: + case BOARD_STARTER_KIT: + case BOARD_SALVATOR_XS: + break; + default: + id = BOARD_ID_DEFAULT; + break; + } + + board_id = id; +} -/************************************************************************ - * Global variables - ************************************************************************/ -const char *g_board_tbl[] = { +static const char *board_name[] = { [BOARD_SALVATOR_X] = "Salvator-X", - [BOARD_SALVATOR_XS] = "Salvator-XS", [BOARD_KRIEK] = "Kriek", - [BOARD_STARTER_KIT] = "Starter Kit" + [BOARD_STARTER_KIT] = "Starter Kit", + [BOARD_SALVATOR_XS] = "Salvator-XS" }; -const char *g_board_unknown = "unknown"; +int32_t get_board_id() +{ + return board_id; +} -int32_t get_board_type(uint32_t *type, uint32_t *rev) +const char *get_board_name() { - int32_t ret = 0; - uint8_t read_rev; - static uint8_t g_board_id = BOARD_ID_UNKNOWN; - const uint8_t board_tbl[][8U] = { - [BOARD_SALVATOR_X] = {0x10U, 0x11U, 0xFFU, 0xFFU, - 0xFFU, 0xFFU, 0xFFU, 0xFFU}, - [BOARD_KRIEK] = {0x10U, 0xFFU, 0xFFU, 0xFFU, - 0xFFU, 0xFFU, 0xFFU, 0xFFU}, - [BOARD_STARTER_KIT] = {0x10U, 0xFFU, 0xFFU, 0xFFU, - 0xFFU, 0xFFU, 0xFFU, 0xFFU}, - [BOARD_SALVATOR_XS] = {0x10U, 0xFFU, 0xFFU, 0xFFU, - 0xFFU, 0xFFU, 0xFFU, 0xFFU}, - }; - - if (BOARD_ID_UNKNOWN == g_board_id) { -#if PMIC_ON_BOARD - /* Board ID detection from EEPROM */ - ret = rcar_iic_dvfs_recieve(SLAVE_ADDR_EEPROM, - REG_ADDR_BOARD_ID, &g_board_id); - if (0 != ret) { - g_board_id = BOARD_ID_UNKNOWN; - } else if (BOARD_ID_UNKNOWN == g_board_id) { - /* Can't recognize the board */ - g_board_id = BOARD_DEFAULT; - } else { - /* none */ - } -#else - g_board_id = BOARD_DEFAULT; -#endif - } + return board_name[board_id]; +} - *type = ((uint32_t)g_board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT; - if (*type < (sizeof(board_tbl) / sizeof(board_tbl[0]))) { - read_rev = (uint8_t)(g_board_id & BOARD_REV_MASK); - *rev = board_tbl[*type][read_rev]; - } else { - /* If there is no revision information, set Rev0.0. */ - *rev = 0x00U; - } +/* board rev ID is not linearly mapped to revision string + * 0 : rev1.0 + * 1 : rev1.1 + * ... + * + * rev ID translation is done via lookup table as below + * + * 7 4 3 0 + * +--------+--------+ + * | major | minor | + * +--------+--------+ + */ +static const uint8_t board_rev[] = { + /* 0 1 2 3 */ + 0x10U, 0x11U, 0xFFU, 0xFFU, + /* 4 5 6 7 */ + 0xFFU, 0xFFU, 0xFFU, 0xFFU +}; + +int32_t get_board_rev() +{ + int32_t rev = board_id & BOARD_ID_REV_MASK; + + return board_rev[rev]; +} + +int32_t get_board_rev_major() +{ + int32_t rev = board_id & BOARD_ID_REV_MASK; + + return board_rev[rev] >> 4; +} + +int32_t get_board_rev_minor() +{ + int32_t rev = board_id & BOARD_ID_REV_MASK; - return ret; + return board_rev[rev] & 0xFU; } diff --git a/plat/renesas/rcar/drivers/board/board.h b/plat/renesas/rcar/drivers/board/board.h index 898d28af96..aeb7cc3e08 100644 --- a/plat/renesas/rcar/drivers/board/board.h +++ b/plat/renesas/rcar/drivers/board/board.h @@ -27,38 +27,43 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _RCAR_BOARD_H_ +#define _RCAR_BOARD_H_ -#ifndef BOARD_H_ -#define BOARD_H_ - - -/************************************************************************ - * Board type - ************************************************************************/ -#define BOARD_SALVATOR_X (0x00U) -#define BOARD_SALVATOR_XS (0x04U) -#define BOARD_KRIEK (0x01U) -#define BOARD_STARTER_KIT (0x02U) +/* board ID register in the EEPROM (e.g. BR24T01FVM-W) + * + * 7 3 2 0 + * +------------+--------+ + * | name ID | rev ID | + * +------------+--------+ + */ +#define PMIC_EEPROM_SLAVE_ADDR (0x50U) +#define PMIC_EEPROM_BOARD_ID_REG_ADDR (0x70U) -#define BOARD_UNKNOWN (0x1FU) +/* board ID bit fields definition */ +#define BOARD_ID_NAME_MASK (0xF8U) +#define BOARD_ID_NAME_SHIFT (3U) +#define BOARD_ID_REV_MASK (0x07U) -/************************************************************************ - * Board name - ************************************************************************/ -extern const char *g_board_tbl[]; -extern const char *g_board_unknown; +/* board name ID */ +#define BOARD_SALVATOR_X (0x00U) +#define BOARD_KRIEK (0x01U) +#define BOARD_STARTER_KIT (0x02U) /* i.e. ULCB */ +#define BOARD_SALVATOR_XS (0x04U) +#define BOARD_UNKNOWN (0x1FU) -/************************************************************************ - * Revisions are expressed in 8 bits. - * The upper 4 bits are major version. - * The lower 4 bits are minor version. - ************************************************************************/ -#define GET_BOARD_MAJOR(a) ((uint32_t)(a) >> 4U) -#define GET_BOARD_MINOR(a) ((uint32_t)(a) & 0xFU) +/* If board ID is not specified during compiling, or board detection fails, + * then fallback to Salvator-X Rev1.0 */ +#define BOARD_ID_DEFAULT (BOARD_SALVATOR_X << BOARD_ID_NAME_SHIFT) +#define BOARD_ID_UNKNOWN (0xFFU) -#define GET_BOARD_NAME(a) ((BOARD_UNKNOWN != (a)) ?\ - g_board_tbl[(a)] : g_board_unknown) +#define board_is(board) ((get_board_id() >> BOARD_ID_NAME_SHIFT) == board) -int32_t get_board_type(uint32_t *type, uint32_t *rev); +void board_id_init(); +int32_t get_board_id(); +const char *get_board_name(); +int32_t get_board_name_id(); +int32_t get_board_rev_major(); +int32_t get_board_rev_minor(); -#endif /* BOARD_H_ */ +#endif /* _RCAR_BOARD_H_ */ diff --git a/plat/renesas/rcar/drivers/board/board.mk b/plat/renesas/rcar/drivers/board/board.mk new file mode 100644 index 0000000000..5c07398f8c --- /dev/null +++ b/plat/renesas/rcar/drivers/board/board.mk @@ -0,0 +1,49 @@ +# +# Copyright (c) 2017, Renesas Electronics Corporation, All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# - Neither the name of Renesas nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# board selection + +# Process RCAR_GEN3_ULCB flag +ifndef RCAR_GEN3_ULCB + RCAR_GEN3_ULCB := 0 +endif +$(eval $(call add_define,RCAR_GEN3_ULCB)) + +# Process BOARD_ID flag +ifeq (${RCAR_GEN3_ULCB},1) + ifndef BOARD_ID + BOARD_ID := 0x10 + endif +endif + +ifdef BOARD_ID + $(eval $(call add_define,BOARD_ID)) +endif + diff --git a/plat/renesas/rcar/platform.mk b/plat/renesas/rcar/platform.mk index ef7bf0f33e..09433d6a4b 100644 --- a/plat/renesas/rcar/platform.mk +++ b/plat/renesas/rcar/platform.mk @@ -232,16 +232,7 @@ PMIC_LEVEL_MODE := 1 endif $(eval $(call add_define,PMIC_LEVEL_MODE)) -# Process RCAR_GEN3_ULCB flag -ifndef RCAR_GEN3_ULCB -RCAR_GEN3_ULCB := 0 -endif -ifeq (${RCAR_GEN3_ULCB},1) - BOARD_DEFAULT := 0x10 - $(eval $(call add_define,BOARD_DEFAULT)) -endif -$(eval $(call add_define,RCAR_GEN3_ULCB)) - +include plat/renesas/rcar/drivers/board/board.mk include plat/renesas/rcar/ddr/ddr.mk include plat/renesas/rcar/qos/qos.mk include plat/renesas/rcar/pfc/pfc.mk