power supply class support for charger managers
cover power supply class support for charger managers
As we are heading towards kernel charger manager soulutions and few are already in mainaline and few are in pipeline. It makes sense have uniform low level driver support independent of charger manager frameworks.
This patchset add the neccessary changes to power supply class to make charger drivers usable with charger managers.
And also enables charegr manager to use power supply drivers for charge controls.
Ramakrishna Pallala (2):
power_supply: Add charge control struct in power supply class
charger_manager: Enable power supply driver support for charge
controls
drivers/power/Kconfig | 6 ++ drivers/power/charger-manager.c | 23 +++++---- drivers/power/power_supply_core.c | 18 +++++++ include/linux/power/charger-manager.h | 84 +++++++++++++++++++++++++++++++++ include/linux/power_supply.h | 26 ++++++++++ 5 files changed, 146 insertions(+), 11 deletions(-)
PATCH v2 2/2 charger_manager: Enable power supply driver support for charge controls
This patch enables the charger manager support for power supply drivers.
Note: this patch does NOT change the variable/function names in charger manager as it is just an enabling patch. I will submit incremental patches to clean some of naming conventions to appeal more reasonable/logical to the source code reader/developer.
--- drivers/power/charger-manager.c | 23 +++++---- include/linux/power/charger-manager.h | 84 +++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 11 deletions(-)
drivers/power/charger-manager.c +12 -11
@@ -336,7 +336,8 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)if (desc->charger_regulators[i].externally_control)continue ; - err =regulator_enable (desc->charger_regulators[i].consumer); + err =psy_cms_enable_charging ( + desc->charger_regulators[i].consumer);if (err <0 ) { dev_warn(cm->dev, "Cannot enable %s regulator\n",
@@ -355,7 +356,8 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)if (desc->charger_regulators[i].externally_control)continue ; - err =regulator_disable (desc->charger_regulators[i].consumer); + err =psy_cms_disable_charging ( + desc->charger_regulators[i].consumer);if (err <0 ) { dev_warn(cm->dev, "Cannot disable %s regulator\n",
@@ -368,9 +370,9 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)* even if charger was enabled at the other places */ for (i =0 ; i < desc->num_charger_regulators; i++) { -if (regulator_is_enabled ( +if (psy_cms_is_charging_enabled ( desc->charger_regulators[i].consumer)) { -regulator_force_disable ( +psy_cms_force_disable_charging ( desc->charger_regulators[i].consumer); dev_warn(cm->dev, "Disable regulator(%s) forcibly.\n",
@@ -1135,8 +1137,8 @@ static void charger_extcon_work(struct work_struct *work)int ret;if (cable->attached && cable->min_uA !=0 && cable->max_uA !=0 ) { - ret =regulator_set_current_limit (cable->charger->consumer, - cable->min_uA, cable->max_uA); + ret =psy_cms_set_current_limit (cable->charger->consumer, + cable->min_uA, cable->max_uA);if (ret <0 ) {pr_err ("Cannot set current limit of %s (%s)\n" , cable->charger->regulator_name, cable->name);
@@ -1239,7 +1241,7 @@ static ssize_t charger_state_show(struct device *dev,int state =0 ;if (!charger->externally_control) - state =regulator_is_enabled (charger->consumer); + state =psy_cms_is_charging_enabled (charger->consumer);return sprintf (buf,"%s\n" , state ?"enabled" :"disabled" ); }
@@ -1507,8 +1509,7 @@ static int charger_manager_probe(struct platform_device *pdev) = &desc->charger_regulators[i];char buf[11 ];char *str; - - charger->consumer =regulator_get (&pdev->dev, + charger->consumer =psy_cms_get_consumer (&pdev->dev, charger->regulator_name);if (charger->consumer ==NULL ) { dev_err(&pdev->dev, "Cannot find charger(%s)n",
@@ -1639,7 +1640,7 @@ err_extcon: } err_chg_get:for (i =0 ; i < desc->num_charger_regulators ; i++) -regulator_put (desc->charger_regulators[i].consumer); +psy_cms_put_consumer (desc->charger_regulators[i].consumer);power_supply_unregister (&cm->charger_psy); err_register:
@@ -1682,7 +1683,7 @@ static int __devexit charger_manager_remove(struct platform_device *pdev) }for (i =0 ; i < desc->num_charger_regulators ; i++) -regulator_put (desc->charger_regulators[i].consumer); +psy_cms_put_consumer (desc->charger_regulators[i].consumer);power_supply_unregister (&cm->charger_psy);
include/linux/power/charger-manager.h +84 -0
95 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 1/2 power_supply: Add charge control struct in power supply class
In reply to Ramakrishna PallalaThis patch adds power supply charge control structure to power_supply struct and add a Kconfig flag to use these controls by charger frameworks.
This patch also adds a helper function/API to return the charge control struct to the charger frameworks.
--- drivers/power/Kconfig | 6 ++++++ drivers/power/power_supply_core.c | 18 ++++++++++++++++++ include/linux/power_supply.h | 26 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 0 deletions(-)
drivers/power/Kconfig +6 -0
@@ -346,6 +346,12 @@ config AB8500_BM help Say Y to include support for AB8500 battery management. +config PSY_CM_LOW_LEVEL_SUPPORT + bool "Low level driver support for charger managers" + help + Say Y here to enable low level power supply class drivers + support for charger manager or framework. + endif # POWER_SUPPLY source "drivers/power/avs/Kconfig"
drivers/power/power_supply_core.c +18 -0
@@ -158,6 +158,24 @@ struct power_supply *power_supply_get_by_name(char *name) }EXPORT_SYMBOL_GPL (power_supply_get_by_name); +#ifdef CONFIG_PSY_CM_LOW_LEVEL_SUPPORT +struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , + (char *)name, power_supply_match_device_by_name); + +return dev ? ((struct power_supply *)dev_get_drvdata (dev))->chrg_cntl :NULL ; +} +#else +struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name) +{ +return NULL ; +} +#endif +EXPORT_SYMBOL_GPL (power_supply_get_chrg_cntl_by_name); +int power_supply_powers (struct power_supply *psy,struct device *dev) {return sysfs_create_link (&psy->dev->kobj, &dev->kobj,"powers" );
include/linux/power_supply.h +26 -0
@@ -191,6 +191,10 @@ struct power_supply {struct thermal_cooling_device *tcd;#endif +#ifdef CONFIG_PSY_CM_LOW_LEVEL_SUPPORT +struct power_supply_charger_control *chrg_cntl; +#endif +#ifdef CONFIG_LEDS_TRIGGERS struct led_trigger *charging_full_trig;char *charging_full_trig_name;
@@ -224,7 +228,29 @@ struct power_supply_info {int use_for_apm; }; +struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ +int (*turnon_charger)(void ); +int (*turnoff_charger)(void ); +}; +extern struct power_supply *power_supply_get_by_name (char *name); +extern struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy);extern int power_supply_set_battery_charged (struct power_supply *psy);
Signature · 1 line
1.7.0.4
Re: [PATCH 1/2] power_supply: Add charge control struct in power supply class
On Tue, Nov 27, 2012 at 01:17:02PM +0530, Ramakrishna Pallala wrote:
[...]
Quoted 55 lines
+++
b/drivers/power/power_supply_core.cdrivers/power/power_supply_core.c +17
-0@@ -158,6 +158,24 @@ struct power_supply *power_supply_get_by_name(char *name) }EXPORT_SYMBOL_GPL (power_supply_get_by_name); +#ifdef CONFIG_PSY_CM_LOW_LEVEL_SUPPORT +struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name) +{ +struct device *dev =class_find_device (power_supply_class,NULL , + (char *)name, power_supply_match_device_by_name); + +return dev ? ((struct power_supply *)dev_get_drvdata (dev))->chrg_cntl :NULL ; +} +#else +struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name) +{ +return NULL ; +} +#endif +EXPORT_SYMBOL_GPL (power_supply_get_chrg_cntl_by_name);int power_supply_powers (struct power_supply *psy,struct device *dev) {return sysfs_create_link (&psy->dev->kobj, &dev->kobj,"powers" );include/linux/power_supply.h +14
-0@@ -191,6 +191,10 @@ struct power_supply {struct thermal_cooling_device *tcd;#endif +#ifdef CONFIG_PSY_CM_LOW_LEVEL_SUPPORT +struct power_supply_charger_control *chrg_cntl; +#endif +#ifdef CONFIG_LEDS_TRIGGERS struct led_trigger *charging_full_trig;char *charging_full_trig_name;@@ -224,7 +228,29 @@ struct power_supply_info {int use_for_apm; }; +struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV);
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 10 lines
include/linux/power_supply.h +10
-0+ +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ +int (*turnon_charger)(void ); +int (*turnoff_charger)(void ); +}; +
I'm all for this patch, but why do you need to place it into power_supply.h and power_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
You can still add this:
include/linux/power_supply.h struct power_supply { · line 196
Quoted 3 lines
include/linux/power_supply.h +3
-0+#ifdef CONFIG_PSY_CM_LOW_LEVEL_SUPPORT +struct power_supply_charger_control *chrg_cntl; +#endif
to power_supply.h, of course. It's OK.
Quoted 8 lines
include/linux/power_supply.h +2
-0extern struct power_supply *power_supply_get_by_name (char *name); +extern struct power_supply_charger_control + *power_supply_get_chrg_cntl_by_name (const char *name);extern void power_supply_changed (struct power_supply *psy);extern int power_supply_am_i_supplied (struct power_supply *psy);extern int power_supply_set_battery_charged (struct power_supply *psy);Signature · 1 line
1.7.0.4
RE: [PATCH 1/2] power_supply: Add charge control struct in power supply class
Quoted 16 lines
Quoted 16 lines
include/linux/power_supply.h +16
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */
Quoted 8 lines
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 4 lines
include/linux/power_supply.h +4
-0+int (*turnon_charger)(void ); +int (*turnoff_charger)(void ); +}; +I'm all for this patch, but why do you need to place it into
power_supply.handpower_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
Hi Anton,
The main reason for keeping this stuff in power_supply.h and power_supply_core.c is to make these interfaces uniform Across multiple charger frameworks and to avoid each charger framework define it's own interfaces. If there is need for new callback They can add to the existing struct defined above and it will available to all the frameworks. Also the work required to support a new Framework will be reduced if the driver already support any one of the existing frameworks.
Thanks,
Ram ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
RE: [PATCH 1/2] power_supply: Add charge control struct in power supply class
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
include/linux/power_supply.h +16
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ Quoted 8 lines
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 4 lines
include/linux/power_supply.h +4
-0+int (*turnon_charger)(void ); +int (*turnoff_charger)(void ); +}; +I'm all for this patch, but why do you need to place it into
power_supply.handpower_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
Hi Anton,
Quoted 8 lines
The main reason for keeping this stuff in
power_supply.handpower_supply_core.cis to make these interfaces uniform Across multiple charger frameworks and to avoid each charger framework define it's own interfaces. If there is need for new callback They can add to the existing struct defined above and it will available to all the frameworks. Also the work required to support a new Framework will be reduced if the driver already support any one of the existing frameworks.
Rama,
The similar functionalities are exposed by patch https://lkml.org/lkml/2012/10/18/219.
As per Anton's review comments on this patch, I'll be moving the macros to power_supply.h.
Wouldn't that be enough ? ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Re: [PATCH 1/2] power_supply: Add charge control struct in power supply class
Quoted 38 lines · Jenny
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
include/linux/power_supply.h +16
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ Quoted 8 lines
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 4 lines
include/linux/power_supply.h +4
-0+int (*turnon_charger)(void ); +int (*turnoff_charger)(void ); +}; +I'm all for this patch, but why do you need to place it into
power_supply.handpower_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
Hi Anton,
Quoted 8 lines
The main reason for keeping this stuff in
power_supply.handpower_supply_core.cis to make these interfaces uniform Across multiple charger frameworks and to avoid each charger framework define it's own interfaces. If there is need for new callback They can add to the existing struct defined above and it will available to all the frameworks. Also the work required to support a new Framework will be reduced if the driver already support any one of the existing frameworks.
Quoted 5 lines
Rama,
The similar functionalities are exposed by patch https://lkml.org/lkml/2012/10/18/219.
As per Anton's review comments on this patch, I'll be moving the macros topower_supply.h. Wouldn't that be enough ?
Btw, how do these two sets relate to each other? Both seem to control chargers in some way... But yours approach uses properties, which I like more.
I guess you should coordinate on this?
Thanks,
Anton
RE: [PATCH 1/2] power_supply: Add charge control struct in power supply class
Quoted 43 lines
Quoted 29 lines
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
include/linux/power_supply.h +17
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ +int (*turnon_charger)(void );Quoted 8 lines
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 3 lines
include/linux/power_supply.h +3
-0+int (*turnoff_charger)(void ); +}; +I'm all for this patch, but why do you need to place it into
power_supply.handpower_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
Hi Anton,
Quoted 7 lines
Quoted 7 lines
The main reason for keeping this stuff in
power_supply.handpower_supply_core.cis to make these interfaces uniform Across multiple charger frameworks and to avoid each charger framework define it's own interfaces. If there is need for new callback They can add to the existing struct defined above and it will available to all the frameworks. Also the work required to support a new Framework will be reduced if the driver already support any one of theexisting frameworks.
Quoted 5 lines
Quoted 1 line
Rama,
The similar functionalities are exposed by patch
Quoted 8 lines
Quoted 1 line
As per Anton's review comments on this patch, I'll be moving the macros to
power_supply.h.Quoted 1 line
Wouldn't that be enough ?
Btw, how do these two sets relate to each other? Both seem to control chargers in some way... But yours approach uses properties, which I like more.
I guess you should coordinate on this?
Sure Anton we will sync up on this and get back to you. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
RE: [PATCH 1/2] power_supply: Add charge control struct in power supply class
In reply to Tc, JennyQuoted 38 lines
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
include/linux/power_supply.h +17
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void ); + +/* set charging parameters */ +int (*set_in_current_limit)(int uA); +int (*set_charge_current)(int uA); +int (*set_charge_voltage)(int uV); + +/* control battery charging */ +int (*enable_charging)(void ); +int (*disable_charging)(void ); + +/* control VSYS or system supply */ +int (*turnon_charger)(void );Quoted 8 lines
include/linux/power_supply.h struct power_supply_info { · line 250
Quoted 3 lines
include/linux/power_supply.h +3
-0+int (*turnoff_charger)(void ); +}; +I'm all for this patch, but why do you need to place it into
power_supply.handpower_supply_core.c? :) I see nothing generic here, it's pure charger-manager stuff. So, place everything into charger-manager.{c,h}.
Hi Anton,
Quoted 8 lines
The main reason for keeping this stuff in
power_supply.handpower_supply_core.cis to make these interfaces uniform Across multiple charger frameworks and to avoid each charger framework define it's own interfaces. If there is need for new callback They can add to the existing struct defined above and it will available to all the frameworks. Also the work required to support a new Framework will be reduced if the driver already support any one of the existing frameworks.
Quoted 7 lines
Rama,
The similar functionalities are exposed by patch
https://lkml.org/lkml/2012/10/18/219.
As per Anton's review comments on this patch, I'll be moving the macros topower_supply.h.
Wouldn't that be enough ?
Though the macros seem to be fine but I would still think that call back way of interfaces would be More flexible and straightforward.
Thanks,
Ram ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Re: [PATCH 1/2] power_supply: Add charge control struct in power supply class
Quoted 5 lines · Ramakrishna
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
include/linux/power_supply.h +5
-0+struct power_supply_charger_control { +const char *name; +/* get charging status */ +int (*is_charging_enabled)(void ); +int (*is_charger_enabled)(void );
[...]
Quoted 8 lines
Quoted 5 lines
The similar functionalities are exposed by patch
https://lkml.org/lkml/2012/10/18/219.
As per Anton's review comments on this patch, I'll be moving the macros topower_supply.h.
Wouldn't that be enough ?Though the macros seem to be fine but I would still think that call back way of interfaces would be More flexible and straightforward.
We have properties mechanism deployed already, so I'd rather keep it consistent.
p.s. We had 'properties vs. callbacks' debates before, there are pros and cons of each approach. Unless there are some unresolvable issues, let's stick with the original approach. :)