[RFC 3/4] power_supply: Introduce charger control interface

2015-03-06 Thread Jenny TC
Introduce power_supply charger control interfaces to control
charging from charging framework like charger-manager. The interfaces
are similar to the existing power supply get/set interfaces, but
introduce a different set of properties in order to differentiate
itself from other power supply properties which exposed in sysfs

Signed-off-by: Jenny TC 
---
 include/linux/power_supply.h |   28 
 1 file changed, 28 insertions(+)

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 30145d8e..a80a3ef 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -176,6 +176,32 @@ union power_supply_propval {
 struct device;
 struct device_node;
 
+enum psy_charger_control_property {
+   PSY_CHARGER_PROP_ENABLE_CHARGING = 0,
+   PSY_CHARGER_PROP_ENABLE_CHARGER,
+   PSY_CHARGER_PROP_RESET_WDT,
+};
+
+/**
+ * struct power_supply_charger - power supply charger driver
+ * @get_property: get property function to retrieve charger properties defined
+ * in enum power_supply_charger_property
+ * @set_property: get property function to retrieve charger properties defined
+ * in enum power_supply_charger_property
+ *
+ * This structure is used by charger drivers to register with power supply
+ * charging driver
+ */
+
+struct power_supply_charger {
+   int (*get_property)(struct power_supply_charger *psyc,
+   enum psy_charger_control_property pspc,
+   union power_supply_propval *val);
+   int (*set_property)(struct power_supply_charger *psyc,
+   enum psy_charger_control_property pspc,
+   const union power_supply_propval *val);
+};
+
 struct power_supply {
const char *name;
enum power_supply_type type;
@@ -200,6 +226,8 @@ struct power_supply {
void (*external_power_changed)(struct power_supply *psy);
void (*set_charged)(struct power_supply *psy);
 
+   struct power_supply_charger *psy_charger;
+
/*
 * Set if thermal zone should not be created for this power supply.
 * For example for virtual supplies forwarding calls to actual
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC 4/4] charger-manager: Enable psy based charge control

2015-03-06 Thread Jenny TC
At present charger manager support only regulator based charging
control. But most of the charger drivers are registered with power
supply subsystem. This patch adds support for power supply based
charging control along with the regulator based control. With the
patch, charging control can be done either using power supply
interface or with regulator interface. The charging is setup
based on battery parameters received through the battery info
handlers.

Signed-off-by: Jenny TC 
---
 drivers/power/charger-manager.c   |  486 +
 include/linux/power/charger-manager.h |   30 +-
 2 files changed, 399 insertions(+), 117 deletions(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 14b0d85..b455ac2 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -42,6 +42,7 @@ static const char * const default_event_names[] = {
[CM_EVENT_BATT_OUT] = "Battery Pulled Out",
[CM_EVENT_BATT_OVERHEAT] = "Battery Overheat",
[CM_EVENT_BATT_COLD] = "Battery Cold",
+   [CM_EVENT_BATT_TZONE_CHANGE] = "Battery Temp Zone Change",
[CM_EVENT_EXT_PWR_IN_OUT] = "External Power Attach/Detach",
[CM_EVENT_CHG_START_STOP] = "Charging Start/Stop",
[CM_EVENT_OTHERS] = "Other battery events"
@@ -81,6 +82,97 @@ static unsigned long next_polling; /* Next appointed polling 
time */
 static struct workqueue_struct *cm_wq; /* init at driver add */
 static struct delayed_work cm_monitor_work; /* init at driver add */
 
+static inline int psy_set_charger_contol_prop(struct power_supply *psy,
+   enum psy_charger_control_property pscp,
+   const union power_supply_propval *val)
+{
+   struct power_supply_charger *psyc;
+
+   psyc = psy->psy_charger;
+
+   if (psyc && psyc->set_property)
+   return psyc->set_property(psyc, pscp, val);
+
+   return -EINVAL;
+}
+
+static inline int psy_get_charger_contol_prop(struct power_supply *psy,
+   enum psy_charger_control_property pscp,
+   union power_supply_propval *val)
+{
+   struct power_supply_charger *psyc;
+
+   psyc = psy->psy_charger;
+
+   if (psyc && psyc->get_property)
+   return psyc->get_property(psyc, pscp, val);
+
+   return -EINVAL;
+}
+
+static inline int psy_enable_charger(struct power_supply *psy, bool enable)
+{
+   union power_supply_propval prop_val;
+
+   prop_val.intval = enable;
+   return psy_set_charger_contol_prop(psy,
+   PSY_CHARGER_PROP_ENABLE_CHARGER, _val);
+}
+
+static inline int psy_is_charger_enabled(struct power_supply *psy)
+{
+   union power_supply_propval prop_val;
+   int ret;
+
+   ret = psy_get_charger_contol_prop(psy,
+   PSY_CHARGER_PROP_ENABLE_CHARGER, _val);
+   if (ret)
+   return ret;
+
+   return prop_val.intval;
+}
+
+static inline int psy_set_inlimit(struct power_supply *psy, int inlimit)
+{
+   union power_supply_propval prop_val;
+
+   prop_val.intval = inlimit;
+   return power_supply_set_property(psy,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+   _val);
+}
+
+static int enable_charger(struct charger_controller *charger, bool enable)
+{
+   if (charger->regulator_control) {
+   if (enable)
+   return regulator_enable(charger->regulator_control);
+   else
+   return regulator_disable(charger->regulator_control);
+   }
+
+   return psy_enable_charger(charger->psy_control, enable);
+}
+
+static int is_charger_enabled(struct charger_controller *charger)
+{
+   if (charger->regulator_control)
+   return regulator_is_enabled(charger->regulator_control);
+
+   return psy_is_charger_enabled(charger->psy_control);
+}
+
+static int set_input_current(struct charger_cable *cable)
+{
+   if (cable->charger->regulator_control)
+   return regulator_set_current_limit(
+   cable->charger->regulator_control,
+   cable->min_uA, cable->max_uA);
+
+   return psy_set_inlimit(cable->charger->psy_control,
+   cable->max_uA / 1000);
+}
+
 /**
  * is_batt_present - See if the battery presents in place.
  * @cm: the Charger Manager representing the battery.
@@ -328,6 +420,140 @@ static bool is_polling_required(struct charger_manager 
*cm)
return false;
 }
 
+static int get_temp_zone_index(struct psy_charging_obj *cobj, int temp)
+{
+   int i, tzone_count;
+
+   tzone_count = cobj->temp_mon_count > PSY_MAX_TEMP_ZO

[RFC 2/4] power: core: Add generic interface to get battery specification.

2015-03-06 Thread Jenny TC
In power supply system, battery specification's dealt as static
information regardless of battery chainging. And it often assumed
fuelgauge's role to hold battery specification even same driver is
used with different batteries. To make subsystem handles above cases
properly, this patch adds helper functions to manager the battery
specification.

Signed-off-by: Jonghwa Lee 
Signed-off-by: Jenny TC 
---
 drivers/power/power_supply_core.c |   86 +
 include/linux/power_supply.h  |   12 ++
 2 files changed, 98 insertions(+)

diff --git a/drivers/power/power_supply_core.c 
b/drivers/power/power_supply_core.c
index 694e8cd..99c3455 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -650,6 +650,92 @@ static void __exit power_supply_class_exit(void)
 subsys_initcall(power_supply_class_init);
 module_exit(power_supply_class_exit);
 
+/
+ *   Battery information interface  *
+ /
+
+ATOMIC_NOTIFIER_HEAD(psy_battery_info_notifier);
+static LIST_HEAD(psy_battery_info_list);
+
+struct psy_battery_info {
+   struct list_head entry;
+   struct psy_charging_obj *info;
+};
+
+int psy_battery_info_notifier_register(struct notifier_block *nb)
+{
+   return atomic_notifier_chain_register(_battery_info_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(psy_battery_info_notifier_register);
+
+void psy_battery_info_notifier_unregister(struct notifier_block *nb)
+{
+   atomic_notifier_chain_unregister(_battery_info_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(psy_battery_info_notifier_unregister);
+
+struct psy_charging_obj *psy_get_battery_info(const char *name)
+{
+   struct psy_battery_info *battery;
+
+   /* Sanity check */
+   if (!name)
+   goto err_out;
+
+   list_for_each_entry(battery, _battery_info_list, entry) {
+   if (!strcmp(battery->info->name, name))
+   return battery->info;
+   }
+
+err_out:
+   return NULL;
+}
+EXPORT_SYMBOL(psy_get_battery_info);
+
+int psy_register_battery_info(struct psy_charging_obj *info)
+{
+   struct psy_battery_info *battery;
+
+   /* Sanity check */
+   if (!info->name)
+   return -EINVAL;
+
+   /* Check if same data is existed */
+   list_for_each_entry(battery, _battery_info_list, entry)
+   if (!strcmp(battery->info->name, info->name))
+   return -EEXIST;
+
+   battery = kzalloc(sizeof(*battery), GFP_KERNEL);
+   if (!battery)
+   return -ENOMEM;
+
+   battery->info = info;
+   list_add_tail(>entry, _battery_info_list);
+
+   atomic_notifier_call_chain(_battery_info_notifier,
+   PSY_BATT_INFO_REGISTERED, info);
+
+   return 0;
+}
+EXPORT_SYMBOL(psy_register_battery_info);
+
+void psy_unregister_battery_info(struct psy_charging_obj *info)
+{
+   struct psy_battery_info *battery, *tmp;
+
+   list_for_each_entry_safe(battery, tmp, _battery_info_list, entry) {
+   if (battery->info == info) {
+   list_del(>entry);
+   kfree(battery);
+   return;
+   }
+   }
+
+   atomic_notifier_call_chain(_battery_info_notifier,
+   PSY_BATT_INFO_UNREGISTERED, info);
+}
+EXPORT_SYMBOL(psy_unregister_battery_info);
+
 MODULE_DESCRIPTION("Universal power supply monitor class");
 MODULE_AUTHOR("Ian Molton , "
  "Szabolcs Gyurko, "
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 7aada44..30145d8e 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -279,6 +279,11 @@ struct psy_charging_obj {
struct psy_temp_mon_table temp_mon_table[PSY_MAX_TEMP_ZONE];
 };
 
+enum battery_info_notifier_events {
+   PSY_BATT_INFO_REGISTERED,
+   PSY_BATT_INFO_UNREGISTERED,
+};
+
 extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
@@ -311,6 +316,13 @@ extern int power_supply_powers(struct power_supply *psy, 
struct device *dev);
 /* For APM emulation, think legacy userspace. */
 extern struct class *power_supply_class;
 
+/* Battery information helper */
+extern int psy_battery_info_notifier_register(struct notifier_block *);
+extern void psy_battery_info_notifier_unregister(struct notifier_block *);
+extern struct psy_charging_obj *psy_get_battery_info(const char *);
+extern int psy_register_battery_info(struct psy_charging_obj *);
+extern void psy_unregister_battery_info(struct psy_charging_obj *);
+
 static inline bool power_supply_is_amp_property(enum power_supply_property psp)
 {
 

[RFC 1/4] power_supply: Introduce charging object table

2015-03-06 Thread Jenny TC
Charging current (CC) and charging voltage (CV) may vary based on
battery temperature. To support CC and CV for different temperature
zones, defined a charging object which holds the properties related
to battery charging.

Signed-off-by: Jenny TC 
---
 include/linux/power_supply.h |   27 +++
 1 file changed, 27 insertions(+)

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 096dbce..7aada44 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -252,6 +252,33 @@ struct power_supply_info {
int use_for_apm;
 };
 
+
+struct psy_temp_mon_table {
+   int temp_max;
+   int temp_min;
+   int charging_current; /* CC */
+   int charging_voltage; /* CV */
+   /* delta voltage at which charging should restart */
+   int maint_voltage_delta;
+};
+
+#define PSY_MAX_BAT_NAME_LEN 8
+#define PSY_MAX_TEMP_ZONE 6
+
+struct psy_charging_obj {
+   char name[PSY_MAX_BAT_NAME_LEN];
+   int battery_type;
+   int temp_max;
+   int temp_min;
+   int full_condition_soc;
+   int full_condition_capacity;
+   int full_condition_voltage;
+   int iterm; /* charge termination current */
+   /* CC/CV table for different temperature range */
+   int temp_mon_count; /* number of entries in temp_mon_table */
+   struct psy_temp_mon_table temp_mon_table[PSY_MAX_TEMP_ZONE];
+};
+
 extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC 0/4] Enable power supply charging control

2015-03-06 Thread Jenny TC
Enable power supply based charging control for charger manager.
At present charger manager allows to control charging using
regulator interface. This series of patch extends the charger
manager to setup and monitor charging using power supply based
controls. This patch moves the features introduced in
https://lkml.org/lkml/2014/8/13/355  to charger manager.

Jenny TC (4):
  power_supply: Introduce charging object table
  power: core: Add generic interface to get battery specification.
  power_supply: Introduce charger control interface
  charger-manager: Enable psy based charge control

 drivers/power/charger-manager.c   |  486 +
 drivers/power/power_supply_core.c |   86 ++
 include/linux/power/charger-manager.h |   30 +-
 include/linux/power_supply.h  |   67 +
 4 files changed, 552 insertions(+), 117 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC 0/4] Enable power supply charging control

2015-03-06 Thread Jenny TC
Enable power supply based charging control for charger manager.
At present charger manager allows to control charging using
regulator interface. This series of patch extends the charger
manager to setup and monitor charging using power supply based
controls. This patch moves the features introduced in
https://lkml.org/lkml/2014/8/13/355  to charger manager.

Jenny TC (4):
  power_supply: Introduce charging object table
  power: core: Add generic interface to get battery specification.
  power_supply: Introduce charger control interface
  charger-manager: Enable psy based charge control

 drivers/power/charger-manager.c   |  486 +
 drivers/power/power_supply_core.c |   86 ++
 include/linux/power/charger-manager.h |   30 +-
 include/linux/power_supply.h  |   67 +
 4 files changed, 552 insertions(+), 117 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC 3/4] power_supply: Introduce charger control interface

2015-03-06 Thread Jenny TC
Introduce power_supply charger control interfaces to control
charging from charging framework like charger-manager. The interfaces
are similar to the existing power supply get/set interfaces, but
introduce a different set of properties in order to differentiate
itself from other power supply properties which exposed in sysfs

Signed-off-by: Jenny TC jenny...@intel.com
---
 include/linux/power_supply.h |   28 
 1 file changed, 28 insertions(+)

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 30145d8e..a80a3ef 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -176,6 +176,32 @@ union power_supply_propval {
 struct device;
 struct device_node;
 
+enum psy_charger_control_property {
+   PSY_CHARGER_PROP_ENABLE_CHARGING = 0,
+   PSY_CHARGER_PROP_ENABLE_CHARGER,
+   PSY_CHARGER_PROP_RESET_WDT,
+};
+
+/**
+ * struct power_supply_charger - power supply charger driver
+ * @get_property: get property function to retrieve charger properties defined
+ * in enum power_supply_charger_property
+ * @set_property: get property function to retrieve charger properties defined
+ * in enum power_supply_charger_property
+ *
+ * This structure is used by charger drivers to register with power supply
+ * charging driver
+ */
+
+struct power_supply_charger {
+   int (*get_property)(struct power_supply_charger *psyc,
+   enum psy_charger_control_property pspc,
+   union power_supply_propval *val);
+   int (*set_property)(struct power_supply_charger *psyc,
+   enum psy_charger_control_property pspc,
+   const union power_supply_propval *val);
+};
+
 struct power_supply {
const char *name;
enum power_supply_type type;
@@ -200,6 +226,8 @@ struct power_supply {
void (*external_power_changed)(struct power_supply *psy);
void (*set_charged)(struct power_supply *psy);
 
+   struct power_supply_charger *psy_charger;
+
/*
 * Set if thermal zone should not be created for this power supply.
 * For example for virtual supplies forwarding calls to actual
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC 4/4] charger-manager: Enable psy based charge control

2015-03-06 Thread Jenny TC
At present charger manager support only regulator based charging
control. But most of the charger drivers are registered with power
supply subsystem. This patch adds support for power supply based
charging control along with the regulator based control. With the
patch, charging control can be done either using power supply
interface or with regulator interface. The charging is setup
based on battery parameters received through the battery info
handlers.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/charger-manager.c   |  486 +
 include/linux/power/charger-manager.h |   30 +-
 2 files changed, 399 insertions(+), 117 deletions(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 14b0d85..b455ac2 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -42,6 +42,7 @@ static const char * const default_event_names[] = {
[CM_EVENT_BATT_OUT] = Battery Pulled Out,
[CM_EVENT_BATT_OVERHEAT] = Battery Overheat,
[CM_EVENT_BATT_COLD] = Battery Cold,
+   [CM_EVENT_BATT_TZONE_CHANGE] = Battery Temp Zone Change,
[CM_EVENT_EXT_PWR_IN_OUT] = External Power Attach/Detach,
[CM_EVENT_CHG_START_STOP] = Charging Start/Stop,
[CM_EVENT_OTHERS] = Other battery events
@@ -81,6 +82,97 @@ static unsigned long next_polling; /* Next appointed polling 
time */
 static struct workqueue_struct *cm_wq; /* init at driver add */
 static struct delayed_work cm_monitor_work; /* init at driver add */
 
+static inline int psy_set_charger_contol_prop(struct power_supply *psy,
+   enum psy_charger_control_property pscp,
+   const union power_supply_propval *val)
+{
+   struct power_supply_charger *psyc;
+
+   psyc = psy-psy_charger;
+
+   if (psyc  psyc-set_property)
+   return psyc-set_property(psyc, pscp, val);
+
+   return -EINVAL;
+}
+
+static inline int psy_get_charger_contol_prop(struct power_supply *psy,
+   enum psy_charger_control_property pscp,
+   union power_supply_propval *val)
+{
+   struct power_supply_charger *psyc;
+
+   psyc = psy-psy_charger;
+
+   if (psyc  psyc-get_property)
+   return psyc-get_property(psyc, pscp, val);
+
+   return -EINVAL;
+}
+
+static inline int psy_enable_charger(struct power_supply *psy, bool enable)
+{
+   union power_supply_propval prop_val;
+
+   prop_val.intval = enable;
+   return psy_set_charger_contol_prop(psy,
+   PSY_CHARGER_PROP_ENABLE_CHARGER, prop_val);
+}
+
+static inline int psy_is_charger_enabled(struct power_supply *psy)
+{
+   union power_supply_propval prop_val;
+   int ret;
+
+   ret = psy_get_charger_contol_prop(psy,
+   PSY_CHARGER_PROP_ENABLE_CHARGER, prop_val);
+   if (ret)
+   return ret;
+
+   return prop_val.intval;
+}
+
+static inline int psy_set_inlimit(struct power_supply *psy, int inlimit)
+{
+   union power_supply_propval prop_val;
+
+   prop_val.intval = inlimit;
+   return power_supply_set_property(psy,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+   prop_val);
+}
+
+static int enable_charger(struct charger_controller *charger, bool enable)
+{
+   if (charger-regulator_control) {
+   if (enable)
+   return regulator_enable(charger-regulator_control);
+   else
+   return regulator_disable(charger-regulator_control);
+   }
+
+   return psy_enable_charger(charger-psy_control, enable);
+}
+
+static int is_charger_enabled(struct charger_controller *charger)
+{
+   if (charger-regulator_control)
+   return regulator_is_enabled(charger-regulator_control);
+
+   return psy_is_charger_enabled(charger-psy_control);
+}
+
+static int set_input_current(struct charger_cable *cable)
+{
+   if (cable-charger-regulator_control)
+   return regulator_set_current_limit(
+   cable-charger-regulator_control,
+   cable-min_uA, cable-max_uA);
+
+   return psy_set_inlimit(cable-charger-psy_control,
+   cable-max_uA / 1000);
+}
+
 /**
  * is_batt_present - See if the battery presents in place.
  * @cm: the Charger Manager representing the battery.
@@ -328,6 +420,140 @@ static bool is_polling_required(struct charger_manager 
*cm)
return false;
 }
 
+static int get_temp_zone_index(struct psy_charging_obj *cobj, int temp)
+{
+   int i, tzone_count;
+
+   tzone_count = cobj-temp_mon_count  PSY_MAX_TEMP_ZONE ?
+   PSY_MAX_TEMP_ZONE : cobj-temp_mon_count;
+
+   for (i = 0; i  tzone_count; i++) {
+   if (temp =  cobj-temp_mon_table[i].temp_max

[RFC 2/4] power: core: Add generic interface to get battery specification.

2015-03-06 Thread Jenny TC
In power supply system, battery specification's dealt as static
information regardless of battery chainging. And it often assumed
fuelgauge's role to hold battery specification even same driver is
used with different batteries. To make subsystem handles above cases
properly, this patch adds helper functions to manager the battery
specification.

Signed-off-by: Jonghwa Lee jonghwa3@samsung.com
Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/power_supply_core.c |   86 +
 include/linux/power_supply.h  |   12 ++
 2 files changed, 98 insertions(+)

diff --git a/drivers/power/power_supply_core.c 
b/drivers/power/power_supply_core.c
index 694e8cd..99c3455 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -650,6 +650,92 @@ static void __exit power_supply_class_exit(void)
 subsys_initcall(power_supply_class_init);
 module_exit(power_supply_class_exit);
 
+/
+ *   Battery information interface  *
+ /
+
+ATOMIC_NOTIFIER_HEAD(psy_battery_info_notifier);
+static LIST_HEAD(psy_battery_info_list);
+
+struct psy_battery_info {
+   struct list_head entry;
+   struct psy_charging_obj *info;
+};
+
+int psy_battery_info_notifier_register(struct notifier_block *nb)
+{
+   return atomic_notifier_chain_register(psy_battery_info_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(psy_battery_info_notifier_register);
+
+void psy_battery_info_notifier_unregister(struct notifier_block *nb)
+{
+   atomic_notifier_chain_unregister(psy_battery_info_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(psy_battery_info_notifier_unregister);
+
+struct psy_charging_obj *psy_get_battery_info(const char *name)
+{
+   struct psy_battery_info *battery;
+
+   /* Sanity check */
+   if (!name)
+   goto err_out;
+
+   list_for_each_entry(battery, psy_battery_info_list, entry) {
+   if (!strcmp(battery-info-name, name))
+   return battery-info;
+   }
+
+err_out:
+   return NULL;
+}
+EXPORT_SYMBOL(psy_get_battery_info);
+
+int psy_register_battery_info(struct psy_charging_obj *info)
+{
+   struct psy_battery_info *battery;
+
+   /* Sanity check */
+   if (!info-name)
+   return -EINVAL;
+
+   /* Check if same data is existed */
+   list_for_each_entry(battery, psy_battery_info_list, entry)
+   if (!strcmp(battery-info-name, info-name))
+   return -EEXIST;
+
+   battery = kzalloc(sizeof(*battery), GFP_KERNEL);
+   if (!battery)
+   return -ENOMEM;
+
+   battery-info = info;
+   list_add_tail(battery-entry, psy_battery_info_list);
+
+   atomic_notifier_call_chain(psy_battery_info_notifier,
+   PSY_BATT_INFO_REGISTERED, info);
+
+   return 0;
+}
+EXPORT_SYMBOL(psy_register_battery_info);
+
+void psy_unregister_battery_info(struct psy_charging_obj *info)
+{
+   struct psy_battery_info *battery, *tmp;
+
+   list_for_each_entry_safe(battery, tmp, psy_battery_info_list, entry) {
+   if (battery-info == info) {
+   list_del(battery-entry);
+   kfree(battery);
+   return;
+   }
+   }
+
+   atomic_notifier_call_chain(psy_battery_info_notifier,
+   PSY_BATT_INFO_UNREGISTERED, info);
+}
+EXPORT_SYMBOL(psy_unregister_battery_info);
+
 MODULE_DESCRIPTION(Universal power supply monitor class);
 MODULE_AUTHOR(Ian Molton sp...@f2s.com, 
  Szabolcs Gyurko, 
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 7aada44..30145d8e 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -279,6 +279,11 @@ struct psy_charging_obj {
struct psy_temp_mon_table temp_mon_table[PSY_MAX_TEMP_ZONE];
 };
 
+enum battery_info_notifier_events {
+   PSY_BATT_INFO_REGISTERED,
+   PSY_BATT_INFO_UNREGISTERED,
+};
+
 extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
@@ -311,6 +316,13 @@ extern int power_supply_powers(struct power_supply *psy, 
struct device *dev);
 /* For APM emulation, think legacy userspace. */
 extern struct class *power_supply_class;
 
+/* Battery information helper */
+extern int psy_battery_info_notifier_register(struct notifier_block *);
+extern void psy_battery_info_notifier_unregister(struct notifier_block *);
+extern struct psy_charging_obj *psy_get_battery_info(const char *);
+extern int psy_register_battery_info(struct psy_charging_obj *);
+extern void psy_unregister_battery_info(struct psy_charging_obj *);
+
 static inline bool power_supply_is_amp_property(enum power_supply_property

[RFC 1/4] power_supply: Introduce charging object table

2015-03-06 Thread Jenny TC
Charging current (CC) and charging voltage (CV) may vary based on
battery temperature. To support CC and CV for different temperature
zones, defined a charging object which holds the properties related
to battery charging.

Signed-off-by: Jenny TC jenny...@intel.com
---
 include/linux/power_supply.h |   27 +++
 1 file changed, 27 insertions(+)

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 096dbce..7aada44 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -252,6 +252,33 @@ struct power_supply_info {
int use_for_apm;
 };
 
+
+struct psy_temp_mon_table {
+   int temp_max;
+   int temp_min;
+   int charging_current; /* CC */
+   int charging_voltage; /* CV */
+   /* delta voltage at which charging should restart */
+   int maint_voltage_delta;
+};
+
+#define PSY_MAX_BAT_NAME_LEN 8
+#define PSY_MAX_TEMP_ZONE 6
+
+struct psy_charging_obj {
+   char name[PSY_MAX_BAT_NAME_LEN];
+   int battery_type;
+   int temp_max;
+   int temp_min;
+   int full_condition_soc;
+   int full_condition_capacity;
+   int full_condition_voltage;
+   int iterm; /* charge termination current */
+   /* CC/CV table for different temperature range */
+   int temp_mon_count; /* number of entries in temp_mon_table */
+   struct psy_temp_mon_table temp_mon_table[PSY_MAX_TEMP_ZONE];
+};
+
 extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] power_supply: Introduce generic psy charging driver

2014-08-13 Thread Jenny TC
The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire). With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set_property callbacks.

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_charger.txt |  349 
 drivers/power/Kconfig|8 +
 drivers/power/Makefile   |1 +
 drivers/power/power_supply_charger.c | 1206 ++
 drivers/power/power_supply_charger.h |  224 +
 drivers/power/power_supply_core.c|3 +
 include/linux/power/power_supply_charger.h   |  308 +++
 include/linux/power_supply.h |  161 
 8 files changed, 2260 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

diff --git a/Documentation/power/power_supply_charger.txt 
b/Documentation/power/power_supply_charger.txt
new file mode 100644
index 000..6ae59ea
--- /dev/null
+++ b/Documentation/power/power_supply_charger.txt
@@ -0,0 +1,349 @@
+1. Introduction
+===
+
+The Power Supply charging driver connects multiple subsystems
+to do charging in a generic way. The subsystems involves power_supply,
+thermal and battery communication subsystems (e.g. 1wire). With this the
+charging is handled in a generic way by plugging the driver to power supply
+subsystem.
+
+The driver introduces different new features - Battery Identification
+interfaces, pluggable charging algorithms, charger cable arbitrations etc.
+
+In existing driver implementations the charging is done based on the static
+battery characteristics. This is done at the boot time by passing the battery
+properties (max_voltage, capacity) etc. as a platform data to the
+charger/battery driver. But new generation high volt batteries needs to be
+identified dynamically to do charging in a safe manner. The batteries are
+coming with different communication protocols. It becomes necessary to
+communicate with battery and identify it's charging profiles before setup
+charging.
+
+Also the charging algorithms can vary based on the battery characteristics
+and the platform characteristics. To handle charging in a generic way it's
+necessary to support pluggable charging algorithms. Power Supply Charging
+driver selects algorithms based on the type of battery charging profile.
+This is a simple binding and can be improved later. This may be improved to
+select the algorithms based on the platform requirements. Also we can extend
+this driver to plug algorithms from the user space.
+
+The driver also introduces the charger cable arbitration. A charger may
+supports multiple cables, but it may not be able to charge with multiple
+cables at a time (USB/AC/Wireless etc.). The arbitration logic inside the
+driver selects the cable based on it's capabilities and the maximum
+charge current the platform can support.
+
+Also the driver exposes features to control charging on different platform
+states. One such feature is thermal. The driver handles the thermal
+throttling requests for charging and control charging based on the thermal
+subsystem requirements.
+
+Overall this driver removes the charging logic out of the charger chip driver
+and the charger chip driver just listen to the request from the power
+supply charging driver to set the charger properties. This is accomplished
+by exposing get_property and set_property callbacks.
+
+2. Reading Battery charging profile
+===
+
+Power Supply charging driver expose APIs to retrieve battery profile of a
+battery. The battery profile can be read by battery identification driver which
+may be 1wire/I2C/SFI driver. Battery identification driver can register the
+battery profile with the power supply charging driver using the API
+psy_battery_profile_changed(). The driver also exposes API
+psy_get_battery_profile() to retrieve the battery profile which can be
+used by power supply drivers to setup the charging. Also drivers
+can register for battery removal/insertion notifications using
+power_supply_reg_notifier()
+
+3. Use Charging Driver to setup charging

[PATCH 2/3] power_supply: Introduce PSE compliant algorithm

2014-08-13 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  216 
 include/linux/power/power_supply_charger.h |   66 +
 4 files changed, 298 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..cbedebe
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0, temp_range_cnt;
+
+   temp_range_cnt =  pse_mod_bprof->temp_mon_ranges;
+
+   if (!temp_range_cnt || temp_range_cnt > BATT_TEMP_NR_RNG)
+   return -EINVAL;
+
+   /* Basic validity check. Ensure zones are in decreasing order */
+
+   for (i = 0; i < temp_range_cnt - 1; i++) {
+   if (pse_mod_bprof->temp_mon_range[i].temp_max <=
+   pse_mod_bprof->temp_mon_range[i + 1].temp_max)
+   return -EINVAL;
+   }
+
+   if (pse_mod_bprof->temp_mon_range[i].temp_max <=
+   pse_mod_bprof->temp_min)
+   return -EINVAL;
+
+   if ((temp < pse_mod_bprof->temp_min) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_max))
+   return -

[PATCHv12 0/3] power_supply: Introduce power supply charging driver

2014-08-13 Thread Jenny TC
v1: Introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: Fixed review comments, moved macros and inline functions to power_supply.h
v3: Moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup
v11: Few variable name changes for better readability
v12: Enabled polling and RTC wakeup which is supported in charger-manager as
 suggested by Sebastian. Fixed review comments from Sebastian and Pavel

Jenny TC (3):
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  349 +++
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  217 +
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  225 +
 drivers/power/power_supply_core.c|3 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  374 +++
 include/linux/power_supply.h |  161 +++
 11 files changed, 3924 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] power_supply: bq24261 charger driver

2014-08-13 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..f550e50
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCHv12 0/3] power_supply: Introduce power supply charging driver

