RE: [PATCH 2/4] phy: cadence-torrent: Group reset APIs and clock APIs
> -Original Message- > From: Kishon Vijay Abraham I > Sent: Wednesday, March 10, 2021 9:25 PM > To: Kishon Vijay Abraham I ; Vinod Koul > ; Rob Herring ; Philipp Zabel > ; Swapnil Kashinath Jakhade > > Cc: linux-kernel@vger.kernel.org; devicet...@vger.kernel.org; Lokesh Vutla > ; linux-...@lists.infradead.org > Subject: [PATCH 2/4] phy: cadence-torrent: Group reset APIs and clock APIs > > EXTERNAL MAIL > > > No functional change intended. Group reset APIs and clock APIs in > preparation for adding support to skip configuration if the SERDES > is already configured by bootloader. > > Signed-off-by: Kishon Vijay Abraham I > --- > drivers/phy/cadence/phy-cadence-torrent.c | 84 ++- > 1 file changed, 53 insertions(+), 31 deletions(-) > Reviewed-by: Swapnil Jakhade Thanks & regards, Swapnil > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c > b/drivers/phy/cadence/phy-cadence-torrent.c > index 3fdab0d288c4..ab51c4bf7b30 100644 > --- a/drivers/phy/cadence/phy-cadence-torrent.c > +++ b/drivers/phy/cadence/phy-cadence-torrent.c > @@ -2249,6 +2249,54 @@ static int cdns_torrent_clk_register(struct > cdns_torrent_phy *cdns_phy) > return 0; > } > > +static int cdns_torrent_reset(struct cdns_torrent_phy *cdns_phy) > +{ > + struct device *dev = cdns_phy->dev; > + > + cdns_phy->phy_rst = > devm_reset_control_get_exclusive_by_index(dev, 0); > + if (IS_ERR(cdns_phy->phy_rst)) { > + dev_err(dev, "%s: failed to get reset\n", > + dev->of_node->full_name); > + return PTR_ERR(cdns_phy->phy_rst); > + } > + > + cdns_phy->apb_rst = devm_reset_control_get_optional(dev, > "torrent_apb"); > + if (IS_ERR(cdns_phy->apb_rst)) { > + dev_err(dev, "%s: failed to get apb reset\n", > + dev->of_node->full_name); > + return PTR_ERR(cdns_phy->apb_rst); > + } > + > + return 0; > +} > + > +static int cdns_torrent_clk(struct cdns_torrent_phy *cdns_phy) > +{ > + struct device *dev = cdns_phy->dev; > + int ret; > + > + cdns_phy->clk = devm_clk_get(dev, "refclk"); > + if (IS_ERR(cdns_phy->clk)) { > + dev_err(dev, "phy ref clock not found\n"); > + return PTR_ERR(cdns_phy->clk); > + } > + > + ret = clk_prepare_enable(cdns_phy->clk); > + if (ret) { > + dev_err(cdns_phy->dev, "Failed to prepare ref clock\n"); > + return ret; > + } > + > + cdns_phy->ref_clk_rate = clk_get_rate(cdns_phy->clk); > + if (!(cdns_phy->ref_clk_rate)) { > + dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); > + clk_disable_unprepare(cdns_phy->clk); > + return -EINVAL; > + } > + > + return 0; > +} > + > static int cdns_torrent_phy_probe(struct platform_device *pdev) > { > struct cdns_torrent_phy *cdns_phy; > @@ -2274,26 +2322,6 @@ static int cdns_torrent_phy_probe(struct > platform_device *pdev) > cdns_phy->dev = dev; > cdns_phy->init_data = data; > > - cdns_phy->phy_rst = > devm_reset_control_get_exclusive_by_index(dev, 0); > - if (IS_ERR(cdns_phy->phy_rst)) { > - dev_err(dev, "%s: failed to get reset\n", > - dev->of_node->full_name); > - return PTR_ERR(cdns_phy->phy_rst); > - } > - > - cdns_phy->apb_rst = devm_reset_control_get_optional(dev, > "torrent_apb"); > - if (IS_ERR(cdns_phy->apb_rst)) { > - dev_err(dev, "%s: failed to get apb reset\n", > - dev->of_node->full_name); > - return PTR_ERR(cdns_phy->apb_rst); > - } > - > - cdns_phy->clk = devm_clk_get(dev, "refclk"); > - if (IS_ERR(cdns_phy->clk)) { > - dev_err(dev, "phy ref clock not found\n"); > - return PTR_ERR(cdns_phy->clk); > - } > - > cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(cdns_phy->sd_base)) > return PTR_ERR(cdns_phy->sd_base); > @@ -2316,18 +2344,13 @@ static int cdns_torrent_phy_probe(struct > platform_device *pdev) > if (ret) > return ret; > > - ret = clk_prepare_enable(cdns_phy->clk); > - if (ret) { > - dev_err(cdns_phy->dev, "Failed to prepare ref clock\n"); > + ret = cdns_torrent_reset(cdns_phy); &g
[PATCH 2/4] phy: cadence-torrent: Group reset APIs and clock APIs
No functional change intended. Group reset APIs and clock APIs in preparation for adding support to skip configuration if the SERDES is already configured by bootloader. Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/cadence/phy-cadence-torrent.c | 84 ++- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c index 3fdab0d288c4..ab51c4bf7b30 100644 --- a/drivers/phy/cadence/phy-cadence-torrent.c +++ b/drivers/phy/cadence/phy-cadence-torrent.c @@ -2249,6 +2249,54 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy) return 0; } +static int cdns_torrent_reset(struct cdns_torrent_phy *cdns_phy) +{ + struct device *dev = cdns_phy->dev; + + cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); + if (IS_ERR(cdns_phy->phy_rst)) { + dev_err(dev, "%s: failed to get reset\n", + dev->of_node->full_name); + return PTR_ERR(cdns_phy->phy_rst); + } + + cdns_phy->apb_rst = devm_reset_control_get_optional(dev, "torrent_apb"); + if (IS_ERR(cdns_phy->apb_rst)) { + dev_err(dev, "%s: failed to get apb reset\n", + dev->of_node->full_name); + return PTR_ERR(cdns_phy->apb_rst); + } + + return 0; +} + +static int cdns_torrent_clk(struct cdns_torrent_phy *cdns_phy) +{ + struct device *dev = cdns_phy->dev; + int ret; + + cdns_phy->clk = devm_clk_get(dev, "refclk"); + if (IS_ERR(cdns_phy->clk)) { + dev_err(dev, "phy ref clock not found\n"); + return PTR_ERR(cdns_phy->clk); + } + + ret = clk_prepare_enable(cdns_phy->clk); + if (ret) { + dev_err(cdns_phy->dev, "Failed to prepare ref clock\n"); + return ret; + } + + cdns_phy->ref_clk_rate = clk_get_rate(cdns_phy->clk); + if (!(cdns_phy->ref_clk_rate)) { + dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); + clk_disable_unprepare(cdns_phy->clk); + return -EINVAL; + } + + return 0; +} + static int cdns_torrent_phy_probe(struct platform_device *pdev) { struct cdns_torrent_phy *cdns_phy; @@ -2274,26 +2322,6 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) cdns_phy->dev = dev; cdns_phy->init_data = data; - cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); - if (IS_ERR(cdns_phy->phy_rst)) { - dev_err(dev, "%s: failed to get reset\n", - dev->of_node->full_name); - return PTR_ERR(cdns_phy->phy_rst); - } - - cdns_phy->apb_rst = devm_reset_control_get_optional(dev, "torrent_apb"); - if (IS_ERR(cdns_phy->apb_rst)) { - dev_err(dev, "%s: failed to get apb reset\n", - dev->of_node->full_name); - return PTR_ERR(cdns_phy->apb_rst); - } - - cdns_phy->clk = devm_clk_get(dev, "refclk"); - if (IS_ERR(cdns_phy->clk)) { - dev_err(dev, "phy ref clock not found\n"); - return PTR_ERR(cdns_phy->clk); - } - cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(cdns_phy->sd_base)) return PTR_ERR(cdns_phy->sd_base); @@ -2316,18 +2344,13 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) if (ret) return ret; - ret = clk_prepare_enable(cdns_phy->clk); - if (ret) { - dev_err(cdns_phy->dev, "Failed to prepare ref clock\n"); + ret = cdns_torrent_reset(cdns_phy); + if (ret) goto clk_cleanup; - } - cdns_phy->ref_clk_rate = clk_get_rate(cdns_phy->clk); - if (!(cdns_phy->ref_clk_rate)) { - dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); - ret = -EINVAL; - goto clk_disable; - } + ret = cdns_torrent_clk(cdns_phy); + if (ret) + goto clk_cleanup; /* Enable APB */ reset_control_deassert(cdns_phy->apb_rst); @@ -2505,7 +2528,6 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) reset_control_put(cdns_phy->phys[i].lnk_rst); of_node_put(child); reset_control_assert(cdns_phy->apb_rst); -clk_disable: clk_disable_unprepare(cdns_phy->clk); clk_cleanup: cdns_torrent_clk_cleanup(cdns_phy); -- 2.17.1