diff mbox series

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

Message ID 20200428192606.1808-2-dmurphy@ti.com
State Superseded
Delegated to: Joe Hershberger
Headers show
Series TI Ethernet PHY changes | expand

Commit Message

Dan Murphy April 28, 2020, 7:26 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@ti.com>
---
 include/phy.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

Comments

Michal Simek April 30, 2020, 8 a.m. UTC | #1
On 28. 04. 20 21:26, 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@ti.com>
> ---
>  include/phy.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 80 insertions(+)
> 
> diff --git a/include/phy.h b/include/phy.h
> index b5de14cbfc29..1a875b96edb7 100644
> --- a/include/phy.h
> +++ b/include/phy.h
> @@ -170,6 +170,12 @@ struct fixed_link {
>  	int asym_pause;
>  };
>  
> +/**
> + * phy_read - Convenience function for reading a given PHY register
> + * @phydev: the phy_device struct
> + * @devad: The MMD to read from
> + * @regnum: register number to read
> + */
>  static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
>  {
>  	struct mii_dev *bus = phydev->bus;
> @@ -182,6 +188,13 @@ static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
>  	return bus->read(bus, phydev->addr, devad, regnum);
>  }
>  
> +/**
> + * phy_write - Convenience function for writing a given PHY register
> + * @phydev: the phy_device struct
> + * @devad: The MMD to read from
> + * @regnum: register number to write
> + * @val: value to write to @regnum
> + */
>  static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
>  			u16 val)
>  {
> @@ -209,6 +222,13 @@ static inline void phy_mmd_start_indirect(struct phy_device *phydev, int devad,
>  		  (devad | MII_MMD_CTRL_NOINCR));
>  }
>  
> +/**
> + * phy_read_mmd - Convenience function for reading a register
> + * from an MMD on a given PHY.
> + * @phydev: The phy_device struct
> + * @devad: The MMD to read from
> + * @regnum: The register on the MMD to read
> + */
>  static inline int phy_read_mmd(struct phy_device *phydev, int devad,
>  			       int regnum)
>  {
> @@ -233,6 +253,14 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad,
>  	return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA);
>  }
>  
> +/**
> + * phy_write_mmd - Convenience function for writing a register
> + * on an MMD on a given PHY.
> + * @phydev: The phy_device struct
> + * @devad: The MMD to read from
> + * @regnum: The register on the MMD to read
> + * @val: value to write to @regnum
> + */
>  static inline int phy_write_mmd(struct phy_device *phydev, int devad,
>  				int regnum, u16 val)
>  {
> @@ -257,6 +285,58 @@ 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
> + */
> +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
> + */
> +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;
>  
> 

Better would be to have one patch just with adding missing kernel-doc.
It is not described in commit message too.

And second to add that functions.

And there are errors there.

[u-boot](debian)$ ./scripts/kernel-doc -v -man include/phy.h > /dev/null
include/phy.h:174: info: Scanning doc for phy_read
include/phy.h:180: warning: No description found for return value of
'phy_read'
include/phy.h:192: info: Scanning doc for phy_write
include/phy.h:200: warning: No description found for return value of
'phy_write'
include/phy.h:226: info: Scanning doc for phy_read_mmd
include/phy.h:234: warning: No description found for return value of
'phy_read_mmd'
include/phy.h:257: info: Scanning doc for phy_write_mmd
include/phy.h:266: warning: No description found for return value of
'phy_write_mmd'
include/phy.h:289: info: Scanning doc for phy_set_bits_mmd
include/phy.h:298: warning: No description found for return value of
'phy_set_bits_mmd'
include/phy.h:315: info: Scanning doc for phy_clear_bits_mmd
include/phy.h:324: warning: No description found for return value of
'phy_clear_bits_mmd'


Thanks,
Michal
Dan Murphy April 30, 2020, 11:43 a.m. UTC | #2
Michal

On 4/30/20 3:00 AM, Michal Simek wrote:
> On 28. 04. 20 21:26, 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@ti.com>
>> ---
>>   include/phy.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 80 insertions(+)
>>
>> diff --git a/include/phy.h b/include/phy.h
>> index b5de14cbfc29..1a875b96edb7 100644
>> --- a/include/phy.h
>> +++ b/include/phy.h
>> @@ -170,6 +170,12 @@ struct fixed_link {
>>   	int asym_pause;
>>   };
>>   
>> +/**
>> + * phy_read - Convenience function for reading a given PHY register
>> + * @phydev: the phy_device struct
>> + * @devad: The MMD to read from
>> + * @regnum: register number to read
>> + */
>>   static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
>>   {
>>   	struct mii_dev *bus = phydev->bus;
>> @@ -182,6 +188,13 @@ static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
>>   	return bus->read(bus, phydev->addr, devad, regnum);
>>   }
>>   
>> +/**
>> + * phy_write - Convenience function for writing a given PHY register
>> + * @phydev: the phy_device struct
>> + * @devad: The MMD to read from
>> + * @regnum: register number to write
>> + * @val: value to write to @regnum
>> + */
>>   static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
>>   			u16 val)
>>   {
>> @@ -209,6 +222,13 @@ static inline void phy_mmd_start_indirect(struct phy_device *phydev, int devad,
>>   		  (devad | MII_MMD_CTRL_NOINCR));
>>   }
>>   
>> +/**
>> + * phy_read_mmd - Convenience function for reading a register
>> + * from an MMD on a given PHY.
>> + * @phydev: The phy_device struct
>> + * @devad: The MMD to read from
>> + * @regnum: The register on the MMD to read
>> + */
>>   static inline int phy_read_mmd(struct phy_device *phydev, int devad,
>>   			       int regnum)
>>   {
>> @@ -233,6 +253,14 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad,
>>   	return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA);
>>   }
>>   
>> +/**
>> + * phy_write_mmd - Convenience function for writing a register
>> + * on an MMD on a given PHY.
>> + * @phydev: The phy_device struct
>> + * @devad: The MMD to read from
>> + * @regnum: The register on the MMD to read
>> + * @val: value to write to @regnum
>> + */
>>   static inline int phy_write_mmd(struct phy_device *phydev, int devad,
>>   				int regnum, u16 val)
>>   {
>> @@ -257,6 +285,58 @@ 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
>> + */
>> +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
>> + */
>> +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;
>>   
>>
> Better would be to have one patch just with adding missing kernel-doc.
> It is not described in commit message too.
Yes I was thinking that I should have done 2 patches since the kernel 
doc to the other functions is completely separate work.
>
> And second to add that functions.
>
> And there are errors there.
>
> [u-boot](debian)$ ./scripts/kernel-doc -v -man include/phy.h > /dev/null

I learned something new today.  Now I know how to check my kernel doc :)

I will fix these.

Dan
diff mbox series

Patch

diff --git a/include/phy.h b/include/phy.h
index b5de14cbfc29..1a875b96edb7 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -170,6 +170,12 @@  struct fixed_link {
 	int asym_pause;
 };
 
+/**
+ * phy_read - Convenience function for reading a given PHY register
+ * @phydev: the phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: register number to read
+ */
 static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
 {
 	struct mii_dev *bus = phydev->bus;
@@ -182,6 +188,13 @@  static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
 	return bus->read(bus, phydev->addr, devad, regnum);
 }
 
+/**
+ * phy_write - Convenience function for writing a given PHY register
+ * @phydev: the phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: register number to write
+ * @val: value to write to @regnum
+ */
 static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
 			u16 val)
 {
@@ -209,6 +222,13 @@  static inline void phy_mmd_start_indirect(struct phy_device *phydev, int devad,
 		  (devad | MII_MMD_CTRL_NOINCR));
 }
 
+/**
+ * phy_read_mmd - Convenience function for reading a register
+ * from an MMD on a given PHY.
+ * @phydev: The phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: The register on the MMD to read
+ */
 static inline int phy_read_mmd(struct phy_device *phydev, int devad,
 			       int regnum)
 {
@@ -233,6 +253,14 @@  static inline int phy_read_mmd(struct phy_device *phydev, int devad,
 	return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA);
 }
 
+/**
+ * phy_write_mmd - Convenience function for writing a register
+ * on an MMD on a given PHY.
+ * @phydev: The phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: The register on the MMD to read
+ * @val: value to write to @regnum
+ */
 static inline int phy_write_mmd(struct phy_device *phydev, int devad,
 				int regnum, u16 val)
 {
@@ -257,6 +285,58 @@  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
+ */
+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
+ */
+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;