2014-08-13 Thread Jenny TC
v1: Introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: Fixed review comments, moved macros and inline functions to power_supply.h
v3: Moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup
v11: Few variable name changes for better readability
v12: Enabled polling and RTC wakeup which is supported in charger-manager as
 suggested by Sebastian. Fixed review comments from Sebastian and Pavel

Jenny TC (3):
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  349 +++
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  217 +
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  225 +
 drivers/power/power_supply_core.c|3 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  374 +++
 include/linux/power_supply.h |  161 +++
 11 files changed, 3924 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] power_supply: Introduce generic psy charging driver

2014-08-13 Thread Jenny TC
The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire). With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set_property callbacks.

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_charger.txt |  349 
 drivers/power/Kconfig|8 +
 drivers/power/Makefile   |1 +
 drivers/power/power_supply_charger.c | 1206 ++
 drivers/power/power_supply_charger.h |  224 +
 drivers/power/power_supply_core.c|3 +
 include/linux/power/power_supply_charger.h   |  308 +++
 include/linux/power_supply.h |  161 
 8 files changed, 2260 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

diff --git a/Documentation/power/power_supply_charger.txt 
b/Documentation/power/power_supply_charger.txt
new file mode 100644
index 000..6ae59ea
--- /dev/null
+++ b/Documentation/power/power_supply_charger.txt
@@ -0,0 +1,349 @@
+1. Introduction
+===
+
+The Power Supply charging driver connects multiple subsystems
+to do charging in a generic way. The subsystems involves power_supply,
+thermal and battery communication subsystems (e.g. 1wire). With this the
+charging is handled in a generic way by plugging the driver to power supply
+subsystem.
+
+The driver introduces different new features - Battery Identification
+interfaces, pluggable charging algorithms, charger cable arbitrations etc.
+
+In existing driver implementations the charging is done based on the static
+battery characteristics. This is done at the boot time by passing the battery
+properties (max_voltage, capacity) etc. as a platform data to the
+charger/battery driver. But new generation high volt batteries needs to be
+identified dynamically to do charging in a safe manner. The batteries are
+coming with different communication protocols. It becomes necessary to
+communicate with battery and identify it's charging profiles before setup
+charging.
+
+Also the charging algorithms can vary based on the battery characteristics
+and the platform characteristics. To handle charging in a generic way it's
+necessary to support pluggable charging algorithms. Power Supply Charging
+driver selects algorithms based on the type of battery charging profile.
+This is a simple binding and can be improved later. This may be improved to
+select the algorithms based on the platform requirements. Also we can extend
+this driver to plug algorithms from the user space.
+
+The driver also introduces the charger cable arbitration. A charger may
+supports multiple cables, but it may not be able to charge with multiple
+cables at a time (USB/AC/Wireless etc.). The arbitration logic inside the
+driver selects the cable based on it's capabilities and the maximum
+charge current the platform can support.
+
+Also the driver exposes features to control charging on different platform
+states. One such feature is thermal. The driver handles the thermal
+throttling requests for charging and control charging based on the thermal
+subsystem requirements.
+
+Overall this driver removes the charging logic out of the charger chip driver
+and the charger chip driver just listen to the request from the power
+supply charging driver to set the charger properties. This is accomplished
+by exposing get_property and set_property callbacks.
+
+2. Reading Battery charging profile
+===
+
+Power Supply charging driver expose APIs to retrieve battery profile of a
+battery. The battery profile can be read by battery identification driver which
+may be 1wire/I2C/SFI driver. Battery identification driver can register the
+battery profile with the power supply charging driver using the API
+psy_battery_profile_changed(). The driver also exposes API
+psy_get_battery_profile() to retrieve the battery profile which can be
+used by power supply drivers to setup the charging. Also drivers
+can register for battery removal/insertion notifications using
+power_supply_reg_notifier()
+
+3. Use Charging Driver to setup

