/* * Per-device-type data. Each type of device tree node that we support gets * one of these. * * @mii_offset: the offset of the MII registers within the memory map of the * node. Some nodes define only the MII registers, and some define the whole * MAC (which includes the MII registers). * * @get_tbipa: determines the address of the TBIPA register * * @ucc_configure: a special function for extra QE configuration
*/ struct fsl_pq_mdio_data { unsignedint mii_offset; /* offset of the MII registers */
uint32_t __iomem * (*get_tbipa)(void __iomem *p); void (*ucc_configure)(phys_addr_t start, phys_addr_t end);
};
/* * Write value to the PHY at mii_id at register regnum, on the bus attached * to the local interface, which may be different from the generic mdio bus * (tied to a single interface), waiting until the write is done before * returning. This is helpful in programming interfaces like the TBI which * control interfaces like onchip SERDES and are always tied to the local * mdio pins, which may not be the same as system mdio bus, used for * controlling the external PHYs, for example.
*/ staticint fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
u16 value)
{ struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; unsignedint timeout;
/* Set the PHY address and the register address we want to write */
iowrite32be((mii_id << 8) | regnum, ®s->miimadd);
/* Write out the value we want */
iowrite32be(value, ®s->miimcon);
/* Wait for the transaction to finish */
timeout = MII_TIMEOUT; while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) {
cpu_relax();
timeout--;
}
return timeout ? 0 : -ETIMEDOUT;
}
/* * Read the bus for PHY at addr mii_id, register regnum, and return the value. * Clears miimcom first. * * All PHY operation done on the bus attached to the local interface, which * may be different from the generic mdio bus. This is helpful in programming * interfaces like the TBI which, in turn, control interfaces like on-chip * SERDES and are always tied to the local mdio pins, which may not be the * same as system mdio bus, used for controlling the external PHYs, for eg.
*/ staticint fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{ struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; unsignedint timeout;
u16 value;
/* Set the PHY address and the register address we want to read */
iowrite32be((mii_id << 8) | regnum, ®s->miimadd);
/* Clear miimcom, and then initiate a read */
iowrite32be(0, ®s->miimcom);
iowrite32be(MII_READ_COMMAND, ®s->miimcom);
/* Wait for the transaction to finish, normally less than 100us */
timeout = MII_TIMEOUT; while ((ioread32be(®s->miimind) &
(MIIMIND_NOTVALID | MIIMIND_BUSY)) && timeout) {
cpu_relax();
timeout--;
}
if (!timeout) return -ETIMEDOUT;
/* Grab the value of the register from miimstat */
value = ioread32be(®s->miimstat);
/* Reset the MIIM registers, and wait for the bus to free */ staticint fsl_pq_mdio_reset(struct mii_bus *bus)
{ struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; unsignedint timeout;
mutex_lock(&bus->mdio_lock);
/* Reset the management interface */
iowrite32be(MIIMCFG_RESET, ®s->miimcfg);
/* Setup the MII Mgmt clock speed */
iowrite32be(MIIMCFG_INIT_VALUE, ®s->miimcfg);
/* Wait until the bus is free */
timeout = MII_TIMEOUT; while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) {
cpu_relax();
timeout--;
}
mutex_unlock(&bus->mdio_lock);
if (!timeout) {
dev_err(&bus->dev, "timeout waiting for MII bus\n"); return -EBUSY;
}
return 0;
}
#if IS_ENABLED(CONFIG_GIANFAR) /* * Return the TBIPA address, starting from the address * of the mapped GFAR MDIO registers (struct gfar) * This is mildly evil, but so is our hardware for doing this. * Also, we have to cast back to struct gfar because of * definition weirdness done in gianfar.h.
*/ static uint32_t __iomem *get_gfar_tbipa_from_mdio(void __iomem *p)
{ struct gfar __iomem *enet_regs = p;
return &enet_regs->tbipa;
}
/* * Return the TBIPA address, starting from the address * of the mapped GFAR MII registers (gfar_mii_regs[] within struct gfar)
*/ static uint32_t __iomem *get_gfar_tbipa_from_mii(void __iomem *p)
{ return get_gfar_tbipa_from_mdio(container_of(p, struct gfar, gfar_mii_regs));
}
/* * Return the TBIPAR address for an eTSEC2 node
*/ static uint32_t __iomem *get_etsec_tbipa(void __iomem *p)
{ return p;
} #endif
#if IS_ENABLED(CONFIG_UCC_GETH) /* * Return the TBIPAR address for a QE MDIO node, starting from the address * of the mapped MII registers (struct fsl_pq_mii)
*/ static uint32_t __iomem *get_ucc_tbipa(void __iomem *p)
{ struct fsl_pq_mdio __iomem *mdio = container_of(p, struct fsl_pq_mdio, mii);
return &mdio->utbipar;
}
/* * Find the UCC node that controls the given MDIO node * * For some reason, the QE MDIO nodes are not children of the UCC devices * that control them. Therefore, we need to scan all UCC nodes looking for * the one that encompases the given MDIO node. We do this by comparing * physical addresses. The 'start' and 'end' addresses of the MDIO node are * passed, and the correct UCC node will cover the entire address range. * * This assumes that there is only one QE MDIO node in the entire device tree.
*/ staticvoid ucc_configure(phys_addr_t start, phys_addr_t end)
{ staticbool found_mii_master; struct device_node *np = NULL;
ret = of_address_to_resource(np, 0, &res); if (ret < 0) {
pr_debug("fsl-pq-mdio: no address range in node %pOF\n",
np); continue;
}
/* if our mdio regs fall within this UCC regs range */ if ((start < res.start) || (end > res.end)) continue;
iprop = of_get_property(np, "cell-index", NULL); if (!iprop) {
iprop = of_get_property(np, "device-id", NULL); if (!iprop) {
pr_debug("fsl-pq-mdio: no UCC ID in node %pOF\n",
np); continue;
}
}
id = be32_to_cpup(iprop);
/* * cell-index and device-id for QE nodes are * numbered from 1, not 0.
*/ if (ucc_set_qe_mux_mii_mng(id - 1) < 0) {
pr_debug("fsl-pq-mdio: invalid UCC ID in node %pOF\n",
np); continue;
}
pr_debug("fsl-pq-mdio: setting node UCC%u to MII master\n", id);
found_mii_master = true;
}
}
/* * Add consistency check to make sure TBI is contained within * the mapped range (not because we would get a segfault, * rather to catch bugs in computing TBI address). Print error * message but continue anyway.
*/ if ((void *)tbipa > reg_map + resource_size(reg_res) - 4)
dev_err(&pdev->dev, "invalid register map (should be at least 0x%04zx to contain TBI address)\n",
((void *)tbipa - reg_map) + 4);
}
/* * Some device tree nodes represent only the MII registers, and * others represent the MAC and MII registers. The 'mii_offset' field * contains the offset of the MII registers inside the mapped register * space.
*/ if (data->mii_offset > resource_size(&res)) {
dev_err(&pdev->dev, "invalid register map\n");
err = -EINVAL; goto error;
}
priv->regs = priv->map + data->mii_offset;
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.