blob: 664b1e164e4ab6e73c6ac00c6a9c601575193737 [file] [log] [blame]
Dirk Eibacha605ea72010-10-21 10:50:05 +02001/*
2 * (C) Copyright 2010
3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibacha605ea72010-10-21 10:50:05 +02006 */
7
8#include <common.h>
9#include <command.h>
Dirk Eibache50e8962013-07-25 19:28:13 +020010#include <errno.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020011#include <asm/processor.h>
12#include <asm/io.h>
13#include <asm/ppc4xx-gpio.h>
14
Dirk Eibach6e9e6c32012-04-26 03:54:22 +000015#include "405ep.h"
Dirk Eibach2da0fc02011-01-21 09:31:21 +010016#include <gdsys_fpga.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020017
Dirk Eibach2da0fc02011-01-21 09:31:21 +010018#include "../common/osd.h"
Dirk Eibache50e8962013-07-25 19:28:13 +020019#include "../common/mclink.h"
20
21#include <i2c.h>
22#include <pca953x.h>
23#include <pca9698.h>
24
25#include <miiphy.h>
26
27DECLARE_GLOBAL_DATA_PTR;
Dirk Eibacha605ea72010-10-21 10:50:05 +020028
Dirk Eibach6e9e6c32012-04-26 03:54:22 +000029#define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
30#define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
31#define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
32
Dirk Eibachd78951d2013-08-09 10:52:52 +020033#define MAX_MUX_CHANNELS 2
34
Dirk Eibacha605ea72010-10-21 10:50:05 +020035enum {
36 UNITTYPE_MAIN_SERVER = 0,
37 UNITTYPE_MAIN_USER = 1,
38 UNITTYPE_VIDEO_SERVER = 2,
39 UNITTYPE_VIDEO_USER = 3,
40};
41
42enum {
43 HWVER_100 = 0,
44 HWVER_104 = 1,
45 HWVER_110 = 2,
Dirk Eibache50e8962013-07-25 19:28:13 +020046 HWVER_120 = 3,
47 HWVER_200 = 4,
48 HWVER_210 = 5,
Dirk Eibacha8089702013-08-09 10:52:51 +020049 HWVER_220 = 6,
50 HWVER_230 = 7,
Dirk Eibache50e8962013-07-25 19:28:13 +020051};
52
53enum {
54 FPGA_HWVER_200 = 0,
55 FPGA_HWVER_210 = 1,
Dirk Eibacha605ea72010-10-21 10:50:05 +020056};
57
58enum {
59 COMPRESSION_NONE = 0,
Dirk Eibache50e8962013-07-25 19:28:13 +020060 COMPRESSION_TYPE1_DELTA = 1,
61 COMPRESSION_TYPE1_TYPE2_DELTA = 3,
Dirk Eibacha605ea72010-10-21 10:50:05 +020062};
63
64enum {
65 AUDIO_NONE = 0,
66 AUDIO_TX = 1,
67 AUDIO_RX = 2,
68 AUDIO_RXTX = 3,
69};
70
71enum {
72 SYSCLK_147456 = 0,
73};
74
75enum {
76 RAM_DDR2_32 = 0,
Dirk Eibache50e8962013-07-25 19:28:13 +020077 RAM_DDR3_32 = 1,
Dirk Eibacha605ea72010-10-21 10:50:05 +020078};
79
Dirk Eibache50e8962013-07-25 19:28:13 +020080enum {
Dirk Eibacha8089702013-08-09 10:52:51 +020081 CARRIER_SPEED_1G = 0,
82 CARRIER_SPEED_2_5G = 1,
83};
84
85enum {
Dirk Eibache50e8962013-07-25 19:28:13 +020086 MCFPGA_DONE = 1 << 0,
87 MCFPGA_INIT_N = 1 << 1,
88 MCFPGA_PROGRAM_N = 1 << 2,
89 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
90 MCFPGA_RESET_N = 1 << 4,
91};
92
93enum {
94 GPIO_MDC = 1 << 14,
95 GPIO_MDIO = 1 << 15,
96};
97
98unsigned int mclink_fpgacount;
Dirk Eibachaba27ac2013-06-26 16:04:26 +020099struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
100
Dirk Eibache50e8962013-07-25 19:28:13 +0200101static int setup_88e1518(const char *bus, unsigned char addr);
102static int verify_88e1518(const char *bus, unsigned char addr);
103
104int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
105{
106 int res;
107
108 switch (fpga) {
109 case 0:
110 out_le16(reg, data);
111 break;
112 default:
113 res = mclink_send(fpga - 1, regoff, data);
114 if (res < 0) {
115 printf("mclink_send reg %02lx data %04x returned %d\n",
116 regoff, data, res);
117 return res;
118 }
119 break;
120 }
121
122 return 0;
123}
124
125int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
126{
127 int res;
128
129 switch (fpga) {
130 case 0:
131 *data = in_le16(reg);
132 break;
133 default:
134 if (fpga > mclink_fpgacount)
135 return -EINVAL;
136 res = mclink_receive(fpga - 1, regoff, data);
137 if (res < 0) {
138 printf("mclink_receive reg %02lx returned %d\n",
139 regoff, res);
140 return res;
141 }
142 }
143
144 return 0;
145}
146
Dirk Eibacha605ea72010-10-21 10:50:05 +0200147/*
148 * Check Board Identity:
149 */
150int checkboard(void)
151{
Dirk Eibachb19bf832012-04-26 03:54:23 +0000152 char *s = getenv("serial#");
153
154 puts("Board: ");
155
156 puts("IoCon");
157
158 if (s != NULL) {
159 puts(", serial# ");
160 puts(s);
161 }
162
163 puts("\n");
164
165 return 0;
166}
167
Dirk Eibachd78951d2013-08-09 10:52:52 +0200168static void print_fpga_info(unsigned int fpga, bool rgmii2_present)
Dirk Eibachb19bf832012-04-26 03:54:23 +0000169{
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200170 u16 versions;
171 u16 fpga_version;
172 u16 fpga_features;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200173 unsigned unit_type;
174 unsigned hardware_version;
175 unsigned feature_compression;
176 unsigned feature_osd;
177 unsigned feature_audio;
178 unsigned feature_sysclock;
179 unsigned feature_ramconfig;
Dirk Eibacha8089702013-08-09 10:52:51 +0200180 unsigned feature_carrier_speed;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200181 unsigned feature_carriers;
182 unsigned feature_video_channels;
Dirk Eibacha8089702013-08-09 10:52:51 +0200183
Dirk Eibache50e8962013-07-25 19:28:13 +0200184 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200185
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200186 FPGA_GET_REG(0, versions, &versions);
187 FPGA_GET_REG(0, fpga_version, &fpga_version);
188 FPGA_GET_REG(0, fpga_features, &fpga_features);
189
Dirk Eibacha605ea72010-10-21 10:50:05 +0200190 unit_type = (versions & 0xf000) >> 12;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200191 feature_compression = (fpga_features & 0xe000) >> 13;
192 feature_osd = fpga_features & (1<<11);
193 feature_audio = (fpga_features & 0x0600) >> 9;
194 feature_sysclock = (fpga_features & 0x0180) >> 7;
195 feature_ramconfig = (fpga_features & 0x0060) >> 5;
Dirk Eibacha8089702013-08-09 10:52:51 +0200196 feature_carrier_speed = fpga_features & (1<<4);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200197 feature_carriers = (fpga_features & 0x000c) >> 2;
198 feature_video_channels = fpga_features & 0x0003;
199
Dirk Eibache50e8962013-07-25 19:28:13 +0200200 if (legacy)
201 printf("legacy ");
202
Dirk Eibacha605ea72010-10-21 10:50:05 +0200203 switch (unit_type) {
204 case UNITTYPE_MAIN_USER:
205 printf("Mainchannel");
206 break;
207
208 case UNITTYPE_VIDEO_USER:
209 printf("Videochannel");
210 break;
211
212 default:
213 printf("UnitType %d(not supported)", unit_type);
214 break;
215 }
216
Dirk Eibache50e8962013-07-25 19:28:13 +0200217 if (unit_type == UNITTYPE_MAIN_USER) {
218 if (legacy)
219 hardware_version =
220 (in_le16((void *)LATCH2_BASE)>>8) & 0x0f;
221 else
222 hardware_version =
223 (!!pca9698_get_value(0x20, 24) << 0)
224 | (!!pca9698_get_value(0x20, 25) << 1)
225 | (!!pca9698_get_value(0x20, 26) << 2)
226 | (!!pca9698_get_value(0x20, 27) << 3);
227 switch (hardware_version) {
228 case HWVER_100:
229 printf(" HW-Ver 1.00,");
230 break;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200231
Dirk Eibache50e8962013-07-25 19:28:13 +0200232 case HWVER_104:
233 printf(" HW-Ver 1.04,");
234 break;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200235
Dirk Eibache50e8962013-07-25 19:28:13 +0200236 case HWVER_110:
237 printf(" HW-Ver 1.10,");
238 break;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200239
Dirk Eibache50e8962013-07-25 19:28:13 +0200240 case HWVER_120:
241 printf(" HW-Ver 1.20-1.21,");
242 break;
243
244 case HWVER_200:
245 printf(" HW-Ver 2.00,");
246 break;
247
248 case HWVER_210:
249 printf(" HW-Ver 2.10,");
250 break;
251
Dirk Eibacha8089702013-08-09 10:52:51 +0200252 case HWVER_220:
253 printf(" HW-Ver 2.20,");
254 break;
255
256 case HWVER_230:
257 printf(" HW-Ver 2.30,");
258 break;
259
Dirk Eibache50e8962013-07-25 19:28:13 +0200260 default:
261 printf(" HW-Ver %d(not supported),",
262 hardware_version);
263 break;
264 }
Dirk Eibachd78951d2013-08-09 10:52:52 +0200265 if (rgmii2_present)
266 printf(" RGMII2,");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200267 }
268
Dirk Eibache50e8962013-07-25 19:28:13 +0200269 if (unit_type == UNITTYPE_VIDEO_USER) {
270 hardware_version = versions & 0x000f;
271 switch (hardware_version) {
272 case FPGA_HWVER_200:
273 printf(" HW-Ver 2.00,");
274 break;
275
276 case FPGA_HWVER_210:
277 printf(" HW-Ver 2.10,");
278 break;
279
280 default:
281 printf(" HW-Ver %d(not supported),",
282 hardware_version);
283 break;
284 }
285 }
286
287 printf(" FPGA V %d.%02d\n features:",
288 fpga_version / 100, fpga_version % 100);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200289
290
291 switch (feature_compression) {
292 case COMPRESSION_NONE:
293 printf(" no compression");
294 break;
295
296 case COMPRESSION_TYPE1_DELTA:
297 printf(" type1-deltacompression");
298 break;
299
Dirk Eibache50e8962013-07-25 19:28:13 +0200300 case COMPRESSION_TYPE1_TYPE2_DELTA:
301 printf(" type1-deltacompression, type2-inlinecompression");
302 break;
303
Dirk Eibacha605ea72010-10-21 10:50:05 +0200304 default:
305 printf(" compression %d(not supported)", feature_compression);
306 break;
307 }
308
309 printf(", %sosd", feature_osd ? "" : "no ");
310
311 switch (feature_audio) {
312 case AUDIO_NONE:
313 printf(", no audio");
314 break;
315
316 case AUDIO_TX:
317 printf(", audio tx");
318 break;
319
320 case AUDIO_RX:
321 printf(", audio rx");
322 break;
323
324 case AUDIO_RXTX:
325 printf(", audio rx+tx");
326 break;
327
328 default:
329 printf(", audio %d(not supported)", feature_audio);
330 break;
331 }
332
333 puts(",\n ");
334
335 switch (feature_sysclock) {
336 case SYSCLK_147456:
337 printf("clock 147.456 MHz");
338 break;
339
340 default:
341 printf("clock %d(not supported)", feature_sysclock);
342 break;
343 }
344
345 switch (feature_ramconfig) {
346 case RAM_DDR2_32:
347 printf(", RAM 32 bit DDR2");
348 break;
349
Dirk Eibache50e8962013-07-25 19:28:13 +0200350 case RAM_DDR3_32:
351 printf(", RAM 32 bit DDR3");
352 break;
353
Dirk Eibacha605ea72010-10-21 10:50:05 +0200354 default:
355 printf(", RAM %d(not supported)", feature_ramconfig);
356 break;
357 }
358
Dirk Eibacha8089702013-08-09 10:52:51 +0200359 printf(", %d carrier(s) %s", feature_carriers,
360 feature_carrier_speed ? "2.5Gbit/s" : "1Gbit/s");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200361
362 printf(", %d video channel(s)\n", feature_video_channels);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200363}
364
365int last_stage_init(void)
366{
Dirk Eibache50e8962013-07-25 19:28:13 +0200367 int slaves;
368 unsigned int k;
Dirk Eibachd78951d2013-08-09 10:52:52 +0200369 unsigned int mux_ch;
Dirk Eibache50e8962013-07-25 19:28:13 +0200370 unsigned char mclink_controllers[] = { 0x24, 0x25, 0x26 };
371 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
Dirk Eibacha8089702013-08-09 10:52:51 +0200372 u16 fpga_features;
373 int feature_carrier_speed = fpga_features & (1<<4);
Dirk Eibachd78951d2013-08-09 10:52:52 +0200374 bool ch0_rgmii2_present = false;
Dirk Eibacha8089702013-08-09 10:52:51 +0200375
376 FPGA_GET_REG(0, fpga_features, &fpga_features);
Dirk Eibachb19bf832012-04-26 03:54:23 +0000377
Dirk Eibachd78951d2013-08-09 10:52:52 +0200378 if (!legacy)
379 ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
380
381 print_fpga_info(0, ch0_rgmii2_present);
Dirk Eibache50e8962013-07-25 19:28:13 +0200382 osd_probe(0);
383
384 /* wait for FPGA done */
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;
390
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 }
399 }
400
Dirk Eibacha8089702013-08-09 10:52:51 +0200401 if (!legacy && (feature_carrier_speed == CARRIER_SPEED_1G)) {
Dirk Eibache50e8962013-07-25 19:28:13 +0200402 miiphy_register(bb_miiphy_buses[0].name, bb_miiphy_read,
403 bb_miiphy_write);
Dirk Eibachd78951d2013-08-09 10:52:52 +0200404 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
405 if ((mux_ch == 1) && !ch0_rgmii2_present)
406 continue;
407
408 if (!verify_88e1518(bb_miiphy_buses[0].name, mux_ch)) {
409 printf("Fixup 88e1518 erratum on %s phy %u\n",
410 bb_miiphy_buses[0].name, mux_ch);
411 setup_88e1518(bb_miiphy_buses[0].name, mux_ch);
412 }
Dirk Eibache50e8962013-07-25 19:28:13 +0200413 }
414 }
415
416 /* wait for slave-PLLs to be up and running */
417 udelay(500000);
418
419 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
420 slaves = mclink_probe();
421 mclink_fpgacount = 0;
422
423 if (slaves <= 0)
424 return 0;
425
426 mclink_fpgacount = slaves;
427
428 for (k = 1; k <= slaves; ++k) {
Dirk Eibacha8089702013-08-09 10:52:51 +0200429 FPGA_GET_REG(k, fpga_features, &fpga_features);
430 feature_carrier_speed = fpga_features & (1<<4);
431
Dirk Eibachd78951d2013-08-09 10:52:52 +0200432 print_fpga_info(k, false);
Dirk Eibache50e8962013-07-25 19:28:13 +0200433 osd_probe(k);
Dirk Eibacha8089702013-08-09 10:52:51 +0200434 if (feature_carrier_speed == CARRIER_SPEED_1G) {
435 miiphy_register(bb_miiphy_buses[k].name,
436 bb_miiphy_read, bb_miiphy_write);
437 if (!verify_88e1518(bb_miiphy_buses[k].name, 0)) {
438 printf("Fixup 88e1518 erratum on %s\n",
439 bb_miiphy_buses[k].name);
440 setup_88e1518(bb_miiphy_buses[k].name, 0);
441 }
Dirk Eibache50e8962013-07-25 19:28:13 +0200442 }
443 }
444
445 return 0;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200446}
447
448/*
449 * provide access to fpga gpios (for I2C bitbang)
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200450 * (these may look all too simple but make iocon.h much more readable)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200451 */
Dirk Eibache50e8962013-07-25 19:28:13 +0200452void fpga_gpio_set(unsigned int bus, int pin)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200453{
Dirk Eibache50e8962013-07-25 19:28:13 +0200454 FPGA_SET_REG(bus, gpio.set, pin);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200455}
456
Dirk Eibache50e8962013-07-25 19:28:13 +0200457void fpga_gpio_clear(unsigned int bus, int pin)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200458{
Dirk Eibache50e8962013-07-25 19:28:13 +0200459 FPGA_SET_REG(bus, gpio.clear, pin);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200460}
461
Dirk Eibache50e8962013-07-25 19:28:13 +0200462int fpga_gpio_get(unsigned int bus, int pin)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200463{
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200464 u16 val;
465
Dirk Eibache50e8962013-07-25 19:28:13 +0200466 FPGA_GET_REG(bus, gpio.read, &val);
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200467
468 return val & pin;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200469}
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000470
471void gd405ep_init(void)
472{
Dirk Eibache50e8962013-07-25 19:28:13 +0200473 unsigned int k;
474
475 if (i2c_probe(0x20)) { /* i2c_probe returns 0 on success */
476 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
477 gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM;
478 } else {
479 pca9698_direction_output(0x20, 4, 1);
480 }
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000481}
482
483void gd405ep_set_fpga_reset(unsigned state)
484{
Dirk Eibache50e8962013-07-25 19:28:13 +0200485 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
486
487 if (legacy) {
488 if (state) {
489 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
490 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
491 } else {
492 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
493 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
494 }
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000495 } else {
Dirk Eibache50e8962013-07-25 19:28:13 +0200496 pca9698_set_value(0x20, 4, state ? 0 : 1);
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000497 }
498}
499
500void gd405ep_setup_hw(void)
501{
502 /*
503 * set "startup-finished"-gpios
504 */
505 gpio_write_bit(21, 0);
506 gpio_write_bit(22, 1);
507}
508
509int gd405ep_get_fpga_done(unsigned fpga)
510{
Dirk Eibache50e8962013-07-25 19:28:13 +0200511 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
512
513 if (legacy)
514 return in_le16((void *)LATCH2_BASE)
515 & CONFIG_SYS_FPGA_DONE(fpga);
516 else
517 return pca9698_get_value(0x20, 20);
518}
519
520/*
521 * FPGA MII bitbang implementation
522 */
523
524struct fpga_mii {
525 unsigned fpga;
526 int mdio;
527} fpga_mii[] = {
528 { 0, 1},
529 { 1, 1},
530 { 2, 1},
531 { 3, 1},
532};
533
534static int mii_dummy_init(struct bb_miiphy_bus *bus)
535{
536 return 0;
537}
538
539static int mii_mdio_active(struct bb_miiphy_bus *bus)
540{
541 struct fpga_mii *fpga_mii = bus->priv;
542
543 if (fpga_mii->mdio)
544 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
545 else
546 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
547
548 return 0;
549}
550
551static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
552{
553 struct fpga_mii *fpga_mii = bus->priv;
554
555 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
556
557 return 0;
558}
559
560static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
561{
562 struct fpga_mii *fpga_mii = bus->priv;
563
564 if (v)
565 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
566 else
567 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
568
569 fpga_mii->mdio = v;
570
571 return 0;
572}
573
574static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
575{
576 u16 gpio;
577 struct fpga_mii *fpga_mii = bus->priv;
578
579 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
580
581 *v = ((gpio & GPIO_MDIO) != 0);
582
583 return 0;
584}
585
586static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
587{
588 struct fpga_mii *fpga_mii = bus->priv;
589
590 if (v)
591 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
592 else
593 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
594
595 return 0;
596}
597
598static int mii_delay(struct bb_miiphy_bus *bus)
599{
600 udelay(1);
601
602 return 0;
603}
604
605struct bb_miiphy_bus bb_miiphy_buses[] = {
606 {
Dirk Eibachd78951d2013-08-09 10:52:52 +0200607 .name = "board0",
Dirk Eibache50e8962013-07-25 19:28:13 +0200608 .init = mii_dummy_init,
609 .mdio_active = mii_mdio_active,
610 .mdio_tristate = mii_mdio_tristate,
611 .set_mdio = mii_set_mdio,
612 .get_mdio = mii_get_mdio,
613 .set_mdc = mii_set_mdc,
614 .delay = mii_delay,
615 .priv = &fpga_mii[0],
616 },
617 {
Dirk Eibachd78951d2013-08-09 10:52:52 +0200618 .name = "board1",
Dirk Eibache50e8962013-07-25 19:28:13 +0200619 .init = mii_dummy_init,
620 .mdio_active = mii_mdio_active,
621 .mdio_tristate = mii_mdio_tristate,
622 .set_mdio = mii_set_mdio,
623 .get_mdio = mii_get_mdio,
624 .set_mdc = mii_set_mdc,
625 .delay = mii_delay,
626 .priv = &fpga_mii[1],
627 },
628 {
Dirk Eibachd78951d2013-08-09 10:52:52 +0200629 .name = "board2",
Dirk Eibache50e8962013-07-25 19:28:13 +0200630 .init = mii_dummy_init,
631 .mdio_active = mii_mdio_active,
632 .mdio_tristate = mii_mdio_tristate,
633 .set_mdio = mii_set_mdio,
634 .get_mdio = mii_get_mdio,
635 .set_mdc = mii_set_mdc,
636 .delay = mii_delay,
637 .priv = &fpga_mii[2],
638 },
639 {
Dirk Eibachd78951d2013-08-09 10:52:52 +0200640 .name = "board3",
Dirk Eibache50e8962013-07-25 19:28:13 +0200641 .init = mii_dummy_init,
642 .mdio_active = mii_mdio_active,
643 .mdio_tristate = mii_mdio_tristate,
644 .set_mdio = mii_set_mdio,
645 .get_mdio = mii_get_mdio,
646 .set_mdc = mii_set_mdc,
647 .delay = mii_delay,
648 .priv = &fpga_mii[3],
649 },
650};
651
652int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
653 sizeof(bb_miiphy_buses[0]);
654
655/*
656 * Workaround for erratum mentioned in 88E1518 release notes
657 */
658
659static int verify_88e1518(const char *bus, unsigned char addr)
660{
661 u16 phy_id1, phy_id2;
662
663 if (miiphy_read(bus, addr, 2, &phy_id1) ||
664 miiphy_read(bus, addr, 3, &phy_id2)) {
665 printf("Error reading from the PHY addr=%02x\n", addr);
666 return -EIO;
667 }
668
669 if ((phy_id1 != 0x0141) || ((phy_id2 & 0xfff0) != 0x0dd0))
670 return -EINVAL;
671
672 return 0;
673}
674
675struct regfix_88e1518 {
676 u8 reg;
677 u16 data;
678} regfix_88e1518[] = {
679 { 22, 0x00ff },
680 { 17, 0x214b },
681 { 16, 0x2144 },
682 { 17, 0x0c28 },
683 { 16, 0x2146 },
684 { 17, 0xb233 },
685 { 16, 0x214d },
686 { 17, 0xcc0c },
687 { 16, 0x2159 },
688 { 22, 0x00fb },
689 { 7, 0xc00d },
690 { 22, 0x0000 },
691};
692
693static int setup_88e1518(const char *bus, unsigned char addr)
694{
695 unsigned int k;
696
697 for (k = 0; k < ARRAY_SIZE(regfix_88e1518); ++k) {
698 if (miiphy_write(bus, addr,
699 regfix_88e1518[k].reg,
700 regfix_88e1518[k].data)) {
701 printf("Error writing to the PHY addr=%02x\n", addr);
702 return -1;
703 }
704 }
705
706 return 0;
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000707}