diff mbox series

[U-Boot,u-boot,1/2] net: phy: Add support for accessing MMD PHY registers

Message ID 20190116180436.8757-2-ccaione@baylibre.com
State Changes Requested
Delegated to: Joe Hershberger
Headers show
Series Add MMD PHY helpers | expand

Commit Message

Carlo Caione Jan. 16, 2019, 6:04 p.m. UTC
Two new helper functions (phy_read_mmd() and phy_write_mmd()) are added
to allow access to the MMD PHY registers.

The MMD PHY registers can be accessed by two means:

1. Using two new MMD access function hooks in the PHY driver. These
functions can be implemented when the PHY driver does not support the
standard IEEE Compatible clause 45 access mechanism described in clause
22 or if the PHY uses its own non-standard access mechanism.

2. The standard clause 45 access extensions to the MMD registers through
the indirection registers (clause 22) in all the other cases.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/net/phy/phy.c |  4 +++
 include/phy.h         | 62 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

Comments

Joe Hershberger Jan. 22, 2019, 10:21 p.m. UTC | #1
On Wed, Jan 16, 2019 at 12:06 PM Carlo Caione <ccaione@baylibre.com> wrote:
>
> Two new helper functions (phy_read_mmd() and phy_write_mmd()) are added
> to allow access to the MMD PHY registers.
>
> The MMD PHY registers can be accessed by two means:
>
> 1. Using two new MMD access function hooks in the PHY driver. These
> functions can be implemented when the PHY driver does not support the
> standard IEEE Compatible clause 45 access mechanism described in clause
> 22 or if the PHY uses its own non-standard access mechanism.
>
> 2. The standard clause 45 access extensions to the MMD registers through
> the indirection registers (clause 22) in all the other cases.
>
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>

This seems like a duplicate of https://patchwork.ozlabs.org/patch/1015782/

The command patch should probably be adapted to use that.

Thanks,
-Joe
Carlo Caione Jan. 22, 2019, 10:53 p.m. UTC | #2
On 22/01/19 22:21, Joe Hershberger wrote:
>On Wed, Jan 16, 2019 at 12:06 PM Carlo Caione <ccaione@baylibre.com> wrote:
>>
>> Two new helper functions (phy_read_mmd() and phy_write_mmd()) are added
>> to allow access to the MMD PHY registers.
>>
>> The MMD PHY registers can be accessed by two means:
>>
>> 1. Using two new MMD access function hooks in the PHY driver. These
>> functions can be implemented when the PHY driver does not support the
>> standard IEEE Compatible clause 45 access mechanism described in clause
>> 22 or if the PHY uses its own non-standard access mechanism.
>>
>> 2. The standard clause 45 access extensions to the MMD registers through
>> the indirection registers (clause 22) in all the other cases.
>>
>> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
>
>This seems like a duplicate of https://patchwork.ozlabs.org/patch/1015782/

Well, I should have looked better. Interestingly I was going to use my
patch to fix the exact same issue on a different PHY.

The problem I see with that patch is that it is assuming that all the 
PHY devices support clause 45 access extension using the clause 22 
registers. This is not always true (see for example [0]). That's why I 
added two new hooks in the PHY driver.

On a side note looking at that patch it seems that 'addr' (documented as 
the PHY address in the same patch) is being passed to 'phy_write' where 
we should have the 'devad' parameter instead (MDIO_DEVAD_NONE)?

>The command patch should probably be adapted to use that.

Let me know if you think it is valuable still to add the two hooks on 
top of that patch.

Thanks,

[0] https://patchwork.ozlabs.org/patch/351634/
Joe Hershberger Jan. 23, 2019, 12:04 a.m. UTC | #3
On Tue, Jan 22, 2019 at 4:54 PM Carlo Caione <ccaione@baylibre.com> wrote:
>
> On 22/01/19 22:21, Joe Hershberger wrote:
> >On Wed, Jan 16, 2019 at 12:06 PM Carlo Caione <ccaione@baylibre.com> wrote:
> >>
> >> Two new helper functions (phy_read_mmd() and phy_write_mmd()) are added
> >> to allow access to the MMD PHY registers.
> >>
> >> The MMD PHY registers can be accessed by two means:
> >>
> >> 1. Using two new MMD access function hooks in the PHY driver. These
> >> functions can be implemented when the PHY driver does not support the
> >> standard IEEE Compatible clause 45 access mechanism described in clause
> >> 22 or if the PHY uses its own non-standard access mechanism.
> >>
> >> 2. The standard clause 45 access extensions to the MMD registers through
> >> the indirection registers (clause 22) in all the other cases.
> >>
> >> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> >
> >This seems like a duplicate of https://patchwork.ozlabs.org/patch/1015782/
>
> Well, I should have looked better. Interestingly I was going to use my
> patch to fix the exact same issue on a different PHY.
>
> The problem I see with that patch is that it is assuming that all the
> PHY devices support clause 45 access extension using the clause 22
> registers. This is not always true (see for example [0]). That's why I
> added two new hooks in the PHY driver.

Ah, I didn't realize there were other ways to access it.

> On a side note looking at that patch it seems that 'addr' (documented as
> the PHY address in the same patch) is being passed to 'phy_write' where
> we should have the 'devad' parameter instead (MDIO_DEVAD_NONE)?

That is peculiar... Vlad, that wasn't your intent, was it?

> >The command patch should probably be adapted to use that.
>
> Let me know if you think it is valuable still to add the two hooks on
> top of that patch.

