1 /* 2 * (C) Copyright 2010 3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <miiphy.h> 10 11 #include <asm/io.h> 12 13 struct io_bb_pinset { 14 int mdio; 15 int mdc; 16 }; 17 18 static int io_bb_mii_init(struct bb_miiphy_bus *bus) 19 { 20 return 0; 21 } 22 23 static int io_bb_mdio_active(struct bb_miiphy_bus *bus) 24 { 25 struct io_bb_pinset *pins = bus->priv; 26 27 out_be32((void *)GPIO0_TCR, 28 in_be32((void *)GPIO0_TCR) | pins->mdio); 29 30 return 0; 31 } 32 33 static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus) 34 { 35 struct io_bb_pinset *pins = bus->priv; 36 37 out_be32((void *)GPIO0_TCR, 38 in_be32((void *)GPIO0_TCR) & ~pins->mdio); 39 40 return 0; 41 } 42 43 static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v) 44 { 45 struct io_bb_pinset *pins = bus->priv; 46 47 if (v) 48 out_be32((void *)GPIO0_OR, 49 in_be32((void *)GPIO0_OR) | pins->mdio); 50 else 51 out_be32((void *)GPIO0_OR, 52 in_be32((void *)GPIO0_OR) & ~pins->mdio); 53 54 return 0; 55 } 56 57 static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) 58 { 59 struct io_bb_pinset *pins = bus->priv; 60 61 *v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0); 62 63 return 0; 64 } 65 66 static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v) 67 { 68 struct io_bb_pinset *pins = bus->priv; 69 70 if (v) 71 out_be32((void *)GPIO0_OR, 72 in_be32((void *)GPIO0_OR) | pins->mdc); 73 else 74 out_be32((void *)GPIO0_OR, 75 in_be32((void *)GPIO0_OR) & ~pins->mdc); 76 77 return 0; 78 } 79 80 static int io_bb_delay(struct bb_miiphy_bus *bus) 81 { 82 udelay(1); 83 84 return 0; 85 } 86 87 struct io_bb_pinset io_bb_pinsets[] = { 88 { 89 .mdio = CONFIG_SYS_MDIO_PIN, 90 .mdc = CONFIG_SYS_MDC_PIN, 91 }, 92 #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME 93 { 94 .mdio = CONFIG_SYS_MDIO1_PIN, 95 .mdc = CONFIG_SYS_MDC1_PIN, 96 }, 97 #endif 98 }; 99 100 struct bb_miiphy_bus bb_miiphy_buses[] = { 101 { 102 .name = CONFIG_SYS_GBIT_MII_BUSNAME, 103 .init = io_bb_mii_init, 104 .mdio_active = io_bb_mdio_active, 105 .mdio_tristate = io_bb_mdio_tristate, 106 .set_mdio = io_bb_set_mdio, 107 .get_mdio = io_bb_get_mdio, 108 .set_mdc = io_bb_set_mdc, 109 .delay = io_bb_delay, 110 .priv = &io_bb_pinsets[0], 111 }, 112 #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME 113 { 114 .name = CONFIG_SYS_GBIT_MII1_BUSNAME, 115 .init = io_bb_mii_init, 116 .mdio_active = io_bb_mdio_active, 117 .mdio_tristate = io_bb_mdio_tristate, 118 .set_mdio = io_bb_set_mdio, 119 .get_mdio = io_bb_get_mdio, 120 .set_mdc = io_bb_set_mdc, 121 .delay = io_bb_delay, 122 .priv = &io_bb_pinsets[1], 123 }, 124 #endif 125 }; 126 127 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / 128 sizeof(bb_miiphy_buses[0]); 129