[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20201108121052.240909-1-wqu@suse.com>
Date: Sun, 8 Nov 2020 20:10:52 +0800
From: Qu Wenruo <wqu@...e.com>
To: linux-arm-kernel@...ts.infradead.org,
linux-rockchip@...ts.infradead.org
Cc: linux-kernel@...r.kernel.org, shawn.lin@...k-chips.com
Subject: [PATCH] PCI: Rockchip: output proper error message for regulator error
There is a regression caused by commit aea6cb99703e ("regulator: resolve
supply after creating regulator") which makes RK808 unable to register
its regulators.
This leads to vpcie1v8 and vpcie0v9 unable to be looked up, causing
rockchip pcie root controller unable to initialize.
At the same time, the dmesg shows nothing about the problem, making
debug much harder.
This patch will introduce a macro, rockchip_get_regulator(), which we
can get mandatory or optional regulator with just one line, with proper
error message when it goes wrong.
Signed-off-by: Qu Wenruo <wqu@...e.com>
---
drivers/pci/controller/pcie-rockchip-host.c | 58 ++++++++++++++-------
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 9705059523a6..981ea882ba26 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -578,6 +578,33 @@ static int rockchip_pcie_setup_irq(struct rockchip_pcie *rockchip)
return 0;
}
+#define rockchip_get_regulator(rockchip, name, optional) \
+({ \
+ struct device *dev = rockchip->dev; \
+ int ret = 0; \
+ \
+ if (optional) \
+ rockchip->name = devm_regulator_get_optional(dev, \
+ #name); \
+ else \
+ rockchip->name = devm_regulator_get(dev, #name); \
+ if (IS_ERR(rockchip->name)) { \
+ ret = PTR_ERR(rockchip->name); \
+ if (ret != -ENODEV || !optional) { \
+ dev_err(dev, "failed to get %s regulator: %d\n",\
+ #name, ret); \
+ } else if (optional) { \
+ dev_info(dev, "no %s regulator found, skip\n", \
+ #name); \
+ ret = 0; \
+ } \
+ } \
+ ret; \
+});
+
+#define OPTIONAL true
+#define MANDATORY false
+
/**
* rockchip_pcie_parse_host_dt - Parse Device Tree
* @rockchip: PCIe port information
@@ -586,7 +613,6 @@ static int rockchip_pcie_setup_irq(struct rockchip_pcie *rockchip)
*/
static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip)
{
- struct device *dev = rockchip->dev;
int err;
err = rockchip_pcie_parse_dt(rockchip);
@@ -597,29 +623,21 @@ static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip)
if (err)
return err;
- rockchip->vpcie12v = devm_regulator_get_optional(dev, "vpcie12v");
- if (IS_ERR(rockchip->vpcie12v)) {
- if (PTR_ERR(rockchip->vpcie12v) != -ENODEV)
- return PTR_ERR(rockchip->vpcie12v);
- dev_info(dev, "no vpcie12v regulator found\n");
- }
+ err = rockchip_get_regulator(rockchip, vpcie12v, OPTIONAL);
+ if (err)
+ return err;
- rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3");
- if (IS_ERR(rockchip->vpcie3v3)) {
- if (PTR_ERR(rockchip->vpcie3v3) != -ENODEV)
- return PTR_ERR(rockchip->vpcie3v3);
- dev_info(dev, "no vpcie3v3 regulator found\n");
- }
+ err = rockchip_get_regulator(rockchip, vpcie3v3, OPTIONAL);
+ if (err)
+ return err;
- rockchip->vpcie1v8 = devm_regulator_get(dev, "vpcie1v8");
- if (IS_ERR(rockchip->vpcie1v8))
- return PTR_ERR(rockchip->vpcie1v8);
+ err = rockchip_get_regulator(rockchip, vpcie1v8, MANDATORY);
+ if (err)
+ return err;
- rockchip->vpcie0v9 = devm_regulator_get(dev, "vpcie0v9");
- if (IS_ERR(rockchip->vpcie0v9))
- return PTR_ERR(rockchip->vpcie0v9);
+ err = rockchip_get_regulator(rockchip, vpcie0v9, MANDATORY);
- return 0;
+ return err;
}
static int rockchip_pcie_set_vpcie(struct rockchip_pcie *rockchip)
--
2.29.2
Powered by blists - more mailing lists