diff mbox series

[v3,17/18] PCI: j721e: add reset GPIO to struct j721e_pcie

Message ID 20240102-j7200-pcie-s2r-v3-17-5c2e4a3fac1f@bootlin.com (mailing list archive)
State New, archived
Headers show
Series Add suspend to ram support for PCIe on J7200 | expand

Commit Message

Thomas Richard Feb. 15, 2024, 3:18 p.m. UTC
From: Théo Lebrun <theo.lebrun@bootlin.com>

Add reset GPIO to struct j721e_pcie, so it can be used at suspend and
resume stages.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Signed-off-by: Thomas Richard <thomas.richard@bootlin.com>
---
 drivers/pci/controller/cadence/pci-j721e.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko Feb. 15, 2024, 4:04 p.m. UTC | #1
On Thu, Feb 15, 2024 at 04:18:02PM +0100, Thomas Richard wrote:
> From: Théo Lebrun <theo.lebrun@bootlin.com>
> 
> Add reset GPIO to struct j721e_pcie, so it can be used at suspend and
> resume stages.

...

>  	case PCI_MODE_RC:
> -		gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> -		if (IS_ERR(gpiod)) {
> -			ret = PTR_ERR(gpiod);
> +		pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> +		if (IS_ERR(pcie->reset_gpio)) {
> +			ret = PTR_ERR(pcie->reset_gpio);
>  			if (ret != -EPROBE_DEFER)
>  				dev_err(dev, "Failed to get reset GPIO\n");
>  			goto err_get_sync;
> @@ -504,9 +504,9 @@ static int j721e_pcie_probe(struct platform_device *pdev)
>  		 * mode is selected while enabling the PHY. So deassert PERST#
>  		 * after 100 us.
>  		 */
> -		if (gpiod) {
> +		if (pcie->reset_gpio) {
>  			usleep_range(100, 200);
> -			gpiod_set_value_cansleep(gpiod, 1);
> +			gpiod_set_value_cansleep(pcie->reset_gpio, 1);
>  		}

Instead of all this, just add one line assignment. Moreover, before or after
this patch refactor the code to use ret = dev_err_probe(...); pattern that
eliminates those deferral probe checks.
Thomas Richard Feb. 26, 2024, 5:05 p.m. UTC | #2
On 2/15/24 17:04, Andy Shevchenko wrote:
> On Thu, Feb 15, 2024 at 04:18:02PM +0100, Thomas Richard wrote:
>> From: Théo Lebrun <theo.lebrun@bootlin.com>
>>
>> Add reset GPIO to struct j721e_pcie, so it can be used at suspend and
>> resume stages.
> 
> ...
> 
>>  	case PCI_MODE_RC:
>> -		gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
>> -		if (IS_ERR(gpiod)) {
>> -			ret = PTR_ERR(gpiod);
>> +		pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
>> +		if (IS_ERR(pcie->reset_gpio)) {
>> +			ret = PTR_ERR(pcie->reset_gpio);
>>  			if (ret != -EPROBE_DEFER)
>>  				dev_err(dev, "Failed to get reset GPIO\n");
>>  			goto err_get_sync;
>> @@ -504,9 +504,9 @@ static int j721e_pcie_probe(struct platform_device *pdev)
>>  		 * mode is selected while enabling the PHY. So deassert PERST#
>>  		 * after 100 us.
>>  		 */
>> -		if (gpiod) {
>> +		if (pcie->reset_gpio) {
>>  			usleep_range(100, 200);
>> -			gpiod_set_value_cansleep(gpiod, 1);
>> +			gpiod_set_value_cansleep(pcie->reset_gpio, 1);
>>  		}
> 
> Instead of all this, just add one line assignment. Moreover, before or after
> this patch refactor the code to use ret = dev_err_probe(...); pattern that
> eliminates those deferral probe checks.

Hi Andy,

I'm not sure what you exactly want when you write "just add one line
assignment".
For the dev_err_probe() it's okay, it will be fixed in the next iteration.

Regards,
Andy Shevchenko Feb. 26, 2024, 5:54 p.m. UTC | #3
On Mon, Feb 26, 2024 at 06:05:16PM +0100, Thomas Richard wrote:
> On 2/15/24 17:04, Andy Shevchenko wrote:
> > On Thu, Feb 15, 2024 at 04:18:02PM +0100, Thomas Richard wrote:
> >> From: Théo Lebrun <theo.lebrun@bootlin.com>

...

> >>  	case PCI_MODE_RC:
> >> -		gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> >> -		if (IS_ERR(gpiod)) {
> >> -			ret = PTR_ERR(gpiod);
> >> +		pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> >> +		if (IS_ERR(pcie->reset_gpio)) {
> >> +			ret = PTR_ERR(pcie->reset_gpio);
> >>  			if (ret != -EPROBE_DEFER)
> >>  				dev_err(dev, "Failed to get reset GPIO\n");
> >>  			goto err_get_sync;
> >> @@ -504,9 +504,9 @@ static int j721e_pcie_probe(struct platform_device *pdev)
> >>  		 * mode is selected while enabling the PHY. So deassert PERST#
> >>  		 * after 100 us.
> >>  		 */
> >> -		if (gpiod) {
> >> +		if (pcie->reset_gpio) {
> >>  			usleep_range(100, 200);
> >> -			gpiod_set_value_cansleep(gpiod, 1);
> >> +			gpiod_set_value_cansleep(pcie->reset_gpio, 1);
> >>  		}
> > 
> > Instead of all this, just add one line assignment. Moreover, before or after
> > this patch refactor the code to use ret = dev_err_probe(...); pattern that
> > eliminates those deferral probe checks.
> 
> Hi Andy,
> 
> I'm not sure what you exactly want when you write "just add one line
> assignment".

		pcie->reset_gpio = gpiod;

That's it. No additional code changes are needed (WRT the above context,
of course you want to have a new structure member).
diff mbox series

Patch

diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c
index 2c87e7728a65..9c588e79f5ac 100644
--- a/drivers/pci/controller/cadence/pci-j721e.c
+++ b/drivers/pci/controller/cadence/pci-j721e.c
@@ -54,6 +54,7 @@  struct j721e_pcie {
 	struct clk		*refclk;
 	u32			mode;
 	u32			num_lanes;
+	struct gpio_desc	*reset_gpio;
 	void __iomem		*user_cfg_base;
 	void __iomem		*intd_cfg_base;
 	u32			linkdown_irq_regfield;
@@ -359,7 +360,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;
 	struct clk *clk;
 	u32 num_lanes;
@@ -468,9 +468,9 @@  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 = PTR_ERR(gpiod);
+		pcie->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+		if (IS_ERR(pcie->reset_gpio)) {
+			ret = PTR_ERR(pcie->reset_gpio);
 			if (ret != -EPROBE_DEFER)
 				dev_err(dev, "Failed to get reset GPIO\n");
 			goto err_get_sync;
@@ -504,9 +504,9 @@  static int j721e_pcie_probe(struct platform_device *pdev)
 		 * mode is selected while enabling the PHY. So deassert PERST#
 		 * after 100 us.
 		 */
-		if (gpiod) {
+		if (pcie->reset_gpio) {
 			usleep_range(100, 200);
-			gpiod_set_value_cansleep(gpiod, 1);
+			gpiod_set_value_cansleep(pcie->reset_gpio, 1);
 		}
 
 		ret = cdns_pcie_host_setup(rc);