From patchwork Thu Jun 9 00:28:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12874738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 367D5C43334 for ; Thu, 9 Jun 2022 00:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=gec6eX3Mz08SzDXUhbHKhGAuky5R3SZri31y+b2TBwk=; b=jZCYJQwZWMrkaL 1vKDUNcJmCUYP8E1OcR3glsJReTizkrQJ+a9++VkiBQABOuSiqZZlPBQWm28lLm1s+gYyUyyrQQs/ /NZIaWqqPe4YDa1l73pUlrpW3efgYdXYK/8A7GOu3wxsqjQQTdHxM7E1y/zloV/8ltyT1Tky/+sh4 Ll3Z49SNLMgCHLxYMW0nFmOtcDhFA+wdirdWWejx/SCCUVSj37pZ2loLcKFh3hAzv/lsQ3efdxZL2 jP9Bg47o0egPzxTnSEUH7ftcKffsByVY84s5XdfjQY2dBCvaJQ9uMc7PAuNskXT0Z3DCZMjcyJsDd qEpIryL6jL6kUGZrjrIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nz62q-00FKKe-4v; Thu, 09 Jun 2022 00:29:04 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nz62n-00FKIx-22 for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 00:29:02 +0000 Received: by mail-ej1-x631.google.com with SMTP id u12so44480943eja.8 for ; Wed, 08 Jun 2022 17:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MmMak1g0Or5/SPEB3988q7jPgBcZiEs6ACLIGroSnsk=; b=YJ/+S4sd6V5TTpWe3HozJ6aT4U5QrdBRDxy8HERqMCsYOduLGF+IeYdUMu+4WjQZD4 yCD6viR0tZPk0htv+QHuhU4aP0/ScEGIBAfR0JeTpEQdrXpOwyoM87SEMJOSuydFpgyc WxfUVoYrqoHZP0RAfW60Fx+T9BGiKjbvOQVIhvA3gYlsnYrqQc+2T70o51iwjrmb8n+g 54a0g302y2sIOnkLe+syaOvH4+qUPNy5dorI0qUTjo+oHq8a1mmaYa6vFKtmOxrVF2hJ 8ev5j8lGyxWTA9LSg7TVUyN7XRNmoxv4jvSI3OHwcglSqxX6BLMQaJWbSNP/cv0OAe10 kczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MmMak1g0Or5/SPEB3988q7jPgBcZiEs6ACLIGroSnsk=; b=dh7SAE1VKcT8oDfM1ZkKLxsg3s8rzDE4o7T49Skl5uCR1eV/ZMj7rGIf0XEzc6FtEQ oxwd25mMFUC2mkMUpcZ7jZI65WtzLVQXyB/4Bteo/cLcE8VziCxBhyglEhO/ek5fA5XP i5xMA34R7+WlfG+SkDZjKH2sB89xIUI8lBdy/BAen5AcS59gg6fP0fY01OQD7EGjksaZ MG8g1PbwhoXLU00Dfyu4f1VdEBM7s1oR4g+zt2d5DXX/MZPxEV9Q1W+XI2JsQlxcTEtc zWLjhgvId8AK8CNf53e8yQ0KhPNZWCS/c957sHqANz9jmKqzZtip8OV85Dykke9QoM2c YZIA== X-Gm-Message-State: AOAM53373shjYt0xr+DQ4hK08U3EUJl+KLLAL1WGEBO+7DnqA3hv4U1M FhOE6SoAvWP5yHpNfyymX1k= X-Google-Smtp-Source: ABdhPJxWiOTBDATWmUT0/XEHaIWadZNAuHe/ThI65GnYp+/wA5AuZbJ+tHEdwZOg2U0+MZ8IrjhN9w== X-Received: by 2002:a17:906:5d07:b0:6ff:40d2:1ff9 with SMTP id g7-20020a1709065d0700b006ff40d21ff9mr34588933ejt.435.1654734532957; Wed, 08 Jun 2022 17:28:52 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id g22-20020aa7c596000000b0042deea0e961sm13110325edq.67.2022.06.08.17.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 17:28:52 -0700 (PDT) From: Christian 'Ansuel' Marangi To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [net-next PATCH 1/2] net: ethernet: stmmac: add missing sgmii configure for ipq806x Date: Thu, 9 Jun 2022 02:28:30 +0200 Message-Id: <20220609002831.24236-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220608_172901_145195_DBEBA498 X-CRM114-Status: GOOD ( 18.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The different gmacid require different configuration based on the soc and on the gmac id. Add these missing configuration taken from the original driver. Signed-off-by: Christian 'Ansuel' Marangi --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + .../ethernet/stmicro/stmmac/dwmac-ipq806x.c | 93 +++++++++++++++---- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 929cfc22cd0c..c4bca16dae57 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -83,6 +83,7 @@ config DWMAC_IPQ806X default ARCH_QCOM depends on OF && (ARCH_QCOM || COMPILE_TEST) select MFD_SYSCON + select QCOM_SOCINFO help Support for QCA IPQ806X DWMAC Ethernet. diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c index f7dc8458cde8..832f442254d8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "stmmac_platform.h" @@ -75,11 +77,20 @@ #define QSGMII_PHY_RX_SIGNAL_DETECT_EN BIT(2) #define QSGMII_PHY_TX_DRIVER_EN BIT(3) #define QSGMII_PHY_QSGMII_EN BIT(7) -#define QSGMII_PHY_PHASE_LOOP_GAIN_OFFSET 12 -#define QSGMII_PHY_RX_DC_BIAS_OFFSET 18 -#define QSGMII_PHY_RX_INPUT_EQU_OFFSET 20 -#define QSGMII_PHY_CDR_PI_SLEW_OFFSET 22 -#define QSGMII_PHY_TX_DRV_AMP_OFFSET 28 +#define QSGMII_PHY_DEEMPHASIS_LVL_MASK GENMASK(11, 10) +#define QSGMII_PHY_DEEMPHASIS_LVL(x) FIELD_PREP(QSGMII_PHY_DEEMPHASIS_LVL_MASK, (x)) +#define QSGMII_PHY_PHASE_LOOP_GAIN_MASK GENMASK(14, 12) +#define QSGMII_PHY_PHASE_LOOP_GAIN(x) FIELD_PREP(QSGMII_PHY_PHASE_LOOP_GAIN_MASK, (x)) +#define QSGMII_PHY_RX_DC_BIAS_MASK GENMASK(19, 18) +#define QSGMII_PHY_RX_DC_BIAS(x) FIELD_PREP(QSGMII_PHY_RX_DC_BIAS_MASK, (x)) +#define QSGMII_PHY_RX_INPUT_EQU_MASK GENMASK(21, 20) +#define QSGMII_PHY_RX_INPUT_EQU(x) FIELD_PREP(QSGMII_PHY_RX_INPUT_EQU_MASK, (x)) +#define QSGMII_PHY_CDR_PI_SLEW_MASK GENMASK(23, 22) +#define QSGMII_PHY_CDR_PI_SLEW(x) FIELD_PREP(QSGMII_PHY_CDR_PI_SLEW_MASK, (x)) +#define QSGMII_PHY_TX_SLEW_MASK GENMASK(27, 26) +#define QSGMII_PHY_TX_SLEW(x) FIELD_PREP(QSGMII_PHY_TX_SLEW_MASK, (x)) +#define QSGMII_PHY_TX_DRV_AMP_MASK GENMASK(31, 28) +#define QSGMII_PHY_TX_DRV_AMP(x) FIELD_PREP(QSGMII_PHY_TX_DRV_AMP_MASK, (x)) struct ipq806x_gmac { struct platform_device *pdev; @@ -242,6 +253,64 @@ static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed) ipq806x_gmac_set_speed(gmac, speed); } +static const struct soc_device_attribute ipq806x_gmac_soc_v1[] = { + { + .revision = "1.*", + }, + { + /* sentinel */ + } +}; + +static int +ipq806x_gmac_configure_qsgmii_params(struct ipq806x_gmac *gmac) +{ + struct platform_device *pdev = gmac->pdev; + const struct soc_device_attribute *soc; + struct device *dev = &pdev->dev; + u32 qsgmii_param; + + switch (gmac->id) { + case 1: + soc = soc_device_match(ipq806x_gmac_soc_v1); + + if (soc) + qsgmii_param = QSGMII_PHY_TX_DRV_AMP(0xc) | + QSGMII_PHY_TX_SLEW(0x2) | + QSGMII_PHY_DEEMPHASIS_LVL(0x2); + else + qsgmii_param = QSGMII_PHY_TX_DRV_AMP(0xd) | + QSGMII_PHY_TX_SLEW(0x0) | + QSGMII_PHY_DEEMPHASIS_LVL(0x0); + + qsgmii_param |= QSGMII_PHY_RX_DC_BIAS(0x2); + break; + case 2: + case 3: + qsgmii_param = QSGMII_PHY_RX_DC_BIAS(0x3) | + QSGMII_PHY_TX_DRV_AMP(0xc); + break; + default: /* gmac 0 can't be set in SGMII mode */ + dev_err(dev, "gmac id %d can't be in SGMII mode", gmac->id); + return -EINVAL; + } + + /* Common params across all gmac id */ + qsgmii_param |= QSGMII_PHY_CDR_EN | + QSGMII_PHY_RX_FRONT_EN | + QSGMII_PHY_RX_SIGNAL_DETECT_EN | + QSGMII_PHY_TX_DRIVER_EN | + QSGMII_PHY_QSGMII_EN | + QSGMII_PHY_PHASE_LOOP_GAIN(0x4) | + QSGMII_PHY_RX_INPUT_EQU(0x1) | + QSGMII_PHY_CDR_PI_SLEW(0x2); + + regmap_write(gmac->qsgmii_csr, QSGMII_PHY_SGMII_CTL(gmac->id), + qsgmii_param); + + return 0; +} + static int ipq806x_gmac_probe(struct platform_device *pdev) { struct plat_stmmacenet_data *plat_dat; @@ -328,17 +397,9 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val); if (gmac->phy_mode == PHY_INTERFACE_MODE_SGMII) { - regmap_write(gmac->qsgmii_csr, QSGMII_PHY_SGMII_CTL(gmac->id), - QSGMII_PHY_CDR_EN | - QSGMII_PHY_RX_FRONT_EN | - QSGMII_PHY_RX_SIGNAL_DETECT_EN | - QSGMII_PHY_TX_DRIVER_EN | - QSGMII_PHY_QSGMII_EN | - 0x4ul << QSGMII_PHY_PHASE_LOOP_GAIN_OFFSET | - 0x3ul << QSGMII_PHY_RX_DC_BIAS_OFFSET | - 0x1ul << QSGMII_PHY_RX_INPUT_EQU_OFFSET | - 0x2ul << QSGMII_PHY_CDR_PI_SLEW_OFFSET | - 0xCul << QSGMII_PHY_TX_DRV_AMP_OFFSET); + err = ipq806x_gmac_configure_qsgmii_params(gmac); + if (err) + goto err_remove_config_dt; } plat_dat->has_gmac = true;