All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
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 v4 4/6] net: phy: Add phy_modify() accessor
Date: Fri,  4 Mar 2022 09:22:26 -0300	[thread overview]
Message-ID: <20220304122228.71412-5-ariel.dalessandro@collabora.com> (raw)
In-Reply-To: <20220304122228.71412-1-ariel.dalessandro@collabora.com>

Add read-modify-write unlocked accessor for accessing a PHY register.

Signed-off-by: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
---
 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 9935e40fcdc..b73361d87d9 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1105,3 +1105,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 d4035fdef2b..2dd2e02ab5d 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -500,6 +500,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


  parent reply	other threads:[~2022-03-04 13:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 12:22 [PATCH v4 0/6] imx8mn-smm-s2/pro: Add iMX8MN BSH SMM S2 boards Ariel D'Alessandro
2022-03-04 12:22 ` [PATCH v4 1/6] imx8m: add regs used by GPMI Ariel D'Alessandro
2022-03-04 12:22 ` [PATCH v4 2/6] phy: nxp-c45-tja11xx: Rename functions to be c45 tja11xx specific Ariel D'Alessandro
2022-03-04 12:22 ` [PATCH v4 3/6] iopoll: Extend read_poll_timeout macro to support variable parameters Ariel D'Alessandro
2022-03-04 12:22 ` Ariel D'Alessandro [this message]
2022-03-04 12:22 ` [PATCH v4 5/6] net: phy: nxp-tja11xx: Add NXP TJA11xx PHY driver Ariel D'Alessandro
2022-03-04 12:22 ` [PATCH v4 6/6] bsh: imx8mn-smm-s2/pro: Add iMX8MN BSH SMM S2 boards Ariel D'Alessandro
2022-04-05 20:44 ` [PATCH v4 0/6] " Ariel D'Alessandro
2022-04-05 22:46   ` Tom Rini
2022-04-11 11:56     ` Ariel D'Alessandro
2022-04-11 15:56       ` Stefano Babic
2022-04-11 16:03         ` Tom Rini
2022-04-11 16:27           ` Stefano Babic
2022-04-11 17:18             ` Tom Rini
2022-04-12 11:50         ` Ariel D'Alessandro
2022-04-12 11:53           ` Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220304122228.71412-5-ariel.dalessandro@collabora.com \
    --to=ariel.dalessandro@collabora.com \
    --cc=Peter.Hoyes@arm.com \
    --cc=aford173@gmail.com \
    --cc=alice.guo@nxp.com \
    --cc=andre.przywara@arm.com \
    --cc=andrey.zhizhikin@leica-geosystems.com \
    --cc=bmeng.cn@gmail.com \
    --cc=christian.gmeiner@gmail.com \
    --cc=christianshewitt@gmail.com \
    --cc=festevam@gmail.com \
    --cc=iliev@ronetix.at \
    --cc=jagan@amarulasolutions.com \
    --cc=jh80.chung@samsung.com \
    --cc=joe.hershberger@ni.com \
    --cc=kettenis@openbsd.org \
    --cc=kever.yang@rock-chips.com \
    --cc=kuldeep.singh@nxp.com \
    --cc=marcel.ziswiler@toradex.com \
    --cc=marex@denx.de \
    --cc=michael@amarulasolutions.com \
    --cc=michal.simek@xilinx.com \
    --cc=oliver.graute@kococonnector.com \
    --cc=pali@kernel.org \
    --cc=paul.liu@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=priyanka.jain@nxp.com \
    --cc=radu-nicolae.pirea@oss.nxp.com \
    --cc=rath@ibv-augsburg.net \
    --cc=rfried.dev@gmail.com \
    --cc=samuel@sholland.org \
    --cc=sbabic@denx.de \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=sjg@chromium.org \
    --cc=stephan@gerhold.net \
    --cc=tharvey@gateworks.com \
    --cc=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wd@denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=ye.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.