From 76fe489c58f83591d3357a4560ba671049b74c59 Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 30 Jul 2020 15:23:36 +0800 Subject: [PATCH] ethernet: support power on timeout Closes https://github.com/espressif/esp-idf/issues/5425 --- components/esp_eth/src/esp_eth_phy_dm9051.c | 16 +++++++++++++--- components/esp_eth/src/esp_eth_phy_dp83848.c | 16 +++++++++++++--- components/esp_eth/src/esp_eth_phy_ip101.c | 16 +++++++++++++--- components/esp_eth/src/esp_eth_phy_ksz8041.c | 16 +++++++++++++--- components/esp_eth/src/esp_eth_phy_lan8720.c | 16 +++++++++++++--- components/esp_eth/src/esp_eth_phy_rtl8201.c | 16 +++++++++++++--- 6 files changed, 78 insertions(+), 18 deletions(-) diff --git a/components/esp_eth/src/esp_eth_phy_dm9051.c b/components/esp_eth/src/esp_eth_phy_dm9051.c index bef51e254a..49102cf93d 100644 --- a/components/esp_eth/src/esp_eth_phy_dm9051.c +++ b/components/esp_eth/src/esp_eth_phy_dm9051.c @@ -265,12 +265,22 @@ static esp_err_t dm9051_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, dm9051->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, dm9051->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, dm9051->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < dm9051->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, dm9051->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < dm9051->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: diff --git a/components/esp_eth/src/esp_eth_phy_dp83848.c b/components/esp_eth/src/esp_eth_phy_dp83848.c index c512397882..3dd0d6366b 100644 --- a/components/esp_eth/src/esp_eth_phy_dp83848.c +++ b/components/esp_eth/src/esp_eth_phy_dp83848.c @@ -255,12 +255,22 @@ static esp_err_t dp83848_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, dp83848->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, dp83848->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, dp83848->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < dp83848->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, dp83848->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < dp83848->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: diff --git a/components/esp_eth/src/esp_eth_phy_ip101.c b/components/esp_eth/src/esp_eth_phy_ip101.c index 45bb399f5f..951a0a714c 100644 --- a/components/esp_eth/src/esp_eth_phy_ip101.c +++ b/components/esp_eth/src/esp_eth_phy_ip101.c @@ -292,12 +292,22 @@ static esp_err_t ip101_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, ip101->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, ip101->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, ip101->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < ip101->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, ip101->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < ip101->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: diff --git a/components/esp_eth/src/esp_eth_phy_ksz8041.c b/components/esp_eth/src/esp_eth_phy_ksz8041.c index 67c045476c..3c9a89f569 100644 --- a/components/esp_eth/src/esp_eth_phy_ksz8041.c +++ b/components/esp_eth/src/esp_eth_phy_ksz8041.c @@ -242,12 +242,22 @@ static esp_err_t ksz8041_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, ksz8041->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, ksz8041->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, ksz8041->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < ksz8041->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, ksz8041->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < ksz8041->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: diff --git a/components/esp_eth/src/esp_eth_phy_lan8720.c b/components/esp_eth/src/esp_eth_phy_lan8720.c index 5fd2cb4760..3ff28786ec 100644 --- a/components/esp_eth/src/esp_eth_phy_lan8720.c +++ b/components/esp_eth/src/esp_eth_phy_lan8720.c @@ -339,12 +339,22 @@ static esp_err_t lan8720_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, lan8720->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, lan8720->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, lan8720->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < lan8720->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, lan8720->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < lan8720->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: diff --git a/components/esp_eth/src/esp_eth_phy_rtl8201.c b/components/esp_eth/src/esp_eth_phy_rtl8201.c index 022b52f39a..3af6e27ffa 100644 --- a/components/esp_eth/src/esp_eth_phy_rtl8201.c +++ b/components/esp_eth/src/esp_eth_phy_rtl8201.c @@ -246,12 +246,22 @@ static esp_err_t rtl8201_pwrctl(esp_eth_phy_t *phy, bool enable) } PHY_CHECK(eth->phy_reg_write(eth, rtl8201->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val) == ESP_OK, "write BMCR failed", err); - PHY_CHECK(eth->phy_reg_read(eth, rtl8201->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, - "read BMCR failed", err); if (!enable) { + PHY_CHECK(eth->phy_reg_read(eth, rtl8201->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); PHY_CHECK(bmcr.power_down == 1, "power down failed", err); } else { - PHY_CHECK(bmcr.power_down == 0, "power up failed", err); + /* wait for power up complete */ + uint32_t to = 0; + for (to = 0; to < rtl8201->reset_timeout_ms / 10; to++) { + vTaskDelay(pdMS_TO_TICKS(10)); + PHY_CHECK(eth->phy_reg_read(eth, rtl8201->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)) == ESP_OK, + "read BMCR failed", err); + if (bmcr.power_down == 0) { + break; + } + } + PHY_CHECK(to < rtl8201->reset_timeout_ms / 10, "power up timeout", err); } return ESP_OK; err: