Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Masahiro Yamada | 56da564 | 2020-02-03 19:46:40 +0900 | [diff] [blame] | 7 | #include <common/bl_common.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <lib/mmio.h> |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 9 | |
| 10 | #include "uniphier.h" |
| 11 | |
Masahiro Yamada | 56da564 | 2020-02-03 19:46:40 +0900 | [diff] [blame] | 12 | #define UNIPHIER_REVISION 0x5f800000UL |
| 13 | #define UNIPHIER_REVISION_NEW 0x1f800000UL |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 14 | |
| 15 | static unsigned int uniphier_get_revision_field(unsigned int mask, |
| 16 | unsigned int shift) |
| 17 | { |
Masahiro Yamada | 56da564 | 2020-02-03 19:46:40 +0900 | [diff] [blame] | 18 | uintptr_t reg; |
| 19 | |
| 20 | if (BL_CODE_BASE >= 0x80000000UL) |
| 21 | reg = UNIPHIER_REVISION; |
| 22 | else |
| 23 | reg = UNIPHIER_REVISION_NEW; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 24 | |
Masahiro Yamada | 56da564 | 2020-02-03 19:46:40 +0900 | [diff] [blame] | 25 | return (mmio_read_32(reg) >> shift) & mask; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | unsigned int uniphier_get_soc_type(void) |
| 29 | { |
| 30 | return uniphier_get_revision_field(0xff, 16); |
| 31 | } |
| 32 | |
| 33 | unsigned int uniphier_get_soc_model(void) |
| 34 | { |
| 35 | return uniphier_get_revision_field(0x07, 8); |
| 36 | } |
| 37 | |
| 38 | unsigned int uniphier_get_soc_revision(void) |
| 39 | { |
| 40 | return uniphier_get_revision_field(0x1f, 0); |
| 41 | } |
| 42 | |
| 43 | unsigned int uniphier_get_soc_id(void) |
| 44 | { |
| 45 | uint32_t type = uniphier_get_soc_type(); |
| 46 | |
| 47 | switch (type) { |
| 48 | case 0x31: |
| 49 | return UNIPHIER_SOC_LD11; |
| 50 | case 0x32: |
| 51 | return UNIPHIER_SOC_LD20; |
| 52 | case 0x35: |
| 53 | return UNIPHIER_SOC_PXS3; |
| 54 | default: |
| 55 | return UNIPHIER_SOC_UNKNOWN; |
| 56 | } |
| 57 | } |