Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4850567imm; Tue, 26 Jun 2018 01:24:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKoa38jOH7nTRLscXfL1o95n9xRwioVb1Et2btPymBBqs9qHpEOVfsPypqc3q00WSgjlp+0 X-Received: by 2002:a65:6147:: with SMTP id o7-v6mr492480pgv.163.1530001468239; Tue, 26 Jun 2018 01:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530001468; cv=none; d=google.com; s=arc-20160816; b=pHyqebJ2oBfF9gqIf7ScHoJvoIrlmvWYLagziXXftDM6ZUQ84tQD5DFqdEHEkJYvgn V/57D7Kt6bj9TJInk9fwMoggQjmndNizwTLAbzyNF8VAXHxX5NPZjZyHv2Zh/LECm2Tu i8M8Mp+p+27JUSyxKrA/9Wgyz88xqDS7r0W8SEcnP7tuyyTBb9/1BCg/3vwwExLJbQiO RAvtmAOmFci1RhCMoCFOQz4lbWS2SZsF98e6ylM7+eDTvMOvtdrM7Ps3oin3AO5EimXl fDkYoTz9gDXlx6JcBsL71oP0qk4sfEI/Fxf5h7Xl9n/p8NILqs3Dx9m/6Oh9op3hxTse dyAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=E+YtlG0Cjzu64QB+ukESxZl8+LdUUQc4up5udxtJFVM=; b=oAl9D0VFBGzrc1Qbc+A3vIT77yijEXWASnfuXXpOgl2gxaWqniWbWZzngycr1rz+3W Bz/TEh/K3CUGOkqzsfME0KghC6q+9OG8IsRB+cxrDnqMVtXkSazwgueJ9vMsM95hlSEX UM+6c/0Nr4lld2wVWQlUqc3VfsQS2ClmUy3OJwaXmCLf+/LFzwBbdJcpHpR+5rwD19Hu xQd3e+5srfLUix6htvy3hsHWHkK1IFTpNQoB4UjVbHSvuvqty5QYdSibnAbDmrh49DRG rxdP5/3Es/Gcz6PgIG9Y7zihemRUP7e8OMvDZwGJhSX6ypuFANP4aep3ONNBGz2o07YW YZoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 85-v6si1113980pfm.264.2018.06.26.01.24.13; Tue, 26 Jun 2018 01:24:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933185AbeFZIWK (ORCPT + 99 others); Tue, 26 Jun 2018 04:22:10 -0400 Received: from regular1.263xmail.com ([211.150.99.139]:52993 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932353AbeFZIVt (ORCPT ); Tue, 26 Jun 2018 04:21:49 -0400 Received: from david.wu?rock-chips.com (unknown [192.168.167.228]) by regular1.263xmail.com (Postfix) with ESMTP id CAE444CDC; Tue, 26 Jun 2018 16:21:39 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 9BC363AA; Tue, 26 Jun 2018 16:21:39 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: david.wu@rock-chips.com X-FST-TO: davem@davemloft.net X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: david.wu@rock-chips.com X-UNIQUE-TAG: <46fc8abc335ef140bf9b24bdb3894f9b> X-ATTACHMENT-NUM: 0 X-SENDER: wdc@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 25256WKL5W5; Tue, 26 Jun 2018 16:21:41 +0800 (CST) From: David Wu To: davem@davemloft.net, heiko@sntech.de, robh+dt@kernel.org Cc: mark.rutland@arm.com, huangtao@rock-chips.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, David Wu Subject: [PATCH v3] net: ethernet: stmmac: dwmac-rk: Add GMAC support for px30 Date: Tue, 26 Jun 2018 16:19:33 +0800 Message-Id: <1530001173-21935-1-git-send-email-david.wu@rock-chips.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add constants and callback functions for the dwmac on px30 Soc. The base structure is the same, but registers and the bits in them are moved slightly, and add the clk_mac_speed for selecting mac speed. Signed-off-by: David Wu --- Change in v3: - Add the clock enable/disable for clk_mac_speed. Change in v2: - Fix some error in commit title and message. .../devicetree/bindings/net/rockchip-dwmac.txt | 1 + drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 71 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Documentation/devicetree/bindings/net/rockchip-dwmac.txt b/Documentation/devicetree/bindings/net/rockchip-dwmac.txt index 9c16ee2..3b71da7 100644 --- a/Documentation/devicetree/bindings/net/rockchip-dwmac.txt +++ b/Documentation/devicetree/bindings/net/rockchip-dwmac.txt @@ -4,6 +4,7 @@ The device node has following properties. Required properties: - compatible: should be "rockchip,-gamc" + "rockchip,px30-gmac": found on PX30 SoCs "rockchip,rk3128-gmac": found on RK312x SoCs "rockchip,rk3228-gmac": found on RK322x SoCs "rockchip,rk3288-gmac": found on RK3288 SoCs diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 13133b3..fc5fef7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -61,6 +61,7 @@ struct rk_priv_data { struct clk *mac_clk_tx; struct clk *clk_mac_ref; struct clk *clk_mac_refout; + struct clk *clk_mac_speed; struct clk *aclk_mac; struct clk *pclk_mac; struct clk *clk_phy; @@ -83,6 +84,64 @@ struct rk_priv_data { (((tx) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \ ((rx) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE)) +#define PX30_GRF_GMAC_CON1 0x0904 + +/* PX30_GRF_GMAC_CON1 */ +#define PX30_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(4) | GRF_CLR_BIT(5) | \ + GRF_BIT(6)) +#define PX30_GMAC_SPEED_10M GRF_CLR_BIT(2) +#define PX30_GMAC_SPEED_100M GRF_BIT(2) + +static void px30_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, PX30_GRF_GMAC_CON1, + PX30_GMAC_PHY_INTF_SEL_RMII); +} + +static void px30_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) +{ + struct device *dev = &bsp_priv->pdev->dev; + int ret; + + if (IS_ERR(bsp_priv->clk_mac_speed)) { + dev_err(dev, "%s: Missing clk_mac_speed clock\n", __func__); + return; + } + + if (speed == 10) { + regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, + PX30_GMAC_SPEED_10M); + + ret = clk_set_rate(bsp_priv->clk_mac_speed, 2500000); + if (ret) + dev_err(dev, "%s: set clk_mac_speed rate 2500000 failed: %d\n", + __func__, ret); + } else if (speed == 100) { + regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, + PX30_GMAC_SPEED_100M); + + ret = clk_set_rate(bsp_priv->clk_mac_speed, 25000000); + if (ret) + dev_err(dev, "%s: set clk_mac_speed rate 25000000 failed: %d\n", + __func__, ret); + + } else { + dev_err(dev, "unknown speed value for RMII! speed=%d", speed); + } +} + +static const struct rk_gmac_ops px30_ops = { + .set_to_rmii = px30_set_to_rmii, + .set_rmii_speed = px30_set_rmii_speed, +}; + #define RK3128_GRF_MAC_CON0 0x0168 #define RK3128_GRF_MAC_CON1 0x016c @@ -1042,6 +1101,10 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat) } } + bsp_priv->clk_mac_speed = devm_clk_get(dev, "clk_mac_speed"); + if (IS_ERR(bsp_priv->clk_mac_speed)) + dev_err(dev, "cannot get clock %s\n", "clk_mac_speed"); + if (bsp_priv->clock_input) { dev_info(dev, "clock input from PHY\n"); } else { @@ -1094,6 +1157,9 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable) if (!IS_ERR(bsp_priv->mac_clk_tx)) clk_prepare_enable(bsp_priv->mac_clk_tx); + if (!IS_ERR(bsp_priv->clk_mac_speed)) + clk_prepare_enable(bsp_priv->clk_mac_speed); + /** * if (!IS_ERR(bsp_priv->clk_mac)) * clk_prepare_enable(bsp_priv->clk_mac); @@ -1128,6 +1194,10 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable) if (!IS_ERR(bsp_priv->mac_clk_tx)) clk_disable_unprepare(bsp_priv->mac_clk_tx); + + if (!IS_ERR(bsp_priv->clk_mac_speed)) + clk_disable_unprepare(bsp_priv->clk_mac_speed); + /** * if (!IS_ERR(bsp_priv->clk_mac)) * clk_disable_unprepare(bsp_priv->clk_mac); @@ -1424,6 +1494,7 @@ static int rk_gmac_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(rk_gmac_pm_ops, rk_gmac_suspend, rk_gmac_resume); static const struct of_device_id rk_gmac_dwmac_match[] = { + { .compatible = "rockchip,px30-gmac", .data = &px30_ops }, { .compatible = "rockchip,rk3128-gmac", .data = &rk3128_ops }, { .compatible = "rockchip,rk3228-gmac", .data = &rk3228_ops }, { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_ops }, -- 2.7.4