diff mbox

[2/2] net: davinci_mdio: allow to create phys from dt

Message ID 1404911451-9921-3-git-send-email-grygorii.strashko@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Grygorii Strashko July 9, 2014, 1:10 p.m. UTC
This patch allows to create PHYs from DT in case
if they are explicitly defined. The of_mdiobus_register() is
used for such purposes.

For backward compatibility, call  of_mdiobus_register() only in case
if at least one PHY's child is defined in DT, otherwise rollback to
mdiobus_register().

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 drivers/net/ethernet/ti/davinci_mdio.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Santosh Shilimkar July 9, 2014, 2:23 p.m. UTC | #1
On Wednesday 09 July 2014 09:10 AM, Grygorii Strashko wrote:
> This patch allows to create PHYs from DT in case
> if they are explicitly defined. The of_mdiobus_register() is
> used for such purposes.
> 
> For backward compatibility, call  of_mdiobus_register() only in case
> if at least one PHY's child is defined in DT, otherwise rollback to
> mdiobus_register().
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---
>  drivers/net/ethernet/ti/davinci_mdio.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
> index 735dc53..22d3dab 100644
> --- a/drivers/net/ethernet/ti/davinci_mdio.c
> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
> @@ -38,6 +38,7 @@
>  #include <linux/davinci_emac.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/of_mdio.h>
>  #include <linux/pinctrl/consumer.h>
>  
>  /*
> @@ -95,6 +96,7 @@ struct davinci_mdio_data {
>  	struct mii_bus	*bus;
>  	bool		suspended;
>  	unsigned long	access_time; /* jiffies */
> +	bool		skip_scan;
The vairiable name is not too intutive so probably add a little
bit description on what are you skipping with it.

>  };
>  
>  static void __davinci_mdio_reset(struct davinci_mdio_data *data)
> @@ -144,6 +146,9 @@ static int davinci_mdio_reset(struct mii_bus *bus)
>  	dev_info(data->dev, "davinci mdio revision %d.%d\n",
>  		 (ver >> 8) & 0xff, ver & 0xff);
>  
> +	if (data->skip_scan)
> +		return 0;
> +
>  	/* get phy mask from the alive register */
>  	phy_mask = __raw_readl(&data->regs->alive);
>  	if (phy_mask) {
> @@ -369,8 +374,17 @@ static int davinci_mdio_probe(struct platform_device *pdev)
>  		goto bail_out;
>  	}
>  
> -	/* register the mii bus */
> -	ret = mdiobus_register(data->bus);
> +	/* register the mii bus
> +	 * Create PHYs from DT only in case if PHY child nodes are explicitly
> +	 * defined to support backward compatibility with DTs which assume that
> +	 * Davinci MDIO will always scan the bus for PHYs detection.
> +	 */
multi line comment is not as per coding style. Please fix that.
Patch as such looks good to me so with those minor fixes, feel
free to append my review tag.

Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com>

> +	if (dev->of_node && of_get_child_count(dev->of_node)) {
> +		data->skip_scan = true;
> +		ret = of_mdiobus_register(data->bus, dev->of_node);
> +	} else {
> +		ret = mdiobus_register(data->bus);
> +	}
>  	if (ret)
>  		goto bail_out;
>  
>
Grygorii Strashko July 10, 2014, 1:15 p.m. UTC | #2
On 07/09/2014 05:23 PM, Santosh Shilimkar wrote:
> On Wednesday 09 July 2014 09:10 AM, Grygorii Strashko wrote:
>> This patch allows to create PHYs from DT in case
>> if they are explicitly defined. The of_mdiobus_register() is
>> used for such purposes.
>>
>> For backward compatibility, call  of_mdiobus_register() only in case
>> if at least one PHY's child is defined in DT, otherwise rollback to
>> mdiobus_register().
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>> ---
>>   drivers/net/ethernet/ti/davinci_mdio.c |   18 ++++++++++++++++--
>>   1 file changed, 16 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
>> index 735dc53..22d3dab 100644
>> --- a/drivers/net/ethernet/ti/davinci_mdio.c
>> +++ b/drivers/net/ethernet/ti/davinci_mdio.c
>> @@ -38,6 +38,7 @@
>>   #include <linux/davinci_emac.h>
>>   #include <linux/of.h>
>>   #include <linux/of_device.h>
>> +#include <linux/of_mdio.h>
>>   #include <linux/pinctrl/consumer.h>
>>   
>>   /*
>> @@ -95,6 +96,7 @@ struct davinci_mdio_data {
>>   	struct mii_bus	*bus;
>>   	bool		suspended;
>>   	unsigned long	access_time; /* jiffies */

	/*
	 * Indicates that driver shouldn't modify phy_mask in case
	 * if MDIO bus is registered from DT.
	 */

