Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 |
Mario Six | b489358 | 2018-03-06 08:04:58 +0100 | [diff] [blame] | 4 | * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | 8e20188 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 9 | #include <flash.h> |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 10 | #include <hwconfig.h> |
| 11 | #include <i2c.h> |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 12 | #include <init.h> |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 13 | #include <spi.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame^] | 14 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 16 | #include <fdt_support.h> |
| 17 | #include <pci.h> |
| 18 | #include <mpc83xx.h> |
| 19 | #include <fsl_esdhc.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/fsl_serdes.h> |
| 22 | #include <asm/fsl_mpc83xx_serdes.h> |
| 23 | |
| 24 | #include "mpc8308.h" |
| 25 | |
| 26 | #include <gdsys_fpga.h> |
| 27 | |
| 28 | #include "../common/adv7611.h" |
| 29 | #include "../common/ch7301.h" |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 30 | #include "../common/dp501.h" |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 31 | #include "../common/ioep-fpga.h" |
| 32 | #include "../common/mclink.h" |
| 33 | #include "../common/osd.h" |
| 34 | #include "../common/phy.h" |
Dirk Eibach | 9459433 | 2015-10-28 11:46:36 +0100 | [diff] [blame] | 35 | #include "../common/fanctrl.h" |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 36 | |
| 37 | #include <pca953x.h> |
| 38 | #include <pca9698.h> |
| 39 | |
| 40 | #include <miiphy.h> |
| 41 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 42 | #define MAX_MUX_CHANNELS 2 |
| 43 | |
| 44 | enum { |
| 45 | MCFPGA_DONE = 1 << 0, |
| 46 | MCFPGA_INIT_N = 1 << 1, |
| 47 | MCFPGA_PROGRAM_N = 1 << 2, |
| 48 | MCFPGA_UPDATE_ENABLE_N = 1 << 3, |
| 49 | MCFPGA_RESET_N = 1 << 4, |
| 50 | }; |
| 51 | |
| 52 | enum { |
| 53 | GPIO_MDC = 1 << 14, |
| 54 | GPIO_MDIO = 1 << 15, |
| 55 | }; |
| 56 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 57 | uint mclink_fpgacount; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 58 | struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR; |
| 59 | |
| 60 | struct { |
| 61 | u8 bus; |
| 62 | u8 addr; |
| 63 | } strider_fans[] = CONFIG_STRIDER_FANS; |
| 64 | |
| 65 | int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data) |
| 66 | { |
| 67 | int res; |
| 68 | |
| 69 | switch (fpga) { |
| 70 | case 0: |
| 71 | out_le16(reg, data); |
| 72 | break; |
| 73 | default: |
| 74 | res = mclink_send(fpga - 1, regoff, data); |
| 75 | if (res < 0) { |
| 76 | printf("mclink_send reg %02lx data %04x returned %d\n", |
| 77 | regoff, data, res); |
| 78 | return res; |
| 79 | } |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data) |
| 87 | { |
| 88 | int res; |
| 89 | |
| 90 | switch (fpga) { |
| 91 | case 0: |
| 92 | *data = in_le16(reg); |
| 93 | break; |
| 94 | default: |
| 95 | if (fpga > mclink_fpgacount) |
| 96 | return -EINVAL; |
| 97 | res = mclink_receive(fpga - 1, regoff, data); |
| 98 | if (res < 0) { |
| 99 | printf("mclink_receive reg %02lx returned %d\n", |
| 100 | regoff, res); |
| 101 | return res; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | int checkboard(void) |
| 109 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 110 | char *s = env_get("serial#"); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 111 | bool hw_type_cat = pca9698_get_value(0x20, 18); |
| 112 | |
| 113 | puts("Board: "); |
| 114 | |
| 115 | printf("Strider %s", hw_type_cat ? "CAT" : "Fiber"); |
| 116 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 117 | if (s) { |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 118 | puts(", serial# "); |
| 119 | puts(s); |
| 120 | } |
| 121 | |
| 122 | puts("\n"); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 127 | int last_stage_init(void) |
| 128 | { |
| 129 | int slaves; |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 130 | uint k; |
| 131 | uint mux_ch; |
| 132 | uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e }; |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 133 | #ifdef CONFIG_STRIDER_CPU |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 134 | uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 }; |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 135 | #endif |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 136 | bool hw_type_cat = pca9698_get_value(0x20, 18); |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 137 | #ifdef CONFIG_STRIDER_CON_DP |
| 138 | bool is_dh = pca9698_get_value(0x20, 25); |
| 139 | #endif |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 140 | bool ch0_sgmii2_present; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 141 | |
| 142 | /* Turn on Analog Devices ADV7611 */ |
| 143 | pca9698_direction_output(0x20, 8, 0); |
| 144 | |
| 145 | /* Turn on Parade DP501 */ |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 146 | pca9698_direction_output(0x20, 10, 1); |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 147 | pca9698_direction_output(0x20, 11, 1); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 148 | |
| 149 | ch0_sgmii2_present = !pca9698_get_value(0x20, 37); |
| 150 | |
| 151 | /* wait for FPGA done, then reset FPGA */ |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 152 | for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 153 | uint ctr = 0; |
| 154 | uchar *mclink_controllers = mclink_controllers_dvi; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 155 | |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 156 | #ifdef CONFIG_STRIDER_CPU |
| 157 | if (i2c_probe(mclink_controllers[k])) { |
| 158 | mclink_controllers = mclink_controllers_dp; |
| 159 | if (i2c_probe(mclink_controllers[k])) |
| 160 | continue; |
| 161 | } |
| 162 | #else |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 163 | if (i2c_probe(mclink_controllers[k])) |
| 164 | continue; |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 165 | #endif |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 166 | while (!(pca953x_get_val(mclink_controllers[k]) |
| 167 | & MCFPGA_DONE)) { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 168 | mdelay(100); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 169 | if (ctr++ > 5) { |
| 170 | printf("no done for mclink_controller %d\n", k); |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0); |
| 176 | pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0); |
| 177 | udelay(10); |
| 178 | pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, |
| 179 | MCFPGA_RESET_N); |
| 180 | } |
| 181 | |
| 182 | if (hw_type_cat) { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 183 | int retval; |
| 184 | struct mii_dev *mdiodev = mdio_alloc(); |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 185 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 186 | if (!mdiodev) |
| 187 | return -ENOMEM; |
| 188 | strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN); |
| 189 | mdiodev->read = bb_miiphy_read; |
| 190 | mdiodev->write = bb_miiphy_write; |
| 191 | |
| 192 | retval = mdio_register(mdiodev); |
| 193 | if (retval < 0) |
| 194 | return retval; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 195 | for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) { |
| 196 | if ((mux_ch == 1) && !ch0_sgmii2_present) |
| 197 | continue; |
| 198 | |
| 199 | setup_88e1514(bb_miiphy_buses[0].name, mux_ch); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /* give slave-PLLs and Parade DP501 some time to be up and running */ |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 204 | mdelay(500); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 205 | |
| 206 | mclink_fpgacount = CONFIG_SYS_MCLINK_MAX; |
| 207 | slaves = mclink_probe(); |
| 208 | mclink_fpgacount = 0; |
| 209 | |
| 210 | ioep_fpga_print_info(0); |
| 211 | |
| 212 | if (!adv7611_probe(0)) |
| 213 | printf(" Advantiv ADV7611 HDMI Receiver\n"); |
| 214 | |
| 215 | #ifdef CONFIG_STRIDER_CON |
| 216 | if (ioep_fpga_has_osd(0)) |
| 217 | osd_probe(0); |
| 218 | #endif |
| 219 | |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 220 | #ifdef CONFIG_STRIDER_CON_DP |
| 221 | if (ioep_fpga_has_osd(0)) { |
| 222 | osd_probe(0); |
| 223 | if (is_dh) |
| 224 | osd_probe(4); |
| 225 | } |
| 226 | #endif |
| 227 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 228 | #ifdef CONFIG_STRIDER_CPU |
| 229 | ch7301_probe(0, false); |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 230 | dp501_probe(0, false); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 231 | #endif |
| 232 | |
| 233 | if (slaves <= 0) |
| 234 | return 0; |
| 235 | |
| 236 | mclink_fpgacount = slaves; |
| 237 | |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 238 | #ifdef CONFIG_STRIDER_CPU |
| 239 | /* get ADV7611 out of reset, power up DP501, give some time to wakeup */ |
| 240 | for (k = 1; k <= slaves; ++k) |
| 241 | FPGA_SET_REG(k, extended_control, 0x10); /* enable video */ |
| 242 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 243 | mdelay(500); |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 244 | #endif |
| 245 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 246 | for (k = 1; k <= slaves; ++k) { |
| 247 | ioep_fpga_print_info(k); |
| 248 | #ifdef CONFIG_STRIDER_CON |
| 249 | if (ioep_fpga_has_osd(k)) |
| 250 | osd_probe(k); |
| 251 | #endif |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 252 | #ifdef CONFIG_STRIDER_CON_DP |
| 253 | if (ioep_fpga_has_osd(k)) { |
| 254 | osd_probe(k); |
| 255 | if (is_dh) |
| 256 | osd_probe(k + 4); |
| 257 | } |
| 258 | #endif |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 259 | #ifdef CONFIG_STRIDER_CPU |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 260 | if (!adv7611_probe(k)) |
| 261 | printf(" Advantiv ADV7611 HDMI Receiver\n"); |
| 262 | ch7301_probe(k, false); |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 263 | dp501_probe(k, false); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 264 | #endif |
| 265 | if (hw_type_cat) { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 266 | int retval; |
| 267 | struct mii_dev *mdiodev = mdio_alloc(); |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 268 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 269 | if (!mdiodev) |
| 270 | return -ENOMEM; |
| 271 | strncpy(mdiodev->name, bb_miiphy_buses[k].name, |
| 272 | MDIO_NAME_LEN); |
| 273 | mdiodev->read = bb_miiphy_read; |
| 274 | mdiodev->write = bb_miiphy_write; |
| 275 | |
| 276 | retval = mdio_register(mdiodev); |
| 277 | if (retval < 0) |
| 278 | return retval; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 279 | setup_88e1514(bb_miiphy_buses[k].name, 0); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) { |
| 284 | i2c_set_bus_num(strider_fans[k].bus); |
| 285 | init_fan_controller(strider_fans[k].addr); |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * provide access to fpga gpios (for I2C bitbang) |
| 293 | * (these may look all too simple but make iocon.h much more readable) |
| 294 | */ |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 295 | void fpga_gpio_set(uint bus, int pin) |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 296 | { |
| 297 | FPGA_SET_REG(bus, gpio.set, pin); |
| 298 | } |
| 299 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 300 | void fpga_gpio_clear(uint bus, int pin) |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 301 | { |
| 302 | FPGA_SET_REG(bus, gpio.clear, pin); |
| 303 | } |
| 304 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 305 | int fpga_gpio_get(uint bus, int pin) |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 306 | { |
| 307 | u16 val; |
| 308 | |
| 309 | FPGA_GET_REG(bus, gpio.read, &val); |
| 310 | |
| 311 | return val & pin; |
| 312 | } |
| 313 | |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_STRIDER_CON_DP |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 315 | void fpga_control_set(uint bus, int pin) |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 316 | { |
| 317 | u16 val; |
| 318 | |
| 319 | FPGA_GET_REG(bus, control, &val); |
| 320 | FPGA_SET_REG(bus, control, val | pin); |
| 321 | } |
| 322 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 323 | void fpga_control_clear(uint bus, int pin) |
Dirk Eibach | 3c6a509 | 2016-06-02 09:05:41 +0200 | [diff] [blame] | 324 | { |
| 325 | u16 val; |
| 326 | |
| 327 | FPGA_GET_REG(bus, control, &val); |
| 328 | FPGA_SET_REG(bus, control, val & ~pin); |
| 329 | } |
| 330 | #endif |
| 331 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 332 | void mpc8308_init(void) |
| 333 | { |
| 334 | pca9698_direction_output(0x20, 26, 1); |
| 335 | } |
| 336 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 337 | void mpc8308_set_fpga_reset(uint state) |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 338 | { |
| 339 | pca9698_set_value(0x20, 26, state ? 0 : 1); |
| 340 | } |
| 341 | |
| 342 | void mpc8308_setup_hw(void) |
| 343 | { |
| 344 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
| 345 | |
| 346 | /* |
| 347 | * set "startup-finished"-gpios |
| 348 | */ |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 349 | setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12)); |
Mario Six | ae0feaa | 2019-03-29 10:18:07 +0100 | [diff] [blame] | 350 | setbits_gpio0_out(BIT(31 - 12)); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 353 | int mpc8308_get_fpga_done(uint fpga) |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 354 | { |
| 355 | return pca9698_get_value(0x20, 20); |
| 356 | } |
| 357 | |
| 358 | #ifdef CONFIG_FSL_ESDHC |
| 359 | int board_mmc_init(bd_t *bd) |
| 360 | { |
| 361 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
| 362 | sysconf83xx_t *sysconf = &immr->sysconf; |
| 363 | |
| 364 | /* Enable cache snooping in eSDHC system configuration register */ |
| 365 | out_be32(&sysconf->sdhccr, 0x02000000); |
| 366 | |
| 367 | return fsl_esdhc_mmc_init(bd); |
| 368 | } |
| 369 | #endif |
| 370 | |
| 371 | static struct pci_region pcie_regions_0[] = { |
| 372 | { |
| 373 | .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, |
| 374 | .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, |
| 375 | .size = CONFIG_SYS_PCIE1_MEM_SIZE, |
| 376 | .flags = PCI_REGION_MEM, |
| 377 | }, |
| 378 | { |
| 379 | .bus_start = CONFIG_SYS_PCIE1_IO_BASE, |
| 380 | .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, |
| 381 | .size = CONFIG_SYS_PCIE1_IO_SIZE, |
| 382 | .flags = PCI_REGION_IO, |
| 383 | }, |
| 384 | }; |
| 385 | |
| 386 | void pci_init_board(void) |
| 387 | { |
| 388 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
| 389 | sysconf83xx_t *sysconf = &immr->sysconf; |
| 390 | law83xx_t *pcie_law = sysconf->pcielaw; |
| 391 | struct pci_region *pcie_reg[] = { pcie_regions_0 }; |
| 392 | |
| 393 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX, |
| 394 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 395 | |
| 396 | /* Deassert the resets in the control register */ |
| 397 | out_be32(&sysconf->pecr1, 0xE0008000); |
| 398 | udelay(2000); |
| 399 | |
| 400 | /* Configure PCI Express Local Access Windows */ |
| 401 | out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); |
| 402 | out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 403 | |
| 404 | mpc83xx_pcie_init(1, pcie_reg); |
| 405 | } |
| 406 | |
| 407 | ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info) |
| 408 | { |
| 409 | info->portwidth = FLASH_CFI_16BIT; |
| 410 | info->chipwidth = FLASH_CFI_BY16; |
| 411 | info->interface = FLASH_CFI_X16; |
| 412 | return 1; |
| 413 | } |
| 414 | |
| 415 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 416 | int ft_board_setup(void *blob, bd_t *bd) |
| 417 | { |
| 418 | ft_cpu_setup(blob, bd); |
Sriram Dash | 9fd465c | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 419 | fsl_fdt_fixup_dr_usb(blob, bd); |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 420 | fdt_fixup_esdhc(blob, bd); |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | #endif |
| 425 | |
| 426 | /* |
| 427 | * FPGA MII bitbang implementation |
| 428 | */ |
| 429 | |
| 430 | struct fpga_mii { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 431 | uint fpga; |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 432 | int mdio; |
| 433 | } fpga_mii[] = { |
| 434 | { 0, 1}, |
| 435 | { 1, 1}, |
| 436 | { 2, 1}, |
| 437 | { 3, 1}, |
| 438 | }; |
| 439 | |
| 440 | static int mii_dummy_init(struct bb_miiphy_bus *bus) |
| 441 | { |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int mii_mdio_active(struct bb_miiphy_bus *bus) |
| 446 | { |
| 447 | struct fpga_mii *fpga_mii = bus->priv; |
| 448 | |
| 449 | if (fpga_mii->mdio) |
| 450 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 451 | else |
| 452 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int mii_mdio_tristate(struct bb_miiphy_bus *bus) |
| 458 | { |
| 459 | struct fpga_mii *fpga_mii = bus->priv; |
| 460 | |
| 461 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int mii_set_mdio(struct bb_miiphy_bus *bus, int v) |
| 467 | { |
| 468 | struct fpga_mii *fpga_mii = bus->priv; |
| 469 | |
| 470 | if (v) |
| 471 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO); |
| 472 | else |
| 473 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO); |
| 474 | |
| 475 | fpga_mii->mdio = v; |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v) |
| 481 | { |
| 482 | u16 gpio; |
| 483 | struct fpga_mii *fpga_mii = bus->priv; |
| 484 | |
| 485 | FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio); |
| 486 | |
| 487 | *v = ((gpio & GPIO_MDIO) != 0); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static int mii_set_mdc(struct bb_miiphy_bus *bus, int v) |
| 493 | { |
| 494 | struct fpga_mii *fpga_mii = bus->priv; |
| 495 | |
| 496 | if (v) |
| 497 | FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC); |
| 498 | else |
| 499 | FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static int mii_delay(struct bb_miiphy_bus *bus) |
| 505 | { |
| 506 | udelay(1); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | struct bb_miiphy_bus bb_miiphy_buses[] = { |
| 512 | { |
| 513 | .name = "board0", |
| 514 | .init = mii_dummy_init, |
| 515 | .mdio_active = mii_mdio_active, |
| 516 | .mdio_tristate = mii_mdio_tristate, |
| 517 | .set_mdio = mii_set_mdio, |
| 518 | .get_mdio = mii_get_mdio, |
| 519 | .set_mdc = mii_set_mdc, |
| 520 | .delay = mii_delay, |
| 521 | .priv = &fpga_mii[0], |
| 522 | }, |
| 523 | { |
| 524 | .name = "board1", |
| 525 | .init = mii_dummy_init, |
| 526 | .mdio_active = mii_mdio_active, |
| 527 | .mdio_tristate = mii_mdio_tristate, |
| 528 | .set_mdio = mii_set_mdio, |
| 529 | .get_mdio = mii_get_mdio, |
| 530 | .set_mdc = mii_set_mdc, |
| 531 | .delay = mii_delay, |
| 532 | .priv = &fpga_mii[1], |
| 533 | }, |
| 534 | { |
| 535 | .name = "board2", |
| 536 | .init = mii_dummy_init, |
| 537 | .mdio_active = mii_mdio_active, |
| 538 | .mdio_tristate = mii_mdio_tristate, |
| 539 | .set_mdio = mii_set_mdio, |
| 540 | .get_mdio = mii_get_mdio, |
| 541 | .set_mdc = mii_set_mdc, |
| 542 | .delay = mii_delay, |
| 543 | .priv = &fpga_mii[2], |
| 544 | }, |
| 545 | { |
| 546 | .name = "board3", |
| 547 | .init = mii_dummy_init, |
| 548 | .mdio_active = mii_mdio_active, |
| 549 | .mdio_tristate = mii_mdio_tristate, |
| 550 | .set_mdio = mii_set_mdio, |
| 551 | .get_mdio = mii_get_mdio, |
| 552 | .set_mdc = mii_set_mdc, |
| 553 | .delay = mii_delay, |
| 554 | .priv = &fpga_mii[3], |
| 555 | }, |
| 556 | }; |
| 557 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 558 | int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); |