From patchwork Sat Dec 2 22:06:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10089059 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 BFB7860234 for ; Sat, 2 Dec 2017 22:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99D1B29085 for ; Sat, 2 Dec 2017 22:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AC0F29449; Sat, 2 Dec 2017 22:07:39 +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, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED 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 9E4A328AD0 for ; Sat, 2 Dec 2017 22:07:38 +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=W05NayZYxOsCW+uTXfrpmHSHvNuvCSg5i+ymf14SJQ4=; b=WH4YVZOru0hcZlNiI8Mlzo++SM F2jMXlO4irvf51TTxOXJuv0TB24YezZ9ZJE6+WH909D8o4zyH/3L+WhQ98t11GkWQ+4ybq5/jg8sm 88UbcPT9M0m+tOAi8nuBT9nHOirCbxSAlP1g1tuHm5p/eTd6LvLM8/nWpT995+I70Gsj+KKkqGYEh UuyTeTIVKFqaSJSzJIc+rgvqwiB7y1Z8rd1dJVSpQzV6L8EgRPo1FDDyaGWc/Nu9spn3YbLXtpJk4 L47/zkImjT+RwU8Vj5qM1GI5eXXEyorTdTr4hmn80f7OPqJBfS2Xp8pQGHh46vDC7BHK1WIf3BK+t ebth2WZw==; 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 1eLFwX-0008P3-4f; Sat, 02 Dec 2017 22:07:29 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLFwU-0008MK-MO for linux-amlogic@lists.infradead.org; Sat, 02 Dec 2017 22:07:28 +0000 Received: by mail-wm0-x241.google.com with SMTP id r78so8972269wme.5 for ; Sat, 02 Dec 2017 14:07:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=acb6azYeyP0OmWvijj3LCOKNLTDj/YgKL6t/z41UiVU=; b=vai/HAK1+Tsh65gONkOEihHGYzBCOduU+8SB6m773el6Rhr/QCKZ9TxZTXwbJUYDf7 MhXpXM7D462kRlsh36r5Jm3WhD3z2D4/Q4pxv8v8PFRhi1FM6VIw+4yvfGsHST/VcoCB zuDQ961TyRiiDFXz5fYoOOSIG5bZOVvoz+pJnuqiZ9CWg7MQbFJQGsBba27t7pa8jAbP nTy00U/xTzURCfdWgF/kxZyz5haaoMqjj5KlfK8NJrsG3wDl1uSS9144KOgeTn4Iy0I/ /IGnNV/+jlzBESSEi0Er43Mcd9JW6ro2mie/wvgyk2Q7fEZoPD81hscOy275b8ExOqZ5 hVJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=acb6azYeyP0OmWvijj3LCOKNLTDj/YgKL6t/z41UiVU=; b=TUha5ealWK8DJkfWw0V9X6456lh6vL/Bs4UfUN+UOrbqdAjIA/fa1+qJXScMzA1TZR 2VHQQtOrMrpkF89Acuy2BhUaM+Lro4zEMa7m14gQIzRZcfI5sq5RAbrKWFJiGeeYIN3j JmmUSRcmEvHB+U371XyhgmUAj8e6xMqW6PdIXtxT/4NkL9qw9i3gs3oNaSr+frC/cQps KHTTfxz2520lr9VNLyrprF7agVnflRKZwzBMGG/daK4B8WogmJUkL0I7qjRexveZ5A0i 1ok6JEpDtpGp8qUKdQd3X3/PdKorzHMd7bjP+c2ZWwPAXWjIur+171/fNP861NT4uGVa JmMA== X-Gm-Message-State: AKGB3mIdT83895ElFkhqqaExPzTvWXUJrpak78Y5XyJJyLOpEiQeA3KO g9D74Y3FRJeQHM+HUqN3hKw= X-Google-Smtp-Source: AGs4zMZdZ4JvmVpORj6UNiah33vJHtEBchIN//q7Pxw29uoEHqMdO4ehNvDd/0tcosIbRZGzSnNw/w== X-Received: by 10.28.207.8 with SMTP id f8mr3721091wmg.30.1512252425092; Sat, 02 Dec 2017 14:07:05 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD3EE8B0450E3B0AB6D937D82.dip0.t-ipconnect.de. [2003:dc:d3ee:8b04:50e3:b0ab:6d93:7d82]) by smtp.googlemail.com with ESMTPSA id m64sm4311944wmb.10.2017.12.02.14.07.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Dec 2017 14:07:04 -0800 (PST) From: Martin Blumenstingl To: netdev@vger.kernel.org Subject: [RfC net-next 1/3] net: phy: realtek: add support for configuring the RX delay on RTL8211F Date: Sat, 2 Dec 2017 23:06:48 +0100 Message-Id: <20171202220650.23391-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171202220650.23391-1-martin.blumenstingl@googlemail.com> References: <20171202220650.23391-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171202_140726_938851_2294CAF1 X-CRM114-Status: GOOD ( 14.77 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andrew@lunn.ch, f.fainelli@gmail.com, Martin Blumenstingl , Shengzhou.Liu@freescale.com, jaswinder.singh@linaro.org, linux-amlogic@lists.infradead.org, hkallweit1@gmail.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On RTL8211F the RX delay can also be enabled/disabled. The overall behavior of the RX delay is similar to the behavior of the TX delay, which was already supported by the driver. The RX delay (similar to the TX delay) may be enabled using hardware pin strapping. If the MAC already configures the RX delay (if required) then the RX delay generated by the RTL8211F PHY has to be turned off. While here, update the comment regarding the TX delay why it has to be enabled or disabled within the driver. Also avoid code-duplication by extracting the code to mask/unmask bits in a paged register into a new rtl8211x_page_mask_bits helper function. Signed-off-by: Martin Blumenstingl --- drivers/net/phy/realtek.c | 55 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 5416ec5af042..d4e7f249a4bc 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -32,7 +32,10 @@ #define RTL8211F_INSR 0x1d -#define RTL8211F_TX_DELAY BIT(8) +#define RTL8211F_RX_DELAY_REG 0x15 +#define RTL8211F_RX_DELAY_EN BIT(3) +#define RTL8211F_TX_DELAY_REG 0x11 +#define RTL8211F_TX_DELAY_EN BIT(8) #define RTL8201F_ISR 0x1e #define RTL8201F_IER 0x13 @@ -74,6 +77,23 @@ static int rtl8211x_page_write(struct phy_device *phydev, u16 page, return ret; } +static int rtl8211x_page_mask_bits(struct phy_device *phydev, u16 page, + u16 address, u16 mask, u16 set) +{ + int ret; + u16 val; + + ret = rtl8211x_page_read(phydev, page, address); + if (ret < 0) + return ret; + + val = ret & 0xffff; + val &= ~mask; + val |= (set & mask); + + return rtl8211x_page_write(phydev, page, address, val); +} + static int rtl8201_ack_interrupt(struct phy_device *phydev) { int err; @@ -160,20 +180,35 @@ static int rtl8211f_config_init(struct phy_device *phydev) if (ret < 0) return ret; - ret = rtl8211x_page_read(phydev, 0xd08, 0x11); - if (ret < 0) - return ret; + /* + * enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it. + * this is needed because it can be enabled by pin strapping and + * conflict with the TX-delay configured by the MAC. + */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) + val = RTL8211F_TX_DELAY_EN; + else + val = 0; - val = ret & 0xffff; + ret = rtl8211x_page_mask_bits(phydev, 0xd08, RTL8211F_TX_DELAY_REG, + RTL8211F_TX_DELAY_EN, val); + if (ret) + return ret; - /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */ + /* + * enable RX-delay for rgmii-id and rgmii-rxid, otherwise disable it. + * this is needed because it can be enabled by pin strapping and + * conflict with the RX-delay configured by the MAC. + */ if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || - phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) - val |= RTL8211F_TX_DELAY; + phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) + val = RTL8211F_RX_DELAY_EN; else - val &= ~RTL8211F_TX_DELAY; + val = 0; - ret = rtl8211x_page_write(phydev, 0xd08, 0x11, val); + ret = rtl8211x_page_mask_bits(phydev, 0xd08, RTL8211F_RX_DELAY_REG, + RTL8211F_RX_DELAY_EN, val); if (ret) return ret;