]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: ti: cpsw: move parsing of dt port's parameters in separate func
authorGrygorii Strashko <grygorii.strashko@ti.com>
Thu, 19 Sep 2019 08:16:38 +0000 (11:16 +0300)
committerTom Rini <trini@konsulko.com>
Sun, 3 Nov 2019 14:36:06 +0000 (09:36 -0500)
Move parsing of dt port's parameters in separate func for better code
readability.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
drivers/net/ti/cpsw.c

index f0d008f0f56df3b433daf88c103d9032a49e6a64..533c1679950c694e458f861d9ccf2fbdc2363a09 100644 (file)
@@ -1179,12 +1179,40 @@ static int cpsw_eth_probe(struct udevice *dev)
 }
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data,
+                                   int slave_index, int subnode)
+{
+       struct cpsw_slave_data  *slave_data;
+       const void *fdt = gd->fdt_blob;
+       const char *phy_mode;
+       u32 phy_id[2];
+
+       slave_data = &data->slave_data[slave_index];
+
+       phy_mode = fdt_getprop(fdt, subnode, "phy-mode", NULL);
+       if (phy_mode)
+               slave_data->phy_if =
+                       phy_get_interface_by_name(phy_mode);
+
+       slave_data->phy_of_handle = fdtdec_lookup_phandle(fdt, subnode,
+                                                         "phy-handle");
+
+       if (data->slave_data[slave_index].phy_of_handle >= 0) {
+               slave_data->phy_addr =
+                       fdtdec_get_int(fdt, slave_data->phy_of_handle,
+                                      "reg", -1);
+       } else {
+               fdtdec_get_int_array(fdt, subnode, "phy_id",
+                                    phy_id, 2);
+               slave_data->phy_addr = phy_id[1];
+       }
+}
+
 static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_platdata(dev);
        struct cpsw_platform_data *data;
        struct gpio_desc *mode_gpios;
-       const char *phy_mode;
        const void *fdt = gd->fdt_blob;
        int node = dev_of_offset(dev);
        int subnode;
@@ -1267,30 +1295,10 @@ static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
                }
 
                if (!strncmp(name, "slave", 5)) {
-                       u32 phy_id[2];
-
                        if (slave_index >= data->slaves)
                                continue;
-                       phy_mode = fdt_getprop(fdt, subnode, "phy-mode", NULL);
-                       if (phy_mode)
-                               data->slave_data[slave_index].phy_if =
-                                       phy_get_interface_by_name(phy_mode);
-
-                       data->slave_data[slave_index].phy_of_handle =
-                               fdtdec_lookup_phandle(fdt, subnode,
-                                                     "phy-handle");
-
-                       if (data->slave_data[slave_index].phy_of_handle >= 0) {
-                               data->slave_data[slave_index].phy_addr =
-                                               fdtdec_get_int(gd->fdt_blob,
-                                               data->slave_data[slave_index].phy_of_handle,
-                                                              "reg", -1);
-                       } else {
-                               fdtdec_get_int_array(fdt, subnode, "phy_id",
-                                                    phy_id, 2);
-                               data->slave_data[slave_index].phy_addr =
-                                               phy_id[1];
-                       }
+
+                       cpsw_eth_of_parse_slave(data, slave_index, subnode);
                        slave_index++;
                }
 
@@ -1331,7 +1339,8 @@ static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
 
        pdata->phy_interface = data->slave_data[active_slave].phy_if;
        if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+               debug("%s: Invalid PHY interface '%s'\n", __func__,
+                     phy_string_for_interface(pdata->phy_interface));
                return -EINVAL;
        }