power_supply: Add driver for TWL4030/TPS65950 BCI charger
PATCH v3 1/1 power_supply: Add driver for TWL4030/TPS65950 BCI charger
TWL4030/TPS65950 is a multi-function device with integrated charger, which allows charging from AC or USB. This driver enables the charger and provides several monitoring functions.
Tested on OMAP3 Pandora board.
---
This is v3 of BCI charger driver I first sent nearly a year ago [1]. I've updated it to use the new OTG notifiers for VBUS notifications, however it still is not able to determine charge current to use. For that reason there is now a temporary module param to enable USB charging, until I can figure out how to get that info from the gadget stack (hopefully Felipe can help me here).
Besides that it now uses threaded interrupts and makes use of charge state change interrupt to notify power supply core.
For this driver to work, twl-core needs to be patched to register correct platform device, and twl4030-irq needs to set COR bit correctly (will send those patches to mfd).
[1] http://marc.info/?l=linux-omap&m=125933316000333&w=2
drivers/power/Kconfig | 6 + drivers/power/Makefile | 1 + drivers/power/twl4030_charger.c | 575 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 582 insertions(+), 0 deletions(-) create mode 100644 drivers/power/twl4030_charger.c
drivers/power/Kconfig +6 -0
@@ -180,4 +180,10 @@ config CHARGER_ISP1704 Say Y to enable support for USB Charger Detection with ISP1707/ISP1704 USB transceivers. +config CHARGER_TWL4030 + tristate "OMAP TWL4030 BCI charger driver" + depends on TWL4030_CORE + help + Say Y here to enable support for TWL4030 Battery Charge Interface. + endif # POWER_SUPPLY
drivers/power/Makefile +1 -0
@@ -39,3 +39,4 @@ obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o +obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
drivers/power/twl4030_charger.c new file +575 -0
575 lines not on this page · raw message
Signature · 6 lines
1.6.3.3 -- 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
Quoted 6 lines · Grazvydas Ignotas
TWL4030/TPS65950 is a multi-function device with integrated charger, which allows charging from AC or USB. This driver enables the charger and provides several monitoring functions.
Tested on OMAP3 Pandora board.
Quoted 8 lines
Signed-off-by Grazvydas Ignotas <[email protected]>---
This is v3 of BCI charger driver I first sent nearly a year ago [1]. I've updated it to use the new OTG notifiers for VBUS notifications, however it still is not able to determine charge current to use. For that reason there is now a temporary module param to enable USB charging, until I can figure out how to get that info from the gadget stack (hopefully Felipe can help me here).
You need to send USB_EVENT_ENUMERATED from usb_gadget_vbus_draw(), but wait until the UDC class is finished, then we will have a common location to do those stuff.
Quoted 26 lines
Besides that it now uses threaded interrupts and makes use of charge state change interrupt to notify power supply core.
For this driver to work, twl-core needs to be patched to register correct platform device, and twl4030-irq needs to set COR bit correctly (will send those patches to mfd).
drivers/power/twl4030_charger.c new file +19
-0+static int __devinit twl4030_bci_probe (struct platform_device *pdev) +{ +struct twl4030_bci *bci; +int ret; +int reg; + + bci =kzalloc (sizeof (*bci),GFP_KERNEL ); +if (bci ==NULL ) +return -ENOMEM ; + + bci->dev = &pdev->dev; + bci->irq_chg =platform_get_irq (pdev,0 ); + bci->irq_bci =platform_get_irq (pdev,1 ); + + ret =request_threaded_irq (bci->irq_chg,NULL , + twl4030_charger_interrupt,0 , pdev->name, bci); +if (ret <0 ) { +dev_err (&pdev->dev,"could not request irq %d, status %d\n" , + bci->irq_chg, ret);
drivers/power/twl4030_charger.c line 441
Quoted 10 lines
drivers/power/twl4030_charger.c new file +10
-0+ goto fail_chg_irq; + } + + ret =request_threaded_irq (bci->irq_bci,NULL , + twl4030_bci_interrupt,0 , pdev->name, bci); +if (ret <0 ) { +dev_err (&pdev->dev,"could not request irq %d, status %d\n" , + bci->irq_bci, ret); + goto fail_bci_irq; + }
you should register the power_supply before enabling the IRQ lines, otherwise you might call power_supply_changed() to a non-existent power_supply.
Quoted 19 lines
drivers/power/twl4030_charger.c new file +19
-0+platform_set_drvdata (pdev, bci); + + bci->ac.name ="twl4030_ac" ; + bci->ac.type =POWER_SUPPLY_TYPE_MAINS ; + bci->ac.properties = twl4030_charger_props; + bci->ac.num_properties =ARRAY_SIZE (twl4030_charger_props); + bci->ac.get_property = twl4030_bci_get_property; + + ret =power_supply_register (&pdev->dev, &bci->ac); +if (ret) { +dev_err (&pdev->dev,"failed to register ac: %d\n" , ret); + goto fail_register_ac; + } + + bci->usb.name ="twl4030_usb" ; + bci->usb.type =POWER_SUPPLY_TYPE_USB ; + bci->usb.properties = twl4030_charger_props; + bci->usb.num_properties =ARRAY_SIZE (twl4030_charger_props); + bci->usb.get_property = twl4030_bci_get_property;
drivers/power/twl4030_charger.c line 471
Quoted 10 lines
drivers/power/twl4030_charger.c new file +10
-0+ + ret =power_supply_register (&pdev->dev, &bci->usb); +if (ret) { +dev_err (&pdev->dev,"failed to register usb: %d\n" , ret); + goto fail_register_usb; + } + +#ifdef CONFIG_USB_OTG_UTILS + bci->transceiver =otg_get_transceiver (); +#endif
this driver should actually depend on that. It won't work without access to the transceiver anyway. Or you add something like:
#ifdef CONFIG_USB_OTG_UTILS
extern struct otg_transceiver *otg_get_transceiver(void); extern void otg_put_transceiver(struct otg_transceiver *); #else
static inline struct otg_transceiver *otg_get_transceiver(void) { return NULL; }
static inline void otg_put_transceiver(struct otg_transceiver *x) { }
#endif
to the otg.h and avoid having to use that ifdef here and on any other driver. (should be a separate patch though).
drivers/power/twl4030_charger.c line 552
Quoted 2 lines
drivers/power/twl4030_charger.c new file +2
-0+static struct platform_driver twl4030_bci_driver = { + .probe = twl4030_bci_probe,
drivers should not reference __init sections anymore. If you make this
statically linked to the kernel, you'll get section mismatches. It's
better to make probe __init remove it from here and call platform_driver_probe() from module_init();
Quoted 6 lines
drivers/power/twl4030_charger.c new file +6
-0+ .remove = __devexit_p(twl4030_bci_remove), + .driver = { + .name = "twl4030_bci", + .owner = THIS_MODULE, + }, +};
Signature · 1 line
balbi
hello,
Quoted 17 lines · Felipe Balbi
Quoted 7 lines · Grazvydas Ignotas
TWL4030/TPS65950 is a multi-function device with integrated charger, which allows charging from AC or USB. This driver enables the charger and provides several monitoring functions.
Tested on OMAP3 Pandora board.
Quoted 8 lines
Signed-off-by Grazvydas Ignotas <[email protected]>---
This is v3 of BCI charger driver I first sent nearly a year ago [1]. I've updated it to use the new OTG notifiers for VBUS notifications, however it still is not able to determine charge current to use. For that reason there is now a temporary module param to enable USB charging, until I can figure out how to get that info from the gadget stack (hopefully Felipe can help me here).
Quoted 3 lines
You need to send
USB_EVENT_ENUMERATEDfromusb_gadget_vbus_draw(), but wait until the UDC class is finished, then we will have a common location to do those stuff.
ok, I hope I can get CCed or notified in some way as I might miss that.
<snip>
Quoted 10 lines
Quoted 9 lines
+
+ ret = request_threaded_irq(bci->irq_bci, NULL,
+twl4030_bci_interrupt, 0,pdev->name, bci);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "could not request irq %d, status %d\n",
+bci->irq_bci, ret);
+ gotofail_bci_irq;
+ }
Quoted 3 lines
you should register the
power_supplybefore enabling the IRQ lines, otherwise you might callpower_supply_changed()to a non-existentpower_supply.
good catch, will do.
<snip>
Quoted 7 lines
drivers/power/twl4030_charger.c line 471
Quoted 4 lines
drivers/power/twl4030_charger.c new file +4
-0+ +#ifdef CONFIG_USB_OTG_UTILS + bci->transceiver = otg_get_transceiver(); +#endif this driver should actually depend on that. It won't work without access to the transceiver anyway.
Well it can still do AC charging fine without OTG stuff.
Quoted 11 lines
Or you add something like:
#ifdef
CONFIG_USB_OTG_UTILS
extern structotg_transceiver*otg_get_transceiver(void); extern voidotg_put_transceiver(struct otg_transceiver *); #else
static inline structotg_transceiver*otg_get_transceiver(void){ return NULL; }
static inline voidotg_put_transceiver(struct otg_transceiver *x){ }
#endif
I much prefer that, will send a patch.
Quoted 11 lines
to the
otg.hand avoid having to use that ifdef here and on any other driver. (should be a separate patch though).Quoted 2 lines
+static struct
platform_drivertwl4030_bci_driver= {
+ .probe =twl4030_bci_probe,drivers should not reference
__initsections anymore. If you make this statically linked to the kernel, you'll get section mismatches. It's better to make probe__initremove it from here and callplatform_driver_probe()frommodule_init();
Tried that and did not get any section mismatches, but will switch anyway to better match trends.
Quoted 11 lines
Quoted 7 lines
+ .remove =
__devexit_p(twl4030_bci_remove),
+ .driver = {
+ .name = "twl4030_bci",
+ .owner =THIS_MODULE,
+ },
+};--
balbi
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi,
please re-send this email without the HTML formatting. Please follow the netiquette [1].
[1] http://elinux.org/Netiquette
Signature · 1 line
balbi
Quoted 10 lines · Arun Murthy
Quoted 7 lines · Grazvydas Ignotas
---
This is v3 of BCI charger driver I first sent nearly a year ago [1]. I've updated it to use the new OTG notifiers for VBUS notifications, however it still is not able to determine charge current to use. For that reason there is now a temporary module param to enable USB charging, until I can figure out how to get that info from the gadget stack (hopefully Felipe can help me here).
Quoted 6 lines
On detecting USB plug, the driver is suppose to detect the type of usb device. Then if the device is a PC(standard host) the charging current is to be obtained from the usb stack. Hence the driver will have to wait until the usb stack or driver notifies the current that can be drawn. The usb stack or driver gets to know the amount of current to be drawn through the negotiations that happen between the host and device.
I'm aware of that, the question was how to get that from Linux USB stack (which Felipe already responded).
<snip>
Quoted 5 lines
Only AC and USB monitoring is achieved by registering with power supply class.
How is battery monitored?
An instance of battery is to be registered with power supply class in order to monitor battery.
The problem is that BCI is only active while charging, when it is not charging most (all?) monitoring registers freeze and no monitoring happens (BCI registers read frozen values from last charge). So I don't register battery as it has no useful data to report. I heard it is possible to use MADC to perform monitoring while not charging, so battery can be added when MADC driver is merged and corresponding code is written for this driver.
Quoted 12 lines
drivers/power/twl4030_charger.c line 558
Quoted 10 lines
drivers/power/twl4030_charger.c new file +9
-0+ +static struct platform_driver twl4030_bci_driver = { + .probe = twl4030_bci_probe, + .remove = __devexit_p(twl4030_bci_remove), + .driver = { + .name = "twl4030_bci", + .owner = THIS_MODULE, + }, +};
dev_pm_opscan be use
nothing to do there right now, the driver relies on FSM change interrupts from BCI to update state.
Quoted 10 lines · Grazvydas Ignotas
Quoted 8 lines · Arun Murthy
Quoted 1 line · Grazvydas Ignotas
---
Only AC and USB monitoring is achieved by registering with power supply class.
How is battery monitored?
An instance of battery is to be registered with power supply class in order to monitor battery.
Quoted 8 lines
The problem is that BCI is only active while charging, when it is not charging most (all?) monitoring registers freeze and no monitoring happens (BCI registers read frozen values from last charge). So I don't register battery as it has no useful data to report. I heard it is possible to use MADC to perform monitoring while not charging, so battery can be added when MADC driver is merged and corresponding code is written for this driver.
How do I check the battery voltage?
I need to check the battery voltage/current/temp and, if I am not wrong these are obtained from MADC.
MADC driver has to be added first and then the battery. With being able to read the basic parameter battery voltage, this driver becomes incomplete.
How do I get notified if battery voltage is low and needs charging from user space?
Thanks and Regards,
Arun R Murthy
---------------------
Quoted 10 lines · Arun Murthy
Quoted 9 lines · Grazvydas Ignotas
On Mon, Sep 27, 2010 at 10:21 AM, Arun Murthy <[email protected]> wrote:
The problem is that BCI is only active while charging, when it is not charging most (all?) monitoring registers freeze and no monitoring happens (BCI registers read frozen values from last charge). So I don't register battery as it has no useful data to report. I heard it is possible to use MADC to perform monitoring while not charging, so battery can be added when MADC driver is merged and corresponding code is written for this driver.
Quoted 6 lines
How do I check the battery voltage?
I need to check the battery voltage/current/temp and, if I am not wrong these are obtained from MADC.
MADC driver has to be added first and then the battery. With being able to read the basic parameter battery voltage, this driver becomes incomplete.
Incomplete driver is better than no driver, don't you think? There are some boards like pandora or oswald that have additional battery monitoring chips (as twl monitoring is pretty crude anyway), those boards would have fully functional charging now. Currently mainline kernel is not very useful with them simply because the battery runs flat.
Quoted 2 lines
How do I get notified if battery voltage is low and needs charging from user space?
Either additional monitoring chip notifies you (if you are lucky and have one), or wait for update of this driver :) There are efforts to merge MADC driver [1], but it may take some time.
Quoted 18 lines · Grazvydas Ignotas
Quoted 10 lines · Arun Murthy
Quoted 9 lines · Grazvydas Ignotas
On Mon, Sep 27, 2010 at 10:21 AM, Arun Murthy <[email protected]> wrote:
The problem is that BCI is only active while charging, when it is not charging most (all?) monitoring registers freeze and no monitoring happens (BCI registers read frozen values from last charge). So I don't register battery as it has no useful data to report. I heard it is possible to use MADC to perform monitoring while not charging, so battery can be added when MADC driver is merged and corresponding code is written for this driver.Quoted 6 lines
How do I check the battery voltage?
I need to check the battery voltage/current/temp and, if I am not wrong these are obtained from MADC.
MADC driver has to be added first and then the battery. With being able to read the basic parameter battery voltage, this driver becomes incomplete.
Quoted 6 lines
Incomplete driver is better than no driver, don't you think? There are some boards like pandora or oswald that have additional battery monitoring chips (as twl monitoring is pretty crude anyway), those boards would have fully functional charging now. Currently mainline kernel is not very useful with them simply because the battery runs flat.
I agree, but I feel it would be better to make driver compatible with all boards(Zoom2, OMAP3430SDP, Chameleon, BeagleBoard etc). Even support for back-up battery is not supported.
This is just a suggestion to have a full fledged driver for twl4030 Battery Charger Interface as a module. You may discard this if you have some strong reasons.
Quoted 7 lines
Quoted 3 lines
How do I get notified if battery voltage is low and needs charging from user space?
Either additional monitoring chip notifies you (if you are lucky and have one), or wait for update of this driver :) There are efforts to merge MADC driver [1], but it may take some time.
But using MADC, I can get the battery voltage and by means of monitoring battery voltage we can get to know low battery notification.
Quoted 3 lines
Thanks and Regards,
Arun R Murthy
--------------------
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
How do I get notified if battery voltage is low and needs charging from user space?
Either additional monitoring chip notifies you (if you are lucky and have one), or wait for update of this driver :) There are efforts to merge MADC driver [1], but it may take some time.
But using MADC, I can get the battery voltage and by means of monitoring battery voltage we can get to know low battery notification.
True, but let's wait for MADC driver to be merged for that first.
Quoted 7 lines
Quoted 3 lines
Thanks and Regards,
Arun R Murthy
--------------------
Quoted 7 lines · Grazvydas Ignotas
TWL4030/TPS65950 is a multi-function device with integrated charger, which allows charging from AC or USB. This driver enables the charger and provides several monitoring functions.
Tested on OMAP3 Pandora board.
Quoted 8 lines
Signed-off-by Grazvydas Ignotas <[email protected]>---
This is v3 of BCI charger driver I first sent nearly a year ago [1]. I've updated it to use the new OTG notifiers for VBUS notifications, however it still is not able to determine charge current to use. For that reason there is now a temporary module param to enable USB charging, until I can figure out how to get that info from the gadget stack (hopefully Felipe can help me here).
On detecting USB plug, the driver is suppose to detect the type of usb device. Then if the device is a PC(standard host) the charging current is to be obtained from the usb stack. Hence the driver will have to wait until the usb stack or driver notifies the current that can be drawn. The usb stack or driver gets to know the amount of current to be drawn through the negotiations that happen between the host and device.
Quoted 16 lines
drivers/power/twl4030_charger.c new file +16
-0+ + platform_set_drvdata(pdev, bci); + + bci->ac.name = "twl4030_ac"; + bci->ac.type = POWER_SUPPLY_TYPE_MAINS; + bci->ac.properties = twl4030_charger_props; + bci->ac.num_properties = ARRAY_SIZE(twl4030_charger_props); + bci->ac.get_property = twl4030_bci_get_property; + + ret = power_supply_register(&pdev->dev, &bci->ac); + if (ret) { + dev_err(&pdev->dev, "failed to register ac: %d\n", ret); + goto fail_register_ac; + } + + bci->usb.name = "twl4030_usb";
drivers/power/twl4030_charger.c line 467
Quoted 10 lines
drivers/power/twl4030_charger.c new file +10
-0+ bci->usb.type = POWER_SUPPLY_TYPE_USB; + bci->usb.properties = twl4030_charger_props; + bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props); + bci->usb.get_property = twl4030_bci_get_property; + + ret = power_supply_register(&pdev->dev, &bci->usb); + if (ret) { + dev_err(&pdev->dev, "failed to register usb: %d\n", ret); + goto fail_register_usb; + }
Only AC and USB monitoring is achieved by registering with power supply class. How is battery monitored?
An instance of battery is to be registered with power supply class in order to monitor battery.
Thanks and Regards,
Arun R Murthy
---------------------