Skip to contentSkip to conversation

usb: otg: palmas-usb: fixes/cleanups to get dwc3 working

PATCH In review Kishon Vijay Abraham I 2 participants 12 messages Jan 25, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover usb: otg: palmas-usb: fixes/cleanups to get dwc3 working

This includes a series of patches that should be used for testing dwc3 in omap5.

Among other changes, palmas is made as a comparator driver to the phy. And includes a fix to get a regulator by having phandle.

This patch series is developed on
git://github.com/rrnayak/linux.git omap5-3.8-rc4-base-palmas

I've kept this patch series and the patch series to follow in a single branch
git://gitorious.org/linux-usb/linux-usb.git omap5-with-palmas (changes up to 23b4dfa2ab7052569cd88acc6383c4b1a8e8a482)

Did enumeration testing on omap5 evm.

Kishon Vijay Abraham I (8):
usb: otg: palmas-usb: make palmas-usb as a comparator driver
usb: otg: palmas-usb: use devres API to allocate resources
usb: otg: palmas-usb: remove compiler warning
usb: otg: palmas-usb: use mailbox API to send VBUS or ID events
usb: otg: palmas-usb: use bool to read property instead of u32
usb: otg: palmas-usb: call regulator enable/disable only on valid
regulator
usb: otg: palmas-usb: pass the correct dev ptr in regulator get
usb: otg: palmas-usb: fix cold plug issue

 .../devicetree/bindings/usb/twlxxxx-usb.txt        |   24 +++
 drivers/usb/otg/palmas-usb.c                       |  163 +++++++++-----------
 include/linux/mfd/palmas.h                         |    7 +-
 3 files changed, 99 insertions(+), 95 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/8 usb: otg: palmas-usb: make palmas-usb as a comparator driver

palmas-usb is made as a comparator driver to omap usb2 phy, so that omap usb can make use of palmas for srp and also to set vbus.

---
 drivers/usb/otg/palmas-usb.c |   20 ++++++++++++++++++--
 include/linux/mfd/palmas.h   |    3 +++
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/usb/otg/palmas-usb.c +18 -2
index 8389ad6..76240ef 100644
@@ -31,6 +31,8 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/usb/otg.h>
+#include <linux/usb/phy_companion.h>
+#include <linux/usb/omap_usb.h>
 #include <linux/regulator/consumer.h>
 #include <linux/err.h>
 #include <linux/notifier.h>
@@ -208,16 +210,20 @@ static void palmas_set_vbus_work(struct work_struct *data)
 		regulator_disable(palmas_usb->vbus_reg);
 }
 
-static int palmas_set_vbus(struct palmas_usb *palmas_usb, bool enabled)
+static int palmas_set_vbus(struct phy_companion *comparator, bool enabled)
 {
+	struct palmas_usb *palmas_usb = comparator_to_palmas(comparator);
+
 	palmas_usb->vbus_enable = enabled;
 	schedule_work(&palmas_usb->set_vbus_work);
 
 	return 0;
 }
 