If we have to override the access then probably so. Maybe it would
make more sense to have a v2 from you that removes the duplicate code
from the ti phy driver and then have Vlad's smartEEE patch be rebased
on that.

I have not yet pushed Vlad's patches so we have an opportunity to do
it more cleanly potentially.

Thoughts from each of you?

> Thanks,
>
> [0] https://patchwork.ozlabs.org/patch/351634/
>
> --
> Carlo Caione
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
Carlo Caione Jan. 23, 2019, 9:59 a.m. UTC | #4
On 23/01/19 00:04, Joe Hershberger wrote:
>
>If we have to override the access then probably so. Maybe it would
>make more sense to have a v2 from you that removes the duplicate code
>from the ti phy driver and then have Vlad's smartEEE patch be rebased
>on that.
>
>I have not yet pushed Vlad's patches so we have an opportunity to do
>it more cleanly potentially.
>
>Thoughts from each of you?

I'll rebase that patch on top of my set and I'll let Vlad submit the 
smartEEE patch on top.
Vladimir Oltean Jan. 23, 2019, 12:58 p.m. UTC | #5
On 23.01.2019 11:59, Carlo Caione wrote:
> On 23/01/19 00:04, Joe Hershberger wrote:
>>
>> If we have to override the access then probably so. Maybe it would
>> make more sense to have a v2 from you that removes the duplicate code
>> from the ti phy driver and then have Vlad's smartEEE patch be rebased
>> on that.
>>
>> I have not yet pushed Vlad's patches so we have an opportunity to do
>> it more cleanly potentially.
>>
>> Thoughts from each of you?
> 
> I'll rebase that patch on top of my set and I'll let Vlad submit the 
> smartEEE patch on top.
> 

Hi Carlo, good if you could take care of the TI driver and I will resend 
the Atheros SmartEEE patch to use phy_read_mmd/phy_write_mmd.

Thanks,
-Vladimir
Joe Hershberger Jan. 23, 2019, 3:54 p.m. UTC | #6
On Wed, Jan 23, 2019 at 8:32 AM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
>
> On 23.01.2019 11:59, Carlo Caione wrote:
> > On 23/01/19 00:04, Joe Hershberger wrote:
> >>
> >> If we have to override the access then probably so. Maybe it would
> >> make more sense to have a v2 from you that removes the duplicate code
> >> from the ti phy driver and then have Vlad's smartEEE patch be rebased
> >> on that.
> >>
> >> I have not yet pushed Vlad's patches so we have an opportunity to do
> >> it more cleanly potentially.
> >>
> >> Thoughts from each of you?
> >
> > I'll rebase that patch on top of my set and I'll let Vlad submit the
> > smartEEE patch on top.
> >
>
> Hi Carlo, good if you could take care of the TI driver and I will resend
> the Atheros SmartEEE patch to use phy_read_mmd/phy_write_mmd.

He's already sent a V1 that you could base off of. The changes I
requested should not make it incompatible with your Atheros change.

Thanks,
-Joe

>
> Thanks,
> -Vladimir
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
diff mbox series

Patch

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index cda4caa803..6769047407 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -549,6 +549,10 @@  int phy_register(struct phy_driver *drv)
 		drv->readext += gd->reloc_off;
 	if (drv->writeext)
 		drv->writeext += gd->reloc_off;
+	if (drv->read_mmd)
+		drv->read_mmd += gd->reloc_off;
+	if (drv->write_mmd)
+		drv->write_mmd += gd->reloc_off;
 #endif
 	return 0;
 }
diff --git a/include/phy.h b/include/phy.h
index b86fdfb2ce..0ce41661fa 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -101,6 +101,13 @@  struct phy_driver {
 	int (*readext)(struct phy_device *phydev, int addr, int devad, int reg);
 	int (*writeext)(struct phy_device *phydev, int addr, int devad, int reg,
 			u16 val);
+
+	/* Phy specific driver override for reading a MMD register */
+	int (*read_mmd)(struct phy_device *phydev, int devad, int reg);
+
+	/* Phy specific driver override for writing a MMD register */
+	int (*write_mmd)(struct phy_device *phydev, int devad, int reg, u16 val);
+
 	struct list_head list;
 };
 
@@ -164,6 +171,61 @@  static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
 	return bus->write(bus, phydev->addr, devad, regnum, val);
 }
 
+static inline void phy_mmd_indirect(struct phy_device *phydev, int devad,
+				    int regnum)
+{
+	/* Write the desired MMD Devad */
+	phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, devad);
+
+	/* Write the desired MMD register address */
+	phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, regnum);
+
+	/* Select the Function : DATA with no post increment */
+	phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR));
+}
+
+static inline int phy_read_mmd(struct phy_device *phydev, int devad,
+			       int regnum)
+{
+	int ret;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	if (phydev->drv->read_mmd) {
+		ret = phydev->drv->read_mmd(phydev, devad, regnum);
+	} else {
+		phy_mmd_indirect(phydev, devad, regnum);
+
+		/* Read the content of the MMD's selected register */
+		ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA);
+	}
+
+	return ret;
+}
+
+static inline int phy_write_mmd(struct phy_device *phydev, int devad,
+				int regnum, u16 val)
+{
+	int ret;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	if (phydev->drv->write_mmd) {
+		ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
+	} else {
+		phy_mmd_indirect(phydev, devad, regnum);
+
+		/* Write the data into MMD's selected register */
+		phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val);
+
+		ret = 0;
+	}
+
+	return ret;
+}
+
 #ifdef CONFIG_PHYLIB_10G
 extern struct phy_driver gen10g_driver;