mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-27 20:48:29 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2523f81499 |
No files matched your search
+47
-38
@@ -33128,7 +33128,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
|
|||||||
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||||
NETC_EMDIO->EMDIO_CFG =
|
NETC_EMDIO->EMDIO_CFG =
|
||||||
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
||||||
mg_phy_init(&phy, d->phy_addr, 0);
|
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||||
|
|
||||||
// Initialize ENETC1 PSI0 and port
|
// Initialize ENETC1 PSI0 and port
|
||||||
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||||
@@ -33634,17 +33634,19 @@ bool __attribute__((weak)) mg_wifi_ap_stop(void) {
|
|||||||
|
|
||||||
enum { // ID1 ID2
|
enum { // ID1 ID2
|
||||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||||
MG_PHY_DP83x = 0x2000,
|
MG_PHY_DP83x = 0x2000, //
|
||||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||||
MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
|
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse
|
||||||
MG_PHY_RTL82x = 0x1c,
|
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720
|
||||||
|
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02
|
||||||
|
MG_PHY_RTL82x = 0x1c, //
|
||||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||||
MG_PHY_ICS1894x = 0x15,
|
MG_PHY_ICS1894x = 0x15, //
|
||||||
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
||||||
MG_PHY_YT85x = 0x4f51,
|
MG_PHY_YT85x = 0x4f51, //
|
||||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33664,45 +33666,44 @@ enum {
|
|||||||
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
||||||
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
||||||
MG_PHY_ICS189432_REG_POLL = 17,
|
MG_PHY_ICS189432_REG_POLL = 17,
|
||||||
|
MG_PHY_VSC8531_REG_DACS = 28,
|
||||||
MG_PHY_YT8531_REG_PHYSTS = 17,
|
MG_PHY_YT8531_REG_PHYSTS = 17,
|
||||||
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
||||||
MG_PHY_YT8531_REG_EXT_DATA = 31
|
MG_PHY_YT8531_REG_EXT_DATA = 31
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
||||||
switch (id1) {
|
switch (id1) {
|
||||||
case MG_PHY_DP83x:
|
case MG_PHY_DP83x:
|
||||||
switch (id2) {
|
switch (id2) {
|
||||||
case MG_PHY_DP83867:
|
case MG_PHY_DP83867: return "DP83867";
|
||||||
return "DP83867";
|
case MG_PHY_DP83848: return "DP83848";
|
||||||
case MG_PHY_DP83848:
|
case MG_PHY_DP83825: return "DP83825";
|
||||||
return "DP83848";
|
default: return "DP83x";
|
||||||
case MG_PHY_DP83825:
|
|
||||||
return "DP83825";
|
|
||||||
default:
|
|
||||||
return "DP83x";
|
|
||||||
}
|
}
|
||||||
case MG_PHY_KSZ8x:
|
case MG_PHY_KSZ8x: return "KSZ8x";
|
||||||
return "KSZ8x";
|
case MG_PHY_LANxVSCx:
|
||||||
case MG_PHY_LAN87x:
|
switch (id2) {
|
||||||
return "LAN87x";
|
case MG_PHY_VSC8531: return "VSC8531";
|
||||||
|
default:
|
||||||
|
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MG_PHY_RTL82x:
|
case MG_PHY_RTL82x:
|
||||||
switch (id2) {
|
switch (id2) {
|
||||||
case MG_PHY_RTL8201:
|
case MG_PHY_RTL8201: return "RTL8201";
|
||||||
return "RTL8201";
|
case MG_PHY_RTL8211: return "RTL8211";
|
||||||
case MG_PHY_RTL8211:
|
default: return "RTL82x";
|
||||||
return "RTL8211";
|
|
||||||
default:
|
|
||||||
return "RTL82x";
|
|
||||||
}
|
}
|
||||||
case MG_PHY_ICS1894x:
|
case MG_PHY_ICS1894x: return "ICS1894x";
|
||||||
return "ICS1894x";
|
|
||||||
case MG_PHY_YT85x:
|
case MG_PHY_YT85x:
|
||||||
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
||||||
default:
|
default: break;
|
||||||
return "unknown";
|
|
||||||
}
|
}
|
||||||
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||||
uint16_t id1, id2;
|
uint16_t id1, id2;
|
||||||
@@ -33714,6 +33715,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
||||||
|
|
||||||
|
if (config & MG_PHY_RGMII) {
|
||||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||||
@@ -33724,19 +33726,17 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||||
}
|
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
|
phy->write_reg(phy_addr, 0x0d,
|
||||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||||
phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
|
||||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||||
}
|
}
|
||||||
|
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
|
||||||
if (config & MG_PHY_CLOCKS_MAC) {
|
|
||||||
// Use PHY crystal oscillator (preserve defaults)
|
// Use PHY crystal oscillator (preserve defaults)
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else { // MAC clocks PHY, PHY has no xtal
|
} else { // RMII, MAC clocks PHY, PHY has no xtal.
|
||||||
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
||||||
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
||||||
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
||||||
@@ -33749,7 +33749,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
// now do clock stuff
|
// now do clock stuff
|
||||||
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
||||||
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
||||||
} else if (id1 == MG_PHY_LAN87x) {
|
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
||||||
// assume PHY has been hardware strapped properly
|
// assume PHY has been hardware strapped properly
|
||||||
@@ -33795,10 +33795,19 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
|
|||||||
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
||||||
*full_duplex = pc1r & MG_BIT(2);
|
*full_duplex = pc1r & MG_BIT(2);
|
||||||
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
||||||
} else if (id1 == MG_PHY_LAN87x) {
|
} else if (id1 == MG_PHY_LANxVSCx) {
|
||||||
|
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
|
if (id2 == MG_PHY_VSC8531) {
|
||||||
|
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS);
|
||||||
|
*full_duplex = dacs & MG_BIT(5);
|
||||||
|
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
|
||||||
|
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
|
||||||
|
: MG_PHY_SPEED_10M;
|
||||||
|
} else {
|
||||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||||
*full_duplex = scsr & MG_BIT(4);
|
*full_duplex = scsr & MG_BIT(4);
|
||||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||||
|
}
|
||||||
} else if (id1 == MG_PHY_RTL82x) {
|
} else if (id1 == MG_PHY_RTL82x) {
|
||||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
if (id2 == MG_PHY_RTL8211) {
|
if (id2 == MG_PHY_RTL8211) {
|
||||||
@@ -39807,7 +39816,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
|
|||||||
|
|
||||||
// init phy
|
// init phy
|
||||||
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
||||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
|
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||||
|
|
||||||
(void) d;
|
(void) d;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+4
-2
@@ -5605,8 +5605,10 @@ struct mg_phy {
|
|||||||
enum {
|
enum {
|
||||||
// Set if PHY LEDs are connected to ground
|
// Set if PHY LEDs are connected to ground
|
||||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
||||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||||
MG_PHY_CLOCKS_MAC = (1 << 1)
|
MG_PHY_CLOCKS_MAC = (1 << 1),
|
||||||
|
// Set on RGMII. Otherwise, we assume RMII
|
||||||
|
MG_PHY_RGMII = (1 << 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
||||||
|
|||||||
+1
-1
@@ -242,7 +242,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
|
|||||||
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||||
NETC_EMDIO->EMDIO_CFG =
|
NETC_EMDIO->EMDIO_CFG =
|
||||||
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
||||||
mg_phy_init(&phy, d->phy_addr, 0);
|
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||||
|
|
||||||
// Initialize ENETC1 PSI0 and port
|
// Initialize ENETC1 PSI0 and port
|
||||||
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||||
|
|||||||
+45
-36
@@ -4,17 +4,19 @@
|
|||||||
|
|
||||||
enum { // ID1 ID2
|
enum { // ID1 ID2
|
||||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||||
MG_PHY_DP83x = 0x2000,
|
MG_PHY_DP83x = 0x2000, //
|
||||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||||
MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
|
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse
|
||||||
MG_PHY_RTL82x = 0x1c,
|
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720
|
||||||
|
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02
|
||||||
|
MG_PHY_RTL82x = 0x1c, //
|
||||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||||
MG_PHY_ICS1894x = 0x15,
|
MG_PHY_ICS1894x = 0x15, //
|
||||||
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
||||||
MG_PHY_YT85x = 0x4f51,
|
MG_PHY_YT85x = 0x4f51, //
|
||||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,45 +36,44 @@ enum {
|
|||||||
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
||||||
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
||||||
MG_PHY_ICS189432_REG_POLL = 17,
|
MG_PHY_ICS189432_REG_POLL = 17,
|
||||||
|
MG_PHY_VSC8531_REG_DACS = 28,
|
||||||
MG_PHY_YT8531_REG_PHYSTS = 17,
|
MG_PHY_YT8531_REG_PHYSTS = 17,
|
||||||
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
||||||
MG_PHY_YT8531_REG_EXT_DATA = 31
|
MG_PHY_YT8531_REG_EXT_DATA = 31
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
||||||
switch (id1) {
|
switch (id1) {
|
||||||
case MG_PHY_DP83x:
|
case MG_PHY_DP83x:
|
||||||
switch (id2) {
|
switch (id2) {
|
||||||
case MG_PHY_DP83867:
|
case MG_PHY_DP83867: return "DP83867";
|
||||||
return "DP83867";
|
case MG_PHY_DP83848: return "DP83848";
|
||||||
case MG_PHY_DP83848:
|
case MG_PHY_DP83825: return "DP83825";
|
||||||
return "DP83848";
|
default: return "DP83x";
|
||||||
case MG_PHY_DP83825:
|
|
||||||
return "DP83825";
|
|
||||||
default:
|
|
||||||
return "DP83x";
|
|
||||||
}
|
}
|
||||||
case MG_PHY_KSZ8x:
|
case MG_PHY_KSZ8x: return "KSZ8x";
|
||||||
return "KSZ8x";
|
case MG_PHY_LANxVSCx:
|
||||||
case MG_PHY_LAN87x:
|
switch (id2) {
|
||||||
return "LAN87x";
|
case MG_PHY_VSC8531: return "VSC8531";
|
||||||
|
default:
|
||||||
|
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MG_PHY_RTL82x:
|
case MG_PHY_RTL82x:
|
||||||
switch (id2) {
|
switch (id2) {
|
||||||
case MG_PHY_RTL8201:
|
case MG_PHY_RTL8201: return "RTL8201";
|
||||||
return "RTL8201";
|
case MG_PHY_RTL8211: return "RTL8211";
|
||||||
case MG_PHY_RTL8211:
|
default: return "RTL82x";
|
||||||
return "RTL8211";
|
|
||||||
default:
|
|
||||||
return "RTL82x";
|
|
||||||
}
|
}
|
||||||
case MG_PHY_ICS1894x:
|
case MG_PHY_ICS1894x: return "ICS1894x";
|
||||||
return "ICS1894x";
|
|
||||||
case MG_PHY_YT85x:
|
case MG_PHY_YT85x:
|
||||||
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
||||||
default:
|
default: break;
|
||||||
return "unknown";
|
|
||||||
}
|
}
|
||||||
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||||
uint16_t id1, id2;
|
uint16_t id1, id2;
|
||||||
@@ -84,6 +85,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
||||||
|
|
||||||
|
if (config & MG_PHY_RGMII) {
|
||||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||||
@@ -94,19 +96,17 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||||
}
|
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
|
phy->write_reg(phy_addr, 0x0d,
|
||||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||||
phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
|
||||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||||
}
|
}
|
||||||
|
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
|
||||||
if (config & MG_PHY_CLOCKS_MAC) {
|
|
||||||
// Use PHY crystal oscillator (preserve defaults)
|
// Use PHY crystal oscillator (preserve defaults)
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else { // MAC clocks PHY, PHY has no xtal
|
} else { // RMII, MAC clocks PHY, PHY has no xtal.
|
||||||
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
||||||
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
||||||
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
||||||
@@ -119,7 +119,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
// now do clock stuff
|
// now do clock stuff
|
||||||
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
||||||
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
||||||
} else if (id1 == MG_PHY_LAN87x) {
|
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
||||||
// assume PHY has been hardware strapped properly
|
// assume PHY has been hardware strapped properly
|
||||||
@@ -165,10 +165,19 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
|
|||||||
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
||||||
*full_duplex = pc1r & MG_BIT(2);
|
*full_duplex = pc1r & MG_BIT(2);
|
||||||
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
||||||
} else if (id1 == MG_PHY_LAN87x) {
|
} else if (id1 == MG_PHY_LANxVSCx) {
|
||||||
|
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
|
if (id2 == MG_PHY_VSC8531) {
|
||||||
|
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS);
|
||||||
|
*full_duplex = dacs & MG_BIT(5);
|
||||||
|
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
|
||||||
|
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
|
||||||
|
: MG_PHY_SPEED_10M;
|
||||||
|
} else {
|
||||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||||
*full_duplex = scsr & MG_BIT(4);
|
*full_duplex = scsr & MG_BIT(4);
|
||||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||||
|
}
|
||||||
} else if (id1 == MG_PHY_RTL82x) {
|
} else if (id1 == MG_PHY_RTL82x) {
|
||||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||||
if (id2 == MG_PHY_RTL8211) {
|
if (id2 == MG_PHY_RTL8211) {
|
||||||
|
|||||||
+4
-2
@@ -11,8 +11,10 @@ struct mg_phy {
|
|||||||
enum {
|
enum {
|
||||||
// Set if PHY LEDs are connected to ground
|
// Set if PHY LEDs are connected to ground
|
||||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
||||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||||
MG_PHY_CLOCKS_MAC = (1 << 1)
|
MG_PHY_CLOCKS_MAC = (1 << 1),
|
||||||
|
// Set on RGMII. Otherwise, we assume RMII
|
||||||
|
MG_PHY_RGMII = (1 << 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
|
|||||||
|
|
||||||
// init phy
|
// init phy
|
||||||
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
||||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
|
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||||
|
|
||||||
(void) d;
|
(void) d;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in new issue
Block a user