// SPDX-License-Identifier: GPL-2.0-only /* * PHY drivers for the sungem ethernet driver. * * This file could be shared with other drivers. * * (c) 2002-2007, Benjamin Herrenscmidt (benh@kernel.crashing.org) * * TODO: * - Add support for PHYs that provide an IRQ line * - Eventually moved the entire polling state machine in * there (out of the eth driver), so that it can easily be * skipped on PHYs that implement it in hardware. * - On LXT971 & BCM5201, Apple uses some chip specific regs * to read the link status. Figure out why and if it makes * sense to do the same (magic aneg ?) * - Apple has some additional power management code for some * Broadcom PHYs that they "hide" from the OpenSource version * of darwin, still need to reverse engineer that
*/
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data | MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
data | MII_BCM5221_SHDOW_AUX_MODE4_CLKLOPWR);
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data & ~MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data | MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
data | MII_BCM5221_SHDOW_AUX_MODE4_IDDQMODE);
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data | MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_STAT2);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_STAT2,
data | MII_BCM5221_SHDOW_AUX_STAT2_APD);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
data & ~MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data & ~MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_TEST);
sungem_phy_write(phy, MII_BCM5221_TEST,
data | MII_BCM5221_TEST_ENABLE_SHADOWS);
data = sungem_phy_read(phy, MII_BCM5221_SHDOW_AUX_MODE4);
sungem_phy_write(phy, MII_BCM5221_SHDOW_AUX_MODE4,
data | MII_BCM5241_SHDOW_AUX_MODE4_STANDBYPWR);
/* Configure for gigabit full duplex */
data = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL);
data |= MII_BCM5400_AUXCONTROL_PWR10BASET;
sungem_phy_write(phy, MII_BCM5400_AUXCONTROL, data);
data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data);
udelay(100);
/* Reset and configure cascaded 10/100 PHY */
(void)reset_one_mii_phy(phy, 0x1f);
data = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
data |= MII_BCM5201_MULTIPHY_SERIALMODE;
__sungem_phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data);
data = sungem_phy_read(phy, MII_BCM5400_AUXCONTROL);
data &= ~MII_BCM5400_AUXCONTROL_PWR10BASET;
sungem_phy_write(phy, MII_BCM5400_AUXCONTROL, data);
return 0;
}
staticint bcm5400_suspend(struct mii_phy* phy)
{ #if 0 /* Commented out in Darwin... someone has those dawn docs ? */
sungem_phy_write(phy, MII_BMCR, BMCR_PDOWN); #endif return 0;
}
staticint bcm5401_init(struct mii_phy* phy)
{
u16 data; int rev;
rev = sungem_phy_read(phy, MII_PHYSID2) & 0x000f; if (rev == 0 || rev == 3) { /* Some revisions of 5401 appear to need this * initialisation sequence to disable, according * to OF, "tap power management" * * WARNING ! OF and Darwin don't agree on the * register addresses. OF seem to interpret the * register numbers below as decimal * * Note: This should (and does) match tg3_init_5401phy_dsp * in the tg3.c driver. -DaveM
*/
sungem_phy_write(phy, 0x18, 0x0c20);
sungem_phy_write(phy, 0x17, 0x0012);
sungem_phy_write(phy, 0x15, 0x1804);
sungem_phy_write(phy, 0x17, 0x0013);
sungem_phy_write(phy, 0x15, 0x1204);
sungem_phy_write(phy, 0x17, 0x8006);
sungem_phy_write(phy, 0x15, 0x0132);
sungem_phy_write(phy, 0x17, 0x8006);
sungem_phy_write(phy, 0x15, 0x0232);
sungem_phy_write(phy, 0x17, 0x201f);
sungem_phy_write(phy, 0x15, 0x0a20);
}
/* Configure for gigabit full duplex */
data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data);
udelay(10);
/* Reset and configure cascaded 10/100 PHY */
(void)reset_one_mii_phy(phy, 0x1f);
data = __sungem_phy_read(phy, 0x1f, MII_BCM5201_MULTIPHY);
data |= MII_BCM5201_MULTIPHY_SERIALMODE;
__sungem_phy_write(phy, 0x1f, MII_BCM5201_MULTIPHY, data);
return 0;
}
staticint bcm5401_suspend(struct mii_phy* phy)
{ #if 0 /* Commented out in Darwin... someone has those dawn docs ? */
sungem_phy_write(phy, MII_BMCR, BMCR_PDOWN); #endif return 0;
}
/* Here's some more Apple black magic to setup * some voltage stuffs.
*/
sungem_phy_write(phy, 0x1c, 0x8c23);
sungem_phy_write(phy, 0x1c, 0x8ca3);
sungem_phy_write(phy, 0x1c, 0x8c23);
/* Here, Apple seems to want to reset it, do * it as well
*/
sungem_phy_write(phy, MII_BMCR, BMCR_RESET);
sungem_phy_write(phy, MII_BMCR, 0x1340);
data = sungem_phy_read(phy, MII_BCM5400_GB_CONTROL);
data |= MII_BCM5400_GB_CONTROL_FULLDUPLEXCAP;
sungem_phy_write(phy, MII_BCM5400_GB_CONTROL, data);
udelay(10);
/* Reset and configure cascaded 10/100 PHY */
(void)reset_one_mii_phy(phy, 0x1f);
if (phy->autoneg) {
lpa = sungem_phy_read(phy, MII_LPA);
if (lpa & (LPA_10FULL | LPA_100FULL))
phy->duplex = DUPLEX_FULL; else
phy->duplex = DUPLEX_HALF; if (lpa & (LPA_100FULL | LPA_100HALF))
phy->speed = SPEED_100; else
phy->speed = SPEED_10;
phy->pause = 0;
} /* On non-aneg, we assume what we put in BMCR is the speed, * though magic-aneg shouldn't prevent this case from occurring
*/
id = (sungem_phy_read(phy, MII_PHYSID1) << 16 | sungem_phy_read(phy, MII_PHYSID2));
/* Revision 0 of 5421 needs some fixups */ if (id == 0x002060e0) { /* This is borrowed from MacOS
*/
sungem_phy_write(phy, 0x18, 0x1007);
data = sungem_phy_read(phy, 0x18);
sungem_phy_write(phy, 0x18, data | 0x0400);
sungem_phy_write(phy, 0x18, 0x0007);
data = sungem_phy_read(phy, 0x18);
sungem_phy_write(phy, 0x18, data | 0x0800);
sungem_phy_write(phy, 0x17, 0x000a);
data = sungem_phy_read(phy, 0x15);
sungem_phy_write(phy, 0x15, data | 0x0200);
}
/* Pick up some init code from OF for K2 version */ if ((id & 0xfffffff0) == 0x002062e0) {
sungem_phy_write(phy, 4, 0x01e1);
sungem_phy_write(phy, 9, 0x0300);
}
/* Check if we can enable automatic low power */ #ifdef CONFIG_PPC_PMAC if (phy->platform_data) { struct device_node *np = of_get_parent(phy->platform_data); int can_low_power = 1; if (np == NULL || of_get_property(np, "no-autolowpower", NULL))
can_low_power = 0;
of_node_put(np); if (can_low_power) { /* Enable automatic low-power */
sungem_phy_write(phy, 0x1c, 0x9002);
sungem_phy_write(phy, 0x1c, 0xa821);
sungem_phy_write(phy, 0x1c, 0x941d);
}
} #endif/* CONFIG_PPC_PMAC */
/* First reset the PHY */
sungem_phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
/* Select speed & duplex */ switch(speed) { case SPEED_10: break; case SPEED_100:
ctl |= BMCR_SPEED100; break; case SPEED_1000:
ctl |= BMCR_SPD2;
} if (fd == DUPLEX_FULL)
ctl |= BMCR_FULLDPLX;
// XXX Should we set the sungem to GII now on 1000BT ?
sungem_phy_write(phy, MII_BMCR, ctl);
return 0;
}
staticint bcm54xx_read_link(struct mii_phy *phy)
{ int link_mode;
u16 val;
if (phy->autoneg) {
val = sungem_phy_read(phy, MII_BCM5400_AUXSTATUS);
link_mode = ((val & MII_BCM5400_AUXSTATUS_LINKMODE_MASK) >>
MII_BCM5400_AUXSTATUS_LINKMODE_SHIFT);
phy->duplex = phy_BCM5400_link_table[link_mode][0] ?
DUPLEX_FULL : DUPLEX_HALF;
phy->speed = phy_BCM5400_link_table[link_mode][2] ?
SPEED_1000 :
(phy_BCM5400_link_table[link_mode][1] ?
SPEED_100 : SPEED_10);
val = sungem_phy_read(phy, MII_LPA);
phy->pause = (phy->duplex == DUPLEX_FULL) &&
((val & LPA_PAUSE) != 0);
} /* On non-aneg, we assume what we put in BMCR is the speed, * though magic-aneg shouldn't prevent this case from occurring
*/
/* Setup standard advertise */
adv = sungem_phy_read(phy, MII_ADVERTISE);
adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); if (advertise & ADVERTISED_10baseT_Half)
adv |= ADVERTISE_10HALF; if (advertise & ADVERTISED_10baseT_Full)
adv |= ADVERTISE_10FULL; if (advertise & ADVERTISED_100baseT_Half)
adv |= ADVERTISE_100HALF; if (advertise & ADVERTISED_100baseT_Full)
adv |= ADVERTISE_100FULL; if (advertise & ADVERTISED_Pause)
adv |= ADVERTISE_PAUSE_CAP; if (advertise & ADVERTISED_Asym_Pause)
adv |= ADVERTISE_PAUSE_ASYM;
sungem_phy_write(phy, MII_ADVERTISE, adv);
/* Setup 1000BT advertise & enable crossover detect * XXX How do we advertise 1000BT ? Darwin source is * confusing here, they read from specific control and * write to control... Someone has specs for those * beasts ?
*/
adv = sungem_phy_read(phy, MII_M1011_PHY_SPEC_CONTROL);
adv |= MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX;
adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
MII_1000BASETCONTROL_HALFDUPLEXCAP); if (advertise & SUPPORTED_1000baseT_Half)
adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; if (advertise & SUPPORTED_1000baseT_Full)
adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
sungem_phy_write(phy, MII_1000BASETCONTROL, adv);
/* Select speed & duplex */ switch(speed) { case SPEED_10: break; case SPEED_100:
ctl |= BMCR_SPEED100; break; /* I'm not sure about the one below, again, Darwin source is * quite confusing and I lack chip specs
*/ case SPEED_1000:
ctl |= BMCR_SPD2;
} if (fd == DUPLEX_FULL)
ctl |= BMCR_FULLDPLX;
/* Disable crossover. Again, the way Apple does it is strange, * though I don't assume they are wrong ;)
*/
ctl2 = sungem_phy_read(phy, MII_M1011_PHY_SPEC_CONTROL);
ctl2 &= ~(MII_M1011_PHY_SPEC_CONTROL_MANUAL_MDIX |
MII_M1011_PHY_SPEC_CONTROL_AUTO_MDIX |
MII_1000BASETCONTROL_FULLDUPLEXCAP |
MII_1000BASETCONTROL_HALFDUPLEXCAP); if (speed == SPEED_1000)
ctl2 |= (fd == DUPLEX_FULL) ?
MII_1000BASETCONTROL_FULLDUPLEXCAP :
MII_1000BASETCONTROL_HALFDUPLEXCAP;
sungem_phy_write(phy, MII_1000BASETCONTROL, ctl2);
// XXX Should we set the sungem to GII now on 1000BT ?
if (phy->autoneg) {
status = sungem_phy_read(phy, MII_M1011_PHY_SPEC_STATUS); if ((status & MII_M1011_PHY_SPEC_STATUS_RESOLVED) == 0) return -EAGAIN; if (status & MII_M1011_PHY_SPEC_STATUS_1000)
phy->speed = SPEED_1000; elseif (status & MII_M1011_PHY_SPEC_STATUS_100)
phy->speed = SPEED_100; else
phy->speed = SPEED_10; if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
phy->duplex = DUPLEX_FULL; else
phy->duplex = DUPLEX_HALF;
pmask = MII_M1011_PHY_SPEC_STATUS_TX_PAUSE |
MII_M1011_PHY_SPEC_STATUS_RX_PAUSE;
phy->pause = (status & pmask) == pmask;
} /* On non-aneg, we assume what we put in BMCR is the speed, * though magic-aneg shouldn't prevent this case from occurring
*/
/* On gigabit capable PHYs, we advertise Pause support but not asym pause * support for now as I'm not sure it's supported and Darwin doesn't do * it neither. --BenH.
*/ #define MII_GBIT_FEATURES \
(MII_BASIC_FEATURES | \
SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
/* two revs in darwin for the 88e1101 ... I could use a datasheet * to get the proper names...
*/ staticconststruct mii_phy_def marvell88e1101v1_phy_def = {
.phy_id = 0x01410c20,
.phy_id_mask = 0xfffffff0,
.name = "Marvell 88E1101v1",
.features = MII_GBIT_FEATURES,
.magic_aneg = 1,
.ops = &marvell88e1101_phy_ops
};
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.