Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 1 | /* |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights reserved. |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | #include <lib/mmio.h> |
| 10 | #include <lib/utils_def.h> |
| 11 | |
| 12 | #include "board.h" |
| 13 | #include "rcar_def.h" |
| 14 | |
| 15 | #ifndef BOARD_DEFAULT |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 16 | #if (RCAR_LSI == RZ_G2H) |
| 17 | #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2H << BOARD_CODE_SHIFT) |
Lad Prabhakar | 21d04f0 | 2021-03-19 12:01:00 +0000 | [diff] [blame] | 18 | #elif (RCAR_LSI == RZ_G2N) |
| 19 | #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2N << BOARD_CODE_SHIFT) |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 20 | #elif (RCAR_LSI == RZ_G2E) |
| 21 | #define BOARD_DEFAULT (BOARD_EK874_RZ_G2E << BOARD_CODE_SHIFT) |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 22 | #else |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 23 | #define BOARD_DEFAULT (BOARD_HIHOPE_RZ_G2M << BOARD_CODE_SHIFT) |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 24 | #endif /* RCAR_LSI == RZ_G2H */ |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 25 | #endif /* BOARD_DEFAULT */ |
| 26 | |
| 27 | #define BOARD_CODE_MASK (0xF8U) |
| 28 | #define BOARD_REV_MASK (0x07U) |
| 29 | #define BOARD_CODE_SHIFT (0x03) |
| 30 | #define BOARD_ID_UNKNOWN (0xFFU) |
| 31 | |
| 32 | #define GPIO_INDT5 0xE605500C |
| 33 | #define GP5_19_BIT (0x01U << 19) |
| 34 | #define GP5_21_BIT (0x01U << 21) |
| 35 | #define GP5_25_BIT (0x01U << 25) |
| 36 | |
| 37 | #define HM_ID { 0x10U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 38 | #define HH_ID HM_ID |
Lad Prabhakar | 21d04f0 | 2021-03-19 12:01:00 +0000 | [diff] [blame] | 39 | #define HN_ID { 0x20U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU } |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 40 | #define EK_ID HM_ID |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 41 | |
| 42 | const char *g_board_tbl[] = { |
| 43 | [BOARD_HIHOPE_RZ_G2M] = "HiHope RZ/G2M", |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 44 | [BOARD_HIHOPE_RZ_G2H] = "HiHope RZ/G2H", |
Lad Prabhakar | 21d04f0 | 2021-03-19 12:01:00 +0000 | [diff] [blame] | 45 | [BOARD_HIHOPE_RZ_G2N] = "HiHope RZ/G2N", |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 46 | [BOARD_EK874_RZ_G2E] = "EK874 RZ/G2E", |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 47 | [BOARD_UNKNOWN] = "unknown" |
| 48 | }; |
| 49 | |
| 50 | void rzg_get_board_type(uint32_t *type, uint32_t *rev) |
| 51 | { |
| 52 | static uint8_t board_id = BOARD_ID_UNKNOWN; |
| 53 | const uint8_t board_tbl[][8] = { |
| 54 | [BOARD_HIHOPE_RZ_G2M] = HM_ID, |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 55 | [BOARD_HIHOPE_RZ_G2H] = HH_ID, |
Lad Prabhakar | 21d04f0 | 2021-03-19 12:01:00 +0000 | [diff] [blame] | 56 | [BOARD_HIHOPE_RZ_G2N] = HN_ID, |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 57 | [BOARD_EK874_RZ_G2E] = EK_ID, |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 58 | }; |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 59 | uint32_t reg; |
| 60 | #if (RCAR_LSI != RZ_G2E) |
| 61 | uint32_t boardInfo; |
| 62 | #endif /* RCAR_LSI == RZ_G2E */ |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 63 | |
| 64 | if (board_id == BOARD_ID_UNKNOWN) { |
| 65 | board_id = BOARD_DEFAULT; |
| 66 | } |
| 67 | |
| 68 | *type = ((uint32_t) board_id & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT; |
| 69 | |
| 70 | if (*type >= ARRAY_SIZE(board_tbl)) { |
| 71 | /* no revision information, set Rev0.0. */ |
| 72 | *rev = 0; |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
| 76 | reg = mmio_read_32(RCAR_PRR); |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 77 | #if (RCAR_LSI == RZ_G2E) |
| 78 | if (reg & RCAR_MINOR_MASK) { |
| 79 | *rev = 0x30U; |
| 80 | } else { |
| 81 | *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)]; |
| 82 | } |
| 83 | #else |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 84 | if ((reg & PRR_CUT_MASK) == RCAR_M3_CUT_VER11) { |
| 85 | *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)]; |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 86 | } else { |
Lad Prabhakar | e1c0f74 | 2020-12-21 13:51:58 +0000 | [diff] [blame] | 87 | reg = mmio_read_32(GPIO_INDT5); |
Lad Prabhakar | 21d04f0 | 2021-03-19 12:01:00 +0000 | [diff] [blame] | 88 | if (reg & GP5_25_BIT) { |
| 89 | *rev = board_tbl[*type][(uint8_t)(board_id & BOARD_REV_MASK)]; |
| 90 | } else { |
| 91 | boardInfo = reg & (GP5_19_BIT | GP5_21_BIT); |
| 92 | *rev = (((boardInfo & GP5_19_BIT) >> 14) | |
| 93 | ((boardInfo & GP5_21_BIT) >> 17)) + 0x30U; |
| 94 | } |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 95 | } |
Lad Prabhakar | ea64734 | 2021-03-19 12:14:01 +0000 | [diff] [blame] | 96 | #endif /* RCAR_LSI == RZ_G2E */ |
Biju Das | 40e8073 | 2020-12-07 16:29:22 +0000 | [diff] [blame] | 97 | } |