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