Skip to contentSkip to conversation

bq24190: What's the correct API to turn boost mode (OTG) on for the battery charger ?

DISCUSSION Laurent Pinchart 2 participants 6 messages May 15, 2014 – May 21, 2014

lore
Share & tools
lore
#0 lore raw

Hello,

I'm trying to enable battery charging on an OMAP4 board based on a twl6030 PMIC with external bq24190 battery charger and bq27510 fuel gauge.

The system has an OTG USB port that can be used to charge the battery, and that can also be used in host mode. In that case the bq24190 needs to be switched to boost mode to provide the +5V power supply from the battery.

The bq24190 has a charge configuration register field that supports charge disabled, charge enabled and OTG (boost mode). The field is set by the bq24190 driver in response to setting the charge type : POWER_SUPPLY_CHARGE_TYPE_NONE will disable charing, and POWER_SUPPLY_CHARGE_TYPE_TRICKLE and POWER_SUPPLY_CHARGE_TYPE_FAST will enable it. However, OTG boost mode is not supported.

The driver exposes most register fields as sysfs attributes (which doesn't sound very safe to me, but that's another story). I can thus enable OTG boost mode directly from userspace through the driver-specific API, but that just bypasses the power supply API. I'm thus not very fond of that solution.

Possibly due to my really basic (not to say nonexistent) knowledge of the power supply subsystem I haven't found an API to expose this feature. I was wondering if someone had given a though regarding how to implement this properly.

Signature · 3 lines
Regards,

Laurent Pinchart
#1 lore raw
Quoted 1 line · Laurent Pinchart

Hello,

[Adding Anton Vorontsov to CC list.]

Hi Laurent.

Quoted 16 lines

I'm trying to enable battery charging on an OMAP4 board based on a twl6030 PMIC with external bq24190 battery charger and bq27510 fuel gauge.

The system has an OTG USB port that can be used to charge the battery, and that can also be used in host mode. In that case the bq24190 needs to be switched to boost mode to provide the +5V power supply from the battery.

The bq24190 has a charge configuration register field that supports charge disabled, charge enabled and OTG (boost mode). The field is set by the bq24190 driver in response to setting the charge type : POWER_SUPPLY_CHARGE_TYPE_NONE will disable charing, and POWER_SUPPLY_CHARGE_TYPE_TRICKLE and POWER_SUPPLY_CHARGE_TYPE_FAST will enable it. However, OTG boost mode is not supported.

Quoted 4 lines

The driver exposes most register fields as sysfs attributes (which doesn't sound very safe to me, but that's another story). I can thus enable OTG boost mode directly from userspace through the driver-specific API, but that just bypasses the power supply API. I'm thus not very fond of that solution.

No, its not a good solution. As indicated in the commit log, the sysfs entries are there because there are just so many fields that don't map well to the existing interface.

Maybe we should add support for a DT entry to enable exporting those fields(disabled by default)?

Quoted 4 lines

Possibly due to my really basic (not to say nonexistent) knowledge of the power supply subsystem I haven't found an API to expose this feature. I was wondering if someone had given a though regarding how to implement this properly.

What if we just added something like POWER_SUPPLY_CHARGE_TYPE_BOOST?

Mark
--

#2 lore raw

Hi Mark,

Thank you for the quick reply.

Quoted 36 lines · On Thursday 15 May 2014 15:08:44 Mark A. Greer wrote:
Quoted 1 line · Laurent Pinchart

Hello,

[Adding Anton Vorontsov to CC list.]

Hi Laurent.

Quoted 16 lines

I'm trying to enable battery charging on an OMAP4 board based on a twl6030 PMIC with external bq24190 battery charger and bq27510 fuel gauge.

The system has an OTG USB port that can be used to charge the battery, and that can also be used in host mode. In that case the bq24190 needs to be switched to boost mode to provide the +5V power supply from the battery.

The bq24190 has a charge configuration register field that supports charge disabled, charge enabled and OTG (boost mode). The field is set by the bq24190 driver in response to setting the charge type :
POWER_SUPPLY_CHARGE_TYPE_NONE will disable charing, and POWER_SUPPLY_CHARGE_TYPE_TRICKLE and POWER_SUPPLY_CHARGE_TYPE_FAST will enable it. However, OTG boost mode is not supported.

Quoted 5 lines

The driver exposes most register fields as sysfs attributes (which doesn't sound very safe to me, but that's another story). I can thus enable OTG boost mode directly from userspace through the driver-specific API, but that just bypasses the power supply API. I'm thus not very fond of that solution.

No, its not a good solution. As indicated in the commit log, the sysfs entries are there because there are just so many fields that don't map well to the existing interface.

Maybe we should add support for a DT entry to enable exporting those fields(disabled by default)?

Quoted 6 lines
Quoted 4 lines

Possibly due to my really basic (not to say nonexistent) knowledge of the power supply subsystem I haven't found an API to expose this feature. I was wondering if someone had given a though regarding how to implement this properly.

What if we just added something like POWER_SUPPLY_CHARGE_TYPE_BOOST?

That was actually my first thought, and I assumed it would be rejected as boost mode is not a charge type but a discharge type :-) This being said, I don't have enough experience with battery chargers to decide whether this is a good solution. If you believe it is, I'll trust you on that.

On a side note, is there any reference userspace implementation of a battery manager ? The vendor BSP I've received with the board hardcodes calls to the bq24190 in the MUSB driver to switch between OTG and trickle charge modes based on USB cable connection/disconnection events. That's pretty ugly, and I assume this should be handled in userspace - or is there a standard kernel infrastructure for that ?

Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw
Quoted 3 lines · Laurent Pinchart

Hi Mark,

Thank you for the quick reply.

Hi Laurent. Sorry for the delay.

Quoted 42 lines · On Thursday 15 May 2014 15:08:44 Mark A. Greer wrote:
Quoted 41 lines · Laurent Pinchart
Quoted 1 line

Hello,

[Adding Anton Vorontsov to CC list.]

Hi Laurent.

Quoted 16 lines

I'm trying to enable battery charging on an OMAP4 board based on a twl6030 PMIC with external bq24190 battery charger and bq27510 fuel gauge.

The system has an OTG USB port that can be used to charge the battery, and that can also be used in host mode. In that case the bq24190 needs to be switched to boost mode to provide the +5V power supply from the battery.

The bq24190 has a charge configuration register field that supports charge disabled, charge enabled and OTG (boost mode). The field is set by the bq24190 driver in response to setting the charge type :
POWER_SUPPLY_CHARGE_TYPE_NONE will disable charing, and POWER_SUPPLY_CHARGE_TYPE_TRICKLE and POWER_SUPPLY_CHARGE_TYPE_FAST will enable it. However, OTG boost mode is not supported.

Quoted 5 lines

The driver exposes most register fields as sysfs attributes (which doesn't sound very safe to me, but that's another story). I can thus enable OTG boost mode directly from userspace through the driver-specific API, but that just bypasses the power supply API. I'm thus not very fond of that solution.

No, its not a good solution. As indicated in the commit log, the sysfs entries are there because there are just so many fields that don't map well to the existing interface.

Maybe we should add support for a DT entry to enable exporting those fields(disabled by default)?

Quoted 4 lines

Possibly due to my really basic (not to say nonexistent) knowledge of the power supply subsystem I haven't found an API to expose this feature. I was wondering if someone had given a though regarding how to implement this properly.

Quoted 4 lines
Quoted 1 line

What if we just added something like POWER_SUPPLY_CHARGE_TYPE_BOOST?

That was actually my first thought, and I assumed it would be rejected as boost mode is not a charge type but a discharge type :-)

Er, right. :(

Quoted 3 lines

This being said, I
don't have enough experience with battery chargers to decide whether this is a good solution. If you believe it is, I'll trust you on that.

No, you're right, that isn't a good solution.

I don't see a really good fit anywhere. The easiest thing may be to add a new POWER_SUPPLY_PROP_xxx power_supply_property member which can be set to flip it into boost mode but I'm not sure if that's really the right thing to do.

I hope Anton will comment on this.

Quoted 6 lines

On a side note, is there any reference userspace implementation of a battery manager ? The vendor BSP I've received with the board hardcodes calls to the bq24190 in the MUSB driver to switch between OTG and trickle charge modes based on USB cable connection/disconnection events. That's pretty ugly, and I assume this should be handled in userspace - or is there a standard kernel infrastructure for that ?

I don't have a good feel for what's out there but the charger-manager may be a good place to start:

Documentation/power/charger-manager.txt
drivers/power/charger-manager.c

HTH,

Mark
--

#4 lore raw
Quoted 9 lines · Mark A. Greer
Quoted 6 lines · Laurent Pinchart

On a side note, is there any reference userspace implementation of a battery manager ? The vendor BSP I've received with the board hardcodes calls to the bq24190 in the MUSB driver to switch between OTG and trickle charge modes based on USB cable connection/disconnection events. That's pretty ugly, and I assume this should be handled in userspace - or is there a standard kernel infrastructure for that ?

Quoted 5 lines

I don't have a good feel for what's out there but the charger-manager may be a good place to start:

Documentation/power/charger-manager.txt
drivers/power/charger-manager.c

And,

http://elinux.org/images/c/c6/Elce11_ham.pdf

#5 lore raw
In reply to Mark A. Greer

[Removing Anton from CC]

Quoted 60 lines · Mark A. Greer
Quoted 3 lines · Laurent Pinchart

Hi Mark,

Thank you for the quick reply.

Hi Laurent. Sorry for the delay.

Quoted 42 lines · On Thursday 15 May 2014 15:08:44 Mark A. Greer wrote:
Quoted 41 lines · Laurent Pinchart
Quoted 1 line

Hello,

[Adding Anton Vorontsov to CC list.]

Hi Laurent.

Quoted 16 lines

I'm trying to enable battery charging on an OMAP4 board based on a twl6030 PMIC with external bq24190 battery charger and bq27510 fuel gauge.

The system has an OTG USB port that can be used to charge the battery, and that can also be used in host mode. In that case the bq24190 needs to be switched to boost mode to provide the +5V power supply from the battery.

The bq24190 has a charge configuration register field that supports charge disabled, charge enabled and OTG (boost mode). The field is set by the bq24190 driver in response to setting the charge type :
POWER_SUPPLY_CHARGE_TYPE_NONE will disable charing, and POWER_SUPPLY_CHARGE_TYPE_TRICKLE and POWER_SUPPLY_CHARGE_TYPE_FAST will enable it. However, OTG boost mode is not supported.

Quoted 5 lines

The driver exposes most register fields as sysfs attributes (which doesn't sound very safe to me, but that's another story). I can thus enable OTG boost mode directly from userspace through the driver-specific API, but that just bypasses the power supply API. I'm thus not very fond of that solution.

No, its not a good solution. As indicated in the commit log, the sysfs entries are there because there are just so many fields that don't map well to the existing interface.

Maybe we should add support for a DT entry to enable exporting those fields(disabled by default)?

Quoted 4 lines

Possibly due to my really basic (not to say nonexistent) knowledge of the power supply subsystem I haven't found an API to expose this feature. I was wondering if someone had given a though regarding how to implement this properly.

Quoted 4 lines
Quoted 1 line

What if we just added something like POWER_SUPPLY_CHARGE_TYPE_BOOST?

That was actually my first thought, and I assumed it would be rejected as boost mode is not a charge type but a discharge type :-)

Er, right. :(

Quoted 3 lines

This being said, I
don't have enough experience with battery chargers to decide whether this is a good solution. If you believe it is, I'll trust you on that.

Quoted 8 lines

No, you're right, that isn't a good solution.

I don't see a really good fit anywhere. The easiest thing may be to add a new POWER_SUPPLY_PROP_xxx power_supply_property member which can be set to flip it into boost mode but I'm not sure if that's really the right thing to do.

I hope Anton will comment on this.

After looking at MAINTAINERS and its git log, it looks like Dmitry has taken over.

Dmitry, do you have anything insight?

Mark
--