blob: eee9ba0aaa15c8b809a84f30c17892c5fe97d471 [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>
10#include <asm/processor.h>
11#include <asm/io.h>
12#include <asm/ppc4xx-gpio.h>
13
Dirk Eibachb19bf832012-04-26 03:54:23 +000014#include <dtt.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020015#include <miiphy.h>
16
Dirk Eibach6e9e6c32012-04-26 03:54:22 +000017#include "405ep.h"
Dirk Eibach2da0fc02011-01-21 09:31:21 +010018#include <gdsys_fpga.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020019
Dirk Eibach6e9e6c32012-04-26 03:54:22 +000020#define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
21#define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
22#define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
23
Dirk Eibacha605ea72010-10-21 10:50:05 +020024#define PHYREG_CONTROL 0
25#define PHYREG_PAGE_ADDRESS 22
26#define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16
27#define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26
28
29enum {
Dirk Eibacha605ea72010-10-21 10:50:05 +020030 UNITTYPE_CCD_SWITCH = 1,
31};
32
33enum {
34 HWVER_100 = 0,
35 HWVER_110 = 1,
36 HWVER_121 = 2,
37 HWVER_122 = 3,
38};
39
Dirk Eibachb19bf832012-04-26 03:54:23 +000040int misc_init_r(void)
41{
42 /* startup fans */
43 dtt_init();
44
45 return 0;
46}
47
Dirk Eibacha605ea72010-10-21 10:50:05 +020048int configure_gbit_phy(unsigned char addr)
49{
50 unsigned short value;
51
52 /* select page 2 */
53 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
54 PHYREG_PAGE_ADDRESS, 0x0002))
55 goto err_out;
56 /* disable SGMII autonegotiation */
57 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
58 PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2, 0x800a))
59 goto err_out;
60 /* select page 0 */
61 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
62 PHYREG_PAGE_ADDRESS, 0x0000))
63 goto err_out;
64 /* switch from powerdown to normal operation */
65 if (miiphy_read(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
66 PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, &value))
67 goto err_out;
68 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
69 PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, value & ~0x0004))
70 goto err_out;
71 /* reset phy so settings take effect */
72 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
73 PHYREG_CONTROL, 0x9140))
74 goto err_out;
75
76 return 0;
77
78err_out:
79 printf("Error writing to the PHY addr=%02x\n", addr);
80 return -1;
81}
82
83/*
84 * Check Board Identity:
85 */
86int checkboard(void)
87{
Dirk Eibachb19bf832012-04-26 03:54:23 +000088 char *s = getenv("serial#");
89
90 puts("Board: CATCenter Io");
91
92 if (s != NULL) {
93 puts(", serial# ");
94 puts(s);
95 }
96
97 puts("\n");
98
99 return 0;
100}
101
102static void print_fpga_info(void)
103{
Dirk Eibach0e60aa82012-04-27 10:33:46 +0200104 struct ihs_fpga *fpga = (struct ihs_fpga *) CONFIG_SYS_FPGA_BASE(0);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100105 u16 versions = in_le16(&fpga->versions);
106 u16 fpga_version = in_le16(&fpga->fpga_version);
107 u16 fpga_features = in_le16(&fpga->fpga_features);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200108 unsigned unit_type;
109 unsigned hardware_version;
110 unsigned feature_channels;
111 unsigned feature_expansion;
112
113 unit_type = (versions & 0xf000) >> 12;
114 hardware_version = versions & 0x000f;
115 feature_channels = fpga_features & 0x007f;
116 feature_expansion = fpga_features & (1<<15);
117
Dirk Eibachb19bf832012-04-26 03:54:23 +0000118 puts("FPGA: ");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200119
120 switch (unit_type) {
121 case UNITTYPE_CCD_SWITCH:
122 printf("CCD-Switch");
123 break;
124
125 default:
126 printf("UnitType %d(not supported)", unit_type);
127 break;
128 }
129
130 switch (hardware_version) {
131 case HWVER_100:
132 printf(" HW-Ver 1.00\n");
133 break;
134
135 case HWVER_110:
136 printf(" HW-Ver 1.10\n");
137 break;
138
139 case HWVER_121:
140 printf(" HW-Ver 1.21\n");
141 break;
142
143 case HWVER_122:
144 printf(" HW-Ver 1.22\n");
145 break;
146
147 default:
148 printf(" HW-Ver %d(not supported)\n",
149 hardware_version);
150 break;
151 }
152
153 printf(" FPGA V %d.%02d, features:",
154 fpga_version / 100, fpga_version % 100);
155
156 printf(" %d channel(s)", feature_channels);
157
158 printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200159}
160
161/*
162 * setup Gbit PHYs
163 */
164int last_stage_init(void)
165{
Dirk Eibach0e60aa82012-04-27 10:33:46 +0200166 struct ihs_fpga *fpga = (struct ihs_fpga *) CONFIG_SYS_FPGA_BASE(0);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200167 unsigned int k;
168
Dirk Eibachb19bf832012-04-26 03:54:23 +0000169 print_fpga_info();
170
Dirk Eibacha605ea72010-10-21 10:50:05 +0200171 miiphy_register(CONFIG_SYS_GBIT_MII_BUSNAME,
172 bb_miiphy_read, bb_miiphy_write);
173
174 for (k = 0; k < 32; ++k)
175 configure_gbit_phy(k);
176
177 /* take fpga serdes blocks out of reset */
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100178 out_le16(&fpga->quad_serdes_reset, 0);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200179
180 return 0;
181}
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000182
183void gd405ep_init(void)
184{
185}
186
187void gd405ep_set_fpga_reset(unsigned state)
188{
189 if (state) {
190 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
191 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
192 } else {
193 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
194 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
195 }
196}
197
198void gd405ep_setup_hw(void)
199{
200 /*
201 * set "startup-finished"-gpios
202 */
203 gpio_write_bit(21, 0);
204 gpio_write_bit(22, 1);
205}
206
207int gd405ep_get_fpga_done(unsigned fpga)
208{
209 return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga);
210}