[PATCH 3/3] power_supply: bq24261 charger driver

2014-08-13 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..f550e50
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

[PATCH 2/3] power_supply: Introduce PSE compliant algorithm

2014-08-13 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  216 
 include/linux/power/power_supply_charger.h |   66 +
 4 files changed, 298 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..cbedebe
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0, temp_range_cnt;
+
+   temp_range_cnt =  pse_mod_bprof-temp_mon_ranges;
+
+   if (!temp_range_cnt || temp_range_cnt  BATT_TEMP_NR_RNG)
+   return -EINVAL;
+
+   /* Basic validity check. Ensure zones are in decreasing order */
+
+   for (i = 0; i  temp_range_cnt - 1; i++) {
+   if (pse_mod_bprof-temp_mon_range[i].temp_max =
+   pse_mod_bprof-temp_mon_range[i + 1].temp_max)
+   return -EINVAL;
+   }
+
+   if (pse_mod_bprof-temp_mon_range[i].temp_max =
+   pse_mod_bprof-temp_min)
+   return -EINVAL;
+
+   if ((temp  pse_mod_bprof-temp_min) ||
+   (temp  pse_mod_bprof

[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-07-08 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  203 
 include/linux/power/power_supply_charger.h |   66 +
 4 files changed, 285 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..fbc9ea6
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt;
+
+   temp_range_cnt =  min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+   if ((temp < pse_mod_bprof->temp_min) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_max))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_max)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   return (cur > 0) && (cur <= iterm) &&
+   ((volt * 100)  >= (FULL_CV_MIN * cv));
+}
+
+static inline bool is_battery_full(struct psy_batt_context *batt_cxt,

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-07-08 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT - input current limit programmed
by charger. Indicates the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT - Charge termination current used
to detect the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv11 0/4] power_supply: Introduce power supply charging driver

2014-07-08 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup
v11: Few variable name changes for better readability

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  202 
 drivers/power/power_supply_charger.c | 1016 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  372 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3753 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4] power_supply: bq24261 charger driver

2014-07-08 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..4de73e1
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCH 4/4] power_supply: bq24261 charger driver

2014-07-08 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..4de73e1
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-07-08 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT - input current limit programmed
by charger. Indicates the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT - Charge termination current used
to detect the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv11 0/4] power_supply: Introduce power supply charging driver

2014-07-08 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup
v11: Few variable name changes for better readability

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  202 
 drivers/power/power_supply_charger.c | 1016 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  372 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3753 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-07-08 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  203 
 include/linux/power/power_supply_charger.h |   66 +
 4 files changed, 285 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..fbc9ea6
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt;
+
+   temp_range_cnt =  min_t(u16, pse_mod_bprof-temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+   if ((temp  pse_mod_bprof-temp_min) ||
+   (temp  pse_mod_bprof-temp_mon_range[0].temp_max))
+   return -EINVAL;
+
+   for (i = 0; i  temp_range_cnt; ++i)
+   if (temp  pse_mod_bprof-temp_mon_range[i].temp_max)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   return (cur  0)  (cur = iterm) 
+   ((volt * 100)  = (FULL_CV_MIN * cv));
+}
+
+static inline bool is_battery_full

Re: Power Supply Subsystem Maintainer

2014-07-01 Thread Jenny Tc
Andrew Morton,

Appreciate your help to sort out the power supply maintainer issue. The
subsystem is not active after February 2014. No response from maintainer and 
the 
last commit on git://git.infradead.org/battery-2.6 was on 2014-02-01. Appreciate
your help.

-Jenny

On Mon, Jun 30, 2014 at 01:26:46PM +0200, Belisko Marek wrote:
> Same on my side (some pending patches) but there was already
> discussion: https://lkml.org/lkml/2014/5/16/504
> 
> On Mon, Jun 30, 2014 at 1:16 PM, Jenny Tc  wrote:
> > Hi all,
> >
> > I have few pending patches on power supply subsystem. So far I haven't seen
> > any response from the power supply maintainers. As per the MAINTAINERS 
> > entry,
> > the susbsystem is owned by "Dmitry Eremin-Solenikov ".
> > But not sure he still maintains the susbsystem, as I don't see any response
> > from him. Also the last commit I could see on 
> > git://git.infradead.org/battery-2.6
> > is on Feb this year.  I would appreciate if anyone could clarify who really
> > maintains the power supply subsystem.
> >
> > Thanks
> > Jenny
> >
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Power Supply Subsystem Maintainer

2014-07-01 Thread Jenny Tc
Andrew Morton,

Appreciate your help to sort out the power supply maintainer issue. The
subsystem is not active after February 2014. No response from maintainer and 
the 
last commit on git://git.infradead.org/battery-2.6 was on 2014-02-01. Appreciate
your help.

-Jenny

On Mon, Jun 30, 2014 at 01:26:46PM +0200, Belisko Marek wrote:
 Same on my side (some pending patches) but there was already
 discussion: https://lkml.org/lkml/2014/5/16/504
 
 On Mon, Jun 30, 2014 at 1:16 PM, Jenny Tc jenny...@intel.com wrote:
  Hi all,
 
  I have few pending patches on power supply subsystem. So far I haven't seen
  any response from the power supply maintainers. As per the MAINTAINERS 
  entry,
  the susbsystem is owned by Dmitry Eremin-Solenikov dbarysh...@gmail.com.
  But not sure he still maintains the susbsystem, as I don't see any response
  from him. Also the last commit I could see on 
  git://git.infradead.org/battery-2.6
  is on Feb this year.  I would appreciate if anyone could clarify who really
  maintains the power supply subsystem.
 
  Thanks
  Jenny
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Power Supply Subsystem Maintainer

2014-06-30 Thread Jenny Tc
Hi all,

I have few pending patches on power supply subsystem. So far I haven't seen any 
response from the power supply maintainers. As per the MAINTAINERS entry, the 
susbsystem is owned by "Dmitry Eremin-Solenikov ". But 
not sure he still maintains the susbsystem, as I don't see any response from 
him. Also the last commit I could see on git://git.infradead.org/battery-2.6 is 
on Feb this year.  I would appreciate if anyone could clarify who really 
maintains the power supply subsystem.

Thanks
Jenny

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-06-30 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   15 +++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  202 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 281 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..6ec4873
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt;
+
+   temp_range_cnt =  min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+   if ((temp < pse_mod_bprof->temp_low_lim) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   return (cur > 0) && (cur <= iterm) &&
+   ((volt * 100)  >= (FULL_CV_MIN * cv));
+}
+
+static inline bool is_battery_full(struct psy_batt_con

[PATCH 4/4] power_supply: bq24261 charger driver

2014-06-30 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1351 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1387 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..c21ea04
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1351 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-06-30 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv10 0/4] power_supply: Introduce power supply charging driver

2014-06-30 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1351 ++
 drivers/power/charging_algo_pse.c|  202 
 drivers/power/power_supply_charger.c | 1016 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  370 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3754 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-06-30 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv10 0/4] power_supply: Introduce power supply charging driver

2014-06-30 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization
v10: Fixed bug in algorithm lookup

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1351 ++
 drivers/power/charging_algo_pse.c|  202 
 drivers/power/power_supply_charger.c | 1016 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  370 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3754 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4] power_supply: bq24261 charger driver

2014-06-30 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1351 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1387 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..c21ea04
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1351 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-06-30 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   15 +++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  202 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 281 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..6ec4873
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt;
+
+   temp_range_cnt =  min_t(u16, pse_mod_bprof-temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+   if ((temp  pse_mod_bprof-temp_low_lim) ||
+   (temp  pse_mod_bprof-temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i  temp_range_cnt; ++i)
+   if (temp  pse_mod_bprof-temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   return (cur  0)  (cur = iterm) 
+   ((volt * 100)  = (FULL_CV_MIN * cv));
+}
+
+static inline bool

Power Supply Subsystem Maintainer

2014-06-30 Thread Jenny Tc
Hi all,

I have few pending patches on power supply subsystem. So far I haven't seen any 
response from the power supply maintainers. As per the MAINTAINERS entry, the 
susbsystem is owned by Dmitry Eremin-Solenikov dbarysh...@gmail.com. But 
not sure he still maintains the susbsystem, as I don't see any response from 
him. Also the last commit I could see on git://git.infradead.org/battery-2.6 is 
on Feb this year.  I would appreciate if anyone could clarify who really 
maintains the power supply subsystem.

Thanks
Jenny

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4] power_supply: bq24261 charger driver

2014-06-19 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..659ac24
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-06-19 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  211 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 290 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..2b13c74
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp < pse_mod_bprof->temp_low_lim) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel("%s:current=%ld pse_mod_bprof->chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld",
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN * cv));
+
+   return (cur > 0) &&am

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-06-19 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv9 0/4] power_supply: Introduce power supply charging driver

2014-06-19 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1022 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  370 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3759 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv9 0/4] power_supply: Introduce power supply charging driver

2014-06-19 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE
v9: Removed string lookups, static cable initialization

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  350 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   33 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261_charger.c  | 1348 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1022 +++
 drivers/power/power_supply_charger.h |  226 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  370 +++
 include/linux/power_supply.h |  165 
 13 files changed, 3759 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-06-19 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  211 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 290 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..2b13c74
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof-temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp  pse_mod_bprof-temp_low_lim) ||
+   (temp  pse_mod_bprof-temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i  temp_range_cnt; ++i)
+   if (temp  pse_mod_bprof-temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel(%s:current=%ld pse_mod_bprof-chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld,
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-06-19 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4] power_supply: bq24261 charger driver

2014-06-19 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261_charger.c   | 1348 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1384 insertions(+)
 create mode 100644 drivers/power/bq24261_charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..a6e9897 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261_charger.c b/drivers/power/bq24261_charger.c
new file mode 100644
index 000..659ac24
--- /dev/null
+++ b/drivers/power/bq24261_charger.c
@@ -0,0 +1,1348 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

Re: [jenny...@intel.com: [RFC] power_supply: Introduce generic psy charging driver]

2014-05-07 Thread Jenny Tc
> > +static struct charger_cable cable_list[] = {
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_SDP,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_CDP,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_DCP,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_ACA,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_ACA_DOCK,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_SE1,
> > +},
> > +   {
> > +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_AC,
> > +},
> > +};
> 
> Can we get rid of this?

Agreed, can initialize it runtime.

> > +   for (i = 0; i < psy->num_supplicants; i++) {
> > +   charger_context->supplied_to_psy[cnt++] =
> > +   power_supply_get_by_name(psy->supplied_to[i]);
> > +   charger_context->supplied_to_psy[cnt] = NULL;
> > +   }
> > +}
> 
> Still some name lookups to be killed.

The look up is only once, when the charger/battery driver is registered.
The supplied_to is defined as character pointer in struct power_supply.

char **supplied_to;
size_t num_supplicants;

This allows the drivers to define the supplied_to argument even if the
supplied_to driver is loaded at later stage. So the name lookup cannot be
avoided. But it is optimized to do lookup only once
> 
> > +   for (i = 0; i < pst->num_supplicants; i++) {
> > +   psb = power_supply_get_by_name(pst->supplied_to[i]);
> > +   if (psb == psy) {
> > +   batt_context->supplied_by_psy[cnt++] = pst;
> > +   batt_context->supplied_by_psy[cnt] = NULL;
> > +   break;
> > +   }
> > +   }
> > +   }
> 
> And here.

Same here
> > +   charger_context = (struct psy_charger_context *)psy->data;
> 
> > +static inline bool is_supplied_to_has_ext_pwr_changed(struct power_supply 
> > *psy)
> > +{
> > +   int i;
> > +   struct power_supply *psb;
> > +   bool is_pwr_changed_defined = true;
> > +
> > +   for (i = 0; i < psy->num_supplicants; i++) {
> > +   psb =
> > +   power_supply_get_by_name(psy->
> > +supplied_to[i]);
> > +   if (psb && !psb->external_power_changed)
> > +   is_pwr_changed_defined &= false;
> > +   }
> 
> You did not really get rid of the name lookups..

This lookup can be removed
> > +#define PSY_MAX_CV(psy) \
> > +   psy_get_ps_int_property(psy,\
> > +   POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX)
> > +#define PSY_VOLTAGE_NOW(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW)
> > +#define PSY_VOLTAGE_OCV(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_VOLTAGE_OCV)
> > +#define PSY_CURRENT_NOW(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_CURRENT_NOW)
> > +#define PSY_STATUS(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_STATUS)
> > +#define PSY_TEMPERATURE(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_TEMP)
> > +#define PSY_BATTERY_TYPE(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_TECHNOLOGY)
> > +#define PSY_ONLINE(psy) \
> > +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_ONLINE)
> 
> This looks like bad idea. Just opencode it.

This was to make it more readable, and avoids open codes in multiple places.
Initially Anton had positive thoughts about this. Isn't it more readable with
the macros?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [jenny...@intel.com: [RFC] power_supply: Introduce generic psy charging driver]

2014-05-07 Thread Jenny Tc
  +static struct charger_cable cable_list[] = {
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_SDP,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_CDP,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_DCP,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_USB_ACA,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_ACA_DOCK,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_SE1,
  +},
  +   {
  +.psy_cable_type = PSY_CHARGER_CABLE_TYPE_AC,
  +},
  +};
 
 Can we get rid of this?

Agreed, can initialize it runtime.

  +   for (i = 0; i  psy-num_supplicants; i++) {
  +   charger_context-supplied_to_psy[cnt++] =
  +   power_supply_get_by_name(psy-supplied_to[i]);
  +   charger_context-supplied_to_psy[cnt] = NULL;
  +   }
  +}
 
 Still some name lookups to be killed.

The look up is only once, when the charger/battery driver is registered.
The supplied_to is defined as character pointer in struct power_supply.

char **supplied_to;
size_t num_supplicants;

This allows the drivers to define the supplied_to argument even if the
supplied_to driver is loaded at later stage. So the name lookup cannot be
avoided. But it is optimized to do lookup only once
 
  +   for (i = 0; i  pst-num_supplicants; i++) {
  +   psb = power_supply_get_by_name(pst-supplied_to[i]);
  +   if (psb == psy) {
  +   batt_context-supplied_by_psy[cnt++] = pst;
  +   batt_context-supplied_by_psy[cnt] = NULL;
  +   break;
  +   }
  +   }
  +   }
 
 And here.

Same here
  +   charger_context = (struct psy_charger_context *)psy-data;
 
  +static inline bool is_supplied_to_has_ext_pwr_changed(struct power_supply 
  *psy)
  +{
  +   int i;
  +   struct power_supply *psb;
  +   bool is_pwr_changed_defined = true;
  +
  +   for (i = 0; i  psy-num_supplicants; i++) {
  +   psb =
  +   power_supply_get_by_name(psy-
  +supplied_to[i]);
  +   if (psb  !psb-external_power_changed)
  +   is_pwr_changed_defined = false;
  +   }
 
 You did not really get rid of the name lookups..

This lookup can be removed
  +#define PSY_MAX_CV(psy) \
  +   psy_get_ps_int_property(psy,\
  +   POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX)
  +#define PSY_VOLTAGE_NOW(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW)
  +#define PSY_VOLTAGE_OCV(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_VOLTAGE_OCV)
  +#define PSY_CURRENT_NOW(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_CURRENT_NOW)
  +#define PSY_STATUS(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_STATUS)
  +#define PSY_TEMPERATURE(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_TEMP)
  +#define PSY_BATTERY_TYPE(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_TECHNOLOGY)
  +#define PSY_ONLINE(psy) \
  +   psy_get_ps_int_property(psy, POWER_SUPPLY_PROP_ONLINE)
 
 This looks like bad idea. Just opencode it.

This was to make it more readable, and avoids open codes in multiple places.
Initially Anton had positive thoughts about this. Isn't it more readable with
the macros?


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] power_supply: Introduce generic psy charging driver

2014-04-28 Thread Jenny Tc
On Mon, Apr 28, 2014 at 07:56:06PM +0200, Pavel Machek wrote:
> On Mon 2014-04-28 22:24:36, Jenny Tc wrote:
> > Dmitry/Pavel,
> > 
> > Request your feedback on this. Fixed the comments from Pavel and waiting 
> > for 
> > your feedback on the changes
> 
> IIRC, my latest comments were "this is completely misdesigned, it is
> using strings and table searches where it should use pointers". Did
> that change?

Yes, that's changed.

> 
> -- 
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) 
> http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] power_supply: Introduce generic psy charging driver

2014-04-28 Thread Jenny Tc
On Mon, Apr 28, 2014 at 07:56:06PM +0200, Pavel Machek wrote:
 On Mon 2014-04-28 22:24:36, Jenny Tc wrote:
  Dmitry/Pavel,
  
  Request your feedback on this. Fixed the comments from Pavel and waiting 
  for 
  your feedback on the changes
 
 IIRC, my latest comments were this is completely misdesigned, it is
 using strings and table searches where it should use pointers. Did
 that change?

Yes, that's changed.

 
 -- 
 (english) http://www.livejournal.com/~pavelmachek
 (cesky, pictures) 
 http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv8 2/4] power_supply: Introduce generic psy charging driver

2014-03-09 Thread Jenny Tc
On Fri, Mar 07, 2014 at 09:25:20PM +0100, Pavel Machek wrote:

Hi,

> > The Power Supply charging driver connects multiple subsystems
> > to do charging in a generic way. The subsystems involves power_supply,
> > thermal and battery communication subsystems (1wire).With this the charging 
> > is
> > handled in a generic way.
> 
> " " after ".", please.

Will fix in next patch set

> > +
> > +The Power Supply charging driver connects multiple subsystems
> > +to do charging in a generic way. The subsystems involves power_supply,
> > +thermal and battery communication subsystems (1wire).With this the 
> > charging is
> 
> Here too.

Same here
> 
> 
> 
> > +
> > +The driver introduces different new features - Battery Identification
> > +interfaces, pluggable charging algorithms, charger cable arbitrations etc.
> > +
> > +In existing driver implementations the charging is done based on the static
> > +battery characteristics. This is done at the boot time by passing the 
> > battery
> > +properties (max_voltage, capacity) etc. as a platform data to the
> 
> -> (max_voltage, capacity, etc.)

Same here
> 
> > --- a/drivers/power/Kconfig
> > +++ b/drivers/power/Kconfig
> > @@ -14,6 +14,14 @@ config POWER_SUPPLY_DEBUG
> >   Say Y here to enable debugging messages for power supply class
> >   and drivers.
> >  
> > +config POWER_SUPPLY_CHARGER
> > +   bool "Power Supply Charger"
> > +   help
> > + Say Y here to enable the power supply charging control driver. 
> > Charging
> > + control supports charging in a generic way. This allows the charger
> > + drivers to keep the charging logic outside and the charger driver
> > + just need to abstract the charger hardware.
> > +
> 
> Umm. This is not too helpful for our users.

Will add more text to help users.
> 
> > +struct psy_charger_context {
> > +   bool is_usb_cable_evt_reg;
> > +   int psyc_cnt;
> > +   int batt_status;
> > +   /* cache battery and charger properties */
> > +   struct list_head chrgr_cache_lst;
> > +   struct list_head batt_cache_lst;
> > +   struct mutex event_lock;
> > +   struct list_head event_queue;
> > +   struct psy_batt_chrg_prof batt_property;
> > +   wait_queue_head_t wait_chrg_enable;
> > +   spinlock_t battid_spinlock;
> > +   spinlock_t event_queue_lock;
> > +   struct work_struct event_work;
> > +};
> > +
> > +struct charger_cable {
> > +   struct psy_cable_props cable_props;
> > +   enum psy_charger_cable_type psy_cable_type;
> > +};
> > +
> > +static struct psy_charger_context psy_chrgr;
> 
> You still miss some wovels here. Sometimes it imakes it unlear: 
> chrg is charge? charger?

chrgr means charger, chrg means charge. Isn't it used consistently?. Can fix it 
if
it's really annoying. Please suggest.
> 
> 
> > +static inline bool psy_is_charger_prop_changed(struct psy_charger_props 
> > prop,
> > +   struct psy_charger_props cache_prop)
> > +{
> > +   /* if online/prsent/health/is_charging is changed, then return true */
> 
> Typo - present.

Will fix in next patch set
> 
> > +static inline void cache_chrgr_prop(struct psy_charger_props 
> > *chrgr_prop_new)
> > +{
> > +   struct psy_charger_props *chrgr_cache;
> > +
> > +   list_for_each_entry(chrgr_cache, _chrgr.chrgr_cache_lst, node) {
> > +   if (!strcmp(chrgr_cache->name, chrgr_prop_new->name))
> > +   goto update_props;
> > +   }
> 
> Interesting use of goto. Maybe update_properties should be separate function?

I feel, having a function just for few assignments may not be a good idea.
What about having memcpy?
> 
> > +update_props:
> > +   chrgr_cache->is_charging = chrgr_prop_new->is_charging;
> > +   chrgr_cache->online = chrgr_prop_new->online;
> > +   chrgr_cache->health = chrgr_prop_new->health;
> > +   chrgr_cache->present = chrgr_prop_new->present;
> > +   chrgr_cache->cable = chrgr_prop_new->cable;
> > +   chrgr_cache->tstamp = chrgr_prop_new->tstamp;
> > +   chrgr_cache->psyc = chrgr_prop_new->psyc;
> > +}
> > +
> > +   chrgr_prop.psyc = chrgr_prop_cache.psyc;
> > +   cache_chrgr_prop(_prop);
> > +   return true;
> > +}
> > +static void cache_successive_samples(long *sample_array, long new_sample)
> > +{
> 
> Add empty line between the functions.

Ok..Will fix in next patch set
> 
> > +static inline void cache_bat_prop(struct psy_batt_props *bat_prop_new)
> > +{
> > +   struct psy_batt_props *bat_cache;
> > +
> > +   /*
> > +   *  Find entry in cache list. If an entry is located update
> > +   *  the existing entry else create new entry in the list
> > +   */
> > +   list_for_each_entry(bat_cache, _chrgr.batt_cache_lst, node) {
> > +   if (!strcmp(bat_cache->name, bat_prop_new->name))
> > +   goto update_props;
> > +   }
> > +
> > +   bat_cache = kzalloc(sizeof(*bat_cache), GFP_KERNEL);
> 
> What is it with all the caching? Is it good idea to have caches
> indexed by strings? Can't you go without caching, or attach caches to
> some structure? Interesting goto again.

Cache is to store 

Re: [PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-09 Thread Jenny Tc
On Fri, Mar 07, 2014 at 09:12:40PM +0100, Pavel Machek wrote:
> On Fri 2014-03-07 10:59:31, Jenny TC wrote:
> > Add new power supply properties for input current, charge termination
> > current, min and max temperature
> > 
> > POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
> > POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature
> > 
> > POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. 
> > Indicates
> > the input current for a charging source.
> > 
> > POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to 
> > detect
> > the end of charge condition
> > 
> > Signed-off-by: Jenny TC 
> 
> The patch no longer matches the description, otherwise it looks good.

Will fix it in next patch set
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-09 Thread Jenny Tc
On Fri, Mar 07, 2014 at 09:12:40PM +0100, Pavel Machek wrote:
 On Fri 2014-03-07 10:59:31, Jenny TC wrote:
  Add new power supply properties for input current, charge termination
  current, min and max temperature
  
  POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
  POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature
  
  POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. 
  Indicates
  the input current for a charging source.
  
  POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to 
  detect
  the end of charge condition
  
  Signed-off-by: Jenny TC jenny...@intel.com
 
 The patch no longer matches the description, otherwise it looks good.

Will fix it in next patch set
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv8 2/4] power_supply: Introduce generic psy charging driver

2014-03-09 Thread Jenny Tc
On Fri, Mar 07, 2014 at 09:25:20PM +0100, Pavel Machek wrote:

Hi,

  The Power Supply charging driver connects multiple subsystems
  to do charging in a generic way. The subsystems involves power_supply,
  thermal and battery communication subsystems (1wire).With this the charging 
  is
  handled in a generic way.
 
   after ., please.

Will fix in next patch set

  +
  +The Power Supply charging driver connects multiple subsystems
  +to do charging in a generic way. The subsystems involves power_supply,
  +thermal and battery communication subsystems (1wire).With this the 
  charging is
 
 Here too.

Same here
 
 
 
  +
  +The driver introduces different new features - Battery Identification
  +interfaces, pluggable charging algorithms, charger cable arbitrations etc.
  +
  +In existing driver implementations the charging is done based on the static
  +battery characteristics. This is done at the boot time by passing the 
  battery
  +properties (max_voltage, capacity) etc. as a platform data to the
 
 - (max_voltage, capacity, etc.)

Same here
 
  --- a/drivers/power/Kconfig
  +++ b/drivers/power/Kconfig
  @@ -14,6 +14,14 @@ config POWER_SUPPLY_DEBUG
Say Y here to enable debugging messages for power supply class
and drivers.
   
  +config POWER_SUPPLY_CHARGER
  +   bool Power Supply Charger
  +   help
  + Say Y here to enable the power supply charging control driver. 
  Charging
  + control supports charging in a generic way. This allows the charger
  + drivers to keep the charging logic outside and the charger driver
  + just need to abstract the charger hardware.
  +
 
 Umm. This is not too helpful for our users.

Will add more text to help users.
 
  +struct psy_charger_context {
  +   bool is_usb_cable_evt_reg;
  +   int psyc_cnt;
  +   int batt_status;
  +   /* cache battery and charger properties */
  +   struct list_head chrgr_cache_lst;
  +   struct list_head batt_cache_lst;
  +   struct mutex event_lock;
  +   struct list_head event_queue;
  +   struct psy_batt_chrg_prof batt_property;
  +   wait_queue_head_t wait_chrg_enable;
  +   spinlock_t battid_spinlock;
  +   spinlock_t event_queue_lock;
  +   struct work_struct event_work;
  +};
  +
  +struct charger_cable {
  +   struct psy_cable_props cable_props;
  +   enum psy_charger_cable_type psy_cable_type;
  +};
  +
  +static struct psy_charger_context psy_chrgr;
 
 You still miss some wovels here. Sometimes it imakes it unlear: 
 chrg is charge? charger?

chrgr means charger, chrg means charge. Isn't it used consistently?. Can fix it 
if
it's really annoying. Please suggest.
 
 
  +static inline bool psy_is_charger_prop_changed(struct psy_charger_props 
  prop,
  +   struct psy_charger_props cache_prop)
  +{
  +   /* if online/prsent/health/is_charging is changed, then return true */
 
 Typo - present.

Will fix in next patch set
 
  +static inline void cache_chrgr_prop(struct psy_charger_props 
  *chrgr_prop_new)
  +{
  +   struct psy_charger_props *chrgr_cache;
  +
  +   list_for_each_entry(chrgr_cache, psy_chrgr.chrgr_cache_lst, node) {
  +   if (!strcmp(chrgr_cache-name, chrgr_prop_new-name))
  +   goto update_props;
  +   }
 
 Interesting use of goto. Maybe update_properties should be separate function?

I feel, having a function just for few assignments may not be a good idea.
What about having memcpy?
 
  +update_props:
  +   chrgr_cache-is_charging = chrgr_prop_new-is_charging;
  +   chrgr_cache-online = chrgr_prop_new-online;
  +   chrgr_cache-health = chrgr_prop_new-health;
  +   chrgr_cache-present = chrgr_prop_new-present;
  +   chrgr_cache-cable = chrgr_prop_new-cable;
  +   chrgr_cache-tstamp = chrgr_prop_new-tstamp;
  +   chrgr_cache-psyc = chrgr_prop_new-psyc;
  +}
  +
  +   chrgr_prop.psyc = chrgr_prop_cache.psyc;
  +   cache_chrgr_prop(chrgr_prop);
  +   return true;
  +}
  +static void cache_successive_samples(long *sample_array, long new_sample)
  +{
 
 Add empty line between the functions.

Ok..Will fix in next patch set
 
  +static inline void cache_bat_prop(struct psy_batt_props *bat_prop_new)
  +{
  +   struct psy_batt_props *bat_cache;
  +
  +   /*
  +   *  Find entry in cache list. If an entry is located update
  +   *  the existing entry else create new entry in the list
  +   */
  +   list_for_each_entry(bat_cache, psy_chrgr.batt_cache_lst, node) {
  +   if (!strcmp(bat_cache-name, bat_prop_new-name))
  +   goto update_props;
  +   }
  +
  +   bat_cache = kzalloc(sizeof(*bat_cache), GFP_KERNEL);
 
 What is it with all the caching? Is it good idea to have caches
 indexed by strings? Can't you go without caching, or attach caches to
 some structure? Interesting goto again.

Cache is to store previous battery properties. On receiving a new event
compare the properties with cached value to decide charging state
(charging/not charging/full etc.) and to control charging. There is added
saving with caching. If the previous and current 

Re: power_supply mailing list

2014-03-06 Thread Jenny Tc
On Sat, Feb 01, 2014 at 09:06:48AM -0700, Dmitry Eremin-Solenikov wrote:
> Hello,
> 
> On Thu, Jan 30, 2014 at 10:46 PM, Jenny Tc  wrote:
> >
> > Do we have any mailing list for power_supply subsystem? If not what about 
> > having
> > one - linux-power-sup...@vger.kernel.org?
> 
> I'm not sure that if that ML will have enough traffic to be fully
> usefull or enough
> reviewers on it. However as currently most of the power_supply patches receive
> a long list of To and Cc people, let's try that ML.
> 
> 
> David, could you please create a mailing list for power_supply discussions?
> 

Dmitry/David,

Any update on this. Appreciate your help on this.

Thanks
Jenny
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 4/4] power_supply: bq24261 charger driver

2014-03-06 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261-charger.c   | 1350 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1386 insertions(+)
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..9dde895 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261-charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261-charger.c b/drivers/power/bq24261-charger.c
new file mode 100644
index 000..187c1fe
--- /dev/null
+++ b/drivers/power/bq24261-charger.c
@@ -0,0 +1,1350 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-06 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 0/4] power_supply: Introduce power supply charging driver

2014-03-06 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE

The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire).With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set property callbacks.

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  353 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   31 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261-charger.c  | 1350 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  218 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  341 +++
 include/linux/power_supply.h |  164 
 13 files changed, 3888 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-06 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  204 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 283 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..ac95885
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp < pse_mod_bprof->temp_low_lim) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel("%s:current=%ld pse_mod_bprof->chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld",
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN * cv));
+
+   return (cur > 0) &&am

Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver

2014-03-06 Thread Jenny Tc
On Fri, Mar 07, 2014 at 11:03:02AM +0800, Linus Walleij wrote:
> On Fri, Feb 28, 2014 at 12:27 PM, Jenny Tc  wrote:
> > On Thu, Feb 27, 2014 at 09:08:01PM +0100, Linus Walleij wrote:
> >> On Thu, Feb 20, 2014 at 6:53 AM, Jenny TC  wrote:
> >>
> >> > +++ b/include/linux/power/power_supply_charger.h
> >>
> >> > +#define MAX_CUR_VOLT_SAMPLES 3
> >> > +#define DEF_CUR_VOLT_SAMPLE_JIFF (30*HZ)
> >>
> >> Why are things defined in Jiffies like this insead of seconds, milliseconds
> >> etc? This will vary with the current operating frequency of the system,
> >> why should physical measurements do that?
> >
> > Is it fine if I use msecs_to_jiffies(3)?
> 
> Keep the
> #define DEF_CUR_VOLT_SAMPLE_PERIOD 3
> 
> Then use msecs_to_jiffies(DEF_CUR_VOLT_SAMPLE_PERIOD)
> in the call site.
> 

Ok..fine will fix it in next patch set
> >> > +enum psy_charger_cable_event {
> >> > +   PSY_CHARGER_CABLE_EVENT_DISCONNECT = 0,
> >> > +   PSY_CHARGER_CABLE_EVENT_CONNECT,
> >> > +   PSY_CHARGER_CABLE_EVENT_UPDATE,
> >> > +   PSY_CHARGER_CABLE_EVENT_RESUME,
> >> > +   PSY_CHARGER_CABLE_EVENT_SUSPEND,
> >> > +};
> >> > +
> >> > +enum psy_charger_cable_type {
> >> > +   PSY_CHARGER_CABLE_TYPE_NONE = 0,
> >> > +   PSY_CHARGER_CABLE_TYPE_USB_SDP = 1 << 0,
> >> > +   PSY_CHARGER_CABLE_TYPE_USB_DCP = 1 << 1,
> >> > +   PSY_CHARGER_CABLE_TYPE_USB_CDP = 1 << 2,
> >> > +   PSY_CHARGER_CABLE_TYPE_USB_ACA = 1 << 3,
> >> > +   PSY_CHARGER_CABLE_TYPE_AC = 1 << 4,
> >> > +   PSY_CHARGER_CABLE_TYPE_ACA_DOCK = 1 << 5,
> >> > +   PSY_CHARGER_CABLE_TYPE_ACA_A = 1 << 6,
> >> > +   PSY_CHARGER_CABLE_TYPE_ACA_B = 1 << 7,
> >> > +   PSY_CHARGER_CABLE_TYPE_ACA_C = 1 << 8,
> >> > +   PSY_CHARGER_CABLE_TYPE_SE1 = 1 << 9,
> >> > +   PSY_CHARGER_CABLE_TYPE_MHL = 1 << 10,
> >> > +   PSY_CHARGER_CABLE_TYPE_B_DEVICE = 1 << 11,
> >> > +};
> >>
> >> Why is this even an enum? It is clearly bitfields. I would just:
> >>
> >> #include 
> >>
> >> #define PSY_CHARGER_CABLE_TYPE_NONE 0x0
> >> #define PSY_CHARGER_CABLE_TYPE_USB_SDP BIT(0)
> >> #define PSY_CHARGER_CABLE_TYPE_USB_DCP BIT(1)
> >> (etc)
> >
> > This is to ensure type checks when the cable types are handled, #defines 
> > will
> > not help in type checks.
> 
> Type checks with static code check tools? But misrepresenting
> a bitfield as an enum just to satisfy a static code checker is not
> OK IMO.

not just for tools, compile time type checks also.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-06 Thread Jenny Tc
On Fri, Mar 07, 2014 at 11:34:14AM +0800, Linus Walleij wrote:
> On Fri, Feb 28, 2014 at 11:07 AM, Jenny Tc  wrote:
> > On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
> >> On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC  wrote:
> >>
> >> > +static inline bool __is_battery_full
> >> > +   (long volt, long cur, long iterm, unsigned long cv)
> >>
> >> Overall I wonder if you've run checkpatch on these patches, but why
> >> are you naming this one function with a double __underscore?
> >> Just is_battery_full_check() or something would work fine I guess?
> >
> > Just to convey that is_battery_full is a local function and not generic. You
> > can find similar usage in power_supply_core.c (__power_supply_changed_work)
> > and in other drivers. Isn't it advised to have __ prefixes?
> 
> The preference is different, usually __ is for compiler things, but
> while I dislike it (disturbs my perception) I can sure live with it.

Fixed in patch set v7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-06 Thread Jenny Tc
On Fri, Mar 07, 2014 at 11:34:14AM +0800, Linus Walleij wrote:
 On Fri, Feb 28, 2014 at 11:07 AM, Jenny Tc jenny...@intel.com wrote:
  On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
  On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC jenny...@intel.com wrote:
 
   +static inline bool __is_battery_full
   +   (long volt, long cur, long iterm, unsigned long cv)
 
  Overall I wonder if you've run checkpatch on these patches, but why
  are you naming this one function with a double __underscore?
  Just is_battery_full_check() or something would work fine I guess?
 
  Just to convey that is_battery_full is a local function and not generic. You
  can find similar usage in power_supply_core.c (__power_supply_changed_work)
  and in other drivers. Isn't it advised to have __ prefixes?
 
 The preference is different, usually __ is for compiler things, but
 while I dislike it (disturbs my perception) I can sure live with it.

Fixed in patch set v7
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver

2014-03-06 Thread Jenny Tc
On Fri, Mar 07, 2014 at 11:03:02AM +0800, Linus Walleij wrote:
 On Fri, Feb 28, 2014 at 12:27 PM, Jenny Tc jenny...@intel.com wrote:
  On Thu, Feb 27, 2014 at 09:08:01PM +0100, Linus Walleij wrote:
  On Thu, Feb 20, 2014 at 6:53 AM, Jenny TC jenny...@intel.com wrote:
 
   +++ b/include/linux/power/power_supply_charger.h
 
   +#define MAX_CUR_VOLT_SAMPLES 3
   +#define DEF_CUR_VOLT_SAMPLE_JIFF (30*HZ)
 
  Why are things defined in Jiffies like this insead of seconds, milliseconds
  etc? This will vary with the current operating frequency of the system,
  why should physical measurements do that?
 
  Is it fine if I use msecs_to_jiffies(3)?
 
 Keep the
 #define DEF_CUR_VOLT_SAMPLE_PERIOD 3
 
 Then use msecs_to_jiffies(DEF_CUR_VOLT_SAMPLE_PERIOD)
 in the call site.
 

Ok..fine will fix it in next patch set
   +enum psy_charger_cable_event {
   +   PSY_CHARGER_CABLE_EVENT_DISCONNECT = 0,
   +   PSY_CHARGER_CABLE_EVENT_CONNECT,
   +   PSY_CHARGER_CABLE_EVENT_UPDATE,
   +   PSY_CHARGER_CABLE_EVENT_RESUME,
   +   PSY_CHARGER_CABLE_EVENT_SUSPEND,
   +};
   +
   +enum psy_charger_cable_type {
   +   PSY_CHARGER_CABLE_TYPE_NONE = 0,
   +   PSY_CHARGER_CABLE_TYPE_USB_SDP = 1  0,
   +   PSY_CHARGER_CABLE_TYPE_USB_DCP = 1  1,
   +   PSY_CHARGER_CABLE_TYPE_USB_CDP = 1  2,
   +   PSY_CHARGER_CABLE_TYPE_USB_ACA = 1  3,
   +   PSY_CHARGER_CABLE_TYPE_AC = 1  4,
   +   PSY_CHARGER_CABLE_TYPE_ACA_DOCK = 1  5,
   +   PSY_CHARGER_CABLE_TYPE_ACA_A = 1  6,
   +   PSY_CHARGER_CABLE_TYPE_ACA_B = 1  7,
   +   PSY_CHARGER_CABLE_TYPE_ACA_C = 1  8,
   +   PSY_CHARGER_CABLE_TYPE_SE1 = 1  9,
   +   PSY_CHARGER_CABLE_TYPE_MHL = 1  10,
   +   PSY_CHARGER_CABLE_TYPE_B_DEVICE = 1  11,
   +};
 
  Why is this even an enum? It is clearly bitfields. I would just:
 
  #include linux/bitops.h
 
  #define PSY_CHARGER_CABLE_TYPE_NONE 0x0
  #define PSY_CHARGER_CABLE_TYPE_USB_SDP BIT(0)
  #define PSY_CHARGER_CABLE_TYPE_USB_DCP BIT(1)
  (etc)
 
  This is to ensure type checks when the cable types are handled, #defines 
  will
  not help in type checks.
 
 Type checks with static code check tools? But misrepresenting
 a bitfield as an enum just to satisfy a static code checker is not
 OK IMO.

not just for tools, compile time type checks also.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-06 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   15 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  204 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 283 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..54a0321 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,21 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   depends on POWER_SUPPLY_CHARGER
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. Select this if your charging algorithm need to change the
+ charging parameters based on the battery temperature and the battery
+ charging profile follows the struct psy_pse_chrg_prof definition.
+ This  config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..ac95885
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof-temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp  pse_mod_bprof-temp_low_lim) ||
+   (temp  pse_mod_bprof-temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i  temp_range_cnt; ++i)
+   if (temp  pse_mod_bprof-temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel(%s:current=%ld pse_mod_bprof-chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld,
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN

[PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-06 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 0/4] power_supply: Introduce power supply charging driver

2014-03-06 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes
v8: used msecs_to_jiffies instead of HZ directly, modified Kconfig help text
for POWER_SUPPLY_CHARGING_ALGO_PSE

The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire).With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set property callbacks.

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  353 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   31 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261-charger.c  | 1350 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  218 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  341 +++
 include/linux/power_supply.h |  164 
 13 files changed, 3888 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv8 4/4] power_supply: bq24261 charger driver

2014-03-06 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261-charger.c   | 1350 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1386 insertions(+)
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 54a0321..4ff080c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -411,6 +411,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..9dde895 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261-charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261-charger.c b/drivers/power/bq24261-charger.c
new file mode 100644
index 000..187c1fe
--- /dev/null
+++ b/drivers/power/bq24261-charger.c
@@ -0,0 +1,1350 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

Re: power_supply mailing list

2014-03-06 Thread Jenny Tc
On Sat, Feb 01, 2014 at 09:06:48AM -0700, Dmitry Eremin-Solenikov wrote:
 Hello,
 
 On Thu, Jan 30, 2014 at 10:46 PM, Jenny Tc jenny...@intel.com wrote:
 
  Do we have any mailing list for power_supply subsystem? If not what about 
  having
  one - linux-power-sup...@vger.kernel.org?
 
 I'm not sure that if that ML will have enough traffic to be fully
 usefull or enough
 reviewers on it. However as currently most of the power_supply patches receive
 a long list of To and Cc people, let's try that ML.
 
 
 David, could you please create a mailing list for power_supply discussions?
 

Dmitry/David,

Any update on this. Appreciate your help on this.

Thanks
Jenny
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv7 4/4] power_supply: bq24261 charger driver

2014-03-03 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261-charger.c   | 1350 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1386 insertions(+)
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 913ec36..a1c2780 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -409,6 +409,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..9dde895 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261-charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261-charger.c b/drivers/power/bq24261-charger.c
new file mode 100644
index 000..187c1fe
--- /dev/null
+++ b/drivers/power/bq24261-charger.c
@@ -0,0 +1,1350 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCHv7 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-03 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   13 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  204 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 281 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..913ec36 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. This config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
+   depends on POWER_SUPPLY_CHARGER
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..ac95885
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp < pse_mod_bprof->temp_low_lim) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel("%s:current=%ld pse_mod_bprof->chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld",
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN * cv));
+
+   return (cur > 0) && (cur <= iterm) &&
+   ((volt * 100)  >= (FULL_CV_MIN * cv));
+
+}
+
+static inline bool is_battery_full(struct psy_batt_props bat_prop,
+   struct psy_pse_chrg_pro

[PATCH v7 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-03 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv7 0/4] power_supply: Introduce power supply charging driver

2014-03-03 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes

The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire).With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set property callbacks.

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  353 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   31 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261-charger.c  | 1350 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  218 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  341 +++
 include/linux/power_supply.h |  164 
 13 files changed, 3888 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-03-03 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv7 0/4] power_supply: Introduce power supply charging driver

2014-03-03 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style
v7: added kerneldocs for structs and minor fixes

The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire).With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set property callbacks.

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  353 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   31 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261-charger.c  | 1350 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  218 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  341 +++
 include/linux/power_supply.h |  164 
 13 files changed, 3888 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv7 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-03 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig  |   13 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  204 
 include/linux/power/power_supply_charger.h |   63 +
 4 files changed, 281 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..913ec36 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. This config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
+   depends on POWER_SUPPLY_CHARGER
+
 config PDA_POWER
tristate Generic PDA/phone power driver
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..ac95885
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/err.h
+#include linux/power_supply.h
+#include linux/thermal.h
+#include power_supply.h
+#include power_supply_charger.h
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof-temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp  pse_mod_bprof-temp_low_lim) ||
+   (temp  pse_mod_bprof-temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i  temp_range_cnt; ++i)
+   if (temp  pse_mod_bprof-temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool is_charge_terminated(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel(%s:current=%ld pse_mod_bprof-chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld,
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN * cv));
+
+   return (cur  0)  (cur = iterm) 
+   ((volt * 100)  = (FULL_CV_MIN * cv));
+
+}
+
+static inline bool is_battery_full(struct psy_batt_props bat_prop,
+   struct

[PATCHv7 4/4] power_supply: bq24261 charger driver

2014-03-03 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC jenny...@intel.com
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261-charger.c   | 1350 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1386 insertions(+)
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 913ec36..a1c2780 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -409,6 +409,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate BQ24261 charger driver
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source drivers/power/reset/Kconfig
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..9dde895 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261-charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261-charger.c b/drivers/power/bq24261-charger.c
new file mode 100644
index 000..187c1fe
--- /dev/null
+++ b/drivers/power/bq24261-charger.c
@@ -0,0 +1,1350 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~
+ * Author: Jenny TC jenny...@intel.com
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/err.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/power_supply.h
+#include linux/power/power_supply_charger.h
+#include linux/power/bq24261-charger.h
+#include linux/sched.h
+#include linux/seq_file.h
+#include linux/slab.h
+#include linux/usb/otg.h
+#include linux/version.h
+
+
+#define DEV_NAME bq24261_charger
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01  7)
+#define BQ24261_RESET_ENABLE   (0x01  7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03  4)
+#define BQ24261_BOOST_MASK (0x01  6)
+#define BQ24261_TMR_RST_MASK   (0x01  7)
+#define BQ24261_TMR_RST(0x01  7)
+
+#define BQ24261_ENABLE_BOOST   (0x01  6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01  4)
+#define BQ24261_STAT_CHRG_DONE (0x02  4)
+#define BQ24261_STAT_FAULT (0x03  4)
+
+#define BQ24261_CE_MASK(0x01  1)
+#define BQ24261_CE_DISABLE (0x01  1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define

Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-02 Thread Jenny Tc
On Fri, Feb 28, 2014 at 11:08:16AM +0100, Pavel Machek wrote:
> On Fri 2014-02-28 08:37:27, Jenny Tc wrote:
> > On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
> > > On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC  wrote:
> > > 
> > > > +static inline bool __is_battery_full
> > > > +   (long volt, long cur, long iterm, unsigned long cv)
> > > 
> > > Overall I wonder if you've run checkpatch on these patches, but why
> > > are you naming this one function with a double __underscore?
> > > Just is_battery_full_check() or something would work fine I guess?
> > 
> > Just to convey that is_battery_full is a local function and not generic. You
> > can find similar usage in power_supply_core.c (__power_supply_changed_work)
> > and in other drivers. Isn't it advised to have __ prefixes?
> 
> It is static; everybody sees it is local. __ prefix usually means
> something else.

Agreed, I will remove the __ prefix in next patchset. Meanwhile I would
appreciate if anyone could help me to understand what __ prefix really means.

> > > > +   u16 capacity;   /* mAh */
> > > > +   u16 voltage_max; /* mV */
> > > > +   /* charge termination current */
> > > > +   u16 chrg_term_mA;
> > > > +   /* Low battery level voltage */
> > > > +   u16 low_batt_mV;
> > > > +   /* upper and lower temperature limits on discharging */
> > > > +   s8 disch_temp_ul; /* Degree Celsius */
> > > > +   s8 disch_temp_ll; /* Degree Celsius */
> > > > +   /* number of temperature monitoring ranges */
> > > > +   u16 temp_mon_ranges;
> > > > +   struct psy_ps_temp_chg_table temp_mon_range[BATT_TEMP_NR_RNG];
> > > > +   /* lowest temperature supported */
> > > > +   s8 temp_low_lim;
> > > > +} __packed;
> > > 
> > > Why packed, and convert to kerneldoc for this struct.
> > 
> > Battery charging profile, may come from EEPROM/emmc which would be packed.
> 
> Do you need to do endianness conversion, too?

