Lines Matching +full:bus +full:- +full:addr

1 // SPDX-License-Identifier: GPL-2.0
4 #include <linux/pcs/pcs-xpcs.h>
10 int sja1105_pcs_mdio_read_c45(struct mii_bus *bus, int phy, int mmd, int reg) in sja1105_pcs_mdio_read_c45() argument
12 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_pcs_mdio_read_c45()
13 struct sja1105_private *priv = mdio_priv->priv; in sja1105_pcs_mdio_read_c45()
14 u64 addr; in sja1105_pcs_mdio_read_c45() local
18 addr = (mmd << 16) | reg; in sja1105_pcs_mdio_read_c45()
28 rc = sja1105_xfer_u32(priv, SPI_READ, addr, &tmp, NULL); in sja1105_pcs_mdio_read_c45()
35 int sja1105_pcs_mdio_write_c45(struct mii_bus *bus, int phy, int mmd, in sja1105_pcs_mdio_write_c45() argument
38 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_pcs_mdio_write_c45()
39 struct sja1105_private *priv = mdio_priv->priv; in sja1105_pcs_mdio_write_c45()
40 u64 addr; in sja1105_pcs_mdio_write_c45() local
43 addr = (mmd << 16) | reg; in sja1105_pcs_mdio_write_c45()
47 return -EINVAL; in sja1105_pcs_mdio_write_c45()
49 return sja1105_xfer_u32(priv, SPI_WRITE, addr, &tmp, NULL); in sja1105_pcs_mdio_write_c45()
52 int sja1110_pcs_mdio_read_c45(struct mii_bus *bus, int phy, int mmd, int reg) in sja1110_pcs_mdio_read_c45() argument
54 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1110_pcs_mdio_read_c45()
55 struct sja1105_private *priv = mdio_priv->priv; in sja1110_pcs_mdio_read_c45()
56 const struct sja1105_regs *regs = priv->info->regs; in sja1110_pcs_mdio_read_c45()
58 u64 addr; in sja1110_pcs_mdio_read_c45() local
62 if (regs->pcs_base[phy] == SJA1105_RSV_ADDR) in sja1110_pcs_mdio_read_c45()
63 return -ENODEV; in sja1110_pcs_mdio_read_c45()
65 addr = (mmd << 16) | reg; in sja1110_pcs_mdio_read_c45()
72 bank = addr >> 8; in sja1110_pcs_mdio_read_c45()
73 offset = addr & GENMASK(7, 0); in sja1110_pcs_mdio_read_c45()
79 return -ENODEV; in sja1110_pcs_mdio_read_c45()
84 regs->pcs_base[phy] + SJA1110_PCS_BANK_REG, in sja1110_pcs_mdio_read_c45()
89 rc = sja1105_xfer_u32(priv, SPI_READ, regs->pcs_base[phy] + offset, in sja1110_pcs_mdio_read_c45()
97 int sja1110_pcs_mdio_write_c45(struct mii_bus *bus, int phy, int mmd, int reg, in sja1110_pcs_mdio_write_c45() argument
100 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1110_pcs_mdio_write_c45()
101 struct sja1105_private *priv = mdio_priv->priv; in sja1110_pcs_mdio_write_c45()
102 const struct sja1105_regs *regs = priv->info->regs; in sja1110_pcs_mdio_write_c45()
104 u64 addr; in sja1110_pcs_mdio_write_c45() local
108 if (regs->pcs_base[phy] == SJA1105_RSV_ADDR) in sja1110_pcs_mdio_write_c45()
109 return -ENODEV; in sja1110_pcs_mdio_write_c45()
111 addr = (mmd << 16) | reg; in sja1110_pcs_mdio_write_c45()
113 bank = addr >> 8; in sja1110_pcs_mdio_write_c45()
114 offset = addr & GENMASK(7, 0); in sja1110_pcs_mdio_write_c45()
120 return -ENODEV; in sja1110_pcs_mdio_write_c45()
125 regs->pcs_base[phy] + SJA1110_PCS_BANK_REG, in sja1110_pcs_mdio_write_c45()
132 return sja1105_xfer_u32(priv, SPI_WRITE, regs->pcs_base[phy] + offset, in sja1110_pcs_mdio_write_c45()
147 const struct sja1105_regs *regs = priv->info->regs; in sja1105_base_t1_encode_addr()
149 return regs->mdio_100base_t1 | (phy << 7) | (op << 5) | (xad << 0); in sja1105_base_t1_encode_addr()
152 static int sja1105_base_t1_mdio_read_c22(struct mii_bus *bus, int phy, int reg) in sja1105_base_t1_mdio_read_c22() argument
154 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_t1_mdio_read_c22()
155 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_t1_mdio_read_c22()
156 u64 addr; in sja1105_base_t1_mdio_read_c22() local
160 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C22, reg & 0x1f); in sja1105_base_t1_mdio_read_c22()
162 rc = sja1105_xfer_u32(priv, SPI_READ, addr, &tmp, NULL); in sja1105_base_t1_mdio_read_c22()
169 static int sja1105_base_t1_mdio_read_c45(struct mii_bus *bus, int phy, in sja1105_base_t1_mdio_read_c45() argument
172 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_t1_mdio_read_c45()
173 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_t1_mdio_read_c45()
174 u64 addr; in sja1105_base_t1_mdio_read_c45() local
178 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C45_ADDR, mmd); in sja1105_base_t1_mdio_read_c45()
180 rc = sja1105_xfer_u32(priv, SPI_WRITE, addr, &reg, NULL); in sja1105_base_t1_mdio_read_c45()
184 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C45_DATA, mmd); in sja1105_base_t1_mdio_read_c45()
186 rc = sja1105_xfer_u32(priv, SPI_READ, addr, &tmp, NULL); in sja1105_base_t1_mdio_read_c45()
193 static int sja1105_base_t1_mdio_write_c22(struct mii_bus *bus, int phy, int reg, in sja1105_base_t1_mdio_write_c22() argument
196 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_t1_mdio_write_c22()
197 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_t1_mdio_write_c22()
198 u64 addr; in sja1105_base_t1_mdio_write_c22() local
201 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C22, reg & 0x1f); in sja1105_base_t1_mdio_write_c22()
205 return sja1105_xfer_u32(priv, SPI_WRITE, addr, &tmp, NULL); in sja1105_base_t1_mdio_write_c22()
208 static int sja1105_base_t1_mdio_write_c45(struct mii_bus *bus, int phy, in sja1105_base_t1_mdio_write_c45() argument
211 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_t1_mdio_write_c45()
212 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_t1_mdio_write_c45()
213 u64 addr; in sja1105_base_t1_mdio_write_c45() local
217 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C45_ADDR, mmd); in sja1105_base_t1_mdio_write_c45()
219 rc = sja1105_xfer_u32(priv, SPI_WRITE, addr, &reg, NULL); in sja1105_base_t1_mdio_write_c45()
223 addr = sja1105_base_t1_encode_addr(priv, phy, SJA1105_C45_DATA, mmd); in sja1105_base_t1_mdio_write_c45()
227 return sja1105_xfer_u32(priv, SPI_WRITE, addr, &tmp, NULL); in sja1105_base_t1_mdio_write_c45()
230 static int sja1105_base_tx_mdio_read(struct mii_bus *bus, int phy, int reg) in sja1105_base_tx_mdio_read() argument
232 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_tx_mdio_read()
233 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_tx_mdio_read()
234 const struct sja1105_regs *regs = priv->info->regs; in sja1105_base_tx_mdio_read()
238 rc = sja1105_xfer_u32(priv, SPI_READ, regs->mdio_100base_tx + reg, in sja1105_base_tx_mdio_read()
246 static int sja1105_base_tx_mdio_write(struct mii_bus *bus, int phy, int reg, in sja1105_base_tx_mdio_write() argument
249 struct sja1105_mdio_private *mdio_priv = bus->priv; in sja1105_base_tx_mdio_write()
250 struct sja1105_private *priv = mdio_priv->priv; in sja1105_base_tx_mdio_write()
251 const struct sja1105_regs *regs = priv->info->regs; in sja1105_base_tx_mdio_write()
254 return sja1105_xfer_u32(priv, SPI_WRITE, regs->mdio_100base_tx + reg, in sja1105_base_tx_mdio_write()
263 struct mii_bus *bus; in sja1105_mdiobus_base_tx_register() local
266 np = of_get_compatible_child(mdio_node, "nxp,sja1110-base-tx-mdio"); in sja1105_mdiobus_base_tx_register()
273 bus = mdiobus_alloc_size(sizeof(*mdio_priv)); in sja1105_mdiobus_base_tx_register()
274 if (!bus) { in sja1105_mdiobus_base_tx_register()
275 rc = -ENOMEM; in sja1105_mdiobus_base_tx_register()
279 bus->name = "SJA1110 100base-TX MDIO bus"; in sja1105_mdiobus_base_tx_register()
280 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-base-tx", in sja1105_mdiobus_base_tx_register()
281 dev_name(priv->ds->dev)); in sja1105_mdiobus_base_tx_register()
282 bus->read = sja1105_base_tx_mdio_read; in sja1105_mdiobus_base_tx_register()
283 bus->write = sja1105_base_tx_mdio_write; in sja1105_mdiobus_base_tx_register()
284 bus->parent = priv->ds->dev; in sja1105_mdiobus_base_tx_register()
285 mdio_priv = bus->priv; in sja1105_mdiobus_base_tx_register()
286 mdio_priv->priv = priv; in sja1105_mdiobus_base_tx_register()
288 rc = of_mdiobus_register(bus, np); in sja1105_mdiobus_base_tx_register()
290 mdiobus_free(bus); in sja1105_mdiobus_base_tx_register()
294 priv->mdio_base_tx = bus; in sja1105_mdiobus_base_tx_register()
304 if (!priv->mdio_base_tx) in sja1105_mdiobus_base_tx_unregister()
307 mdiobus_unregister(priv->mdio_base_tx); in sja1105_mdiobus_base_tx_unregister()
308 mdiobus_free(priv->mdio_base_tx); in sja1105_mdiobus_base_tx_unregister()
309 priv->mdio_base_tx = NULL; in sja1105_mdiobus_base_tx_unregister()
317 struct mii_bus *bus; in sja1105_mdiobus_base_t1_register() local
320 np = of_get_compatible_child(mdio_node, "nxp,sja1110-base-t1-mdio"); in sja1105_mdiobus_base_t1_register()
327 bus = mdiobus_alloc_size(sizeof(*mdio_priv)); in sja1105_mdiobus_base_t1_register()
328 if (!bus) { in sja1105_mdiobus_base_t1_register()
329 rc = -ENOMEM; in sja1105_mdiobus_base_t1_register()
333 bus->name = "SJA1110 100base-T1 MDIO bus"; in sja1105_mdiobus_base_t1_register()
334 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-base-t1", in sja1105_mdiobus_base_t1_register()
335 dev_name(priv->ds->dev)); in sja1105_mdiobus_base_t1_register()
336 bus->read = sja1105_base_t1_mdio_read_c22; in sja1105_mdiobus_base_t1_register()
337 bus->write = sja1105_base_t1_mdio_write_c22; in sja1105_mdiobus_base_t1_register()
338 bus->read_c45 = sja1105_base_t1_mdio_read_c45; in sja1105_mdiobus_base_t1_register()
339 bus->write_c45 = sja1105_base_t1_mdio_write_c45; in sja1105_mdiobus_base_t1_register()
340 bus->parent = priv->ds->dev; in sja1105_mdiobus_base_t1_register()
341 mdio_priv = bus->priv; in sja1105_mdiobus_base_t1_register()
342 mdio_priv->priv = priv; in sja1105_mdiobus_base_t1_register()
344 rc = of_mdiobus_register(bus, np); in sja1105_mdiobus_base_t1_register()
346 mdiobus_free(bus); in sja1105_mdiobus_base_t1_register()
350 priv->mdio_base_t1 = bus; in sja1105_mdiobus_base_t1_register()
360 if (!priv->mdio_base_t1) in sja1105_mdiobus_base_t1_unregister()
363 mdiobus_unregister(priv->mdio_base_t1); in sja1105_mdiobus_base_t1_unregister()
364 mdiobus_free(priv->mdio_base_t1); in sja1105_mdiobus_base_t1_unregister()
365 priv->mdio_base_t1 = NULL; in sja1105_mdiobus_base_t1_unregister()
371 struct dsa_switch *ds = priv->ds; in sja1105_mdiobus_pcs_register()
372 struct mii_bus *bus; in sja1105_mdiobus_pcs_register() local
376 if (!priv->info->pcs_mdio_read_c45 || !priv->info->pcs_mdio_write_c45) in sja1105_mdiobus_pcs_register()
379 bus = mdiobus_alloc_size(sizeof(*mdio_priv)); in sja1105_mdiobus_pcs_register()
380 if (!bus) in sja1105_mdiobus_pcs_register()
381 return -ENOMEM; in sja1105_mdiobus_pcs_register()
383 bus->name = "SJA1105 PCS MDIO bus"; in sja1105_mdiobus_pcs_register()
384 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-pcs", in sja1105_mdiobus_pcs_register()
385 dev_name(ds->dev)); in sja1105_mdiobus_pcs_register()
386 bus->read_c45 = priv->info->pcs_mdio_read_c45; in sja1105_mdiobus_pcs_register()
387 bus->write_c45 = priv->info->pcs_mdio_write_c45; in sja1105_mdiobus_pcs_register()
388 bus->parent = ds->dev; in sja1105_mdiobus_pcs_register()
389 /* There is no PHY on this MDIO bus => mask out all PHY addresses in sja1105_mdiobus_pcs_register()
392 bus->phy_mask = ~0; in sja1105_mdiobus_pcs_register()
393 mdio_priv = bus->priv; in sja1105_mdiobus_pcs_register()
394 mdio_priv->priv = priv; in sja1105_mdiobus_pcs_register()
396 rc = mdiobus_register(bus); in sja1105_mdiobus_pcs_register()
398 mdiobus_free(bus); in sja1105_mdiobus_pcs_register()
402 for (port = 0; port < ds->num_ports; port++) { in sja1105_mdiobus_pcs_register()
408 if (priv->phy_mode[port] != PHY_INTERFACE_MODE_SGMII && in sja1105_mdiobus_pcs_register()
409 priv->phy_mode[port] != PHY_INTERFACE_MODE_2500BASEX) in sja1105_mdiobus_pcs_register()
412 xpcs = xpcs_create_mdiodev(bus, port, priv->phy_mode[port]); in sja1105_mdiobus_pcs_register()
418 priv->xpcs[port] = xpcs; in sja1105_mdiobus_pcs_register()
421 priv->mdio_pcs = bus; in sja1105_mdiobus_pcs_register()
426 for (port = 0; port < ds->num_ports; port++) { in sja1105_mdiobus_pcs_register()
427 if (!priv->xpcs[port]) in sja1105_mdiobus_pcs_register()
430 xpcs_destroy(priv->xpcs[port]); in sja1105_mdiobus_pcs_register()
431 priv->xpcs[port] = NULL; in sja1105_mdiobus_pcs_register()
434 mdiobus_unregister(bus); in sja1105_mdiobus_pcs_register()
435 mdiobus_free(bus); in sja1105_mdiobus_pcs_register()
442 struct dsa_switch *ds = priv->ds; in sja1105_mdiobus_pcs_unregister()
445 if (!priv->mdio_pcs) in sja1105_mdiobus_pcs_unregister()
448 for (port = 0; port < ds->num_ports; port++) { in sja1105_mdiobus_pcs_unregister()
449 if (!priv->xpcs[port]) in sja1105_mdiobus_pcs_unregister()
452 xpcs_destroy(priv->xpcs[port]); in sja1105_mdiobus_pcs_unregister()
453 priv->xpcs[port] = NULL; in sja1105_mdiobus_pcs_unregister()
456 mdiobus_unregister(priv->mdio_pcs); in sja1105_mdiobus_pcs_unregister()
457 mdiobus_free(priv->mdio_pcs); in sja1105_mdiobus_pcs_unregister()
458 priv->mdio_pcs = NULL; in sja1105_mdiobus_pcs_unregister()
463 struct sja1105_private *priv = ds->priv; in sja1105_mdiobus_register()
464 const struct sja1105_regs *regs = priv->info->regs; in sja1105_mdiobus_register()
465 struct device_node *switch_node = ds->dev->of_node; in sja1105_mdiobus_register()
480 if (regs->mdio_100base_tx != SJA1105_RSV_ADDR) { in sja1105_mdiobus_register()
486 if (regs->mdio_100base_t1 != SJA1105_RSV_ADDR) { in sja1105_mdiobus_register()
508 struct sja1105_private *priv = ds->priv; in sja1105_mdiobus_unregister()