linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] twl4030: Various fixes for charing-from-USB
@ 2012-04-25  7:33 NeilBrown
  2012-04-25  7:33 ` [PATCH 1/6] twl4030_charger: Fix some typos NeilBrown
                   ` (7 more replies)
  0 siblings, 8 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap

Following are a collection of patches that I've need using for a while
to make sure the charge-from-usb on my GTA04 works.
Hopefully I've included the right people in the recipient list :-)

The issues are:
 - charge the backup battery as well as the main battery
 - charge from a charger which ties ID to ground via a resistor
 - charge while device is suspended, or when no gadget module is
   loaded (i.e. when the USB side thinks the phy should be powered
   down).

Questions and comments more welcome.

Thanks,
NeilBrown


---

NeilBrown (6):
      twl4030-usb: Don't report EVENT_ID when there is VBUS.
      twl4030-usb: Don't power down phy when it is in-use by charger.
      twl4030_charger: Allow charger to control the regulator that feeds it.
      twl4030_charger: allow charging whenever VBUS is present.
      twl4030_charger: add backup-battery charging.
      twl4030_charger: Fix some typos


 drivers/mfd/twl-core.c          |    9 ++--
 drivers/power/twl4030_charger.c |   86 +++++++++++++++++++++++++++++++++++----
 drivers/usb/otg/twl4030-usb.c   |   27 ++++++++----
 include/linux/i2c/twl.h         |    2 +
 4 files changed, 102 insertions(+), 22 deletions(-)

-- 
Signature


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 1/6] twl4030_charger: Fix some typos
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-25  7:33 ` [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present NeilBrown
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

Signed-off-by:  NeilBrown <neilb@suse.de>
---

 drivers/power/twl4030_charger.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index fdad850..3e6e991 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -103,7 +103,7 @@ static int twl4030_bci_read(u8 reg, u8 *val)
 
 static int twl4030_clear_set_boot_bci(u8 clear, u8 set)
 {
-	return twl4030_clear_set(TWL4030_MODULE_PM_MASTER, 0,
+	return twl4030_clear_set(TWL4030_MODULE_PM_MASTER, clear,
 			TWL4030_CONFIG_DONE | TWL4030_BCIAUTOWEN | set,
 			TWL4030_PM_MASTER_BOOT_BCI);
 }
@@ -151,14 +151,14 @@ static int twl4030_bci_have_vbus(struct twl4030_bci *bci)
 }
 
 /*
- * Enable/Disable USB Charge funtionality.
+ * Enable/Disable USB Charge functionality.
  */
 static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
 {
 	int ret;
 
 	if (enable) {
-		/* Check for USB charger conneted */
+		/* Check for USB charger connected */
 		if (!twl4030_bci_have_vbus(bci))
 			return -ENODEV;
 



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/6] twl4030_charger: add backup-battery charging.
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
  2012-04-25  7:33 ` [PATCH 1/6] twl4030_charger: Fix some typos NeilBrown
  2012-04-25  7:33 ` [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-25  7:33 ` [PATCH 5/6] twl4030-usb: Don't power down phy when it is in-use by charger NeilBrown
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

This allows a voltage and current (bb_uvolts and bb_uamps)
to be specified in the platform_data, and charging of the backup
battery will be enabled with those specification.

As it is not possible to monitor the backup battery at all
there is no new device created to represent it.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/power/twl4030_charger.c |   59 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/twl.h         |    2 +
 2 files changed, 61 insertions(+)

diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 3e6e991..0511610 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -28,6 +28,7 @@
 #define TWL4030_BCIVBUS		0x0c
 #define TWL4030_BCIMFSTS4	0x10
 #define TWL4030_BCICTL1		0x23
+#define TWL4030_BB_CFG		0x12
 
 #define TWL4030_BCIAUTOWEN	BIT(5)
 #define TWL4030_CONFIG_DONE	BIT(4)
@@ -37,6 +38,17 @@
 #define TWL4030_USBFASTMCHG	BIT(2)
 #define TWL4030_STS_VBUS	BIT(7)
 #define TWL4030_STS_USB_ID	BIT(2)
+#define TWL4030_BBCHEN		BIT(4)
+#define TWL4030_BBSEL_MASK	0b1100
+#define TWL4030_BBSEL_2V5	0b0000
+#define TWL4030_BBSEL_3V0	0b0100
+#define TWL4030_BBSEL_3V1	0b1000
+#define TWL4030_BBSEL_3V2	0b1100
+#define TWL4030_BBISEL_MASK	0b11
+#define TWL4030_BBISEL_25uA	0b00
+#define TWL4030_BBISEL_150uA	0b01
+#define TWL4030_BBISEL_500uA	0b10
+#define TWL4030_BBISEL_1000uA	0b11
 
 /* BCI interrupts */
 #define TWL4030_WOVF		BIT(0) /* Watchdog overflow */
@@ -202,6 +214,49 @@ static int twl4030_charger_enable_ac(bool enable)
 }
 
 /*
+ * Enable/Disable charging of Backup Battery.
+ */
+static int twl4030_charger_enable_backup(int uvolt, int uamp)
+{
+	int ret;
+	u8 flags;
+
+	if (uvolt < 2500000 ||
+	    uamp < 25) {
+		/* disable charging of backup battery */
+		ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
+					TWL4030_BBCHEN, 0, TWL4030_BB_CFG);
+		return ret;
+	}
+
+	flags = TWL4030_BBCHEN;
+	if (uvolt >= 3200000)
+		flags |= TWL4030_BBSEL_3V2;
+	else if (uvolt >= 3100000)
+		flags |= TWL4030_BBSEL_3V1;
+	else if (uvolt >= 3000000)
+		flags |= TWL4030_BBSEL_3V0;
+	else
+		flags |= TWL4030_BBSEL_2V5;
+
+	if (uamp >= 1000)
+		flags |= TWL4030_BBISEL_1000uA;
+	else if (uamp >= 500)
+		flags |= TWL4030_BBISEL_500uA;
+	else if (uamp >= 150)
+		flags |= TWL4030_BBISEL_150uA;
+	else
+		flags |= TWL4030_BBISEL_25uA;
+
+	ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
+				TWL4030_BBSEL_MASK | TWL4030_BBISEL_MASK,
+				flags,
+				TWL4030_BB_CFG);
+
+	return ret;
+}
+
+/*
  * TWL4030 CHG_PRES (AC charger presence) events
  */
 static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
