Skip to contentSkip to conversation

Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree binding documentation

RFC PATCH Superseded Kedareswara rao Appana 3 participants 6 messages Aug 4, 2016 – Aug 5, 2016

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v3 1/2 Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree binding documentation

Device-tree binding documentation for xilinx gmiitorgmii converter.

---
Changes for v3:
--> None.
Changes for v2:
--> New patch.

 .../devicetree/bindings/net/xilinx_gmii2rgmii.txt  | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +32 -0
new file mode 100644
index 0000000..79fa504
@@ -0,0 +1,32 @@
+XILINX GMIITORGMII Converter Driver Device Tree Bindings
+--------------------------------------------------------
+
+The Gigabit Media Independent Interface (GMII) to Reduced Gigabit Media
+Independent Interface (RGMII) core provides the RGMII between RGMII-compliant
+Ethernet physical media devices (PHY) and the Gigabit Ethernet controller.
+This core can be used in all three modes of operation(10/100/1000 Mb/s).
+The Management Data Input/Output (MDIO) interface is used to configure the
+Speed of operation. This core can switch dynamically between the three
+Different speed modes by configuring the conveter register through mdio write.
+
+The MDIO is a bus to which the PHY devices are connected.  For each
+device that exists on this bus, a child node should be created.  See
+the definition of the PHY node in booting-without-of.txt for an example
+of how to define a PHY.
+
+Required properties:
+  - compatible : Should be "xilinx,gmiitorgmii"
+  - reg : The ID number for the phy, usually a small integer
+
+Example:
+	mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+		ethernet-phy at 0 {
+			......
+		};
+                gmii_to_rgmii: gmii_to_rgmii at 8 {
+                        compatible = "xilinx,gmiitorgmii";
+                        reg = <8>;
+                };
+        };
Signature · 1 line
2.1.2
#1 lore raw

RFC PATCH v3 2/2 net: phy: Add gmiitorgmii converter support

This patch adds support for gmiitorgmii converter.

The GMII to RGMII IP core provides the Reduced Gigabit Media Independent Interface (RGMII) between Ethernet physical media Devices and the Gigabit Ethernet controller. This core can Switch dynamically between the three different speed modes of Operation by configuring the converter register through mdio write.

MDIO interface is used to set operating speed of Ethernet MAC.

---
Thanks a lot Andrew for your inputs.
Changes for v3:
--> Updated the driver as suggested by Andrew. Changes for v2:
--> Passed struct xphy pointer directly to the fix_mac_speed API as suggested by the Florian.
--> Added checks for the phy-node fail case as suggested by the Florian

 drivers/net/phy/Kconfig             |   8 +++
 drivers/net/phy/Makefile            |   1 +
 drivers/net/phy/xilinx_gmii2rgmii.c | 121 ++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/net/phy/xilinx_gmii2rgmii.c
drivers/net/phy/Kconfig +8 -0
index 6dad9a9..eec31a3 100644
@@ -271,6 +271,14 @@ config MDIO_BCM_IPROC
 	  This module provides a driver for the MDIO busses found in the
 	  Broadcom iProc SoC's.
 
+config XILINX_GMII2RGMII
+       tristate "Xilinx GMII2RGMII converter driver"
+       default y
+       ---help---
+         This driver support xilinx GMII to RGMII IP core it provides
+         the Reduced Gigabit Media Independent Interface(RGMII) between
+         Ethernet physical media devices and the Gigabit Ethernet controller.
+
 endif # PHYLIB
 
 config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
index fcdbb92..8650067 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_MDIO_MOXART)	+= mdio-moxart.o
 obj-$(CONFIG_MDIO_BCM_UNIMAC)	+= mdio-bcm-unimac.o
 obj-$(CONFIG_MICROCHIP_PHY)	+= microchip.o
 obj-$(CONFIG_MDIO_BCM_IPROC)	+= mdio-bcm-iproc.o
+obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o
drivers/net/phy/xilinx_gmii2rgmii.c new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.1.2
#2 lore raw

Re: [RFC PATCH v3 2/2] net: phy: Add gmiitorgmii converter support

