[PATCH v2] usb: dwc2: skip regulator operations if supplies vusb_a and vusb_d are not available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Supplies for vusb_a and vusb_d are needed only on a minority of systems
supported by the dwc2 driver (AFAIK systems with Samsung SoCs).

On all other systems this results in harmless but annoying warnings:

c9000000.usb supply vusb_d not found, using dummy regulator
c9000000.usb supply vusb_a not found, using dummy regulator

Therefore introduce an upfront check whether the supplies are available.
If they are not skip all supply regulator operations.

Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx>
---
v2:
- replace the config parameter with an upfront check whether
  the supplies are available and adjust commit message and
  patch subject accordingly
---
 drivers/usb/dwc2/core.h     |  2 ++
 drivers/usb/dwc2/platform.c | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 1a7e8300..47e32f0e 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -772,6 +772,7 @@ struct dwc2_hregs_backup {
  * @plat:               The platform specific configuration data. This can be
  *                      removed once all SoCs support usb transceiver.
  * @supplies:           Definition of USB power supplies
+ * @supplies_available: Supplies are available (optional on most chips)
  * @phyif:              PHY interface width
  * @lock:		Spinlock that protects all the driver data structures
  * @priv:		Stores a pointer to the struct usb_hcd
@@ -908,6 +909,7 @@ struct dwc2_hsotg {
 	struct usb_phy *uphy;
 	struct dwc2_hsotg_plat *plat;
 	struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
+	bool supplies_available;
 	u32 phyif;
 
 	spinlock_t lock;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 9564bc76..849f6bdb 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -125,10 +125,12 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
 	struct platform_device *pdev = to_platform_device(hsotg->dev);
 	int ret;
 
-	ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
-				    hsotg->supplies);
-	if (ret)
-		return ret;
+	if (hsotg->supplies_available) {
+		ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
+					    hsotg->supplies);
+		if (ret)
+			return ret;
+	}
 
 	if (hsotg->clk) {
 		ret = clk_prepare_enable(hsotg->clk);
@@ -185,6 +187,9 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
 	if (hsotg->clk)
 		clk_disable_unprepare(hsotg->clk);
 
+	if (!hsotg->supplies_available)
+		return 0;
+
 	ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
 				     hsotg->supplies);
 
@@ -207,6 +212,25 @@ int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
 	return ret;
 }
 
+static bool dwc2_supplies_available(struct dwc2_hsotg *hsotg)
+{
+	struct regulator *reg;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(dwc2_hsotg_supply_names); i++) {
+		reg = regulator_get_optional(hsotg->dev,
+					     dwc2_hsotg_supply_names[i]);
+		if (reg == ERR_PTR(-ENODEV)) {
+			hsotg->supplies_available = false;
+			return false;
+		}
+		regulator_put(reg);
+	}
+
+	hsotg->supplies_available = true;
+	return true;
+}
+
 static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
 {
 	int i, ret;
@@ -293,6 +317,9 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
 	for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
 		hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i];
 
+	if (!dwc2_supplies_available(hsotg))
+		return 0;
+
 	ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies),
 				      hsotg->supplies);
 	if (ret) {
-- 
2.11.0


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux