diff mbox series

[PATCHv2,3/3] net: tsec: Access TBI PHY through the corresponding MII

Message ID 20200503144843.36949-4-Zhiqiang.Hou@nxp.com
State New
Headers show
Series net: tsec: Fix issues of DM driver | expand

Commit Message

Zhiqiang Hou May 3, 2020, 2:48 p.m. UTC
From: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>

When an eTSEC is configured to use TBI, configuration of the
TBI is done through the MIIM registers for that eTSEC.
For example, if a TBI interface is required on eTSEC2, then
the MIIM registers starting at offset 0x2_5520 are used to
configure it.

Fixes: 9a1d6af55ecd ("net: tsec: Add driver model ethernet support")
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean at nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean at nxp.com>
---
V2:
 - Added error message for getting the internal TBI PHY MII reg.
 - Only try to get TBI PHY MII reg under the condition "tbi-handle".

 drivers/net/tsec.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

Comments

Vladimir Oltean May 3, 2020, 4:26 p.m. UTC | #1
On Sun, 3 May 2020 at 17:53, Zhiqiang Hou <Zhiqiang.Hou at nxp.com> wrote:
>
> From: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>
>
> When an eTSEC is configured to use TBI, configuration of the
> TBI is done through the MIIM registers for that eTSEC.
> For example, if a TBI interface is required on eTSEC2, then
> the MIIM registers starting at offset 0x2_5520 are used to
> configure it.
>
> Fixes: 9a1d6af55ecd ("net: tsec: Add driver model ethernet support")
> Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>
> Reviewed-by: Vladimir Oltean <vladimir.oltean at nxp.com>
> Tested-by: Vladimir Oltean <vladimir.oltean at nxp.com>
> ---

Looks good, thanks!
Out of curiosity, are you also working on DM_MDIO for the tsec driver?
Some of this code should go away when we do that conversion.

> V2:
>  - Added error message for getting the internal TBI PHY MII reg.
>  - Only try to get TBI PHY MII reg under the condition "tbi-handle".
>
>  drivers/net/tsec.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
> index 541f964d2e..842cddf229 100644
> --- a/drivers/net/tsec.c
> +++ b/drivers/net/tsec.c
> @@ -789,6 +789,7 @@ int tsec_probe(struct udevice *dev)
>  {
>         struct eth_pdata *pdata = dev_get_platdata(dev);
>         struct tsec_private *priv = dev_get_priv(dev);
> +       struct tsec_mii_mng __iomem *ext_phyregs_mii;
>         struct ofnode_phandle_args phandle_args;
>         u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
>         struct fsl_pq_mdio_info mdio_info;
> @@ -822,14 +823,30 @@ int tsec_probe(struct udevice *dev)
>                 return -ENOENT;
>         }
>
> -       priv->phyregs_sgmii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0,
> -                                         MAP_NOCACHE);
> +       ext_phyregs_mii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0,
> +                                     MAP_NOCACHE);
>
>         ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
>                                          &phandle_args);
> -       if (ret == 0)
> +       if (ret == 0) {
>                 ofnode_read_u32(phandle_args.node, "reg", &tbiaddr);
>
> +               parent = ofnode_get_parent(phandle_args.node);
> +               if (!ofnode_valid(parent)) {
> +                       printf("No parent node for TBI PHY?\n");
> +                       return -ENOENT;
> +               }
> +
> +               reg = ofnode_get_addr_index(parent, 0);
> +               if (reg == FDT_ADDR_T_NONE) {
> +                       printf("No 'reg' property of MII for TBI PHY\n");
> +                       return -ENOENT;
> +               }
> +
> +               priv->phyregs_sgmii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET,
> +                                                 0, MAP_NOCACHE);
> +       }
> +
>         priv->tbiaddr = tbiaddr;
>
>         phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
> @@ -846,7 +863,7 @@ int tsec_probe(struct udevice *dev)
>         if (priv->interface == PHY_INTERFACE_MODE_SGMII)
>                 priv->flags |= TSEC_SGMII;
>
> -       mdio_info.regs = priv->phyregs_sgmii;
> +       mdio_info.regs = ext_phyregs_mii;
>         mdio_info.name = (char *)dev->name;
>         ret = fsl_pq_mdio_init(NULL, &mdio_info);
>         if (ret)
> --
> 2.17.1
>

Regards,
-Vladimir
Zhiqiang Hou May 4, 2020, 6:06 a.m. UTC | #2
Hi Vladimir,

Thanks for your comments!

> -----Original Message-----
> From: Vladimir Oltean <olteanv at gmail.com>
> Sent: 2020?5?4? 0:27
> To: Z.q. Hou <zhiqiang.hou at nxp.com>
> Cc: u-boot <u-boot at lists.denx.de>; Joe Hershberger
> <joe.hershberger at ni.com>; Bin Meng <bmeng.cn at gmail.com>; Priyanka Jain
> <priyanka.jain at nxp.com>
> Subject: Re: [PATCHv2 3/3] net: tsec: Access TBI PHY through the
> corresponding MII
> 
> On Sun, 3 May 2020 at 17:53, Zhiqiang Hou <Zhiqiang.Hou at nxp.com> wrote:
> >
> > From: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>
> >
> > When an eTSEC is configured to use TBI, configuration of the TBI is
> > done through the MIIM registers for that eTSEC.
> > For example, if a TBI interface is required on eTSEC2, then the MIIM
> > registers starting at offset 0x2_5520 are used to configure it.
> >
> > Fixes: 9a1d6af55ecd ("net: tsec: Add driver model ethernet support")
> > Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou at nxp.com>
> > Reviewed-by: Vladimir Oltean <vladimir.oltean at nxp.com>
> > Tested-by: Vladimir Oltean <vladimir.oltean at nxp.com>
> > ---
> 
> Looks good, thanks!
> Out of curiosity, are you also working on DM_MDIO for the tsec driver?
> Some of this code should go away when we do that conversion.