+ switch (phydev->speed) {
+ case SPEED_1000:
+ val |= BMCR_SPEED1000;
+ case SPEED_100:
+ val |= BMCR_SPEED100;
+ }

Are there only 2 kinds of speed?

Quoted 185 lines · Kedareswara rao Appana

This patch adds support for gmiitorgmii converter.

The GMII to RGMII IP core provides the Reduced Gigabit Media Independent Interface (RGMII) between Ethernet physical media Devices and the Gigabit Ethernet controller. This core can Switch dynamically between the three different speed modes of Operation by configuring the converter register through mdio write.

MDIO interface is used to set operating speed of Ethernet MAC.

---
Thanks a lot Andrew for your inputs.
Changes for v3:
--> Updated the driver as suggested by Andrew. Changes for v2:
--> Passed struct xphy pointer directly to the fix_mac_speed API as suggested by the Florian.
--> Added checks for the phy-node fail case as suggested by the Florian

 drivers/net/phy/Kconfig             |   8 +++
 drivers/net/phy/Makefile            |   1 +
 drivers/net/phy/xilinx_gmii2rgmii.c | 121 ++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/net/phy/xilinx_gmii2rgmii.c
drivers/net/phy/Kconfig +8 -0
index 6dad9a9..eec31a3 100644
@@ -271,6 +271,14 @@ config MDIO_BCM_IPROC
          This module provides a driver for the MDIO busses found in the
          Broadcom iProc SoC's.
 
+config XILINX_GMII2RGMII
+       tristate "Xilinx GMII2RGMII converter driver"
+       default y
+       ---help---
+         This driver support xilinx GMII to RGMII IP core it provides
+         the Reduced Gigabit Media Independent Interface(RGMII) between
+         Ethernet physical media devices and the Gigabit Ethernet controller.
+
 endif # PHYLIB
 
 config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
index fcdbb92..8650067 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_MDIO_MOXART)     += mdio-moxart.o
 obj-$(CONFIG_MDIO_BCM_UNIMAC)  += mdio-bcm-unimac.o
 obj-$(CONFIG_MICROCHIP_PHY)    += microchip.o
 obj-$(CONFIG_MDIO_BCM_IPROC)   += mdio-bcm-iproc.o
+obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o
drivers/net/phy/xilinx_gmii2rgmii.c new file +121 -1
new file mode 100644
index 0000000..56a655a9
@@ -0,0 +1,121 @@
+/* Xilinx GMII2RGMII Converter driver
+ *
+ * Copyright (C) 2016 Xilinx, Inc.
+ *
+ * Author: Kedareswara rao Appana <[email protected]>
+ *
+ * Description:
+ * This driver is developed for Xilinx GMII2RGMII Converter
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/mii.h>
+#include <linux/mdio.h>
+#include <linux/phy.h>
+#include <linux/of_mdio.h>
+
+#define XILINX_GMII2RGMII_REG  0x10
+
+struct gmii2rgmii {
+       struct phy_device *phy_dev;
+       struct phy_driver *phy_drv;
+       struct phy_driver conv_phy_drv;
+       int addr;
+};
+
+static int xgmiitorgmii_read_status(struct phy_device *phydev)
+{
+       struct gmii2rgmii *priv = (struct gmii2rgmii *)phydev->priv;
+       u16 val = 0;
+
+       priv->phy_drv->read_status(phydev);
+
+       val = mdiobus_read(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG);
+
+       switch (phydev->speed) {
+       case SPEED_1000:
+               val |= BMCR_SPEED1000;
+       case SPEED_100:
+               val |= BMCR_SPEED100;
+       }
+
+       mdiobus_write(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG, val);
+
+       return 0;
+}
+
+int xgmiitorgmii_probe(struct mdio_device *mdiodev)
+{
+       struct device *dev = &mdiodev->dev;
+       struct device_node *np = dev->of_node, *phy_node;
+       struct gmii2rgmii *priv;
+       int ret;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       phy_node = of_parse_phandle(np, "phy-handle", 0);
+       if (IS_ERR(phy_node)) {
+               dev_err(dev, "Couldn't parse phy-handle\n");
+               ret = -ENODEV;
+               goto out;
+       }
+
+       priv->phy_dev = of_phy_find_device(phy_node);
+       if (!priv->phy_dev) {
+               ret = -EPROBE_DEFER;
+               dev_info(dev, "Couldn't find phydev\n");
+               goto out;
+       }
+
+       priv->addr = mdiodev->addr;
+       priv->phy_drv = priv->phy_dev->drv;
+       memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
+              sizeof(struct phy_driver));
+       priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
+       priv->phy_dev->priv = priv;
+       priv->phy_dev->drv = &priv->conv_phy_drv;
+
+       return 0;
+out:
+       return ret;
+}
+
+static const struct of_device_id xgmiitorgmii_of_match[] = {
+       { .compatible = "xilinx,gmiitorgmii" },
+};
+MODULE_DEVICE_TABLE(of, xgmiitorgmii_of_match);
+
+static struct mdio_driver xgmiitorgmii_driver = {
+       .probe  = xgmiitorgmii_probe,
+       .mdiodrv.driver = {
+               .name = "xgmiitorgmii",
+               .of_match_table = xgmiitorgmii_of_match,
+       },
+};
+
+static int __init xgmiitorgmii_init(void)
+{
+       return mdio_driver_register(&xgmiitorgmii_driver);
+}
+module_init(xgmiitorgmii_init);
+
+static void __exit xgmiitorgmii_cleanup(void)
+{
+       mdio_driver_unregister(&xgmiitorgmii_driver);
+}
+module_exit(xgmiitorgmii_cleanup);
+
+MODULE_DESCRIPTION("Xilinx GMII2RGMII converter driver");
+MODULE_LICENSE("GPL");
--

2.1.2

#3 lore raw

RE: [RFC PATCH v3 2/2] net: phy: Add gmiitorgmii converter support

Hi zhuyj,

Thanks for the review...

Quoted 9 lines
drivers/net/phy/xilinx_gmii2rgmii.c new file +6 -0
+       switch (phydev->speed) {
+       case SPEED_1000:
+               val |= BMCR_SPEED1000;
+       case SPEED_100:
+               val |= BMCR_SPEED100;
+       }

Are there only 2 kinds of speed?

Converter supports 3 different speeds will fix in the next version...

Thanks,
Kedar.

Quoted 190 lines
Quoted 186 lines · Kedareswara rao Appana

This patch adds support for gmiitorgmii converter.

The GMII to RGMII IP core provides the Reduced Gigabit Media Independent Interface (RGMII) between Ethernet physical media Devices and the Gigabit Ethernet controller. This core can Switch dynamically between the three different speed modes of Operation by configuring the converter register through mdio write.

MDIO interface is used to set operating speed of Ethernet MAC.

---
Thanks a lot Andrew for your inputs.
Changes for v3:
--> Updated the driver as suggested by Andrew. Changes for v2:
--> Passed struct xphy pointer directly to the fix_mac_speed API as suggested by the Florian.
--> Added checks for the phy-node fail case as suggested by the Florian

 drivers/net/phy/Kconfig             |   8 +++
 drivers/net/phy/Makefile            |   1 +
 drivers/net/phy/xilinx_gmii2rgmii.c | 121
++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/net/phy/xilinx_gmii2rgmii.c
drivers/net/phy/Kconfig index renamed from drivers/net/phy/Kconfig +0 -0

6dad9a9..eec31a3 100644

drivers/net/phy/Kconfig +8 -0
@@ -271,6 +271,14 @@ config MDIO_BCM_IPROC
          This module provides a driver for the MDIO busses found in the
          Broadcom iProc SoC's.
 
+config XILINX_GMII2RGMII
+       tristate "Xilinx GMII2RGMII converter driver"
+       default y
+       ---help---
+         This driver support xilinx GMII to RGMII IP core it provides
+         the Reduced Gigabit Media Independent Interface(RGMII) between
+         Ethernet physical media devices and the Gigabit Ethernet controller.
+
 endif # PHYLIB
 
 config MICREL_KS8995MA
drivers/net/phy/Makefile index renamed from drivers/net/phy/Makefile +0 -0

fcdbb92..8650067 100644

drivers/net/phy/Makefile +1 -0
@@ -44,3 +44,4 @@ obj-$(CONFIG_MDIO_MOXART)     += mdio-moxart.o
 obj-$(CONFIG_MDIO_BCM_UNIMAC)  += mdio-bcm-unimac.o
 obj-$(CONFIG_MICROCHIP_PHY)    += microchip.o
 obj-$(CONFIG_MDIO_BCM_IPROC)   += mdio-bcm-iproc.o
+obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o
drivers/net/phy/xilinx_gmii2rgmii.c new file +120 -1
new file mode 100644
index 0000000..56a655a9
@@ -0,0 +1,121 @@
+/* Xilinx GMII2RGMII Converter driver
+ *
+ * Copyright (C) 2016 Xilinx, Inc.
+ *
+ * Author: Kedareswara rao Appana <[email protected]>
+ *
+ * Description:
+ * This driver is developed for Xilinx GMII2RGMII Converter
+ *
+ * This program is free software: you can redistribute it and/or
+modify
+ * it under the terms of the GNU General Public License as published
+by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/mii.h>
+#include <linux/mdio.h>
+#include <linux/phy.h>
+#include <linux/of_mdio.h>
+
+#define XILINX_GMII2RGMII_REG  0x10
+
+struct gmii2rgmii {
+       struct phy_device *phy_dev;
+       struct phy_driver *phy_drv;
+       struct phy_driver conv_phy_drv;
+       int addr;
+};
+
+static int xgmiitorgmii_read_status(struct phy_device *phydev) {
+       struct gmii2rgmii *priv = (struct gmii2rgmii *)phydev->priv;
+       u16 val = 0;
+
+       priv->phy_drv->read_status(phydev);
+
+       val = mdiobus_read(phydev->mdio.bus, priv->addr,
+ XILINX_GMII2RGMII_REG);
+
+       switch (phydev->speed) {
+       case SPEED_1000:
+               val |= BMCR_SPEED1000;
+       case SPEED_100:
+               val |= BMCR_SPEED100;
+       }
+
+       mdiobus_write(phydev->mdio.bus, priv->addr,
+ XILINX_GMII2RGMII_REG, val);
+
+       return 0;
+}
+
+int xgmiitorgmii_probe(struct mdio_device *mdiodev) {
+       struct device *dev = &mdiodev->dev;
+       struct device_node *np = dev->of_node, *phy_node;
+       struct gmii2rgmii *priv;
+       int ret;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       phy_node = of_parse_phandle(np, "phy-handle", 0);
+       if (IS_ERR(phy_node)) {
+               dev_err(dev, "Couldn't parse phy-handle\n");
+               ret = -ENODEV;
+               goto out;
+       }
+
+       priv->phy_dev = of_phy_find_device(phy_node);
+       if (!priv->phy_dev) {
+               ret = -EPROBE_DEFER;
+               dev_info(dev, "Couldn't find phydev\n");
+               goto out;
+       }
+
+       priv->addr = mdiodev->addr;
+       priv->phy_drv = priv->phy_dev->drv;
+       memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
+              sizeof(struct phy_driver));
+       priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
+       priv->phy_dev->priv = priv;
+       priv->phy_dev->drv = &priv->conv_phy_drv;
+
+       return 0;
+out:
+       return ret;
+}
+
+static const struct of_device_id xgmiitorgmii_of_match[] = {
+       { .compatible = "xilinx,gmiitorgmii" }, };
+MODULE_DEVICE_TABLE(of, xgmiitorgmii_of_match);
+
+static struct mdio_driver xgmiitorgmii_driver = {
+       .probe  = xgmiitorgmii_probe,
+       .mdiodrv.driver = {
+               .name = "xgmiitorgmii",
+               .of_match_table = xgmiitorgmii_of_match,
+       },
+};
+
+static int __init xgmiitorgmii_init(void) {
+       return mdio_driver_register(&xgmiitorgmii_driver);
+}
+module_init(xgmiitorgmii_init);
+
+static void __exit xgmiitorgmii_cleanup(void) {
+       mdio_driver_unregister(&xgmiitorgmii_driver);
+}
+module_exit(xgmiitorgmii_cleanup);
+
+MODULE_DESCRIPTION("Xilinx GMII2RGMII converter driver");
+MODULE_LICENSE("GPL");
--

2.1.2

maintainer
#4 lore raw
In reply to Kedareswara rao Appana
Quoted 27 lines · Kedareswara rao Appana

Device-tree binding documentation for xilinx gmiitorgmii converter.

---
Changes for v3:
--> None.
Changes for v2:
--> New patch.

 .../devicetree/bindings/net/xilinx_gmii2rgmii.txt  | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +8 -0
new file mode 100644
index 0000000..79fa504
@@ -0,0 +1,32 @@
+XILINX GMIITORGMII Converter Driver Device Tree Bindings
+--------------------------------------------------------
+
+The Gigabit Media Independent Interface (GMII) to Reduced Gigabit Media
+Independent Interface (RGMII) core provides the RGMII between RGMII-compliant
+Ethernet physical media devices (PHY) and the Gigabit Ethernet controller.
+This core can be used in all three modes of operation(10/100/1000 Mb/s).
+The Management Data Input/Output (MDIO) interface is used to configure the

Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +10 -0
+Speed of operation. This core can switch dynamically between the three
+Different speed modes by configuring the conveter register through mdio write.
+
+The MDIO is a bus to which the PHY devices are connected.  For each
+device that exists on this bus, a child node should be created.  See
+the definition of the PHY node in booting-without-of.txt for an example
+of how to define a PHY.
+
+Required properties:
+  - compatible : Should be "xilinx,gmiitorgmii"

Perhaps xilinx,gmii-to-rgmii.

This needs some sort of version information in the compatible string.

Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt line 28

Quoted 10 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +10 -0
+  - reg : The ID number for the phy, usually a small integer
+
+Example:
+	mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+		ethernet-phy at 0 {
+			......
+		};
+                gmii_to_rgmii: gmii_to_rgmii at 8 {

Don't use underscores in node names.

Quoted 7 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +4 -0
+                        compatible = "xilinx,gmiitorgmii";
+                        reg = <8>;
+                };
+        };
Signature · 1 line
2.1.2
#5 lore raw

Hi Rob,

Thanks for the review...

<Snip>

Quoted 12 lines

Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt

Quoted 6 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +6 -0
+XILINX GMIITORGMII Converter Driver Device Tree Bindings
+--------------------------------------------------------
+
+The Gigabit Media Independent Interface (GMII) to Reduced Gigabit
+Media Independent Interface (RGMII) core provides the RGMII between
+RGMII-compliant Ethernet physical media devices (PHY) and the Gigabit

Ethernet controller.

Review

Quoted 4 lines
(quoted diff) +4 -0
+This core can be used in all three modes of operation(10/100/1000 Mb/s).
+The Management Data Input/Output (MDIO) interface is used to
+configure the Speed of operation. This core can switch dynamically
+between the three Different speed modes by configuring the conveter

register through mdio write.

Quoted 10 lines

Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt line 18

Quoted 8 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +8 -0
+
+The MDIO is a bus to which the PHY devices are connected.  For each
+device that exists on this bus, a child node should be created.  See
+the definition of the PHY node in booting-without-of.txt for an
+example of how to define a PHY.
+
+Required properties:
+  - compatible : Should be "xilinx,gmiitorgmii"

Perhaps xilinx,gmii-to-rgmii.

Sure...

Quoted 2 lines

This needs some sort of version information in the compatible string.

Sure will fix in the next version...

Quoted 13 lines

Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt line 28

Quoted 11 lines
Documentation/devicetree/bindings/net/xilinx_gmii2rgmii.txt new file +10 -0
+  - reg : The ID number for the phy, usually a small integer
+
+Example:
+	mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+		ethernet-phy at 0 {
+			......
+		};
+                gmii_to_rgmii: gmii_to_rgmii at 8 {

Don't use underscores in node names.

Ok will fix in the next version...

Regards,
Kedar.