/* MDIO must already be configured as output. */ staticvoid mdiobb_send_num(struct mdiobb_ctrl *ctrl, u16 val, int bits)
{ int i;
for (i = bits - 1; i >= 0; i--)
mdiobb_send_bit(ctrl, (val >> i) & 1);
}
/* MDIO must already be configured as input. */ static u16 mdiobb_get_num(struct mdiobb_ctrl *ctrl, int bits)
{ int i;
u16 ret = 0;
for (i = bits - 1; i >= 0; i--) {
ret <<= 1;
ret |= mdiobb_get_bit(ctrl);
}
return ret;
}
/* Utility to send the preamble, address, and * register (common to read and write).
*/ staticvoid mdiobb_cmd(struct mdiobb_ctrl *ctrl, int op, u8 phy, u8 reg)
{ conststruct mdiobb_ops *ops = ctrl->ops; int i;
ops->set_mdio_dir(ctrl, 1);
/* * Send a 32 bit preamble ('1's) with an extra '1' bit for good * measure. The IEEE spec says this is a PHY optional * requirement. The AMD 79C874 requires one after power up and * one after a MII communications error. This means that we are * doing more preambles than we need, but it is safer and will be * much more robust.
*/
for (i = 0; i < 32; i++)
mdiobb_send_bit(ctrl, 1);
/* send the start bit (01) and the read opcode (10) or write (01). Clause 45 operation uses 00 for the start and 11, 10 for
read/write */
mdiobb_send_bit(ctrl, 0); if (op & MDIO_C45)
mdiobb_send_bit(ctrl, 0); else
mdiobb_send_bit(ctrl, 1);
mdiobb_send_bit(ctrl, (op >> 1) & 1);
mdiobb_send_bit(ctrl, (op >> 0) & 1);
/* In clause 45 mode all commands are prefixed by MDIO_ADDR to specify the lower 16 bits of the 21 bit address. This transfer is done identically to a MDIO_WRITE except for a different code. Theoretically clause 45 and normal devices can exist on the same bus. Normal devices should ignore the MDIO_ADDR
phase. */ staticvoid mdiobb_cmd_addr(struct mdiobb_ctrl *ctrl, int phy, int dev_addr, int reg)
{
mdiobb_cmd(ctrl, MDIO_C45_ADDR, phy, dev_addr);
/* send the turnaround (10) */
mdiobb_send_bit(ctrl, 1);
mdiobb_send_bit(ctrl, 0);
staticint mdiobb_read_common(struct mii_bus *bus, int phy)
{ struct mdiobb_ctrl *ctrl = bus->priv; int ret, i;
ctrl->ops->set_mdio_dir(ctrl, 0);
/* check the turnaround bit: the PHY should be driving it to zero, if this * PHY is listed in phy_ignore_ta_mask as having broken TA, skip that
*/ if (mdiobb_get_bit(ctrl) != 0 &&
!(bus->phy_ignore_ta_mask & (1 << phy))) { /* PHY didn't drive TA low -- flush any bits it * may be trying to send.
*/ for (i = 0; i < 32; i++)
mdiobb_get_bit(ctrl);
return 0xffff;
}
ret = mdiobb_get_num(ctrl, 16);
mdiobb_get_bit(ctrl); return ret;
}
int mdiobb_read_c22(struct mii_bus *bus, int phy, int reg)
{ struct mdiobb_ctrl *ctrl = bus->priv;
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.