From patchwork Sat Dec 2 21:51:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10089051 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 0E1B560380 for ; Sat, 2 Dec 2017 21:52:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F33D82943F for ; Sat, 2 Dec 2017 21:52:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E81F229442; Sat, 2 Dec 2017 21:52:22 +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 7B7EE2944B for ; Sat, 2 Dec 2017 21:52:22 +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=PZ4dc+j7iZBq+7xS09BoRIzoJBt2aptoc4ex/kNmtKo=; b=h5BsJFjgQk/LtKIAv7fj4zKsqJ dKP1wPXUh6cA6bbmenUmHIuB0EOGg8cySgLkPmWGIFWqz1G3y9W0NgIDdfoLeQj6Ju2VfPLCCcaaL n16u767o6wTcCzQ7Z9weU963IAr8vHkL7jfNhzz5qAHtTT/IeSOfe9BX7sdLcwOPeeoqlh97v3yDd NTBE7vNyM5vWco1kUUn3JQ/BoMCl6cbuzGsWsVaWZm68UncM4OSlJrEVlSXQ/dtVJ6v5lIzwxCoTC hjz9mgWQkQoPZV0nrQSFvyIqIOOYt1RXohQ2ocA106pPQDF97S0RJlIrpg5qKL4KBINrHkHZ3KvvH 1J+CHzOw==; 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 1eLFho-0002a8-Qm; Sat, 02 Dec 2017 21:52:16 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLFhg-0002Rh-3F for linux-amlogic@lists.infradead.org; Sat, 02 Dec 2017 21:52:10 +0000 Received: by mail-wm0-x243.google.com with SMTP id l141so8950019wmg.1 for ; Sat, 02 Dec 2017 13:51:50 -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=//ZE5JWH5B1qbrm63rMXObqvYtMmaEqhZ281M4k1bWs=; b=E+WtS626fW2K34KLbkratAm5OZtsPchOZY/E1YIR7bWH5ltbpNoHps7d4ndDvhR0ri /w6ww/Ablo/D+yNzrxztT8OuobcaCWcKtwAJ4JgONo6qIv7E48MQdvKWEeNqDHKL4aH0 4LgB8jRi3gJUTCf7u2nOz2QNldkiYW4pgDw5PIggqKZEzPZ4MWgIpcaW4oFWcHUhlZOu mIudIWn58K4po+hKYawv2W19T4tjHsfQsTrbViRtIZlYIySCkHzKDJXhJu2K1q2mr8uJ TIAhGxloZoQ2+8b5y3ocAzqpmAiGIsFwc5x0jM35/Oary02lHqfXFjIa3Rnlofc66xuQ nUVw== 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=//ZE5JWH5B1qbrm63rMXObqvYtMmaEqhZ281M4k1bWs=; b=NCFdF6PkpJFK5shMahS9qqTZ2T7F+UjgXYzh7SVRrsghVyhSkbqOXNzgUw4RMxCzea aY2ETGFSO1JI66SHHX6spk6BBt+6Kqg3+vP0ynk2K3SwLHU+fbT/YpbUyli94MGc08m/ FM4/vP9G4o8uFBiWulJYRZ5xk3zTItn8FxmTlCce+L2D0ENa7gmJNiIch/2a5kw/Ima6 vf6X/WfhUn1ArHgFWjbwwSgsGRNej+l0DhAFJgfEvSW2vUAEI6vv3y32hUTR3Sd4jy6G T0+zXFSJ13nlZBj8vcHRyw/wmDqYGJ87ZeWXMqm5IwKaV8hdKM407O7c6+XAZ6YkCKqW RYvg== X-Gm-Message-State: AKGB3mKYMWrR1EFYrXChMJxcWJVxjcDbFTa2NAaHchRYy5oqji8fCM6M dr6tkiEJIJ1K0ylkShnKIac= X-Google-Smtp-Source: AGs4zMYgsLAsURYzTC0eyZVkZcLi1T1PNir1BGS6cUKtJb0JZuiRpoHAInnpCw67Gv7GhkF3F/YQvg== X-Received: by 10.28.175.8 with SMTP id y8mr4239718wme.21.1512251509630; Sat, 02 Dec 2017 13:51:49 -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 j10sm9770641wrh.32.2017.12.02.13.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Dec 2017 13:51:49 -0800 (PST) From: Martin Blumenstingl To: netdev@vger.kernel.org Subject: [PATCH net-next 5/5] net: phy: realtek: add utility functions to read/write page addresses Date: Sat, 2 Dec 2017 22:51:28 +0100 Message-Id: <20171202215128.20202-6-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171202215128.20202-1-martin.blumenstingl@googlemail.com> References: <20171202215128.20202-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171202_135208_355846_F7262E81 X-CRM114-Status: GOOD ( 14.89 ) 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 Realtek PHYs implement the concept of so-called "extension pages". The reason for this is probably because these PHYs expose more registers than available in the standard address range. After all read/write operations on such a page are done the driver should switch back to page 0 where the standard MII registers (such as MII_BMCR) are available. When referring to such a register the datasheets of RTL8211E and RTL8211F always specify: - the page / "ext. page" which has to be written to RTL821x_PAGE_SELECT - an address (sometimes also called reg) These new utility functions make the existing code easier to read since it removes some duplication (switching back to page 0 is done within the new helpers for example). No functional changes are intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Andrew Lunn --- drivers/net/phy/realtek.c | 83 ++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index d6868e8daaab..5416ec5af042 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -41,6 +41,39 @@ MODULE_DESCRIPTION("Realtek PHY driver"); MODULE_AUTHOR("Johnson Leung"); MODULE_LICENSE("GPL"); +static int rtl8211x_page_read(struct phy_device *phydev, u16 page, u16 address) +{ + int ret; + + ret = phy_write(phydev, RTL821x_PAGE_SELECT, page); + if (ret) + return ret; + + ret = phy_read(phydev, address); + + /* restore to default page 0 */ + phy_write(phydev, RTL821x_PAGE_SELECT, 0x0); + + return ret; +} + +static int rtl8211x_page_write(struct phy_device *phydev, u16 page, + u16 address, u16 val) +{ + int ret; + + ret = phy_write(phydev, RTL821x_PAGE_SELECT, page); + if (ret) + return ret; + + ret = phy_write(phydev, address, val); + + /* restore to default page 0 */ + phy_write(phydev, RTL821x_PAGE_SELECT, 0x0); + + return ret; +} + static int rtl8201_ack_interrupt(struct phy_device *phydev) { int err; @@ -63,31 +96,21 @@ static int rtl8211f_ack_interrupt(struct phy_device *phydev) { int err; - phy_write(phydev, RTL821x_PAGE_SELECT, 0xa43); - err = phy_read(phydev, RTL8211F_INSR); - /* restore to default page 0 */ - phy_write(phydev, RTL821x_PAGE_SELECT, 0x0); + err = rtl8211x_page_read(phydev, 0xa43, RTL8211F_INSR); return (err < 0) ? err : 0; } static int rtl8201_config_intr(struct phy_device *phydev) { - int err; - - /* switch to page 7 */ - phy_write(phydev, RTL821x_PAGE_SELECT, 0x7); + u16 val; if (phydev->interrupts == PHY_INTERRUPT_ENABLED) - err = phy_write(phydev, RTL8201F_IER, - BIT(13) | BIT(12) | BIT(11)); + val = BIT(13) | BIT(12) | BIT(11); else - err = phy_write(phydev, RTL8201F_IER, 0); + val = 0; - /* restore to default page 0 */ - phy_write(phydev, RTL821x_PAGE_SELECT, 0x0); - - return err; + return rtl8211x_page_write(phydev, 0x7, RTL8201F_IER, val); } static int rtl8211b_config_intr(struct phy_device *phydev) @@ -118,41 +141,41 @@ static int rtl8211e_config_intr(struct phy_device *phydev) static int rtl8211f_config_intr(struct phy_device *phydev) { - int err; + u16 val; - phy_write(phydev, RTL821x_PAGE_SELECT, 0xa42); if (phydev->interrupts == PHY_INTERRUPT_ENABLED) - err = phy_write(phydev, RTL821x_INER, - RTL8211F_INER_LINK_STATUS); + val = RTL8211F_INER_LINK_STATUS; else - err = phy_write(phydev, RTL821x_INER, 0); - phy_write(phydev, RTL821x_PAGE_SELECT, 0); + val = 0; - return err; + return rtl8211x_page_write(phydev, 0xa42, RTL821x_INER, val); } static int rtl8211f_config_init(struct phy_device *phydev) { int ret; - u16 reg; + u16 val; ret = genphy_config_init(phydev); if (ret < 0) return ret; - phy_write(phydev, RTL821x_PAGE_SELECT, 0xd08); - reg = phy_read(phydev, 0x11); + ret = rtl8211x_page_read(phydev, 0xd08, 0x11); + if (ret < 0) + return ret; + + val = ret & 0xffff; /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */ if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) - reg |= RTL8211F_TX_DELAY; + val |= RTL8211F_TX_DELAY; else - reg &= ~RTL8211F_TX_DELAY; + val &= ~RTL8211F_TX_DELAY; - phy_write(phydev, 0x11, reg); - /* restore to default page 0 */ - phy_write(phydev, RTL821x_PAGE_SELECT, 0x0); + ret = rtl8211x_page_write(phydev, 0xd08, 0x11, val); + if (ret) + return ret; return 0; }