Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 10 | #include <errno.h> |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 11 | #include <asm/processor.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/ppc4xx-gpio.h> |
| 14 | |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 15 | #include "405ep.h" |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 16 | #include <gdsys_fpga.h> |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 17 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 18 | #include "../common/osd.h" |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 19 | #include "../common/mclink.h" |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 20 | #include "../common/phy.h" |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 21 | |
| 22 | #include <i2c.h> |
| 23 | #include <pca953x.h> |
| 24 | #include <pca9698.h> |
| 25 | |
| 26 | #include <miiphy.h> |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 29 | |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 30 | #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE) |
| 31 | #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100) |
| 32 | #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200) |
| 33 | |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 34 | #define MAX_MUX_CHANNELS 2 |
| 35 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 36 | enum { |
| 37 | UNITTYPE_MAIN_SERVER = 0, |
| 38 | UNITTYPE_MAIN_USER = 1, |
| 39 | UNITTYPE_VIDEO_SERVER = 2, |
| 40 | UNITTYPE_VIDEO_USER = 3, |
| 41 | }; |
| 42 | |
| 43 | enum { |
| 44 | HWVER_100 = 0, |
| 45 | HWVER_104 = 1, |
| 46 | HWVER_110 = 2, |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 47 | HWVER_120 = 3, |
| 48 | HWVER_200 = 4, |
| 49 | HWVER_210 = 5, |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 50 | HWVER_220 = 6, |
| 51 | HWVER_230 = 7, |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | enum { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 55 | FPGA_HWVER_200 = 0, |
| 56 | FPGA_HWVER_210 = 1, |
| 57 | }; |
| 58 | |
| 59 | enum { |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 60 | COMPRESSION_NONE = 0, |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 61 | COMPRESSION_TYPE1_DELTA = 1, |
| 62 | COMPRESSION_TYPE1_TYPE2_DELTA = 3, |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | enum { |
| 66 | AUDIO_NONE = 0, |
| 67 | AUDIO_TX = 1, |
| 68 | AUDIO_RX = 2, |
| 69 | AUDIO_RXTX = 3, |
| 70 | }; |
| 71 | |
| 72 | enum { |
| 73 | SYSCLK_147456 = 0, |
| 74 | }; |
| 75 | |
| 76 | enum { |
| 77 | RAM_DDR2_32 = 0, |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 78 | RAM_DDR3_32 = 1, |
| 79 | }; |
| 80 | |
| 81 | enum { |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 82 | CARRIER_SPEED_1G = 0, |
| 83 | CARRIER_SPEED_2_5G = 1, |
| 84 | }; |
| 85 | |
| 86 | enum { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 87 | MCFPGA_DONE = 1 << 0, |
| 88 | MCFPGA_INIT_N = 1 << 1, |
| 89 | MCFPGA_PROGRAM_N = 1 << 2, |
| 90 | MCFPGA_UPDATE_ENABLE_N = 1 << 3, |
| 91 | MCFPGA_RESET_N = 1 << 4, |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 94 | enum { |
| 95 | GPIO_MDC = 1 << 14, |
| 96 | GPIO_MDIO = 1 << 15, |
| 97 | }; |
| 98 | |
| 99 | unsigned int mclink_fpgacount; |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 100 | struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR; |
| 101 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 102 | int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data) |
| 103 | { |
| 104 | int res; |
| 105 | |
| 106 | switch (fpga) { |
| 107 | case 0: |
| 108 | out_le16(reg, data); |
| 109 | break; |
| 110 | default: |
| 111 | res = mclink_send(fpga - 1, regoff, data); |
| 112 | if (res < 0) { |
| 113 | printf("mclink_send reg %02lx data %04x returned %d\n", |
| 114 | regoff, data, res); |
| 115 | return res; |
| 116 | } |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data) |
| 124 | { |
| 125 | int res; |
| 126 | |
| 127 | switch (fpga) { |
| 128 | case 0: |
| 129 | *data = in_le16(reg); |
| 130 | break; |
| 131 | default: |
| 132 | if (fpga > mclink_fpgacount) |
| 133 | return -EINVAL; |
| 134 | res = mclink_receive(fpga - 1, regoff, data); |
| 135 | if (res < 0) { |
| 136 | printf("mclink_receive reg %02lx returned %d\n", |
| 137 | regoff, res); |
| 138 | return res; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 145 | /* |
| 146 | * Check Board Identity: |
| 147 | */ |
| 148 | int checkboard(void) |
| 149 | { |
Dirk Eibach | 6b4b92f | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 150 | char *s = getenv("serial#"); |
| 151 | |
| 152 | puts("Board: "); |
| 153 | |
| 154 | puts("IoCon"); |
| 155 | |
| 156 | if (s != NULL) { |
| 157 | puts(", serial# "); |
| 158 | puts(s); |
| 159 | } |
| 160 | |
| 161 | puts("\n"); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 166 | static void print_fpga_info(unsigned int fpga, bool rgmii2_present) |
Dirk Eibach | 6b4b92f | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 167 | { |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 168 | u16 versions; |
| 169 | u16 fpga_version; |
| 170 | u16 fpga_features; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 171 | unsigned unit_type; |
| 172 | unsigned hardware_version; |
| 173 | unsigned feature_compression; |
| 174 | unsigned feature_osd; |
| 175 | unsigned feature_audio; |
| 176 | unsigned feature_sysclock; |
| 177 | unsigned feature_ramconfig; |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 178 | unsigned feature_carrier_speed; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 179 | unsigned feature_carriers; |
| 180 | unsigned feature_video_channels; |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 181 | |
Dirk Eibach | 7623db9 | 2014-11-13 19:21:16 +0100 | [diff] [blame] | 182 | int legacy = get_fpga_state(fpga) & FPGA_STATE_PLATFORM; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 183 | |
Dirk Eibach | 7623db9 | 2014-11-13 19:21:16 +0100 | [diff] [blame] | 184 | FPGA_GET_REG(fpga, versions, &versions); |
| 185 | FPGA_GET_REG(fpga, fpga_version, &fpga_version); |
| 186 | FPGA_GET_REG(fpga, fpga_features, &fpga_features); |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 187 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 188 | unit_type = (versions & 0xf000) >> 12; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 189 | feature_compression = (fpga_features & 0xe000) >> 13; |
| 190 | feature_osd = fpga_features & (1<<11); |
| 191 | feature_audio = (fpga_features & 0x0600) >> 9; |
| 192 | feature_sysclock = (fpga_features & 0x0180) >> 7; |
| 193 | feature_ramconfig = (fpga_features & 0x0060) >> 5; |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 194 | feature_carrier_speed = fpga_features & (1<<4); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 195 | feature_carriers = (fpga_features & 0x000c) >> 2; |
| 196 | feature_video_channels = fpga_features & 0x0003; |
| 197 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 198 | if (legacy) |
| 199 | printf("legacy "); |
| 200 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 201 | switch (unit_type) { |
| 202 | case UNITTYPE_MAIN_USER: |
| 203 | printf("Mainchannel"); |
| 204 | break; |
| 205 | |
| 206 | case UNITTYPE_VIDEO_USER: |
| 207 | printf("Videochannel"); |
| 208 | break; |
| 209 | |
| 210 | default: |
| 211 | printf("UnitType %d(not supported)", unit_type); |
| 212 | break; |
| 213 | } |
| 214 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 215 | if (unit_type == UNITTYPE_MAIN_USER) { |
| 216 | if (legacy) |
| 217 | hardware_version = |
| 218 | (in_le16((void *)LATCH2_BASE)>>8) & 0x0f; |
| 219 | else |
| 220 | hardware_version = |
| 221 | (!!pca9698_get_value(0x20, 24) << 0) |
| 222 | | (!!pca9698_get_value(0x20, 25) << 1) |
| 223 | | (!!pca9698_get_value(0x20, 26) << 2) |
| 224 | | (!!pca9698_get_value(0x20, 27) << 3); |
| 225 | switch (hardware_version) { |
| 226 | case HWVER_100: |
| 227 | printf(" HW-Ver 1.00,"); |
| 228 | break; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 229 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 230 | case HWVER_104: |
| 231 | printf(" HW-Ver 1.04,"); |
| 232 | break; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 233 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 234 | case HWVER_110: |
| 235 | printf(" HW-Ver 1.10,"); |
| 236 | break; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 237 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 238 | case HWVER_120: |
| 239 | printf(" HW-Ver 1.20-1.21,"); |
| 240 | break; |
| 241 | |
| 242 | case HWVER_200: |
| 243 | printf(" HW-Ver 2.00,"); |
| 244 | break; |
| 245 | |
| 246 | case HWVER_210: |
| 247 | printf(" HW-Ver 2.10,"); |
| 248 | break; |
| 249 | |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 250 | case HWVER_220: |
| 251 | printf(" HW-Ver 2.20,"); |
| 252 | break; |
| 253 | |
| 254 | case HWVER_230: |
| 255 | printf(" HW-Ver 2.30,"); |
| 256 | break; |
| 257 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 258 | default: |
| 259 | printf(" HW-Ver %d(not supported),", |
| 260 | hardware_version); |
| 261 | break; |
| 262 | } |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 263 | if (rgmii2_present) |
| 264 | printf(" RGMII2,"); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 267 | if (unit_type == UNITTYPE_VIDEO_USER) { |
| 268 | hardware_version = versions & 0x000f; |
| 269 | switch (hardware_version) { |
| 270 | case FPGA_HWVER_200: |
| 271 | printf(" HW-Ver 2.00,"); |
| 272 | break; |
| 273 | |
| 274 | case FPGA_HWVER_210: |
| 275 | printf(" HW-Ver 2.10,"); |
| 276 | break; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 277 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 278 | default: |
| 279 | printf(" HW-Ver %d(not supported),", |
| 280 | hardware_version); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | printf(" FPGA V %d.%02d\n features:", |
| 286 | fpga_version / 100, fpga_version % 100); |
| 287 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 288 | |
| 289 | switch (feature_compression) { |
| 290 | case COMPRESSION_NONE: |
| 291 | printf(" no compression"); |
| 292 | break; |
| 293 | |
| 294 | case COMPRESSION_TYPE1_DELTA: |
| 295 | printf(" type1-deltacompression"); |
| 296 | break; |
| 297 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 298 | case COMPRESSION_TYPE1_TYPE2_DELTA: |
| 299 | printf(" type1-deltacompression, type2-inlinecompression"); |
| 300 | break; |
| 301 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 302 | default: |
| 303 | printf(" compression %d(not supported)", feature_compression); |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | printf(", %sosd", feature_osd ? "" : "no "); |
| 308 | |
| 309 | switch (feature_audio) { |
| 310 | case AUDIO_NONE: |
| 311 | printf(", no audio"); |
| 312 | break; |
| 313 | |
| 314 | case AUDIO_TX: |
| 315 | printf(", audio tx"); |
| 316 | break; |
| 317 | |
| 318 | case AUDIO_RX: |
| 319 | printf(", audio rx"); |
| 320 | break; |
| 321 | |
| 322 | case AUDIO_RXTX: |
| 323 | printf(", audio rx+tx"); |
| 324 | break; |
| 325 | |
| 326 | default: |
| 327 | printf(", audio %d(not supported)", feature_audio); |
| 328 | break; |
| 329 | } |
| 330 | |
| 331 | puts(",\n "); |
| 332 | |
| 333 | switch (feature_sysclock) { |
| 334 | case SYSCLK_147456: |
| 335 | printf("clock 147.456 MHz"); |
| 336 | break; |
| 337 | |
| 338 | default: |
| 339 | printf("clock %d(not supported)", feature_sysclock); |
| 340 | break; |
| 341 | } |
| 342 | |
| 343 | switch (feature_ramconfig) { |
| 344 | case RAM_DDR2_32: |
| 345 | printf(", RAM 32 bit DDR2"); |
| 346 | break; |
| 347 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 348 | case RAM_DDR3_32: |
| 349 | printf(", RAM 32 bit DDR3"); |
| 350 | break; |
| 351 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 352 | default: |
| 353 | printf(", RAM %d(not supported)", feature_ramconfig); |
| 354 | break; |
| 355 | } |
| 356 | |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 357 | printf(", %d carrier(s) %s", feature_carriers, |
| 358 | feature_carrier_speed ? "2.5Gbit/s" : "1Gbit/s"); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 359 | |
| 360 | printf(", %d video channel(s)\n", feature_video_channels); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | int last_stage_init(void) |
| 364 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 365 | int slaves; |
| 366 | unsigned int k; |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 367 | unsigned int mux_ch; |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 368 | unsigned char mclink_controllers[] = { 0x24, 0x25, 0x26 }; |
| 369 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 370 | u16 fpga_features; |
Dirk Eibach | eb7dc7f | 2014-11-13 19:21:17 +0100 | [diff] [blame] | 371 | int feature_carrier_speed; |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 372 | bool ch0_rgmii2_present = false; |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 373 | |
| 374 | FPGA_GET_REG(0, fpga_features, &fpga_features); |
Dirk Eibach | eb7dc7f | 2014-11-13 19:21:17 +0100 | [diff] [blame] | 375 | feature_carrier_speed = fpga_features & (1<<4); |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 376 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 377 | if (!legacy) { |
| 378 | /* Turn on Parade DP501 */ |
| 379 | pca9698_direction_output(0x20, 9, 1); |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 380 | |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 381 | ch0_rgmii2_present = !pca9698_get_value(0x20, 30); |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 382 | } |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 383 | |
Reinhard Pfau | 34cbc41 | 2015-10-28 11:46:30 +0100 | [diff] [blame] | 384 | /* wait for FPGA done; then reset FPGA */ |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 385 | for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) { |
| 386 | unsigned int ctr = 0; |
| 387 | |
| 388 | if (i2c_probe(mclink_controllers[k])) |
| 389 | continue; |
Dirk Eibach | 6b4b92f | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 390 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 391 | while (!(pca953x_get_val(mclink_controllers[k]) |
| 392 | & MCFPGA_DONE)) { |
| 393 | udelay(100000); |
| 394 | if (ctr++ > 5) { |
| 395 | printf("no done for mclink_controller %d\n", k); |
| 396 | break; |
| 397 | } |
| 398 | } |
Reinhard Pfau | 34cbc41 | 2015-10-28 11:46:30 +0100 | [diff] [blame] | 399 | |
| 400 | pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0); |
| 401 | pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0); |
| 402 | udelay(10); |
| 403 | pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, |
| 404 | MCFPGA_RESET_N); |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 407 | if (!legacy && (feature_carrier_speed == CARRIER_SPEED_1G)) { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 408 | miiphy_register(bb_miiphy_buses[0].name, bb_miiphy_read, |
| 409 | bb_miiphy_write); |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 410 | for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) { |
| 411 | if ((mux_ch == 1) && !ch0_rgmii2_present) |
| 412 | continue; |
| 413 | |
Dirk Eibach | 8ded7ee | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 414 | setup_88e1518(bb_miiphy_buses[0].name, mux_ch); |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
Dirk Eibach | d444d03 | 2014-07-03 09:28:24 +0200 | [diff] [blame] | 418 | /* give slave-PLLs and Parade DP501 some time to be up and running */ |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 419 | udelay(500000); |
| 420 | |
| 421 | mclink_fpgacount = CONFIG_SYS_MCLINK_MAX; |
| 422 | slaves = mclink_probe(); |
| 423 | mclink_fpgacount = 0; |
| 424 | |
Dirk Eibach | d444d03 | 2014-07-03 09:28:24 +0200 | [diff] [blame] | 425 | print_fpga_info(0, ch0_rgmii2_present); |
| 426 | osd_probe(0); |
| 427 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 428 | if (slaves <= 0) |
| 429 | return 0; |
| 430 | |
| 431 | mclink_fpgacount = slaves; |
| 432 | |
| 433 | for (k = 1; k <= slaves; ++k) { |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 434 | FPGA_GET_REG(k, fpga_features, &fpga_features); |
| 435 | feature_carrier_speed = fpga_features & (1<<4); |
| 436 | |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 437 | print_fpga_info(k, false); |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 438 | osd_probe(k); |
Dirk Eibach | aea8084 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 439 | if (feature_carrier_speed == CARRIER_SPEED_1G) { |
| 440 | miiphy_register(bb_miiphy_buses[k].name, |
| 441 | bb_miiphy_read, bb_miiphy_write); |
Dirk Eibach | 8ded7ee | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 442 | setup_88e1518(bb_miiphy_buses[k].name, 0); |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | return 0; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* |
| 450 | * provide access to fpga gpios (for I2C bitbang) |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 451 | * (these may look all too simple but make iocon.h much more readable) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 452 | */ |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 453 | void fpga_gpio_set(unsigned int bus, int pin) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 454 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 455 | FPGA_SET_REG(bus, gpio.set, pin); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 458 | void fpga_gpio_clear(unsigned int bus, int pin) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 459 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 460 | FPGA_SET_REG(bus, gpio.clear, pin); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 463 | int fpga_gpio_get(unsigned int bus, int pin) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 464 | { |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 465 | u16 val; |
| 466 | |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 467 | FPGA_GET_REG(bus, gpio.read, &val); |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 468 | |
| 469 | return val & pin; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 470 | } |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 471 | |
| 472 | void gd405ep_init(void) |
| 473 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 474 | unsigned int k; |
| 475 | |
| 476 | if (i2c_probe(0x20)) { /* i2c_probe returns 0 on success */ |
| 477 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
| 478 | gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM; |
| 479 | } else { |
| 480 | pca9698_direction_output(0x20, 4, 1); |
| 481 | } |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void gd405ep_set_fpga_reset(unsigned state) |
| 485 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 486 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
| 487 | |
| 488 | if (legacy) { |
| 489 | if (state) { |
| 490 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET); |
| 491 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET); |
| 492 | } else { |
| 493 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT); |
| 494 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT); |
| 495 | } |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 496 | } else { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 497 | pca9698_set_value(0x20, 4, state ? 0 : 1); |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | void gd405ep_setup_hw(void) |
| 502 | { |
| 503 | /* |
| 504 | * set "startup-finished"-gpios |
| 505 | */ |
| 506 | gpio_write_bit(21, 0); |
| 507 | gpio_write_bit(22, 1); |
| 508 | } |
| 509 | |
| 510 | int gd405ep_get_fpga_done(unsigned fpga) |
| 511 | { |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 512 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
| 513 | |
| 514 | if (legacy) |
| 515 | return in_le16((void *)LATCH2_BASE) |
| 516 | & CONFIG_SYS_FPGA_DONE(fpga); |
| 517 | else |
| 518 | return pca9698_get_value(0x20, 20); |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * FPGA MII bitbang implementation |
| 523 | */ |
| 524 | |
| 525 | struct fpga_mii { |
| 526 | unsigned fpga; |
| 527 | int mdio; |
| 528 | } fpga_mii[] = { |
| 529 | { 0, 1}, |
| 530 | { 1, 1}, |
| 531 | { 2, 1}, |
| 532 | { 3, 1}, |
| 533 | }; |
| 534 | |
| 535 | static int mii_dummy_init(struct bb_miiphy_bus *bus) |
| 536 | { |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int mii_mdio_active(struct bb_miiphy_bus *bus) |
| 541 | { |
| 542 | struct fpga_mii *fpga_mii = bus->priv; |
| 543 | |
| 544 | if (fpga_mii->mdio) |
| 545 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 546 | else |
| 547 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | static int mii_mdio_tristate(struct bb_miiphy_bus *bus) |
| 553 | { |
| 554 | struct fpga_mii *fpga_mii = bus->priv; |
| 555 | |
| 556 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int mii_set_mdio(struct bb_miiphy_bus *bus, int v) |
| 562 | { |
| 563 | struct fpga_mii *fpga_mii = bus->priv; |
| 564 | |
| 565 | if (v) |
| 566 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 567 | else |
| 568 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 569 | |
| 570 | fpga_mii->mdio = v; |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v) |
| 576 | { |
| 577 | u16 gpio; |
| 578 | struct fpga_mii *fpga_mii = bus->priv; |
| 579 | |
| 580 | FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio); |
| 581 | |
| 582 | *v = ((gpio & GPIO_MDIO) != 0); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int mii_set_mdc(struct bb_miiphy_bus *bus, int v) |
| 588 | { |
| 589 | struct fpga_mii *fpga_mii = bus->priv; |
| 590 | |
| 591 | if (v) |
| 592 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC); |
| 593 | else |
| 594 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC); |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static int mii_delay(struct bb_miiphy_bus *bus) |
| 600 | { |
| 601 | udelay(1); |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | struct bb_miiphy_bus bb_miiphy_buses[] = { |
| 607 | { |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 608 | .name = "board0", |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 609 | .init = mii_dummy_init, |
| 610 | .mdio_active = mii_mdio_active, |
| 611 | .mdio_tristate = mii_mdio_tristate, |
| 612 | .set_mdio = mii_set_mdio, |
| 613 | .get_mdio = mii_get_mdio, |
| 614 | .set_mdc = mii_set_mdc, |
| 615 | .delay = mii_delay, |
| 616 | .priv = &fpga_mii[0], |
| 617 | }, |
| 618 | { |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 619 | .name = "board1", |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 620 | .init = mii_dummy_init, |
| 621 | .mdio_active = mii_mdio_active, |
| 622 | .mdio_tristate = mii_mdio_tristate, |
| 623 | .set_mdio = mii_set_mdio, |
| 624 | .get_mdio = mii_get_mdio, |
| 625 | .set_mdc = mii_set_mdc, |
| 626 | .delay = mii_delay, |
| 627 | .priv = &fpga_mii[1], |
| 628 | }, |
| 629 | { |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 630 | .name = "board2", |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 631 | .init = mii_dummy_init, |
| 632 | .mdio_active = mii_mdio_active, |
| 633 | .mdio_tristate = mii_mdio_tristate, |
| 634 | .set_mdio = mii_set_mdio, |
| 635 | .get_mdio = mii_get_mdio, |
| 636 | .set_mdc = mii_set_mdc, |
| 637 | .delay = mii_delay, |
| 638 | .priv = &fpga_mii[2], |
| 639 | }, |
| 640 | { |
Dirk Eibach | 373017b | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 641 | .name = "board3", |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 642 | .init = mii_dummy_init, |
| 643 | .mdio_active = mii_mdio_active, |
| 644 | .mdio_tristate = mii_mdio_tristate, |
| 645 | .set_mdio = mii_set_mdio, |
| 646 | .get_mdio = mii_get_mdio, |
| 647 | .set_mdc = mii_set_mdc, |
| 648 | .delay = mii_delay, |
| 649 | .priv = &fpga_mii[3], |
| 650 | }, |
| 651 | }; |
| 652 | |
| 653 | int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / |
| 654 | sizeof(bb_miiphy_buses[0]); |