Dirk Eibach | a605ea7 | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 10 | #include <errno.h> |
Dirk Eibach | a605ea7 | 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 | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 15 | #include "405ep.h" |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 16 | #include <gdsys_fpga.h> |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 17 | |
Dirk Eibach | edfe9fe | 2014-07-03 09:28:17 +0200 | [diff] [blame^] | 18 | #include "../common/dp501.h" |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 19 | #include "../common/osd.h" |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 20 | #include "../common/mclink.h" |
| 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 | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 29 | |
Dirk Eibach | 6e9e6c3 | 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 | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 34 | #define MAX_MUX_CHANNELS 2 |
| 35 | |
Dirk Eibach | a605ea7 | 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 | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 47 | HWVER_120 = 3, |
| 48 | HWVER_200 = 4, |
| 49 | HWVER_210 = 5, |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 50 | HWVER_220 = 6, |
| 51 | HWVER_230 = 7, |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | enum { |
| 55 | FPGA_HWVER_200 = 0, |
| 56 | FPGA_HWVER_210 = 1, |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | enum { |
| 60 | COMPRESSION_NONE = 0, |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 61 | COMPRESSION_TYPE1_DELTA = 1, |
| 62 | COMPRESSION_TYPE1_TYPE2_DELTA = 3, |
Dirk Eibach | a605ea7 | 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 | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 78 | RAM_DDR3_32 = 1, |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 81 | enum { |
Dirk Eibach | a808970 | 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 | e50e896 | 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, |
| 92 | }; |
| 93 | |
| 94 | enum { |
| 95 | GPIO_MDC = 1 << 14, |
| 96 | GPIO_MDIO = 1 << 15, |
| 97 | }; |
| 98 | |
| 99 | unsigned int mclink_fpgacount; |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 100 | struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR; |
| 101 | |
Dirk Eibach | edfe9fe | 2014-07-03 09:28:17 +0200 | [diff] [blame^] | 102 | int dp501_i2c[] = CONFIG_SYS_DP501_I2C; |
| 103 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 104 | static int setup_88e1518(const char *bus, unsigned char addr); |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 105 | |
| 106 | int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data) |
| 107 | { |
| 108 | int res; |
| 109 | |
| 110 | switch (fpga) { |
| 111 | case 0: |
| 112 | out_le16(reg, data); |
| 113 | break; |
| 114 | default: |
| 115 | res = mclink_send(fpga - 1, regoff, data); |
| 116 | if (res < 0) { |
| 117 | printf("mclink_send reg %02lx data %04x returned %d\n", |
| 118 | regoff, data, res); |
| 119 | return res; |
| 120 | } |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data) |
| 128 | { |
| 129 | int res; |
| 130 | |
| 131 | switch (fpga) { |
| 132 | case 0: |
| 133 | *data = in_le16(reg); |
| 134 | break; |
| 135 | default: |
| 136 | if (fpga > mclink_fpgacount) |
| 137 | return -EINVAL; |
| 138 | res = mclink_receive(fpga - 1, regoff, data); |
| 139 | if (res < 0) { |
| 140 | printf("mclink_receive reg %02lx returned %d\n", |
| 141 | regoff, res); |
| 142 | return res; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 149 | /* |
| 150 | * Check Board Identity: |
| 151 | */ |
| 152 | int checkboard(void) |
| 153 | { |
Dirk Eibach | b19bf83 | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 154 | char *s = getenv("serial#"); |
| 155 | |
| 156 | puts("Board: "); |
| 157 | |
| 158 | puts("IoCon"); |
| 159 | |
| 160 | if (s != NULL) { |
| 161 | puts(", serial# "); |
| 162 | puts(s); |
| 163 | } |
| 164 | |
| 165 | puts("\n"); |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 170 | static void print_fpga_info(unsigned int fpga, bool rgmii2_present) |
Dirk Eibach | b19bf83 | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 171 | { |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 172 | u16 versions; |
| 173 | u16 fpga_version; |
| 174 | u16 fpga_features; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 175 | unsigned unit_type; |
| 176 | unsigned hardware_version; |
| 177 | unsigned feature_compression; |
| 178 | unsigned feature_osd; |
| 179 | unsigned feature_audio; |
| 180 | unsigned feature_sysclock; |
| 181 | unsigned feature_ramconfig; |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 182 | unsigned feature_carrier_speed; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 183 | unsigned feature_carriers; |
| 184 | unsigned feature_video_channels; |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 185 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 186 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 187 | |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 188 | FPGA_GET_REG(0, versions, &versions); |
| 189 | FPGA_GET_REG(0, fpga_version, &fpga_version); |
| 190 | FPGA_GET_REG(0, fpga_features, &fpga_features); |
| 191 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 192 | unit_type = (versions & 0xf000) >> 12; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 193 | feature_compression = (fpga_features & 0xe000) >> 13; |
| 194 | feature_osd = fpga_features & (1<<11); |
| 195 | feature_audio = (fpga_features & 0x0600) >> 9; |
| 196 | feature_sysclock = (fpga_features & 0x0180) >> 7; |
| 197 | feature_ramconfig = (fpga_features & 0x0060) >> 5; |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 198 | feature_carrier_speed = fpga_features & (1<<4); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 199 | feature_carriers = (fpga_features & 0x000c) >> 2; |
| 200 | feature_video_channels = fpga_features & 0x0003; |
| 201 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 202 | if (legacy) |
| 203 | printf("legacy "); |
| 204 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 205 | switch (unit_type) { |
| 206 | case UNITTYPE_MAIN_USER: |
| 207 | printf("Mainchannel"); |
| 208 | break; |
| 209 | |
| 210 | case UNITTYPE_VIDEO_USER: |
| 211 | printf("Videochannel"); |
| 212 | break; |
| 213 | |
| 214 | default: |
| 215 | printf("UnitType %d(not supported)", unit_type); |
| 216 | break; |
| 217 | } |
| 218 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 219 | if (unit_type == UNITTYPE_MAIN_USER) { |
| 220 | if (legacy) |
| 221 | hardware_version = |
| 222 | (in_le16((void *)LATCH2_BASE)>>8) & 0x0f; |
| 223 | else |
| 224 | hardware_version = |
| 225 | (!!pca9698_get_value(0x20, 24) << 0) |
| 226 | | (!!pca9698_get_value(0x20, 25) << 1) |
| 227 | | (!!pca9698_get_value(0x20, 26) << 2) |
| 228 | | (!!pca9698_get_value(0x20, 27) << 3); |
| 229 | switch (hardware_version) { |
| 230 | case HWVER_100: |
| 231 | printf(" HW-Ver 1.00,"); |
| 232 | break; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 233 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 234 | case HWVER_104: |
| 235 | printf(" HW-Ver 1.04,"); |
| 236 | break; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 237 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 238 | case HWVER_110: |
| 239 | printf(" HW-Ver 1.10,"); |
| 240 | break; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 241 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 242 | case HWVER_120: |
| 243 | printf(" HW-Ver 1.20-1.21,"); |
| 244 | break; |
| 245 | |
| 246 | case HWVER_200: |
| 247 | printf(" HW-Ver 2.00,"); |
| 248 | break; |
| 249 | |
| 250 | case HWVER_210: |
| 251 | printf(" HW-Ver 2.10,"); |
| 252 | break; |
| 253 | |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 254 | case HWVER_220: |
| 255 | printf(" HW-Ver 2.20,"); |
| 256 | break; |
| 257 | |
| 258 | case HWVER_230: |
| 259 | printf(" HW-Ver 2.30,"); |
| 260 | break; |
| 261 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 262 | default: |
| 263 | printf(" HW-Ver %d(not supported),", |
| 264 | hardware_version); |
| 265 | break; |
| 266 | } |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 267 | if (rgmii2_present) |
| 268 | printf(" RGMII2,"); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 271 | if (unit_type == UNITTYPE_VIDEO_USER) { |
| 272 | hardware_version = versions & 0x000f; |
| 273 | switch (hardware_version) { |
| 274 | case FPGA_HWVER_200: |
| 275 | printf(" HW-Ver 2.00,"); |
| 276 | break; |
| 277 | |
| 278 | case FPGA_HWVER_210: |
| 279 | printf(" HW-Ver 2.10,"); |
| 280 | break; |
| 281 | |
| 282 | default: |
| 283 | printf(" HW-Ver %d(not supported),", |
| 284 | hardware_version); |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | printf(" FPGA V %d.%02d\n features:", |
| 290 | fpga_version / 100, fpga_version % 100); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 291 | |
| 292 | |
| 293 | switch (feature_compression) { |
| 294 | case COMPRESSION_NONE: |
| 295 | printf(" no compression"); |
| 296 | break; |
| 297 | |
| 298 | case COMPRESSION_TYPE1_DELTA: |
| 299 | printf(" type1-deltacompression"); |
| 300 | break; |
| 301 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 302 | case COMPRESSION_TYPE1_TYPE2_DELTA: |
| 303 | printf(" type1-deltacompression, type2-inlinecompression"); |
| 304 | break; |
| 305 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 306 | default: |
| 307 | printf(" compression %d(not supported)", feature_compression); |
| 308 | break; |
| 309 | } |
| 310 | |
| 311 | printf(", %sosd", feature_osd ? "" : "no "); |
| 312 | |
| 313 | switch (feature_audio) { |
| 314 | case AUDIO_NONE: |
| 315 | printf(", no audio"); |
| 316 | break; |
| 317 | |
| 318 | case AUDIO_TX: |
| 319 | printf(", audio tx"); |
| 320 | break; |
| 321 | |
| 322 | case AUDIO_RX: |
| 323 | printf(", audio rx"); |
| 324 | break; |
| 325 | |
| 326 | case AUDIO_RXTX: |
| 327 | printf(", audio rx+tx"); |
| 328 | break; |
| 329 | |
| 330 | default: |
| 331 | printf(", audio %d(not supported)", feature_audio); |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | puts(",\n "); |
| 336 | |
| 337 | switch (feature_sysclock) { |
| 338 | case SYSCLK_147456: |
| 339 | printf("clock 147.456 MHz"); |
| 340 | break; |
| 341 | |
| 342 | default: |
| 343 | printf("clock %d(not supported)", feature_sysclock); |
| 344 | break; |
| 345 | } |
| 346 | |
| 347 | switch (feature_ramconfig) { |
| 348 | case RAM_DDR2_32: |
| 349 | printf(", RAM 32 bit DDR2"); |
| 350 | break; |
| 351 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 352 | case RAM_DDR3_32: |
| 353 | printf(", RAM 32 bit DDR3"); |
| 354 | break; |
| 355 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 356 | default: |
| 357 | printf(", RAM %d(not supported)", feature_ramconfig); |
| 358 | break; |
| 359 | } |
| 360 | |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 361 | printf(", %d carrier(s) %s", feature_carriers, |
| 362 | feature_carrier_speed ? "2.5Gbit/s" : "1Gbit/s"); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 363 | |
| 364 | printf(", %d video channel(s)\n", feature_video_channels); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | int last_stage_init(void) |
| 368 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 369 | int slaves; |
| 370 | unsigned int k; |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 371 | unsigned int mux_ch; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 372 | unsigned char mclink_controllers[] = { 0x24, 0x25, 0x26 }; |
| 373 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 374 | u16 fpga_features; |
| 375 | int feature_carrier_speed = fpga_features & (1<<4); |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 376 | bool ch0_rgmii2_present = false; |
Dirk Eibach | edfe9fe | 2014-07-03 09:28:17 +0200 | [diff] [blame^] | 377 | int old_bus = i2c_get_bus_num(); |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 378 | |
| 379 | FPGA_GET_REG(0, fpga_features, &fpga_features); |
Dirk Eibach | b19bf83 | 2012-04-26 03:54:23 +0000 | [diff] [blame] | 380 | |
Dirk Eibach | edfe9fe | 2014-07-03 09:28:17 +0200 | [diff] [blame^] | 381 | /* Turn on Parade DP501 */ |
| 382 | pca9698_direction_output(0x20, 9, 1); |
| 383 | udelay(500000); |
| 384 | |
| 385 | i2c_set_bus_num(dp501_i2c[0]); |
| 386 | dp501_powerup(0x08); |
| 387 | i2c_set_bus_num(old_bus); |
| 388 | |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 389 | if (!legacy) |
| 390 | ch0_rgmii2_present = !pca9698_get_value(0x20, 30); |
| 391 | |
| 392 | print_fpga_info(0, ch0_rgmii2_present); |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 393 | osd_probe(0); |
| 394 | |
| 395 | /* wait for FPGA done */ |
| 396 | for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) { |
| 397 | unsigned int ctr = 0; |
| 398 | |
| 399 | if (i2c_probe(mclink_controllers[k])) |
| 400 | continue; |
| 401 | |
| 402 | while (!(pca953x_get_val(mclink_controllers[k]) |
| 403 | & MCFPGA_DONE)) { |
| 404 | udelay(100000); |
| 405 | if (ctr++ > 5) { |
| 406 | printf("no done for mclink_controller %d\n", k); |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 412 | if (!legacy && (feature_carrier_speed == CARRIER_SPEED_1G)) { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 413 | miiphy_register(bb_miiphy_buses[0].name, bb_miiphy_read, |
| 414 | bb_miiphy_write); |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 415 | for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) { |
| 416 | if ((mux_ch == 1) && !ch0_rgmii2_present) |
| 417 | continue; |
| 418 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 419 | setup_88e1518(bb_miiphy_buses[0].name, mux_ch); |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | /* wait for slave-PLLs to be up and running */ |
| 424 | udelay(500000); |
| 425 | |
| 426 | mclink_fpgacount = CONFIG_SYS_MCLINK_MAX; |
| 427 | slaves = mclink_probe(); |
| 428 | mclink_fpgacount = 0; |
| 429 | |
| 430 | if (slaves <= 0) |
| 431 | return 0; |
| 432 | |
| 433 | mclink_fpgacount = slaves; |
| 434 | |
| 435 | for (k = 1; k <= slaves; ++k) { |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 436 | FPGA_GET_REG(k, fpga_features, &fpga_features); |
| 437 | feature_carrier_speed = fpga_features & (1<<4); |
| 438 | |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 439 | print_fpga_info(k, false); |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 440 | osd_probe(k); |
Dirk Eibach | a808970 | 2013-08-09 10:52:51 +0200 | [diff] [blame] | 441 | if (feature_carrier_speed == CARRIER_SPEED_1G) { |
| 442 | miiphy_register(bb_miiphy_buses[k].name, |
| 443 | bb_miiphy_read, bb_miiphy_write); |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 444 | setup_88e1518(bb_miiphy_buses[k].name, 0); |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
| 448 | return 0; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* |
| 452 | * provide access to fpga gpios (for I2C bitbang) |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 453 | * (these may look all too simple but make iocon.h much more readable) |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 454 | */ |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 455 | void fpga_gpio_set(unsigned int bus, int pin) |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 456 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 457 | FPGA_SET_REG(bus, gpio.set, pin); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 460 | void fpga_gpio_clear(unsigned int bus, int pin) |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 461 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 462 | FPGA_SET_REG(bus, gpio.clear, pin); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 465 | int fpga_gpio_get(unsigned int bus, int pin) |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 466 | { |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 467 | u16 val; |
| 468 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 469 | FPGA_GET_REG(bus, gpio.read, &val); |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 470 | |
| 471 | return val & pin; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 472 | } |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 473 | |
| 474 | void gd405ep_init(void) |
| 475 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 476 | unsigned int k; |
| 477 | |
| 478 | if (i2c_probe(0x20)) { /* i2c_probe returns 0 on success */ |
| 479 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
| 480 | gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM; |
| 481 | } else { |
| 482 | pca9698_direction_output(0x20, 4, 1); |
| 483 | } |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void gd405ep_set_fpga_reset(unsigned state) |
| 487 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 488 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
| 489 | |
| 490 | if (legacy) { |
| 491 | if (state) { |
| 492 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET); |
| 493 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET); |
| 494 | } else { |
| 495 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT); |
| 496 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT); |
| 497 | } |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 498 | } else { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 499 | pca9698_set_value(0x20, 4, state ? 0 : 1); |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | void gd405ep_setup_hw(void) |
| 504 | { |
| 505 | /* |
| 506 | * set "startup-finished"-gpios |
| 507 | */ |
| 508 | gpio_write_bit(21, 0); |
| 509 | gpio_write_bit(22, 1); |
| 510 | } |
| 511 | |
| 512 | int gd405ep_get_fpga_done(unsigned fpga) |
| 513 | { |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 514 | int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM; |
| 515 | |
| 516 | if (legacy) |
| 517 | return in_le16((void *)LATCH2_BASE) |
| 518 | & CONFIG_SYS_FPGA_DONE(fpga); |
| 519 | else |
| 520 | return pca9698_get_value(0x20, 20); |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * FPGA MII bitbang implementation |
| 525 | */ |
| 526 | |
| 527 | struct fpga_mii { |
| 528 | unsigned fpga; |
| 529 | int mdio; |
| 530 | } fpga_mii[] = { |
| 531 | { 0, 1}, |
| 532 | { 1, 1}, |
| 533 | { 2, 1}, |
| 534 | { 3, 1}, |
| 535 | }; |
| 536 | |
| 537 | static int mii_dummy_init(struct bb_miiphy_bus *bus) |
| 538 | { |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int mii_mdio_active(struct bb_miiphy_bus *bus) |
| 543 | { |
| 544 | struct fpga_mii *fpga_mii = bus->priv; |
| 545 | |
| 546 | if (fpga_mii->mdio) |
| 547 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 548 | else |
| 549 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static int mii_mdio_tristate(struct bb_miiphy_bus *bus) |
| 555 | { |
| 556 | struct fpga_mii *fpga_mii = bus->priv; |
| 557 | |
| 558 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static int mii_set_mdio(struct bb_miiphy_bus *bus, int v) |
| 564 | { |
| 565 | struct fpga_mii *fpga_mii = bus->priv; |
| 566 | |
| 567 | if (v) |
| 568 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 569 | else |
| 570 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 571 | |
| 572 | fpga_mii->mdio = v; |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v) |
| 578 | { |
| 579 | u16 gpio; |
| 580 | struct fpga_mii *fpga_mii = bus->priv; |
| 581 | |
| 582 | FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio); |
| 583 | |
| 584 | *v = ((gpio & GPIO_MDIO) != 0); |
| 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int mii_set_mdc(struct bb_miiphy_bus *bus, int v) |
| 590 | { |
| 591 | struct fpga_mii *fpga_mii = bus->priv; |
| 592 | |
| 593 | if (v) |
| 594 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC); |
| 595 | else |
| 596 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static int mii_delay(struct bb_miiphy_bus *bus) |
| 602 | { |
| 603 | udelay(1); |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | struct bb_miiphy_bus bb_miiphy_buses[] = { |
| 609 | { |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 610 | .name = "board0", |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 611 | .init = mii_dummy_init, |
| 612 | .mdio_active = mii_mdio_active, |
| 613 | .mdio_tristate = mii_mdio_tristate, |
| 614 | .set_mdio = mii_set_mdio, |
| 615 | .get_mdio = mii_get_mdio, |
| 616 | .set_mdc = mii_set_mdc, |
| 617 | .delay = mii_delay, |
| 618 | .priv = &fpga_mii[0], |
| 619 | }, |
| 620 | { |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 621 | .name = "board1", |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 622 | .init = mii_dummy_init, |
| 623 | .mdio_active = mii_mdio_active, |
| 624 | .mdio_tristate = mii_mdio_tristate, |
| 625 | .set_mdio = mii_set_mdio, |
| 626 | .get_mdio = mii_get_mdio, |
| 627 | .set_mdc = mii_set_mdc, |
| 628 | .delay = mii_delay, |
| 629 | .priv = &fpga_mii[1], |
| 630 | }, |
| 631 | { |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 632 | .name = "board2", |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 633 | .init = mii_dummy_init, |
| 634 | .mdio_active = mii_mdio_active, |
| 635 | .mdio_tristate = mii_mdio_tristate, |
| 636 | .set_mdio = mii_set_mdio, |
| 637 | .get_mdio = mii_get_mdio, |
| 638 | .set_mdc = mii_set_mdc, |
| 639 | .delay = mii_delay, |
| 640 | .priv = &fpga_mii[2], |
| 641 | }, |
| 642 | { |
Dirk Eibach | d78951d | 2013-08-09 10:52:52 +0200 | [diff] [blame] | 643 | .name = "board3", |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 644 | .init = mii_dummy_init, |
| 645 | .mdio_active = mii_mdio_active, |
| 646 | .mdio_tristate = mii_mdio_tristate, |
| 647 | .set_mdio = mii_set_mdio, |
| 648 | .get_mdio = mii_get_mdio, |
| 649 | .set_mdc = mii_set_mdc, |
| 650 | .delay = mii_delay, |
| 651 | .priv = &fpga_mii[3], |
| 652 | }, |
| 653 | }; |
| 654 | |
| 655 | int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / |
| 656 | sizeof(bb_miiphy_buses[0]); |
| 657 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 658 | enum { |
| 659 | MIICMD_SET, |
| 660 | MIICMD_MODIFY, |
| 661 | MIICMD_VERIFY_VALUE, |
| 662 | MIICMD_WAIT_FOR_VALUE, |
| 663 | }; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 664 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 665 | struct mii_setupcmd { |
| 666 | u8 token; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 667 | u8 reg; |
| 668 | u16 data; |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 669 | u16 mask; |
| 670 | u32 timeout; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 671 | }; |
| 672 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 673 | /* |
| 674 | * verify we are talking to a 88e1518 |
| 675 | */ |
| 676 | struct mii_setupcmd verify_88e1518[] = { |
| 677 | { MIICMD_SET, 22, 0x0000 }, |
| 678 | { MIICMD_VERIFY_VALUE, 2, 0x0141, 0xffff }, |
| 679 | { MIICMD_VERIFY_VALUE, 3, 0x0dd0, 0xfff0 }, |
| 680 | }; |
| 681 | |
| 682 | /* |
| 683 | * workaround for erratum mentioned in 88E1518 release notes |
| 684 | */ |
| 685 | struct mii_setupcmd fixup_88e1518[] = { |
| 686 | { MIICMD_SET, 22, 0x00ff }, |
| 687 | { MIICMD_SET, 17, 0x214b }, |
| 688 | { MIICMD_SET, 16, 0x2144 }, |
| 689 | { MIICMD_SET, 17, 0x0c28 }, |
| 690 | { MIICMD_SET, 16, 0x2146 }, |
| 691 | { MIICMD_SET, 17, 0xb233 }, |
| 692 | { MIICMD_SET, 16, 0x214d }, |
| 693 | { MIICMD_SET, 17, 0xcc0c }, |
| 694 | { MIICMD_SET, 16, 0x2159 }, |
| 695 | { MIICMD_SET, 22, 0x00fb }, |
| 696 | { MIICMD_SET, 7, 0xc00d }, |
| 697 | { MIICMD_SET, 22, 0x0000 }, |
| 698 | }; |
| 699 | |
| 700 | /* |
| 701 | * default initialization: |
| 702 | * - set RGMII receive timing to "receive clock transition when data stable" |
| 703 | * - set RGMII transmit timing to "transmit clock internally delayed" |
| 704 | * - set RGMII output impedance target to 78,8 Ohm |
| 705 | * - run output impedance calibration |
| 706 | * - set autonegotiation advertise to 1000FD only |
| 707 | */ |
| 708 | struct mii_setupcmd default_88e1518[] = { |
| 709 | { MIICMD_SET, 22, 0x0002 }, |
| 710 | { MIICMD_MODIFY, 21, 0x0030, 0x0030 }, |
| 711 | { MIICMD_MODIFY, 25, 0x0000, 0x0003 }, |
| 712 | { MIICMD_MODIFY, 24, 0x8000, 0x8000 }, |
| 713 | { MIICMD_WAIT_FOR_VALUE, 24, 0x4000, 0x4000, 2000 }, |
| 714 | { MIICMD_SET, 22, 0x0000 }, |
| 715 | { MIICMD_MODIFY, 4, 0x0000, 0x01e0 }, |
| 716 | { MIICMD_MODIFY, 9, 0x0200, 0x0300 }, |
| 717 | }; |
| 718 | |
| 719 | /* |
| 720 | * turn off CLK125 for PHY daughterboard |
| 721 | */ |
| 722 | struct mii_setupcmd ch1fix_88e1518[] = { |
| 723 | { MIICMD_SET, 22, 0x0002 }, |
| 724 | { MIICMD_MODIFY, 16, 0x0006, 0x0006 }, |
| 725 | { MIICMD_SET, 22, 0x0000 }, |
| 726 | }; |
| 727 | |
| 728 | /* |
| 729 | * perform copper software reset |
| 730 | */ |
| 731 | struct mii_setupcmd swreset_88e1518[] = { |
| 732 | { MIICMD_SET, 22, 0x0000 }, |
| 733 | { MIICMD_MODIFY, 0, 0x8000, 0x8000 }, |
| 734 | { MIICMD_WAIT_FOR_VALUE, 0, 0x0000, 0x8000, 2000 }, |
| 735 | }; |
| 736 | |
| 737 | static int process_setupcmd(const char *bus, unsigned char addr, |
| 738 | struct mii_setupcmd *setupcmd) |
| 739 | { |
| 740 | int res; |
| 741 | u8 reg = setupcmd->reg; |
| 742 | u16 data = setupcmd->data; |
| 743 | u16 mask = setupcmd->mask; |
| 744 | u32 timeout = setupcmd->timeout; |
| 745 | u16 orig_data; |
| 746 | unsigned long start; |
| 747 | |
| 748 | debug("mii %s:%u reg %2u ", bus, addr, reg); |
| 749 | |
| 750 | switch (setupcmd->token) { |
| 751 | case MIICMD_MODIFY: |
| 752 | res = miiphy_read(bus, addr, reg, &orig_data); |
| 753 | if (res) |
| 754 | break; |
| 755 | debug("is %04x. (value %04x mask %04x) ", orig_data, data, |
| 756 | mask); |
| 757 | data = (orig_data & ~mask) | (data & mask); |
| 758 | case MIICMD_SET: |
| 759 | debug("=> %04x\n", data); |
| 760 | res = miiphy_write(bus, addr, reg, data); |
| 761 | break; |
| 762 | case MIICMD_VERIFY_VALUE: |
| 763 | res = miiphy_read(bus, addr, reg, &orig_data); |
| 764 | if (res) |
| 765 | break; |
| 766 | if ((orig_data & mask) != (data & mask)) |
| 767 | res = -1; |
| 768 | debug("(value %04x mask %04x) == %04x? %s\n", data, mask, |
| 769 | orig_data, res ? "FAIL" : "PASS"); |
| 770 | break; |
| 771 | case MIICMD_WAIT_FOR_VALUE: |
| 772 | res = -1; |
| 773 | start = get_timer(0); |
| 774 | while ((res != 0) && (get_timer(start) < timeout)) { |
| 775 | res = miiphy_read(bus, addr, reg, &orig_data); |
| 776 | if (res) |
| 777 | continue; |
| 778 | if ((orig_data & mask) != (data & mask)) |
| 779 | res = -1; |
| 780 | } |
| 781 | debug("(value %04x mask %04x) == %04x? %s after %lu ms\n", data, |
| 782 | mask, orig_data, res ? "FAIL" : "PASS", |
| 783 | get_timer(start)); |
| 784 | break; |
| 785 | default: |
| 786 | res = -1; |
| 787 | break; |
| 788 | } |
| 789 | |
| 790 | return res; |
| 791 | } |
| 792 | |
| 793 | static int process_setup(const char *bus, unsigned char addr, |
| 794 | struct mii_setupcmd *setupcmd, unsigned int count) |
| 795 | { |
| 796 | int res = 0; |
| 797 | unsigned int k; |
| 798 | |
| 799 | for (k = 0; k < count; ++k) { |
| 800 | res = process_setupcmd(bus, addr, &setupcmd[k]); |
| 801 | if (res) { |
| 802 | printf("mii cmd %u on bus %s addr %u failed, aborting setup", |
| 803 | setupcmd[k].token, bus, addr); |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return res; |
| 809 | } |
| 810 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 811 | static int setup_88e1518(const char *bus, unsigned char addr) |
| 812 | { |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 813 | int res; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 814 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 815 | res = process_setup(bus, addr, |
| 816 | verify_88e1518, ARRAY_SIZE(verify_88e1518)); |
| 817 | if (res) |
| 818 | return res; |
| 819 | |
| 820 | res = process_setup(bus, addr, |
| 821 | fixup_88e1518, ARRAY_SIZE(fixup_88e1518)); |
| 822 | if (res) |
| 823 | return res; |
| 824 | |
| 825 | res = process_setup(bus, addr, |
| 826 | default_88e1518, ARRAY_SIZE(default_88e1518)); |
| 827 | if (res) |
| 828 | return res; |
| 829 | |
| 830 | if (addr) { |
| 831 | res = process_setup(bus, addr, |
| 832 | ch1fix_88e1518, ARRAY_SIZE(ch1fix_88e1518)); |
| 833 | if (res) |
| 834 | return res; |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 835 | } |
| 836 | |
Dirk Eibach | f24c8e8 | 2013-08-09 10:52:53 +0200 | [diff] [blame] | 837 | res = process_setup(bus, addr, |
| 838 | swreset_88e1518, ARRAY_SIZE(swreset_88e1518)); |
| 839 | if (res) |
| 840 | return res; |
| 841 | |
Dirk Eibach | e50e896 | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 842 | return 0; |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 843 | } |