May/may not depending on the stored format. If needed, the endianess conversion
should be done at driver level where the EEPROM/emmc reading happens.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-03-02 Thread Jenny Tc
On Fri, Feb 28, 2014 at 11:08:16AM +0100, Pavel Machek wrote:
 On Fri 2014-02-28 08:37:27, Jenny Tc wrote:
  On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
   On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC jenny...@intel.com wrote:
   
+static inline bool __is_battery_full
+   (long volt, long cur, long iterm, unsigned long cv)
   
   Overall I wonder if you've run checkpatch on these patches, but why
   are you naming this one function with a double __underscore?
   Just is_battery_full_check() or something would work fine I guess?
  
  Just to convey that is_battery_full is a local function and not generic. You
  can find similar usage in power_supply_core.c (__power_supply_changed_work)
  and in other drivers. Isn't it advised to have __ prefixes?
 
 It is static; everybody sees it is local. __ prefix usually means
 something else.

Agreed, I will remove the __ prefix in next patchset. Meanwhile I would
appreciate if anyone could help me to understand what __ prefix really means.

+   u16 capacity;   /* mAh */
+   u16 voltage_max; /* mV */
+   /* charge termination current */
+   u16 chrg_term_mA;
+   /* Low battery level voltage */
+   u16 low_batt_mV;
+   /* upper and lower temperature limits on discharging */
+   s8 disch_temp_ul; /* Degree Celsius */
+   s8 disch_temp_ll; /* Degree Celsius */
+   /* number of temperature monitoring ranges */
+   u16 temp_mon_ranges;
+   struct psy_ps_temp_chg_table temp_mon_range[BATT_TEMP_NR_RNG];
+   /* lowest temperature supported */
+   s8 temp_low_lim;
+} __packed;
   
   Why packed, and convert to kerneldoc for this struct.
  
  Battery charging profile, may come from EEPROM/emmc which would be packed.
 
 Do you need to do endianness conversion, too?

May/may not depending on the stored format. If needed, the endianess conversion
should be done at driver level where the EEPROM/emmc reading happens.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 09:08:01PM +0100, Linus Walleij wrote:
> On Thu, Feb 20, 2014 at 6:53 AM, Jenny TC  wrote:
> 
> > +++ b/include/linux/power/power_supply_charger.h
> 
> > +#define MAX_CUR_VOLT_SAMPLES 3
> > +#define DEF_CUR_VOLT_SAMPLE_JIFF (30*HZ)
> 
> Why are things defined in Jiffies like this insead of seconds, milliseconds
> etc? This will vary with the current operating frequency of the system,
> why should physical measurements do that?

Is it fine if I use msecs_to_jiffies(3)?

> > +enum psy_charger_cable_event {
> > +   PSY_CHARGER_CABLE_EVENT_DISCONNECT = 0,
> > +   PSY_CHARGER_CABLE_EVENT_CONNECT,
> > +   PSY_CHARGER_CABLE_EVENT_UPDATE,
> > +   PSY_CHARGER_CABLE_EVENT_RESUME,
> > +   PSY_CHARGER_CABLE_EVENT_SUSPEND,
> > +};
> > +
> > +enum psy_charger_cable_type {
> > +   PSY_CHARGER_CABLE_TYPE_NONE = 0,
> > +   PSY_CHARGER_CABLE_TYPE_USB_SDP = 1 << 0,
> > +   PSY_CHARGER_CABLE_TYPE_USB_DCP = 1 << 1,
> > +   PSY_CHARGER_CABLE_TYPE_USB_CDP = 1 << 2,
> > +   PSY_CHARGER_CABLE_TYPE_USB_ACA = 1 << 3,
> > +   PSY_CHARGER_CABLE_TYPE_AC = 1 << 4,
> > +   PSY_CHARGER_CABLE_TYPE_ACA_DOCK = 1 << 5,
> > +   PSY_CHARGER_CABLE_TYPE_ACA_A = 1 << 6,
> > +   PSY_CHARGER_CABLE_TYPE_ACA_B = 1 << 7,
> > +   PSY_CHARGER_CABLE_TYPE_ACA_C = 1 << 8,
> > +   PSY_CHARGER_CABLE_TYPE_SE1 = 1 << 9,
> > +   PSY_CHARGER_CABLE_TYPE_MHL = 1 << 10,
> > +   PSY_CHARGER_CABLE_TYPE_B_DEVICE = 1 << 11,
> > +};
> 
> Why is this even an enum? It is clearly bitfields. I would just:
> 
> #include 
> 
> #define PSY_CHARGER_CABLE_TYPE_NONE 0x0
> #define PSY_CHARGER_CABLE_TYPE_USB_SDP BIT(0)
> #define PSY_CHARGER_CABLE_TYPE_USB_DCP BIT(1)
> (etc)

This is to ensure type checks when the cable types are handled, #defines will
not help in type checks. 

> 
> > +enum {
> > + POWER_SUPPLY_BATTERY_REMOVED = 0,
> > + POWER_SUPPLY_BATTERY_INSERTED,
> > +};
> 
> Why is this enum anonymous? Does that mean the code just
> casts the enum to an int?

