Lines Matching +full:mdio +full:- +full:parent +full:- +full:bus

1 // SPDX-License-Identifier: GPL-2.0
3 * MDIO I2C bridge
5 * Copyright (C) 2015-2016 Russell King
14 #include <linux/mdio/mdio-i2c.h>
19 * I2C bus addresses 0x50 and 0x51 are normally an EEPROM, which is
33 static int i2c_mii_read_default_c45(struct mii_bus *bus, int phy_id, int devad, in i2c_mii_read_default_c45() argument
36 struct i2c_adapter *i2c = bus->priv; in i2c_mii_read_default_c45()
54 msgs[0].len = p - addr; in i2c_mii_read_default_c45()
68 static int i2c_mii_write_default_c45(struct mii_bus *bus, int phy_id, in i2c_mii_write_default_c45() argument
71 struct i2c_adapter *i2c = bus->priv; in i2c_mii_write_default_c45()
90 msg.len = p - data; in i2c_mii_write_default_c45()
98 static int i2c_mii_read_default_c22(struct mii_bus *bus, int phy_id, int reg) in i2c_mii_read_default_c22() argument
100 return i2c_mii_read_default_c45(bus, phy_id, -1, reg); in i2c_mii_read_default_c22()
103 static int i2c_mii_write_default_c22(struct mii_bus *bus, int phy_id, int reg, in i2c_mii_write_default_c22() argument
106 return i2c_mii_write_default_c45(bus, phy_id, -1, reg, val); in i2c_mii_write_default_c22()
114 * ------- ---- -------- -----------
142 return -EIO; in __i2c_transfer_err()
185 * 1. lock the bus
190 * 6. unlock the bus
193 * unfortunately tests show that this does not work :-( Changed SFP_PAGE does
205 ret = __i2c_rollball_get_page(i2c, msgs->addr, &saved_page); in i2c_transfer_rollball()
209 /* change to RollBall MDIO page */ in i2c_transfer_rollball()
210 ret = __i2c_rollball_set_page(i2c, msgs->addr, SFP_PAGE_ROLLBALL_MDIO); in i2c_transfer_rollball()
220 ret = __i2c_rollball_set_page(i2c, msgs->addr, saved_page); in i2c_transfer_rollball()
228 static int i2c_rollball_mii_poll(struct mii_bus *bus, int bus_addr, u8 *buf, in i2c_rollball_mii_poll() argument
231 struct i2c_adapter *i2c = bus->priv; in i2c_rollball_mii_poll()
264 } while (i-- > 0); in i2c_rollball_mii_poll()
266 dev_dbg(&bus->dev, "poll timed out\n"); in i2c_rollball_mii_poll()
268 return -ETIMEDOUT; in i2c_rollball_mii_poll()
271 static int i2c_rollball_mii_cmd(struct mii_bus *bus, int bus_addr, u8 cmd, in i2c_rollball_mii_cmd() argument
274 struct i2c_adapter *i2c = bus->priv; in i2c_rollball_mii_cmd()
294 static int i2c_mii_read_rollball(struct mii_bus *bus, int phy_id, int devad, in i2c_mii_read_rollball() argument
310 ret = i2c_rollball_mii_cmd(bus, bus_addr, ROLLBALL_CMD_READ, buf, in i2c_mii_read_rollball()
315 ret = i2c_rollball_mii_poll(bus, bus_addr, res, sizeof(res)); in i2c_mii_read_rollball()
316 if (ret == -ETIMEDOUT) in i2c_mii_read_rollball()
326 static int i2c_mii_write_rollball(struct mii_bus *bus, int phy_id, int devad, in i2c_mii_write_rollball() argument
343 ret = i2c_rollball_mii_cmd(bus, bus_addr, ROLLBALL_CMD_WRITE, buf, in i2c_mii_write_rollball()
348 ret = i2c_rollball_mii_poll(bus, bus_addr, NULL, 0); in i2c_mii_write_rollball()
376 return -EIO; in i2c_mii_init_rollball()
381 struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c, in mdio_i2c_alloc() argument
388 return ERR_PTR(-EINVAL); in mdio_i2c_alloc()
392 return ERR_PTR(-ENOMEM); in mdio_i2c_alloc()
394 snprintf(mii->id, MII_BUS_ID_SIZE, "i2c:%s", dev_name(parent)); in mdio_i2c_alloc()
395 mii->parent = parent; in mdio_i2c_alloc()
396 mii->priv = i2c; in mdio_i2c_alloc()
402 dev_err(parent, in mdio_i2c_alloc()
403 "Cannot initialize RollBall MDIO I2C protocol: %d\n", in mdio_i2c_alloc()
409 mii->read_c45 = i2c_mii_read_rollball; in mdio_i2c_alloc()
410 mii->write_c45 = i2c_mii_write_rollball; in mdio_i2c_alloc()
413 mii->read = i2c_mii_read_default_c22; in mdio_i2c_alloc()
414 mii->write = i2c_mii_write_default_c22; in mdio_i2c_alloc()
415 mii->read_c45 = i2c_mii_read_default_c45; in mdio_i2c_alloc()
416 mii->write_c45 = i2c_mii_write_default_c45; in mdio_i2c_alloc()
425 MODULE_DESCRIPTION("MDIO I2C bridge library");