From patchwork Mon Feb 8 14:08:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 12075701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E8DC433DB for ; Mon, 8 Feb 2021 14:21:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EF1164E2E for ; Mon, 8 Feb 2021 14:21:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EF1164E2E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baikalelectronics.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZtQfYL4+1BBA+DJr+MmTH1Ma3L5ZQpFUV2+wHF+UK28=; b=edOyNdPCN/rmwqZDIcdIue4zt tNYWeNGAdhV5i7REIu09eZ1GhcLqCVujllKwpMB9p9/9Dm5MNDia18RIdx4azv0y/jqtFJe0SUs1/ ULN7dnqLBe0WmlOeeVk7X65iMQsiRMlePvM2dK6uu+zxcrEB5EDAbqxXX93z8+4MVjTlqIZasbapI HvaznU34c+htGobx/Cc3+D4BhToR88T07Qyko802NQBo7Jod3hIgG2WgXsftppXyqf9TSU3LR9QxC xWRggpscoxMJXL8QPDwGfLlfBlo0hqcWuKCZGsxTgi6DXuKm6g88HEmqL52ttn6K+hsdh0dnPwkLE m/mR9Ta5Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97O1-0002ik-NG; Mon, 08 Feb 2021 14:19:33 +0000 Received: from mail.baikalelectronics.com ([87.245.175.226] helo=mail.baikalelectronics.ru) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97DS-0005MJ-18 for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 14:08:48 +0000 From: Serge Semin To: Rob Herring , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Maxime Coquelin Subject: [PATCH 15/16] net: stmmac: Add DW GMAC GPIOs support Date: Mon, 8 Feb 2021 17:08:19 +0300 Message-ID: <20210208140820.10410-16-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> References: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_090838_394727_F7515A3E X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Serge Semin , Alexey Malahov , Serge Semin , Vyacheslav Mitrofanov , Pavel Parkhomenko , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Synopsys DW GMAC can be synthesized with up to four GPIs and four GPOs support, which in case if enabled can be configured via a MAC CSR 0xe0. In order to have the DW GMAC GPIO interface supported in the STMMAC GPIO driver we just need to define the GPIO configs accessors and GPI state getter. Signed-off-by: Serge Semin --- Folks, I don't know whether the same GPIO CSR layout is defined for some other DW MAC IP-core. So for now the accessors have been created for GMACs only. But if you are sure the callbacks can be used for some other IP, I can move them to dwmac_lib.c. Though in order to have the GPIOs working in the driver the MAC/DMA cleanup methods need to be also defined for that IP-core version. --- .../net/ethernet/stmicro/stmmac/dwmac1000.h | 11 +++++ .../ethernet/stmicro/stmmac/dwmac1000_core.c | 40 +++++++++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.c | 1 + drivers/net/ethernet/stmicro/stmmac/hwif.h | 1 + 4 files changed, 53 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h index 919f5b55bc7d..7fa75e0a33bc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h @@ -30,6 +30,7 @@ #define GMAC_INT_STATUS_MMCCSUM BIT(7) #define GMAC_INT_STATUS_TSTAMP BIT(9) #define GMAC_INT_STATUS_LPIIS BIT(10) +#define GMAC_INT_STATUS_GPIIS BIT(11) /* interrupt mask register */ #define GMAC_INT_MASK 0x0000003c @@ -101,6 +102,16 @@ enum power_event { #define GMAC_RGSMIIIS_SPEED_25 0x1 #define GMAC_RGSMIIIS_SPEED_2_5 0x0 +/* General Purpose IO register */ +#define GMAC_GPIO 0x000000e0 /* General Purpose IO */ +#define GMAC_GPIO_GPIS GENMASK(3, 0) +#define GMAC_GPIO_NGPIS 4 +#define GMAC_GPIO_GPO GENMASK(11, 8) +#define GMAC_GPIO_NGPOS 4 +#define GMAC_GPIO_GPIE GENMASK(19, 16) +#define GMAC_GPIO_GPIT GENMASK(27, 24) +#define GMAC_GPIO_NGPIOS (GMAC_GPIO_NGPIS + GMAC_GPIO_NGPOS) + /* GMAC Configuration defines */ #define GMAC_CONTROL_2K 0x08000000 /* IEEE 802.3as 2K packets */ #define GMAC_CONTROL_TC 0x01000000 /* Transmit Conf. in RGMII/SGMII */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c index 7dc8b254c15a..e2a4b746fde9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c @@ -12,6 +12,7 @@ Author: Giuseppe Cavallaro *******************************************************************************/ +#include #include #include #include @@ -577,6 +578,45 @@ const struct stmmac_ops dwmac1000_ops = { .set_mac_loopback = dwmac1000_set_mac_loopback, }; +static void dwmac1000_gpio_set_ctrl(struct stmmac_priv *priv, u32 gpie, + u32 gpit, u32 gpo) +{ + u32 val; + + val = FIELD_PREP(GMAC_GPIO_GPO, gpo) | + FIELD_PREP(GMAC_GPIO_GPIE, gpie) | + FIELD_PREP(GMAC_GPIO_GPIT, gpit); + + writel(val, priv->ioaddr + GMAC_GPIO); +} + +static void dwmac1000_gpio_get_ctrl(struct stmmac_priv *priv, u32 *gpie, + u32 *gpit, u32 *gpo) +{ + u32 val; + + val = readl(priv->ioaddr + GMAC_GPIO); + + *gpie = FIELD_GET(GMAC_GPIO_GPIE, val); + *gpit = FIELD_GET(GMAC_GPIO_GPIT, val); + *gpo = FIELD_GET(GMAC_GPIO_GPO, val); +} + +static int dwmac1000_gpio_get_gpi(struct stmmac_priv *priv) +{ + u32 val; + + val = readl(priv->ioaddr + GMAC_GPIO); + + return FIELD_GET(GMAC_GPIO_GPIS, val); +} + +const struct stmmac_gpio_ops dwmac1000_gpio_ops = { + .set_ctrl = dwmac1000_gpio_set_ctrl, + .get_ctrl = dwmac1000_gpio_get_ctrl, + .get_gpi = dwmac1000_gpio_get_gpi, +}; + int dwmac1000_setup(struct stmmac_priv *priv) { struct mac_device_info *mac = priv->hw; diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index 067420059c11..18aaa27801e4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -140,6 +140,7 @@ static const struct stmmac_hwif_entry { .mode = NULL, .tc = NULL, .mmc = &dwmac_mmc_ops, + .gpio = &dwmac1000_gpio_ops, .setup = dwmac1000_setup, .quirks = stmmac_dwmac1_quirks, }, { diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 99c5841f1060..1aabdd96ea32 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -661,6 +661,7 @@ extern const struct stmmac_ops dwmac100_ops; extern const struct stmmac_dma_ops dwmac100_dma_ops; extern const struct stmmac_ops dwmac1000_ops; extern const struct stmmac_dma_ops dwmac1000_dma_ops; +extern const struct stmmac_gpio_ops dwmac1000_gpio_ops; extern const struct stmmac_ops dwmac4_ops; extern const struct stmmac_dma_ops dwmac4_dma_ops; extern const struct stmmac_ops dwmac410_ops;