From patchwork Wed Mar 26 21:21:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Klein X-Patchwork-Id: 14030557 X-Patchwork-Delegate: kuba@kernel.org Received: from mo4-p01-ob.smtp.rzone.de (mo4-p01-ob.smtp.rzone.de [85.215.255.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4219123AE79; Wed, 26 Mar 2025 21:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=85.215.255.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024101; cv=pass; b=O7PxjmRwXbTzgbf7zjonscdPOSmnUg5bkSvgKdDOxTz9IWzCIlIFnnq5sgeVRkSUl7l8O41fILUpJJARiE6/4AZ5LDL890CUBotc10bDQLrMlwGgWDHMiy2MXNJjoK+3YXN54wKv2KUPXeHNqP0MCQ2b1ucF5ItnJ75LMLOLFR0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024101; c=relaxed/simple; bh=pWwN1fHpqKDNb8P33HMUlglgT5oRXv79Ga1dRUm3KX0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qgYY84fhl2tDaNnj/yUsHYaWtUmIInXSpCkVBVuH++WXcmL+yKtVi+BTJNfO2nqizxSpzMsXTB2EUStMU9Hs0bSYWZPvH7aExUV+5ZGCX6Sc3uTbF2fHn0ezJEoLdZx5O7ypBSqL5ZggKJDaKRUZSh3B8sxV99knOZLdzZyPUKY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de; spf=pass smtp.mailfrom=a98shuttle.de; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=rqH8yA98; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=TM72ppF0; arc=pass smtp.client-ip=85.215.255.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=a98shuttle.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="rqH8yA98"; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="TM72ppF0" ARC-Seal: i=1; a=rsa-sha256; t=1743024090; cv=none; d=strato.com; s=strato-dkim-0002; b=IgU6YfFYT1FnmQNQFV4aSMVRJgb6nnSPR2Xt5xLnG/Pc0wTgGdL9gz/rmy75GX+9tv Vj/lNbEFcWvaz/FZnyQHXe7WiNVgnU4deKph1xr7A2gSJVZ6DWONs9omd38u816j22z6 FFCRIK3AysLM/fWMjH1SaDTaDVCkDM27TY877dvbR6Fse7hS3oUqtYxgsuCimnX9MnwA vj4/4926uqep36bvJAeszvOVlKVORwzpsBRa6k9Y3EdsiVcss2E1l8KZmoviIA24gTY5 s0A11wSw4mfjyge6oVeKwhhx4yxvQZxvvEjn//2GUv/lqKrrmpzCaG3i/bZTXloWYUd4 uMoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024090; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DRQWVNflVTSKFHFB9UYyJnOIp+l42TmftpYogCcmRdw=; b=UCihouW8TeHkbkggDKHdRo5x1YmdvRxWNtiXLmj67IHwYEviOeMuBoJ7sQA+u2XgM+ ovgknh/Mqs29iSc0YsNCQ7yrrZJEIB3L6DZHgjeSXtXzFsrg4opZO0EvWqWW+OUYH0SZ 4A5KEihjfYmezxccH7AfBlQIDAVPIeDyjaABV+qSDvZohM6pU15PSRPJqb7SmUuqV3Sf Q9Xf+Aza25VvDgsEDyeEzsFoQpFpVkidNfucZ4uuG3R9tKlw5Lq+JGwtqKxzfZtchWWz +ZMLb1XmOt1dAxdx7mR7ht1xarPIpF/sWY/x81E0CW7xDlxqR8+dw1pLJIl28kOC6VBb 6v/A== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024090; s=strato-dkim-0002; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DRQWVNflVTSKFHFB9UYyJnOIp+l42TmftpYogCcmRdw=; b=rqH8yA98e93pKOxJSdvN57PXbZ230fTB25qqwlBbL3i5K6jvH68VkWFV0mqH+9WVsL E+XhWuPwklk4HLKvrRaIKkinYKeCNBktwmg20Mok5rX5NAW1XZUCPGvpIMUD188DcBSc u2vVuOf4hZyqTi7XIR+MegkEowp060TwlkmN7KH2AJVJOpQ6xij3WFy0BurXnpAcl/DH 09bK4EZHZ3WXHGd2bxNEk3ijr3AdhiigzvlC5aEX2u5TtepSBvsYUP9d6ZMKUNOeHoG/ ui9xM5RQYLhW3/oPBp4tL6/hAd9elrf6OoWHccYaXb7hGaoopMxGbdhzrehsyz2FPwrU LHDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1743024090; s=strato-dkim-0003; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DRQWVNflVTSKFHFB9UYyJnOIp+l42TmftpYogCcmRdw=; b=TM72ppF0Jt4aJodxAr8EVMXDKw32JGbPB4X9EtU0oIESniVfLBqh2M48sKI0AAxKGX ryL8Hwwu9HGyHV+pfGAQ== X-RZG-AUTH: ":O2kGeEG7b/pS1EzgE2y7nF0STYsSLflpbjNKxx7cGrBdao6FTL4AJcMdm+lap4JEHkzok9eyEg==" Received: from aerfugl by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id f28b3512QLLU1Hy (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 26 Mar 2025 22:21:30 +0100 (CET) Received: from koltrast.home ([192.168.1.27] helo=a98shuttle.de) by aerfugl with smtp (Exim 4.96) (envelope-from ) id 1txYBl-0000hv-0t; Wed, 26 Mar 2025 22:21:29 +0100 Received: (nullmailer pid 100268 invoked by uid 502); Wed, 26 Mar 2025 21:21:29 -0000 From: Michael Klein To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Michael Klein , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next v5 1/4] net: phy: realtek: Group RTL82* macro definitions Date: Wed, 26 Mar 2025 22:21:22 +0100 Message-Id: <20250326212125.100218-2-michael@fossekall.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250326212125.100218-1-michael@fossekall.de> References: <20250326212125.100218-1-michael@fossekall.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Group macro definitions by chip number in lexicographic order. Signed-off-by: Michael Klein --- drivers/net/phy/realtek/realtek_main.c | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 893c82479671..b27c0f995e56 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -17,6 +17,15 @@ #include "realtek.h" +#define RTL8201F_ISR 0x1e +#define RTL8201F_ISR_ANERR BIT(15) +#define RTL8201F_ISR_DUPLEX BIT(13) +#define RTL8201F_ISR_LINK BIT(11) +#define RTL8201F_ISR_MASK (RTL8201F_ISR_ANERR | \ + RTL8201F_ISR_DUPLEX | \ + RTL8201F_ISR_LINK) +#define RTL8201F_IER 0x13 + #define RTL821x_PHYSR 0x11 #define RTL821x_PHYSR_DUPLEX BIT(13) #define RTL821x_PHYSR_SPEED GENMASK(15, 14) @@ -31,6 +40,10 @@ #define RTL821x_EXT_PAGE_SELECT 0x1e #define RTL821x_PAGE_SELECT 0x1f +#define RTL8211E_CTRL_DELAY BIT(13) +#define RTL8211E_TX_DELAY BIT(12) +#define RTL8211E_RX_DELAY BIT(11) + #define RTL8211F_PHYCR1 0x18 #define RTL8211F_PHYCR2 0x19 #define RTL8211F_CLKOUT_EN BIT(0) @@ -47,6 +60,8 @@ #define RTL8211F_LEDCR_MASK GENMASK(4, 0) #define RTL8211F_LEDCR_SHIFT 5 +#define RTL8211F_LED_COUNT 3 + #define RTL8211F_TX_DELAY BIT(8) #define RTL8211F_RX_DELAY BIT(3) @@ -54,19 +69,6 @@ #define RTL8211F_ALDPS_ENABLE BIT(2) #define RTL8211F_ALDPS_XTAL_OFF BIT(12) -#define RTL8211E_CTRL_DELAY BIT(13) -#define RTL8211E_TX_DELAY BIT(12) -#define RTL8211E_RX_DELAY BIT(11) - -#define RTL8201F_ISR 0x1e -#define RTL8201F_ISR_ANERR BIT(15) -#define RTL8201F_ISR_DUPLEX BIT(13) -#define RTL8201F_ISR_LINK BIT(11) -#define RTL8201F_ISR_MASK (RTL8201F_ISR_ANERR | \ - RTL8201F_ISR_DUPLEX | \ - RTL8201F_ISR_LINK) -#define RTL8201F_IER 0x13 - #define RTL822X_VND1_SERDES_OPTION 0x697a #define RTL822X_VND1_SERDES_OPTION_MODE_MASK GENMASK(5, 0) #define RTL822X_VND1_SERDES_OPTION_MODE_2500BASEX_SGMII 0 @@ -112,8 +114,6 @@ #define RTL_8221B_VN_CG 0x001cc84a #define RTL_8251B 0x001cc862 -#define RTL8211F_LED_COUNT 3 - MODULE_DESCRIPTION("Realtek PHY driver"); MODULE_AUTHOR("Johnson Leung"); MODULE_LICENSE("GPL"); From patchwork Wed Mar 26 21:21:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Klein X-Patchwork-Id: 14030558 X-Patchwork-Delegate: kuba@kernel.org Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA32B24EF7C; Wed, 26 Mar 2025 21:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.171 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024282; cv=pass; b=fBDtsAXvsxLYV74B1T/iGEHg7pEoqfG5xl/By4n+Klp+NjnEMgRAH88hm6vElXt74CgffBR0VgnTM7wSgutv9d1YCQLDNKr2zYgAWx9zs/GKcqIe81waz3RoFXBgWVij5oV5wIiAzOPpVD5kb4pHe43tNsMU5ouBkJIA4amgU7k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024282; c=relaxed/simple; bh=U/3mjJa7+vRHonlRAAZfA88e/j7vMnEK9dHvRxvTqMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MwhzSXwR71rgNf0U1xeOU+iQXbkDEe4J7CrWY/sSxrMTXWRJZsGjz77NSUBqKgLGR/Z1Gr3QE9A4GTi3AxfLVPDxMzPD1rO3Pibw/PSkeP5WnhJNzVAna1+Qz80uJ53G2i50BNax8koPkH3QT/ffFC6IiJ16ctXrfLQDP76plSE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de; spf=pass smtp.mailfrom=a98shuttle.de; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=VCGSD6Cz; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=KtvvhQWT; arc=pass smtp.client-ip=81.169.146.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=a98shuttle.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="VCGSD6Cz"; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="KtvvhQWT" ARC-Seal: i=1; a=rsa-sha256; t=1743024093; cv=none; d=strato.com; s=strato-dkim-0002; b=XaZHl9z85Fxzptv/bmPKYvI80a1dd/aR4c+a2Kq1vN9cyhr1lM2bbmlNJ/W0eSR0Lr a3y/3TXK4cb+fhjqJTCG5ndeJtM/Kf8CHTd7tGwONwhBC70eaP0bb8iYbm3uyUbxZsDL zKvDruCl49KCwteunNpicFwNytf9dTzH3lkJjfcvjVEyWNxrS0MZbUn9jNzwscOzGwmg XcJDybHMoXGMWCUsPDptGn7VGTXwBeOPyRkw+FawUhN2f8nWdNfO0gEfoXEgwr16ZUYs uP5kxXO9V3iJHMrmA1CzgATS0u7QvXYfKlGIto81Ru5b4PA6M6PI2Ag8nHfXbgfOSGo/ B0cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024093; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=4WusYsCr3PnM/I7INx3XdhXuW9evRki5Ti1YpCs2K0Y=; b=tyJbQxf95lhnK8YXsL7il8g5JQZGiqcLlSC+FE3RrgK9Nz5a2/e+NDdbQWXgA1PZ0S 9to9sOqO8iXcou9vDtK2MpITnyYhpYw3VJDVXIfJ2rWeGXFDR0peuX6QNCw2JJz6C2bY asJ+3ntBTPwyB/yvHAUh2cAG2Uw14MDeV0kwm5Cne7M4gIrziX32mLTpwj3G+VUfnWSP CU8aRizVE7ewQP4QDSxiUpD5/im0uN869nePRvz73GgJPi2t5VyEUpjXWBv2+VWY4ruG nDqdXX6ZSSpUOmyz6pxKQAlV5uzWG5LuLJjDKVtN+uVa8oMtpbGIzXvRkIgXl0itR3a0 r8Mw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024093; s=strato-dkim-0002; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=4WusYsCr3PnM/I7INx3XdhXuW9evRki5Ti1YpCs2K0Y=; b=VCGSD6CzNO+mHwgx9gqwfDNAQcSLAlmCKLLU2Vg+PWmxIKdaOxPq68r2qYigzSW/zr L9h3ctqhZorsa2eBh0tV3PVavDPc4bSYgKWVZJqbfoBIBjT6J2AYzm4tQ7VpVmv5GNas szS9403qmaqTqBZNEo/dW/kjL0p9atL97Fn8fNYr4w2slxoH+QjMDb/9SPFQxugKWlmn xTrlPwVABaIx9nlS29BPs2qutelf/rkzTzzG38Xe07kzivvZJBEOFNpiXGBbJizgqp3m rh6eYc4+Vio/l3Xn8IAudnm/rn7babPdhepII57igP1vUHqfsC5Hv2Ftf++qiPKGQvR6 qJ3w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1743024093; s=strato-dkim-0003; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=4WusYsCr3PnM/I7INx3XdhXuW9evRki5Ti1YpCs2K0Y=; b=KtvvhQWTQMYcBATaPFLVAR3O5A63pKNethE4nvrMjezmJloeJo1r1q8c7c3fLp6gV7 a/m9NBEJbRRXTE8uCuDQ== X-RZG-AUTH: ":O2kGeEG7b/pS1EzgE2y7nF0STYsSLflpbjNKxx7cGrBdao6FTL4AJcMdm+lap4JEHkzok9eyEg==" Received: from aerfugl by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id f28b3512QLLX1Hz (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 26 Mar 2025 22:21:33 +0100 (CET) Received: from koltrast.home ([192.168.1.27] helo=a98shuttle.de) by aerfugl with smtp (Exim 4.96) (envelope-from ) id 1txYBn-0000iF-2R; Wed, 26 Mar 2025 22:21:31 +0100 Received: (nullmailer pid 100282 invoked by uid 502); Wed, 26 Mar 2025 21:21:31 -0000 From: Michael Klein To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Michael Klein , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next v5 2/4] net: phy: realtek: Clean up RTL8211E ExtPage access Date: Wed, 26 Mar 2025 22:21:23 +0100 Message-Id: <20250326212125.100218-3-michael@fossekall.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250326212125.100218-1-michael@fossekall.de> References: <20250326212125.100218-1-michael@fossekall.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org - Factor out RTL8211E extension page access code to rtl8211e_modify_ext_page() and clean up rtl8211e_config_init() Signed-off-by: Michael Klein --- drivers/net/phy/realtek/realtek_main.c | 38 +++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index b27c0f995e56..e60c18551a4e 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -37,9 +37,11 @@ #define RTL821x_INSR 0x13 -#define RTL821x_EXT_PAGE_SELECT 0x1e #define RTL821x_PAGE_SELECT 0x1f +#define RTL8211E_EXT_PAGE_SELECT 0x1e +#define RTL8211E_SET_EXT_PAGE 0x07 + #define RTL8211E_CTRL_DELAY BIT(13) #define RTL8211E_TX_DELAY BIT(12) #define RTL8211E_RX_DELAY BIT(11) @@ -135,6 +137,21 @@ static int rtl821x_write_page(struct phy_device *phydev, int page) return __phy_write(phydev, RTL821x_PAGE_SELECT, page); } +static int rtl8211e_modify_ext_page(struct phy_device *phydev, u16 ext_page, + u32 regnum, u16 mask, u16 set) +{ + int oldpage, ret = 0; + + oldpage = phy_select_page(phydev, RTL8211E_SET_EXT_PAGE); + if (oldpage >= 0) { + ret = __phy_write(phydev, RTL8211E_EXT_PAGE_SELECT, ext_page); + if (ret == 0) + ret = __phy_modify(phydev, regnum, mask, set); + } + + return phy_restore_page(phydev, oldpage, ret); +} + static int rtl821x_probe(struct phy_device *phydev) { struct device *dev = &phydev->mdio.dev; @@ -607,7 +624,9 @@ static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index, static int rtl8211e_config_init(struct phy_device *phydev) { - int ret = 0, oldpage; + const u16 delay_mask = RTL8211E_CTRL_DELAY | + RTL8211E_TX_DELAY | + RTL8211E_RX_DELAY; u16 val; /* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */ @@ -637,20 +656,7 @@ static int rtl8211e_config_init(struct phy_device *phydev) * 12 = RX Delay, 11 = TX Delay * 10:0 = Test && debug settings reserved by realtek */ - oldpage = phy_select_page(phydev, 0x7); - if (oldpage < 0) - goto err_restore_page; - - ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4); - if (ret) - goto err_restore_page; - - ret = __phy_modify(phydev, 0x1c, RTL8211E_CTRL_DELAY - | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY, - val); - -err_restore_page: - return phy_restore_page(phydev, oldpage, ret); + return rtl8211e_modify_ext_page(phydev, 0xa4, 0x1c, delay_mask, val); } static int rtl8211b_suspend(struct phy_device *phydev) From patchwork Wed Mar 26 21:21:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Klein X-Patchwork-Id: 14030559 X-Patchwork-Delegate: kuba@kernel.org Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7F325FA31; Wed, 26 Mar 2025 21:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=85.215.255.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024285; cv=pass; b=YHW0ltpZfG6atwOvvu8JUP5OTBcGK/GqeVhUnwyqcS1xYKrNAZbT9Z0vhDaGxUt4kJXVDDt8HcgsAzEX3OL5Livlf+OgsZpJvaqETOkxRkJlehF3Gr3EliMB1wQLDbuwgU790pcsxOhdcPN08gIJ3vlA7Cf1KYstWv4TXeDSc8g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024285; c=relaxed/simple; bh=EZzj8GfhRs6Y/tesFsPnu/VT+y24dgG6LsFxA2u6yE4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=W8sZScm5EFHwURyiC4gsfoWE1og5FOR/exW5qheyOj3AdDVeuhKtvFkHWSgK+6x5uUjSg5rc1wOzcFDOc3AAghqWxdbN4ZjYbY7F6bFqBwuOmiXumSaxElWaNoJmXPMWvbj+W5ZfFpEfbb+CFqBaFrIM7Eabqy2U5Cw1SCuxJsk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de; spf=pass smtp.mailfrom=a98shuttle.de; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=oBlBfDc7; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=wbrd0Irq; arc=pass smtp.client-ip=85.215.255.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=a98shuttle.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="oBlBfDc7"; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="wbrd0Irq" ARC-Seal: i=1; a=rsa-sha256; t=1743024094; cv=none; d=strato.com; s=strato-dkim-0002; b=MdIeM9tS+A2F0cuy697DmxYZjPNB7JxmvaOgFdFD17QYi9RBqvsh1o4+37sdZnZSkc fePfmTkxjx+O6DnYYjNPXko7rhr9qeNOC3g8gUWERUpK3M3f6QTn0ShZ0d6c3QWerRTL woDCh266m9pSX311fx3s6X5D5cgKQl9bKuoQFEh1Sovivmq5RlvSvrzXknATzLRziNzN IvppzEpm/cP318+ycQZj+u6a+QIn+tsoPtCq4WfhN+oVPl9ocRJNVALJdr7pJh07llfp WqhynYAnq6fOeJHxMeG+CUxE0wCopid3FkLZ/mQagA8gXQ1FOj+G7eko0cpBI7kAd0Ek q6Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024094; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=pFmcDmSQKkM+CI9mfKoKWcBh+gkKTmyRWMx+39HmNqk=; b=nw6KZmVV7HD8qT1anBbqKXbdzNBs55vptg/URAYa6RKpFvGMuGIxrkriU7drV8BWOP Oal4yA4uf0StXrcQ37TtQ6ZIwf8Oa+ZvM7qEje8yx4iDX04S3DAPG4HrqNSnEvVzd4xl QXxv0wY+g2u47wjSx2bHGZZhb6l6uvsYycfgniAgVbaXuap2pTAV0+Bz/pdP4fAd4Baw BrP0MSPpABA6s+qJMtmqoVjctS/kcjsMCovQKAaDhYIZvQT7ySJULThi1zigb7ZO4zBw xw39p+yQ3cDdevX4fHZsBJW+9/4wum9PS90/g8VT7FqhMaEDN5J0wpahT97iAkYDmvmV 6EIA== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024094; s=strato-dkim-0002; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=pFmcDmSQKkM+CI9mfKoKWcBh+gkKTmyRWMx+39HmNqk=; b=oBlBfDc73pneIFHeR8EupOBBWiY0t0I0ZqP5h9Kox0Wc9W68QQPz8jOyveGhPNSIXg Y/TlLhxxh9gYj40bZICwEfA00xT7eG9GFc3ijLYtuDV2qxVH+QbZe5TK38mUbZtV+EzV 8Q1Byz47d3yntZAVtsioRz3JGTxst1iv/2LjmnBxkpn+VGYby3L14nrYAzVn9YKWnUPv uGfmKTo7wirPWgTKx1ux2ja0O/ft8j1DKpetTwNuQSKCNimUPBoEyb1VIJBw3n/Mzeeq +L0BfBvS6HXapTKnPMQS6fPBgv5H7cUwLYxzPkv3UtaNsRorWFRdmBpUri6EujevgDSM z+JA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1743024094; s=strato-dkim-0003; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=pFmcDmSQKkM+CI9mfKoKWcBh+gkKTmyRWMx+39HmNqk=; b=wbrd0IrqogWMmE0me9+qPWF5Nxn5/5KMpVGebb4+K5anCJTSn/kmr6EwczrpJdgMsp zQ28vykFvziHz2oV7jCw== X-RZG-AUTH: ":O2kGeEG7b/pS1EzgE2y7nF0STYsSLflpbjNKxx7cGrBdao6FTL4AJcMdm+lap4JEHkzok9eyEg==" Received: from aerfugl by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id f28b3512QLLY1I1 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 26 Mar 2025 22:21:34 +0100 (CET) Received: from koltrast.home ([192.168.1.27] helo=a98shuttle.de) by aerfugl with smtp (Exim 4.96) (envelope-from ) id 1txYBp-0000ih-0X; Wed, 26 Mar 2025 22:21:33 +0100 Received: (nullmailer pid 100296 invoked by uid 502); Wed, 26 Mar 2025 21:21:33 -0000 From: Michael Klein To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Michael Klein , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next v5 3/4] net: phy: realtek: use __set_bit() in rtl8211f_led_hw_control_get() Date: Wed, 26 Mar 2025 22:21:24 +0100 Message-Id: <20250326212125.100218-4-michael@fossekall.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250326212125.100218-1-michael@fossekall.de> References: <20250326212125.100218-1-michael@fossekall.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org rtl8211f_led_hw_control_get() does not need atomic bit operations, replace set_bit() by __set_bit(). Signed-off-by: Michael Klein Reviewed-by: Andrew Lunn --- drivers/net/phy/realtek/realtek_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index e60c18551a4e..0fcc57ad777f 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -577,17 +577,17 @@ static int rtl8211f_led_hw_control_get(struct phy_device *phydev, u8 index, val &= RTL8211F_LEDCR_MASK; if (val & RTL8211F_LEDCR_LINK_10) - set_bit(TRIGGER_NETDEV_LINK_10, rules); + __set_bit(TRIGGER_NETDEV_LINK_10, rules); if (val & RTL8211F_LEDCR_LINK_100) - set_bit(TRIGGER_NETDEV_LINK_100, rules); + __set_bit(TRIGGER_NETDEV_LINK_100, rules); if (val & RTL8211F_LEDCR_LINK_1000) - set_bit(TRIGGER_NETDEV_LINK_1000, rules); + __set_bit(TRIGGER_NETDEV_LINK_1000, rules); if (val & RTL8211F_LEDCR_ACT_TXRX) { - set_bit(TRIGGER_NETDEV_RX, rules); - set_bit(TRIGGER_NETDEV_TX, rules); + __set_bit(TRIGGER_NETDEV_RX, rules); + __set_bit(TRIGGER_NETDEV_TX, rules); } return 0; From patchwork Wed Mar 26 21:21:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Klein X-Patchwork-Id: 14030561 X-Patchwork-Delegate: kuba@kernel.org Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C05017A2E6; Wed, 26 Mar 2025 21:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.170 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024824; cv=pass; b=aKDKXIZaEL/+IguXuV4dMhx0XbiNKb3k7u4xYNuk4MZc3TPB1oZOu45DdRBQC13g2GGC8GEyHcC9zdPA23A4KulsLjAB+ll9aqpKQEwGgAOdTbW/SDqYD5o+80c6Vddyern2OO3yiThL5hYqWbQYlfxbZhqD83akVEHArPsQSh8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743024824; c=relaxed/simple; bh=JsBPV+BoVZZ8mHe+BMDN7NZXxxagZRvpszOxyvlpkrY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TDMVR8yvipkwM2eXZkNB9WmRwzbmQJkivIp7ZsS2dGSYNp8ZGgSh2yKDBwsQbg7lEXoSuV7KHVGLaNF8FIPzuQ8KlWqBbe89LVX+pErW/uYvMVbWyjxOPtrkneGBT6uYWGZF7Pd5k3kll2NsPTNkHKkgBZfudOruZ0XdAeB8NmM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de; spf=pass smtp.mailfrom=a98shuttle.de; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=Iw8pcAGz; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b=cuzACor0; arc=pass smtp.client-ip=81.169.146.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fossekall.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=a98shuttle.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="Iw8pcAGz"; dkim=permerror (0-bit key) header.d=fossekall.de header.i=@fossekall.de header.b="cuzACor0" ARC-Seal: i=1; a=rsa-sha256; t=1743024096; cv=none; d=strato.com; s=strato-dkim-0002; b=KjYzGgrv8LcCKgqJfyhwfUGWeH/67/Kh2Au6GWEGHClurHs0DM1mHBW9UkNPAbzcJr SoC+yIrdqHfDLFLYodf9BKC2Oi+pAPPa0xAUQO7jBt6wqUuqJ18Ry6SBGyHkAPvnrH1e 2U6PXYvBo2NcyVLcjdEZrqZnN6XHjYc8hZdNSSc4MehXv12jUsfsXZu+bTdKzZmVvMfe h/tfZ+sruJwlKYZqhTUPcUAqa+GNKs+oFKpZynKSl5SpZCksUtbUes9cLwXFnhapfg4g 43MjbxhfqxQkQCkoafaaiYqA+1gUuTii67UQ5qaYsGmiaUvJLW8kZFYwnSsTicmvc4mu 5Feg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024096; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=P/McivwteINBEBUe5y6izhPA6joYrRsVsjumRXRwJUU=; b=S2UlCOz9T0UZOIL63KlpQFZ3/PFMAfuKftZRILib7XpLmuaFJNHCv4cg483NsHKujs 7spBgCcMDf75Ut43SmlCHJ/qXRZLnB1RRgcs722DVEJG/tGOiBTAjRNrJz5Ff5LAM2qG kOvrLH2m1E/pU2NpANpGUe1acapCwNHwdzuuhvSAILHZytjYZS1m8t6L/cY7++aMfLJz JPDnS5ykSPgIBJvIWm4qlpwiv2IJVs8LMKgmcjM1jRxCtRBlPrK6zg7Mg92BblNRWa1c w+/WCniDPjnRWwWyaZYy3/FaDZZG6inLaUyPT/fB27GETYzVyyxm6N2kPYMG+x+ynx01 DHow== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1743024096; s=strato-dkim-0002; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=P/McivwteINBEBUe5y6izhPA6joYrRsVsjumRXRwJUU=; b=Iw8pcAGzYvbCPTrRH/yZtOjU0dfsGPPr92kochQMwp5cM1zi2YUVMhFmT57WZJ/xTa 45KJH9oDvQta62b7c+/JnfOuqctVs0dSI78RX5sAa/VFUj+z67n5uILe54svHJ9PYvAZ r/BhDEFRRAuCid7c002qCBk0fRT9wIPhx88vYTkrg2VexgRBbIIkVZ6ib5TGSBO1ULPV 6vjzWsiRScur68NzGGNlSAhBlie3XxyXzclQmvW4Ny72akaerPiUMMri/mApAk5unBiF 3BXgy/pvGaLqtLnpGstFwzxzFSDGiRlUMslwu9LvneewLl/qaZSHHneQSg5mpZMRB6Dd y43g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1743024096; s=strato-dkim-0003; d=fossekall.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=P/McivwteINBEBUe5y6izhPA6joYrRsVsjumRXRwJUU=; b=cuzACor0FejzKTEWHiPaGNQ9eRATq/kyFuoblWlp3nJSVE7/bIYs7Myc3nYvQd822d FAhUR4ZSsJrm/ObBVODg== X-RZG-AUTH: ":O2kGeEG7b/pS1EzgE2y7nF0STYsSLflpbjNKxx7cGrBdao6FTL4AJcMdm+lap4JEHkzok9eyEg==" Received: from aerfugl by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id f28b3512QLLa1I2 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 26 Mar 2025 22:21:36 +0100 (CET) Received: from koltrast.home ([192.168.1.27] helo=a98shuttle.de) by aerfugl with smtp (Exim 4.96) (envelope-from ) id 1txYBq-0000iz-26; Wed, 26 Mar 2025 22:21:34 +0100 Received: (nullmailer pid 100310 invoked by uid 502); Wed, 26 Mar 2025 21:21:34 -0000 From: Michael Klein To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Michael Klein , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next v5 4/4] net: phy: realtek: Add support for PHY LEDs on RTL8211E Date: Wed, 26 Mar 2025 22:21:25 +0100 Message-Id: <20250326212125.100218-5-michael@fossekall.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250326212125.100218-1-michael@fossekall.de> References: <20250326212125.100218-1-michael@fossekall.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Like the RTL8211F, the RTL8211E PHY supports up to three LEDs. Add netdev trigger support for them, too. Signed-off-by: Michael Klein Reviewed-by: Andrew Lunn --- drivers/net/phy/realtek/realtek_main.c | 125 +++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 0fcc57ad777f..9c3727a646f2 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -46,6 +46,20 @@ #define RTL8211E_TX_DELAY BIT(12) #define RTL8211E_RX_DELAY BIT(11) +#define RTL8211E_LEDCR_EXT_PAGE 0x2c + +#define RTL8211E_LEDCR1 0x1a +#define RTL8211E_LEDCR1_ACT_TXRX BIT(4) +#define RTL8211E_LEDCR1_MASK BIT(4) +#define RTL8211E_LEDCR1_SHIFT 1 + +#define RTL8211E_LEDCR2 0x1c +#define RTL8211E_LEDCR2_LINK_1000 BIT(2) +#define RTL8211E_LEDCR2_LINK_100 BIT(1) +#define RTL8211E_LEDCR2_LINK_10 BIT(0) +#define RTL8211E_LEDCR2_MASK GENMASK(2, 0) +#define RTL8211E_LEDCR2_SHIFT 4 + #define RTL8211F_PHYCR1 0x18 #define RTL8211F_PHYCR2 0x19 #define RTL8211F_CLKOUT_EN BIT(0) @@ -62,7 +76,8 @@ #define RTL8211F_LEDCR_MASK GENMASK(4, 0) #define RTL8211F_LEDCR_SHIFT 5 -#define RTL8211F_LED_COUNT 3 +/* RTL8211E and RTL8211F support up to three LEDs */ +#define RTL8211x_LED_COUNT 3 #define RTL8211F_TX_DELAY BIT(8) #define RTL8211F_RX_DELAY BIT(3) @@ -137,6 +152,21 @@ static int rtl821x_write_page(struct phy_device *phydev, int page) return __phy_write(phydev, RTL821x_PAGE_SELECT, page); } +static int rtl8211e_read_ext_page(struct phy_device *phydev, u16 ext_page, + u32 regnum) +{ + int oldpage, ret = 0; + + oldpage = phy_select_page(phydev, RTL8211E_SET_EXT_PAGE); + if (oldpage >= 0) { + ret = __phy_write(phydev, RTL8211E_EXT_PAGE_SELECT, ext_page); + if (ret == 0) + ret = __phy_read(phydev, regnum); + } + + return phy_restore_page(phydev, oldpage, ret); +} + static int rtl8211e_modify_ext_page(struct phy_device *phydev, u16 ext_page, u32 regnum, u16 mask, u16 set) { @@ -526,7 +556,7 @@ static int rtl821x_resume(struct phy_device *phydev) return 0; } -static int rtl8211f_led_hw_is_supported(struct phy_device *phydev, u8 index, +static int rtl8211x_led_hw_is_supported(struct phy_device *phydev, u8 index, unsigned long rules) { const unsigned long mask = BIT(TRIGGER_NETDEV_LINK_10) | @@ -545,9 +575,11 @@ static int rtl8211f_led_hw_is_supported(struct phy_device *phydev, u8 index, * rates and Active indication always at all three 10+100+1000 * link rates. * This code currently uses mode B only. + * + * RTL8211E PHY LED has one mode, which works like RTL8211F mode B. */ - if (index >= RTL8211F_LED_COUNT) + if (index >= RTL8211x_LED_COUNT) return -EINVAL; /* Filter out any other unsupported triggers. */ @@ -566,7 +598,7 @@ static int rtl8211f_led_hw_control_get(struct phy_device *phydev, u8 index, { int val; - if (index >= RTL8211F_LED_COUNT) + if (index >= RTL8211x_LED_COUNT) return -EINVAL; val = phy_read_paged(phydev, 0xd04, RTL8211F_LEDCR); @@ -599,7 +631,7 @@ static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index, const u16 mask = RTL8211F_LEDCR_MASK << (RTL8211F_LEDCR_SHIFT * index); u16 reg = 0; - if (index >= RTL8211F_LED_COUNT) + if (index >= RTL8211x_LED_COUNT) return -EINVAL; if (test_bit(TRIGGER_NETDEV_LINK_10, &rules)) @@ -622,6 +654,84 @@ static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index, return phy_modify_paged(phydev, 0xd04, RTL8211F_LEDCR, mask, reg); } +static int rtl8211e_led_hw_control_get(struct phy_device *phydev, u8 index, + unsigned long *rules) +{ + int ret; + u16 cr1, cr2; + + if (index >= RTL8211x_LED_COUNT) + return -EINVAL; + + ret = rtl8211e_read_ext_page(phydev, RTL8211E_LEDCR_EXT_PAGE, + RTL8211E_LEDCR1); + if (ret < 0) + return ret; + + cr1 = ret >> RTL8211E_LEDCR1_SHIFT * index; + if (cr1 & RTL8211E_LEDCR1_ACT_TXRX) { + __set_bit(TRIGGER_NETDEV_RX, rules); + __set_bit(TRIGGER_NETDEV_TX, rules); + } + + ret = rtl8211e_read_ext_page(phydev, RTL8211E_LEDCR_EXT_PAGE, + RTL8211E_LEDCR2); + if (ret < 0) + return ret; + + cr2 = ret >> RTL8211E_LEDCR2_SHIFT * index; + if (cr2 & RTL8211E_LEDCR2_LINK_10) + __set_bit(TRIGGER_NETDEV_LINK_10, rules); + + if (cr2 & RTL8211E_LEDCR2_LINK_100) + __set_bit(TRIGGER_NETDEV_LINK_100, rules); + + if (cr2 & RTL8211E_LEDCR2_LINK_1000) + __set_bit(TRIGGER_NETDEV_LINK_1000, rules); + + return ret; +} + +static int rtl8211e_led_hw_control_set(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + const u16 cr1mask = + RTL8211E_LEDCR1_MASK << (RTL8211E_LEDCR1_SHIFT * index); + const u16 cr2mask = + RTL8211E_LEDCR2_MASK << (RTL8211E_LEDCR2_SHIFT * index); + u16 cr1 = 0, cr2 = 0; + int ret; + + if (index >= RTL8211x_LED_COUNT) + return -EINVAL; + + if (test_bit(TRIGGER_NETDEV_RX, &rules) || + test_bit(TRIGGER_NETDEV_TX, &rules)) { + cr1 |= RTL8211E_LEDCR1_ACT_TXRX; + } + + cr1 <<= RTL8211E_LEDCR1_SHIFT * index; + ret = rtl8211e_modify_ext_page(phydev, RTL8211E_LEDCR_EXT_PAGE, + RTL8211E_LEDCR1, cr1mask, cr1); + if (ret < 0) + return ret; + + if (test_bit(TRIGGER_NETDEV_LINK_10, &rules)) + cr2 |= RTL8211E_LEDCR2_LINK_10; + + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules)) + cr2 |= RTL8211E_LEDCR2_LINK_100; + + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules)) + cr2 |= RTL8211E_LEDCR2_LINK_1000; + + cr2 <<= RTL8211E_LEDCR2_SHIFT * index; + ret = rtl8211e_modify_ext_page(phydev, RTL8211E_LEDCR_EXT_PAGE, + RTL8211E_LEDCR2, cr2mask, cr2); + + return ret; +} + static int rtl8211e_config_init(struct phy_device *phydev) { const u16 delay_mask = RTL8211E_CTRL_DELAY | @@ -1398,6 +1508,9 @@ static struct phy_driver realtek_drvs[] = { .resume = genphy_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + .led_hw_is_supported = rtl8211x_led_hw_is_supported, + .led_hw_control_get = rtl8211e_led_hw_control_get, + .led_hw_control_set = rtl8211e_led_hw_control_set, }, { PHY_ID_MATCH_EXACT(0x001cc916), .name = "RTL8211F Gigabit Ethernet", @@ -1411,7 +1524,7 @@ static struct phy_driver realtek_drvs[] = { .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, .flags = PHY_ALWAYS_CALL_SUSPEND, - .led_hw_is_supported = rtl8211f_led_hw_is_supported, + .led_hw_is_supported = rtl8211x_led_hw_is_supported, .led_hw_control_get = rtl8211f_led_hw_control_get, .led_hw_control_set = rtl8211f_led_hw_control_set, }, {