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