blob: 03d796cdb89b1b09eb9662328ea862341629d3a9 [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 Eibachaba27ac2013-06-26 16:04:26 +020040struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
41
Dirk Eibachb19bf832012-04-26 03:54:23 +000042int misc_init_r(void)
43{
44 /* startup fans */
45 dtt_init();
46
47 return 0;
48}
49
Dirk Eibacha605ea72010-10-21 10:50:05 +020050int configure_gbit_phy(unsigned char addr)
51{
52 unsigned short value;
53
54 /* select page 2 */
55 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
56 PHYREG_PAGE_ADDRESS, 0x0002))
57 goto err_out;
58 /* disable SGMII autonegotiation */
59 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
60 PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2, 0x800a))
61 goto err_out;
62 /* select page 0 */
63 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
64 PHYREG_PAGE_ADDRESS, 0x0000))
65 goto err_out;
66 /* switch from powerdown to normal operation */
67 if (miiphy_read(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
68 PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, &value))
69 goto err_out;
70 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
71 PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, value & ~0x0004))
72 goto err_out;
73 /* reset phy so settings take effect */
74 if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
75 PHYREG_CONTROL, 0x9140))
76 goto err_out;
77
78 return 0;
79
80err_out:
81 printf("Error writing to the PHY addr=%02x\n", addr);
82 return -1;
83}
84
85/*
86 * Check Board Identity:
87 */
88int checkboard(void)
89{
Dirk Eibachb19bf832012-04-26 03:54:23 +000090 char *s = getenv("serial#");
91
92 puts("Board: CATCenter Io");
93
94 if (s != NULL) {
95 puts(", serial# ");
96 puts(s);
97 }
98
99 puts("\n");
100
101 return 0;
102}
103
104static void print_fpga_info(void)
105{
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200106 u16 versions;
107 u16 fpga_version;
108 u16 fpga_features;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200109 unsigned unit_type;
110 unsigned hardware_version;
111 unsigned feature_channels;
112 unsigned feature_expansion;
113
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200114 FPGA_GET_REG(0, versions, &versions);
115 FPGA_GET_REG(0, fpga_version, &fpga_version);
116 FPGA_GET_REG(0, fpga_features, &fpga_features);
117
Dirk Eibacha605ea72010-10-21 10:50:05 +0200118 unit_type = (versions & 0xf000) >> 12;
119 hardware_version = versions & 0x000f;
120 feature_channels = fpga_features & 0x007f;
121 feature_expansion = fpga_features & (1<<15);
122
Dirk Eibachb19bf832012-04-26 03:54:23 +0000123 puts("FPGA: ");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200124
125 switch (unit_type) {
126 case UNITTYPE_CCD_SWITCH:
127 printf("CCD-Switch");
128 break;
129
130 default:
131 printf("UnitType %d(not supported)", unit_type);
132 break;
133 }
134
135 switch (hardware_version) {
136 case HWVER_100:
137 printf(" HW-Ver 1.00\n");
138 break;
139
140 case HWVER_110:
141 printf(" HW-Ver 1.10\n");
142 break;
143
144 case HWVER_121:
145 printf(" HW-Ver 1.21\n");
146 break;
147
148 case HWVER_122:
149 printf(" HW-Ver 1.22\n");
150 break;
151
152 default:
153 printf(" HW-Ver %d(not supported)\n",
154 hardware_version);
155 break;
156 }
157
158 printf(" FPGA V %d.%02d, features:",
159 fpga_version / 100, fpga_version % 100);
160
161 printf(" %d channel(s)", feature_channels);
162
163 printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
Dirk Eibacha605ea72010-10-21 10:50:05 +0200164}
165
166/*
167 * setup Gbit PHYs
168 */
169int last_stage_init(void)
170{
171 unsigned int k;
172
Dirk Eibachb19bf832012-04-26 03:54:23 +0000173 print_fpga_info();
174
Dirk Eibacha605ea72010-10-21 10:50:05 +0200175 miiphy_register(CONFIG_SYS_GBIT_MII_BUSNAME,
176 bb_miiphy_read, bb_miiphy_write);
177
178 for (k = 0; k < 32; ++k)
179 configure_gbit_phy(k);
180
181 /* take fpga serdes blocks out of reset */
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200182 FPGA_SET_REG(0, quad_serdes_reset, 0);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200183
184 return 0;
185}
Dirk Eibach6e9e6c32012-04-26 03:54:22 +0000186
187void gd405ep_init(void)
188{
189}
190
191void gd405ep_set_fpga_reset(unsigned state)
192{
193 if (state) {
194 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
195 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
196 } else {
197 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
198 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
199 }
200}
201
202void gd405ep_setup_hw(void)
203{
204 /*
205 * set "startup-finished"-gpios
206 */
207 gpio_write_bit(21, 0);
208 gpio_write_bit(22, 1);
209}
210
211int gd405ep_get_fpga_done(unsigned fpga)
212{
213 return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga);
214}