mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-27 20:59:00 +08:00
Add MG_PHY_DISABLE_AUTONEG option
This commit is contained in:
parent
85414cfec2
commit
41a567f089
31
mongoose.c
31
mongoose.c
@ -17658,23 +17658,15 @@ 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_LAN87x: return "LAN87x";
|
||||||
case MG_PHY_LAN87x:
|
case MG_PHY_RTL8201: return "RTL8201";
|
||||||
return "LAN87x";
|
default: return "unknown";
|
||||||
case MG_PHY_RTL8201:
|
|
||||||
return "RTL8201";
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
}
|
||||||
(void) id2;
|
(void) id2;
|
||||||
}
|
}
|
||||||
@ -17689,6 +17681,13 @@ 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_DISABLE_AUTONEG) {
|
||||||
|
uint16_t val = phy->read_reg(phy_addr, MG_PHY_REG_BCR);
|
||||||
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, val & (uint16_t) ~MG_BIT(12));
|
||||||
|
val = phy->read_reg(phy_addr, MG_PHY_REG_BCR);
|
||||||
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, (uint16_t) MG_BIT(9));
|
||||||
|
}
|
||||||
|
|
||||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
phy->write_reg(phy_addr, 0x0d, 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);
|
||||||
|
11
mongoose.h
11
mongoose.h
@ -2928,13 +2928,10 @@ struct mg_phy {
|
|||||||
void (*write_reg)(uint8_t addr, uint8_t reg, uint16_t value);
|
void (*write_reg)(uint8_t addr, uint8_t reg, uint16_t value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// PHY configuration settings, bitmask
|
// MG_TCPIP_PHY_CONF configuration settings, bitmask of the following:
|
||||||
enum {
|
#define MG_PHY_LEDS_ACTIVE_HIGH 1 // PHY LEDs are connected to ground
|
||||||
// Set if PHY LEDs are connected to ground
|
#define MG_PHY_CLOCKS_MAC 2 // PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
#define MG_PHY_DISABLE_AUTONEG 4 // Disable autonegotiation
|
||||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
|
||||||
MG_PHY_CLOCKS_MAC = (1 << 1),
|
|
||||||
};
|
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
|
@ -30,23 +30,15 @@ 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_LAN87x: return "LAN87x";
|
||||||
case MG_PHY_LAN87x:
|
case MG_PHY_RTL8201: return "RTL8201";
|
||||||
return "LAN87x";
|
default: return "unknown";
|
||||||
case MG_PHY_RTL8201:
|
|
||||||
return "RTL8201";
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
}
|
||||||
(void) id2;
|
(void) id2;
|
||||||
}
|
}
|
||||||
@ -61,6 +53,13 @@ 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_DISABLE_AUTONEG) {
|
||||||
|
uint16_t val = phy->read_reg(phy_addr, MG_PHY_REG_BCR);
|
||||||
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, val & (uint16_t) ~MG_BIT(12));
|
||||||
|
val = phy->read_reg(phy_addr, MG_PHY_REG_BCR);
|
||||||
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, (uint16_t) MG_BIT(9));
|
||||||
|
}
|
||||||
|
|
||||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
phy->write_reg(phy_addr, 0x0d, 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);
|
||||||
|
@ -7,13 +7,10 @@ struct mg_phy {
|
|||||||
void (*write_reg)(uint8_t addr, uint8_t reg, uint16_t value);
|
void (*write_reg)(uint8_t addr, uint8_t reg, uint16_t value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// PHY configuration settings, bitmask
|
// MG_TCPIP_PHY_CONF configuration settings, bitmask of the following:
|
||||||
enum {
|
#define MG_PHY_LEDS_ACTIVE_HIGH 1 // PHY LEDs are connected to ground
|
||||||
// Set if PHY LEDs are connected to ground
|
#define MG_PHY_CLOCKS_MAC 2 // PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
#define MG_PHY_DISABLE_AUTONEG 4 // Disable autonegotiation
|
||||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
|
||||||
MG_PHY_CLOCKS_MAC = (1 << 1),
|
|
||||||
};
|
|
||||||
|
|
||||||
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 };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user