Message ID | 20221109042203.375042-4-s-vadapalli@ti.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add support for QSGMII mode for J721e CPSW9G to am65-cpsw driver | expand |
hello, On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote: [...] > +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common) > +{ > + struct device_node *node, *port_np; > + struct device *dev = common->dev; > + const char *name = "serdes-phy"; > + struct phy *phy; > + > + node = of_get_child_by_name(dev->of_node, "ethernet-ports"); > + > + for_each_child_of_node(node, port_np) { > + phy = devm_of_phy_get(dev, port_np, name); The above will try to allocate some memory and can fail. Even if the the following code will handle a NULL ptr, the phy will not be disabled. I think it's better if you cache the serdes phy ptr in am65_cpsw_init_serdes_phy() and you use such reference here, without resorting to devm_of_phy_get(). Cheers, Paolo
Hello Paolo, On 10/11/22 18:36, Paolo Abeni wrote: > hello, > > On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote: > [...] > >> +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common) >> +{ >> + struct device_node *node, *port_np; >> + struct device *dev = common->dev; >> + const char *name = "serdes-phy"; >> + struct phy *phy; >> + >> + node = of_get_child_by_name(dev->of_node, "ethernet-ports"); >> + >> + for_each_child_of_node(node, port_np) { >> + phy = devm_of_phy_get(dev, port_np, name); > > The above will try to allocate some memory and can fail. Even if the > the following code will handle a NULL ptr, the phy will not be > disabled. > > I think it's better if you cache the serdes phy ptr in > am65_cpsw_init_serdes_phy() and you use such reference here, without > resorting to devm_of_phy_get(). Thank you for reviewing the patch. I plan on creating a new "struct phy*" member named "serdes_phy" in the struct "am65_cpsw_slave_data" defined in the file "am65-cpsw-nuss.h", and store the SerDes phy in this member, during the execution of the am65_cpsw_init_serdes_phy() function. Please let me know if I can proceed with this implementation. Regards, Siddharth.
diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index bc9f29d10c22..83349d24a0e6 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -1444,6 +1444,65 @@ static const struct net_device_ops am65_cpsw_nuss_netdev_ops = { .ndo_setup_tc = am65_cpsw_qos_ndo_setup_tc, }; +static void am65_cpsw_disable_phy(struct phy *phy) +{ + phy_power_off(phy); + phy_exit(phy); +} + +static int am65_cpsw_enable_phy(struct phy *phy) +{ + int ret; + + ret = phy_init(phy); + if (ret < 0) + return ret; + + ret = phy_power_on(phy); + if (ret < 0) { + phy_exit(phy); + return ret; + } + + return 0; +} + +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common) +{ + struct device_node *node, *port_np; + struct device *dev = common->dev; + const char *name = "serdes-phy"; + struct phy *phy; + + node = of_get_child_by_name(dev->of_node, "ethernet-ports"); + + for_each_child_of_node(node, port_np) { + phy = devm_of_phy_get(dev, port_np, name); + am65_cpsw_disable_phy(phy); + } +} + +static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *port_np) +{ + const char *name = "serdes-phy"; + struct phy *phy; + int ret; + + phy = devm_of_phy_get(dev, port_np, name); + if (PTR_ERR(phy) == -ENODEV) + return 0; + + ret = am65_cpsw_enable_phy(phy); + if (ret < 0) + goto err_phy; + + return 0; + +err_phy: + devm_phy_put(dev, phy); + return ret; +} + static void am65_cpsw_nuss_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) { @@ -1941,6 +2000,11 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common) goto of_node_put; } + /* Initialize the phy for the port */ + ret = am65_cpsw_init_serdes_phy(dev, port_np); + if (ret) + return ret; + port->slave.mac_only = of_property_read_bool(port_np, "ti,mac-only"); @@ -2868,6 +2932,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev) am65_cpsw_nuss_phylink_cleanup(common); am65_cpsw_unregister_devlink(common); + am65_cpsw_disable_serdes_phy(common); am65_cpsw_unregister_notifiers(common); /* must unregister ndevs here because DD release_driver routine calls
Use PHY framework APIs to initialize the SERDES PHY connected to CPSW MAC. Define the functions am65_cpsw_disable_phy(), am65_cpsw_enable_phy(), am65_cpsw_disable_serdes_phy() and am65_cpsw_enable_serdes_phy(). Power on and initialize the SerDes PHY in am65_cpsw_nuss_init_slave_ports() by invoking am65_cpsw_enable_serdes_phy(). Power off the SerDes PHY in am65_cpsw_nuss_remove() by invoking am65_cpsw_disable_serdes_phy(). Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com> --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+)