From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.1 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1653064176; bh=RJ0H+QdPz91rmv6VL7QwkPCS4mKGMnVhHtijqyAJ54M=; h=Reply-To:In-Reply-To:References:Date:Subject:Cc:To:From: Message-Id; b=kPmtCyj7tKTyz4Vl58HtSpx/ofmTxDvSu+IGbWraK489pzwFrkt/jTYaOVPcy3zqB ea9l2Xbteuf7YJe6yi4mCcSc0+rDOya+h0cl4IgEhEyDMo3J0CfuDSs0CGpdEUtJL2 HR76wcSQGNDm8VW+D5xg6ZpU5FAMwmOiUK6ZNjxI= Authentication-Results: sas1-a0dbea86c90a.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru From: asheplyakov@yandex.ru To: devel@lists.altlinux.org Date: Fri, 20 May 2022 20:28:17 +0400 Message-Id: <20220520162849.1554351-4-asheplyakov@yandex.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520162849.1554351-1-asheplyakov@yandex.ru> References: <20220520162849.1554351-1-asheplyakov@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Alexey Sheplyakov , Dmitry Dunaev , Alexey Sheplyakov , Evgeny Sinelnikov , Vitaly Chikunov , Igor Chudov Subject: [devel] [PATCH 03/35] net: stmmac: custom mdio reset for some Baikal-M boards X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2022 16:29:42 -0000 Archived-At: List-Archive: List-Post: From: Alexey Sheplyakov Signed-off-by: Alexey Sheplyakov Signed-off-by: Dmitry Dunaev X-feature-Baikal-M --- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index a5d150c5f3d8..639bcc35e928 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -346,6 +346,63 @@ static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, return ret; } +#define MAC_GPIO 0xe0 /* GPIO register */ +#define MAC_GPIO_GPO BIT(8) /* output port */ + +#if IS_ENABLED(CONFIG_STMMAC_PLATFORM) && IS_ENABLED(CONFIG_OF) +/** + * Reset the MII bus via MAC GP_OUT pin + */ +static int stmmac_mdio_reset_gp_out(struct stmmac_priv *priv) { + u32 value, high, low; + u32 delays[3] = { 0, 0, 0 }; + bool active_low = false; + struct device_node *np = priv->device->of_node; + + if (!np) + return -ENODEV; + + if (!of_property_read_bool(np, "snps,reset-gp-out")) { + dev_warn(priv->device, "snps,reset-gp-out is not set\n"); + return -ENODEV; + } + + dev_info(priv->device, "resetting MDIO via GP_OUT\n"); + active_low = of_property_read_bool(np, "snsps,reset-active-low"); + of_property_read_u32_array(np, "snps,reset-delays-us", delays, 3); + + value = readl(priv->ioaddr + MAC_GPIO); + if (active_low) { + high = value | MAC_GPIO_GPO; + low = value & ~MAC_GPIO_GPO; + } else { + high = value & ~MAC_GPIO_GPO; + low = value | MAC_GPIO_GPO; + } + + writel(high, priv->ioaddr + MAC_GPIO); + if (delays[0]) + msleep(DIV_ROUND_UP(delays[0], 1000)); + + writel(low, priv->ioaddr + MAC_GPIO); + if (delays[1]) + msleep(DIV_ROUND_UP(delays[1], 1000)); + + writel(high, priv->ioaddr + MAC_GPIO); + if (delays[2]) + msleep(DIV_ROUND_UP(delays[2], 1000)); + + /* Clear PHY reset */ + udelay(10); + value = readl(priv->ioaddr + MAC_GPIO); + value |= MAC_GPIO_GPO; + writel(value, priv->ioaddr + MAC_GPIO); + msleep(1000); + dev_info(priv->device, "mdio reset completed\n"); + return 0; +} +#endif + /** * stmmac_mdio_reset * @bus: points to the mii_bus structure @@ -361,8 +418,14 @@ int stmmac_mdio_reset(struct mii_bus *bus) #ifdef CONFIG_OF if (priv->device->of_node) { struct gpio_desc *reset_gpio; + bool reset_gp_out; u32 delays[3] = { 0, 0, 0 }; + reset_gp_out = of_property_read_bool(priv->device->of_node, + "snps,reset-gp-out"); + if (reset_gp_out) + return stmmac_mdio_reset_gp_out(priv); + reset_gpio = devm_gpiod_get_optional(priv->device, "snps,reset", GPIOD_OUT_LOW); -- 2.32.0