Re: [PATCH v3 4/6] net: phy: Add phy_modify() accessor

2022-03-03 Thread Ramon Fried
On Thu, Feb 17, 2022 at 4:36 PM Ariel D'Alessandro
 wrote:
>
> Add read-modify-write unlocked accessor for accessing a PHY register.
>
> Signed-off-by: Ariel D'Alessandro 
> ---
>  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
>
Reviewed-by: Ramon Fried 


[PATCH v3 4/6] net: phy: Add phy_modify() accessor

2022-02-17 Thread Ariel D'Alessandro
Add read-modify-write unlocked accessor for accessing a PHY register.

Signed-off-by: Ariel D'Alessandro 
---
 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