Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93D68C433F5 for ; Tue, 12 Apr 2022 13:34:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B6EC83E19; Tue, 12 Apr 2022 15:33:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="jt+XSuIJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BC4BD83AE1; Tue, 12 Apr 2022 15:33:12 +0200 (CEST) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F025A835B9 for ; Tue, 12 Apr 2022 15:33:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ariel.dalessandro@collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: adalessandro) with ESMTPSA id A476F1F444CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1649770389; bh=80UzpDKb1KpwsbatQoMXkeOnpLOvbqJIFWdtI8b59QE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jt+XSuIJ2EZukQHh/VOLKS9vfwYtNqWJF9QkzvnZ4hQbZIxcrdEUOSbgpDYNWuQuI W+P7cD7w7U/vzW4CZEoP9s+a1zh9LaoKQ80TYY3MZq+aPLyUAp2uNvIS4JnWAlKFm/ TOHz55Yu3LBGEYvMS/Do4iuTOij0QmWyFpsDPJv1SWJn5PEfNLqsiuD8RSX5r82Ccq oIRZWIifBlIhxTzeoZmMVw1UgbL1svUd5xlIJ4g/vZGggNV3tGGshpkpbucfVkLRDh p9Qbv2LfnXS8Hm+09M7Oy/8wXIHdLx+VwHPwIaJ0hLDVLGmUFPJt8PLmQVQtaRrgrF kSmwZFPvnFV1A== From: Ariel D'Alessandro To: u-boot@lists.denx.de Cc: Peter.Hoyes@arm.com, aford173@gmail.com, alice.guo@nxp.com, andre.przywara@arm.com, andrey.zhizhikin@leica-geosystems.com, ariel.dalessandro@collabora.com, bmeng.cn@gmail.com, christian.gmeiner@gmail.com, christianshewitt@gmail.com, festevam@gmail.com, iliev@ronetix.at, jagan@amarulasolutions.com, jh80.chung@samsung.com, joe.hershberger@ni.com, kettenis@openbsd.org, kever.yang@rock-chips.com, kuldeep.singh@nxp.com, marcel.ziswiler@toradex.com, marex@denx.de, michael@amarulasolutions.com, michal.simek@xilinx.com, oliver.graute@kococonnector.com, pali@kernel.org, paul.liu@linaro.org, pbrobinson@gmail.com, peng.fan@nxp.com, philipp.tomsich@vrull.eu, priyanka.jain@nxp.com, radu-nicolae.pirea@oss.nxp.com, rath@ibv-augsburg.net, rfried.dev@gmail.com, samuel@sholland.org, sbabic@denx.de, simon.k.r.goldschmidt@gmail.com, sjg@chromium.org, stephan@gerhold.net, tharvey@gateworks.com, tien.fong.chee@intel.com, uboot-imx@nxp.com, vladimir.oltean@nxp.com, wd@denx.de, xypron.glpk@gmx.de, ye.li@nxp.com Subject: [PATCH v5 5/7] net: phy: Add phy_modify() accessor Date: Tue, 12 Apr 2022 10:31:36 -0300 Message-Id: <20220412133138.110815-6-ariel.dalessandro@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220412133138.110815-1-ariel.dalessandro@collabora.com> References: <20220412133138.110815-1-ariel.dalessandro@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 12 Apr 2022 15:33:24 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Add read-modify-write unlocked accessor for accessing a PHY register. Signed-off-by: Ariel D'Alessandro Reviewed-by: Ramon Fried --- drivers/net/phy/phy.c | 20 ++++++++++++++++++++ include/phy.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index e61c9b8a178..50448cf62c4 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1110,3 +1110,23 @@ int phy_get_interface_by_name(const char *str) return -1; } + +/** + * phy_modify - Convenience function for modifying a given PHY register + * @phydev: the phy_device struct + * @devad: The MMD to read from + * @regnum: register number to write + * @mask: bit mask of bits to clear + * @set: new value of bits set in mask to write to @regnum + */ +int phy_modify(struct phy_device *phydev, int devad, int regnum, u16 mask, + u16 set) +{ + int ret; + + ret = phy_read(phydev, devad, regnum); + if (ret < 0) + return ret; + + return phy_write(phydev, devad, regnum, (ret & ~mask) | set); +} diff --git a/include/phy.h b/include/phy.h index 807c2932fda..1a30aee5421 100644 --- a/include/phy.h +++ b/include/phy.h @@ -526,6 +526,8 @@ int phy_config(struct phy_device *phydev); int phy_shutdown(struct phy_device *phydev); int phy_register(struct phy_driver *drv); int phy_set_supported(struct phy_device *phydev, u32 max_speed); +int phy_modify(struct phy_device *phydev, int devad, int regnum, u16 mask, + u16 set); int genphy_config_aneg(struct phy_device *phydev); int genphy_restart_aneg(struct phy_device *phydev); int genphy_update_link(struct phy_device *phydev); -- 2.34.1