twl4030: Various fixes for charing-from-USB
Subsystems (3)
cover twl4030: Various fixes for charing-from-USB
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 · 1 line
Signature
PATCH 1/6 twl4030_charger: Fix some typos
---
drivers/power/twl4030_charger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/power/twl4030_charger.c +3 -3
@@ -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 ;
PATCH 2/6 twl4030_charger: add backup-battery charging.
In reply to NeilBrownThis 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.
---
drivers/power/twl4030_charger.c | 59 +++++++++++++++++++++++++++++++++++++++ include/linux/i2c/twl.h | 2 + 2 files changed, 61 insertions(+)
drivers/power/twl4030_charger.c +59 -0
@@ -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,
include/linux/i2c/twl.h +2 -0
@@ -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 */
PATCH 3/6 twl4030_charger: allow charging whenever VBUS is present.
In reply to NeilBrownWe 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.
---
drivers/power/twl4030_charger.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/power/twl4030_charger.c +1 -5
@@ -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 ); }/*
Re: [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present.
Quoted 8 lines · 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.
On pandora I see the opposite, STS_VBUS is set regardless of who drives it, so this will break pandora..
Quoted 26 lines
Signed-off-by NeilBrown <[email protected]>---
drivers/power/twl4030_charger.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)drivers/power/twl4030_charger.c +1
-5@@ -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); } /*
Signature · 5 lines
Gražvydas -- 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
Re: [PATCH 3/6] twl4030_charger: allow charging whenever VBUS is present.
Quoted 6 lines · On Wed, 25 Apr 2012 14:33:25 +0300 Grazvydas Ignotas <[email protected]> wrote:
Quoted 5 lines · 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).
Quoted 6 lines
Quoted 3 lines
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_VBUSis 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
Quoted 29 lines
Quoted 27 lines
Signed-off-by NeilBrown <[email protected]>---
drivers/power/twl4030_charger.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)drivers/power/twl4030_charger.c +1
-5@@ -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); } /*
PATCH 4/6 twl4030_charger: Allow charger to control the regulator that feeds it.
In reply to NeilBrownThe 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.
---
drivers/mfd/twl-core.c | 9 +++++---- drivers/power/twl4030_charger.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/mfd/twl-core.c +5 -4
@@ -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 ()) {
drivers/power/twl4030_charger.c +15 -0
@@ -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);
Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
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
Quoted 107 lines · 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 <[email protected]>---
drivers/mfd/twl-core.c | 9 +++++---- drivers/power/twl4030_charger.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-)drivers/mfd/twl-core.c +5
-4@@ -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 ()) {drivers/power/twl4030_charger.c +15
-1@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
Quoted 6 lines · On Mon, 30 Apr 2012 13:14:32 +0300 Tero Kristo…
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 thetwl-core.cpart. It looks kind of okay, even if I would eventually like to remove/fix the ugly regulator init from twl-core.
Thanks.
Quoted 3 lines
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
Quoted 113 lines
-Tero
Quoted 107 lines · 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 <[email protected]>---
drivers/mfd/twl-core.c | 9 +++++---- drivers/power/twl4030_charger.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-)drivers/mfd/twl-core.c +5
-4@@ -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 ()) {drivers/power/twl4030_charger.c +15
-1@@ -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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/6] twl4030_charger: Allow charger to control the regulator that feeds it.
In reply to NeilBrownHi Neil,
Quoted 6 lines · 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.
Quoted 6 lines
Signed-off-by NeilBrown <[email protected]>---
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:
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/
PATCH 5/6 twl4030-usb: Don't power down phy when it is in-use by charger.
In reply to NeilBrownThe 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.
---
drivers/usb/otg/twl4030-usb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/usb/otg/twl4030-usb.c +7 -1
@@ -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 ); } }
PATCH 6/6 twl4030-usb: Don't report EVENT_ID when there is VBUS.
In reply to NeilBrownSome 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.
---
drivers/usb/otg/twl4030-usb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/usb/otg/twl4030-usb.c +10 -9
@@ -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",
Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
Hi,
Quoted 4 lines · 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.
this isn't entirely true. Have you considered Accessory Charger Adapters ?
Quoted 3 lines
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.
Signature · 1 line
balbi
Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
Quoted 10 lines · On Wed, 25 Apr 2012 11:05:27 +0300 Felipe Balbi <[email protected]> wrote:
Hi,
Quoted 4 lines · 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.
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?)
Quoted 7 lines
Quoted 4 lines
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
Re: [PATCH 6/6] twl4030-usb: Don't report EVENT_ID when there is VBUS.
In reply to NeilBrownQuoted 5 lines · 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.
Quoted 7 lines
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_PRESisn'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..
Quoted 39 lines
Signed-off-by NeilBrown <[email protected]>---
drivers/usb/otg/twl4030-usb.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)drivers/usb/otg/twl4030-usb.c +10
-9@@ -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",
Signature · 1 line
Gražvydas
Quoted 3 lines · NeilBrown
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..
Signature · 1 line
Gražvydas
Quoted 10 lines · On Wed, 25 Apr 2012 14:31:13 +0300 Grazvydas Ignotas…
Quoted 3 lines · NeilBrown
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.plis usually good at finding the right people, although theirMAINTAINERSentry could be better I guess..
I guess you mean:
POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
M: Anton Vorontsov <cbou-JGs/[email protected]>
M: David Woodhouse <[email protected]>
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
Quoted 21 lines · NeilBrown
Quoted 9 lines
Quoted 3 lines
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.plis usually good at finding the right people, although theirMAINTAINERSentry could be better I guess..I guess you mean:
POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
M: Anton Vorontsov <cbou-JGs/[email protected]>
M: David Woodhouse <[email protected]>
T: gitgit://git.infradead.org/battery-2.6.git
S: Maintained
F:include/linux/power_supply.h
F:drivers/power/power_supply*
Quoted 2 lines
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.
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -5290,7 +5290,7 @@ M: David Woodhouse <[email protected]> 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 <[email protected]>
Signature · 6 lines
1.7.9.2 -- 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
Quoted 32 lines · Anton Vorontsov
Quoted 21 lines · NeilBrown
Quoted 9 lines
Quoted 3 lines
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.plis usually good at finding the right people, although theirMAINTAINERSentry could be better I guess..I guess you mean:
POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
M: Anton Vorontsov <cbou-JGs/[email protected]>
M: David Woodhouse <[email protected]>
T: gitgit://git.infradead.org/battery-2.6.git
S: Maintained
F:include/linux/power_supply.h
F:drivers/power/power_supply*Quoted 2 lines
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
Quoted 7 lines
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 <[email protected]>
Oh, Grazvydas Ignotas noticed this too. I added
Just to be precise. ;-)
Thanks folks,
Signature · 6 lines
Anton Vorontsov Email: [email protected] -- 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
Quoted 10 lines · NeilBrown
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.
Quoted 32 lines
Questions and comments more welcome.
Thanks,
NeilBrown---
NeilBrown (6):
twl4030-usb: Don't reportEVENT_IDwhen 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 typosdrivers/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 · 6 lines
Signature -- 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
Signature · 2 lines
Best Regards, Peter Chen
Quoted 11 lines · On Thu, 10 May 2012 09:24:23 +0800 Peter Chen <[email protected]> wrote:
Quoted 10 lines · NeilBrown
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).
Quoted 3 lines
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
Quoted 33 lines
Quoted 32 lines
Questions and comments more welcome.
Thanks,
NeilBrown---
NeilBrown (6):
twl4030-usb: Don't reportEVENT_IDwhen 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 typosdrivers/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 · 6 lines
Signature -- 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
Quoted 6 lines
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
Quoted 3 lines
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.
Quoted 8 lines
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?
Quoted 7 lines
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.
Quoted 4 lines · NeilBrown
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.
Quoted 1 line
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.
Quoted 4 lines
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