@@ -424,6 +479,7 @@ static enum power_supply_property twl4030_charger_props[] = {
 static int __init twl4030_bci_probe(struct platform_device *pdev)
 {
 	struct twl4030_bci *bci;
+	struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
 	int ret;
 	u32 reg;
 
@@ -503,6 +559,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
 
 	twl4030_charger_enable_ac(true);
 	twl4030_charger_enable_usb(bci, true);
+	twl4030_charger_enable_backup(pdata->bb_uvolt,
+				      pdata->bb_uamp);
 
 	return 0;
 
@@ -531,6 +589,7 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
 
 	twl4030_charger_enable_ac(false);
 	twl4030_charger_enable_usb(bci, false);
+	twl4030_charger_enable_backup(0, 0);
 
 	/* mask interrupts */
 	twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 1f90de0..b526031 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -557,6 +557,8 @@ struct twl4030_clock_init_data {
 struct twl4030_bci_platform_data {
 	int *battery_tmp_tbl;
 	unsigned int tblsize;
+	int	bb_uvolt;	/* voltage to charge backup battery */
+	int	bb_uamp;	/* current for backup battery charging */
 };
 
 /* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present.
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
  2012-04-25  7:33 ` [PATCH 1/6] twl4030_charger: Fix some typos NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-25 11:33   ` Grazvydas Ignotas
  2012-04-25  7:33 ` [PATCH 2/6] twl4030_charger: add backup-battery charging NeilBrown
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

We currently refuse to charge if the USB ID pin is grounded, even
though VBUS might be present.
However some chargers do pull the ID pin low through a resistor which
might be as low as 47Kohm (openmoko charger).

The documentation is unclear but some experimental evidence suggests
that when the charge pump provides VBUS that doesn't get reflected in
HW_CONDITIONS, so we should be safe to ignore the ID pin.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/power/twl4030_charger.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 0511610..684662a 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -155,11 +155,7 @@ static int twl4030_bci_have_vbus(struct twl4030_bci *bci)
 
 	dev_dbg(bci->dev, "check_vbus: HW_CONDITIONS %02x\n", hwsts);
 
-	/* in case we also have STS_USB_ID, VBUS is driven by TWL itself */
-	if ((hwsts & TWL4030_STS_VBUS) && !(hwsts & TWL4030_STS_USB_ID))
-		return 1;
-
-	return 0;
+	return (hwsts & TWL4030_STS_VBUS);
 }
 
 /*



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
                   ` (3 preceding siblings ...)
  2012-04-25  7:33 ` [PATCH 5/6] twl4030-usb: Don't power down phy when it is in-use by charger NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-30 10:14   ` Tero Kristo
  2012-05-09 16:06   ` Samuel Ortiz
  2012-04-25  7:33 ` [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS NeilBrown
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

The charger needs usb3v1 to be running, so add a new consumer to
keep it running.

This allows the charger to draw current even when the USB driver has
powered down.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/mfd/twl-core.c          |    9 +++++----
 drivers/power/twl4030_charger.c |   15 +++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 7c2267e..4cbf285 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -723,8 +723,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
 		static struct regulator_consumer_supply usb1v8 = {
 			.supply =	"usb1v8",
 		};
-		static struct regulator_consumer_supply usb3v1 = {
-			.supply =	"usb3v1",
+		static struct regulator_consumer_supply usb3v1[] = {
+			{ .supply =	"usb3v1" },
+			{ .supply =	"bci3v1" },
 		};
 
 	/* First add the regulators so that they can be used by transceiver */
@@ -752,7 +753,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
 				return PTR_ERR(child);
 
 			child = add_regulator_linked(TWL4030_REG_VUSB3V1,
-						      &usb_fixed, &usb3v1, 1,
+						      &usb_fixed, usb3v1, 2,
 						      features);
 			if (IS_ERR(child))
 				return PTR_ERR(child);
@@ -773,7 +774,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
 		if (twl_has_regulator() && child) {
 			usb1v5.dev_name = dev_name(child);
 			usb1v8.dev_name = dev_name(child);
-			usb3v1.dev_name = dev_name(child);
+			usb3v1[0].dev_name = dev_name(child);
 		}
 	}
 	if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 684662a..d9d8e4a 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -21,6 +21,7 @@
 #include <linux/power_supply.h>
 #include <linux/notifier.h>
 #include <linux/usb/otg.h>
+#include <linux/regulator/machine.h>
 
 #define TWL4030_BCIMSTATEC	0x02
 #define TWL4030_BCIICHG		0x08
@@ -86,6 +87,8 @@ struct twl4030_bci {
 	struct work_struct	work;
 	int			irq_chg;
 	int			irq_bci;
+	struct regulator	*usb_reg;
+	int			usb_enabled;
 
 	unsigned long		event;
 };
@@ -179,6 +182,12 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
 			return -EACCES;
 		}
 
+		/* Need to keep regulator on */
+		if (!bci->usb_enabled) {
+			regulator_enable(bci->usb_reg);
+			bci->usb_enabled = 1;
+		}
+
 		/* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */
 		ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB);
 		if (ret < 0)
@@ -189,6 +198,10 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
 			TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4);
 	} else {
 		ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0);
+		if (bci->usb_enabled) {
+			regulator_disable(bci->usb_reg);
+			bci->usb_enabled = 0;
+		}
 	}
 
 	return ret;
@@ -507,6 +520,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
 	bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
 	bci->usb.get_property = twl4030_bci_get_property;
 
+	bci->usb_reg = regulator_get(bci->dev, "bci3v1");
+
 	ret = power_supply_register(&pdev->dev, &bci->usb);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register usb: %d\n", ret);



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 5/6] twl4030-usb: Don't power down phy when it is in-use by charger.
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
                   ` (2 preceding siblings ...)
  2012-04-25  7:33 ` [PATCH 2/6] twl4030_charger: add backup-battery charging NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-25  7:33 ` [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it NeilBrown
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

The USB phy is used both for data transfer and to charge the battery.
If the charger it active it will hold a reference to
usb3v1.  In that case we don't want to power-down the phy.

This allows charging to continue while the device is suspended.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/usb/otg/twl4030-usb.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index c4a86da..bd8fe9b 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -388,10 +388,16 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
 					(PHY_CLK_CTRL_CLOCKGATING_EN |
 						PHY_CLK_CTRL_CLK32K_EN));
 	} else {
-		__twl4030_phy_power(twl, 0);
 		regulator_disable(twl->usb1v5);
 		regulator_disable(twl->usb1v8);
 		regulator_disable(twl->usb3v1);
+		if (!regulator_is_enabled(twl->usb3v1))
+			/* no-one else is requesting this
+			 * so it is OK to power-down the
+			 * phy.  Sometimes a charger might
+			 * hold the regulator active.
+			 */
+			__twl4030_phy_power(twl, 0);
 	}
 }
 



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
                   ` (4 preceding siblings ...)
  2012-04-25  7:33 ` [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it NeilBrown
@ 2012-04-25  7:33 ` NeilBrown
  2012-04-25  8:05   ` Felipe Balbi
  2012-04-25 11:44   ` Grazvydas Ignotas
  2012-04-25 11:31 ` [PATCH 0/6] twl4030: Various fixes for charing-from-USB Grazvydas Ignotas
  2012-05-10  1:24 ` Peter Chen
  7 siblings, 2 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25  7:33 UTC (permalink / raw)
  To: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman
  Cc: linux-kernel, linux-usb, linux-omap, NeilBrown

Some USB chargers tie the ID pin low via various resistors.
So they can cause VBUS to be high and ID to be low.

The 'A' end of an OTG cable never receives VBUS, it only ever generates it.

So if we see VBUS and are not generating it, this must be a charger,
not the A end of an OTG cable, so in that case, ignore the fact that
ID is low.

This assumes that VBUS_PRES isn't asserted when the charge pump is
providing VBUS.  The document isn't clear on this and some experiments
suggest that it isn't.

Signed-off-by: NeilBrown <neilb@suse.de>
---

 drivers/usb/otg/twl4030-usb.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index bd8fe9b..990400f 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -268,15 +268,16 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
 			STS_HW_CONDITIONS);
 	if (status < 0)
 		dev_err(twl->dev, "USB link status err %d\n", status);
-	else if (status & (BIT(7) | BIT(2))) {
-		if (status & (BIT(7)))
-                        twl->vbus_supplied = true;
-
-		if (status & BIT(2))
-			linkstat = USB_EVENT_ID;
-		else
-			linkstat = USB_EVENT_VBUS;
-	} else
+	else if (status & (BIT(7))) {
+		/* We have VBUS so ignore ID_PRES - it is only meaningful
+		 * as an indicator of an A plug when there is no
+		 * VBUS.
+		 */
+		twl->vbus_supplied = true;
+		linkstat = USB_EVENT_VBUS;
+	} else if (status & BIT(2))
+		linkstat = USB_EVENT_ID;
+	else
 		linkstat = USB_EVENT_NONE;
 
 	dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
  2012-04-25  7:33 ` [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS NeilBrown
@ 2012-04-25  8:05   ` Felipe Balbi
  2012-04-25 10:29     ` NeilBrown
  2012-04-25 11:44   ` Grazvydas Ignotas
  1 sibling, 1 reply; 23+ messages in thread
From: Felipe Balbi @ 2012-04-25  8:05 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

Hi,

On Wed, Apr 25, 2012 at 05:33:11PM +1000, NeilBrown wrote:
> Some USB chargers tie the ID pin low via various resistors.
> So they can cause VBUS to be high and ID to be low.
> 
> The 'A' end of an OTG cable never receives VBUS, it only ever generates it.

this isn't entirely true. Have you considered Accessory Charger
Adapters ?

> So if we see VBUS and are not generating it, this must be a charger,
> not the A end of an OTG cable, so in that case, ignore the fact that
> ID is low.

wrong.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
  2012-04-25  8:05   ` Felipe Balbi
@ 2012-04-25 10:29     ` NeilBrown
  0 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-25 10:29 UTC (permalink / raw)
  To: balbi
  Cc: Samuel Ortiz, Grazvydas Ignotas, Greg Kroah-Hartman,
	linux-kernel, linux-usb, linux-omap

[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]

On Wed, 25 Apr 2012 11:05:27 +0300 Felipe Balbi <balbi@ti.com> wrote:

> Hi,
> 
> On Wed, Apr 25, 2012 at 05:33:11PM +1000, NeilBrown wrote:
> > Some USB chargers tie the ID pin low via various resistors.
> > So they can cause VBUS to be high and ID to be low.
> > 
> > The 'A' end of an OTG cable never receives VBUS, it only ever generates it.
> 
> this isn't entirely true. Have you considered Accessory Charger
> Adapters ?

I confess that I probably did get lost amid the maze of twisty standards -
all different.

Looking at http://en.wikipedia.org/wiki/USB_On-The-Go

it seems that a USB Accessory Charger Adapter can present 3 states including:

   A charger and a B-device are attached. The OTG device is allowed to charge
   and enter host mode.

which would mean that the TWL4030 would see that A end of an OTG cable, and
VBUS asserted.

However that appears to be selected if the ID resistance is 36.5Kohms, while
others are selected for 68Kohm and 124Kohm.
But the twl4030 cannot detect that distinction.  The cut-offs are
  Ground,  102K,  200K,  440K,  Floating

so it seems this is a standard that post-dates TWL4030.  It also seems to be
specific to OTG Micro plugs, and I have an OTG Mini plug (does TWL4030
support Micro plugs? Does it care?)

> 
> > So if we see VBUS and are not generating it, this must be a charger,
> > not the A end of an OTG cable, so in that case, ignore the fact that
> > ID is low.
> 
> wrong.
> 

That may well be.  However we need some way to tell twl4030_charger.c
either USB_EVENT_VBUS or USB_EVENT_CHARGER when a charger is plugged in.
I guess we could just punt to user-space: provide all the measurements
through sysfs and allow user-space to enable the charger and select the
desired current?

Or should this just go in the too-hard basket for now?


