From patchwork Tue Jun 21 07:13:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhengxing X-Patchwork-Id: 9189617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4CAA5601C0 for ; Tue, 21 Jun 2016 07:14:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34D121FF10 for ; Tue, 21 Jun 2016 07:14:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28FD12094F; Tue, 21 Jun 2016 07:14:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 967D31FF10 for ; Tue, 21 Jun 2016 07:14:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFFtO-0005fm-IK; Tue, 21 Jun 2016 07:14:38 +0000 Received: from regular1.263xmail.com ([211.150.99.140]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFFtE-0005J5-GM; Tue, 21 Jun 2016 07:14:30 +0000 Received: from zhengxing?rock-chips.com (unknown [192.168.167.130]) by regular1.263xmail.com (Postfix) with SMTP id 744574AAB; Tue, 21 Jun 2016 15:14:02 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id C2E542CC1; Tue, 21 Jun 2016 15:13:59 +0800 (CST) X-RL-SENDER: zhengxing@rock-chips.com X-FST-TO: heiko@sntech.de X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: zhengxing@rock-chips.com X-UNIQUE-TAG: <52b5a2e082be500e8a2ff71a86f44f9f> X-ATTACHMENT-NUM: 0 X-SENDER: zhengxing@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 1962322JVC4; Tue, 21 Jun 2016 15:14:01 +0800 (CST) From: Xing Zheng To: heiko@sntech.de Subject: [PATCH] net: stmmac: dwmac-rk: add rk322x-specific data Date: Tue, 21 Jun 2016 15:13:55 +0800 Message-Id: <1466493235-17789-1-git-send-email-zhengxing@rock-chips.com> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160621_001429_048886_B2C35B03 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Xing Zheng , Pawel Moll , Ian Campbell , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Rob Herring , roger.chen@rock-chips.com, Kumar Gala , Giuseppe Cavallaro , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Alexandre Torgue MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add constants and callback functions for the dwmac on rk322x socs. As can be seen, the base structure is the same, only registers and the bits in them moved slightly. Signed-off-by: Xing Zheng --- .../devicetree/bindings/net/rockchip-dwmac.txt | 3 +- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 117 ++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/rockchip-dwmac.txt b/Documentation/devicetree/bindings/net/rockchip-dwmac.txt index 93eac7c..5040ed4 100644 --- a/Documentation/devicetree/bindings/net/rockchip-dwmac.txt +++ b/Documentation/devicetree/bindings/net/rockchip-dwmac.txt @@ -3,7 +3,8 @@ Rockchip SoC RK3288 10/100/1000 Ethernet driver(GMAC) The device node has following properties. Required properties: - - compatible: Can be one of "rockchip,rk3288-gmac", "rockchip,rk3368-gmac" + - compatible: Can be one of "rockchip,rk322x-gmac", "rockchip,rk3288-gmac", + "rockchip,rk3368-gmac" - reg: addresses and length of the register sets for the device. - interrupts: Should contain the GMAC interrupts. - interrupt-names: Should contain the interrupt names "macirq". diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 0cd3ecf..7f045db 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -72,6 +72,122 @@ struct rk_priv_data { #define GRF_BIT(nr) (BIT(nr) | BIT(nr+16)) #define GRF_CLR_BIT(nr) (BIT(nr+16)) +#define RK322X_GRF_MAC_CON0 0x0900 +#define RK322X_GRF_MAC_CON1 0x0904 + +/* RK322X_GRF_MAC_CON0 */ +#define RK322X_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 7) +#define RK322X_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0) + +/* RK322X_GRF_MAC_CON1 */ +#define RK322X_GMAC_PHY_INTF_SEL_RGMII \ + (GRF_BIT(4) | GRF_CLR_BIT(5) | GRF_CLR_BIT(6)) +#define RK322X_GMAC_PHY_INTF_SEL_RMII \ + (GRF_CLR_BIT(4) | GRF_CLR_BIT(5) | GRF_BIT(6)) +#define RK322X_GMAC_FLOW_CTRL GRF_BIT(3) +#define RK322X_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(3) +#define RK322X_GMAC_SPEED_10M GRF_CLR_BIT(2) +#define RK322X_GMAC_SPEED_100M GRF_BIT(2) +#define RK322X_GMAC_RMII_CLK_25M GRF_BIT(7) +#define RK322X_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(7) +#define RK322X_GMAC_CLK_125M (GRF_CLR_BIT(8) | GRF_CLR_BIT(9)) +#define RK322X_GMAC_CLK_25M (GRF_BIT(8) | GRF_BIT(9)) +#define RK322X_GMAC_CLK_2_5M (GRF_CLR_BIT(8) | GRF_BIT(9)) +#define RK322X_GMAC_RMII_MODE GRF_BIT(10) +#define RK322X_GMAC_RMII_MODE_CLR GRF_CLR_BIT(10) +#define RK322X_GMAC_TXCLK_DLY_ENABLE GRF_BIT(0) +#define RK322X_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(0) +#define RK322X_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1) +#define RK322X_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(1) + +static void rk322x_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, RK322X_GRF_MAC_CON1, + RK322X_GMAC_PHY_INTF_SEL_RGMII | + RK322X_GMAC_RMII_MODE_CLR | + RK322X_GMAC_RXCLK_DLY_ENABLE | + RK322X_GMAC_TXCLK_DLY_ENABLE); + + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON0, + RK322X_GMAC_CLK_RX_DL_CFG(rx_delay) | + RK322X_GMAC_CLK_TX_DL_CFG(tx_delay)); +} + +static void rk322x_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, "Missing rockchip,grf property\n"); + return; + } + + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_PHY_INTF_SEL_RMII | + RK322X_GMAC_RMII_MODE); + + /* set MAC to RMII mode */ + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, GRF_BIT(11)); +} + +static void rk322x_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) +{ + struct device *dev = &bsp_priv->pdev->dev; + + if (IS_ERR(bsp_priv->grf)) { + dev_err(dev, "Missing rockchip,grf property\n"); + return; + } + + if (speed == 10) + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_CLK_2_5M); + else if (speed == 100) + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_CLK_25M); + else if (speed == 1000) + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_CLK_125M); + else + dev_err(dev, "unknown speed value for RGMII! speed=%d", speed); +} + +static void rk322x_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) +{ + struct device *dev = &bsp_priv->pdev->dev; + + if (IS_ERR(bsp_priv->grf)) { + dev_err(dev, "Missing rockchip,grf property\n"); + return; + } + + if (speed == 10) + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_RMII_CLK_2_5M | + RK322X_GMAC_SPEED_10M); + else if (speed == 100) + regmap_write(bsp_priv->grf, RK322X_GRF_MAC_CON1, + RK322X_GMAC_RMII_CLK_25M | + RK322X_GMAC_SPEED_100M); + else + dev_err(dev, "unknown speed value for RMII! speed=%d", speed); +} + +static const struct rk_gmac_ops rk322x_ops = { + .set_to_rgmii = rk322x_set_to_rgmii, + .set_to_rmii = rk322x_set_to_rmii, + .set_rgmii_speed = rk322x_set_rgmii_speed, + .set_rmii_speed = rk322x_set_rmii_speed, +}; + #define RK3288_GRF_SOC_CON1 0x0248 #define RK3288_GRF_SOC_CON3 0x0250 @@ -604,6 +720,7 @@ static int rk_gmac_probe(struct platform_device *pdev) } static const struct of_device_id rk_gmac_dwmac_match[] = { + { .compatible = "rockchip,rk322x-gmac", .data = &rk322x_ops }, { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_ops }, { .compatible = "rockchip,rk3368-gmac", .data = &rk3368_ops }, { }