-static int palmas_start_srp(struct palmas_usb *palmas_usb)
+static int palmas_start_srp(struct phy_companion *comparator)
 {
+	struct palmas_usb *palmas_usb = comparator_to_palmas(comparator);
+
 	palmas_usb_write(palmas_usb->palmas, PALMAS_USB_VBUS_CTRL_SET,
 			PALMAS_USB_VBUS_CTRL_SET_VBUS_DISCHRG |
 			PALMAS_USB_VBUS_CTRL_SET_VBUS_IADP_SINK);
@@ -253,6 +259,7 @@ static void palmas_dt_to_pdata(struct device_node *node,
 
 static int palmas_usb_probe(struct platform_device *pdev)
 {
+	u32 ret;
 	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
 	struct palmas_usb_platform_data	*pdata = pdev->dev.platform_data;
 	struct device_node *node = pdev->dev.of_node;
@@ -289,6 +296,15 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	palmas_usb->irq4 = regmap_irq_get_virq(palmas->irq_data,
 						PALMAS_VBUS_IRQ);
 
+	palmas_usb->comparator.set_vbus	= palmas_set_vbus;
+	palmas_usb->comparator.start_srp = palmas_start_srp;
+
+	ret = omap_usb2_set_comparator(&palmas_usb->comparator);
+	if (ret == -ENODEV) {
+		dev_info(&pdev->dev, "phy not ready, deferring probe");
+		return -EPROBE_DEFER;
+	}
+
 	palmas_usb_wakeup(palmas, pdata->wakeup);
 
 	/* init spinlock for workqueue */
include/linux/mfd/palmas.h +3 -0
index 82932db..a557db6 100644
@@ -19,6 +19,7 @@
 #include <linux/leds.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
+#include <linux/usb/phy_companion.h>
 
 #define PALMAS_NUM_CLIENTS		3
 
@@ -343,6 +344,8 @@ struct palmas_usb {
 	struct palmas *palmas;
 	struct device *dev;
 
+	struct phy_companion comparator;
+
 	/* for vbus reporting with irqs disabled */
 	spinlock_t lock;
 
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [PATCH v1 1/8] usb: otg: palmas-usb: make palmas-usb as a comparator driver

Hi,

Quoted 4 lines · Kishon Vijay Abraham I

palmas-usb is made as a comparator driver to omap usb2 phy, so that omap usb can make use of palmas for srp and also to set vbus.

doesn't apply. palmas-usb isn't in mainline

Signature · 1 line
balbi
author
#3 lore raw

Re: [PATCH v1 1/8] usb: otg: palmas-usb: make palmas-usb as a comparator driver

Quoted 10 lines · Felipe Balbi

Hi,

Quoted 4 lines · Kishon Vijay Abraham I

palmas-usb is made as a comparator driver to omap usb2 phy, so that omap usb can make use of palmas for srp and also to set vbus.

doesn't apply. palmas-usb isn't in mainline

Yes. We'll ask Rajendra Nayak to pick this up in his tree?

Thanks
Kishon

#4 lore raw

Re: [PATCH v1 1/8] usb: otg: palmas-usb: make palmas-usb as a comparator driver

Quoted 4 lines · kishon
Quoted 3 lines · Felipe Balbi

Hi,

On Fri, Jan 25, 2013 at 08:42:24AM +0530, Kishon Vijay Abraham I wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

palmas-usb is made as a comparator driver to omap usb2 phy, so that omap usb can make use of palmas for srp and also to set vbus.

doesn't apply. palmas-usb isn't in mainline

Yes. We'll ask Rajendra Nayak to pick this up in his tree?

Eventually the final version needs to go upstream, though.

Signature · 1 line
balbi
#5 lore raw

PATCH 2/8 usb: otg: palmas-usb: use devres API to allocate resources

In reply to Kishon Vijay Abraham I

used devres API while allocating resources so that these resources are released automatically on driver detach.

---
 drivers/usb/otg/palmas-usb.c |   47 ++++++++++++++----------------------------
 1 file changed, 15 insertions(+), 32 deletions(-)
drivers/usb/otg/palmas-usb.c +15 -32
index 76240ef..f063350 100644
@@ -278,7 +278,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	if (!pdata)
 		return -EINVAL;
 
-	palmas_usb = kzalloc(sizeof(*palmas_usb), GFP_KERNEL);
+	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
 	if (!palmas_usb)
 		return -ENOMEM;
 
@@ -311,11 +311,10 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	spin_lock_init(&palmas_usb->lock);
 
 	if (!pdata->no_control_vbus) {
-		palmas_usb->vbus_reg = regulator_get(palmas->dev,
+		palmas_usb->vbus_reg = devm_regulator_get(palmas->dev,
 								"vbus");
 		if (IS_ERR(palmas_usb->vbus_reg)) {
 			dev_err(&pdev->dev, "vbus init failed\n");
-			kfree(palmas_usb);
 			return PTR_ERR(palmas_usb->vbus_reg);
 		}
 	}
@@ -330,44 +329,44 @@ static int palmas_usb_probe(struct platform_device *pdev)
 
 	INIT_WORK(&palmas_usb->set_vbus_work, palmas_set_vbus_work);
 
-	status = request_threaded_irq(palmas_usb->irq1, NULL,
-				palmas_id_irq,
+	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq1,
+				NULL, palmas_id_irq,
 				IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 				"palmas_usb", palmas_usb);
 	if (status < 0) {
 		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->irq1, status);
-		goto fail_irq1;
+		goto fail_irq;
 	}
 
-	status = request_threaded_irq(palmas_usb->irq2, NULL,
-			palmas_id_wakeup_irq,
+	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq2,
+			NULL, palmas_id_wakeup_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 			"palmas_usb", palmas_usb);
 	if (status < 0) {
 		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->irq2, status);
-		goto fail_irq2;
+		goto fail_irq;
 	}
 
-	status = request_threaded_irq(palmas_usb->irq3, NULL,
-			palmas_vbus_irq,
+	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq3,
+			NULL, palmas_vbus_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 			"palmas_usb", palmas_usb);
 	if (status < 0) {
 		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->irq3, status);
-		goto fail_irq3;
+		goto fail_irq;
 	}
 
-	status = request_threaded_irq(palmas_usb->irq4, NULL,
-			palmas_vbus_wakeup_irq,
+	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq4,
+			NULL, palmas_vbus_wakeup_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 			"palmas_usb", palmas_usb);
 	if (status < 0) {
 		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->irq4, status);
-		goto fail_irq4;
+		goto fail_irq;
 	}
 
 	dev_info(&pdev->dev, "Initialized Palmas USB module\n");
@@ -376,19 +375,9 @@ static int palmas_usb_probe(struct platform_device *pdev)
 
 	return 0;
 
-fail_irq4:
-	free_irq(palmas_usb->irq3, palmas_usb);
-
-fail_irq3:
-	free_irq(palmas_usb->irq2, palmas_usb);
-
-fail_irq2:
-	free_irq(palmas_usb->irq1, palmas_usb);
-
-fail_irq1:
+fail_irq:
 	cancel_work_sync(&palmas_usb->set_vbus_work);
 	device_remove_file(palmas_usb->dev, &dev_attr_vbus);
-	kfree(palmas_usb);
 
 	return status;
 }
@@ -397,14 +386,8 @@ static int palmas_usb_remove(struct platform_device *pdev)
 {
 	struct palmas_usb *palmas_usb = platform_get_drvdata(pdev);
 
-	free_irq(palmas_usb->irq1, palmas_usb);
-	free_irq(palmas_usb->irq2, palmas_usb);
-	free_irq(palmas_usb->irq3, palmas_usb);
-	free_irq(palmas_usb->irq4, palmas_usb);
-	regulator_put(palmas_usb->vbus_reg);
 	device_remove_file(palmas_usb->dev, &dev_attr_vbus);
 	cancel_work_sync(&palmas_usb->set_vbus_work);
-	kfree(palmas_usb);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 3/8 usb: otg: palmas-usb: remove compiler warning

In reply to Kishon Vijay Abraham I

commit 696c5c04 (USB: Palmas OTG Transceiver Driver) introduced empty palmas_vbus_irq/palmas_id_irq with only *palmas_usb* declaration. Removed these unnecessary functions.

---
 drivers/usb/otg/palmas-usb.c |   38 --------------------------------------
 1 file changed, 38 deletions(-)
drivers/usb/otg/palmas-usb.c +0 -38
index f063350..be9d81c 100644
@@ -103,15 +103,6 @@ static ssize_t palmas_usb_vbus_show(struct device *dev,
 }
 static DEVICE_ATTR(vbus, 0444, palmas_usb_vbus_show, NULL);
 
-static irqreturn_t palmas_vbus_irq(int irq, void *_palmas_usb)
-{
-	struct palmas_usb *palmas_usb = _palmas_usb;
-
-	/* TODO: Do we need to do any work here? */
-
-	return IRQ_HANDLED;
-}
-
 static irqreturn_t palmas_vbus_wakeup_irq(int irq, void *_palmas_usb)
 {
 	struct palmas_usb *palmas_usb = _palmas_usb;
@@ -138,15 +129,6 @@ static irqreturn_t palmas_vbus_wakeup_irq(int irq, void *_palmas_usb)
 	return IRQ_HANDLED;
 }
 
-static irqreturn_t palmas_id_irq(int irq, void *_palmas_usb)
-{
-	struct palmas_usb *palmas_usb = _palmas_usb;
-
-	/* TODO: Do we need to do any work here? */
-
-	return IRQ_HANDLED;
-}
-
 static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 {
 	int			status = 0;
@@ -329,16 +311,6 @@ static int palmas_usb_probe(struct platform_device *pdev)
 
 	INIT_WORK(&palmas_usb->set_vbus_work, palmas_set_vbus_work);
 
-	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq1,
-				NULL, palmas_id_irq,
-				IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
-				"palmas_usb", palmas_usb);
-	if (status < 0) {
-		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
-					palmas_usb->irq1, status);
-		goto fail_irq;
-	}
-
 	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq2,
 			NULL, palmas_id_wakeup_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
@@ -349,16 +321,6 @@ static int palmas_usb_probe(struct platform_device *pdev)
 		goto fail_irq;
 	}
 
-	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq3,
-			NULL, palmas_vbus_irq,
-			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
-			"palmas_usb", palmas_usb);
-	if (status < 0) {
-		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
-					palmas_usb->irq3, status);
-		goto fail_irq;
-	}
-
 	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->irq4,
 			NULL, palmas_vbus_wakeup_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 4/8 usb: otg: palmas-usb: use mailbox API to send VBUS or ID events

In reply to Kishon Vijay Abraham I

Whenever palmas detects a VBUS or ID event, the mailbox API in dwc3 glue is called. The mailbox API takes care of notifying it to the core.

---
 drivers/usb/otg/palmas-usb.c |   32 +++++++++++++++++++++-----------
 include/linux/mfd/palmas.h   |    4 +++-
 2 files changed, 24 insertions(+), 12 deletions(-)
drivers/usb/otg/palmas-usb.c +21 -11
index be9d81c..1bd8b15 100644
@@ -33,6 +33,7 @@
 #include <linux/usb/otg.h>
 #include <linux/usb/phy_companion.h>
 #include <linux/usb/omap_usb.h>
+#include <linux/usb/dwc3-omap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/err.h>
 #include <linux/notifier.h>
@@ -85,13 +86,14 @@ static ssize_t palmas_usb_vbus_show(struct device *dev,
 	spin_lock_irqsave(&palmas_usb->lock, flags);
 
 	switch (palmas_usb->linkstat) {
-	case USB_EVENT_VBUS:
+	case OMAP_DWC3_VBUS_VALID:
 	       ret = snprintf(buf, PAGE_SIZE, "vbus\n");
 	       break;
-	case USB_EVENT_ID:
+	case OMAP_DWC3_ID_GROUND:
 	       ret = snprintf(buf, PAGE_SIZE, "id\n");
 	       break;
-	case USB_EVENT_NONE:
+	case OMAP_DWC3_ID_FLOAT:
+	case OMAP_DWC3_VBUS_OFF:
 	       ret = snprintf(buf, PAGE_SIZE, "none\n");
 	       break;
 	default:
@@ -106,7 +108,7 @@ static DEVICE_ATTR(vbus, 0444, palmas_usb_vbus_show, NULL);
 static irqreturn_t palmas_vbus_wakeup_irq(int irq, void *_palmas_usb)
 {
 	struct palmas_usb *palmas_usb = _palmas_usb;
-	int status = 0;
+	enum omap_dwc3_vbus_id_status status = OMAP_DWC3_UNKNOWN;
 	int slave;
 	unsigned int vbus_line_state, addr;
 
@@ -118,20 +120,24 @@ static irqreturn_t palmas_vbus_wakeup_irq(int irq, void *_palmas_usb)
 
 	if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
 		regulator_enable(palmas_usb->vbus_reg);
-		status = USB_EVENT_VBUS;
+		status = OMAP_DWC3_VBUS_VALID;
 	} else {
-		status = USB_EVENT_NONE;
+		status = OMAP_DWC3_VBUS_OFF;
 		regulator_disable(palmas_usb->vbus_reg);
 	}
 
 	palmas_usb->linkstat = status;
+	if (status != OMAP_DWC3_UNKNOWN) {
+		dwc3_omap_mailbox(status);
+		return IRQ_HANDLED;
+	}
 
-	return IRQ_HANDLED;
+	return IRQ_NONE;
 }
 
 static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 {
-	int			status = 0;
+	enum omap_dwc3_vbus_id_status status = OMAP_DWC3_UNKNOWN;
 	unsigned int		set;
 	struct palmas_usb	*palmas_usb = _palmas_usb;
 
@@ -145,7 +151,7 @@ static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 		palmas_usb_write(palmas_usb->palmas,
 					PALMAS_USB_ID_INT_EN_HI_CLR,
 					PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
-		status = USB_EVENT_ID;
+		status = OMAP_DWC3_ID_GROUND;
 	} else if (set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) {
 		palmas_usb_write(palmas_usb->palmas,
 					PALMAS_USB_ID_INT_EN_HI_SET,
@@ -154,12 +160,16 @@ static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 					PALMAS_USB_ID_INT_EN_HI_CLR,
 					PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
 		regulator_disable(palmas_usb->vbus_reg);
-		status = USB_EVENT_NONE;
+		status = OMAP_DWC3_ID_FLOAT;
 	}
 
 	palmas_usb->linkstat = status;
+	if (status != OMAP_DWC3_UNKNOWN) {
+		dwc3_omap_mailbox(status);
+		return IRQ_HANDLED;
+	}
 
-	return IRQ_HANDLED;
+	return IRQ_NONE;
 }
 
 static int palmas_enable_irq(struct palmas_usb *palmas_usb)
include/linux/mfd/palmas.h +3 -1
index a557db6..d6c3bec 100644
@@ -20,6 +20,8 @@
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/usb/phy_companion.h>
+#include <linux/usb/dwc3-omap.h>
+#include <linux/platform_data/dwc3-omap.h>
 
 #define PALMAS_NUM_CLIENTS		3
 
@@ -361,7 +363,7 @@ struct palmas_usb {
 
 	int vbus_enable;
 
-	u8 linkstat;
+	enum omap_dwc3_vbus_id_status linkstat;
 };
 
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 5/8 usb: otg: palmas-usb: use bool to read property instead of u32

In reply to Kishon Vijay Abraham I

properies like wakeup and no_control_vbus can be represented in boolean, so read those properties using of_property_read_bool.

Also updated the documentation with device tree binding information for palmas-usb.

---
 .../devicetree/bindings/usb/twlxxxx-usb.txt        |   24 ++++++++++++++++++++
 drivers/usb/otg/palmas-usb.c                       |   15 +++---------
 2 files changed, 27 insertions(+), 12 deletions(-)
Documentation/devicetree/bindings/usb/twlxxxx-usb.txt +24 -0
index 36b9aed..fa037ad 100644
@@ -38,3 +38,27 @@ twl4030-usb {
 	usb3v1-supply = <&vusb3v1>;
 	usb_mode = <1>;
 };
+
+PALMAS USB COMPARATOR
+Required Properties:
+ - compatible : Should be "ti,palmas-usb"
+ - interrupts : Four interrupt numbers to the cpu should be specified. First
+   interrupt number is the otg interrupt number that raises ID interrupts when
+   the controller has to act as host and the second interrupt number is the
+   ID wakeup interrupt number, third interrupt is VBUS interrupt and fourth
+   interrupt is VBUS wakeup interrupt.
+-  interrupt-name : the name corresponding to each interrupt populated in
+   interrupts property.
+ - vbus-supply : phandle to the regulator device tree node.
+
+Optional Properties:
+ - ti,wakeup : To enable the wakeup comparator in probe
+ - ti,no_control_vbus: if the platform wishes its own vbus control
+
+palmas-usb {
+	compatible = "ti,palmas-usb";
+	interrupts = <20 0>, <21 0>, <22 0>, <23 0>;
+	interrupt-names = "ID", "ID_WAKEUP", "VBUS", "VBUS_WAKEUP";
+	vbus-supply = <&smps10_reg>;
+	ti,wakeup;
+};
drivers/usb/otg/palmas-usb.c +3 -12
index 1bd8b15..2377836 100644
@@ -235,18 +235,9 @@ static int palmas_start_srp(struct phy_companion *comparator)
 static void palmas_dt_to_pdata(struct device_node *node,
 		struct palmas_usb_platform_data *pdata)
 {
-	int ret;
-	u32 prop;
-
-	ret = of_property_read_u32(node, "ti,no_control_vbus", &prop);
-	if (!ret) {
-		pdata->no_control_vbus = prop;
-	}
-
-	ret = of_property_read_u32(node, "ti,wakeup", &prop);
-	if (!ret) {
-		pdata->wakeup = prop;
-	}
+	pdata->no_control_vbus = of_property_read_bool(node,
+					"ti,no_control_vbus");
+	pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
 }
 
 static int palmas_usb_probe(struct platform_device *pdev)
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 6/8 usb: otg: palmas-usb: call regulator enable/disable only on valid regulator

In reply to Kishon Vijay Abraham I

The calls to regulator enable/disable was done unconditionally which might result in warn dumps if *no_control_vbus* is set. So always call regulator enable/disable on valid regulator.

---
 drivers/usb/otg/palmas-usb.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/usb/otg/palmas-usb.c +13 -4
index 2377836..442f09c 100644
@@ -119,11 +119,13 @@ static irqreturn_t palmas_vbus_wakeup_irq(int irq, void *_palmas_usb)
 	regmap_read(palmas_usb->palmas->regmap[slave], addr, &vbus_line_state);
 
 	if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
-		regulator_enable(palmas_usb->vbus_reg);
+		if (!IS_ERR_OR_NULL(palmas_usb->vbus_reg))
+			regulator_enable(palmas_usb->vbus_reg);
 		status = OMAP_DWC3_VBUS_VALID;
 	} else {
 		status = OMAP_DWC3_VBUS_OFF;
-		regulator_disable(palmas_usb->vbus_reg);
+		if (!IS_ERR_OR_NULL(palmas_usb->vbus_reg))
+			regulator_disable(palmas_usb->vbus_reg);
 	}
 
 	palmas_usb->linkstat = status;
@@ -144,7 +146,8 @@ static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 	palmas_usb_read(palmas_usb->palmas, PALMAS_USB_ID_INT_LATCH_SET, &set);
 
 	if (set & PALMAS_USB_ID_INT_SRC_ID_GND) {
-		regulator_enable(palmas_usb->vbus_reg);
+		if (!IS_ERR_OR_NULL(palmas_usb->vbus_reg))
+			regulator_enable(palmas_usb->vbus_reg);
 		palmas_usb_write(palmas_usb->palmas,
 					PALMAS_USB_ID_INT_EN_HI_SET,
 					PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
@@ -159,7 +162,8 @@ static irqreturn_t palmas_id_wakeup_irq(int irq, void *_palmas_usb)
 		palmas_usb_write(palmas_usb->palmas,
 					PALMAS_USB_ID_INT_EN_HI_CLR,
 					PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
-		regulator_disable(palmas_usb->vbus_reg);
+		if (!IS_ERR_OR_NULL(palmas_usb->vbus_reg))
+			regulator_disable(palmas_usb->vbus_reg);
 		status = OMAP_DWC3_ID_FLOAT;
 	}
 
@@ -191,6 +195,11 @@ static void palmas_set_vbus_work(struct work_struct *data)
 	struct palmas_usb *palmas_usb = container_of(data, struct palmas_usb,
 								set_vbus_work);
 
+	if (IS_ERR_OR_NULL(palmas_usb->vbus_reg)) {
+		dev_err(palmas_usb->dev, "invalid regulator\n");
+		return;
+	}
+
 	/*
 	 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
 	 * register. This enables boost mode.
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH 7/8 usb: otg: palmas-usb: pass the correct dev ptr in regulator get

In reply to Kishon Vijay Abraham I

regulator_get is passing the device pointer of the parent (palmas) instead of the child (palmas-usb). It's been fixed here.

---
 drivers/usb/otg/palmas-usb.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/otg/palmas-usb.c +1 -2
index 442f09c..07629cd 100644
@@ -303,8 +303,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	spin_lock_init(&palmas_usb->lock);
 
 	if (!pdata->no_control_vbus) {
-		palmas_usb->vbus_reg = devm_regulator_get(palmas->dev,
-								"vbus");
+		palmas_usb->vbus_reg = devm_regulator_get(&pdev->dev, "vbus");
 		if (IS_ERR(palmas_usb->vbus_reg)) {
 			dev_err(&pdev->dev, "vbus init failed\n");
 			return PTR_ERR(palmas_usb->vbus_reg);
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH 8/8 usb: otg: palmas-usb: fix cold plug issue

In reply to Kishon Vijay Abraham I

if the cable is connected even before the palmas-usb is loaded, the cable connect detection event will be missed. It's fixed here by checking for VBUS line states when palmas-usb is loaded.

---
 drivers/usb/otg/palmas-usb.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/otg/palmas-usb.c +5 -0
index 07629cd..d62f673 100644
@@ -187,6 +187,11 @@ static int palmas_enable_irq(struct palmas_usb *palmas_usb)
 	palmas_usb_write(palmas_usb->palmas, PALMAS_USB_ID_INT_EN_HI_SET,
 			PALMAS_USB_ID_INT_EN_HI_SET_ID_GND);
 
+	palmas_vbus_wakeup_irq(palmas_usb->irq4, palmas_usb);
+
+	if (palmas_usb->linkstat == OMAP_DWC3_UNKNOWN)
+		palmas_id_wakeup_irq(palmas_usb->irq2, palmas_usb);
+
 	return 0;
 }
 
Signature · 1 line
1.7.9.5