Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 1 | /* |
Yusuke Goda | 94ea41b | 2019-11-28 13:30:58 +0900 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 3 | * reserved. |
| 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <lib/utils_def.h> |
| 11 | |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 12 | #include <iic_dvfs.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 14 | #include "board.h" |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 15 | |
| 16 | #ifndef BOARD_DEFAULT |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 17 | #if (RCAR_LSI == RCAR_D3) |
| 18 | #define BOARD_DEFAULT (BOARD_DRAAK << BOARD_CODE_SHIFT) |
| 19 | #elif (RCAR_LSI == RCAR_E3) |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 20 | #define BOARD_DEFAULT (BOARD_EBISU << BOARD_CODE_SHIFT) |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 21 | #elif (RCAR_LSI == RCAR_V3M) |
| 22 | #define BOARD_DEFAULT (BOARD_EAGLE << BOARD_CODE_SHIFT) |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 23 | #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 | |
| 33 | #define SXS_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 34 | #define SX_ID { 0x10U, 0x11U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Yusuke Goda | 908b1ca | 2019-03-11 15:09:39 +0900 | [diff] [blame] | 35 | #define SKP_ID { 0x10U, 0x10U, 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Yusuke Goda | 94ea41b | 2019-11-28 13:30:58 +0900 | [diff] [blame] | 36 | #define SK_ID { 0x10U, 0x30U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 37 | #define EB4_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 38 | #define EB_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 39 | #define DR_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 40 | #define EA_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 41 | #define KK_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
| 42 | |
| 43 | const 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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 51 | [BOARD_DRAAK] = "Draak", |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 52 | [BOARD_EAGLE] = "Eagle", |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 53 | [BOARD_UNKNOWN] = "unknown" |
| 54 | }; |
| 55 | |
| 56 | int32_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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 66 | [BOARD_DRAAK] = DR_ID, |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 67 | [BOARD_EAGLE] = EA_ID, |
Jorge Ramirez-Ortiz | 268162f | 2018-09-23 09:39:11 +0200 | [diff] [blame] | 68 | [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 | |
| 89 | get_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 | } |