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