Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 1 | /* |
| 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> |
| 9 | #include <iic_dvfs.h> |
| 10 | #include "board.h" |
| 11 | #include "utils_def.h" |
| 12 | |
| 13 | #ifndef BOARD_DEFAULT |
| 14 | #if (RCAR_LSI == RCAR_E3) |
| 15 | #define BOARD_DEFAULT (BOARD_EBISU << BOARD_CODE_SHIFT) |
| 16 | #else |
| 17 | #define BOARD_DEFAULT (BOARD_SALVATOR_X << BOARD_CODE_SHIFT) |
| 18 | #endif |
| 19 | #endif |
| 20 | |
| 21 | #define BOARD_CODE_MASK (0xF8) |
| 22 | #define BOARD_REV_MASK (0x07) |
| 23 | #define BOARD_CODE_SHIFT (0x03) |
| 24 | #define BOARD_ID_UNKNOWN (0xFF) |
| 25 | |
| 26 | #define SXS_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 27 | #define SX_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 28 | #define SKP_ID { 0x10U, 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 29 | #define SK_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 30 | #define EB4_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 31 | #define EB_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 32 | #define KK_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 33 | |
| 34 | const char *g_board_tbl[] = { |
| 35 | [BOARD_STARTER_KIT_PRE] = "Starter Kit Premier", |
| 36 | [BOARD_STARTER_KIT] = "Starter Kit", |
| 37 | [BOARD_SALVATOR_XS] = "Salvator-XS", |
| 38 | [BOARD_SALVATOR_X] = "Salvator-X", |
| 39 | [BOARD_EBISU_4D] = "Ebisu-4D", |
| 40 | [BOARD_KRIEK] = "Kriek", |
| 41 | [BOARD_EBISU] = "Ebisu", |
| 42 | [BOARD_UNKNOWN] = "unknown" |
| 43 | }; |
| 44 | |
| 45 | int32_t rcar_get_board_type(uint32_t *type, uint32_t *rev) |
| 46 | { |
| 47 | int32_t ret = 0; |
| 48 | const uint8_t board_tbl[][8] = { |
| 49 | [BOARD_STARTER_KIT_PRE] = SKP_ID, |
| 50 | [BOARD_SALVATOR_XS] = SXS_ID, |
| 51 | [BOARD_STARTER_KIT] = SK_ID, |
| 52 | [BOARD_SALVATOR_X] = SX_ID, |
| 53 | [BOARD_EBISU_4D] = EB4_ID, |
| 54 | [BOARD_EBISU] = EB_ID, |
| 55 | [BOARD_KRIEK] = KK_ID, |
| 56 | }; |
| 57 | static uint8_t board_id = BOARD_ID_UNKNOWN; |
| 58 | |
| 59 | if (board_id != BOARD_ID_UNKNOWN) |
| 60 | goto get_type; |
| 61 | |
| 62 | #if PMIC_ROHM_BD9571 |
| 63 | /* Board ID detection from EEPROM */ |
| 64 | ret = rcar_iic_dvfs_receive(EEPROM, BOARD_ID, &board_id); |
| 65 | if (ret) { |
| 66 | board_id = BOARD_ID_UNKNOWN; |
| 67 | goto get_type; |
| 68 | } |
| 69 | |
| 70 | if (board_id == BOARD_ID_UNKNOWN) |
| 71 | board_id = BOARD_DEFAULT; |
| 72 | #else |
| 73 | board_id = BOARD_DEFAULT; |
| 74 | #endif |
| 75 | |
| 76 | get_type: |
| 77 | *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT; |
| 78 | |
| 79 | if (*type >= ARRAY_SIZE(board_tbl)) { |
| 80 | /* no revision information, set Rev0.0. */ |
| 81 | *rev = 0; |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | *rev = board_tbl[*type][(uint8_t) (board_id & BOARD_REV_MASK)]; |
| 86 | |
| 87 | return ret; |
| 88 | } |