blob: 6a837883a7bfb920d72a49264ddf93a4b3a9bda8 [file] [log] [blame]
Dirk Eibach6fabe552011-10-20 11:12:55 +02001/*
2 * (C) Copyright 2010
3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
4 *
5 * based on kilauea.c
6 * by Stefan Roese, DENX Software Engineering, sr@denx.de.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibach6fabe552011-10-20 11:12:55 +02009 */
10
11#include <common.h>
12#include <asm/ppc4xx.h>
13#include <asm/ppc405.h>
14#include <libfdt.h>
15#include <fdt_support.h>
16#include <asm/processor.h>
17#include <asm/io.h>
18#include <asm/errno.h>
19#include <asm/ppc4xx-gpio.h>
20#include <flash.h>
21
22#include <pca9698.h>
23
24#include "405ex.h"
25#include <gdsys_fpga.h>
26
27#include <miiphy.h>
28#include <i2c.h>
29#include <dtt.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
33#define PHYREG_CONTROL 0
34#define PHYREG_PAGE_ADDRESS 22
35#define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16
36#define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26
37#define PHYREG_PG2_MAC_SPECIFIC_STATUS_1 17
38#define PHYREG_PG2_MAC_SPECIFIC_CONTROL 21
39
40#define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
41#define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
42#define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
43#define LATCH3_BASE (CONFIG_SYS_LATCH_BASE + 0x300)
44
45enum {
46 UNITTYPE_CCD_SWITCH = 1,
47};
48
49enum {
50 HWVER_100 = 0,
51 HWVER_110 = 1,
52};
53
Dirk Eibach20614a22013-06-26 16:04:26 +020054struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
55
Dirk Eibach6fabe552011-10-20 11:12:55 +020056static inline void blank_string(int size)
57{
58 int i;
59
60 for (i = 0; i < size; i++)
61 putc('\b');
62 for (i = 0; i < size; i++)
63 putc(' ');
64 for (i = 0; i < size; i++)
65 putc('\b');
66}
67
68/*
69 * Board early initialization function
70 */
71int misc_init_r(void)
72{
73 /* startup fans */
74 dtt_init();
75
76#ifdef CONFIG_ENV_IS_IN_FLASH
77 /* Monitor protection ON by default */
78 flash_protect(FLAG_PROTECT_SET,
79 -CONFIG_SYS_MONITOR_LEN,
80 0xffffffff,
81 &flash_info[0]);
82#endif
83
84 return 0;
85}
86
87static void print_fpga_info(unsigned dev)
88{
Dirk Eibach20614a22013-06-26 16:04:26 +020089 u16 versions;
90 u16 fpga_version;
91 u16 fpga_features;
Dirk Eibach6fabe552011-10-20 11:12:55 +020092 int fpga_state = get_fpga_state(dev);
93
94 unsigned unit_type;
95 unsigned hardware_version;
96 unsigned feature_channels;
97 unsigned feature_expansion;
98
Dirk Eibach20614a22013-06-26 16:04:26 +020099 FPGA_GET_REG(dev, versions, &versions);
100 FPGA_GET_REG(dev, fpga_version, &fpga_version);
101 FPGA_GET_REG(dev, fpga_features, &fpga_features);
102
Dirk Eibach6fabe552011-10-20 11:12:55 +0200103 printf("FPGA%d: ", dev);
104 if (fpga_state & FPGA_STATE_PLATFORM)
105 printf("(legacy) ");
106
107 if (fpga_state & FPGA_STATE_DONE_FAILED) {
108 printf(" done timed out\n");
109 return;
110 }
111
112 if (fpga_state & FPGA_STATE_REFLECTION_FAILED) {
113 printf(" refelectione test failed\n");
114 return;
115 }
116
117 unit_type = (versions & 0xf000) >> 12;
118 hardware_version = versions & 0x000f;
119 feature_channels = fpga_features & 0x007f;
120 feature_expansion = fpga_features & (1<<15);
121
122 switch (unit_type) {
123 case UNITTYPE_CCD_SWITCH:
124 printf("CCD-Switch");
125 break;
126
127 default:
128 printf("UnitType %d(not supported)", unit_type);
129 break;
130 }
131
132 switch (hardware_version) {
133 case HWVER_100:
134 printf(" HW-Ver 1.00\n");
135 break;
136
137 case HWVER_110:
138 printf(" HW-Ver 1.10\n");
139 break;
140
141 default:
142 printf(" HW-Ver %d(not supported)\n",
143 hardware_version);
144 break;
145 }
146
147 printf(" FPGA V %d.%02d, features:",
148 fpga_version / 100, fpga_version % 100);
149
150 printf(" %d channel(s)", feature_channels);
151
152 printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
153}
154
155int checkboard(void)
156{
157 char *s = getenv("serial#");
158
159 printf("Board: CATCenter Io64\n");
160
161 if (s != NULL) {
162 puts(", serial# ");
163 puts(s);
164 }
165
166 return 0;
167}
168
169int configure_gbit_phy(char *bus, unsigned char addr)
170{
171 unsigned short value;
172
173 /* select page 0 */
174 if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0000))
175 goto err_out;
176 /* switch to powerdown */
177 if (miiphy_read(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
178 &value))
179 goto err_out;
180 if (miiphy_write(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
181 value | 0x0004))
182 goto err_out;
183 /* select page 2 */
184 if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0002))
185 goto err_out;
186 /* disable SGMII autonegotiation */
187 if (miiphy_write(bus, addr, PHYREG_PG2_MAC_SPECIFIC_CONTROL, 48))
188 goto err_out;
189 /* select page 0 */
190 if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0000))
191 goto err_out;
192 /* switch from powerdown to normal operation */
193 if (miiphy_read(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
194 &value))
195 goto err_out;
196 if (miiphy_write(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
197 value & ~0x0004))
198 goto err_out;
199 /* reset phy so settings take effect */
200 if (miiphy_write(bus, addr, PHYREG_CONTROL, 0x9140))
201 goto err_out;
202
203 return 0;
204
205err_out:
206 printf("Error writing to the PHY addr=%02x\n", addr);
207 return -1;
208}
209
210int verify_gbit_phy(char *bus, unsigned char addr)
211{
212 unsigned short value;
213
214 /* select page 2 */
215 if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0002))
216 goto err_out;
217 /* verify SGMII link status */
218 if (miiphy_read(bus, addr, PHYREG_PG2_MAC_SPECIFIC_STATUS_1, &value))
219 goto err_out;
220 if (!(value & (1 << 10)))
221 return -2;
222
223 return 0;
224
225err_out:
226 printf("Error writing to the PHY addr=%02x\n", addr);
227 return -1;
228}
229
230int last_stage_init(void)
231{
232 unsigned int k;
233 unsigned int fpga;
Dirk Eibach6fabe552011-10-20 11:12:55 +0200234 int failed = 0;
235 char str_phys[] = "Setup PHYs -";
236 char str_serdes[] = "Start SERDES blocks";
237 char str_channels[] = "Start FPGA channels";
238 char str_locks[] = "Verify SERDES locks";
Dirk Eibach6e2350f2012-01-02 11:02:46 +0100239 char str_hicb[] = "Verify HICB status";
Dirk Eibach6fabe552011-10-20 11:12:55 +0200240 char str_status[] = "Verify PHY status -";
241 char slash[] = "\\|/-\\|/-";
242
243 print_fpga_info(0);
244 print_fpga_info(1);
245
246 /* setup Gbit PHYs */
247 puts("TRANS: ");
248 puts(str_phys);
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500249 int retval;
250 struct mii_dev *mdiodev = mdio_alloc();
251 if (!mdiodev)
252 return -ENOMEM;
253 strncpy(mdiodev->name, CONFIG_SYS_GBIT_MII_BUSNAME, MDIO_NAME_LEN);
254 mdiodev->read = bb_miiphy_read;
255 mdiodev->write = bb_miiphy_write;
256
257 retval = mdio_register(mdiodev);
258 if (retval < 0)
259 return retval;
Dirk Eibach6fabe552011-10-20 11:12:55 +0200260
261 for (k = 0; k < 32; ++k) {
262 configure_gbit_phy(CONFIG_SYS_GBIT_MII_BUSNAME, k);
263 putc('\b');
264 putc(slash[k % 8]);
265 }
266
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500267 int retval;
268 struct mii_dev *mdiodev = mdio_alloc();
269 if (!mdiodev)
270 return -ENOMEM;
271 strncpy(mdiodev->name, CONFIG_SYS_GBIT_MII1_BUSNAME, MDIO_NAME_LEN);
272 mdiodev->read = bb_miiphy_read;
273 mdiodev->write = bb_miiphy_write;
274
275 retval = mdio_register(mdiodev);
276 if (retval < 0)
277 return retval;
Dirk Eibach6fabe552011-10-20 11:12:55 +0200278
279 for (k = 0; k < 32; ++k) {
280 configure_gbit_phy(CONFIG_SYS_GBIT_MII1_BUSNAME, k);
281 putc('\b');
282 putc(slash[k % 8]);
283 }
284 blank_string(strlen(str_phys));
285
286 /* take fpga serdes blocks out of reset */
287 puts(str_serdes);
288 udelay(500000);
Dirk Eibach20614a22013-06-26 16:04:26 +0200289 FPGA_SET_REG(0, quad_serdes_reset, 0);
290 FPGA_SET_REG(1, quad_serdes_reset, 0);
Dirk Eibach6fabe552011-10-20 11:12:55 +0200291 blank_string(strlen(str_serdes));
292
293 /* take channels out of reset */
294 puts(str_channels);
295 udelay(500000);
296 for (fpga = 0; fpga < 2; ++fpga) {
Dirk Eibach6fabe552011-10-20 11:12:55 +0200297 for (k = 0; k < 32; ++k)
Dirk Eibach20614a22013-06-26 16:04:26 +0200298 FPGA_SET_REG(fpga, ch[k].config_int, 0);
Dirk Eibach6fabe552011-10-20 11:12:55 +0200299 }
300 blank_string(strlen(str_channels));
301
302 /* verify channels serdes lock */
303 puts(str_locks);
304 udelay(500000);
305 for (fpga = 0; fpga < 2; ++fpga) {
Dirk Eibach6fabe552011-10-20 11:12:55 +0200306 for (k = 0; k < 32; ++k) {
Dirk Eibach20614a22013-06-26 16:04:26 +0200307 u16 status;
Vasili Galka18b050c2014-06-16 17:40:59 +0300308 FPGA_GET_REG(fpga, ch[k].status_int, &status);
Dirk Eibach6fabe552011-10-20 11:12:55 +0200309 if (!(status & (1 << 4))) {
310 failed = 1;
311 printf("fpga %d channel %d: no serdes lock\n",
312 fpga, k);
313 }
314 /* reset events */
Dirk Eibach20614a22013-06-26 16:04:26 +0200315 FPGA_SET_REG(fpga, ch[k].status_int, 0);
Dirk Eibach6fabe552011-10-20 11:12:55 +0200316 }
317 }
318 blank_string(strlen(str_locks));
319
Dirk Eibach6e2350f2012-01-02 11:02:46 +0100320 /* verify hicb_status */
321 puts(str_hicb);
322 for (fpga = 0; fpga < 2; ++fpga) {
Dirk Eibach6e2350f2012-01-02 11:02:46 +0100323 for (k = 0; k < 32; ++k) {
Dirk Eibach20614a22013-06-26 16:04:26 +0200324 u16 status;
Vasili Galka18b050c2014-06-16 17:40:59 +0300325 FPGA_GET_REG(fpga, hicb_ch[k].status_int, &status);
Dirk Eibach6e2350f2012-01-02 11:02:46 +0100326 if (status)
327 printf("fpga %d hicb %d: hicb status %04x\n",
328 fpga, k, status);
329 /* reset events */
Dirk Eibach20614a22013-06-26 16:04:26 +0200330 FPGA_SET_REG(fpga, hicb_ch[k].status_int, 0);
Dirk Eibach6e2350f2012-01-02 11:02:46 +0100331 }
332 }
333 blank_string(strlen(str_hicb));
334
Dirk Eibach6fabe552011-10-20 11:12:55 +0200335 /* verify phy status */
336 puts(str_status);
337 for (k = 0; k < 32; ++k) {
338 if (verify_gbit_phy(CONFIG_SYS_GBIT_MII_BUSNAME, k)) {
339 printf("verify baseboard phy %d failed\n", k);
340 failed = 1;
341 }
342 putc('\b');
343 putc(slash[k % 8]);
344 }
345 for (k = 0; k < 32; ++k) {
346 if (verify_gbit_phy(CONFIG_SYS_GBIT_MII1_BUSNAME, k)) {
347 printf("verify extensionboard phy %d failed\n", k);
348 failed = 1;
349 }
350 putc('\b');
351 putc(slash[k % 8]);
352 }
353 blank_string(strlen(str_status));
354
355 printf("Starting 64 channels %s\n", failed ? "failed" : "ok");
356
357 return 0;
358}
359
360void gd405ex_init(void)
361{
362 unsigned int k;
363
364 if (i2c_probe(0x22)) { /* i2c_probe returns 0 on success */
365 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
Simon Glassf2d9aaf2012-12-13 20:49:02 +0000366 gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM;
Dirk Eibach6fabe552011-10-20 11:12:55 +0200367 } else {
368 pca9698_direction_output(0x22, 39, 1);
369 }
370}
371
372void gd405ex_set_fpga_reset(unsigned state)
373{
374 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
375
376 if (legacy) {
377 if (state) {
378 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
379 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
380 } else {
381 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
382 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
383 }
384 } else {
385 pca9698_set_value(0x22, 39, state ? 0 : 1);
386 }
387}
388
389void gd405ex_setup_hw(void)
390{
391 gpio_write_bit(CONFIG_SYS_GPIO_STARTUP_FINISHED_N, 0);
392 gpio_write_bit(CONFIG_SYS_GPIO_STARTUP_FINISHED, 1);
393}
394
395int gd405ex_get_fpga_done(unsigned fpga)
396{
397 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
398
399 if (legacy)
400 return in_le16((void *)LATCH3_BASE)
401 & CONFIG_SYS_FPGA_DONE(fpga);
402 else
403 return pca9698_get_value(0x22, fpga ? 9 : 8);
404}