pci: pcie-rcar: add regulators support
Subsystems (5)
PATCH 1/1 pci: pcie-rcar: add regulators support
From: Andrey Gusakov <[email protected]>
Add PCIe regulators for KingFisher board.
--- arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++ drivers/pci/controller/pcie-rcar-host.c | 64 ++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi +47 -0
@@ -50,6 +50,25 @@ startup-delay-us = <70000>; enable-active-high; }; + + mpcie_3v3: regulator-mpcie_3v3 { + compatible = "regulator-fixed"; + regulator-name = "mPCIe 3v3"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + gpio = <&gpio_exp_77 14 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; + + mpcie_1v8: regulator-mpcie_1v8 { + compatible = "regulator-fixed"; + regulator-name = "mPCIe 1v8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + gpio = <&gpio_exp_77 15 GPIO_ACTIVE_HIGH>; + startup-delay-us = <200000>; + enable-active-high; + }; }; &can0 {
@@ -241,6 +260,31 @@ interrupt-controller; interrupt-parent = <&gpio5>; interrupts = <9 IRQ_TYPE_EDGE_FALLING>; + + mpcie_wake { + gpio-hog; + gpios = <0 GPIO_ACTIVE_HIGH>; + output-low; + line-name = "mPCIe WAKE#"; + }; + mpcie_wdisable { + gpio-hog; + gpios = <1 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "mPCIe W_DISABLE"; + }; + mpcie_clreq { + gpio-hog; + gpios = <2 GPIO_ACTIVE_HIGH>; + input; + line-name = "mPCIe CLKREQ#"; + }; + mpcie_ovc { + gpio-hog; + gpios = <3 GPIO_ACTIVE_HIGH>; + input; + line-name = "mPCIe OVC"; + }; }; };
@@ -259,6 +303,9 @@ &pciec1 { status = "okay"; + + pcie3v3-supply = <&mpcie_3v3>; + pcie1v8-supply = <&mpcie_1v8>; }; &pfc {
drivers/pci/controller/pcie-rcar-host.c +64 -0
94 lines not on this page · raw message
Signature · 1 line
2.17.1
Hi Meng,
Quoted 5 lines · Meng Li
From: Andrey Gusakov <[email protected]>
Add PCIe regulators for KingFisher board.
Signed-off-by Meng Li <[email protected]>
Thanks for your patch!
Quoted 2 lines
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++ drivers/pci/controller/pcie-rcar-host.c | 64 ++++++++++++++++++++++++
Please split patches touching both DT and driver sources.
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi line 308
Quoted 10 lines
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi +3
-0@@ -259,6 +303,9 @@ &pciec1 { status = "okay"; + + pcie3v3-supply = <&mpcie_3v3>; + pcie1v8-supply = <&mpcie_1v8>;
This needs an update to the R-Car PCIe DT bindings first.
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 905
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +7
-0@@ -893,6 +896,36 @@ static const struct of_device_id rcar_pcie_of_match[] = { {}, }; +static int rcar_pcie_set_vpcie (struct rcar_pcie_host *host) +{ +struct device *dev = host->pcie.dev; +int err; + +if (!IS_ERR (host->pcie3v3)) { + err =regulator_enable (host->pcie3v3);
This will crash if host->pcie3v3 is NULL (optional regulator not present). Probably you just want to check for non-NULL (see below).
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 913
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+if (err) { +dev_err (dev,"fail to enable vpcie3v3 regulator\n" ); + goto err_out; + } + } + +if (!IS_ERR (host->pcie1v8)) { + err =regulator_enable (host->pcie1v8);
Likewise.
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 923
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+if (err) { +dev_err (dev,"fail to enable vpcie1v8 regulator\n" ); + goto err_disable_3v3; + } + } + +return 0 ; + +err_disable_3v3: +if (!IS_ERR (host->pcie3v3))
Likewise.
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +5
-0+regulator_disable (host->pcie3v3); +err_out: +return err; +} +static int rcar_pcie_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 950
Quoted 7 lines
drivers/pci/controller/pcie-rcar-host.c +4
-0@@ -911,6 +944,31 @@ static int rcar_pcie_probe(struct platform_device *pdev) pcie->dev = dev;platform_set_drvdata (pdev, host); + host->pcie3v3 =devm_regulator_get_optional (dev,"pcie3v3" ); +if (IS_ERR (host->pcie3v3)) { +if (PTR_ERR (host->pcie3v3) == -EPROBE_DEFER ) { +pci_free_host_bridge (bridge);
Please drop this. As the bridge was allocated using devm_pci_alloc_host_bridge(), freeing it manually will cause a double free.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 953
Quoted 3 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+return -EPROBE_DEFER ; + } +dev_info (dev,"no pcie3v3 regulator found\n" );
devm_regulator_get_optional() returns NULL if the regulator was not found. Hence if IS_ERR() is true, this indicates a real error, which you should handle:
if (IS_ERR(host->pcie3v3))
return PTR_ERR(host->pcie3v3);drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 962
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ } + + host->pcie1v8 =devm_regulator_get_optional (dev,"pcie1v8" ); +if (IS_ERR (host->pcie1v8)) { +if (PTR_ERR (host->pcie1v8) == -EPROBE_DEFER ) { +pci_free_host_bridge (bridge); +return -EPROBE_DEFER ; + } +dev_info (dev,"no pcie1v8 regulator found\n" );
Likewise.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 968
Quoted 6 lines
drivers/pci/controller/pcie-rcar-host.c +6
-0+ } + + err =rcar_pcie_set_vpcie (host); +if (err) { +dev_err (dev,"failed to set pcie regulators\n" ); +pci_free_host_bridge (bridge);
Please drop this to avoid double free.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1046
Quoted 11 lines
drivers/pci/controller/pcie-rcar-host.c +4
-0+return err; + } +pm_runtime_enable (pcie->dev); err =pm_runtime_get_sync (pcie->dev);if (err <0 ) {@@ -985,6 +1043,12 @@ static int rcar_pcie_probe(struct platform_device *pdev)irq_dispose_mapping (host->msi.irq1); err_pm_put: +if (!IS_ERR (host->pcie3v3))
if (host->pcie3v3)
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1047
Quoted 1 line
drivers/pci/controller/pcie-rcar-host.c +1
-0+if (regulator_is_enabled (host->pcie3v3))
If you get here, the regulator should be enabled?
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1049
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+regulator_disable (host->pcie3v3); +if (!IS_ERR (host->pcie1v8))
if (host->pcie1v8)
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1051
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+if (regulator_is_enabled (host->pcie1v8)) +regulator_disable (host->pcie1v8);
Please move this below the call to pm_runtime_disable(), to preserve symmetry.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1053
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +0
-0pm_runtime_put (dev);pm_runtime_disable (dev);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 167 lines
-----Original Message-----
From: Geert Uytterhoeven <[email protected]>
Sent: Tuesday, October 19, 2021 6:20 PM
To: Li, Meng <[email protected]>
Cc: Magnus Damm <[email protected]>; Rob Herring <[email protected]>; Marek Vasut <[email protected]>; Yoshihiro Shimoda <[email protected]>; Lorenzo Pieralisi <[email protected]>; Krzysztof Wilczyński <[email protected]>; Bjorn Helgaas <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Linux-Renesas <linux-renesas- [email protected]>; open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS <[email protected]>; Linux Kernel Mailing List <[email protected]>; linux-pci <[email protected]>
Subject: Re: [PATCH] pci: pcie-rcar: add regulators support[Please note: This e-mail is from an EXTERNAL e-mail address]
Hi Meng,
Quoted 5 lines · Meng Li
From: Andrey Gusakov <[email protected]>
Add PCIe regulators for KingFisher board.
Signed-off-by Meng Li <[email protected]>Thanks for your patch!
Quoted 2 lines
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++
drivers/pci/controller/pcie-rcar-host.c| 64 ++++++++++++++++++++++++Please split patches touching both DT and driver sources.
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi line 308
Quoted 10 lines
arch/arm64/boot/dts/renesas/ulcb-kf.dtsi +3
-0@@ -259,6 +303,9 @@ &pciec1 { status = "okay"; + + pcie3v3-supply = <&mpcie_3v3>; + pcie1v8-supply = <&mpcie_1v8>;This needs an update to the R-Car PCIe DT bindings first.
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +0
-0@@ -893,6 +896,36 @@ static const struct of_device_idrcar_pcie_of_match[] = {
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 905
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +6
-0{}, }; +static int rcar_pcie_set_vpcie (struct rcar_pcie_host *host) { +struct device *dev = host->pcie.dev; +int err; + +if (!IS_ERR (host->pcie3v3)) { + err =regulator_enable (host->pcie3v3);This will crash if
host->pcie3v3is NULL (optional regulator not present). Probably you just want to check for non-NULL (see below).drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 913
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+if (err) { +dev_err (dev,"fail to enable vpcie3v3 regulator\n" ); + goto err_out; + } + } + +if (!IS_ERR (host->pcie1v8)) { + err =regulator_enable (host->pcie1v8);Likewise.
drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_of_match[] = { · line 923
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+if (err) { +dev_err (dev,"fail to enable vpcie1v8 regulator\n" ); + goto err_disable_3v3; + } + } + +return 0 ; + +err_disable_3v3: +if (!IS_ERR (host->pcie3v3))Likewise.
Quoted 5 lines
drivers/pci/controller/pcie-rcar-host.c +5
-0+regulator_disable (host->pcie3v3); +err_out: +return err; +} +drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +4
-0static int rcar_pcie_probe (struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -911,6 +944,31 @@ staticint rcar_pcie_probe (struct platform_device *pdev) pcie->dev = dev;platform_set_drvdata (pdev, host); + host->pcie3v3 =devm_regulator_get_optional (dev,"pcie3v3" ); +if (IS_ERR (host->pcie3v3)) { +if (PTR_ERR (host->pcie3v3) == -EPROBE_DEFER ) { +pci_free_host_bridge (bridge);Please drop this. As the bridge was allocated using
devm_pci_alloc_host_bridge(), freeing it manually will cause a double free.drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 953
Quoted 3 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+return -EPROBE_DEFER ; + } +dev_info (dev,"no pcie3v3 regulator found\n" );
devm_regulator_get_optional()returns NULL if the regulator was not found. Hence ifIS_ERR()is true, this indicates a real error, which you should handle:if (IS_ERR(host->pcie3v3)) return PTR_ERR(host->pcie3v3);drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 962
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ } + + host->pcie1v8 =devm_regulator_get_optional (dev,"pcie1v8" ); +if (IS_ERR (host->pcie1v8)) { +if (PTR_ERR (host->pcie1v8) == -EPROBE_DEFER ) { +pci_free_host_bridge (bridge); +return -EPROBE_DEFER ; + } +dev_info (dev,"no pcie1v8 regulator found\n" );Likewise.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 968
Quoted 6 lines
drivers/pci/controller/pcie-rcar-host.c +6
-0+ } + + err =rcar_pcie_set_vpcie (host); +if (err) { +dev_err (dev,"failed to set pcie regulators\n" ); +pci_free_host_bridge (bridge);Please drop this to avoid double free.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device
Quoted 7 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+return err; + } +pm_runtime_enable (pcie->dev); err =pm_runtime_get_sync (pcie->dev);if (err <0 ) {@@ -985,6 +1043,12 @@ static int rcar_pcie_probe(struct platform_device*pdev)
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1046
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +1
-0irq_dispose_mapping (host->msi.irq1); err_pm_put: +if (!IS_ERR (host->pcie3v3))if (
host->pcie3v3)drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1047
Quoted 1 line
drivers/pci/controller/pcie-rcar-host.c +1
-0+if (regulator_is_enabled (host->pcie3v3))If you get here, the regulator should be enabled?
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1049
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+regulator_disable (host->pcie3v3); +if (!IS_ERR (host->pcie1v8))if (
host->pcie1v8)drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1051
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+if (regulator_is_enabled (host->pcie1v8)) +regulator_disable (host->pcie1v8);
Quoted 8 lines
Please move this below the call to
pm_runtime_disable(), to preserve symmetry.drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1053
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +0
-0pm_runtime_put (dev);pm_runtime_disable (dev);Gr{oetje,eeting}s,
Thanks for your professional suggest.
I will improve patches and send v2 in later
Thanks,
Limeng
Quoted 9 lines
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux- m68k.orgIn personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 6 lines · Meng Li
From: Andrey Gusakov <[email protected]>
Add PCIe regulators for KingFisher board.
Signed-off-by Meng Li <[email protected]>---
You've not provided a Signed-off-by for Andrey, please see Documentation/process/submitting-patches.rst for details on what this is and why it's important.
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 956
Quoted 3 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+ host->pcie3v3 =devm_regulator_get_optional (dev,"pcie3v3" ); + host->pcie1v8 =devm_regulator_get_optional (dev,"pcie1v8" );
Unless PCIe works without these supplies (which are in my understanding mandatory according to the spec) these should not be optional, this API is for supplies that may be physically absent.
Quoted 3 lines · Meng Li
From: Andrey Gusakov <[email protected]>
Add PCIe regulators for KingFisher board.
Please pay attention to the existing code and history. Your current subject line is:
pci: pcie-rcar: add regulators support
which looks nothing like the history:
$ git log --oneline drivers/pci/controller/pcie-rcar-host.c
861e133ba268 ("PCI: rcar-host: Remove unneeded includes")
a115b1bd3af0 ("PCI: rcar: Add L1 link state fix into data abort hook")
d21faba11693 ("PCI: Bulk conversion to generic_handle_domain_irq()")
83ed8d4fa656 ("PCI: rcar: Convert to MSI domains")
93cd1bb4862d ("PCI: rcar: Don't allocate extra memory for the MSI capture address")
c4e0fec2f7ee ("PCI: rcar: Always allocate MSI addresses in 32bit space")
6e8e137abeab ("PCI: rcar: Drop unused members from struct rcar_pcie_host")
b64aa11eb2dd ("PCI: Set bridge map_irq and swizzle_irq to default functions")
669cbc708122 ("PCI: Move DT resource setup into devm_pci_alloc_host_bridge()")
b411b2e1adb9 ("PCI: rcar: Use struct pci_host_bridge.windows list directly")
61f11f8250e2 ("PCI: rcar: Use devm_pci_alloc_host_bridge()")
4f5c883d7815 ("PCI: Move setting pci_host_bridge.busnr out of host drivers")
6176a5f32751 ("PCI: rcar: Use pci_is_root_bus() to check if bus is root bus")
6a589900d050 ("PCI: Set default bridge parent device")
a68e06e729b1 ("PCI: rcar: Fix runtime PM imbalance on error")
56d292348470 ("PCI: rcar: Use pci_host_probe() to register host")
78a0d7f2f5a3 ("PCI: rcar: Move shareable code to a common file")
a18f4b6ea50b ("PCI: rcar: Rename pcie-rcar.c to pcie-rcar-host.c")You could use something like:
PCI: rcar-host: Add regulator support for KingFisher
drivers/pci/controller/pcie-rcar-host.c static int rcar_pcie_probe(struct platform_device *pdev) · line 948
Quoted 2 lines
drivers/pci/controller/pcie-rcar-host.c +2
-0+ host->pcie3v3 =devm_regulator_get_optional (dev,"pcie3v3" ); +if (IS_ERR (host->pcie3v3)) {
+1 to Geert's comments. Sprinkling IS_ERR() everywhere is kind of ugly. host->pcie3v3 should be NULL if not present.
Bjorn