>> +	bool		skip_scan;
> The vairiable name is not too intutive so probably add a little
> bit description on what are you skipping with it.


Now the Davinci MDIO driver updates mii_bus->phy_mask from
its reset routine to limit number of phy addresses to be scanned.

The MDIO bus scanning has to be skipped at all in case of DT MDIO registration.
And of_mdiobus_register() maintain mii_bus->phy_mask by itself,
thus driver shouldn't touch it.

I'll add above comment. Is it ok?


> 
>>   };
>>   
>>   static void __davinci_mdio_reset(struct davinci_mdio_data *data)
>> @@ -144,6 +146,9 @@ static int davinci_mdio_reset(struct mii_bus *bus)
>>   	dev_info(data->dev, "davinci mdio revision %d.%d\n",
>>   		 (ver >> 8) & 0xff, ver & 0xff);
>>   
>> +	if (data->skip_scan)
>> +		return 0;
>> +
>>   	/* get phy mask from the alive register */
>>   	phy_mask = __raw_readl(&data->regs->alive);
>>   	if (phy_mask) {
>> @@ -369,8 +374,17 @@ static int davinci_mdio_probe(struct platform_device *pdev)
>>   		goto bail_out;
>>   	}
>>   
>> -	/* register the mii bus */
>> -	ret = mdiobus_register(data->bus);
>> +	/* register the mii bus
>> +	 * Create PHYs from DT only in case if PHY child nodes are explicitly
>> +	 * defined to support backward compatibility with DTs which assume that
>> +	 * Davinci MDIO will always scan the bus for PHYs detection.
>> +	 */
> multi line comment is not as per coding style. Please fix that.
> Patch as such looks good to me so with those minor fixes, feel
> free to append my review tag.

will fix it.

> 
> Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
> 
>> +	if (dev->of_node && of_get_child_count(dev->of_node)) {
>> +		data->skip_scan = true;
>> +		ret = of_mdiobus_register(data->bus, dev->of_node);
>> +	} else {
>> +		ret = mdiobus_register(data->bus);
>> +	}
>>   	if (ret)
>>   		goto bail_out;
>>   
>>
>
Mugunthan V N July 11, 2014, 5:05 a.m. UTC | #3
On Wednesday 09 July 2014 06:40 PM, Grygorii Strashko wrote:
> This patch allows to create PHYs from DT in case
> if they are explicitly defined. The of_mdiobus_register() is
> used for such purposes.
>
> For backward compatibility, call  of_mdiobus_register() only in case
> if at least one PHY's child is defined in DT, otherwise rollback to
> mdiobus_register().
>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Except Santhosh comment patch looks good to me.

Acked-by: Mugunthan V N <mugunthanvnm@ti.com>

Regards
Mugunthan V N
diff mbox

Patch

diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 735dc53..22d3dab 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -38,6 +38,7 @@ 
 #include <linux/davinci_emac.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/of_mdio.h>
 #include <linux/pinctrl/consumer.h>
 
 /*
@@ -95,6 +96,7 @@  struct davinci_mdio_data {
 	struct mii_bus	*bus;
 	bool		suspended;
 	unsigned long	access_time; /* jiffies */
+	bool		skip_scan;
 };
 
 static void __davinci_mdio_reset(struct davinci_mdio_data *data)
@@ -144,6 +146,9 @@  static int davinci_mdio_reset(struct mii_bus *bus)
 	dev_info(data->dev, "davinci mdio revision %d.%d\n",
 		 (ver >> 8) & 0xff, ver & 0xff);
 
+	if (data->skip_scan)
+		return 0;
+
 	/* get phy mask from the alive register */
 	phy_mask = __raw_readl(&data->regs->alive);
 	if (phy_mask) {
@@ -369,8 +374,17 @@  static int davinci_mdio_probe(struct platform_device *pdev)
 		goto bail_out;
 	}
 
-	/* register the mii bus */
-	ret = mdiobus_register(data->bus);
+	/* register the mii bus
+	 * Create PHYs from DT only in case if PHY child nodes are explicitly
+	 * defined to support backward compatibility with DTs which assume that
+	 * Davinci MDIO will always scan the bus for PHYs detection.
+	 */
+	if (dev->of_node && of_get_child_count(dev->of_node)) {
+		data->skip_scan = true;
+		ret = of_mdiobus_register(data->bus, dev->of_node);
+	} else {
+		ret = mdiobus_register(data->bus);
+	}
 	if (ret)
 		goto bail_out;