Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <lib/mmio.h> |
| 11 | |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 12 | #include "rcar_def.h" |
| 13 | #if RCAR_LSI == RCAR_AUTO |
| 14 | #include "H3/pfc_init_h3_v1.h" |
| 15 | #include "H3/pfc_init_h3_v2.h" |
| 16 | #include "M3/pfc_init_m3.h" |
| 17 | #include "M3N/pfc_init_m3n.h" |
| 18 | #endif |
| 19 | #if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) /* H3 */ |
| 20 | #include "H3/pfc_init_h3_v1.h" |
| 21 | #include "H3/pfc_init_h3_v2.h" |
| 22 | #endif |
| 23 | #if RCAR_LSI == RCAR_M3 /* M3 */ |
| 24 | #include "M3/pfc_init_m3.h" |
| 25 | #endif |
| 26 | #if RCAR_LSI == RCAR_M3N /* M3N */ |
| 27 | #include "M3N/pfc_init_m3n.h" |
| 28 | #endif |
| 29 | #if RCAR_LSI == RCAR_E3 /* E3 */ |
| 30 | #include "E3/pfc_init_e3.h" |
| 31 | #endif |
Marek Vasut | 6f4984c | 2018-06-14 06:26:45 +0200 | [diff] [blame] | 32 | #if RCAR_LSI == RCAR_D3 /* D3 */ |
| 33 | #include "D3/pfc_init_d3.h" |
| 34 | #endif |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 35 | |
| 36 | /* Product Register */ |
| 37 | #define PRR (0xFFF00044U) |
| 38 | #define PRR_PRODUCT_MASK (0x00007F00U) |
| 39 | #define PRR_CUT_MASK (0x000000FFU) |
| 40 | #define PRR_PRODUCT_H3 (0x00004F00U) /* R-Car H3 */ |
| 41 | #define PRR_PRODUCT_M3 (0x00005200U) /* R-Car M3 */ |
| 42 | #define PRR_PRODUCT_M3N (0x00005500U) /* R-Car M3N */ |
| 43 | #define PRR_PRODUCT_E3 (0x00005700U) /* R-Car E3 */ |
Marek Vasut | 6f4984c | 2018-06-14 06:26:45 +0200 | [diff] [blame] | 44 | #define PRR_PRODUCT_D3 (0x00005800U) /* R-Car D3 */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 45 | #define PRR_PRODUCT_10 (0x00U) |
| 46 | #define PRR_PRODUCT_11 (0x01U) |
| 47 | #define PRR_PRODUCT_20 (0x10U) |
| 48 | |
| 49 | #define PRR_PRODUCT_ERR(reg) do{\ |
| 50 | ERROR("LSI Product ID(PRR=0x%x) PFC "\ |
| 51 | "initialize not supported.\n",reg);\ |
| 52 | panic();\ |
| 53 | }while(0) |
| 54 | #define PRR_CUT_ERR(reg) do{\ |
| 55 | ERROR("LSI Cut ID(PRR=0x%x) PFC "\ |
| 56 | "initialize not supported.\n",reg);\ |
| 57 | panic();\ |
| 58 | }while(0) |
| 59 | |
| 60 | void rcar_pfc_init(void) |
| 61 | { |
| 62 | uint32_t reg; |
| 63 | |
| 64 | reg = mmio_read_32(RCAR_PRR); |
| 65 | #if RCAR_LSI == RCAR_AUTO |
| 66 | switch (reg & RCAR_PRODUCT_MASK) { |
| 67 | case RCAR_PRODUCT_H3: |
| 68 | switch (reg & PRR_CUT_MASK) { |
| 69 | case PRR_PRODUCT_10: /* H3 Ver.1.0 */ |
| 70 | pfc_init_h3_v1(); |
| 71 | break; |
| 72 | case PRR_PRODUCT_11: /* H3 Ver.1.1 */ |
| 73 | pfc_init_h3_v1(); |
| 74 | break; |
| 75 | default: /* H3 Ver.2.0 or later */ |
| 76 | pfc_init_h3_v2(); |
| 77 | break; |
| 78 | } |
| 79 | break; |
| 80 | case RCAR_PRODUCT_M3: |
| 81 | pfc_init_m3(); |
| 82 | break; |
| 83 | case RCAR_PRODUCT_M3N: |
| 84 | pfc_init_m3n(); |
| 85 | break; |
| 86 | default: |
| 87 | PRR_PRODUCT_ERR(reg); |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | #elif RCAR_LSI_CUT_COMPAT |
| 92 | switch (reg & PRR_PRODUCT_MASK) { |
| 93 | case PRR_PRODUCT_H3: |
| 94 | #if (RCAR_LSI != RCAR_H3) && (RCAR_LSI != RCAR_H3N) |
| 95 | PRR_PRODUCT_ERR(reg); |
| 96 | #else |
| 97 | switch (reg & PRR_CUT_MASK) { |
| 98 | case PRR_PRODUCT_10: /* H3 Ver.1.0 */ |
| 99 | pfc_init_h3_v1(); |
| 100 | break; |
| 101 | case PRR_PRODUCT_11: /* H3 Ver.1.1 */ |
| 102 | pfc_init_h3_v1(); |
| 103 | break; |
| 104 | default: /* H3 Ver.2.0 or later */ |
| 105 | pfc_init_h3_v2(); |
| 106 | break; |
| 107 | } |
| 108 | #endif |
| 109 | break; |
| 110 | case PRR_PRODUCT_M3: |
| 111 | #if RCAR_LSI != RCAR_M3 |
| 112 | PRR_PRODUCT_ERR(reg); |
| 113 | #else |
| 114 | pfc_init_m3(); |
| 115 | #endif |
| 116 | break; |
| 117 | case PRR_PRODUCT_M3N: |
| 118 | #if RCAR_LSI != RCAR_M3N |
| 119 | PRR_PRODUCT_ERR(reg); |
| 120 | #else |
| 121 | pfc_init_m3n(); |
| 122 | #endif |
| 123 | break; |
| 124 | case PRR_PRODUCT_E3: |
| 125 | #if RCAR_LSI != RCAR_E3 |
| 126 | PRR_PRODUCT_ERR(reg); |
| 127 | #else |
| 128 | pfc_init_e3(); |
| 129 | #endif |
| 130 | break; |
Marek Vasut | 6f4984c | 2018-06-14 06:26:45 +0200 | [diff] [blame] | 131 | case PRR_PRODUCT_D3: |
| 132 | #if RCAR_LSI != RCAR_D3 |
| 133 | PRR_PRODUCT_ERR(reg); |
| 134 | #else |
| 135 | pfc_init_d3(); |
| 136 | #endif |
| 137 | break; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 138 | default: |
| 139 | PRR_PRODUCT_ERR(reg); |
| 140 | break; |
| 141 | } |
| 142 | |
| 143 | #else |
| 144 | #if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) /* H3 */ |
| 145 | #if RCAR_LSI_CUT == RCAR_CUT_10 |
| 146 | /* H3 Ver.1.0 */ |
| 147 | if ((PRR_PRODUCT_H3 | PRR_PRODUCT_10) |
| 148 | != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) { |
| 149 | PRR_PRODUCT_ERR(reg); |
| 150 | } |
| 151 | pfc_init_h3_v1(); |
| 152 | #elif RCAR_LSI_CUT == RCAR_CUT_11 |
| 153 | /* H3 Ver.1.1 */ |
| 154 | if ((PRR_PRODUCT_H3 | PRR_PRODUCT_11) |
| 155 | != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) { |
| 156 | PRR_PRODUCT_ERR(reg); |
| 157 | } |
| 158 | pfc_init_h3_v1(); |
| 159 | #else |
| 160 | /* H3 Ver.2.0 or later */ |
| 161 | if (PRR_PRODUCT_H3 != (reg & PRR_PRODUCT_MASK)) { |
| 162 | PRR_PRODUCT_ERR(reg); |
| 163 | } |
| 164 | pfc_init_h3_v2(); |
| 165 | #endif |
| 166 | #elif RCAR_LSI == RCAR_M3 /* M3 */ |
| 167 | if ((PRR_PRODUCT_M3) != (reg & PRR_PRODUCT_MASK)) { |
| 168 | PRR_PRODUCT_ERR(reg); |
| 169 | } |
| 170 | pfc_init_m3(); |
| 171 | #elif RCAR_LSI == RCAR_M3N /* M3N */ |
| 172 | if ((PRR_PRODUCT_M3N) != (reg & PRR_PRODUCT_MASK)) { |
| 173 | PRR_PRODUCT_ERR(reg); |
| 174 | } |
| 175 | pfc_init_m3n(); |
| 176 | #elif RCAR_LSI == RCAR_E3 /* E3 */ |
| 177 | if ((PRR_PRODUCT_E3) != (reg & PRR_PRODUCT_MASK)) { |
| 178 | PRR_PRODUCT_ERR(reg); |
| 179 | } |
| 180 | pfc_init_e3(); |
Marek Vasut | 6f4984c | 2018-06-14 06:26:45 +0200 | [diff] [blame] | 181 | #elif RCAR_LSI == RCAR_D3 /* D3 */ |
| 182 | if ((PRR_PRODUCT_D3) != (reg & PRR_PRODUCT_MASK)) { |
| 183 | PRR_PRODUCT_ERR(reg); |
| 184 | } |
| 185 | pfc_init_d3(); |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 186 | #else |
| 187 | #error "Don't have PFC initialize routine(unknown)." |
| 188 | #endif |
| 189 | #endif |
| 190 | } |