Thanks,
NeilBrown


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
                   ` (5 preceding siblings ...)
  2012-04-25  7:33 ` [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS NeilBrown
@ 2012-04-25 11:31 ` Grazvydas Ignotas
  2012-04-29 23:30   ` NeilBrown
  2012-05-10  1:24 ` Peter Chen
  7 siblings, 1 reply; 23+ messages in thread
From: Grazvydas Ignotas @ 2012-04-25 11:31 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Greg Kroah-Hartman, linux-kernel,
	linux-usb, linux-omap, Anton Vorontsov

On Wed, Apr 25, 2012 at 10:33 AM, NeilBrown <neilb@suse.de> wrote:
> Following are a collection of patches that I've need using for a while
> to make sure the charge-from-usb on my GTA04 works.
> Hopefully I've included the right people in the recipient list :-)

You missed the power supply maintainers - ./scripts/get_maintainer.pl
is usually good at finding the right people, although their
MAINTAINERS entry could be better I guess..


-- 
Gražvydas

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present.
  2012-04-25  7:33 ` [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present NeilBrown
@ 2012-04-25 11:33   ` Grazvydas Ignotas
  2012-04-29 23:34     ` NeilBrown
  0 siblings, 1 reply; 23+ messages in thread
From: Grazvydas Ignotas @ 2012-04-25 11:33 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Greg Kroah-Hartman, linux-kernel,
	linux-usb, linux-omap

On Wed, Apr 25, 2012 at 10:33 AM, NeilBrown <neilb@suse.de> wrote:
> We currently refuse to charge if the USB ID pin is grounded, even
> though VBUS might be present.
> However some chargers do pull the ID pin low through a resistor which
> might be as low as 47Kohm (openmoko charger).
>
> The documentation is unclear but some experimental evidence suggests
> that when the charge pump provides VBUS that doesn't get reflected in
> HW_CONDITIONS, so we should be safe to ignore the ID pin.

On pandora I see the opposite, STS_VBUS is set regardless of who
drives it, so this will break pandora..

>
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
>
>  drivers/power/twl4030_charger.c |    6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
> index 0511610..684662a 100644
> --- a/drivers/power/twl4030_charger.c
> +++ b/drivers/power/twl4030_charger.c
> @@ -155,11 +155,7 @@ static int twl4030_bci_have_vbus(struct twl4030_bci *bci)
>
>        dev_dbg(bci->dev, "check_vbus: HW_CONDITIONS %02x\n", hwsts);
>
> -       /* in case we also have STS_USB_ID, VBUS is driven by TWL itself */
> -       if ((hwsts & TWL4030_STS_VBUS) && !(hwsts & TWL4030_STS_USB_ID))
> -               return 1;
> -
> -       return 0;
> +       return (hwsts & TWL4030_STS_VBUS);
>  }
>
>  /*
>
>


-- 
Gražvydas

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
  2012-04-25  7:33 ` [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS NeilBrown
  2012-04-25  8:05   ` Felipe Balbi
@ 2012-04-25 11:44   ` Grazvydas Ignotas
  1 sibling, 0 replies; 23+ messages in thread
From: Grazvydas Ignotas @ 2012-04-25 11:44 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Greg Kroah-Hartman, linux-kernel,
	linux-usb, linux-omap

On Wed, Apr 25, 2012 at 10:33 AM, NeilBrown <neilb@suse.de> wrote:
> Some USB chargers tie the ID pin low via various resistors.
> So they can cause VBUS to be high and ID to be low.
>
> The 'A' end of an OTG cable never receives VBUS, it only ever generates it.
>
> So if we see VBUS and are not generating it, this must be a charger,
> not the A end of an OTG cable, so in that case, ignore the fact that
> ID is low.
>
> This assumes that VBUS_PRES isn't asserted when the charge pump is
> providing VBUS.  The document isn't clear on this and some experiments
> suggest that it isn't.

Like already mentioned, this is not what I see on pandora. I don't
know, maybe it's due to some errata or different versions of TWL chip
act different, or perhaps even board design issue, but that's how it
is here.

If you look at git history, this has been changed back and forth
several times, like in commit def6f8b9. Perhaps some platform_data
could be added to handle this, I don't know..

>
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
>
>  drivers/usb/otg/twl4030-usb.c |   19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
> index bd8fe9b..990400f 100644
> --- a/drivers/usb/otg/twl4030-usb.c
> +++ b/drivers/usb/otg/twl4030-usb.c
> @@ -268,15 +268,16 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
>                        STS_HW_CONDITIONS);
>        if (status < 0)
>                dev_err(twl->dev, "USB link status err %d\n", status);
> -       else if (status & (BIT(7) | BIT(2))) {
> -               if (status & (BIT(7)))
> -                        twl->vbus_supplied = true;
> -
> -               if (status & BIT(2))
> -                       linkstat = USB_EVENT_ID;
> -               else
> -                       linkstat = USB_EVENT_VBUS;
> -       } else
> +       else if (status & (BIT(7))) {
> +               /* We have VBUS so ignore ID_PRES - it is only meaningful
> +                * as an indicator of an A plug when there is no
> +                * VBUS.
> +                */
> +               twl->vbus_supplied = true;
> +               linkstat = USB_EVENT_VBUS;
> +       } else if (status & BIT(2))
> +               linkstat = USB_EVENT_ID;
> +       else
>                linkstat = USB_EVENT_NONE;
>
>        dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
>
>

-- 
Gražvydas

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-04-25 11:31 ` [PATCH 0/6] twl4030: Various fixes for charing-from-USB Grazvydas Ignotas
@ 2012-04-29 23:30   ` NeilBrown
  2012-05-05 10:49     ` Anton Vorontsov
  0 siblings, 1 reply; 23+ messages in thread
From: NeilBrown @ 2012-04-29 23:30 UTC (permalink / raw)
  To: Grazvydas Ignotas
  Cc: Samuel Ortiz, Felipe Balbi, Greg Kroah-Hartman, linux-kernel,
	linux-usb, linux-omap, Anton Vorontsov

[-- Attachment #1: Type: text/plain, Size: 994 bytes --]

On Wed, 25 Apr 2012 14:31:13 +0300 Grazvydas Ignotas <notasas@gmail.com>
wrote:

> On Wed, Apr 25, 2012 at 10:33 AM, NeilBrown <neilb@suse.de> wrote:
> > Following are a collection of patches that I've need using for a while
> > to make sure the charge-from-usb on my GTA04 works.
> > Hopefully I've included the right people in the recipient list :-)
> 
> You missed the power supply maintainers - ./scripts/get_maintainer.pl
> is usually good at finding the right people, although their
> MAINTAINERS entry could be better I guess..
> 
> 

I guess you mean:

POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
M:	Anton Vorontsov <cbou@mail.ru>
M:	David Woodhouse <dwmw2@infradead.org>
T:	git git://git.infradead.org/battery-2.6.git
S:	Maintained
F:	include/linux/power_supply.h
F:	drivers/power/power_supply*


get_maintainer.pl didn't find them.  The F: line seems to say they aren't
interested in individual drivers...

I'll include them if I resend.
Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present.
  2012-04-25 11:33   ` Grazvydas Ignotas
