/* * QorIQ 10G MDIO Controller * * Copyright 2012 Freescale Semiconductor, Inc. * Copyright 2021 NXP * * Authors: Andy Fleming <afleming@freescale.com> * Timur Tabi <timur@freescale.com> * * This file is licensed under the terms of the GNU General Public License * version 2. This program is licensed "as is" without any warranty of any * kind, whether express or implied.
*/
/* * Wait until the MDIO bus is free
*/ staticint xgmac_wait_until_free(struct device *dev, struct tgec_mdio_controller __iomem *regs, bool is_little_endian)
{ unsignedint timeout;
/* Wait till the bus is free */
timeout = TIMEOUT; while ((xgmac_read32(®s->mdio_stat, is_little_endian) &
MDIO_STAT_BSY) && timeout) {
cpu_relax();
timeout--;
}
if (!timeout) {
dev_err(dev, "timeout waiting for bus to be free\n"); return -ETIMEDOUT;
}
return 0;
}
/* * Wait till the MDIO read or write operation is complete
*/ staticint xgmac_wait_until_done(struct device *dev, struct tgec_mdio_controller __iomem *regs, bool is_little_endian)
{ unsignedint timeout;
/* Wait till the MDIO write is complete */
timeout = TIMEOUT; while ((xgmac_read32(®s->mdio_stat, is_little_endian) &
MDIO_STAT_BSY) && timeout) {
cpu_relax();
timeout--;
}
if (!timeout) {
dev_err(dev, "timeout waiting for operation to complete\n"); return -ETIMEDOUT;
}
return 0;
}
staticint xgmac_mdio_write_c22(struct mii_bus *bus, int phy_id, int regnum,
u16 value)
{ struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; struct tgec_mdio_controller __iomem *regs = priv->mdio_base; bool endian = priv->is_little_endian;
u16 dev_addr = regnum & 0x1f;
u32 mdio_ctl, mdio_stat; int ret;
ret = xgmac_wait_until_free(&bus->dev, regs, endian); if (ret) return ret;
/* Set the port and dev addr */
mdio_ctl = MDIO_CTL_PORT_ADDR(phy_id) | MDIO_CTL_DEV_ADDR(dev_addr);
xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian);
/* Set the register address */
xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian);
ret = xgmac_wait_until_free(&bus->dev, regs, endian); if (ret) return ret;
/* Write the value to the register */
xgmac_write32(MDIO_DATA(value), ®s->mdio_data, endian);
ret = xgmac_wait_until_done(&bus->dev, regs, endian); if (ret) return ret;
return 0;
}
/* Reads from register regnum in the PHY for device dev, returning the value. * Clears miimcom first. All PHY configuration has to be done through the * TSEC1 MIIM regs.
*/ staticint xgmac_mdio_read_c22(struct mii_bus *bus, int phy_id, int regnum)
{ struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; struct tgec_mdio_controller __iomem *regs = priv->mdio_base; bool endian = priv->is_little_endian;
u16 dev_addr = regnum & 0x1f; unsignedlong flags;
uint32_t mdio_stat;
uint32_t mdio_ctl; int ret;
ret = xgmac_wait_until_free(&bus->dev, regs, endian); if (ret) return ret;
/* Set the Port and Device Addrs */
mdio_ctl = MDIO_CTL_PORT_ADDR(phy_id) | MDIO_CTL_DEV_ADDR(dev_addr);
xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian);
if (priv->has_a009885) /* Once the operation completes, i.e. MDIO_STAT_BSY clears, we * must read back the data register within 16 MDC cycles.
*/
local_irq_save(flags);
/* Initiate the read */
xgmac_write32(mdio_ctl | MDIO_CTL_READ, ®s->mdio_ctl, endian);
ret = xgmac_wait_until_done(&bus->dev, regs, endian); if (ret) goto irq_restore;
/* Return all Fs if nothing was there */ if ((xgmac_read32(®s->mdio_stat, endian) & MDIO_STAT_RD_ER) &&
!priv->has_a011043) {
dev_dbg(&bus->dev, "Error while reading PHY%d reg at %d.%d\n",
phy_id, dev_addr, regnum);
ret = 0xffff;
} else {
ret = xgmac_read32(®s->mdio_data, endian) & 0xffff;
dev_dbg(&bus->dev, "read %04x\n", ret);
}
irq_restore: if (priv->has_a009885)
local_irq_restore(flags);
return ret;
}
/* Reads from register regnum in the PHY for device dev, returning the value. * Clears miimcom first. All PHY configuration has to be done through the * TSEC1 MIIM regs.
*/ staticint xgmac_mdio_read_c45(struct mii_bus *bus, int phy_id, int dev_addr, int regnum)
{ struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; struct tgec_mdio_controller __iomem *regs = priv->mdio_base; bool endian = priv->is_little_endian;
u32 mdio_stat, mdio_ctl; unsignedlong flags; int ret;
ret = xgmac_wait_until_free(&bus->dev, regs, endian); if (ret) return ret;
/* Set the Port and Device Addrs */
mdio_ctl = MDIO_CTL_PORT_ADDR(phy_id) | MDIO_CTL_DEV_ADDR(dev_addr);
xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian);
/* Set the register address */
xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian);
ret = xgmac_wait_until_free(&bus->dev, regs, endian); if (ret) return ret;
if (priv->has_a009885) /* Once the operation completes, i.e. MDIO_STAT_BSY clears, we * must read back the data register within 16 MDC cycles.
*/
local_irq_save(flags);
/* Initiate the read */
xgmac_write32(mdio_ctl | MDIO_CTL_READ, ®s->mdio_ctl, endian);
ret = xgmac_wait_until_done(&bus->dev, regs, endian); if (ret) goto irq_restore;
/* Return all Fs if nothing was there */ if ((xgmac_read32(®s->mdio_stat, endian) & MDIO_STAT_RD_ER) &&
!priv->has_a011043) {
dev_dbg(&bus->dev, "Error while reading PHY%d reg at %d.%d\n",
phy_id, dev_addr, regnum);
ret = 0xffff;
} else {
ret = xgmac_read32(®s->mdio_data, endian) & 0xffff;
dev_dbg(&bus->dev, "read %04x\n", ret);
}
irq_restore: if (priv->has_a009885)
local_irq_restore(flags);
if (device_property_read_u32(dev, "clock-frequency", &priv->mdc_freq)) return 0;
priv->enet_clk = devm_clk_get(dev, NULL); if (IS_ERR(priv->enet_clk)) {
dev_err(dev, "Input clock unknown, not changing MDC frequency"); return PTR_ERR(priv->enet_clk);
}
div = ((clk_get_rate(priv->enet_clk) / priv->mdc_freq) - 1) / 2; if (div < 5 || div > 0x1ff) {
dev_err(dev, "Requested MDC frequency is out of range, ignoring"); return -EINVAL;
}
/* In DPAA-1, MDIO is one of the many FMan sub-devices. The FMan * defines a register space that spans a large area, covering all the * subdevice areas. Therefore, MDIO cannot claim exclusive access to * this register area.
*/
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) {
dev_err(&pdev->dev, "could not obtain address\n"); return -EINVAL;
}
bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(struct mdio_fsl_priv)); if (!bus) return -ENOMEM;
/* For both ACPI and DT cases, endianness of MDIO controller * needs to be specified using "little-endian" property.
*/
priv->is_little_endian = device_property_read_bool(&pdev->dev, "little-endian");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.