From patchwork Tue Aug 22 04:03:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 9914165 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 A23BD60381 for ; Tue, 22 Aug 2017 04:05:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 949F528831 for ; Tue, 22 Aug 2017 04:05:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8907E283BF; Tue, 22 Aug 2017 04:05:10 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F265C20952 for ; Tue, 22 Aug 2017 04:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=JDwnJ4HjC9BruTbr2ex0LrmAIZ0ESR0c8u/f9eTGcpU=; b=DnqGOLagOSUaRwQbArvBS/Xom4 O9r60kZ0j62UnWANmHS3AsN+Sdm6vlr6dHo2OTledBLYw/YGl/8QhlsJYqetKrIlyYJptUHlTdDnS iHEbY2A6coLRN65UmdB542D56X3A9Q0v/ZZpY1GXigo2C+SMSYnsV6GEceVWGHrzk0b2wvhSZnubj kUUMl+8ARdbkHDUKH0nlweuhlrYGRZDaHQRBkXRanwNdFUq70zNYC7uQR2MieXp8Vz1BejMVqmipd 5foKDr6Vpc1KDb5szktuxmk7h3xcUrs61qBnHUkiJJRhDPc+4p3PPXbcuGZThYpYOUY/J5XNlqdTr DdqzcBRg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dk0R7-0003G5-5D; Tue, 22 Aug 2017 04:05:05 +0000 Received: from egyptian.birch.relay.mailchannels.net ([23.83.209.56]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dk0R2-0002ya-DZ for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2017 04:05:03 +0000 X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 593867CA3CD; Tue, 22 Aug 2017 04:04:40 +0000 (UTC) Received: from hermes.aosc.io (unknown [100.96.145.5]) (Authenticated sender: lmn-TZDUIOWCRQMW) by relay.mailchannels.net (Postfix) with ESMTPA id 773507C91E6; Tue, 22 Aug 2017 04:04:39 +0000 (UTC) X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from hermes.aosc.io (hermes.aosc.io [172.20.82.214]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.9.10); Tue, 22 Aug 2017 04:04:40 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io X-MailChannels-Auth-Id: lmn-TZDUIOWCRQMW X-Bubble-Continue: 78633c4f6a1b8731_1503374680147_232211163 X-MC-Loop-Signature: 1503374680147:1795018293 X-MC-Ingress-Time: 1503374680146 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id D9E6B4546B; Tue, 22 Aug 2017 04:04:34 +0000 (UTC) From: Icenowy Zheng To: Maxime Ripard , Chen-Yu Tsai , Florian Fainelli , Corentin Labbe Subject: [PATCH v2 3/4] net: phy: realtek: add disable RX internal delay mode Date: Tue, 22 Aug 2017 12:03:59 +0800 Message-Id: <20170822040400.12166-4-icenowy@aosc.io> In-Reply-To: <20170822040400.12166-1-icenowy@aosc.io> References: <20170822040400.12166-1-icenowy@aosc.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170821_210500_571243_339E09E7 X-CRM114-Status: GOOD ( 12.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 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, linux-sunxi@googlegroups.com, Icenowy Zheng , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Icenowy Zheng Some RTL8211E chips have broken GbE function, which needs a hack to fix. It's said that this fix will affect the performance on not-buggy PHYs, so it should only be enabled on boards with the broken PHY. Currently only some Pine64+ boards are known to have this issue. This hack is said to disable RX relay for RTL8211E according to Realtek. So implement it as RGMII-TXID mode. As this hack is not documented on the datasheet at all, it contains magic numbers, and could not be revealed. These magic numbers are received from Realtek via Pine64. Signed-off-by: Icenowy Zheng --- Changes in v2: - Used RGMII_TXID phy mode. drivers/net/phy/realtek.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index d820d00addf6..8306b6abaaa8 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -13,6 +13,7 @@ * option) any later version. * */ +#include #include #include @@ -26,6 +27,8 @@ #define RTL8211_PAGE_SELECT 0x1f #define RTL8211E_INER_LINK_STATUS 0x400 +#define RTL8211E_EXT_PAGE_SELECT 0x1e +#define RTL8211E_EXT_PAGE 0x7 #define RTL8211F_INER_LINK_STATUS 0x0010 #define RTL8211F_INSR 0x1d @@ -121,6 +124,33 @@ static int rtl8211f_config_init(struct phy_device *phydev) return 0; } +static int rtl8211e_config_init(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct device_node *of_node = dev->of_node; + int ret; + + ret = genphy_config_init(phydev); + if (ret < 0) + return ret; + + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { + /* Disable the RX internal delay here. + * + * All the magic numbers are not documented on RTL8211E + * datasheet. They're said to be from Realtek by Pine64. + */ + phy_write(phydev, RTL8211_PAGE_SELECT, RTL8211E_EXT_PAGE); + phy_write(phydev, RTL8211E_EXT_PAGE_SELECT, 0xa4); + phy_write(phydev, 0x1c, 0xb591); + + /* Restore to default page 0 */ + phy_write(phydev, RTL8211_PAGE_SELECT, 0); + } + + return 0; +} + static struct phy_driver realtek_drvs[] = { { .phy_id = 0x00008201, @@ -159,6 +189,7 @@ static struct phy_driver realtek_drvs[] = { .features = PHY_GBIT_FEATURES, .flags = PHY_HAS_INTERRUPT, .config_aneg = &genphy_config_aneg, + .config_init = rtl8211e_config_init, .read_status = &genphy_read_status, .ack_interrupt = &rtl821x_ack_interrupt, .config_intr = &rtl8211e_config_intr,