Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <asm/processor.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/ppc4xx-gpio.h> |
| 29 | |
| 30 | #include <miiphy.h> |
| 31 | |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame^] | 32 | #include "405ep.h" |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 33 | #include <gdsys_fpga.h> |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 34 | |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame^] | 35 | #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE) |
| 36 | #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100) |
| 37 | #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200) |
| 38 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 39 | #define PHYREG_CONTROL 0 |
| 40 | #define PHYREG_PAGE_ADDRESS 22 |
| 41 | #define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16 |
| 42 | #define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26 |
| 43 | |
| 44 | enum { |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 45 | UNITTYPE_CCD_SWITCH = 1, |
| 46 | }; |
| 47 | |
| 48 | enum { |
| 49 | HWVER_100 = 0, |
| 50 | HWVER_110 = 1, |
| 51 | HWVER_121 = 2, |
| 52 | HWVER_122 = 3, |
| 53 | }; |
| 54 | |
| 55 | int configure_gbit_phy(unsigned char addr) |
| 56 | { |
| 57 | unsigned short value; |
| 58 | |
| 59 | /* select page 2 */ |
| 60 | if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 61 | PHYREG_PAGE_ADDRESS, 0x0002)) |
| 62 | goto err_out; |
| 63 | /* disable SGMII autonegotiation */ |
| 64 | if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 65 | PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2, 0x800a)) |
| 66 | goto err_out; |
| 67 | /* select page 0 */ |
| 68 | if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 69 | PHYREG_PAGE_ADDRESS, 0x0000)) |
| 70 | goto err_out; |
| 71 | /* switch from powerdown to normal operation */ |
| 72 | if (miiphy_read(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 73 | PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, &value)) |
| 74 | goto err_out; |
| 75 | if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 76 | PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, value & ~0x0004)) |
| 77 | goto err_out; |
| 78 | /* reset phy so settings take effect */ |
| 79 | if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr, |
| 80 | PHYREG_CONTROL, 0x9140)) |
| 81 | goto err_out; |
| 82 | |
| 83 | return 0; |
| 84 | |
| 85 | err_out: |
| 86 | printf("Error writing to the PHY addr=%02x\n", addr); |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Check Board Identity: |
| 92 | */ |
| 93 | int checkboard(void) |
| 94 | { |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 95 | char buf[64]; |
| 96 | int i = getenv_f("serial#", buf, sizeof(buf)); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 97 | ihs_fpga_t *fpga = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(0); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 98 | u16 versions = in_le16(&fpga->versions); |
| 99 | u16 fpga_version = in_le16(&fpga->fpga_version); |
| 100 | u16 fpga_features = in_le16(&fpga->fpga_features); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 101 | unsigned unit_type; |
| 102 | unsigned hardware_version; |
| 103 | unsigned feature_channels; |
| 104 | unsigned feature_expansion; |
| 105 | |
| 106 | unit_type = (versions & 0xf000) >> 12; |
| 107 | hardware_version = versions & 0x000f; |
| 108 | feature_channels = fpga_features & 0x007f; |
| 109 | feature_expansion = fpga_features & (1<<15); |
| 110 | |
| 111 | printf("Board: "); |
| 112 | |
| 113 | printf("CATCenter Io"); |
| 114 | |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 115 | if (i > 0) { |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 116 | puts(", serial# "); |
Wolfgang Denk | 5c1cfee | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 117 | puts(buf); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 118 | } |
| 119 | puts("\n "); |
| 120 | |
| 121 | switch (unit_type) { |
| 122 | case UNITTYPE_CCD_SWITCH: |
| 123 | printf("CCD-Switch"); |
| 124 | break; |
| 125 | |
| 126 | default: |
| 127 | printf("UnitType %d(not supported)", unit_type); |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | switch (hardware_version) { |
| 132 | case HWVER_100: |
| 133 | printf(" HW-Ver 1.00\n"); |
| 134 | break; |
| 135 | |
| 136 | case HWVER_110: |
| 137 | printf(" HW-Ver 1.10\n"); |
| 138 | break; |
| 139 | |
| 140 | case HWVER_121: |
| 141 | printf(" HW-Ver 1.21\n"); |
| 142 | break; |
| 143 | |
| 144 | case HWVER_122: |
| 145 | printf(" HW-Ver 1.22\n"); |
| 146 | break; |
| 147 | |
| 148 | default: |
| 149 | printf(" HW-Ver %d(not supported)\n", |
| 150 | hardware_version); |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | printf(" FPGA V %d.%02d, features:", |
| 155 | fpga_version / 100, fpga_version % 100); |
| 156 | |
| 157 | printf(" %d channel(s)", feature_channels); |
| 158 | |
| 159 | printf(", expansion %ssupported\n", feature_expansion ? "" : "un"); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * setup Gbit PHYs |
| 166 | */ |
| 167 | int last_stage_init(void) |
| 168 | { |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 169 | ihs_fpga_t *fpga = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(0); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 170 | unsigned int k; |
| 171 | |
| 172 | miiphy_register(CONFIG_SYS_GBIT_MII_BUSNAME, |
| 173 | bb_miiphy_read, bb_miiphy_write); |
| 174 | |
| 175 | for (k = 0; k < 32; ++k) |
| 176 | configure_gbit_phy(k); |
| 177 | |
| 178 | /* take fpga serdes blocks out of reset */ |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 179 | out_le16(&fpga->quad_serdes_reset, 0); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
Dirk Eibach | 9a65957 | 2012-04-26 03:54:22 +0000 | [diff] [blame^] | 183 | |
| 184 | void gd405ep_init(void) |
| 185 | { |
| 186 | } |
| 187 | |
| 188 | void gd405ep_set_fpga_reset(unsigned state) |
| 189 | { |
| 190 | if (state) { |
| 191 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET); |
| 192 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET); |
| 193 | } else { |
| 194 | out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT); |
| 195 | out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void gd405ep_setup_hw(void) |
| 200 | { |
| 201 | /* |
| 202 | * set "startup-finished"-gpios |
| 203 | */ |
| 204 | gpio_write_bit(21, 0); |
| 205 | gpio_write_bit(22, 1); |
| 206 | } |
| 207 | |
| 208 | int gd405ep_get_fpga_done(unsigned fpga) |
| 209 | { |
| 210 | return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga); |
| 211 | } |