linux-rockchip.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: Rockchip: output proper error message for regulator error
@ 2020-11-08 12:10 Qu Wenruo
  0 siblings, 0 replies; only message in thread
From: Qu Wenruo @ 2020-11-08 12:10 UTC (permalink / raw)
  To: linux-arm-kernel, linux-rockchip; +Cc: shawn.lin, linux-kernel

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@suse.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


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-08 12:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-08 12:10 [PATCH] PCI: Rockchip: output proper error message for regulator error Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).