@ 2012-04-29 23:34     ` NeilBrown
  0 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-04-29 23:34 UTC (permalink / raw)
  To: Grazvydas Ignotas
  Cc: Samuel Ortiz, Felipe Balbi, Greg Kroah-Hartman, linux-kernel,
	linux-usb, linux-omap

[-- Attachment #1: Type: text/plain, Size: 1804 bytes --]

On Wed, 25 Apr 2012 14:33:25 +0300 Grazvydas Ignotas <notasas@gmail.com>
wrote:

> On Wed, Apr 25, 2012 at 10:33 AM, NeilBrown <neilb@suse.de> wrote:
> > We currently refuse to charge if the USB ID pin is grounded, even
> > though VBUS might be present.
> > However some chargers do pull the ID pin low through a resistor which
> > might be as low as 47Kohm (openmoko charger).
> >
> > The documentation is unclear but some experimental evidence suggests
> > that when the charge pump provides VBUS that doesn't get reflected in
> > HW_CONDITIONS, so we should be safe to ignore the ID pin.
> 
> On pandora I see the opposite, STS_VBUS is set regardless of who
> drives it, so this will break pandora..

OK... I guess this needs more thought.
I'll withdraw this patch and 6/6 for now.
The rest should be good to go.  Maybe I'll resend them an include Anton
Vorontsov..

Thanks,
NeilBrown

> 
> >
> > Signed-off-by: NeilBrown <neilb@suse.de>
> > ---
> >
> >  drivers/power/twl4030_charger.c |    6 +-----
> >  1 file changed, 1 insertion(+), 5 deletions(-)
> >
> > diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
> > index 0511610..684662a 100644
> > --- a/drivers/power/twl4030_charger.c
> > +++ b/drivers/power/twl4030_charger.c
> > @@ -155,11 +155,7 @@ static int twl4030_bci_have_vbus(struct twl4030_bci *bci)
> >
> >        dev_dbg(bci->dev, "check_vbus: HW_CONDITIONS %02x\n", hwsts);
> >
> > -       /* in case we also have STS_USB_ID, VBUS is driven by TWL itself */
> > -       if ((hwsts & TWL4030_STS_VBUS) && !(hwsts & TWL4030_STS_USB_ID))
> > -               return 1;
> > -
> > -       return 0;
> > +       return (hwsts & TWL4030_STS_VBUS);
> >  }
> >
> >  /*
> >
> >
> 
> 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
  2012-04-25  7:33 ` [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it NeilBrown
@ 2012-04-30 10:14   ` Tero Kristo
  2012-05-01  1:01     ` NeilBrown
  2012-05-09 16:06   ` Samuel Ortiz
  1 sibling, 1 reply; 23+ messages in thread
From: Tero Kristo @ 2012-04-30 10:14 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

Hi Neil,

As I am supposed to be acting as a maintainer for the drivers/mfd/twl-*,
you can add an ack from me for the twl-core.c part. It looks kind of
okay, even if I would eventually like to remove/fix the ugly regulator
init from twl-core.

Just a question, who is going to merge all this seeing it is touching
stuff all over the place?

-Tero


On Wed, 2012-04-25 at 17:33 +1000, NeilBrown wrote:
> The charger needs usb3v1 to be running, so add a new consumer to
> keep it running.
> 
> This allows the charger to draw current even when the USB driver has
> powered down.
> 
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
> 
>  drivers/mfd/twl-core.c          |    9 +++++----
>  drivers/power/twl4030_charger.c |   15 +++++++++++++++
>  2 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
> index 7c2267e..4cbf285 100644
> --- a/drivers/mfd/twl-core.c
> +++ b/drivers/mfd/twl-core.c
> @@ -723,8 +723,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
>  		static struct regulator_consumer_supply usb1v8 = {
>  			.supply =	"usb1v8",
>  		};
> -		static struct regulator_consumer_supply usb3v1 = {
> -			.supply =	"usb3v1",
> +		static struct regulator_consumer_supply usb3v1[] = {
> +			{ .supply =	"usb3v1" },
> +			{ .supply =	"bci3v1" },
>  		};
>  
>  	/* First add the regulators so that they can be used by transceiver */
> @@ -752,7 +753,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
>  				return PTR_ERR(child);
>  
>  			child = add_regulator_linked(TWL4030_REG_VUSB3V1,
> -						      &usb_fixed, &usb3v1, 1,
> +						      &usb_fixed, usb3v1, 2,
>  						      features);
>  			if (IS_ERR(child))
>  				return PTR_ERR(child);
> @@ -773,7 +774,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
>  		if (twl_has_regulator() && child) {
>  			usb1v5.dev_name = dev_name(child);
>  			usb1v8.dev_name = dev_name(child);
> -			usb3v1.dev_name = dev_name(child);
> +			usb3v1[0].dev_name = dev_name(child);
>  		}
>  	}
>  	if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
> diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
> index 684662a..d9d8e4a 100644
> --- a/drivers/power/twl4030_charger.c
> +++ b/drivers/power/twl4030_charger.c
> @@ -21,6 +21,7 @@
>  #include <linux/power_supply.h>
>  #include <linux/notifier.h>
>  #include <linux/usb/otg.h>
> +#include <linux/regulator/machine.h>
>  
>  #define TWL4030_BCIMSTATEC	0x02
>  #define TWL4030_BCIICHG		0x08
> @@ -86,6 +87,8 @@ struct twl4030_bci {
>  	struct work_struct	work;
>  	int			irq_chg;
>  	int			irq_bci;
> +	struct regulator	*usb_reg;
> +	int			usb_enabled;
>  
>  	unsigned long		event;
>  };
> @@ -179,6 +182,12 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
>  			return -EACCES;
>  		}
>  
> +		/* Need to keep regulator on */
> +		if (!bci->usb_enabled) {
> +			regulator_enable(bci->usb_reg);
> +			bci->usb_enabled = 1;
> +		}
> +
>  		/* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */
>  		ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB);
>  		if (ret < 0)
> @@ -189,6 +198,10 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
>  			TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4);
>  	} else {
>  		ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0);
> +		if (bci->usb_enabled) {
> +			regulator_disable(bci->usb_reg);
> +			bci->usb_enabled = 0;
> +		}
>  	}
>  
>  	return ret;
> @@ -507,6 +520,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
>  	bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
>  	bci->usb.get_property = twl4030_bci_get_property;
>  
> +	bci->usb_reg = regulator_get(bci->dev, "bci3v1");
> +
>  	ret = power_supply_register(&pdev->dev, &bci->usb);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to register usb: %d\n", ret);
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
  2012-04-30 10:14   ` Tero Kristo
@ 2012-05-01  1:01     ` NeilBrown
  0 siblings, 0 replies; 23+ messages in thread
From: NeilBrown @ 2012-05-01  1:01 UTC (permalink / raw)
  To: t-kristo
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

[-- Attachment #1: Type: text/plain, Size: 4807 bytes --]

On Mon, 30 Apr 2012 13:14:32 +0300 Tero Kristo <t-kristo@ti.com> wrote:

> Hi Neil,
> 
> As I am supposed to be acting as a maintainer for the drivers/mfd/twl-*,
> you can add an ack from me for the twl-core.c part. It looks kind of
> okay, even if I would eventually like to remove/fix the ugly regulator
> init from twl-core.

Thanks.

> 
> Just a question, who is going to merge all this seeing it is touching
> stuff all over the place?

Good question.  I'll try Anton Vorontsov as he seems to handle drivers/power/
stuff.  Maybe with your ack he will take it.  Otherwise apkm seems to be the
default if no-one else cares :-)

Thanks,
NeilBrown


> 
> -Tero
> 
> 
> On Wed, 2012-04-25 at 17:33 +1000, NeilBrown wrote:
> > The charger needs usb3v1 to be running, so add a new consumer to
> > keep it running.
> > 
> > This allows the charger to draw current even when the USB driver has
> > powered down.
> > 
> > Signed-off-by: NeilBrown <neilb@suse.de>
> > ---
> > 
> >  drivers/mfd/twl-core.c          |    9 +++++----
> >  drivers/power/twl4030_charger.c |   15 +++++++++++++++
> >  2 files changed, 20 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
> > index 7c2267e..4cbf285 100644
> > --- a/drivers/mfd/twl-core.c
> > +++ b/drivers/mfd/twl-core.c
> > @@ -723,8 +723,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
> >  		static struct regulator_consumer_supply usb1v8 = {
> >  			.supply =	"usb1v8",
> >  		};
> > -		static struct regulator_consumer_supply usb3v1 = {
> > -			.supply =	"usb3v1",
> > +		static struct regulator_consumer_supply usb3v1[] = {
> > +			{ .supply =	"usb3v1" },
> > +			{ .supply =	"bci3v1" },
> >  		};
> >  
> >  	/* First add the regulators so that they can be used by transceiver */
> > @@ -752,7 +753,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
> >  				return PTR_ERR(child);
> >  
> >  			child = add_regulator_linked(TWL4030_REG_VUSB3V1,
> > -						      &usb_fixed, &usb3v1, 1,
> > +						      &usb_fixed, usb3v1, 2,
> >  						      features);
> >  			if (IS_ERR(child))
> >  				return PTR_ERR(child);
> > @@ -773,7 +774,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
> >  		if (twl_has_regulator() && child) {
> >  			usb1v5.dev_name = dev_name(child);
> >  			usb1v8.dev_name = dev_name(child);
> > -			usb3v1.dev_name = dev_name(child);
> > +			usb3v1[0].dev_name = dev_name(child);
> >  		}
> >  	}
> >  	if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
> > diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
> > index 684662a..d9d8e4a 100644
> > --- a/drivers/power/twl4030_charger.c
> > +++ b/drivers/power/twl4030_charger.c
> > @@ -21,6 +21,7 @@
> >  #include <linux/power_supply.h>
> >  #include <linux/notifier.h>
> >  #include <linux/usb/otg.h>
> > +#include <linux/regulator/machine.h>
> >  
> >  #define TWL4030_BCIMSTATEC	0x02
> >  #define TWL4030_BCIICHG		0x08
> > @@ -86,6 +87,8 @@ struct twl4030_bci {
> >  	struct work_struct	work;
> >  	int			irq_chg;
> >  	int			irq_bci;
> > +	struct regulator	*usb_reg;
> > +	int			usb_enabled;
> >  
> >  	unsigned long		event;
> >  };
> > @@ -179,6 +182,12 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
> >  			return -EACCES;
> >  		}
> >  
> > +		/* Need to keep regulator on */
> > +		if (!bci->usb_enabled) {
> > +			regulator_enable(bci->usb_reg);
> > +			bci->usb_enabled = 1;
> > +		}
> > +
> >  		/* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */
> >  		ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB);
> >  		if (ret < 0)
> > @@ -189,6 +198,10 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
> >  			TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4);
> >  	} else {
> >  		ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0);
> > +		if (bci->usb_enabled) {
> > +			regulator_disable(bci->usb_reg);
> > +			bci->usb_enabled = 0;
> > +		}
> >  	}
> >  
> >  	return ret;
> > @@ -507,6 +520,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
> >  	bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
> >  	bci->usb.get_property = twl4030_bci_get_property;
> >  
> > +	bci->usb_reg = regulator_get(bci->dev, "bci3v1");
> > +
> >  	ret = power_supply_register(&pdev->dev, &bci->usb);
> >  	if (ret) {
> >  		dev_err(&pdev->dev, "failed to register usb: %d\n", ret);
> > 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-04-29 23:30   ` NeilBrown
@ 2012-05-05 10:49     ` Anton Vorontsov
  2012-05-05 10:52       ` Anton Vorontsov
  0 siblings, 1 reply; 23+ messages in thread
From: Anton Vorontsov @ 2012-05-05 10:49 UTC (permalink / raw)
  To: NeilBrown
  Cc: Grazvydas Ignotas, Samuel Ortiz, Felipe Balbi,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

On Mon, Apr 30, 2012 at 09:30:02AM +1000, NeilBrown wrote:
> > > Following are a collection of patches that I've need using for a while
> > > to make sure the charge-from-usb on my GTA04 works.
> > > Hopefully I've included the right people in the recipient list :-)
> > 
> > You missed the power supply maintainers - ./scripts/get_maintainer.pl
> > is usually good at finding the right people, although their
> > MAINTAINERS entry could be better I guess..
> > 
> > 
> 
> I guess you mean:
> 
> POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
> M:	Anton Vorontsov <cbou@mail.ru>
> M:	David Woodhouse <dwmw2@infradead.org>
> T:	git git://git.infradead.org/battery-2.6.git
> S:	Maintained
> F:	include/linux/power_supply.h
> F:	drivers/power/power_supply*
> 
> 
> get_maintainer.pl didn't find them.  The F: line seems to say they aren't
> interested in individual drivers...

This is a 'bug', of course. :-) Thanks for the report.

