[v2,3/4] net/ftgmac100: Add NC-SI mode support
diff mbox series

Message ID 20190618013720.2823-4-sam@mendozajonas.com
State New
Headers show
Series
  • NC-SI PHY Support
Related show

Commit Message

Samuel Mendoza-Jonas June 18, 2019, 1:37 a.m. UTC
Update the ftgmac100 driver to support NC-SI instead of an mdio phy
where available. This is a common setup for Aspeed AST2x00 platforms.

NC-SI mode is determined from the device-tree if either phy-mode sets it
or the use-ncsi property exists. If set then normal mdio setup is
skipped in favour of the NC-SI phy.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

Comments

Cédric Le Goater June 18, 2019, 8:31 a.m. UTC | #1
On 18/06/2019 03:37, Samuel Mendoza-Jonas wrote:
> Update the ftgmac100 driver to support NC-SI instead of an mdio phy
> where available. This is a common setup for Aspeed AST2x00 platforms.
> 
> NC-SI mode is determined from the device-tree if either phy-mode sets it
> or the use-ncsi property exists. If set then normal mdio setup is
> skipped in favour of the NC-SI phy.
> 
> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>


LGTM. Some very minor remarks below in case you resend.

Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
>  drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++----------
>  1 file changed, 29 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
> index 92c38a81bd..c0100e91c7 100644
> --- a/drivers/net/ftgmac100.c
> +++ b/drivers/net/ftgmac100.c
> @@ -18,6 +18,7 @@
>  #include <wait_bit.h>
>  #include <linux/io.h>
>  #include <linux/iopoll.h>
> +#include <net/ncsi.h>
>  
>  #include "ftgmac100.h"
>  
> @@ -81,6 +82,7 @@ struct ftgmac100_data {
>  	struct mii_dev *bus;
>  	u32 phy_mode;
>  	u32 max_speed;
> +	bool ncsi_mode;
>  
>  	struct clk_bulk clks;
>  
> @@ -181,7 +183,7 @@ static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)
>  	struct phy_device *phydev = priv->phydev;
>  	u32 maccr;
>  
> -	if (!phydev->link) {
> +	if (!phydev->link && !priv->ncsi_mode) {
>  		dev_err(phydev->dev, "No link\n");
>  		return -EREMOTEIO;
>  	}
> @@ -217,7 +219,8 @@ static int ftgmac100_phy_init(struct udevice *dev)
>  	if (!phydev)
>  		return -ENODEV;
>  
> -	phydev->supported &= PHY_GBIT_FEATURES;
> +	if (!priv->ncsi_mode)
> +		phydev->supported &= PHY_GBIT_FEATURES;
>  	if (priv->max_speed) {
>  		ret = phy_set_supported(phydev, priv->max_speed);
>  		if (ret)
> @@ -275,7 +278,8 @@ static void ftgmac100_stop(struct udevice *dev)
>  
>  	writel(0, &ftgmac100->maccr);
>  
> -	phy_shutdown(priv->phydev);
> +	if (!priv->ncsi_mode)
> +		phy_shutdown(priv->phydev);
>  }
>  
>  static int ftgmac100_start(struct udevice *dev)
> @@ -513,6 +517,7 @@ static int ftgmac100_ofdata_to_platdata(struct udevice *dev)
>  	pdata->iobase = devfdt_get_addr(dev);
>  	pdata->phy_interface = -1;
>  	phy_mode = dev_read_string(dev, "phy-mode");
> +
>  	if (phy_mode)
>  		pdata->phy_interface = phy_get_interface_by_name(phy_mode);
>  	if (pdata->phy_interface == -1) {
> @@ -537,8 +542,13 @@ static int ftgmac100_probe(struct udevice *dev)
>  {
>  	struct eth_pdata *pdata = dev_get_platdata(dev);
>  	struct ftgmac100_data *priv = dev_get_priv(dev);
> +	const char *phy_mode;
>  	int ret;
>  
> +	phy_mode = dev_read_string(dev, "phy-mode");
> +	priv->ncsi_mode = dev_read_bool(dev, "use-ncsi") ||
> +		(phy_mode && strcmp(phy_mode, "NC-SI") == 0);

strncmp() may be ? I think a helper routine would make sense. 

> +
>  	priv->iobase = (struct ftgmac100 *)pdata->iobase;
>  	priv->phy_mode = pdata->phy_interface;
>  	priv->max_speed = pdata->max_speed;
> @@ -548,10 +558,15 @@ static int ftgmac100_probe(struct udevice *dev)
>  	if (ret)
>  		goto out;
>  
> -	ret = ftgmac100_mdio_init(dev);
> -	if (ret) {
> -		dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
> -		goto out;
> +	if (priv->ncsi_mode) {
> +		printf("%s - NCSI detected\n", __func__);

"NC-SI"

> +	} else {
> +		ret = ftgmac100_mdio_init(dev);
> +		if (ret) {
> +			dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
> +			goto out;
> +		}
> +
>  	}
>  
>  	ret = ftgmac100_phy_init(dev);
> @@ -571,9 +586,13 @@ static int ftgmac100_remove(struct udevice *dev)
>  {
>  	struct ftgmac100_data *priv = dev_get_priv(dev);
>  
> -	free(priv->phydev);
> -	mdio_unregister(priv->bus);
> -	mdio_free(priv->bus);
> +	if (!priv->ncsi_mode) {
> +		free(priv->phydev);
> +		mdio_unregister(priv->bus);
> +		mdio_free(priv->bus);
> +	} else {
> +		free(priv->phydev);
> +	}
>  	clk_release_bulk(&priv->clks);
>  
>  	return 0;
>
Joe Hershberger July 9, 2019, 11:28 p.m. UTC | #2
On Mon, Jun 17, 2019 at 8:43 PM Samuel Mendoza-Jonas
<sam@mendozajonas.com> wrote:
>
> Update the ftgmac100 driver to support NC-SI instead of an mdio phy
> where available. This is a common setup for Aspeed AST2x00 platforms.
>
> NC-SI mode is determined from the device-tree if either phy-mode sets it
> or the use-ncsi property exists. If set then normal mdio setup is
> skipped in favour of the NC-SI phy.
>
> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
> ---
>  drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++----------
>  1 file changed, 29 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
> index 92c38a81bd..c0100e91c7 100644
> --- a/drivers/net/ftgmac100.c
> +++ b/drivers/net/ftgmac100.c
> @@ -18,6 +18,7 @@
>  #include <wait_bit.h>
>  #include <linux/io.h>
>  #include <linux/iopoll.h>
> +#include <net/ncsi.h>
>
>  #include "ftgmac100.h"
>
> @@ -81,6 +82,7 @@ struct ftgmac100_data {
>         struct mii_dev *bus;
>         u32 phy_mode;
>         u32 max_speed;
> +       bool ncsi_mode;
>
>         struct clk_bulk clks;
>
> @@ -181,7 +183,7 @@ static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)
>         struct phy_device *phydev = priv->phydev;
>         u32 maccr;
>
> -       if (!phydev->link) {
> +       if (!phydev->link && !priv->ncsi_mode) {
>                 dev_err(phydev->dev, "No link\n");
>                 return -EREMOTEIO;
>         }
> @@ -217,7 +219,8 @@ static int ftgmac100_phy_init(struct udevice *dev)
>         if (!phydev)
>                 return -ENODEV;
>
> -       phydev->supported &= PHY_GBIT_FEATURES;
> +       if (!priv->ncsi_mode)
> +               phydev->supported &= PHY_GBIT_FEATURES;
>         if (priv->max_speed) {
>                 ret = phy_set_supported(phydev, priv->max_speed);
>                 if (ret)
> @@ -275,7 +278,8 @@ static void ftgmac100_stop(struct udevice *dev)
>
>         writel(0, &ftgmac100->maccr);
>
> -       phy_shutdown(priv->phydev);
> +       if (!priv->ncsi_mode)
> +               phy_shutdown(priv->phydev);
>  }
>
>  static int ftgmac100_start(struct udevice *dev)
> @@ -513,6 +517,7 @@ static int ftgmac100_ofdata_to_platdata(struct udevice *dev)
>         pdata->iobase = devfdt_get_addr(dev);
>         pdata->phy_interface = -1;
>         phy_mode = dev_read_string(dev, "phy-mode");
> +
>         if (phy_mode)
>                 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
>         if (pdata->phy_interface == -1) {
> @@ -537,8 +542,13 @@ static int ftgmac100_probe(struct udevice *dev)
>  {
>         struct eth_pdata *pdata = dev_get_platdata(dev);
>         struct ftgmac100_data *priv = dev_get_priv(dev);
> +       const char *phy_mode;
>         int ret;
>
> +       phy_mode = dev_read_string(dev, "phy-mode");
> +       priv->ncsi_mode = dev_read_bool(dev, "use-ncsi") ||
> +               (phy_mode && strcmp(phy_mode, "NC-SI") == 0);
> +
>         priv->iobase = (struct ftgmac100 *)pdata->iobase;
>         priv->phy_mode = pdata->phy_interface;
>         priv->max_speed = pdata->max_speed;
> @@ -548,10 +558,15 @@ static int ftgmac100_probe(struct udevice *dev)
>         if (ret)
>                 goto out;
>
> -       ret = ftgmac100_mdio_init(dev);
> -       if (ret) {
> -               dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
> -               goto out;
> +       if (priv->ncsi_mode) {
> +               printf("%s - NCSI detected\n", __func__);

NC-SI

> +       } else {
> +               ret = ftgmac100_mdio_init(dev);
> +               if (ret) {
> +                       dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
> +                       goto out;
> +               }
> +
>         }
>
>         ret = ftgmac100_phy_init(dev);
> @@ -571,9 +586,13 @@ static int ftgmac100_remove(struct udevice *dev)
>  {
>         struct ftgmac100_data *priv = dev_get_priv(dev);
>
> -       free(priv->phydev);
> -       mdio_unregister(priv->bus);
> -       mdio_free(priv->bus);

This should be before the test like it was and eliminate the else...
free(priv->phydev);

> +       if (!priv->ncsi_mode) {
> +               free(priv->phydev);
> +               mdio_unregister(priv->bus);
> +               mdio_free(priv->bus);
> +       } else {
> +               free(priv->phydev);
> +       }
>         clk_release_bulk(&priv->clks);
>
>         return 0;
> --
> 2.21.0
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot

Patch
diff mbox series

diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index 92c38a81bd..c0100e91c7 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -18,6 +18,7 @@ 
 #include <wait_bit.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
+#include <net/ncsi.h>
 
 #include "ftgmac100.h"
 
@@ -81,6 +82,7 @@  struct ftgmac100_data {
 	struct mii_dev *bus;
 	u32 phy_mode;
 	u32 max_speed;
+	bool ncsi_mode;
 
 	struct clk_bulk clks;
 
@@ -181,7 +183,7 @@  static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)
 	struct phy_device *phydev = priv->phydev;
 	u32 maccr;
 
-	if (!phydev->link) {
+	if (!phydev->link && !priv->ncsi_mode) {
 		dev_err(phydev->dev, "No link\n");
 		return -EREMOTEIO;
 	}
@@ -217,7 +219,8 @@  static int ftgmac100_phy_init(struct udevice *dev)
 	if (!phydev)
 		return -ENODEV;
 
-	phydev->supported &= PHY_GBIT_FEATURES;
+	if (!priv->ncsi_mode)
+		phydev->supported &= PHY_GBIT_FEATURES;
 	if (priv->max_speed) {
 		ret = phy_set_supported(phydev, priv->max_speed);
 		if (ret)
@@ -275,7 +278,8 @@  static void ftgmac100_stop(struct udevice *dev)
 
 	writel(0, &ftgmac100->maccr);
 
-	phy_shutdown(priv->phydev);
+	if (!priv->ncsi_mode)
+		phy_shutdown(priv->phydev);
 }
 
 static int ftgmac100_start(struct udevice *dev)
@@ -513,6 +517,7 @@  static int ftgmac100_ofdata_to_platdata(struct udevice *dev)
 	pdata->iobase = devfdt_get_addr(dev);
 	pdata->phy_interface = -1;
 	phy_mode = dev_read_string(dev, "phy-mode");
+
 	if (phy_mode)
 		pdata->phy_interface = phy_get_interface_by_name(phy_mode);
 	if (pdata->phy_interface == -1) {
@@ -537,8 +542,13 @@  static int ftgmac100_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct ftgmac100_data *priv = dev_get_priv(dev);
+	const char *phy_mode;
 	int ret;
 
+	phy_mode = dev_read_string(dev, "phy-mode");
+	priv->ncsi_mode = dev_read_bool(dev, "use-ncsi") ||
+		(phy_mode && strcmp(phy_mode, "NC-SI") == 0);
+
 	priv->iobase = (struct ftgmac100 *)pdata->iobase;
 	priv->phy_mode = pdata->phy_interface;
 	priv->max_speed = pdata->max_speed;
@@ -548,10 +558,15 @@  static int ftgmac100_probe(struct udevice *dev)
 	if (ret)
 		goto out;
 
-	ret = ftgmac100_mdio_init(dev);
-	if (ret) {
-		dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
-		goto out;
+	if (priv->ncsi_mode) {
+		printf("%s - NCSI detected\n", __func__);
+	} else {
+		ret = ftgmac100_mdio_init(dev);
+		if (ret) {
+			dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
+			goto out;
+		}
+
 	}
 
 	ret = ftgmac100_phy_init(dev);
@@ -571,9 +586,13 @@  static int ftgmac100_remove(struct udevice *dev)
 {
 	struct ftgmac100_data *priv = dev_get_priv(dev);
 
-	free(priv->phydev);
-	mdio_unregister(priv->bus);
-	mdio_free(priv->bus);
+	if (!priv->ncsi_mode) {
+		free(priv->phydev);
+		mdio_unregister(priv->bus);
+		mdio_free(priv->bus);
+	} else {
+		free(priv->phydev);
+	}
 	clk_release_bulk(&priv->clks);
 
 	return 0;