Re: [U-Boot] [PATCH v2 36/45] net: mvpp2: Restructure probe / init functions

2017-03-25 Thread Joe Hershberger
On Thu, Mar 23, 2017 at 12:02 PM, Stefan Roese  wrote:
> This patch does a bit of restructuring of the probe / init functions,
> mainly to allow earlier register access as it is needed for the upcoming
> GoP (Group of Ports) and NetC (Net Complex) code.
>
> Signed-off-by: Stefan Roese 
> Cc: Joe Hershberger 

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


[U-Boot] [PATCH v2 36/45] net: mvpp2: Restructure probe / init functions

2017-03-23 Thread Stefan Roese
This patch does a bit of restructuring of the probe / init functions,
mainly to allow earlier register access as it is needed for the upcoming
GoP (Group of Ports) and NetC (Net Complex) code.

Signed-off-by: Stefan Roese 
Cc: Joe Hershberger 

---

Changes in v2:
- New patch

 drivers/net/mvpp2.c | 76 -
 1 file changed, 46 insertions(+), 30 deletions(-)

diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 4863336985..ecefa21097 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -3830,19 +3830,14 @@ static int mvpp2_port_init(struct udevice *dev, struct 
mvpp2_port *port)
return 0;
 }
 
-/* Ports initialization */
-static int mvpp2_port_probe(struct udevice *dev,
-   struct mvpp2_port *port,
-   int port_node,
-   struct mvpp2 *priv)
+static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
 {
+   int port_node = dev_of_offset(dev);
+   const char *phy_mode_str;
int phy_node;
u32 id;
u32 phyaddr;
-   const char *phy_mode_str;
int phy_mode = -1;
-   int priv_common_regs_num = 2;
-   int err;
 
phy_node = fdtdec_lookup_phandle(gd->fdt_blob, port_node, "phy");
if (phy_node < 0) {
@@ -3866,46 +3861,37 @@ static int mvpp2_port_probe(struct udevice *dev,
 
phyaddr = fdtdec_get_int(gd->fdt_blob, phy_node, "reg", 0);
 
-   port->priv = priv;
port->id = id;
-   if (priv->hw_version == MVPP21)
+   if (port->priv->hw_version == MVPP21)
port->first_rxq = port->id * rxq_number;
else
-   port->first_rxq = port->id * priv->max_port_rxqs;
+   port->first_rxq = port->id * port->priv->max_port_rxqs;
port->phy_node = phy_node;
port->phy_interface = phy_mode;
port->phyaddr = phyaddr;
 
-   if (priv->hw_version == MVPP21) {
-   port->base = (void __iomem *)dev_get_addr_index(
-   dev->parent, priv_common_regs_num + id);
-   if (IS_ERR(port->base))
-   return PTR_ERR(port->base);
-   } else {
-   u32 gop_id;
-
-   gop_id = fdtdec_get_int(gd->fdt_blob, port_node,
-   "gop-port-id", -1);
-   if (id == -1) {
-   dev_err(>dev, "missing gop-port-id value\n");
-   return -EINVAL;
-   }
+   return 0;
+}
 
-   port->base = priv->iface_base + MVPP22_PORT_BASE +
-   gop_id * MVPP22_PORT_OFFSET;
-   }
+/* Ports initialization */
+static int mvpp2_port_probe(struct udevice *dev,
+   struct mvpp2_port *port,
+   int port_node,
+   struct mvpp2 *priv)
+{
+   int err;
 
port->tx_ring_size = MVPP2_MAX_TXD;
port->rx_ring_size = MVPP2_MAX_RXD;
 
err = mvpp2_port_init(dev, port);
if (err < 0) {
-   dev_err(>dev, "failed to init port %d\n", id);
+   dev_err(>dev, "failed to init port %d\n", port->id);
return err;
}
mvpp2_port_power_up(port);
 
-   priv->port_list[id] = port;
+   priv->port_list[port->id] = port;
return 0;
 }
 
@@ -4553,6 +4539,36 @@ static int mvpp2_probe(struct udevice *dev)
err = mvpp2_base_probe(dev->parent);
priv->probe_done = 1;
}
+
+   port->priv = dev_get_priv(dev->parent);
+
+   err = phy_info_parse(dev, port);
+   if (err)
+   return err;
+
+   /*
+* We need the port specific io base addresses at this stage, since
+* gop_port_init() accesses these registers
+*/
+   if (priv->hw_version == MVPP21) {
+   int priv_common_regs_num = 2;
+
+   port->base = (void __iomem *)dev_get_addr_index(
+   dev->parent, priv_common_regs_num + port->id);
+   if (IS_ERR(port->base))
+   return PTR_ERR(port->base);
+   } else {
+   port->gop_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
+ "gop-port-id", -1);
+   if (port->id == -1) {
+   dev_err(>dev, "missing gop-port-id value\n");
+   return -EINVAL;
+   }
+
+   port->base = priv->iface_base + MVPP22_PORT_BASE +
+   port->gop_id * MVPP22_PORT_OFFSET;
+   }
+
/* Initialize network controller */
err = mvpp2_init(dev, priv);
if (err < 0) {
-- 
2.12.1

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