This is what I've just applied:

- - - -
MAINTAINERS: Fix 'F' entry for the power supply class

For some reason the maintainers file only specifies power
supply core files.

We're surely interested in individual drivers as well, so fix
the entry.

Reported-by: NeilBrown <neilb@suse.de>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
 MAINTAINERS |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index bb76fc4..3766f6a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5290,7 +5290,7 @@ M:	David Woodhouse <dwmw2@infradead.org>
 T:	git git://git.infradead.org/battery-2.6.git
 S:	Maintained
 F:	include/linux/power_supply.h
-F:	drivers/power/power_supply*
+F:	drivers/power/
 
 PNP SUPPORT
 M:	Adam Belay <abelay@mit.edu>
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-05-05 10:49     ` Anton Vorontsov
@ 2012-05-05 10:52       ` Anton Vorontsov
  0 siblings, 0 replies; 23+ messages in thread
From: Anton Vorontsov @ 2012-05-05 10:52 UTC (permalink / raw)
  To: NeilBrown
  Cc: Grazvydas Ignotas, Samuel Ortiz, Felipe Balbi,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

On Sat, May 05, 2012 at 03:49:10AM -0700, Anton Vorontsov wrote:
> On Mon, Apr 30, 2012 at 09:30:02AM +1000, NeilBrown wrote:
> > > > Following are a collection of patches that I've need using for a while
> > > > to make sure the charge-from-usb on my GTA04 works.
> > > > Hopefully I've included the right people in the recipient list :-)
> > > 
> > > You missed the power supply maintainers - ./scripts/get_maintainer.pl
> > > is usually good at finding the right people, although their
> > > MAINTAINERS entry could be better I guess..
> > > 
> > > 
> > 
> > I guess you mean:
> > 
> > POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
> > M:	Anton Vorontsov <cbou@mail.ru>
> > M:	David Woodhouse <dwmw2@infradead.org>
> > T:	git git://git.infradead.org/battery-2.6.git
> > S:	Maintained
> > F:	include/linux/power_supply.h
> > F:	drivers/power/power_supply*
> > 
> > 
> > get_maintainer.pl didn't find them.  The F: line seems to say they aren't
> > interested in individual drivers...
> 
> This is a 'bug', of course. :-) Thanks for the report.
> 
> This is what I've just applied:
> 
> - - - -
> MAINTAINERS: Fix 'F' entry for the power supply class
> 
> For some reason the maintainers file only specifies power
> supply core files.
> 
> We're surely interested in individual drivers as well, so fix
> the entry.
> 
> Reported-by: NeilBrown <neilb@suse.de>

