From 749c61e5b30a18037fcae27694cd949c4d652205 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 27 Apr 2022 23:44:04 +0200 Subject: [PATCH 1/3] dt-bindings: net: micrel: add coma-mode-gpios property The LAN8814 has a coma mode pin which is used to put the PHY into isolate and power-down mode. Usually strapped to be asserted by default. A GPIO is then used to take the PHY out of this mode. Signed-off-by: Michael Walle Acked-by: Rob Herring Signed-off-by: Jakub Kicinski --- Documentation/devicetree/bindings/net/micrel.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/net/micrel.txt b/Documentation/devicetree/bindings/net/micrel.txt index 8d157f0295a50..a9ed691ffb034 100644 --- a/Documentation/devicetree/bindings/net/micrel.txt +++ b/Documentation/devicetree/bindings/net/micrel.txt @@ -45,3 +45,12 @@ Optional properties: In fiber mode, auto-negotiation is disabled and the PHY can only work in 100base-fx (full and half duplex) modes. + + - coma-mode-gpios: If present the given gpio will be deasserted when the + PHY is probed. + + Some PHYs have a COMA mode input pin which puts the PHY into + isolate and power-down mode. On some boards this input is connected + to a GPIO of the SoC. + + Supported on the LAN8814. From 31d00ca4ce0e1abf5342854606bbe7d20e38c3f8 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 27 Apr 2022 23:44:05 +0200 Subject: [PATCH 2/3] net: phy: micrel: move the PHY timestamping check Both lan8814_ptp_init() and lan8814_ptp_probe_once() are only used if PTP and PHY timestamping is enabed. Up until now the probe function just returns early, if they are not needed. But we need the phy_package_init_once() functionality for the coma mode GPIO setup. Move the check into the functions itself. Signed-off-by: Michael Walle Signed-off-by: Jakub Kicinski --- drivers/net/phy/micrel.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 96840695debde..b981c5eaac33f 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -2729,6 +2729,10 @@ static void lan8814_ptp_init(struct phy_device *phydev) struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; u32 temp; + if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) || + !IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) + return; + lanphy_write_page_reg(phydev, 5, TSU_HARD_RESET, TSU_HARD_RESET_); temp = lanphy_read_page_reg(phydev, 5, PTP_TX_MOD); @@ -2767,6 +2771,10 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev) { struct lan8814_shared_priv *shared = phydev->shared->priv; + if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) || + !IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) + return 0; + /* Initialise shared lock for clock*/ mutex_init(&shared->shared_lock); @@ -2843,10 +2851,6 @@ static int lan8814_probe(struct phy_device *phydev) phydev->priv = priv; - if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) || - !IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) - return 0; - /* Strap-in value for PHY address, below register read gives starting * phy address value */ From 738871b09250ee9043c0e05101fcc254059f1492 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 27 Apr 2022 23:44:06 +0200 Subject: [PATCH 3/3] net: phy: micrel: add coma mode GPIO The LAN8814 has a coma mode pin which puts the PHY into isolate and power-dowm mode. Unfortunately, the mode cannot be disabled by a register. Usually, the input pin has a pull-up and connected to a GPIO which can then be used to disable the mode. Try to get the GPIO and deassert it. Signed-off-by: Michael Walle Signed-off-by: Jakub Kicinski --- drivers/net/phy/micrel.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index b981c5eaac33f..685a0ab5453c4 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -32,6 +32,7 @@ #include #include #include +#include /* Operation Mode Strap Override */ #define MII_KSZPHY_OMSO 0x16 @@ -2837,6 +2838,21 @@ static int lan8814_config_init(struct phy_device *phydev) return 0; } +static int lan8814_release_coma_mode(struct phy_device *phydev) +{ + struct gpio_desc *gpiod; + + gpiod = devm_gpiod_get_optional(&phydev->mdio.dev, "coma-mode", + GPIOD_OUT_HIGH_OPEN_DRAIN); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + + gpiod_set_consumer_name(gpiod, "LAN8814 coma mode"); + gpiod_set_value_cansleep(gpiod, 0); + + return 0; +} + static int lan8814_probe(struct phy_device *phydev) { struct kszphy_priv *priv; @@ -2859,6 +2875,10 @@ static int lan8814_probe(struct phy_device *phydev) addr, sizeof(struct lan8814_shared_priv)); if (phy_package_init_once(phydev)) { + err = lan8814_release_coma_mode(phydev); + if (err) + return err; + err = lan8814_ptp_probe_once(phydev); if (err) return err;