Re: [U-Boot] [PATCH] net: introduce MDIO DM class for MDIO devices

2019-06-01 Thread Alex Marginean

On 6/1/2019 9:42 PM, Joe Hershberger wrote:

Hi Bin,

Thanks for the review. I shouldn't have tried to look at this while
falling asleep in the airport. :(

-Joe


I guess I should have double checked the comments and the other things
too, sorry for that..
I'll send a v2 on Monday.

Thank you!
Alex



On Sat, Jun 1, 2019 at 12:16 PM Bin Meng  wrote:


Hi Alex,

On Sat, Jun 1, 2019 at 12:27 AM Alex Marginean  wrote:


Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
stand-alone devices.  Useful in particular for systems that support
DM_ETH and have a stand-alone MDIO hardware block shared by multiple
Ethernet interfaces.



Please add a test case for testing mdio (see test/dm/*)


Signed-off-by: Alex Marginean 
---
  cmd/mdio.c |   5 ++
  drivers/net/Kconfig|  13 +
  include/dm/uclass-id.h |   1 +
  include/miiphy.h   |  50 
  net/Makefile   |   1 +
  net/mdio-uclass.c  | 105 +
  6 files changed, 175 insertions(+)
  create mode 100644 net/mdio-uclass.c

diff --git a/cmd/mdio.c b/cmd/mdio.c
index 5e219f699d..a6fa9266d0 100644
--- a/cmd/mdio.c
+++ b/cmd/mdio.c
@@ -203,6 +203,11 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 if (argc < 2)
 return CMD_RET_USAGE;

+#ifdef CONFIG_DM_MDIO
+   /* probe DM MII device before any operation so they are all accesible */
+   dm_mdio_probe_devices();
+#endif
+
 /*
  * We use the last specified parameters, unless new ones are
  * entered.
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e6a4fdf30e..6fba5a84dd 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -11,6 +11,19 @@ config DM_ETH
   This is currently implemented in net/eth-uclass.c
   Look in include/net.h for details.

+config DM_MDIO
+   bool "Enable Driver Model for MDIO devices"
+   depends on DM_ETH && PHYLIB
+   help
+ Enable driver model for MDIO devices
+
+ Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
+ stand-alone devices.  Useful in particular for systems that support
+ DM_ETH and have a stand-alone MDIO hardware block shared by multiple
+ Ethernet interfaces.
+ This is currently implemented in net/mdio-uclass.c
+ Look in include/miiphy.h for details.
+
  menuconfig NETDEVICES
 bool "Network device support"
 depends on NET
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 09e0ad5391..90667e62cf 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -58,6 +58,7 @@ enum uclass_id {
 UCLASS_LPC, /* x86 'low pin count' interface */
 UCLASS_MAILBOX, /* Mailbox controller */
 UCLASS_MASS_STORAGE,/* Mass storage device */
+   UCLASS_MDIO,/* MDIO bus */
 UCLASS_MISC,/* Miscellaneous device */
 UCLASS_MMC, /* SD / MMC card or chip */
 UCLASS_MOD_EXP, /* RSA Mod Exp device */
diff --git a/include/miiphy.h b/include/miiphy.h
index f11763affd..455feacd33 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -118,4 +118,54 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, int 
devad, int reg,
  #define ESTATUS_1000XF 0x8000
  #define ESTATUS_1000XH 0x4000

+#ifdef CONFIG_DM_MDIO
+
+/**
+ * struct mii_pdata - Platform data for MDIO buses


wrong name: mii_pdata


+ *
+ * @mii_bus: Supporting MII legacy bus
+ * @priv_pdata: device specific platdata


there is no such field called priv_pdata.


+ */
+struct mdio_perdev_priv {
+   struct mii_dev *mii_bus;
+};
+
+/**
+ * struct mii_ops - MDIO bus operations


struct mdio_ops


+ *
+ * @read: Read from a PHY register
+ * @write: Write to a PHY register
+ * @reset: Reset the MDIO bus, NULL if not supported
+ */
+struct mdio_ops {
+   int (*read)(struct udevice *mdio_dev, int addr, int devad, int reg);
+   int (*write)(struct udevice *mdio_dev, int addr, int devad, int reg,
+u16 val);
+   int (*reset)(struct udevice *mdio_dev);
+};
+
+#define mdio_get_ops(dev) ((struct mdio_ops *)(dev)->driver->ops)
+
+/**
+ * mii_dm_probe_devices - Call probe on all MII devices, currently used for


wrong name "mii_dm_probe_devices". MII devices -> MDIO devices?


+ * MDIO console commands.
+ */
+void dm_mdio_probe_devices(void);
+
+/**
+ * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
+ *
+ * @dev: mdio dev
+ * @addr: PHY address on MDIO bus
+ * @ethdev: ethernet device to connect to the PHY
+ * @interface: MAC-PHY protocol
+ *
+ * @return pointer to phy_device, or 0 on error
+ */
+struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr,
+  struct udevice *ethdev,
+  phy_interface_t interface);
+
+#endif
+
  #endif
diff --git a/net/Makefile 

Re: [U-Boot] [PATCH] net: introduce MDIO DM class for MDIO devices

2019-06-01 Thread Joe Hershberger
Hi Bin,

Thanks for the review. I shouldn't have tried to look at this while
falling asleep in the airport. :(

-Joe

On Sat, Jun 1, 2019 at 12:16 PM Bin Meng  wrote:
>
> Hi Alex,
>
> On Sat, Jun 1, 2019 at 12:27 AM Alex Marginean  
> wrote:
> >
> > Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> > stand-alone devices.  Useful in particular for systems that support
> > DM_ETH and have a stand-alone MDIO hardware block shared by multiple
> > Ethernet interfaces.
> >
>
> Please add a test case for testing mdio (see test/dm/*)
>
> > Signed-off-by: Alex Marginean 
> > ---
> >  cmd/mdio.c |   5 ++
> >  drivers/net/Kconfig|  13 +
> >  include/dm/uclass-id.h |   1 +
> >  include/miiphy.h   |  50 
> >  net/Makefile   |   1 +
> >  net/mdio-uclass.c  | 105 +
> >  6 files changed, 175 insertions(+)
> >  create mode 100644 net/mdio-uclass.c
> >
> > diff --git a/cmd/mdio.c b/cmd/mdio.c
> > index 5e219f699d..a6fa9266d0 100644
> > --- a/cmd/mdio.c
> > +++ b/cmd/mdio.c
> > @@ -203,6 +203,11 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int 
> > argc, char * const argv[])
> > if (argc < 2)
> > return CMD_RET_USAGE;
> >
> > +#ifdef CONFIG_DM_MDIO
> > +   /* probe DM MII device before any operation so they are all 
> > accesible */
> > +   dm_mdio_probe_devices();
> > +#endif
> > +
> > /*
> >  * We use the last specified parameters, unless new ones are
> >  * entered.
> > diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> > index e6a4fdf30e..6fba5a84dd 100644
> > --- a/drivers/net/Kconfig
> > +++ b/drivers/net/Kconfig
> > @@ -11,6 +11,19 @@ config DM_ETH
> >   This is currently implemented in net/eth-uclass.c
> >   Look in include/net.h for details.
> >
> > +config DM_MDIO
> > +   bool "Enable Driver Model for MDIO devices"
> > +   depends on DM_ETH && PHYLIB
> > +   help
> > + Enable driver model for MDIO devices
> > +
> > + Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> > + stand-alone devices.  Useful in particular for systems that 
> > support
> > + DM_ETH and have a stand-alone MDIO hardware block shared by 
> > multiple
> > + Ethernet interfaces.
> > + This is currently implemented in net/mdio-uclass.c
> > + Look in include/miiphy.h for details.
> > +
> >  menuconfig NETDEVICES
> > bool "Network device support"
> > depends on NET
> > diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> > index 09e0ad5391..90667e62cf 100644
> > --- a/include/dm/uclass-id.h
> > +++ b/include/dm/uclass-id.h
> > @@ -58,6 +58,7 @@ enum uclass_id {
> > UCLASS_LPC, /* x86 'low pin count' interface */
> > UCLASS_MAILBOX, /* Mailbox controller */
> > UCLASS_MASS_STORAGE,/* Mass storage device */
> > +   UCLASS_MDIO,/* MDIO bus */
> > UCLASS_MISC,/* Miscellaneous device */
> > UCLASS_MMC, /* SD / MMC card or chip */
> > UCLASS_MOD_EXP, /* RSA Mod Exp device */
> > diff --git a/include/miiphy.h b/include/miiphy.h
> > index f11763affd..455feacd33 100644
> > --- a/include/miiphy.h
> > +++ b/include/miiphy.h
> > @@ -118,4 +118,54 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, 
> > int devad, int reg,
> >  #define ESTATUS_1000XF 0x8000
> >  #define ESTATUS_1000XH 0x4000
> >
> > +#ifdef CONFIG_DM_MDIO
> > +
> > +/**
> > + * struct mii_pdata - Platform data for MDIO buses
>
> wrong name: mii_pdata
>
> > + *
> > + * @mii_bus: Supporting MII legacy bus
> > + * @priv_pdata: device specific platdata
>
> there is no such field called priv_pdata.
>
> > + */
> > +struct mdio_perdev_priv {
> > +   struct mii_dev *mii_bus;
> > +};
> > +
> > +/**
> > + * struct mii_ops - MDIO bus operations
>
> struct mdio_ops
>
> > + *
> > + * @read: Read from a PHY register
> > + * @write: Write to a PHY register
> > + * @reset: Reset the MDIO bus, NULL if not supported
> > + */
> > +struct mdio_ops {
> > +   int (*read)(struct udevice *mdio_dev, int addr, int devad, int reg);
> > +   int (*write)(struct udevice *mdio_dev, int addr, int devad, int reg,
> > +u16 val);
> > +   int (*reset)(struct udevice *mdio_dev);
> > +};
> > +
> > +#define mdio_get_ops(dev) ((struct mdio_ops *)(dev)->driver->ops)
> > +
> > +/**
> > + * mii_dm_probe_devices - Call probe on all MII devices, currently used for
>
> wrong name "mii_dm_probe_devices". MII devices -> MDIO devices?
>
> > + * MDIO console commands.
> > + */
> > +void dm_mdio_probe_devices(void);
> > +
> > +/**
> > + * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
> > + *
> > + * @dev: mdio dev
> > + * @addr: PHY address on MDIO bus
> > + * @ethdev: ethernet device to connect to the PHY
> > + * @interface: MAC-PHY protocol
> > + *
> > 

Re: [U-Boot] [PATCH] net: introduce MDIO DM class for MDIO devices

2019-06-01 Thread Alex Marginean

Hi Bin,

On 6/1/2019 8:16 PM, Bin Meng wrote:

Hi Alex,

On Sat, Jun 1, 2019 at 12:27 AM Alex Marginean  wrote:


Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
stand-alone devices.  Useful in particular for systems that support
DM_ETH and have a stand-alone MDIO hardware block shared by multiple
Ethernet interfaces.



Please add a test case for testing mdio (see test/dm/*)


OK, will look into it.




Signed-off-by: Alex Marginean 
---
  cmd/mdio.c |   5 ++
  drivers/net/Kconfig|  13 +
  include/dm/uclass-id.h |   1 +
  include/miiphy.h   |  50 
  net/Makefile   |   1 +
  net/mdio-uclass.c  | 105 +
  6 files changed, 175 insertions(+)
  create mode 100644 net/mdio-uclass.c

diff --git a/cmd/mdio.c b/cmd/mdio.c
index 5e219f699d..a6fa9266d0 100644
--- a/cmd/mdio.c
+++ b/cmd/mdio.c
@@ -203,6 +203,11 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 if (argc < 2)
 return CMD_RET_USAGE;

+#ifdef CONFIG_DM_MDIO
+   /* probe DM MII device before any operation so they are all accesible */
+   dm_mdio_probe_devices();
+#endif
+
 /*
  * We use the last specified parameters, unless new ones are
  * entered.
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e6a4fdf30e..6fba5a84dd 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -11,6 +11,19 @@ config DM_ETH
   This is currently implemented in net/eth-uclass.c
   Look in include/net.h for details.

+config DM_MDIO
+   bool "Enable Driver Model for MDIO devices"
+   depends on DM_ETH && PHYLIB
+   help
+ Enable driver model for MDIO devices
+
+ Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
+ stand-alone devices.  Useful in particular for systems that support
+ DM_ETH and have a stand-alone MDIO hardware block shared by multiple
+ Ethernet interfaces.
+ This is currently implemented in net/mdio-uclass.c
+ Look in include/miiphy.h for details.
+
  menuconfig NETDEVICES
 bool "Network device support"
 depends on NET
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 09e0ad5391..90667e62cf 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -58,6 +58,7 @@ enum uclass_id {
 UCLASS_LPC, /* x86 'low pin count' interface */
 UCLASS_MAILBOX, /* Mailbox controller */
 UCLASS_MASS_STORAGE,/* Mass storage device */
+   UCLASS_MDIO,/* MDIO bus */
 UCLASS_MISC,/* Miscellaneous device */
 UCLASS_MMC, /* SD / MMC card or chip */
 UCLASS_MOD_EXP, /* RSA Mod Exp device */
diff --git a/include/miiphy.h b/include/miiphy.h
index f11763affd..455feacd33 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -118,4 +118,54 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, int 
devad, int reg,
  #define ESTATUS_1000XF 0x8000
  #define ESTATUS_1000XH 0x4000

+#ifdef CONFIG_DM_MDIO
+
+/**
+ * struct mii_pdata - Platform data for MDIO buses


wrong name: mii_pdata


Oops, I had this renamed and refactored and I seem to missed the
comments entirely.  And a few other things as you pointed out below.




+ *
+ * @mii_bus: Supporting MII legacy bus
+ * @priv_pdata: device specific platdata


there is no such field called priv_pdata.


+ */
+struct mdio_perdev_priv {
+   struct mii_dev *mii_bus;
+};
+
+/**
+ * struct mii_ops - MDIO bus operations


struct mdio_ops


Thanks for pointing these out, I'll send a v2 with the fixes.



+ *
+ * @read: Read from a PHY register
+ * @write: Write to a PHY register
+ * @reset: Reset the MDIO bus, NULL if not supported
+ */
+struct mdio_ops {
+   int (*read)(struct udevice *mdio_dev, int addr, int devad, int reg);
+   int (*write)(struct udevice *mdio_dev, int addr, int devad, int reg,
+u16 val);
+   int (*reset)(struct udevice *mdio_dev);
+};
+
+#define mdio_get_ops(dev) ((struct mdio_ops *)(dev)->driver->ops)
+
+/**
+ * mii_dm_probe_devices - Call probe on all MII devices, currently used for


wrong name "mii_dm_probe_devices". MII devices -> MDIO devices?


+ * MDIO console commands.
+ */
+void dm_mdio_probe_devices(void);
+
+/**
+ * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
+ *
+ * @dev: mdio dev
+ * @addr: PHY address on MDIO bus
+ * @ethdev: ethernet device to connect to the PHY
+ * @interface: MAC-PHY protocol
+ *
+ * @return pointer to phy_device, or 0 on error
+ */
+struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr,
+  struct udevice *ethdev,
+  phy_interface_t interface);
+
+#endif
+
  #endif
diff --git a/net/Makefile b/net/Makefile
index ce36362168..6251ff3991 100644
--- a/net/Makefile
+++ 

Re: [U-Boot] [PATCH] net: introduce MDIO DM class for MDIO devices

2019-06-01 Thread Bin Meng
Hi Alex,

On Sat, Jun 1, 2019 at 12:27 AM Alex Marginean  wrote:
>
> Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> stand-alone devices.  Useful in particular for systems that support
> DM_ETH and have a stand-alone MDIO hardware block shared by multiple
> Ethernet interfaces.
>

Please add a test case for testing mdio (see test/dm/*)

> Signed-off-by: Alex Marginean 
> ---
>  cmd/mdio.c |   5 ++
>  drivers/net/Kconfig|  13 +
>  include/dm/uclass-id.h |   1 +
>  include/miiphy.h   |  50 
>  net/Makefile   |   1 +
>  net/mdio-uclass.c  | 105 +
>  6 files changed, 175 insertions(+)
>  create mode 100644 net/mdio-uclass.c
>
> diff --git a/cmd/mdio.c b/cmd/mdio.c
> index 5e219f699d..a6fa9266d0 100644
> --- a/cmd/mdio.c
> +++ b/cmd/mdio.c
> @@ -203,6 +203,11 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, 
> char * const argv[])
> if (argc < 2)
> return CMD_RET_USAGE;
>
> +#ifdef CONFIG_DM_MDIO
> +   /* probe DM MII device before any operation so they are all accesible 
> */
> +   dm_mdio_probe_devices();
> +#endif
> +
> /*
>  * We use the last specified parameters, unless new ones are
>  * entered.
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index e6a4fdf30e..6fba5a84dd 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -11,6 +11,19 @@ config DM_ETH
>   This is currently implemented in net/eth-uclass.c
>   Look in include/net.h for details.
>
> +config DM_MDIO
> +   bool "Enable Driver Model for MDIO devices"
> +   depends on DM_ETH && PHYLIB
> +   help
> + Enable driver model for MDIO devices
> +
> + Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> + stand-alone devices.  Useful in particular for systems that support
> + DM_ETH and have a stand-alone MDIO hardware block shared by multiple
> + Ethernet interfaces.
> + This is currently implemented in net/mdio-uclass.c
> + Look in include/miiphy.h for details.
> +
>  menuconfig NETDEVICES
> bool "Network device support"
> depends on NET
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index 09e0ad5391..90667e62cf 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -58,6 +58,7 @@ enum uclass_id {
> UCLASS_LPC, /* x86 'low pin count' interface */
> UCLASS_MAILBOX, /* Mailbox controller */
> UCLASS_MASS_STORAGE,/* Mass storage device */
> +   UCLASS_MDIO,/* MDIO bus */
> UCLASS_MISC,/* Miscellaneous device */
> UCLASS_MMC, /* SD / MMC card or chip */
> UCLASS_MOD_EXP, /* RSA Mod Exp device */
> diff --git a/include/miiphy.h b/include/miiphy.h
> index f11763affd..455feacd33 100644
> --- a/include/miiphy.h
> +++ b/include/miiphy.h
> @@ -118,4 +118,54 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, 
> int devad, int reg,
>  #define ESTATUS_1000XF 0x8000
>  #define ESTATUS_1000XH 0x4000
>
> +#ifdef CONFIG_DM_MDIO
> +
> +/**
> + * struct mii_pdata - Platform data for MDIO buses

wrong name: mii_pdata

> + *
> + * @mii_bus: Supporting MII legacy bus
> + * @priv_pdata: device specific platdata

there is no such field called priv_pdata.

> + */
> +struct mdio_perdev_priv {
> +   struct mii_dev *mii_bus;
> +};
> +
> +/**
> + * struct mii_ops - MDIO bus operations

struct mdio_ops

> + *
> + * @read: Read from a PHY register
> + * @write: Write to a PHY register
> + * @reset: Reset the MDIO bus, NULL if not supported
> + */
> +struct mdio_ops {
> +   int (*read)(struct udevice *mdio_dev, int addr, int devad, int reg);
> +   int (*write)(struct udevice *mdio_dev, int addr, int devad, int reg,
> +u16 val);
> +   int (*reset)(struct udevice *mdio_dev);
> +};
> +
> +#define mdio_get_ops(dev) ((struct mdio_ops *)(dev)->driver->ops)
> +
> +/**
> + * mii_dm_probe_devices - Call probe on all MII devices, currently used for

wrong name "mii_dm_probe_devices". MII devices -> MDIO devices?

> + * MDIO console commands.
> + */
> +void dm_mdio_probe_devices(void);
> +
> +/**
> + * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
> + *
> + * @dev: mdio dev
> + * @addr: PHY address on MDIO bus
> + * @ethdev: ethernet device to connect to the PHY
> + * @interface: MAC-PHY protocol
> + *
> + * @return pointer to phy_device, or 0 on error
> + */
> +struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr,
> +  struct udevice *ethdev,
> +  phy_interface_t interface);
> +
> +#endif
> +
>  #endif
> diff --git a/net/Makefile b/net/Makefile
> index ce36362168..6251ff3991 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -15,6 +15,7 @@ obj-$(CONFIG_NET)  

Re: [U-Boot] [PATCH] net: introduce MDIO DM class for MDIO devices

2019-06-01 Thread Joe Hershberger
On Fri, May 31, 2019 at 11:27 AM Alex Marginean  wrote:
>
> Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> stand-alone devices.  Useful in particular for systems that support
> DM_ETH and have a stand-alone MDIO hardware block shared by multiple
> Ethernet interfaces.
>
> Signed-off-by: Alex Marginean 

Looks good!

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot