Lines Matching +full:mdio +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2004-2013 Synopsys, Inc. (www.synopsys.com)
5 * MDIO implementation for ARC EMAC
15 /* Number of seconds we wait for "MDIO complete" flag to appear */
19 * arc_mdio_complete_wait - Waits until MDIO transaction is completed.
22 * returns: 0 on success, -ETIMEDOUT on a timeout.
34 /* Reset "MDIO complete" flag */ in arc_mdio_complete_wait()
42 return -ETIMEDOUT; in arc_mdio_complete_wait()
46 * arc_mdio_read - MDIO interface read function.
47 * @bus: Pointer to MII bus structure.
51 * returns: The register contents on success, -ETIMEDOUT on a timeout.
56 static int arc_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num) in arc_mdio_read() argument
58 struct arc_emac_priv *priv = bus->priv; in arc_mdio_read()
71 dev_dbg(priv->dev, "arc_mdio_read(phy_addr=%i, reg_num=%x) = %x\n", in arc_mdio_read()
78 * arc_mdio_write - MDIO interface write function.
79 * @bus: Pointer to MII bus structure.
84 * returns: 0 on success, -ETIMEDOUT on a timeout.
88 static int arc_mdio_write(struct mii_bus *bus, int phy_addr, in arc_mdio_write() argument
91 struct arc_emac_priv *priv = bus->priv; in arc_mdio_write()
93 dev_dbg(priv->dev, in arc_mdio_write()
105 * @bus: points to the mii_bus structure
106 * Description: reset the MII bus
108 static int arc_mdio_reset(struct mii_bus *bus) in arc_mdio_reset() argument
110 struct arc_emac_priv *priv = bus->priv; in arc_mdio_reset()
111 struct arc_emac_mdio_bus_data *data = &priv->bus_data; in arc_mdio_reset()
113 if (data->reset_gpio) { in arc_mdio_reset()
114 gpiod_set_value_cansleep(data->reset_gpio, 1); in arc_mdio_reset()
115 msleep(data->msec); in arc_mdio_reset()
116 gpiod_set_value_cansleep(data->reset_gpio, 0); in arc_mdio_reset()
123 * arc_mdio_probe - MDIO probe function.
126 * returns: 0 on success, -ENOMEM when mdiobus_alloc
127 * (to allocate memory for MII bus structure) fails.
129 * Sets up and registers the MDIO interface.
133 struct arc_emac_mdio_bus_data *data = &priv->bus_data; in arc_mdio_probe()
134 struct device_node *np = priv->dev->of_node; in arc_mdio_probe()
135 const char *name = "Synopsys MII Bus"; in arc_mdio_probe()
137 struct mii_bus *bus; in arc_mdio_probe() local
140 bus = mdiobus_alloc(); in arc_mdio_probe()
141 if (!bus) in arc_mdio_probe()
142 return -ENOMEM; in arc_mdio_probe()
144 priv->bus = bus; in arc_mdio_probe()
145 bus->priv = priv; in arc_mdio_probe()
146 bus->parent = priv->dev; in arc_mdio_probe()
147 bus->name = name; in arc_mdio_probe()
148 bus->read = &arc_mdio_read; in arc_mdio_probe()
149 bus->write = &arc_mdio_write; in arc_mdio_probe()
150 bus->reset = &arc_mdio_reset; in arc_mdio_probe()
152 /* optional reset-related properties */ in arc_mdio_probe()
153 data->reset_gpio = devm_gpiod_get_optional(priv->dev, "phy-reset", in arc_mdio_probe()
155 if (IS_ERR(data->reset_gpio)) { in arc_mdio_probe()
156 mdiobus_free(bus); in arc_mdio_probe()
157 return dev_err_probe(priv->dev, PTR_ERR(data->reset_gpio), in arc_mdio_probe()
161 of_property_read_u32(np, "phy-reset-duration", &data->msec); in arc_mdio_probe()
163 if (data->msec > 1000) in arc_mdio_probe()
164 data->msec = 1; in arc_mdio_probe()
166 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", bus->name); in arc_mdio_probe()
168 /* Backwards compatibility for EMAC nodes without MDIO subnode. */ in arc_mdio_probe()
169 mdio_node = of_get_child_by_name(np, "mdio"); in arc_mdio_probe()
173 error = of_mdiobus_register(bus, mdio_node); in arc_mdio_probe()
176 mdiobus_free(bus); in arc_mdio_probe()
177 return dev_err_probe(priv->dev, error, in arc_mdio_probe()
178 "cannot register MDIO bus %s\n", name); in arc_mdio_probe()
185 * arc_mdio_remove - MDIO remove function.
188 * Unregisters the MDIO and frees any associate memory for MII bus.
192 mdiobus_unregister(priv->bus); in arc_mdio_remove()
193 mdiobus_free(priv->bus); in arc_mdio_remove()
194 priv->bus = NULL; in arc_mdio_remove()