OK.I'll name the enum.
> 
> > +
> > +struct psy_cable_props {
> > +   enum psy_charger_cable_eventchrg_evt;
> > +   enum psy_charger_cable_type chrg_type;
> > +   unsigned intmA; /* input current limit */
> 
> You are naming a struct member after a unit, can it not
> be given a better name like "current_limit" and write in the
> kerneldoc (not a comment) that it is stated in mA?

I'll change the variable name in next patch set.
> > +struct psy_batt_props {
> > +   struct list_head node;
> > +   const char *name;
> > +   long voltage_now; /* mV */
> > +   long voltage_now_cache[MAX_CUR_VOLT_SAMPLES]; /* mV */
> > +   long current_now; /* mA */
> > +   long current_now_cache[MAX_CUR_VOLT_SAMPLES]; /* mV */
> > +   int temperature; /* Degree Celsius */
> > +   long status; /* POWER_SUPPLY_STATUS_* */
> 
> I don't understand these comments... Do you mean you are
> using the enums from ?
>
> Would it not be better to give those enums a real name
> (as a separate patch) and then use:
> 
> enum power_supply_status status;
> 
> here? That would be helpful methinks.

My intention is to convey that status variable takes values
POWER_SUPPLY_STATUS_*. I'll submit a separate patch to name the enums in
power_supply.h. Also I'll make the appropriate changes in power_supply_charger.h
> > +struct power_supply_charger {
> > +   struct power_supply *psy;
> > +   struct psy_throttle_state *throttle_states;
> > +   size_t num_throttle_states;
> > +   unsigned long supported_cables;
> > +   int (*get_property)(struct power_supply_charger *psyc,
> > +   enum power_supply_charger_property psp,
> > +   union power_supply_propval *val);
> > +   int (*set_property)(struct power_supply_charger *psyc,
> > +   enum power_supply_charger_property psp,
> > +   const union power_supply_propval *val);
> > +   int (*property_is_writeable)(struct power_supply_charger *psyc,
> > +enum power_supply_charger_property 
> > psp);
> > +};
> 
> Kerneldoc this vtable struct.

I'll make the necessary kerneldoc changes as you suggested for this structure
and other structures.
> 
> > +/* power_supply_charger functions */
> > +
> > +#ifdef CONFIG_POWER_SUPPLY_CHARGER
> > +
>

Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
> On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC  wrote:
> 
> > +static inline bool __is_battery_full
> > +   (long volt, long cur, long iterm, unsigned long cv)
> 
> Overall I wonder if you've run checkpatch on these patches, but why
> are you naming this one function with a double __underscore?
> Just is_battery_full_check() or something would work fine I guess?

Just to convey that is_battery_full is a local function and not generic. You
can find similar usage in power_supply_core.c (__power_supply_changed_work)
and in other drivers. Isn't it advised to have __ prefixes?
> (...)
> > +/* Parameters defining the charging range */
> > +struct psy_ps_temp_chg_table {
> > +   /* upper temperature limit for each zone */
> > +   short int temp_up_lim; /* Degree Celsius */
> > +
> > +   /* charge current and voltage */
> > +   short int full_chrg_vol; /* mV */
> > +   short int full_chrg_cur; /* mA */
> > +
> > +   /*
> > +   *  Maintenance charging thresholds.
> > +   *  Maintenance charging voltage lower limit - Once battery hits 
> > full,
> > +   *  charging will be resumed when battery voltage <= this voltage
> > +   */
> > +   short int maint_chrg_vol_ll; /* mV */
> > +
> > +   /* Charge current and voltage in maintenance charging mode */
> > +   short int maint_chrg_vol_ul; /* mV */
> > +   short int maint_chrg_cur;   /* mA */
> > +} __packed;
> 
> Why are you packing these structs? If no real reason, remove it.
> The compiler will pack what it thinks is appropriate anyway.

The structure is part of the  battery charging profile which can be read 
directly
from an EEPROM or from secondary storage (emmc). So it should be packed to keep
it align with the stored format.

> > +#define BATTID_STR_LEN 8
> > +#define BATT_TEMP_NR_RNG   6
> > +
> > +struct psy_pse_chrg_prof {
> > +   /* battery id */
> > +   char batt_id[BATTID_STR_LEN];
> > +   u16 battery_type; /* Defined as POWER_SUPPLY_TECHNOLOGY_* */
> 
> Use a named enum by patching that in ?

This is to convey that battery_type takes value as defined by
POWER_SUPPLY_TECHNOLOGY_*
> 
> > +   u16 capacity;   /* mAh */
> > +   u16 voltage_max; /* mV */
> > +   /* charge termination current */
> > +   u16 chrg_term_mA;
> > +   /* Low battery level voltage */
> > +   u16 low_batt_mV;
> > +   /* upper and lower temperature limits on discharging */
> > +   s8 disch_temp_ul; /* Degree Celsius */
> > +   s8 disch_temp_ll; /* Degree Celsius */
> > +   /* number of temperature monitoring ranges */
> > +   u16 temp_mon_ranges;
> > +   struct psy_ps_temp_chg_table temp_mon_range[BATT_TEMP_NR_RNG];
> > +   /* lowest temperature supported */
> > +   s8 temp_low_lim;
> > +} __packed;
> 
> Why packed, and convert to kerneldoc for this struct.

Battery charging profile, may come from EEPROM/emmc which would be packed.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 08:47:07PM +0100, Linus Walleij wrote:
> On Wed, Feb 26, 2014 at 3:54 AM, Jenny Tc  wrote:
> 
> > The idea is to allow pluggable charging algorithms. Currently we have only 
> > one
> > charging algorithm proposed, but can have other charging algorithms (like 
> > pulse
> > charging, rule based charging etc.). Based on the platform need, the 
> > algorithms
> > can be selected. So this should be a user configurable option. I can add 
> > more
> > explanation on when to select this option.
> 
> Do you see a generic framework for pluggable algorithms on an abstracted
> level, so that it could be used for the CC/CV charging, measurement and
> temperature check algorithm that is found in e.g.
> drivers/power/abx500_chargalg.c
> drivers/power/ab8500_charger.c etc, or do you envision a set of pluggable
> algorithms for this one hardware?
> 
> I'm asking because these drivers are a massive set of code and we may
> need to start to abstract out and define library functions and frameworks
> already now before it becomes impossible to contain.

The idea of power_supply_charger driver is to move the charging logic outside of
the charger chip driver. This makes the charger chip driver as a  h/w
abstraction layer without  having any charging logic in it. power supply charger
driver invokes charging algorithm to decide the CC, CV and to stop/start
charging on different conditions (based on voltage/temperature ...). Detailed
note on using power supply charger driver can be found in
Documentation/power/power_supply_charger.txt  which is part of patch
power_supply-Introduce-generic-psy-charging-driver.patch
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 08:47:07PM +0100, Linus Walleij wrote:
 On Wed, Feb 26, 2014 at 3:54 AM, Jenny Tc jenny...@intel.com wrote:
 
  The idea is to allow pluggable charging algorithms. Currently we have only 
  one
  charging algorithm proposed, but can have other charging algorithms (like 
  pulse
  charging, rule based charging etc.). Based on the platform need, the 
  algorithms
  can be selected. So this should be a user configurable option. I can add 
  more
  explanation on when to select this option.
 
 Do you see a generic framework for pluggable algorithms on an abstracted
 level, so that it could be used for the CC/CV charging, measurement and
 temperature check algorithm that is found in e.g.
 drivers/power/abx500_chargalg.c
 drivers/power/ab8500_charger.c etc, or do you envision a set of pluggable
 algorithms for this one hardware?
 
 I'm asking because these drivers are a massive set of code and we may
 need to start to abstract out and define library functions and frameworks
 already now before it becomes impossible to contain.

The idea of power_supply_charger driver is to move the charging logic outside of
the charger chip driver. This makes the charger chip driver as a  h/w
abstraction layer without  having any charging logic in it. power supply charger
driver invokes charging algorithm to decide the CC, CV and to stop/start
charging on different conditions (based on voltage/temperature ...). Detailed
note on using power supply charger driver can be found in
Documentation/power/power_supply_charger.txt  which is part of patch
power_supply-Introduce-generic-psy-charging-driver.patch
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 09:18:57PM +0100, Linus Walleij wrote:
 On Tue, Feb 4, 2014 at 6:12 AM, Jenny TC jenny...@intel.com wrote:
 
  +static inline bool __is_battery_full
  +   (long volt, long cur, long iterm, unsigned long cv)
 
 Overall I wonder if you've run checkpatch on these patches, but why
 are you naming this one function with a double __underscore?
 Just is_battery_full_check() or something would work fine I guess?

Just to convey that is_battery_full is a local function and not generic. You
can find similar usage in power_supply_core.c (__power_supply_changed_work)
and in other drivers. Isn't it advised to have __ prefixes?
 (...)
  +/* Parameters defining the charging range */
  +struct psy_ps_temp_chg_table {
  +   /* upper temperature limit for each zone */
  +   short int temp_up_lim; /* Degree Celsius */
  +
  +   /* charge current and voltage */
  +   short int full_chrg_vol; /* mV */
  +   short int full_chrg_cur; /* mA */
  +
  +   /*
  +   *  Maintenance charging thresholds.
  +   *  Maintenance charging voltage lower limit - Once battery hits 
  full,
  +   *  charging will be resumed when battery voltage = this voltage
  +   */
  +   short int maint_chrg_vol_ll; /* mV */
  +
  +   /* Charge current and voltage in maintenance charging mode */
  +   short int maint_chrg_vol_ul; /* mV */
  +   short int maint_chrg_cur;   /* mA */
  +} __packed;
 
 Why are you packing these structs? If no real reason, remove it.
 The compiler will pack what it thinks is appropriate anyway.

The structure is part of the  battery charging profile which can be read 
directly
from an EEPROM or from secondary storage (emmc). So it should be packed to keep
it align with the stored format.

  +#define BATTID_STR_LEN 8
  +#define BATT_TEMP_NR_RNG   6
  +
  +struct psy_pse_chrg_prof {
  +   /* battery id */
  +   char batt_id[BATTID_STR_LEN];
  +   u16 battery_type; /* Defined as POWER_SUPPLY_TECHNOLOGY_* */
 
 Use a named enum by patching that in linux/power_supply.h?

This is to convey that battery_type takes value as defined by
POWER_SUPPLY_TECHNOLOGY_*
 
  +   u16 capacity;   /* mAh */
  +   u16 voltage_max; /* mV */
  +   /* charge termination current */
  +   u16 chrg_term_mA;
  +   /* Low battery level voltage */
  +   u16 low_batt_mV;
  +   /* upper and lower temperature limits on discharging */
  +   s8 disch_temp_ul; /* Degree Celsius */
  +   s8 disch_temp_ll; /* Degree Celsius */
  +   /* number of temperature monitoring ranges */
  +   u16 temp_mon_ranges;
  +   struct psy_ps_temp_chg_table temp_mon_range[BATT_TEMP_NR_RNG];
  +   /* lowest temperature supported */
  +   s8 temp_low_lim;
  +} __packed;
 
 Why packed, and convert to kerneldoc for this struct.

Battery charging profile, may come from EEPROM/emmc which would be packed.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver

2014-02-27 Thread Jenny Tc
On Thu, Feb 27, 2014 at 09:08:01PM +0100, Linus Walleij wrote:
 On Thu, Feb 20, 2014 at 6:53 AM, Jenny TC jenny...@intel.com wrote:
 
  +++ b/include/linux/power/power_supply_charger.h
 
  +#define MAX_CUR_VOLT_SAMPLES 3
  +#define DEF_CUR_VOLT_SAMPLE_JIFF (30*HZ)
 
 Why are things defined in Jiffies like this insead of seconds, milliseconds
 etc? This will vary with the current operating frequency of the system,
 why should physical measurements do that?

Is it fine if I use msecs_to_jiffies(3)?

  +enum psy_charger_cable_event {
  +   PSY_CHARGER_CABLE_EVENT_DISCONNECT = 0,
  +   PSY_CHARGER_CABLE_EVENT_CONNECT,
  +   PSY_CHARGER_CABLE_EVENT_UPDATE,
  +   PSY_CHARGER_CABLE_EVENT_RESUME,
  +   PSY_CHARGER_CABLE_EVENT_SUSPEND,
  +};
  +
  +enum psy_charger_cable_type {
  +   PSY_CHARGER_CABLE_TYPE_NONE = 0,
  +   PSY_CHARGER_CABLE_TYPE_USB_SDP = 1  0,
  +   PSY_CHARGER_CABLE_TYPE_USB_DCP = 1  1,
  +   PSY_CHARGER_CABLE_TYPE_USB_CDP = 1  2,
  +   PSY_CHARGER_CABLE_TYPE_USB_ACA = 1  3,
  +   PSY_CHARGER_CABLE_TYPE_AC = 1  4,
  +   PSY_CHARGER_CABLE_TYPE_ACA_DOCK = 1  5,
  +   PSY_CHARGER_CABLE_TYPE_ACA_A = 1  6,
  +   PSY_CHARGER_CABLE_TYPE_ACA_B = 1  7,
  +   PSY_CHARGER_CABLE_TYPE_ACA_C = 1  8,
  +   PSY_CHARGER_CABLE_TYPE_SE1 = 1  9,
  +   PSY_CHARGER_CABLE_TYPE_MHL = 1  10,
  +   PSY_CHARGER_CABLE_TYPE_B_DEVICE = 1  11,
  +};
 
 Why is this even an enum? It is clearly bitfields. I would just:
 
 #include linux/bitops.h
 
 #define PSY_CHARGER_CABLE_TYPE_NONE 0x0
 #define PSY_CHARGER_CABLE_TYPE_USB_SDP BIT(0)
 #define PSY_CHARGER_CABLE_TYPE_USB_DCP BIT(1)
 (etc)

This is to ensure type checks when the cable types are handled, #defines will
not help in type checks. 

 
  +enum {
  + POWER_SUPPLY_BATTERY_REMOVED = 0,
  + POWER_SUPPLY_BATTERY_INSERTED,
  +};
 
 Why is this enum anonymous? Does that mean the code just
 casts the enum to an int?

OK.I'll name the enum.
 
  +
  +struct psy_cable_props {
  +   enum psy_charger_cable_eventchrg_evt;
  +   enum psy_charger_cable_type chrg_type;
  +   unsigned intmA; /* input current limit */
 
 You are naming a struct member after a unit, can it not
 be given a better name like current_limit and write in the
 kerneldoc (not a comment) that it is stated in mA?

I'll change the variable name in next patch set.
  +struct psy_batt_props {
  +   struct list_head node;
  +   const char *name;
  +   long voltage_now; /* mV */
  +   long voltage_now_cache[MAX_CUR_VOLT_SAMPLES]; /* mV */
  +   long current_now; /* mA */
  +   long current_now_cache[MAX_CUR_VOLT_SAMPLES]; /* mV */
  +   int temperature; /* Degree Celsius */
  +   long status; /* POWER_SUPPLY_STATUS_* */
 
 I don't understand these comments... Do you mean you are
 using the enums from linux/power_supply.h?

 Would it not be better to give those enums a real name
 (as a separate patch) and then use:
 
 enum power_supply_status status;
 
 here? That would be helpful methinks.

My intention is to convey that status variable takes values
POWER_SUPPLY_STATUS_*. I'll submit a separate patch to name the enums in
power_supply.h. Also I'll make the appropriate changes in power_supply_charger.h
  +struct power_supply_charger {
  +   struct power_supply *psy;
  +   struct psy_throttle_state *throttle_states;
  +   size_t num_throttle_states;
  +   unsigned long supported_cables;
  +   int (*get_property)(struct power_supply_charger *psyc,
  +   enum power_supply_charger_property psp,
  +   union power_supply_propval *val);
  +   int (*set_property)(struct power_supply_charger *psyc,
  +   enum power_supply_charger_property psp,
  +   const union power_supply_propval *val);
  +   int (*property_is_writeable)(struct power_supply_charger *psyc,
  +enum power_supply_charger_property 
  psp);
  +};
 
 Kerneldoc this vtable struct.

I'll make the necessary kerneldoc changes as you suggested for this structure
and other structures.
 
  +/* power_supply_charger functions */
  +
  +#ifdef CONFIG_POWER_SUPPLY_CHARGER
  +
  +extern int power_supply_register_charger(struct power_supply_charger 
  *psyc);
  +extern int power_supply_unregister_charger(struct power_supply_charger 
  *psyc);
  +extern int power_supply_register_charging_algo(struct psy_charging_algo *);
  +extern int power_supply_unregister_charging_algo(struct psy_charging_algo 
  *);
  +extern int psy_get_battery_prop(struct psy_batt_chrg_prof *batt_prop);
  +extern void psy_battery_prop_changed(int battery_conn_stat,
  +   struct psy_batt_chrg_prof *batt_prop);
  +
  +#else
  +
  +static int power_supply_register_charger(struct power_supply_charger *psyc)
  +{ return 0; }
  +static  int power_supply_unregister_charger(struct

Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 03:45:29PM +0100, Pavel Machek wrote:
> On Thu 2014-02-20 10:46:55, Jenny Tc wrote:
> > On Tue, Feb 04, 2014 at 12:36:40PM +0100, Pavel Machek wrote:
> > > > --- a/drivers/power/Kconfig
> > > > +++ b/drivers/power/Kconfig
> > > > @@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
> > > >   drivers to keep the charging logic outside and the charger 
> > > > driver
> > > >   just need to abstract the charger hardware.
> > > >  
> > > > +config POWER_SUPPLY_CHARGING_ALGO_PSE
> > > > +   bool "PSE compliant charging algorithm"
> > > > +   help
> > > > + Say Y here to select Product Safety Engineering (PSE) 
> > > > compliant
> > > > + charging algorithm. As per PSE standard the battery 
> > > > characteristics
> > > > + and thereby the charging rates can vary on different 
> > > > temperature
> > > > + zones. This config will enable PSE compliant charging 
> > > > algorithm with
> > > > + maintenance charging support. At runtime the algorithm will be
> > > > + selected by the psy charger driver based on the type of the 
> > > > battery
> > > > + charging profile.
> > > 
> > > Information where to expect PSE compliant chargers would be nice.
> > 
> > This algorithm can be used with non PSE compliant chargers also. This is a 
> > SW
> > based charging algorithm.
> 
> Ok, but you need to explain for the users when it might be good idea
> to select this option...
> 
> Or maybe this should not be user configurable and drivers should just
> select it?

The idea is to allow pluggable charging algorithms. Currently we have only one
charging algorithm proposed, but can have other charging algorithms (like pulse
charging, rule based charging etc.). Based on the platform need, the algorithms
can be selected. So this should be a user configurable option. I can add more
explanation on when to select this option.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4] power_supply: bq24261 charger driver

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 03:44:00PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > +static inline int bq24261_set_cv(struct bq24261_charger *chip, int cv)
> > > > +{
> > > > +   int bat_volt;
> > > > +   int ret;
> > > > +   u8 reg_val;
> > > > +   u8 vindpm_val = 0x0;
> > > > +
> > > > +   /*
> > > > +   * Setting VINDPM value as per the battery voltage
> > > > +   *  VBatt   Vindpm Register Setting
> > > > +   *  < 3.7v   4.2v   0x0 (default)
> > > > +   *  3.71v - 3.96v4.36v  0x2
> > > > +   *  > 3.96v  4.6v   0x5
> > > > +   */
> > > > +   ret = get_battery_voltage(_volt);
> > > > +   if (ret) {
> > > > +   dev_err(>client->dev,
> > > > +   "Error getting battery voltage!!\n");
> > > > +   } else {
> > > 
> > > You forget the error value and continue anyway.
> > 
> > On error, throw the error and program default VINDPM value.
> 
> Is it good idea to attempt charging when we can't read battery
> voltage?

This function decides the VINDPM setting and doesn't enable charging.
VINDPM setting is used to ensure minimum input voltage and thereby allow to
charge with low power charging source. If the voltage read fails, then the
default VINDPM value 0x0 will be programmed and the input voltage may go down
as low as 4.2V. The charging/not charging decision is taken by power supply
charger driver and not by the chip driver. The worst case impact would be that
charging may happen with a low charge current at high battery voltages,
but doesn't compromise safety at all. 

-Jenny
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3.14] power_supply: don't export power_supply_notifier

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 02:19:28PM +0100, Johannes Berg wrote:
> From: Johannes Berg 
> 
> Since there are registration/unregistration functions and the
> invocation is in the core code, there's no need to export the
> notifier chain head, make it static instead.

This is a generic notifier which can be used outside power_supply_core.c
to post psy events as in patch
power_supply-Introduce-generic-psy-charging-driver.patch. So the notifier chain
need to be exported.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3.14] power_supply: don't export power_supply_notifier

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 02:19:28PM +0100, Johannes Berg wrote:
 From: Johannes Berg johannes.b...@intel.com
 
 Since there are registration/unregistration functions and the
 invocation is in the core code, there's no need to export the
 notifier chain head, make it static instead.

This is a generic notifier which can be used outside power_supply_core.c
to post psy events as in patch
power_supply-Introduce-generic-psy-charging-driver.patch. So the notifier chain
need to be exported.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4] power_supply: bq24261 charger driver

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 03:44:00PM +0100, Pavel Machek wrote:
 Hi!
 
+static inline int bq24261_set_cv(struct bq24261_charger *chip, int cv)
+{
+   int bat_volt;
+   int ret;
+   u8 reg_val;
+   u8 vindpm_val = 0x0;
+
+   /*
+   * Setting VINDPM value as per the battery voltage
+   *  VBatt   Vindpm Register Setting
+   *   3.7v   4.2v   0x0 (default)
+   *  3.71v - 3.96v4.36v  0x2
+   *   3.96v  4.6v   0x5
+   */
+   ret = get_battery_voltage(bat_volt);
+   if (ret) {
+   dev_err(chip-client-dev,
+   Error getting battery voltage!!\n);
+   } else {
   
   You forget the error value and continue anyway.
  
  On error, throw the error and program default VINDPM value.
 
 Is it good idea to attempt charging when we can't read battery
 voltage?

This function decides the VINDPM setting and doesn't enable charging.
VINDPM setting is used to ensure minimum input voltage and thereby allow to
charge with low power charging source. If the voltage read fails, then the
default VINDPM value 0x0 will be programmed and the input voltage may go down
as low as 4.2V. The charging/not charging decision is taken by power supply
charger driver and not by the chip driver. The worst case impact would be that
charging may happen with a low charge current at high battery voltages,
but doesn't compromise safety at all. 

-Jenny
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-25 Thread Jenny Tc
On Fri, Feb 21, 2014 at 03:45:29PM +0100, Pavel Machek wrote:
 On Thu 2014-02-20 10:46:55, Jenny Tc wrote:
  On Tue, Feb 04, 2014 at 12:36:40PM +0100, Pavel Machek wrote:
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger 
driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool PSE compliant charging algorithm
+   help
+ Say Y here to select Product Safety Engineering (PSE) 
compliant
+ charging algorithm. As per PSE standard the battery 
characteristics
+ and thereby the charging rates can vary on different 
temperature
+ zones. This config will enable PSE compliant charging 
algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the 
battery
+ charging profile.
   
   Information where to expect PSE compliant chargers would be nice.
  
  This algorithm can be used with non PSE compliant chargers also. This is a 
  SW
  based charging algorithm.
 
 Ok, but you need to explain for the users when it might be good idea
 to select this option...
 
 Or maybe this should not be user configurable and drivers should just
 select it?

The idea is to allow pluggable charging algorithms. Currently we have only one
charging algorithm proposed, but can have other charging algorithms (like pulse
charging, rule based charging etc.). Based on the platform need, the algorithms
can be selected. So this should be a user configurable option. I can add more
explanation on when to select this option.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 14/15] charger: max14577: Configure battery-dependent settings from DTS

2014-02-19 Thread Jenny Tc
On Mon, Feb 17, 2014 at 10:05:49AM +0100, Krzysztof Kozlowski wrote:
> +static inline int max14577_init_eoc(struct max14577_charger *chg,
> + unsigned int uamp)
> +{
> + unsigned int current_bits = 0xf;
> + u8 reg_data;
> +
> + switch (chg->maxim_core->dev_type) {
> + case MAXIM_DEVICE_TYPE_MAX77836:
> + if (uamp < 5000)
> + return -EINVAL; /* Requested current is too low */
> +
> + if (uamp == 7500)
> + current_bits = 0x0;

if (uamp <= 7500) ?

> + /* Initialize Overvoltage-Protection Threshold */
> + switch (chg->pdata->ovp_uvolt) {
> + case 750:
> + reg_data = 0x0;
> + break;
> + case 600:
> + case 650:
> + case 700:
> + reg_data = 0x1 + (chg->pdata->ovp_uvolt - 600) / 50;
> + break;

Is it battery OVP or charger source OVP? If it's battery OVP, then  minimum
level as 6V seems to be unsafe even for 4.4V batteries.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/4] power_supply: bq24261 charger driver

2014-02-19 Thread Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power
supply charging driver to setup charging. So the driver does hardware
abstraction and handles h/w specific corner cases. The charging logic resides
with power supply charging driver

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig |   10 +
 drivers/power/Makefile|1 +
 drivers/power/bq24261-charger.c   | 1350 +
 include/linux/power/bq24261-charger.h |   25 +
 4 files changed, 1386 insertions(+)
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 include/linux/power/bq24261-charger.h

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 913ec36..a1c2780 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -409,6 +409,16 @@ config BATTERY_GOLDFISH
  Say Y to enable support for the battery and AC power in the
  Goldfish emulator.
 
+config CHARGER_BQ24261
+   tristate "BQ24261 charger driver"
+   select POWER_SUPPLY_CHARGER
+   depends on I2C
+   help
+ Say Y to include support for BQ24261 Charger driver. This driver
+ makes use of power supply charging driver. So the driver gives
+ the charger hardware abstraction only. Charging logic is abstracted
+ in the power supply charging driver.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 77535fd..9dde895 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -59,4 +59,5 @@ obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_BQ24261)  += bq24261-charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
diff --git a/drivers/power/bq24261-charger.c b/drivers/power/bq24261-charger.c
new file mode 100644
index 000..187c1fe
--- /dev/null
+++ b/drivers/power/bq24261-charger.c
@@ -0,0 +1,1350 @@
+/*
+ * bq24261-charger.c - BQ24261 Charger I2C client driver
+ *
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#define DEV_NAME "bq24261_charger"
+#define MODEL_NAME_SIZE 8
+
+#define EXCEPTION_MONITOR_DELAY (60 * HZ)
+#define WDT_RESET_DELAY (15 * HZ)
+
+/* BQ24261 registers */
+#define BQ24261_STAT_CTRL0_ADDR0x00
+#define BQ24261_CTRL_ADDR  0x01
+#define BQ24261_BATT_VOL_CTRL_ADDR 0x02
+#define BQ24261_VENDOR_REV_ADDR0x03
+#define BQ24261_TERM_FCC_ADDR  0x04
+#define BQ24261_VINDPM_STAT_ADDR   0x05
+#define BQ24261_ST_NTC_MON_ADDR0x06
+
+#define BQ24261_RESET_MASK (0x01 << 7)
+#define BQ24261_RESET_ENABLE   (0x01 << 7)
+
+#define BQ24261_FAULT_MASK 0x07
+#define BQ24261_STAT_MASK  (0x03 << 4)
+#define BQ24261_BOOST_MASK (0x01 << 6)
+#define BQ24261_TMR_RST_MASK   (0x01 << 7)
+#define BQ24261_TMR_RST(0x01 << 7)
+
+#define BQ24261_ENABLE_BOOST   (0x01 << 6)
+
+#define BQ24261_VOVP   0x01
+#define BQ24261_LOW_SUPPLY 0x02
+#define BQ24261_THERMAL_SHUTDOWN   0x03
+#define BQ24261_BATT_TEMP_FAULT0x04
+#define BQ24261_TIMER_FAULT0x05
+#define BQ24261_BATT_OVP   0x06
+#define BQ24261_NO_BATTERY 0x07
+#define BQ24261_STAT_READY 0x00
+
+#define BQ24261_STAT_CHRG_PRGRSS   (0x01 << 4)
+#define BQ24261_STAT_CHRG_DONE (0x02 << 4)
+#define BQ24261_STAT_FAULT (0x03 << 4)
+
+#define BQ24261_CE_MASK(0x01 << 1)
+#define BQ24261_CE_DISABLE (0x01 << 1)
+
+#define BQ24261_HZ_MASK(0x01)
+#define BQ24261_HZ_ENABLE  (0x01)
+
+#define BQ24261_ICHRG_MASK (0x1F << 3)
+#define BQ24261_MIN_CC 500 /* 500mA */
+#define BQ24261_MAX_CC 3000 /* 3A */
+
+#define BQ

[PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-19 Thread Jenny TC
As per Product Safety Engineering (PSE) specification for battery charging, the
battery characteristics and thereby the charging rates can vary on different
temperature zones. This patch introduces a PSE compliant charging algorithm with
maintenance charging support. The algorithm can be selected by the power supply
charging driver based on the type of the battery charging profile.

Signed-off-by: Jenny TC 
---
 drivers/power/Kconfig  |   13 ++
 drivers/power/Makefile |1 +
 drivers/power/charging_algo_pse.c  |  204 
 include/linux/power/power_supply_charger.h |   48 +++
 4 files changed, 266 insertions(+)
 create mode 100644 drivers/power/charging_algo_pse.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f679f82..913ec36 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
  drivers to keep the charging logic outside and the charger driver
  just need to abstract the charger hardware.
 
+config POWER_SUPPLY_CHARGING_ALGO_PSE
+   bool "PSE compliant charging algorithm"
+   help
+ Say Y here to select Product Safety Engineering (PSE) compliant
+ charging algorithm. As per PSE standard the battery characteristics
+ and thereby the charging rates can vary on different temperature
+ zones. This config will enable PSE compliant charging algorithm with
+ maintenance charging support. At runtime the algorithm will be
+ selected by the psy charger driver based on the type of the battery
+ charging profile.
+
+   depends on POWER_SUPPLY_CHARGER
+
 config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 405f0f4..77535fd 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_SUPPLY)  += power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)  += generic-adc-battery.o
 
 obj-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o
+obj-$(CONFIG_POWER_SUPPLY_CHARGING_ALGO_PSE) += charging_algo_pse.o
 obj-$(CONFIG_PDA_POWER)+= pda_power.o
 obj-$(CONFIG_APM_POWER)+= apm_power.o
 obj-$(CONFIG_MAX8925_POWER)+= max8925_power.o
diff --git a/drivers/power/charging_algo_pse.c 
b/drivers/power/charging_algo_pse.c
new file mode 100644
index 000..a092e30
--- /dev/null
+++ b/drivers/power/charging_algo_pse.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * ~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
+ * General Public License for more details.
+ *
+ * ~~~~~~
+ * Author: Jenny TC 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "power_supply.h"
+#include "power_supply_charger.h"
+
+/* 98% of CV is considered as voltage to detect Full */
+#define FULL_CV_MIN 98
+
+/*
+ * Offset to exit from maintenance charging. In maintenance charging
+ * if the volatge is less than the (maintenance_lower_threshold -
+ * MAINT_EXIT_OFFSET) then system can switch to normal charging
+ */
+
+#define MAINT_EXIT_OFFSET 50  /* mV */
+
+static int get_tempzone(struct psy_pse_chrg_prof *pse_mod_bprof,
+   int temp)
+{
+   int i = 0;
+   int temp_range_cnt = min_t(u16, pse_mod_bprof->temp_mon_ranges,
+   BATT_TEMP_NR_RNG);
+
+   if ((temp < pse_mod_bprof->temp_low_lim) ||
+   (temp > pse_mod_bprof->temp_mon_range[0].temp_up_lim))
+   return -EINVAL;
+
+   for (i = 0; i < temp_range_cnt; ++i)
+   if (temp > pse_mod_bprof->temp_mon_range[i].temp_up_lim)
+   break;
+   return i-1;
+}
+
+static inline bool __is_battery_full(long volt, long cur,
+   long iterm, unsigned long cv)
+{
+   pr_devel("%s:current=%ld pse_mod_bprof->chrg_term_mA =%ld 
voltage_now=%ld full_cond=%ld",
+   __func__, cur, iterm, volt * 100, (FULL_CV_MIN * cv));
+
+   return (cur > 0) && (cur <= iterm) &&
+   ((volt * 100)  >= (FULL_CV_MIN * cv));
+
+}
+
+static inline bool is_battery_full(struct psy_batt_props bat_prop,
+   struct psy_pse_chrg_prof *pse_

[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-02-19 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC 
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 0/4] power_supply: Introduce power supply charging driver

2014-02-19 Thread Jenny TC
v1: introduced feature as a framework within power supply class driver with
separate files for battid framework and charging framework
v2: fixed review comments, moved macros and inline functions to power_supply.h
v3: moved the feature as a separate driver, combined battid framework and
charging framework inside the power supply charging driver. Moved
charger specific properties to power_supply_charger.h and plugged the
driver with power supply subsystem using power_supply_notifier
introduced in my previous patch. Also a sample charger chip driver
(bq24261) patch added to give more idea on the psy charging driver
usage
v4: Fixed review comments, no major design changes.
v5: Fixed makefile inconsistencies, removed unused pdata callbacks
v6: Fixed nested loops, commenting style

The Power Supply charging driver connects multiple subsystems
to do charging in a generic way. The subsystems involves power_supply,
thermal and battery communication subsystems (1wire).With this the charging is
handled in a generic way.

The driver makes use of different new features - Battery Identification
interfaces, pluggable charging algorithms, charger cable arbitrations etc.
The patch also introduces generic interface for charger cable notifications.
Charger cable events and capabilities can be notified using the generic
power_supply_notifier chain.

Overall this driver removes the charging logic out of the charger chip driver
and the charger chip driver can just listen to the request from the power
supply charging driver to set the charger properties. This can be implemented
by exposing get_property and set property callbacks.

Jenny TC (4):
  power_supply: Add inlmt,iterm, min/max temp props
  power_supply: Introduce generic psy charging driver
  power_supply: Introduce PSE compliant algorithm
  power_supply: bq24261 charger driver

 Documentation/power/power_supply_charger.txt |  353 +++
 Documentation/power/power_supply_class.txt   |6 +
 drivers/power/Kconfig|   31 +
 drivers/power/Makefile   |3 +
 drivers/power/bq24261-charger.c  | 1350 ++
 drivers/power/charging_algo_pse.c|  204 
 drivers/power/power_supply_charger.c | 1186 ++
 drivers/power/power_supply_charger.h |  218 +
 drivers/power/power_supply_core.c|3 +
 drivers/power/power_supply_sysfs.c   |4 +
 include/linux/power/bq24261-charger.h|   25 +
 include/linux/power/power_supply_charger.h   |  235 +
 include/linux/power_supply.h |  164 
 13 files changed, 3782 insertions(+)
 create mode 100644 Documentation/power/power_supply_charger.txt
 create mode 100644 drivers/power/bq24261-charger.c
 create mode 100644 drivers/power/charging_algo_pse.c
 create mode 100644 drivers/power/power_supply_charger.c
 create mode 100644 drivers/power/power_supply_charger.h
 create mode 100644 include/linux/power/bq24261-charger.h
 create mode 100644 include/linux/power/power_supply_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-19 Thread Jenny Tc
On Tue, Feb 04, 2014 at 12:36:40PM +0100, Pavel Machek wrote:
> > --- a/drivers/power/Kconfig
> > +++ b/drivers/power/Kconfig
> > @@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
> >   drivers to keep the charging logic outside and the charger driver
> >   just need to abstract the charger hardware.
> >  
> > +config POWER_SUPPLY_CHARGING_ALGO_PSE
> > +   bool "PSE compliant charging algorithm"
> > +   help
> > + Say Y here to select Product Safety Engineering (PSE) compliant
> > + charging algorithm. As per PSE standard the battery characteristics
> > + and thereby the charging rates can vary on different temperature
> > + zones. This config will enable PSE compliant charging algorithm with
> > + maintenance charging support. At runtime the algorithm will be
> > + selected by the psy charger driver based on the type of the battery
> > + charging profile.
> 
> Information where to expect PSE compliant chargers would be nice.

This algorithm can be used with non PSE compliant chargers also. This is a SW
based charging algorithm.

-Jenny
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4] power_supply: bq24261 charger driver

2014-02-19 Thread Jenny Tc
On Tue, Feb 04, 2014 at 12:36:21PM +0100, Pavel Machek wrote:
> > +#define BQ24261_MIN_CV 3500
> > +#define BQ24261_MAX_CV 4440
> 
> Other defines use uV as an unit :-(.

uV is used if the value is read from psy class. For register configurations
uses mV. Will change the name to reflect mV

> > +   /* If status is fault, wait for READY before enabling the charging */
> > +
> > +   if (!is_ready) {
> > +   ret = wait_event_timeout(chip->wait_ready,
> > +   (chip->chrgr_stat != BQ24261_CHRGR_STAT_READY),
> > +   HZ);
> > +   dev_info(>client->dev,
> > +   "chrgr_stat=%x\n", chip->chrgr_stat);
> > +   if (ret == 0) {
> > +   dev_err(>client->dev,
> > +   "Waiting for Charger Ready Failed.Enabling 
> > charging anyway\n");
> > +   }
> > +   }
> 
> So charger has a problem, and we force it on, anyway? Also put space
> after ".".

Yes, sometimes charger does not give ready, so we force.
> 
> > +static inline int bq24261_set_cv(struct bq24261_charger *chip, int cv)
> > +{
> > +   int bat_volt;
> > +   int ret;
> > +   u8 reg_val;
> > +   u8 vindpm_val = 0x0;
> > +
> > +   /*
> > +   * Setting VINDPM value as per the battery voltage
> > +   *  VBatt   Vindpm Register Setting
> > +   *  < 3.7v   4.2v   0x0 (default)
> > +   *  3.71v - 3.96v4.36v  0x2
> > +   *  > 3.96v  4.6v   0x5
> > +   */
> > +   ret = get_battery_voltage(_volt);
> > +   if (ret) {
> > +   dev_err(>client->dev,
> > +   "Error getting battery voltage!!\n");
> > +   } else {
> 
> You forget the error value and continue anyway.

On error, throw the error and program default VINDPM value.

-Jenny
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4] power_supply: bq24261 charger driver

2014-02-19 Thread Jenny Tc
On Tue, Feb 04, 2014 at 12:36:21PM +0100, Pavel Machek wrote:
  +#define BQ24261_MIN_CV 3500
  +#define BQ24261_MAX_CV 4440
 
 Other defines use uV as an unit :-(.

uV is used if the value is read from psy class. For register configurations
uses mV. Will change the name to reflect mV

  +   /* If status is fault, wait for READY before enabling the charging */
  +
  +   if (!is_ready) {
  +   ret = wait_event_timeout(chip-wait_ready,
  +   (chip-chrgr_stat != BQ24261_CHRGR_STAT_READY),
  +   HZ);
  +   dev_info(chip-client-dev,
  +   chrgr_stat=%x\n, chip-chrgr_stat);
  +   if (ret == 0) {
  +   dev_err(chip-client-dev,
  +   Waiting for Charger Ready Failed.Enabling 
  charging anyway\n);
  +   }
  +   }
 
 So charger has a problem, and we force it on, anyway? Also put space
 after ..

Yes, sometimes charger does not give ready, so we force.
 
  +static inline int bq24261_set_cv(struct bq24261_charger *chip, int cv)
  +{
  +   int bat_volt;
  +   int ret;
  +   u8 reg_val;
  +   u8 vindpm_val = 0x0;
  +
  +   /*
  +   * Setting VINDPM value as per the battery voltage
  +   *  VBatt   Vindpm Register Setting
  +   *   3.7v   4.2v   0x0 (default)
  +   *  3.71v - 3.96v4.36v  0x2
  +   *   3.96v  4.6v   0x5
  +   */
  +   ret = get_battery_voltage(bat_volt);
  +   if (ret) {
  +   dev_err(chip-client-dev,
  +   Error getting battery voltage!!\n);
  +   } else {
 
 You forget the error value and continue anyway.

On error, throw the error and program default VINDPM value.

-Jenny
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm

2014-02-19 Thread Jenny Tc
On Tue, Feb 04, 2014 at 12:36:40PM +0100, Pavel Machek wrote:
  --- a/drivers/power/Kconfig
  +++ b/drivers/power/Kconfig
  @@ -22,6 +22,19 @@ config POWER_SUPPLY_CHARGER
drivers to keep the charging logic outside and the charger driver
just need to abstract the charger hardware.
   
  +config POWER_SUPPLY_CHARGING_ALGO_PSE
  +   bool PSE compliant charging algorithm
  +   help
  + Say Y here to select Product Safety Engineering (PSE) compliant
  + charging algorithm. As per PSE standard the battery characteristics
  + and thereby the charging rates can vary on different temperature
  + zones. This config will enable PSE compliant charging algorithm with
  + maintenance charging support. At runtime the algorithm will be
  + selected by the psy charger driver based on the type of the battery
  + charging profile.
 
 Information where to expect PSE compliant chargers would be nice.

This algorithm can be used with non PSE compliant chargers also. This is a SW
based charging algorithm.

-Jenny
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props

2014-02-19 Thread Jenny TC
Add new power supply properties for input current, charge termination
current, min and max temperature

POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature

POWER_SUPPLY_PROP_INLMT - input current limit programmed by charger. Indicates
the input current for a charging source.

POWER_SUPPLY_PROP_CHARGE_TERM_CUR - Charge termination current used to detect
the end of charge condition

Signed-off-by: Jenny TC jenny...@intel.com
---
 Documentation/power/power_supply_class.txt |6 ++
 drivers/power/power_supply_sysfs.c |4 
 include/linux/power_supply.h   |4 
 3 files changed, 14 insertions(+)

diff --git a/Documentation/power/power_supply_class.txt 
b/Documentation/power/power_supply_class.txt
index 89a8816..48cff88 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -118,6 +118,10 @@ relative, time-based measurements.
 CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
 CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
 power supply object.
+INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
+the current drawn from a charging source.
+CHARGE_TERM_CURRENT - Charge termination current used to detect the end of 
charge
+condition.
 
 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
@@ -140,6 +144,8 @@ TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
 TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
 TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
+TEMP_MIN - minimum operatable temperature
+TEMP_MAX - maximum operatable temperature
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
diff --git a/drivers/power/power_supply_sysfs.c 
b/drivers/power/power_supply_sysfs.c
index 44420d1..750a202 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -167,6 +167,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(constant_charge_voltage_max),
POWER_SUPPLY_ATTR(charge_control_limit),
POWER_SUPPLY_ATTR(charge_control_limit_max),
+   POWER_SUPPLY_ATTR(input_current_limit),
POWER_SUPPLY_ATTR(energy_full_design),
POWER_SUPPLY_ATTR(energy_empty_design),
POWER_SUPPLY_ATTR(energy_full),
@@ -178,6 +179,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(capacity_alert_max),
POWER_SUPPLY_ATTR(capacity_level),
POWER_SUPPLY_ATTR(temp),
+   POWER_SUPPLY_ATTR(temp_max),
+   POWER_SUPPLY_ATTR(temp_min),
POWER_SUPPLY_ATTR(temp_alert_min),
POWER_SUPPLY_ATTR(temp_alert_max),
POWER_SUPPLY_ATTR(temp_ambient),
@@ -189,6 +192,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(time_to_full_avg),
POWER_SUPPLY_ATTR(type),
POWER_SUPPLY_ATTR(scope),
+   POWER_SUPPLY_ATTR(charge_term_current),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index c9dc4e0..0278600 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -120,6 +120,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
+   POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -131,6 +132,8 @@ enum power_supply_property {
POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
+   POWER_SUPPLY_PROP_TEMP_MAX,
+   POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
@@ -142,6 +145,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
POWER_SUPPLY_PROP_SCOPE,
+   POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   >