Oh, Grazvydas Ignotas noticed this too. I added
Reported-by: Grazvydas Ignotas <notasas@gmail.com> as well.
Just to be precise. ;-)

Thanks folks,

-- 
Anton Vorontsov
Email: cbouatmailru@gmail.com

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
  2012-04-25  7:33 ` [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it NeilBrown
  2012-04-30 10:14   ` Tero Kristo
@ 2012-05-09 16:06   ` Samuel Ortiz
  1 sibling, 0 replies; 23+ messages in thread
From: Samuel Ortiz @ 2012-05-09 16:06 UTC (permalink / raw)
  To: NeilBrown
  Cc: Felipe Balbi, Grazvydas Ignotas, Greg Kroah-Hartman,
	linux-kernel, linux-usb, linux-omap

Hi Neil,

On Wed, Apr 25, 2012 at 05:33:11PM +1000, NeilBrown wrote:
> The charger needs usb3v1 to be running, so add a new consumer to
> keep it running.
> 
> This allows the charger to draw current even when the USB driver has
> powered down.
> 
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
> 
>  drivers/mfd/twl-core.c          |    9 +++++----
>  drivers/power/twl4030_charger.c |   15 +++++++++++++++
>  2 files changed, 20 insertions(+), 4 deletions(-)
In case Anton has not taken that patchset yet:

Acked-by: Samuel Ortiz <sameo@linux.intel.com>

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
                   ` (6 preceding siblings ...)
  2012-04-25 11:31 ` [PATCH 0/6] twl4030: Various fixes for charing-from-USB Grazvydas Ignotas
@ 2012-05-10  1:24 ` Peter Chen
  2012-05-10  2:37   ` NeilBrown
  7 siblings, 1 reply; 23+ messages in thread
From: Peter Chen @ 2012-05-10  1:24 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

On Wed, Apr 25, 2012 at 05:33:10PM +1000, NeilBrown wrote:
> Following are a collection of patches that I've need using for a while
> to make sure the charge-from-usb on my GTA04 works.
> Hopefully I've included the right people in the recipient list :-)
> 
> The issues are:
>  - charge the backup battery as well as the main battery
>  - charge from a charger which ties ID to ground via a resistor
>  - charge while device is suspended, or when no gadget module is
>    loaded (i.e. when the USB side thinks the phy should be powered
>    down).
According to USB Spec, when the USB bus goes to suspend, the device
should not draw more than 2.5mA. So when the device is suspended,
it should notify the battery driver do NOT charge any more.
> 
> Questions and comments more welcome.
> 
> Thanks,
> NeilBrown
> 
> 
> ---
> 
> NeilBrown (6):
>       twl4030-usb: Don't report EVENT_ID when there is VBUS.
>       twl4030-usb: Don't power down phy when it is in-use by charger.
>       twl4030_charger: Allow charger to control the regulator that feeds it.
>       twl4030_charger: allow charging whenever VBUS is present.
>       twl4030_charger: add backup-battery charging.
>       twl4030_charger: Fix some typos
> 
> 
>  drivers/mfd/twl-core.c          |    9 ++--
>  drivers/power/twl4030_charger.c |   86 +++++++++++++++++++++++++++++++++++----
>  drivers/usb/otg/twl4030-usb.c   |   27 ++++++++----
>  include/linux/i2c/twl.h         |    2 +
>  4 files changed, 102 insertions(+), 22 deletions(-)
> 
> -- 
> Signature
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

-- 

Best Regards,
Peter Chen


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-05-10  1:24 ` Peter Chen
@ 2012-05-10  2:37   ` NeilBrown
  2012-05-10  6:46     ` Chen Peter-B29397
  2012-05-10 14:45     ` Alan Stern
  0 siblings, 2 replies; 23+ messages in thread
From: NeilBrown @ 2012-05-10  2:37 UTC (permalink / raw)
  To: Peter Chen
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

[-- Attachment #1: Type: text/plain, Size: 2929 bytes --]

On Thu, 10 May 2012 09:24:23 +0800 Peter Chen <peter.chen@freescale.com>
wrote:

> On Wed, Apr 25, 2012 at 05:33:10PM +1000, NeilBrown wrote:
> > Following are a collection of patches that I've need using for a while
> > to make sure the charge-from-usb on my GTA04 works.
> > Hopefully I've included the right people in the recipient list :-)
> > 
> > The issues are:
> >  - charge the backup battery as well as the main battery
> >  - charge from a charger which ties ID to ground via a resistor
> >  - charge while device is suspended, or when no gadget module is
> >    loaded (i.e. when the USB side thinks the phy should be powered
> >    down).
> According to USB Spec, when the USB bus goes to suspend, the device
> should not draw more than 2.5mA. So when the device is suspended,
> it should notify the battery driver do NOT charge any more.

Hi Peter,
 thanks for your input.

 Would you be able to help me understand exactly what it means for the USB
 bus to go to suspend?  Is this something that the host initiates or
 something that the gadget initiates?
 How does this relate to a simple charger?  It that considered to have a
 non-suspended bus, or is it considered as a separate case?

 Maybe we need to not suspend the USB OTG interface when the device as a
 whole enters suspend-to-RAM.  Maybe we need to register a dummy gadget to
 the bus active while in suspend?
 Does the gadget have to be responsive while-ever the bus is not suspended?
 Maybe we can arrange for any USB activity to trigger a resume?

 Entering suspend while still charging really should be possible - at least
 with a dump charger and hopefully from a host port as well.  I'll like to
 find the best way to achieve that, and any help you can provide would be
 greatly appreciated.

Thanks,
NeilBrown


> > 
> > Questions and comments more welcome.
> > 
> > Thanks,
> > NeilBrown
> > 
> > 
> > ---
> > 
> > NeilBrown (6):
> >       twl4030-usb: Don't report EVENT_ID when there is VBUS.
> >       twl4030-usb: Don't power down phy when it is in-use by charger.
> >       twl4030_charger: Allow charger to control the regulator that feeds it.
> >       twl4030_charger: allow charging whenever VBUS is present.
> >       twl4030_charger: add backup-battery charging.
> >       twl4030_charger: Fix some typos
> > 
> > 
> >  drivers/mfd/twl-core.c          |    9 ++--
> >  drivers/power/twl4030_charger.c |   86 +++++++++++++++++++++++++++++++++++----
> >  drivers/usb/otg/twl4030-usb.c   |   27 ++++++++----
> >  include/linux/i2c/twl.h         |    2 +
> >  4 files changed, 102 insertions(+), 22 deletions(-)
> > 
> > -- 
> > Signature
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* RE: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-05-10  2:37   ` NeilBrown
@ 2012-05-10  6:46     ` Chen Peter-B29397
  2012-05-10 14:45     ` Alan Stern
  1 sibling, 0 replies; 23+ messages in thread
