PCI: controller: Move to agnostic GPIO API
Subsystems (12)
v4 cover PCI: controller: Move to agnostic GPIO API
While at it, remove of_gpio.h leftover from some of the drivers.
In v4:
- added tag (Mani)
- fixed a polarity bug in iMX.6 driver (Linus)
In v3:
- added precursor patch 1 to avoid build errors (LKP)
- used GPIOD_OUT_LOW instead of GPIOD_ASIS (Mani)
- added tags (Mani, Frank)
In v2:
- combined previously sent patches into a series (Manivannan)
- added tags (Rob, Manivannan)
- converted iMX.6 driver (Manivannan)
- dropped leftover in aadvark drivers (Manivannan)
Andy Shevchenko (5):
PCI: dra7xx: Add missing header inclusion
PCI: aardvark: Remove unused of_gpio.h
PCI: dwc: Remove unused of_gpio.h
PCI: imx6: Convert to agnostic GPIO API
PCI: kirin: Convert to agnostic GPIO API
drivers/pci/controller/dwc/pci-dra7xx.c | 2 +- drivers/pci/controller/dwc/pci-imx6.c | 36 ++----- drivers/pci/controller/dwc/pci-meson.c | 1 - drivers/pci/controller/dwc/pcie-kirin.c | 105 +++++++-------------- drivers/pci/controller/dwc/pcie-qcom.c | 1 - drivers/pci/controller/dwc/pcie-tegra194.c | 2 - drivers/pci/controller/pci-aardvark.c | 1 - 7 files changed, 46 insertions(+), 102 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v4 1/5 PCI: dra7xx: Add missing header inclusion
Driver is using chained_irq_*() APIs, add the respective inclusion.
--- drivers/pci/controller/dwc/pci-dra7xx.c | 1 + 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pci-dra7xx.c +1 -0
@@ -13,6 +13,7 @@#include <linux/err.h> #include <linux/interrupt.h> #include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> #include <linux/irqdomain.h> #include <linux/kernel.h> #include <linux/module.h>
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v4 2/5 PCI: aardvark: Remove unused of_gpio.h
In reply to Andy Shevchenkoof_gpio.h is deprecated and subject to remove.
The driver doesn't use it, simply remove the unused header.
--- drivers/pci/controller/pci-aardvark.c | 1 - 1 file changed, 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +0 -1
@@ -23,7 +23,6 @@#include <linux/platform_device.h> #include <linux/msi.h> #include <linux/of_address.h> -#include <linux/of_gpio.h> #include <linux/of_pci.h> #include "../pci.h"
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v4 3/5 PCI: dwc: Remove unused of_gpio.h
In reply to Andy Shevchenkoof_gpio.h is deprecated and subject to remove.
The driver doesn't use it, simply remove the unused header.
--- drivers/pci/controller/dwc/pci-dra7xx.c | 1 - drivers/pci/controller/dwc/pci-meson.c | 1 - drivers/pci/controller/dwc/pcie-qcom.c | 1 - drivers/pci/controller/dwc/pcie-tegra194.c | 2 -- 4 files changed, 5 deletions(-)
drivers/pci/controller/dwc/pci-dra7xx.c +0 -1
@@ -18,7 +18,6 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_pci.h> #include <linux/pci.h> #include <linux/phy/phy.h>
drivers/pci/controller/dwc/pci-meson.c +0 -1
@@ -9,7 +9,6 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/gpio/consumer.h> -#include <linux/of_gpio.h> #include <linux/pci.h> #include <linux/platform_device.h> #include <linux/reset.h>
drivers/pci/controller/dwc/pcie-qcom.c +0 -1
@@ -20,7 +20,6 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_device.h>
drivers/pci/controller/dwc/pcie-tegra194.c +0 -2
@@ -13,7 +13,6 @@#include <linux/clk.h> #include <linux/debugfs.h> #include <linux/delay.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/interconnect.h> #include <linux/interrupt.h>
@@ -21,7 +20,6 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_pci.h> #include <linux/pci.h> #include <linux/phy/phy.h>
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v4 4/5 PCI: imx6: Convert to agnostic GPIO API
In reply to Andy ShevchenkoThe of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API.
--- drivers/pci/controller/dwc/pci-imx6.c | 36 ++++++++------------------- 1 file changed, 10 insertions(+), 26 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +10 -26
@@ -11,14 +11,13 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/kernel.h> #include <linux/mfd/syscon.h> #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> #include <linux/mfd/syscon/imx7-iomuxc-gpr.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_address.h> #include <linux/pci.h> #include <linux/platform_device.h>
@@ -107,8 +106,7 @@ struct imx6_pcie_drvdata {struct imx6_pcie {struct dw_pcie *pci; -int reset_gpio; -bool gpio_active_high; +struct gpio_desc *reset_gpiod;bool link_is_up;struct clk_bulk_data clks[IMX6_PCIE_MAX_CLKS ];struct regmap *iomuxc_gpr;
@@ -721,9 +719,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) }/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,1 ); }static int imx6_pcie_deassert_core_reset (struct imx6_pcie *imx6_pcie)
@@ -771,10 +767,9 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) }/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) { +if (imx6_pcie->reset_gpiod) {msleep (100 ); -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - !imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,0 );/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ msleep (100 ); }
@@ -1285,22 +1280,11 @@ static int imx6_pcie_probe(struct platform_device *pdev)return PTR_ERR (pci->dbi_base);/* Fetch GPIOs */ - imx6_pcie->reset_gpio =of_get_named_gpio (node,"reset-gpio" ,0 ); - imx6_pcie->gpio_active_high =of_property_read_bool (node, -"reset-gpio-active-high" ); -if (gpio_is_valid (imx6_pcie->reset_gpio)) { - ret =devm_gpio_request_one (dev, imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high ? -GPIOF_OUT_INIT_HIGH : -GPIOF_OUT_INIT_LOW , -"PCIe reset" ); -if (ret) { -dev_err (dev,"unable to get reset gpio\n" ); -return ret; - } - }else if (imx6_pcie->reset_gpio == -EPROBE_DEFER ) { -return imx6_pcie->reset_gpio; - } + imx6_pcie->reset_gpiod =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (imx6_pcie->reset_gpiod)) +return dev_err_probe (dev,PTR_ERR (imx6_pcie->reset_gpiod), +"unable to get reset gpio\n" ); +gpiod_set_consumer_name (imx6_pcie->reset_gpiod,"PCIe reset" );if (imx6_pcie->drvdata->clks_cnt >=IMX6_PCIE_MAX_CLKS )return dev_err_probe (dev, -ENOMEM ,"clks_cnt is too big\n" );
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Frank Li
maintainerRe: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO API
Quoted 7 lines · Andy Shevchenko
The
of_gpio.his going to be removed. In preparation of that convert the driver to the agnostic API.Reviewed-by Manivannan Sadhasivam <[email protected]>Reviewed-by Frank Li <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
Can I include your patch in my imx6 pci improvement patches
https://lore.kernel.org/linux-pci/[email protected]/T/#t
There is patch, which rename function from imx6 -> imx. That will avoid conflict.
Frank Li
Quoted 88 lines
drivers/pci/controller/dwc/pci-imx6.c | 36 ++++++++------------------- 1 file changed, 10 insertions(+), 26 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +10
-26@@ -11,14 +11,13 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/kernel.h> #include <linux/mfd/syscon.h> #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> #include <linux/mfd/syscon/imx7-iomuxc-gpr.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_address.h> #include <linux/pci.h> #include <linux/platform_device.h> @@ -107,8 +106,7 @@ struct imx6_pcie_drvdata {struct imx6_pcie {struct dw_pcie *pci; -int reset_gpio; -bool gpio_active_high; +struct gpio_desc *reset_gpiod;bool link_is_up;struct clk_bulk_data clks[IMX6_PCIE_MAX_CLKS ];struct regmap *iomuxc_gpr;@@ -721,9 +719,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) }/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,1 ); }static int imx6_pcie_deassert_core_reset (struct imx6_pcie *imx6_pcie)@@ -771,10 +767,9 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) }/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) { +if (imx6_pcie->reset_gpiod) {msleep (100 ); -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - !imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,0 );/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ msleep (100 ); }@@ -1285,22 +1280,11 @@ static int imx6_pcie_probe(struct platform_device *pdev)return PTR_ERR (pci->dbi_base);/* Fetch GPIOs */ - imx6_pcie->reset_gpio =of_get_named_gpio (node,"reset-gpio" ,0 ); - imx6_pcie->gpio_active_high =of_property_read_bool (node, -"reset-gpio-active-high" ); -if (gpio_is_valid (imx6_pcie->reset_gpio)) { - ret =devm_gpio_request_one (dev, imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high ? -GPIOF_OUT_INIT_HIGH : -GPIOF_OUT_INIT_LOW , -"PCIe reset" ); -if (ret) { -dev_err (dev,"unable to get reset gpio\n" ); -return ret; - } - }else if (imx6_pcie->reset_gpio == -EPROBE_DEFER ) { -return imx6_pcie->reset_gpio; - } + imx6_pcie->reset_gpiod =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (imx6_pcie->reset_gpiod)) +return dev_err_probe (dev,PTR_ERR (imx6_pcie->reset_gpiod), +"unable to get reset gpio\n" ); +gpiod_set_consumer_name (imx6_pcie->reset_gpiod,"PCIe reset" );if (imx6_pcie->drvdata->clks_cnt >=IMX6_PCIE_MAX_CLKS )return dev_err_probe (dev, -ENOMEM ,"clks_cnt is too big\n" );Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO API
Tue, May 07, 2024 at 03:22:33PM -0400, Frank Li kirjoitti:
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines
The
of_gpio.his going to be removed. In preparation of that convert the driver to the agnostic API.
...
Quoted 5 lines
Can I include your patch in my imx6 pci improvement patches
https://lore.kernel.org/linux-pci/[email protected]/T/#tThere is patch, which rename function from imx6 -> imx. That will avoid conflict.
You can, of course, but it will be not my decision to make. Ask PCI maintainers who is supposed to take this series.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hongxing Zhu
maintainerRE: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO API
In reply to Andy ShevchenkoQuoted 104 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: 2024年5月6日 22:21
To: Manivannan Sadhasivam <[email protected]>; Frank Li <[email protected]>; Krzysztof Wilczyński <[email protected]>; Andy Shevchenko <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Vignesh Raghavendra <[email protected]>; Siddharth Vadapalli <[email protected]>; Lorenzo Pieralisi <[email protected]>; Krzysztof Wilczyński <[email protected]>; Rob Herring <[email protected]>; Bjorn Helgaas <[email protected]>; Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Yue Wang <[email protected]>; Neil Armstrong <[email protected]>; Kevin Hilman <[email protected]>; Jerome Brunet <[email protected]>; Martin Blumenstingl <[email protected]>; Xiaowei Song <[email protected]>; Binghui Wang <[email protected]>; Thierry Reding <[email protected]>; Jonathan Hunter <[email protected]>; Thomas Petazzoni <[email protected]>; Pali Rohár <[email protected]>; Linus Walleij <[email protected]>
Subject: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO APIThe
of_gpio.his going to be removed. In preparation of that convert the driver to the agnostic API.Reviewed-by Manivannan Sadhasivam <[email protected]>Reviewed-by Frank Li <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 36 ++++++++------------------- 1 file changed, 10 insertions(+), 26 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +3
-7@@ -11,14 +11,13 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/kernel.h> #include <linux/mfd/syscon.h> #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> #include <linux/mfd/syscon/imx7-iomuxc-gpr.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_address.h> #include <linux/pci.h> #include <linux/platform_device.h> @@ -107,8 +106,7 @@ struct imx6_pcie_drvdata {struct imx6_pcie {struct dw_pcie *pci; -int reset_gpio; -bool gpio_active_high; +struct gpio_desc *reset_gpiod;bool link_is_up;struct clk_bulk_data clks[IMX6_PCIE_MAX_CLKS ];struct regmap *iomuxc_gpr;@@ -721,9 +719,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) }/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,1 ); }static int
imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)@@
-771,10 +767,9 @@ static intimx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c +2
-9}/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) { +if (imx6_pcie->reset_gpiod) {msleep (100 ); -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - !imx6_pcie->gpio_active_high); +gpiod_set_value_cansleep (imx6_pcie->reset_gpiod,0 );/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ msleep (100 ); }@@ -1285,22 +1280,11 @@ static int imx6_pcie_probe(struct platform_device *pdev)return PTR_ERR (pci->dbi_base);/* Fetch GPIOs */ - imx6_pcie->reset_gpio =of_get_named_gpio (node,"reset-gpio" ,0 ); - imx6_pcie->gpio_active_high =of_property_read_bool (node, -"reset-gpio-active-high" ); -if (gpio_is_valid (imx6_pcie->reset_gpio)) { - ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high ?
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_probe(struct platform_device · line 1304
Quoted 10 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-10- GPIOF_OUT_INIT_HIGH : -GPIOF_OUT_INIT_LOW , - "PCIe reset"); -if (ret) { -dev_err (dev,"unable to get reset gpio\n" ); -return ret; - } - }else if (imx6_pcie->reset_gpio == -EPROBE_DEFER ) { -return imx6_pcie->reset_gpio; - }
Hi Andy:
Please correct me if my understand is wrong.
The "reset-gpio-active-high" property is added for some buggy board designs. On these buggy boards, the reset gpio is active high.
In the other words, the PERST# is active and remote endpoint device would be in reset stat when this gpio is high on these buggy boards.
I'm afraid that the PCIe would be broken on these boards, If these codes
are removed totally, and toggle the reset GPIO pin like below.
...gpio_set_value_cansleep(imx6_pcie->reset_gpio, 0); msleep(100);gpio_set_value_cansleep(imx6_pcie->reset_gpio, 1);
...
By the way, this reset GPIO pin should be high at end in imx6_pcie_deassert_core_reset() if the imx6_pcie->gpio_active_high is zero.
Best Regards
Richard Zhu
Quoted 11 lines
drivers/pci/controller/dwc/pci-imx6.c +5
-0+ imx6_pcie->reset_gpiod =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (imx6_pcie->reset_gpiod)) +return dev_err_probe (dev,PTR_ERR (imx6_pcie->reset_gpiod), +"unable to get reset gpio\n" ); +gpiod_set_consumer_name (imx6_pcie->reset_gpiod,"PCIe reset" );drivers/pci/controller/dwc/pci-imx6.c +0
-1if (imx6_pcie->drvdata->clks_cnt >=IMX6_PCIE_MAX_CLKS )return dev_err_probe (dev, -ENOMEM ,"clks_cnt is too big\n" ); --2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO API
Thu, May 09, 2024 at 01:24:45AM +0000, Hongxing Zhu kirjoitti:
Quoted 3 lines
Quoted 3 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: 2024年5月6日 22:21
...
Quoted 11 lines
Quoted 11 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-11- imx6_pcie->gpio_active_high =of_property_read_bool (node, -"reset-gpio-active-high" ); -if (gpio_is_valid (imx6_pcie->reset_gpio)) { - ret =devm_gpio_request_one (dev, imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high ? -GPIOF_OUT_INIT_HIGH : -GPIOF_OUT_INIT_LOW , -"PCIe reset" ); -if (ret) { -dev_err (dev,"unable to get reset gpio\n" ); -return ret;
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_probe(struct platform_device *pdev) · line 1303
Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-4- } - }else if (imx6_pcie->reset_gpio == -EPROBE_DEFER ) { -return imx6_pcie->reset_gpio; - }Please correct me if my understand is wrong.
The "reset-gpio-active-high" property is added for some buggy board designs. On these buggy boards, the reset gpio is active high.
This is my understanding too.
Quoted 2 lines
In the other words, the PERST# is active and remote endpoint device would be in reset stat when this gpio is high on these buggy boards.
Yes.
Quoted 2 lines
I'm afraid that the PCIe would be broken on these boards, If these codes
are removed totally,
No. Linus W. explained in the previous version review round how it's supposed to work.
Quoted 6 lines
and toggle the reset GPIO pin like below.
...gpio_set_value_cansleep(imx6_pcie->reset_gpio, 0); msleep(100);gpio_set_value_cansleep(imx6_pcie->reset_gpio, 1);
...
It's not the code that this patch adds. I'm not sure if I understand starting from here what you mean.
Quoted 2 lines
By the way, this reset GPIO pin should be high at end in
imx6_pcie_deassert_core_reset()if theimx6_pcie->gpio_active_highis zero.
This seems a terminology mixup. You probably meant "inactive". And this is exactly the case with this patch.
If you start thinking in terms of "active"/"inactive" you will see that there is no contradiction and no behaviour change. The quirk itself is located in gpiolib-of.c..
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 4/5] PCI: imx6: Convert to agnostic GPIO API
In reply to Andy ShevchenkoQuoted 6 lines · Andy Shevchenko
The
of_gpio.his going to be removed. In preparation of that convert the driver to the agnostic API.Reviewed-by Manivannan Sadhasivam <[email protected]>Reviewed-by Frank Li <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Would maybe mention in the commit that the quirk to gpiolib is already in place (people are already confused by it) but no big deal.
Yours,
Linus Walleij
PATCH v4 5/5 PCI: kirin: Convert to agnostic GPIO API
In reply to Andy ShevchenkoThe of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API.
--- drivers/pci/controller/dwc/pcie-kirin.c | 105 ++++++++---------------- 1 file changed, 35 insertions(+), 70 deletions(-)
drivers/pci/controller/dwc/pcie-kirin.c +35 -70
@@ -12,12 +12,10 @@#include <linux/compiler.h> #include <linux/delay.h> #include <linux/err.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/interrupt.h> #include <linux/mfd/syscon.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_pci.h> #include <linux/phy/phy.h> #include <linux/pci.h>
@@ -78,16 +76,16 @@ struct kirin_pcie {void *phy_priv;/* only for PCIE_KIRIN_INTERNAL_PHY */ /* DWC PERST# */ -int gpio_id_dwc_perst; +struct gpio_desc *id_dwc_perst_gpio;/* Per-slot PERST# */ int num_slots; -int gpio_id_reset[MAX_PCI_SLOTS ]; +struct gpio_desc *id_reset_gpio[MAX_PCI_SLOTS ];const char *reset_names[MAX_PCI_SLOTS ];/* Per-slot clkreq */ int n_gpio_clkreq; -int gpio_id_clkreq[MAX_PCI_SLOTS ]; +struct gpio_desc *id_clkreq_gpio[MAX_PCI_SLOTS ];const char *clkreq_names[MAX_PCI_SLOTS ]; };
@@ -381,15 +379,20 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie, pcie->n_gpio_clkreq = ret;for (i =0 ; i < pcie->n_gpio_clkreq; i++) { - pcie->gpio_id_clkreq[i] =of_get_named_gpio (dev->of_node, -"hisilicon,clken-gpios" , i); -if (pcie->gpio_id_clkreq[i] <0 ) -return pcie->gpio_id_clkreq[i]; + pcie->id_clkreq_gpio[i] =devm_gpiod_get_index (dev, +"hisilicon,clken" , i, +GPIOD_OUT_LOW ); +if (IS_ERR (pcie->id_clkreq_gpio[i])) +return dev_err_probe (dev,PTR_ERR (pcie->id_clkreq_gpio[i]), +"unable to get a valid clken gpio\n" ); pcie->clkreq_names[i] =devm_kasprintf (dev,GFP_KERNEL ,"pcie_clkreq_%d" , i);if (!pcie->clkreq_names[i])return -ENOMEM ; + +gpiod_set_consumer_name (pcie->id_clkreq_gpio[i], + pcie->clkreq_names[i]); }return 0 ;
@@ -407,10 +410,16 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,for_each_available_child_of_node (parent, child) { i = pcie->num_slots; - pcie->gpio_id_reset[i] =of_get_named_gpio (child, -"reset-gpios" ,0 ); -if (pcie->gpio_id_reset[i] <0 ) -continue ; + pcie->id_reset_gpio[i] =devm_fwnode_gpiod_get_index (dev, +of_fwnode_handle (child), +"reset" ,0 ,GPIOD_OUT_LOW , +NULL ); +if (IS_ERR (pcie->id_reset_gpio[i])) { +if (PTR_ERR (pcie->id_reset_gpio[i]) == -ENOENT ) +continue ; +return dev_err_probe (dev,PTR_ERR (pcie->id_reset_gpio[i]), +"unable to get a valid reset gpio\n" ); + } pcie->num_slots++;if (pcie->num_slots >MAX_PCI_SLOTS ) {
@@ -434,6 +443,9 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie, ret = -ENOMEM ; goto put_node; } + +gpiod_set_consumer_name (pcie->id_reset_gpio[i], + pcie->reset_names[i]); } }
@@ -463,14 +475,11 @@ static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie,return PTR_ERR (kirin_pcie->apb);/* pcie internal PERST# gpio */ - kirin_pcie->gpio_id_dwc_perst =of_get_named_gpio (dev->of_node, -"reset-gpios" ,0 ); -if (kirin_pcie->gpio_id_dwc_perst == -EPROBE_DEFER ) { -return -EPROBE_DEFER ; - }else if (!gpio_is_valid (kirin_pcie->gpio_id_dwc_perst)) { -dev_err (dev,"unable to get a valid gpio pin\n" ); -return -ENODEV ; - } + kirin_pcie->id_dwc_perst_gpio =devm_gpiod_get (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (kirin_pcie->id_dwc_perst_gpio)) +return dev_err_probe (dev,PTR_ERR (kirin_pcie->id_dwc_perst_gpio), +"unable to get a valid gpio pin\n" ); +gpiod_set_consumer_name (kirin_pcie->id_dwc_perst_gpio,"pcie_perst_bridge" ); ret =kirin_pcie_get_gpio_enable (kirin_pcie, pdev);if (ret)
@@ -553,7 +562,7 @@ static int kirin_pcie_add_bus(struct pci_bus *bus)/* Send PERST# to each slot */ for (i =0 ; i < kirin_pcie->num_slots; i++) { - ret =gpio_direction_output (kirin_pcie->gpio_id_reset[i],1 ); + ret =gpiod_direction_output_raw (kirin_pcie->id_reset_gpio[i],1 );if (ret) {dev_err (pci->dev,"PERST# %s error: %d\n" , kirin_pcie->reset_names[i], ret);
@@ -623,44 +632,6 @@ static int kirin_pcie_host_init(struct dw_pcie_rp *pp)return 0 ; } -static int kirin_pcie_gpio_request (struct kirin_pcie *kirin_pcie, -struct device *dev) -{ -int ret, i; - -for (i =0 ; i < kirin_pcie->num_slots; i++) { -if (!gpio_is_valid (kirin_pcie->gpio_id_reset[i])) { -dev_err (dev,"unable to get a valid %s gpio\n" , - kirin_pcie->reset_names[i]); -return -ENODEV ; - } - - ret =devm_gpio_request (dev, kirin_pcie->gpio_id_reset[i], - kirin_pcie->reset_names[i]); -if (ret) -return ret; - } - -for (i =0 ; i < kirin_pcie->n_gpio_clkreq; i++) { -if (!gpio_is_valid (kirin_pcie->gpio_id_clkreq[i])) { -dev_err (dev,"unable to get a valid %s gpio\n" , - kirin_pcie->clkreq_names[i]); -return -ENODEV ; - } - - ret =devm_gpio_request (dev, kirin_pcie->gpio_id_clkreq[i], - kirin_pcie->clkreq_names[i]); -if (ret) -return ret; - - ret =gpio_direction_output (kirin_pcie->gpio_id_clkreq[i],0 ); -if (ret) -return ret; - } - -return 0 ; -} -static const struct dw_pcie_ops kirin_dw_pcie_ops = { .read_dbi = kirin_pcie_read_dbi, .write_dbi = kirin_pcie_write_dbi,
@@ -680,7 +651,7 @@ static int kirin_pcie_power_off(struct kirin_pcie *kirin_pcie)return hi3660_pcie_phy_power_off (kirin_pcie);for (i =0 ; i < kirin_pcie->n_gpio_clkreq; i++) -gpio_direction_output (kirin_pcie->gpio_id_clkreq[i],1 ); +gpiod_direction_output_raw (kirin_pcie->id_clkreq_gpio[i],1 );phy_power_off (kirin_pcie->phy);phy_exit (kirin_pcie->phy);
@@ -707,10 +678,6 @@ static int kirin_pcie_power_on(struct platform_device *pdev,if (IS_ERR (kirin_pcie->phy))return PTR_ERR (kirin_pcie->phy); - ret =kirin_pcie_gpio_request (kirin_pcie, dev); -if (ret) -return ret; - ret =phy_init (kirin_pcie->phy);if (ret) goto err;
@@ -723,11 +690,9 @@ static int kirin_pcie_power_on(struct platform_device *pdev,/* perst assert Endpoint */ usleep_range (REF_2_PERST_MIN ,REF_2_PERST_MAX ); -if (!gpio_request (kirin_pcie->gpio_id_dwc_perst,"pcie_perst_bridge" )) { - ret =gpio_direction_output (kirin_pcie->gpio_id_dwc_perst,1 ); -if (ret) - goto err; - } + ret =gpiod_direction_output_raw (kirin_pcie->id_dwc_perst_gpio,1 ); +if (ret) + goto err;usleep_range (PERST_2_ACCESS_MIN ,PERST_2_ACCESS_MAX );
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Quoted 3 lines · Andy Shevchenko
In v4:
- added tag (Mani)
- fixed a polarity bug in iMX.6 driver (Linus)
Looks good now. The series:
Perhaps the use of _raw accessors could be avoided in 5/5 by some elaborart polarity quirk but I'm no perfectionist and it can be fixed later.
Yours,
Linus Walleij
Quoted 9 lines · Linus Walleij
Quoted 3 lines · Andy Shevchenko
In v4:
- added tag (Mani)
- fixed a polarity bug in iMX.6 driver (Linus)Looks good now. The series:
Reviewed-by Linus Walleij <[email protected]>
Thank you!
Quoted 2 lines
Perhaps the use of
_rawaccessors could be avoided in 5/5 by some elaborart polarity quirk but I'm no perfectionist and it can be fixed later.
After your comment I was thinking the same, and came to the similar conclusion, we might fix this later as in comparison to iMX.6 case this requires an additional code to be added to gpiolib-of.c.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hello,
Quoted 1 line
While at it, remove
of_gpio.hleftover from some of the drivers.
Applied to gpio, thank you!
[01/05] PCI: dra7xx: Add missing chained IRQ header inclusion
https://git.kernel.org/pci/pci/c/1d1efd131cc1 [02/05] PCI: aardvark: Remove unused of_gpio.h inclusion https://git.kernel.org/pci/pci/c/83bf80dc8e2f [03/05] PCI: dwc: Remove unused of_gpio.h inclusion https://git.kernel.org/pci/pci/c/8f69a807234b [04/05] PCI: imx6: Convert to use agnostic GPIO API https://git.kernel.org/pci/pci/c/7dfa559abc93 [05/05] PCI: kirin: Convert to use agnostic GPIO API https://git.kernel.org/pci/pci/c/7ca698ff686c Krzysztof
Quoted 5 lines · Krzysztof Wilczyński
Hello,
Quoted 1 line
While at it, remove
of_gpio.hleftover from some of the drivers.Applied to gpio, thank you!
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko