diff mbox series

[v3,3/5] net: phy: Add helper routines to set and clear bits

Message ID 20200430163047.6898-4-dmurphy@ti.com
State Superseded
Headers show
Series TI Ethernet PHY changes | expand

Commit Message

Dan Murphy April 30, 2020, 4:30 p.m. UTC
Add phy_set/clear_bit helper routines so that ported drivers from the
kernel can use these functions.

Signed-off-by: Dan Murphy <dmurphy at ti.com>
---
 include/phy.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

Comments

Michal Simek May 4, 2020, 9:46 a.m. UTC | #1
On 30. 04. 20 18:30, Dan Murphy wrote:
> Add phy_set/clear_bit helper routines so that ported drivers from the
> kernel can use these functions.
> 
> Signed-off-by: Dan Murphy <dmurphy at ti.com>
> ---
>  include/phy.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 
> diff --git a/include/phy.h b/include/phy.h
> index 34c2af719b67..fedd14609192 100644
> --- a/include/phy.h
> +++ b/include/phy.h
> @@ -296,6 +296,60 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,
>  	return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val);
>  }
>  
> +/**
> + * phy_set_bits_mmd - Convenience function for setting bits in a register
> + * on MMD
> + * @phydev: the phy_device struct
> + * @devad: the MMD containing register to modify
> + * @regnum: register number to modify
> + * @val: bits to set
> + * @return: 0 for success or negative errno for failure
> + */
> +static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
> +				   u32 regnum, u16 val)
> +{
> +	int value, ret;
> +
> +	value = phy_read_mmd(phydev, devad, regnum);
> +	if (value < 0)
> +		return value;
> +
> +	value |= val;
> +
> +	ret = phy_write_mmd(phydev, devad, regnum, value);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +/**
> + * phy_clear_bits_mmd - Convenience function for clearing bits in a register
> + * on MMD
> + * @phydev: the phy_device struct
> + * @devad: the MMD containing register to modify
> + * @regnum: register number to modify
> + * @val: bits to clear
> + * @return: 0 for success or negative errno for failure
> + */
> +static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
> +				     u32 regnum, u16 val)
> +{
> +	int value, ret;
> +
> +	value = phy_read_mmd(phydev, devad, regnum);
> +	if (value < 0)
> +		return value;
> +
> +	value &= ~val;
> +
> +	ret = phy_write_mmd(phydev, devad, regnum, value);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
>  #ifdef CONFIG_PHYLIB_10G
>  extern struct phy_driver gen10g_driver;
>  
> 

Acked-by: Michal Simek <michal.simek at xilinx.com>

Thanks,
Michal
diff mbox series

Patch

diff --git a/include/phy.h b/include/phy.h
index 34c2af719b67..fedd14609192 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -296,6 +296,60 @@  static inline int phy_write_mmd(struct phy_device *phydev, int devad,
 	return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val);
 }
 
+/**
+ * phy_set_bits_mmd - Convenience function for setting bits in a register
+ * on MMD
+ * @phydev: the phy_device struct
+ * @devad: the MMD containing register to modify
+ * @regnum: register number to modify
+ * @val: bits to set
+ * @return: 0 for success or negative errno for failure
+ */
+static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
+				   u32 regnum, u16 val)
+{
+	int value, ret;
+
+	value = phy_read_mmd(phydev, devad, regnum);
+	if (value < 0)
+		return value;
+
+	value |= val;
+
+	ret = phy_write_mmd(phydev, devad, regnum, value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+/**
+ * phy_clear_bits_mmd - Convenience function for clearing bits in a register
+ * on MMD
+ * @phydev: the phy_device struct
+ * @devad: the MMD containing register to modify
+ * @regnum: register number to modify
+ * @val: bits to clear
+ * @return: 0 for success or negative errno for failure
+ */
+static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
+				     u32 regnum, u16 val)
+{
+	int value, ret;
+
+	value = phy_read_mmd(phydev, devad, regnum);
+	if (value < 0)
+		return value;
+
+	value &= ~val;
+
+	ret = phy_write_mmd(phydev, devad, regnum, value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 #ifdef CONFIG_PHYLIB_10G
 extern struct phy_driver gen10g_driver;