From: Chen Peter-B29397 @ 2012-05-10  6:46 UTC (permalink / raw)
  To: NeilBrown
  Cc: Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

 
> 
>  Would you be able to help me understand exactly what it means for the
> USB
>  bus to go to suspend?  Is this something that the host initiates or
>  something that the gadget initiates?
Host initiates it, when host wants to suspend the whole bus or certain port,
it will stop sending SOF, after 3ms of that, the device will pullup dp.
After that, the bus is at suspend state (dp=3, dm=0).

Please see:
http://www.amebasystems.com/downloads/hardware/datasheets/USB/
usb_20_052709/Suspend%20Current%20ECN.pdf

>  How does this relate to a simple charger?  It that considered to have a
>  non-suspended bus, or is it considered as a separate case?
> 
You may need a USB Charger driver which can differentiate dedicated charger (DCP),
host charger (CDP), or pc host port(SDP).
Only at SDP case, you need to consider suspend current limiation. 

>  Maybe we need to not suspend the USB OTG interface when the device as a
>  whole enters suspend-to-RAM.  Maybe we need to register a dummy gadget
> to
>  the bus active while in suspend?
>  Does the gadget have to be responsive while-ever the bus is not
> suspended?
>  Maybe we can arrange for any USB activity to trigger a resume?
> 
>  Entering suspend while still charging really should be possible - at
> least
>  with a dump charger and hopefully from a host port as well.  I'll like
> to
>  find the best way to achieve that, and any help you can provide would be
>  greatly appreciated.
> 
The host may not limit charge current when the vbus is on, but the device should
not draw much current when the host is suspended. Consider below case:

There is a Media Player connecting at laptop (without connecting wall power), 
the laptop may suspend sometime later(vbus is still on), the Media Player may
go on working and continue drawing hundreds of mA from the host. Some hours
later, the capacity of laptop will be exhausted which is not expected. 
 



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 0/6] twl4030: Various fixes for charing-from-USB
  2012-05-10  2:37   ` NeilBrown
  2012-05-10  6:46     ` Chen Peter-B29397
@ 2012-05-10 14:45     ` Alan Stern
  1 sibling, 0 replies; 23+ messages in thread
From: Alan Stern @ 2012-05-10 14:45 UTC (permalink / raw)
  To: NeilBrown
  Cc: Peter Chen, Samuel Ortiz, Felipe Balbi, Grazvydas Ignotas,
	Greg Kroah-Hartman, linux-kernel, linux-usb, linux-omap

On Thu, 10 May 2012, NeilBrown wrote:

>  Maybe we need to not suspend the USB OTG interface when the device as a
>  whole enters suspend-to-RAM.  Maybe we need to register a dummy gadget to
>  the bus active while in suspend?
>  Does the gadget have to be responsive while-ever the bus is not suspended?

Yes.

>  Maybe we can arrange for any USB activity to trigger a resume?

Probably not, at least, not fast enough.  The gadget is required to 
respond to USB packets within a few microseconds.  At a minimum, the 
USB device controller would have to remain fully powered.

>  Entering suspend while still charging really should be possible - at least
>  with a dump charger and hopefully from a host port as well.  I'll like to
>  find the best way to achieve that, and any help you can provide would be
>  greatly appreciated.

If the gadget is attached to a dumb charger rather than a host then 
there's no problem.  But otherwise it's not so simple.

Have you read the USB charger class specification?  (I haven't...)

Alan Stern


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2012-05-10 14:45 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25  7:33 [PATCH 0/6] twl4030: Various fixes for charing-from-USB NeilBrown
2012-04-25  7:33 ` [PATCH 1/6] twl4030_charger: Fix some typos NeilBrown
2012-04-25  7:33 ` [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present NeilBrown
2012-04-25 11:33   ` Grazvydas Ignotas
2012-04-29 23:34     ` NeilBrown
2012-04-25  7:33 ` [PATCH 2/6] twl4030_charger: add backup-battery charging NeilBrown
2012-04-25  7:33 ` [PATCH 5/6] twl4030-usb: Don't power down phy when it is in-use by charger NeilBrown
2012-04-25  7:33 ` [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it NeilBrown
2012-04-30 10:14   ` Tero Kristo
2012-05-01  1:01     ` NeilBrown
2012-05-09 16:06   ` Samuel Ortiz
2012-04-25  7:33 ` [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS NeilBrown
2012-04-25  8:05   ` Felipe Balbi
2012-04-25 10:29     ` NeilBrown
2012-04-25 11:44   ` Grazvydas Ignotas
2012-04-25 11:31 ` [PATCH 0/6] twl4030: Various fixes for charing-from-USB Grazvydas Ignotas
2012-04-29 23:30   ` NeilBrown
2012-05-05 10:49     ` Anton Vorontsov
2012-05-05 10:52       ` Anton Vorontsov
2012-05-10  1:24 ` Peter Chen
2012-05-10  2:37   ` NeilBrown
2012-05-10  6:46     ` Chen Peter-B29397
2012-05-10 14:45     ` Alan Stern

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).