Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp204953rwn; Wed, 7 Sep 2022 15:12:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR66gDRDhZIIYN0/1Ai8Sb3fOBaNXQmAadLV8eLUB+QP3o4Um3nhy76BYs14ao8mIEJ5ZjSM X-Received: by 2002:a05:6402:217:b0:44f:2d3:c8af with SMTP id t23-20020a056402021700b0044f02d3c8afmr4789891edv.388.1662588736391; Wed, 07 Sep 2022 15:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662588736; cv=none; d=google.com; s=arc-20160816; b=GrxlUU+Uup6Uym8vDYMiHSw35iIOfIjGuTRRkk7KVUoUYQimgr+cRRz3tnnCxyrU9E 1IpN+HuJHY53D2BqAopSx0tOxIh+E5iv2vGQJQnY0gtr1RmofhTR5CJMyaEyqIKH+V8e /19I5C4hEQl7OnySP4/fCRjhEq3UqZvjcqCtk8J+akSJWN/Df5mqpgVBKuNn56FmIqbR subLeDKINzBeV5BybP9amCys3g88TVIIttni9BSEuEVGzmwTAh8Blum9BjqjRpLiTtZX zvZj8+A6W7fTg9RpHuHYBeHU72MMr+KQnTPNWAe3mStKQ8gIfJxBEpjfpZygVvL1Esn5 NYGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5+9F9s6fqktfVWWnNP7qsVf3iRyUlMd31YYvVoKbstM=; b=eRJCUy/eDTgvjUHt0MbmAMBD1KPzSn0wOH+1lwWfYctaGzEf9a4h+kde6kctKVZIdw rMXMaXOa5DR9pk04s5M5rukM6nhOH6D85c61+ovK4m2Bnf889huZ/c0/OON1ctNUHppF poKbX7Ew/++XjwlIkV5mC6CjMFTd/WT02cVJTcGzJey7FoQt/BmDmK9QAyoWh9fZK13k VD8JFacV1kLbwcR32cXXvIu7IP0bNNCDwXCgG859b7707HsGh7i9lHlrDRhLaN5fviIq +VgcYlQ4rXoiyVv7lyeoq0nz1lMQGHRZCeZdK7P3jOsiNJXqYx5wehJ3UfPovDfuR3/a wJCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@edgeble-ai.20210112.gappssmtp.com header.s=20210112 header.b="lwys78D/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk17-20020a170906c9d100b0072ab5d0fc33si343028ejb.863.2022.09.07.15.11.51; Wed, 07 Sep 2022 15:12:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@edgeble-ai.20210112.gappssmtp.com header.s=20210112 header.b="lwys78D/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbiIGVHP (ORCPT + 99 others); Wed, 7 Sep 2022 17:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbiIGVHN (ORCPT ); Wed, 7 Sep 2022 17:07:13 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC2F2B07C1 for ; Wed, 7 Sep 2022 14:07:10 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id l65so15828444pfl.8 for ; Wed, 07 Sep 2022 14:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=edgeble-ai.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=5+9F9s6fqktfVWWnNP7qsVf3iRyUlMd31YYvVoKbstM=; b=lwys78D/HG7Xwd4d0necb6nRcqc5E1q9SjJs4QTgDuy6eQ1zpoS73iwBjTvnMRSRRh LR2426cwvek//WF5ATYTbe277Pur4c9wtNFpHx0RuVLGXnhBZiomBVoTJ4sjAjuCZGoF QUf2k4jNHQ+aqr1+VRcLlv8AJ/Z8KOw2t7SHR7nLkwImyfTP3RL9Ep5K6J/SGkVh2QMV dcIJOnImyq7NGbdaTbNXRhabysXWdWpdf5+Y9QRhtST49VOun7Nr8S7f+j06vL8frHL2 UWw5HRfuvi/g1WsRYooW/L4idWz6k7NdhI/36THQpcz6owGynCMtci9sT0vft204Vg2c 1MIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=5+9F9s6fqktfVWWnNP7qsVf3iRyUlMd31YYvVoKbstM=; b=aoOXKF7Zgn7mFlr4v3my44z8g2wvdEGjg7e2xuKsow0CxLZsGSUOGwI2o9W1hyvTsP 7kQ2ZQ6XAAGa7oDF9U6MEAgbYcTvKhaDKUs9A7/RHWXenyFIDs1DbWUlz2pMcyzcLcms 8cws3d9Ihj9q+qMsKeT8cAhd28nHNFpAQ6Jd2zSwAXOvmzoShPsunayRPBiiK7Xmdyq6 LIUkM69ghbCLvtKsyvnfmrK0wiHFdwjXcM4eOjERvYw+9P+GHhkViq0O6FjvylOTrLBb qwElNeHhrK7OkSuj7h1vzYvLz4j3/BNw+SCr1YH6mmKBC2jVf1lkzdDYutVTfFgoJPtA YYkA== X-Gm-Message-State: ACgBeo2BEvGJbpXe6515TYOosyiRLEMWVtq0UMLLX3M71zVh5rBJ4MMM adlff2Pl5sD28VSLpzObS/H21w== X-Received: by 2002:aa7:8e05:0:b0:536:5dda:e634 with SMTP id c5-20020aa78e05000000b005365ddae634mr5519906pfr.35.1662584830196; Wed, 07 Sep 2022 14:07:10 -0700 (PDT) Received: from archl-hc1b.. ([103.51.75.56]) by smtp.gmail.com with ESMTPSA id c23-20020a63d517000000b0042ba1a95235sm10999198pgg.86.2022.09.07.14.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 14:07:09 -0700 (PDT) From: Anand Moon To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: Anand Moon , Sugar Zhang , David Wu , Jagan Teki , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [v2 2/2] net: ethernet: stmicro: stmmac: dwmac-rk: Add rv1126 support Date: Wed, 7 Sep 2022 21:06:46 +0000 Message-Id: <20220907210649.12447-2-anand@edgeble.ai> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220907210649.12447-1-anand@edgeble.ai> References: <20220907210649.12447-1-anand@edgeble.ai> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rockchip RV1126 has GMAC 10/100/1000M ethernet controller via RGMII and RMII interfaces are configured via M0 and M1 pinmux. This patch adds rv1126 support by adding delay lines of M0 and M1 simultaneously. Signed-off-by: Sugar Zhang Signed-off-by: David Wu Signed-off-by: Anand Moon Signed-off-by: Jagan Teki --- v2: changes none --- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index c469abc91fa1..93be3efb5fff 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -1153,6 +1153,130 @@ static const struct rk_gmac_ops rv1108_ops = { .set_rmii_speed = rv1108_set_rmii_speed, }; +#define RV1126_GRF_GMAC_CON0 0X0070 +#define RV1126_GRF_GMAC_CON1 0X0074 +#define RV1126_GRF_GMAC_CON2 0X0078 + +/* RV1126_GRF_GMAC_CON0 */ +#define RV1126_GMAC_PHY_INTF_SEL_RGMII \ + (GRF_BIT(4) | GRF_CLR_BIT(5) | GRF_CLR_BIT(6)) +#define RV1126_GMAC_PHY_INTF_SEL_RMII \ + (GRF_CLR_BIT(4) | GRF_CLR_BIT(5) | GRF_BIT(6)) +#define RV1126_GMAC_FLOW_CTRL GRF_BIT(7) +#define RV1126_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(7) +#define RV1126_GMAC_M0_RXCLK_DLY_ENABLE GRF_BIT(1) +#define RV1126_GMAC_M0_RXCLK_DLY_DISABLE GRF_CLR_BIT(1) +#define RV1126_GMAC_M0_TXCLK_DLY_ENABLE GRF_BIT(0) +#define RV1126_GMAC_M0_TXCLK_DLY_DISABLE GRF_CLR_BIT(0) +#define RV1126_GMAC_M1_RXCLK_DLY_ENABLE GRF_BIT(3) +#define RV1126_GMAC_M1_RXCLK_DLY_DISABLE GRF_CLR_BIT(3) +#define RV1126_GMAC_M1_TXCLK_DLY_ENABLE GRF_BIT(2) +#define RV1126_GMAC_M1_TXCLK_DLY_DISABLE GRF_CLR_BIT(2) + +/* RV1126_GRF_GMAC_CON1 */ +#define RV1126_GMAC_M0_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8) +#define RV1126_GMAC_M0_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0) +/* RV1126_GRF_GMAC_CON2 */ +#define RV1126_GMAC_M1_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8) +#define RV1126_GMAC_M1_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0) + +static void rv1126_set_to_rgmii(struct rk_priv_data *bsp_priv, + int tx_delay, int rx_delay) +{ + struct device *dev = &bsp_priv->pdev->dev; + + if (IS_ERR(bsp_priv->grf)) { + dev_err(dev, "Missing rockchip,grf property\n"); + return; + } + + regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON0, + RV1126_GMAC_PHY_INTF_SEL_RGMII | + RV1126_GMAC_M0_RXCLK_DLY_ENABLE | + RV1126_GMAC_M0_TXCLK_DLY_ENABLE | + RV1126_GMAC_M1_RXCLK_DLY_ENABLE | + RV1126_GMAC_M1_TXCLK_DLY_ENABLE); + + regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON1, + RV1126_GMAC_M0_CLK_RX_DL_CFG(rx_delay) | + RV1126_GMAC_M0_CLK_TX_DL_CFG(tx_delay)); + + regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON2, + RV1126_GMAC_M1_CLK_RX_DL_CFG(rx_delay) | + RV1126_GMAC_M1_CLK_TX_DL_CFG(tx_delay)); +} + +static void rv1126_set_to_rmii(struct rk_priv_data *bsp_priv) +{ + struct device *dev = &bsp_priv->pdev->dev; + + if (IS_ERR(bsp_priv->grf)) { + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); + return; + } + + regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON0, + RV1126_GMAC_PHY_INTF_SEL_RMII); +} + +static void rv1126_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) +{ + struct device *dev = &bsp_priv->pdev->dev; + unsigned long rate; + int ret; + + switch (speed) { + case 10: + rate = 2500000; + break; + case 100: + rate = 25000000; + break; + case 1000: + rate = 125000000; + break; + default: + dev_err(dev, "unknown speed value for RGMII speed=%d", speed); + return; + } + + ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); + if (ret) + dev_err(dev, "%s: set clk_mac_speed rate %ld failed %d\n", + __func__, rate, ret); +} + +static void rv1126_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) +{ + struct device *dev = &bsp_priv->pdev->dev; + unsigned long rate; + int ret; + + switch (speed) { + case 10: + rate = 2500000; + break; + case 100: + rate = 25000000; + break; + default: + dev_err(dev, "unknown speed value for RGMII speed=%d", speed); + return; + } + + ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); + if (ret) + dev_err(dev, "%s: set clk_mac_speed rate %ld failed %d\n", + __func__, rate, ret); +} + +static const struct rk_gmac_ops rv1126_ops = { + .set_to_rgmii = rv1126_set_to_rgmii, + .set_to_rmii = rv1126_set_to_rmii, + .set_rgmii_speed = rv1126_set_rgmii_speed, + .set_rmii_speed = rv1126_set_rmii_speed, +}; + #define RK_GRF_MACPHY_CON0 0xb00 #define RK_GRF_MACPHY_CON1 0xb04 #define RK_GRF_MACPHY_CON2 0xb08 @@ -1681,6 +1805,7 @@ static const struct of_device_id rk_gmac_dwmac_match[] = { { .compatible = "rockchip,rk3399-gmac", .data = &rk3399_ops }, { .compatible = "rockchip,rk3568-gmac", .data = &rk3568_ops }, { .compatible = "rockchip,rv1108-gmac", .data = &rv1108_ops }, + { .compatible = "rockchip,rv1126-gmac", .data = &rv1126_ops }, { } }; MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match); -- 2.37.3