PCI: j721e: A couple of cleanups
Subsystems (4)
cover PCI: j721e: A couple of cleanups
Refactor the J721e probe function to use devres helpers for resource management. This replaces manual clock handling with devm_clk_get_optional_enabled() and assigns the reset GPIO directly to the struct members, eliminating unnecessary local variables.
These patches have been compile-tested only, as I do not have access to the hardware for runtime verification.
Thanks
-Anand
Anand Moon (2):
PCI: j721e: Use devm_clk_get_optional_enabled() to get the clock
PCI: j721e: Use inline reset GPIO assignment and drop local variable
drivers/pci/controller/cadence/pci-j721e.c | 25 +++++++--------------- 1 file changed, 8 insertions(+), 17 deletions(-)
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
Signature · 1 line
2.50.1
RFC 1/2 PCI: j721e: Use devm_clk_get_optional_enabled() to get the clock
Use devm_clk_get_optional_enabled() helper instead of calling devm_clk_get_optional() and then clk_prepare_enable(). It simplifies the error handling and makes the code more compact. This changes removes the unnecessary clk variable and assigns the result of the devm_clk_get_optional_enabled() call directly to pcie->refclk. This makes the code more concise and readable without changing the behavior.
--- drivers/pci/controller/cadence/pci-j721e.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/pci/controller/cadence/pci-j721e.c +2 -10
@@ -479,7 +479,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)struct cdns_pcie_ep *ep =NULL ;struct gpio_desc *gpiod;void __iomem *base; -struct clk *clk;u32 num_lanes;u32 mode;int ret;
@@ -603,18 +602,11 @@ static int j721e_pcie_probe(struct platform_device *pdev) goto err_get_sync; } - clk =devm_clk_get_optional (dev,"pcie_refclk" ); -if (IS_ERR (clk)) { - ret =dev_err_probe (dev,PTR_ERR (clk),"failed to get pcie_refclk\n" ); - goto err_pcie_setup; - } - - ret =clk_prepare_enable (clk); -if (ret) { + pcie->refclk =devm_clk_get_optional_enabled (dev,"pcie_refclk" ); +if (IS_ERR (pcie->refclk)) {dev_err_probe (dev, ret,"failed to enable pcie_refclk\n" ); goto err_pcie_setup; } - pcie->refclk = clk;/* * Section 2.2 of the PCI Express Card Electromechanical
Signature · 1 line
2.50.1
RFC 2/2 PCI: j721e: Use inline reset GPIO assignment and drop local variable
In reply to Anand MoonChange removes the unnecessary local gpiod variable and assigns the result of the devm_gpiod_get_optional() call directly to pcie->reset_gpio. This makes the code more concise and readable without changing the behavior.
--- drivers/pci/controller/cadence/pci-j721e.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/pci/controller/cadence/pci-j721e.c +6 -7
@@ -477,7 +477,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)struct j721e_pcie *pcie;struct cdns_pcie_rc *rc =NULL ;struct cdns_pcie_ep *ep =NULL ; -struct gpio_desc *gpiod;void __iomem *base;u32 num_lanes;u32 mode;
@@ -589,12 +588,12 @@ static int j721e_pcie_probe(struct platform_device *pdev)switch (mode) {case PCI_MODE_RC : - gpiod =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); -if (IS_ERR (gpiod)) { - ret =dev_err_probe (dev,PTR_ERR (gpiod),"Failed to get reset GPIO\n" ); + pcie->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (pcie->reset_gpio)) { + ret =dev_err_probe (dev,PTR_ERR (pcie->reset_gpio), +"Failed to get reset GPIO\n" ); goto err_get_sync; } - pcie->reset_gpio = gpiod; ret =cdns_pcie_init_phy (dev, cdns_pcie);if (ret) {
@@ -615,9 +614,9 @@ static int j721e_pcie_probe(struct platform_device *pdev)* This shall ensure that the power and the reference clock * are stable. */ -if (gpiod) { +if (pcie->reset_gpio) {msleep (PCIE_T_PVPERL_MS ); -gpiod_set_value_cansleep (gpiod,1 ); +gpiod_set_value_cansleep (pcie->reset_gpio,1 ); } ret =cdns_pcie_host_setup (rc);
Signature · 1 line
2.50.1
Siddharth Vadapalli
reviewerRe: [RFC v1 1/2] PCI: j721e: Use devm_clk_get_optional_enabled() to get the clock
In reply to Anand MoonQuoted 32 lines · Anand Moon
Use
devm_clk_get_optional_enabled()helper instead of callingdevm_clk_get_optional()and thenclk_prepare_enable(). It simplifies the error handling and makes the code more compact. This changes removes the unnecessary clk variable and assigns the result of thedevm_clk_get_optional_enabled()call directly topcie->refclk. This makes the code more concise and readable without changing the behavior.Cc Siddharth Vadapalli <[email protected]>Signed-off-by Anand Moon <[email protected]>--- drivers/pci/controller/cadence/pci-j721e.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/pci/controller/cadence/pci-j721e.c +0
-3@@ -479,7 +479,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)struct cdns_pcie_ep *ep =NULL ;struct gpio_desc *gpiod;void __iomem *base; -struct clk *clk;u32 num_lanes;u32 mode;int ret;@@ -603,18 +602,11 @@ static int j721e_pcie_probe(struct platform_device *pdev) goto err_get_sync; } - clk =devm_clk_get_optional (dev,"pcie_refclk" ); -if (IS_ERR (clk)) {
drivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_probe(struct platform_device *pdev) · line 608
Quoted 10 lines
drivers/pci/controller/cadence/pci-j721e.c +2
-6- ret =dev_err_probe (dev,PTR_ERR (clk),"failed to get pcie_refclk\n" ); - goto err_pcie_setup; - } - - ret =clk_prepare_enable (clk); -if (ret) { + pcie->refclk =devm_clk_get_optional_enabled (dev,"pcie_refclk" ); +if (IS_ERR (pcie->refclk)) {dev_err_probe (dev, ret,"failed to enable pcie_refclk\n" ); goto err_pcie_setup;
'err_pcie_setup' returns 'ret' which isn't being updated above. Maybe add:
ret = pcie->refclk;
above dev_err_probe(...
drivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_probe(struct platform_device *pdev) · line 612
Quoted 5 lines
drivers/pci/controller/cadence/pci-j721e.c +0
-1} - pcie->refclk = clk;/* * Section 2.2 of the PCI Express Card Electromechanical
Regards,
Siddharth.
Re: [RFC v1 2/2] PCI: j721e: Use inline reset GPIO assignment and drop local variable
In reply to Anand MoonQuoted 7 lines · Anand Moon
Change removes the unnecessary local gpiod variable and assigns the result of the
devm_gpiod_get_optional()call directly topcie->reset_gpio. This makes the code more concise and readable without changing the behavior.Cc Siddharth Vadapalli <[email protected]>Signed-off-by Anand Moon <[email protected]>
Quoted 3 lines
--- drivers/pci/controller/cadence/pci-j721e.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
[TRIMMED]
I have also tested the series (despite my feedback on the first patch). Logs:
https://gist.github.com/Siddharth-Vadapalli-at-TI/ca82a16e15a892b3349396be17b37643
Please address the feedback on the first patch.
Regards,
Siddharth.
Re: [RFC v1 1/2] PCI: j721e: Use devm_clk_get_optional_enabled() to get the clock
In reply to Siddharth VadapalliHi Siddharth,
Thanks for your review comment
Quoted 47 lines · Siddharth Vadapalli
Quoted 32 lines · Anand Moon
Use
devm_clk_get_optional_enabled()helper instead of callingdevm_clk_get_optional()and thenclk_prepare_enable(). It simplifies the error handling and makes the code more compact. This changes removes the unnecessary clk variable and assigns the result of thedevm_clk_get_optional_enabled()call directly topcie->refclk. This makes the code more concise and readable without changing the behavior.Cc Siddharth Vadapalli <[email protected]>Signed-off-by Anand Moon <[email protected]>--- drivers/pci/controller/cadence/pci-j721e.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/pci/controller/cadence/pci-j721e.c +0
-3@@ -479,7 +479,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)struct cdns_pcie_ep *ep =NULL ;struct gpio_desc *gpiod;void __iomem *base; -struct clk *clk;u32 num_lanes;u32 mode;int ret;@@ -603,18 +602,11 @@ static int j721e_pcie_probe(struct platform_device *pdev) goto err_get_sync; } - clk =devm_clk_get_optional (dev,"pcie_refclk" ); -if (IS_ERR (clk)) {drivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_probe(struct platform_device *pdev) · line 608
Quoted 10 lines
drivers/pci/controller/cadence/pci-j721e.c +2
-6- ret =dev_err_probe (dev,PTR_ERR (clk),"failed to get pcie_refclk\n" ); - goto err_pcie_setup; - } - - ret =clk_prepare_enable (clk); -if (ret) { + pcie->refclk =devm_clk_get_optional_enabled (dev,"pcie_refclk" ); +if (IS_ERR (pcie->refclk)) {dev_err_probe (dev, ret,"failed to enable pcie_refclk\n" ); goto err_pcie_setup;'
err_pcie_setup' returns 'ret' which isn't being updated above. Maybe add:
Quoted 2 lines
ret = pcie->refclk;above dev_err_probe(...
All return values from the dev_err_probe function appear to be missing in this file.
I'll address this in the next revision through a separate patch.
Quoted 9 lines
drivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_probe(struct platform_device *pdev) · line 612
Quoted 6 lines
drivers/pci/controller/cadence/pci-j721e.c +0
-1} - pcie->refclk = clk;/* * Section 2.2 of the PCI Express Card Electromechanical Regards,
Siddharth.
Thanks
-Anand