No, I'm not, I saw your patches for the DM_MDIO support.

Thanks,
Zhiqiang

> 
> > V2:
> >  - Added error message for getting the internal TBI PHY MII reg.
> >  - Only try to get TBI PHY MII reg under the condition "tbi-handle".
> >
> >  drivers/net/tsec.c | 25 +++++++++++++++++++++----
> >  1 file changed, 21 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index
> > 541f964d2e..842cddf229 100644
> > --- a/drivers/net/tsec.c
> > +++ b/drivers/net/tsec.c
> > @@ -789,6 +789,7 @@ int tsec_probe(struct udevice *dev)  {
> >         struct eth_pdata *pdata = dev_get_platdata(dev);
> >         struct tsec_private *priv = dev_get_priv(dev);
> > +       struct tsec_mii_mng __iomem *ext_phyregs_mii;
> >         struct ofnode_phandle_args phandle_args;
> >         u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
> >         struct fsl_pq_mdio_info mdio_info; @@ -822,14 +823,30 @@ int
> > tsec_probe(struct udevice *dev)
> >                 return -ENOENT;
> >         }
> >
> > -       priv->phyregs_sgmii = map_physmem(reg +
> TSEC_MDIO_REGS_OFFSET, 0,
> > -                                         MAP_NOCACHE);
> > +       ext_phyregs_mii = map_physmem(reg +
> TSEC_MDIO_REGS_OFFSET, 0,
> > +                                     MAP_NOCACHE);
> >
> >         ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
> >                                          &phandle_args);
> > -       if (ret == 0)
> > +       if (ret == 0) {
> >                 ofnode_read_u32(phandle_args.node, "reg", &tbiaddr);
> >
> > +               parent = ofnode_get_parent(phandle_args.node);
> > +               if (!ofnode_valid(parent)) {
> > +                       printf("No parent node for TBI PHY?\n");
> > +                       return -ENOENT;
> > +               }
> > +
> > +               reg = ofnode_get_addr_index(parent, 0);
> > +               if (reg == FDT_ADDR_T_NONE) {
> > +                       printf("No 'reg' property of MII for TBI
> PHY\n");
> > +                       return -ENOENT;
> > +               }
> > +
> > +               priv->phyregs_sgmii = map_physmem(reg +
> TSEC_MDIO_REGS_OFFSET,
> > +                                                 0,
> MAP_NOCACHE);
> > +       }
> > +
> >         priv->tbiaddr = tbiaddr;
> >
> >         phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
> @@
> > -846,7 +863,7 @@ int tsec_probe(struct udevice *dev)
> >         if (priv->interface == PHY_INTERFACE_MODE_SGMII)
> >                 priv->flags |= TSEC_SGMII;
> >
> > -       mdio_info.regs = priv->phyregs_sgmii;
> > +       mdio_info.regs = ext_phyregs_mii;
> >         mdio_info.name = (char *)dev->name;
> >         ret = fsl_pq_mdio_init(NULL, &mdio_info);
> >         if (ret)
> > --
> > 2.17.1
> >
> 
> Regards,
> -Vladimir
diff mbox series

Patch

diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
index 541f964d2e..842cddf229 100644
--- a/drivers/net/tsec.c
+++ b/drivers/net/tsec.c
@@ -789,6 +789,7 @@  int tsec_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct tsec_private *priv = dev_get_priv(dev);
+	struct tsec_mii_mng __iomem *ext_phyregs_mii;
 	struct ofnode_phandle_args phandle_args;
 	u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
 	struct fsl_pq_mdio_info mdio_info;
@@ -822,14 +823,30 @@  int tsec_probe(struct udevice *dev)
 		return -ENOENT;
 	}
 
-	priv->phyregs_sgmii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0,
-					  MAP_NOCACHE);
+	ext_phyregs_mii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0,
+				      MAP_NOCACHE);
 
 	ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
 					 &phandle_args);
-	if (ret == 0)
+	if (ret == 0) {
 		ofnode_read_u32(phandle_args.node, "reg", &tbiaddr);
 
+		parent = ofnode_get_parent(phandle_args.node);
+		if (!ofnode_valid(parent)) {
+			printf("No parent node for TBI PHY?\n");
+			return -ENOENT;
+		}
+
+		reg = ofnode_get_addr_index(parent, 0);
+		if (reg == FDT_ADDR_T_NONE) {
+			printf("No 'reg' property of MII for TBI PHY\n");
+			return -ENOENT;
+		}
+
+		priv->phyregs_sgmii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET,
+						  0, MAP_NOCACHE);
+	}
+
 	priv->tbiaddr = tbiaddr;
 
 	phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
@@ -846,7 +863,7 @@  int tsec_probe(struct udevice *dev)
 	if (priv->interface == PHY_INTERFACE_MODE_SGMII)
 		priv->flags |= TSEC_SGMII;
 
-	mdio_info.regs = priv->phyregs_sgmii;
+	mdio_info.regs = ext_phyregs_mii;
 	mdio_info.name = (char *)dev->name;
 	ret = fsl_pq_mdio_init(NULL, &mdio_info);
 	if (ret)