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