[PATCH] EXTCON: Get and set cable properties
Existing EXTCON implementation doesn't give a mechanim to read the cable properties and extra states a cable needs to support. There are scenarios where a cable can have more than two states(CONNECT/DISCONNECT/SUSPEND/RESUME etc) and can have some properties associated with cables(mA) This patch introduces interface to get and set cable properties from EXTCON framework. The cable property can be set either by the extcon cable provider or by other subsystems who know the cable properties using eth API extcon_cable_set_data() When the consumer gets a notification from the extcon, it can use the extcon_cable_get_data() to get the cable properties irrespective of who provides the cable data. This gives a single interface for setting and getting the cable properties. Signed-off-by: Jenny TC --- drivers/extcon/extcon-class.c | 30 ++ include/linux/extcon.h| 39 +++ 2 files changed, 69 insertions(+) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index d398821..304f343 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -545,6 +545,36 @@ int extcon_unregister_notifier(struct extcon_dev *edev, } EXPORT_SYMBOL_GPL(extcon_unregister_notifier); +/** + * extcon_cable_set_data() - Set the data structure for a cable + * @edev: the extcon device + * @cable_index: the cable index of the correspondant + * @type: type of the data structure + * @data: + */ +void extcon_cable_set_data(struct extcon_dev *edev, int cable_index, + enum extcon_cable_name type, + union extcon_cable_data data) +{ + edev->cables[cable_index].type = type; + edev->cables[cable_index].data = data; +} + +/** + * extcon_cable_get_data() - Get the data structure for a cable + * @edev: the extcon device + * @cable_index: the cable index of the correspondant + * @type: type of the data structure + * @data: the corresponding data structure (e.g., regulator) + */ +void extcon_cable_get_data(struct extcon_dev *edev, int cable_index, + enum extcon_cable_name *type, + union extcon_cable_data *data) +{ + *type = edev->cables[cable_index].type; + *data = edev->cables[cable_index].data; +} + static struct device_attribute extcon_attrs[] = { __ATTR(state, S_IRUGO | S_IWUSR, state_show, state_store), __ATTR_RO(name), diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 2c26c14..4556cc5 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -135,6 +135,19 @@ struct extcon_dev { struct device_attribute *d_attrs_muex; }; +/* FIXME: Is this the right place for this structure definition? + * Do we need to move it to power_supply.h? + */ +struct extcon_chrgr_cable_props { + unsigned long state; + int mA; +}; + +union extcon_cable_data { + struct extcon_chrgr_cable_props chrgr_cbl_props; + /* Please add accordingly*/ +}; + /** * struct extcon_cable - An internal data for each cable of extcon device. * @edev The extcon device @@ -143,6 +156,8 @@ struct extcon_dev { * @attr_name "name" sysfs entry * @attr_state "state" sysfs entry * @attrs Array pointing to attr_name and attr_state for attr_g + * @type: The type of @data. + * @data: The data structure representing the status and states of this cable. */ struct extcon_cable { struct extcon_dev *edev; @@ -153,6 +168,11 @@ struct extcon_cable { struct device_attribute attr_state; struct attribute *attrs[3]; /* to be fed to attr_g.attrs */ + + union extcon_cable_data data; + + /* extcon cable type */ + enum extcon_cable_name type; }; /** @@ -183,6 +203,17 @@ extern void extcon_dev_unregister(struct extcon_dev *edev); extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); /* + * Following APIs are for managing the status and states of each cable. + * For example, if a cable is represented as a regulator, then the cable + * may have struct regulator as its data. + */ +extern void extcon_cable_set_data(struct extcon_dev *edev, int cable_index, + enum extcon_cable_name type, + union extcon_cable_data data); +extern void extcon_cable_get_data(struct extcon_dev *edev, int cable_index, + enum extcon_cable_name *type, + union extcon_cable_data *data); +/* * get/set/update_state access the 32b encoded state value, which represents * states of all possible cables of the multistate port. For example, if one * calls extcon_set_state(edev, 0x7), it may mean that all the three cables @@ -244,6 +275,14 @@ static inline int extcon_dev_register(struct extcon_dev *edev, static inline void extcon_dev_unregister(struct
[PATCH 0/7] power_supply: Introduce Power Supply Charging Framework
The Power Supply charging framework connects multiple subsystems to do charging in a generic way. The framework makes use of different new features - Battery Identification framework, pluggable charging algorithms, charger cable arbitrations. PSE compliant charging algorithm also enabled as part of this patch set. With this framework the charging logic can be kept outside the charger driver.The charger driver just need to expose th get_property and set_property functions to get and set a specific set of power supply properties. The driver can convert these values to the hardware configurations to setup charging. Jenny TC (7): power_supply: Add charger control properties power_supply : add charger cable properties power_supply: add throttle state power_supply: Add power_supply notifier power_supply : Introduce battery identification framework power_supply: Introduce Power Supply charging framework power_supply: Introduce PSE compliant algorithm Documentation/power/power_supply_class.txt | 202 ++ drivers/power/Kconfig | 30 + drivers/power/Makefile |3 + drivers/power/battery_id.c | 87 +++ drivers/power/charging_algo_pse.c | 202 ++ drivers/power/power_supply.h | 21 + drivers/power/power_supply_charger.c | 1011 drivers/power/power_supply_charger.h | 130 drivers/power/power_supply_core.c | 38 ++ drivers/power/power_supply_sysfs.c |8 + include/linux/power/battery_id.h | 100 +++ include/linux/power_supply.h | 335 + 12 files changed, 2167 insertions(+) create mode 100644 drivers/power/battery_id.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/battery_id.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 7/7] power_supply: Introduce PSE compliant algorithm
As per PSE standard 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 charging framework based on the type of the battery charging profile. Change-Id: I85149c49b3eb3e259fba72f1d066ba2b020717cd Signed-off-by: Jenny TC --- drivers/power/Kconfig| 12 ++ drivers/power/Makefile |1 + drivers/power/charging_algo_pse.c| 202 ++ drivers/power/power_supply_charger.c | 12 -- include/linux/power/battery_id.h | 45 5 files changed, 260 insertions(+), 12 deletions(-) create mode 100644 drivers/power/charging_algo_pse.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index ff361ee..ec3cf4f 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -18,6 +18,18 @@ 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 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. The + algorithm can be selected by the charging framework based on the type + of the battery charging profile. + + depends on POWER_SUPPLY_CHARGER + config POWER_SUPPLY_BATTID bool "Power Supply Battery Identification Framework" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 021b97a..1909ac2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -9,6 +9,7 @@ power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.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..217799c --- /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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~ + * Author: Jenny TC + */ +#include +#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_ps_pse_mod_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) &&
[PATCH 5/7] power_supply : Introduce battery identification framework
This patch introduces generic battid framework. Different battid drivers sitting on different linux kernel subsystem (1wire, I2C, SFI etc) can interface with the power supply susbsytem using the APIs exposed in the power supply usbsystem. The consumers (charger driver/battery driver/power management drivers) can register for notification from the battery id drivers using the APIs from this framework Change-Id: I3f77f5fd63e050eba13d7e98fcb6bfbbe817621f Signed-off-by: Jenny TC Signed-off-by: adavidra --- Documentation/power/power_supply_class.txt | 12 drivers/power/Kconfig |8 +++ drivers/power/Makefile |1 + drivers/power/battery_id.c | 87 include/linux/power/battery_id.h | 55 ++ 5 files changed, 163 insertions(+) create mode 100644 drivers/power/battery_id.c create mode 100644 include/linux/power/battery_id.h diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt index 5a5e7fa..fc2ff29d 100644 --- a/Documentation/power/power_supply_class.txt +++ b/Documentation/power/power_supply_class.txt @@ -177,6 +177,18 @@ External power supply (AC) lists supplicants (batteries) names in issued by external power supply will notify supplicants via external_power_changed callback. +Reading Battery charging profile + +Power Supply class battery identification framework (battery_id.c) +exposes 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 class using the API +psy_battery_prop_changed(). The framework also exposes API +psy_get_batt_prop() 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() QA ~~ diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index e6f92b4..c95bc55 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY if POWER_SUPPLY +config POWER_SUPPLY_BATTID + bool "Power Supply Battery Identification Framework" + help +Say Y here to enable the power supply battery idnetification +framework. The framework would allow different battery identification +drivers to interface with power supply subsystem. Also it allows consumer +drivers to register for notification from the power_supply subsystem. + config POWER_SUPPLY_DEBUG bool "Power supply debug" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index a4b7417..a8d71db 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG power_supply-y := power_supply_core.o power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o +power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o diff --git a/drivers/power/battery_id.c b/drivers/power/battery_id.c new file mode 100644 index 000..c5a5d02 --- /dev/null +++ b/drivers/power/battery_id.c @@ -0,0 +1,87 @@ +/* + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~ + * Author: Jenny TC + * Author: Ajay Thomas David Rajamanickam + */ + + +#include +#include +#include +#include +#include +#include +#include + +static struct psy_ps_batt_chg_prof batt_property; +static int batt_status; + +DEFINE_SPINLOCK(battid_spinlock); + +/** + * psy_battery_prop_changed - Update properties when battery connection status + *changes + * @battery_conn_stat : The current connection status of battery + * @batt_prop : Address of the psy_ps_batt_chg_prof structure with the updated + *
[PATCH 4/7] power_supply: Add power_supply notifier
This patch adds a notifier chain to the power_supply. This notifier helps drivers in other subsystem to listen to changes in power supply subsystem. This would help to take some actions in those drivers on changing the power supply properties. One such scenario is to increase/decrease system performance based on the battery capacity/voltage. Another scenario is to adjust the h/w peak current detection voltage/current thresholds based on battery voltage/capacity. The notifier helps drivers to listen to changes in power_suppy susbystem without polling the power_supply properties Change-Id: Ic05aa85491e73c60dbb80a479974c8a128bc3aa5 Signed-off-by: Jenny TC --- drivers/power/power_supply_core.c | 17 + include/linux/power_supply.h | 10 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 00e6672..08bce22 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -24,6 +24,9 @@ struct class *power_supply_class; EXPORT_SYMBOL_GPL(power_supply_class); +ATOMIC_NOTIFIER_HEAD(power_supply_notifier); +EXPORT_SYMBOL_GPL(power_supply_notifier); + static struct device_type power_supply_dev_type; static bool __power_supply_is_supplied_by(struct power_supply *supplier, @@ -80,6 +83,8 @@ static void power_supply_changed_work(struct work_struct *work) class_for_each_device(power_supply_class, NULL, psy, __power_supply_changed_work); power_supply_update_leds(psy); + atomic_notifier_call_chain(&power_supply_notifier, + PSY_EVENT_PROP_CHANGED, psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); spin_lock_irqsave(&psy->changed_lock, flags); } @@ -347,6 +352,18 @@ static void power_supply_dev_release(struct device *dev) kfree(dev); } +int power_supply_reg_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_reg_notifier); + +void power_supply_unreg_notifier(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_unreg_notifier); + #ifdef CONFIG_THERMAL static int power_supply_read_temp(struct thermal_zone_device *tzd, unsigned long *temp) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index e99c78d..95a3dd7 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -218,6 +218,13 @@ enum psy_throttle_action { PSY_THROTTLE_INPUT_LIMIT, }; +enum power_supply_notifier_events { + PSY_EVENT_NONE, + PSY_EVENT_PROP_CHANGED, + PSY_EVENT_BATTERY, + PSY_EVENT_CABLE, +}; + struct psy_throttle_state { enum psy_throttle_action throttle_action; unsigned throttle_val; @@ -296,6 +303,9 @@ struct power_supply_info { int use_for_apm; }; +extern struct atomic_notifier_headpower_supply_notifier; +extern int power_supply_reg_notifier(struct notifier_block *nb); +extern void power_supply_unreg_notifier(struct notifier_block *nb); extern struct power_supply *power_supply_get_by_name(const char *name); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); -- 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 6/7] power_supply: Introduce Power Supply charging framework
The Power Supply charging framework connects multiple subsystems to do charging in a generic way. The subsystems involves power_supply, extcon, and thermal. With this the charging is handled in a generic way. The framework makes use of different new features - Battery Identification framework, pluggable charging algorithms, charger cable arbitrations etc. At present 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 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 become 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. Charging framework uses selected 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 framework to plug algorithms from the user space. The framework 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. The arbitration logic inside the framework selects the cable based on it's capabilities and the maximum charge current the platform can support Also this framework exposes features to control charging on different platform states. One such feature is thermal. The framework register with the thermal subsystem and control charging based on the thermal subsystem requirements. Overall this framework removes the charging logic out of the charger driver and the charger driver can just listen to the request from the framework to set the charger properties. This can be implemented by exposing get_property and set property callbacks. Change-Id: I800770a11bb3a9f7a0a7d8d743604fc0daf0a5a8 Signed-off-by: Jenny TC --- Documentation/power/power_supply_class.txt | 174 + drivers/power/Kconfig | 10 + drivers/power/Makefile |1 + drivers/power/power_supply.h | 21 + drivers/power/power_supply_charger.c | 1023 drivers/power/power_supply_charger.h | 130 drivers/power/power_supply_core.c | 21 + include/linux/power_supply.h | 264 +++ 8 files changed, 1644 insertions(+) create mode 100644 drivers/power/power_supply_charger.c create mode 100644 drivers/power/power_supply_charger.h diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt index fc2ff29d..a2be269 100644 --- a/Documentation/power/power_supply_class.txt +++ b/Documentation/power/power_supply_class.txt @@ -190,6 +190,180 @@ used by power supply drivers to setup the charging. Also drivers can register for battery removal/insertion notifications using power_supply_reg_notifier() +Use Charging Framework to setup charging + +* Register the driver with the power_supply class and pass the + charging framework related parameters +* Expose set_property and get_property functions so that charging + framework can control the charging + +Registering charger driver with power supply class +~~ +struct power_supply_class psy_usb; +psy_usb.name = DEV_NAME; +psy_usb.type = POWER_SUPPLY_TYPE_USB; + +/* pointer to power supply property structure */ +psy_usb.properties = &psy_usb_props; +psy_usb.num_properties = ARRAY_SIZE(psy_usb_props); + +/* pointer to power supply get property function */ +psy_usb.get_property = psy_usb_get_property; + +/* pointer to power supply set property function */ +psy_usb.set_property = psy_usb_set_property; + +/* pointer to the supplied_to argument to indicate the batteries + to which this charger is supplying power */ +psy_usb.supplied_to = supplied_to; +psy_usb.num_supplicants = num_supplicants; + +/* Additional Interfaces to support charging framework */ + +/* pointer to throttle states */ +psy_usb.throttle_states = throttle_states; + +/* Number of throttle states */ +psy_usb.num_throttle_states = num_throttle_states; + +/* define supported cable types for this driver */ +psy_usb.supported_cables = POWER_SUPPLY_CHARGER_TYPE_USB; + +/* register with power_supply subsystem */ +power_supply_registe(device, &psy_usb); + +Properties exposed by charger driver + +* POWER_SUPPLY_PROP_ONLINE + * Read access using get_property_function + * Returns the online property set using the
[PATCH 2/7] power_supply : add charger cable properties
Since the charger cables are related to power supply subsystem it makes sense to define the properties associate with charger cables. The properties include cable events and the input current. The cable properties may come from different sources. Since they are associated with power_supply subsystem, it make sense to unify the properties in the power supply susbsyem layer. Also a charger can support different types of charger sources (cables). It make sense to define a field to inform the power supply subsystem what kind of cable a charger driver supports. Since a bitmask would be the easy way to do define, it's good to have a enum which has the bitmask definition for each cable types Change-Id: Ia655c0924b7a5a845121342aa8f5d3840cccfbc4 Signed-off-by: Jenny TC --- include/linux/power_supply.h | 38 ++ 1 file changed, 38 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index ddeab05..c3ce514a 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -166,6 +166,43 @@ enum power_supply_type { POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ }; +enum psy_charger_cable_event { + PSY_CHARGER_CABLE_EVENT_CONNECT = 0, + PSY_CHARGER_CABLE_EVENT_UPDATE, + PSY_CHARGER_CABLE_EVENT_RESUME, + PSY_CHARGER_CABLE_EVENT_SUSPEND, + PSY_CHARGER_CABLE_EVENT_DISCONNECT, +}; + +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, +}; + +struct psy_cable_props { + enum psy_charger_cable_eventchrg_evt; + enum psy_charger_cable_type chrg_type; + unsigned intmA; /* input current limit */ +}; + +#define PSY_CHARGER_CABLE_TYPE_USB \ + (PSY_CHARGER_CABLE_TYPE_USB_SDP | \ + PSY_CHARGER_CABLE_TYPE_USB_DCP | \ + PSY_CHARGER_CABLE_TYPE_USB_CDP | \ + PSY_CHARGER_CABLE_TYPE_USB_ACA | \ + PSY_CHARGER_CABLE_TYPE_ACA_DOCK) + union power_supply_propval { int intval; const char *strval; @@ -181,6 +218,7 @@ struct power_supply { char **supplied_to; size_t num_supplicants; + unsigned long supported_cables; char **supplied_from; size_t num_supplies; -- 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/7] power_supply: Add charger control properties
The battery charger needs to have control path along with the reporting charger properties. In existing solutions this is implemented using regulator framework. A regulator framework doesn't fit a charger driver requirement because of the following reason Charger needs support two paths - charger path (charger to platform) and charging (charger to battery).Disabling the charging path alone (eg over battery temperature) will allow the platform to work with power from charger without discharging the battery. And the charger may need to be disabled completely based on the charger temperature or the platform temperature. Charger has more than one pair of voltage/current to control (CC,CV,INLMT) These features will not directly fit in the regulator framework Since the charger driver sits in the power supply subsystem it make sense to add the properties to control the charger. Signed-off-by: Jenny TC Change-Id: Id91dbbd8f34499afa97b7d8f11ecf5467847f6a8 --- Documentation/power/power_supply_class.txt | 16 drivers/power/power_supply_sysfs.c |8 include/linux/power_supply.h |8 3 files changed, 32 insertions(+) diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt index 3f10b39..5a5e7fa 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_CUR - 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,12 +144,24 @@ TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade. TEMP_AMBIENT - ambient temperature. TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade. TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade. +MIN_TEMP - minimum operatable temperature +MAX_TEMP - maximum operatable temperature TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e. while battery powers a load) TIME_TO_FULL - seconds left for battery to be considered full (i.e. while battery is charging) +ENABLE_CHARGING - Enable/disable charging. Write is used to enable/disable charging. +Reading the interface indicates whether the charging is enabled/disabled by the charger h/w. +ENABLE_CHARGER - Enable/disable charger. Write is used to enable/disable charger. +Reading the interface indicates whether the charger is enabled/disabled. When charger +is disabled platform is not expected to draw current from charging source. + +CABLE_TYPE - Used to indicate the type of cable used for charging. +PRIORITY - Indicates the priority of a power supply charger object. Useful +to setup charging on platforms with multiple charger chips.(Wireless/USB/AC etc.) + Battery <-> external power supply interaction ~ diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index 44420d1..d45c813 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_cur_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(max_temp), + POWER_SUPPLY_ATTR(min_temp), POWER_SUPPLY_ATTR(temp_alert_min), POWER_SUPPLY_ATTR(temp_alert_max), POWER_SUPPLY_ATTR(temp_ambient), @@ -189,6 +192,11 @@ 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_cur), + POWER_SUPPLY_ATTR(enable_charging), + POWER_SUPPLY_ATTR(enable_charger), + POWER_SUPPLY_ATTR(cable_type), + POWER_SUPPLY_ATTR(priority), /* 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 5c26006
[PATCH 0/7] power_supply: Introduce Power Supply Charging Framework
The Power Supply charging framework connects multiple subsystems to do charging in a generic way. The framework makes use of different new features - Battery Identification framework, pluggable charging algorithms, charger cable arbitrations. PSE compliant charging algorithm also enabled as part of this patch set. With this framework the charging logic can be kept outside the charger driver.The charger driver just need to expose th get_property and set_property functions to get and set a specific set of power supply properties. The driver can convert these values to the hardware configurations to setup charging. Jenny TC (7): power_supply: Add charger control properties power_supply : add charger cable properties power_supply: add throttle state power_supply: Add power_supply notifier power_supply : Introduce battery identification framework power_supply: Introduce Power Supply charging framework power_supply: Introduce PSE compliant algorithm Documentation/power/power_supply_class.txt | 202 ++ drivers/power/Kconfig | 30 + drivers/power/Makefile |3 + drivers/power/battery_id.c | 87 +++ drivers/power/charging_algo_pse.c | 202 ++ drivers/power/power_supply.h | 21 + drivers/power/power_supply_charger.c | 1011 drivers/power/power_supply_charger.h | 130 drivers/power/power_supply_core.c | 38 ++ drivers/power/power_supply_sysfs.c |8 + include/linux/power/battery_id.h | 100 +++ include/linux/power_supply.h | 335 + 12 files changed, 2167 insertions(+) create mode 100644 drivers/power/battery_id.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/battery_id.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/7] power_supply: add throttle state
The charger and battery temperature contribute to the platform thermal. The only way to control the temperature is to control the charging. The charging can be controlled in different way. This could be disabling charger, disabling charging, adjusting CC, or by adjusting the INLMT. This patch adds a structure to define the charger throttle actions. Also this patch adds a throttle_states field to the struct power_supply which can be used by the charger driver to define it's throttle actions for different states Change-Id: I390a4c7479df4a7e17f73682802e4be05ea58541 Signed-off-by: Jenny TC --- include/linux/power_supply.h | 15 +++ 1 file changed, 15 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index c3ce514a..e99c78d 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -210,6 +210,18 @@ union power_supply_propval { struct device_node; +enum psy_throttle_action { + + PSY_THROTTLE_DISABLE_CHARGER = 0, + PSY_THROTTLE_DISABLE_CHARGING, + PSY_THROTTLE_CC_LIMIT, + PSY_THROTTLE_INPUT_LIMIT, +}; + +struct psy_throttle_state { + enum psy_throttle_action throttle_action; + unsigned throttle_val; +}; struct power_supply { const char *name; enum power_supply_type type; @@ -224,6 +236,9 @@ struct power_supply { size_t num_supplies; struct device_node *of_node; + struct psy_throttle_state *throttle_states; + size_t num_throttle_states; + int (*get_property)(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val); -- 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] extcon : register for cable interest by cable name
There are some scnearios where a driver/framework needs to register interest for a particular cable without specifying the extcon device name. One such scenario is charger notifications. The platform will have charger cabel which will be bound to any extcon device. It's not mandatory for the charger driver to know which extcon device it should use. This patch enables the support for registering interest for a cable just by cable name wihtout specifying the extcon device name Signed-off-by: Jenny TC --- drivers/extcon/extcon-class.c | 52 + include/linux/extcon.h|3 +++ 2 files changed, 55 insertions(+) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 946a318..3d8e825 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -485,6 +485,58 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, } /** + * extcon_register_interest_cable_byname() - Register a notifier for a state + * change of a specific cable, on any extcon device + * extcon device. + * @obj: an empty extcon_specific_cable_nb object to be returned. + * @cable_name:the target cable name. + * @nb:the notifier block to get notified. + * + * Provide an empty extcon_specific_cable_nb. + * extcon_register_interest_cable_name() sets the struct for you. + * + * extcon_register_cable_interest is a helper function for those who want to get + * notification for a single specific cable's status change without knowing the + * extcon device name. + * + * Note : This will register the interest with the first extcon device which + * reports the status for the cable. If multiple extcon devices reports the + * same cable name, this API will register interest with the first extcon device + */ + +struct extcon_dev *register_interest_cable_byname + (struct extcon_specific_cable_nb *extcon_dev, + const char *cable_name, struct notifier_block *nb) +{ + struct class_dev_iter iter; + struct device *dev; + struct extcon_dev *extd = NULL; + + /* Identify the extcon device which supports the cable and register + * interest. + */ + if (extcon_class == NULL) + return NULL; + class_dev_iter_init(&iter, extcon_class, NULL, NULL); + while ((dev = class_dev_iter_next(&iter))) { + extd = (struct extcon_dev *)dev_get_drvdata(dev); + /* check for cable support */ + if (extcon_find_cable_index(extd, cable_name) < 0) { + extd = NULL; + continue; + } + + if (extcon_register_interest(extcon_dev, extd->name, + cable_name, nb) < 0) { + extd = NULL; + continue; + } + } + class_dev_iter_exit(&iter); + return extd; +} + +/** * extcon_unregister_interest() - Unregister the notifier registered by * extcon_register_interest(). * @obj: the extcon_specific_cable_nb object returned by diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 7443a56..9be8286 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -222,6 +222,9 @@ extern int extcon_register_interest(struct extcon_specific_cable_nb *obj, const char *extcon_name, const char *cable_name, struct notifier_block *nb); +extern struct extcon_dev *register_interest_cable_byname + (struct extcon_specific_cable_nb *extcon_dev, + const char *cable_name, struct notifier_block *nb); extern int extcon_unregister_interest(struct extcon_specific_cable_nb *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] extcon : add charger supported as per spec
Add support for cable names as per USB charging spec 1.2 Also add cable name for AC adapter. This standardises the cable names Signed-off-by: Jenny TC --- drivers/extcon/extcon-class.c |5 + include/linux/extcon.h|5 + 2 files changed, 10 insertions(+) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 3d8e825..7188daf 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -42,6 +42,11 @@ * names that are actually used in your extcon device. */ const char *extcon_cable_name[] = { + [EXTCON_SDP]= "CHARGER_USB_SDP", + [EXTCON_DCP]= "CHARGER_USB_DCP", + [EXTCON_CDP]= "CHARGER_USB_CDP", + [EXTCON_ACA]= "CHARGER_USB_ACA", + [EXTCON_AC] = "CHARGER_AC", [EXTCON_USB]= "USB", [EXTCON_USB_HOST] = "USB-Host", [EXTCON_TA] = "TA", diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 9be8286..073fd49 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -53,6 +53,11 @@ enum extcon_cable_name { EXTCON_FAST_CHARGER, EXTCON_SLOW_CHARGER, EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */ + EXTCON_SDP, + EXTCON_DCP, + EXTCON_CDP, + EXTCON_ACA, + EXTCON_AC, EXTCON_HDMI, EXTCON_MHL, EXTCON_DVI, -- 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] extcon : callback function to read cable property
For some cables a boolean variable will not be enough to represent the state and properties of the cable. For example a charger cable can have states CONNECT,DISCOONECT,SUSPEND(Host suspend for SDP cable), RESUME(Host wakeup), and UPDATE (to increase the charge current after USB enumaeration).Also the properties of the cable may vary based on the state. FOr example in SUSPENDED state platforms can support 0/100/500/950(USB 3.0) mA based on the HW. To initiate charging the consumer should be able to get the charger properties dynamically. Signed-off-by: Jenny TC --- include/linux/extcon.h | 14 ++ 1 file changed, 14 insertions(+) diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 073fd49..2e61ee0 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -122,6 +122,7 @@ struct extcon_dev { /* --- Optional callbacks to override class functions --- */ ssize_t (*print_name)(struct extcon_dev *edev, char *buf); ssize_t (*print_state)(struct extcon_dev *edev, char *buf); + int (*get_cable_properties)(const char *cable_name, void *cable_props); /* --- Internal data. Please do not set. --- */ struct device *dev; @@ -177,6 +178,19 @@ struct extcon_specific_cable_nb { unsigned long previous_value; }; +enum extcon_chrgr_cbl_stat { + EXTCON_CHRGR_CABLE_CONNECTED, + EXTCON_CHRGR_CABLE_DISCONNECTED, + EXTCON_CHRGR_CABLE_SUSPENDED, + EXTCON_CHRGR_CABLE_RESUMED, + EXTCON_CHRGR_CABLE_UPDATED, +}; + +struct extcon_chrgr_cbl_props { + enum extcon_chrgr_cbl_stat cable_stat; + unsigned long mA; +}; + #if IS_ENABLED(CONFIG_EXTCON) /* -- 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 V2] extcon : register for cable interest by cable name
There are some scnearios where a driver/framework needs to register interest for a particular cable without specifying the extcon device name. One such scenario is charger notifications. The platform will have charger cabel which will be bound to any extcon device. It's not mandatory for the charger driver to know which extcon device it should use. This patch enables the support for registering interest for a cable just by cable name wihtout specifying the extcon device name Signed-off-by: Jenny TC --- v1: Initial submit V2: Removed the new API and modified the extcon_register_interest API to accomodate the new requirement drivers/extcon/extcon-class.c | 43 +++-- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 946a318..738919e 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -466,22 +466,45 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, const char *extcon_name, const char *cable_name, struct notifier_block *nb) { - if (!obj || !extcon_name || !cable_name || !nb) + + if (!obj || !cable_name || !nb) return -EINVAL; - obj->edev = extcon_get_extcon_dev(extcon_name); - if (!obj->edev) - return -ENODEV; + if (extcon_name) { + + obj->edev = extcon_get_extcon_dev(extcon_name); + if (!obj->edev) + return -ENODEV; + + obj->cable_index = extcon_find_cable_index(obj->edev, cable_name); + if (obj->cable_index < 0) + return -ENODEV; - obj->cable_index = extcon_find_cable_index(obj->edev, cable_name); - if (obj->cable_index < 0) - return -ENODEV; + obj->user_nb = nb; - obj->user_nb = nb; + obj->internal_nb.notifier_call = _call_per_cable; - obj->internal_nb.notifier_call = _call_per_cable; + return raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); + } else { + struct class_dev_iter iter; + struct extcon_dev *extd; + struct device *dev; + if (!extcon_class) + return -ENODEV; + class_dev_iter_init(&iter, extcon_class, NULL, NULL); + while ((dev = class_dev_iter_next(&iter))) { + extd = (struct extcon_dev *)dev_get_drvdata(dev); + + if (extcon_find_cable_index(extd, cable_name) < 0) + continue; + + class_dev_iter_exit(&iter); + return extcon_register_interest(obj, extd->name, + cable_name, nb); + } - return raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); + return -ENODEV; + } } /** -- 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 0/7] power_supply: Introduce charging Framework
The Power Supply charging framework connects multiple subsystems to do charging in a generic way. The subsystems involves power_supply, extcon, and thermal. With this the charging is handled in a generic way. The framework makes use of different new features - Battery Identification framework, pluggable charging algorithms, charger cable arbitrations. PSE compliant charging algorithm also enabled as part of this patchset. With this framework the charging logic can be kept outside the charger driver. The charger driver just need to expose th get_property and set_property functions to get and set a specific set of power supply properties. The driver can convert these values to the hardware configurations to setup charging. Jenny TC (7): power_supply : Introduce battery identification framework power_supply: Add charger control properties power_supply : add supported charger cable feature power_supply: add throttle state power_supply: Introduce Power Supply charging framework power_supply: enable charger framework callbacks power_supply: Introduce PSE compliant algorithm drivers/power/Kconfig| 28 ++ drivers/power/Makefile |3 + drivers/power/battery_id.c | 94 + drivers/power/charging_algo_pse.c| 79 + drivers/power/power_supply.h | 20 ++ drivers/power/power_supply_charger.c | 634 ++ drivers/power/power_supply_charger.h | 165 + drivers/power/power_supply_core.c| 12 + drivers/power/power_supply_sysfs.c | 16 +- include/linux/power/battery_id.h | 97 ++ include/linux/power_supply.h | 53 ++- 11 files changed, 1189 insertions(+), 12 deletions(-) create mode 100644 drivers/power/battery_id.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/battery_id.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/7] power_supply : Introduce battery identification framework
This patch introduces generic battid framework. Different battid drivers sitting on different linux kernel subsystem (1wire, I2C, SFI etc) can interface with the power supply susbsytem using the APIs exposed in the power supply usbsystem. The consumers (charger driver/battery driver/power management drivers) can register for notification from the battery id drivers using the APIs from this framework Signed-off-by: Jenny TC Signed-off-by: adavidra --- drivers/power/Kconfig|8 drivers/power/Makefile |1 + drivers/power/battery_id.c | 94 ++ include/linux/power/battery_id.h | 50 4 files changed, 153 insertions(+) create mode 100644 drivers/power/battery_id.c create mode 100644 include/linux/power/battery_id.h diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 49a8939..74b297d 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY if POWER_SUPPLY +config POWER_SUPPLY_BATTID + bool "Power Supply Battery Identification Framework" + help +Say Y here to enable the power supply battery idnetification +framework. The framework would allow different battery identification +drivers to interface with power supply subsystem. Also it allows consumer +drivers to register for notification from the power_supply subsystem. + config POWER_SUPPLY_DEBUG bool "Power supply debug" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index b949cf8..6a63f45 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG power_supply-y := power_supply_core.o power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o +power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o diff --git a/drivers/power/battery_id.c b/drivers/power/battery_id.c new file mode 100644 index 000..f6160b6 --- /dev/null +++ b/drivers/power/battery_id.c @@ -0,0 +1,94 @@ +/* + * battery_id.c - Power supply battery identification framework + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~ + * Author: Jenny TC + * Author: David Rajamanickam, Ajay Thomas + * + */ + +#include +#include +#include +#include +#include +#include + +ATOMIC_NOTIFIER_HEAD(batt_id_notifier); + +static struct ps_batt_chg_prof *batt_property; +static int batt_status; + +int batt_id_reg_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&batt_id_notifier, nb); +} +EXPORT_SYMBOL_GPL(batt_id_reg_notifier); + +void batt_id_unreg_notifier(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&batt_id_notifier, nb); +} +EXPORT_SYMBOL_GPL(batt_id_unreg_notifier); + + +/** + * battery_prop_changed - Update properties when battery connection status + *changes + * @battery_conn_stat : The current connection status of battery + * @batt_prop : Address of the ps_batt_chg_prof structure with the updated + * values passed from the calling function + * + * Whenever the battery connection status changes this function will be called + * to indicate a change in the status and to update the status and value of + * properties + */ +void battery_prop_changed(int battery_conn_stat, + struct ps_batt_chg_prof *batt_prop) +{ + if (batt_status != battery_conn_stat) { + if (battery_conn_stat == POWER_SUPPLY_BATTERY_INSERTED) + batt_property = batt_prop; + else + batt_property = NULL; + + batt_status = battery_conn_stat; + } + + atomic_notifier_call_chain(&batt_id_notifier, + 0, &(batt_property)); + +} +EXPORT_SYMBOL_GPL(battery_prop_changed); + +/** + * get_batt_prop - Get the b
[PATCH 2/7] power_supply: Add charger control properties
The battery charger needs to have control path along with the reporting charger properties. In existing solutions this is implemented using regulator framework. A regulator framework doesn't fit a charger driver requirement because of the following reason Charger needs support two paths - charger path (charger to platform) and charging (charger to battery).Disabling the charging path alone (eg over battery temperature) will allow the platform to work with power from charger without discharging the battery. And the charger may need to be disabled completely based on the charger temperature or the platform temperature. Charger has more than one pair of voltage/current to control (CC,CV,INLMT) These features will not directly fit in the regulator framework Since the charger driver sits in the power supply subsystem it make sense to add the properties to control the charger. Also this patch adds/modify the power supply properties to meet the requirements for charger control Signed-off-by: Jenny TC --- drivers/power/power_supply_sysfs.c | 16 include/linux/power_supply.h | 24 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index 40fa3b7..3166d00 100644 --- a/drivers/power/power_supply_sysfs.c +++ b/drivers/power/power_supply_sysfs.c @@ -160,12 +160,13 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(charge_now), POWER_SUPPLY_ATTR(charge_avg), POWER_SUPPLY_ATTR(charge_counter), - POWER_SUPPLY_ATTR(constant_charge_current), - POWER_SUPPLY_ATTR(constant_charge_current_max), - POWER_SUPPLY_ATTR(constant_charge_voltage), - POWER_SUPPLY_ATTR(constant_charge_voltage_max), + POWER_SUPPLY_ATTR(charge_current), + POWER_SUPPLY_ATTR(max_charge_current), + POWER_SUPPLY_ATTR(charge_voltage), + POWER_SUPPLY_ATTR(max_charge_voltage), POWER_SUPPLY_ATTR(charge_control_limit), POWER_SUPPLY_ATTR(charge_control_limit_max), + POWER_SUPPLY_ATTR(input_cur_limit), POWER_SUPPLY_ATTR(energy_full_design), POWER_SUPPLY_ATTR(energy_empty_design), POWER_SUPPLY_ATTR(energy_full), @@ -177,6 +178,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(max_temp), + POWER_SUPPLY_ATTR(min_temp), POWER_SUPPLY_ATTR(temp_alert_min), POWER_SUPPLY_ATTR(temp_alert_max), POWER_SUPPLY_ATTR(temp_ambient), @@ -188,6 +191,11 @@ 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_cur), + POWER_SUPPLY_ATTR(enable_charging), + POWER_SUPPLY_ATTR(enable_charger), + POWER_SUPPLY_ATTR(cable_type), + POWER_SUPPLY_ATTR(priority), /* 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 1f0ab90..7c06956 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -110,12 +110,13 @@ enum power_supply_property { POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_AVG, POWER_SUPPLY_PROP_CHARGE_COUNTER, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, + POWER_SUPPLY_PROP_CHARGE_CURRENT, + POWER_SUPPLY_PROP_MAX_CHARGE_CURRENT, + POWER_SUPPLY_PROP_CHARGE_VOLTAGE, + POWER_SUPPLY_PROP_MAX_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, + POWER_SUPPLY_PROP_INLMT, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, POWER_SUPPLY_PROP_ENERGY_FULL, @@ -127,6 +128,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_MAX_TEMP, + POWER_SUPPLY_PROP_MIN_TEMP, POWER_SUPPLY_PROP_TEMP_ALERT_MIN, POWER_SUPPLY_PROP_TEMP_ALERT_MAX, POWER_SUPPLY_PROP_TEMP_AMBIENT, @@ -138,6 +141,11 @@ 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_CUR, + POWER_SUPPLY_PROP_ENABLE_CHARGING, + POWER_SUPPLY_PROP_ENABLE_CHARGER, + POWER_SUPPLY_PROP_CABLE_TYPE, + POWER_SUPPLY_PROP_PRIORITY, /* Pro
[PATCH 3/7] power_supply : add supported charger cable feature
A charger can support different types of charger sources (cables). It make sense to define a field to inform the power supply subsystem what kind of cable a charger driver supports. Since a bitmask would be the easy way to do define, it's good to have a enum which has the bitmask definition for each cable types Signed-off-by: Jenny TC --- include/linux/power_supply.h | 16 1 file changed, 16 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 7c06956..eea1709 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -163,6 +163,21 @@ enum power_supply_type { POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ }; +enum power_supply_charger_cable_type { + POWER_SUPPLY_CHARGER_TYPE_NONE = 0, + POWER_SUPPLY_CHARGER_TYPE_USB_SDP = 1 << 0, + POWER_SUPPLY_CHARGER_TYPE_USB_DCP = 1 << 1, + POWER_SUPPLY_CHARGER_TYPE_USB_CDP = 1 << 2, + POWER_SUPPLY_CHARGER_TYPE_USB_ACA = 1 << 3, + POWER_SUPPLY_CHARGER_TYPE_AC = 1 << 4, +}; + +#define POWER_SUPPLY_CHARGER_TYPE_USB \ + (POWER_SUPPLY_CHARGER_TYPE_USB_SDP | \ + POWER_SUPPLY_CHARGER_TYPE_USB_DCP | \ + POWER_SUPPLY_CHARGER_TYPE_USB_CDP | \ + POWER_SUPPLY_CHARGER_TYPE_USB_ACA) + union power_supply_propval { int intval; const char *strval; @@ -175,6 +190,7 @@ struct power_supply { size_t num_properties; char **supplied_to; + unsigned long supported_cables; size_t num_supplicants; int (*get_property)(struct power_supply *psy, -- 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/7] power_supply: add throttle state
The charger and battery temperature contribute to the platform thermal. The only way to control the temperature is to control the charging. The charging can be controlled in different way. This could be disabling charger, disabling charging, adjusting CC, or by adjusting the INLMT. This patch adds a structure to define the charger throttle actions. Also this patch adds a throttle_states field to the struct power_supply which can be used by the charger driver to define it's throttle actions for different states Signed-off-by: Jenny TC --- include/linux/power_supply.h | 13 + 1 file changed, 13 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index eea1709..b4eb0af 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -183,6 +183,18 @@ union power_supply_propval { const char *strval; }; +enum psy_throttle_action { + + PSY_THROTTLE_DISABLE_CHARGER = 0, + PSY_THROTTLE_DISABLE_CHARGING, + PSY_THROTTLE_CC_LIMIT, + PSY_THROTTLE_INPUT_LIMIT, +}; + +struct power_supply_throttle { + enum psy_throttle_action throttle_action; + unsigned throttle_val; +}; struct power_supply { const char *name; enum power_supply_type type; @@ -192,6 +204,7 @@ struct power_supply { char **supplied_to; unsigned long supported_cables; size_t num_supplicants; + struct power_supply_throttle *throttle_states; int (*get_property)(struct power_supply *psy, enum power_supply_property psp, -- 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 5/7] power_supply: Introduce Power Supply charging framework
The Power Supply charging framework connects multiple subsystems to do charging in a generic way. The subsystems involves power_supply, extcon, and thermal. With this the charging is handled in a generic way. The framework makes use of different new features - Battery Identification framework, pluggable charging algorithms, charger cable arbitrations etc. At present 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 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 become 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. Charging framework uses selected 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 framework to plug algorithms from the user space. The framework 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. The arbitration logic inside the framework selects the cable based on it's capabilities and the maximum charge current the platform can support Also this framework exposes features to control charging on different platform states. One such feature is thermal. The framework register with the thermal subsystem and control charging based on the thermal subsystem requirements. Overall this framework removes the charging logic out of the charger driver and the charger driver can just listen to the request from the framework to set the charger properties. This can be implemented by exposing get_property and set property callbacks. Signed-off-by: Jenny TC --- drivers/power/Kconfig|8 + drivers/power/Makefile |1 + drivers/power/power_supply_charger.c | 634 ++ drivers/power/power_supply_charger.h | 165 + 4 files changed, 808 insertions(+) create mode 100644 drivers/power/power_supply_charger.c create mode 100644 drivers/power/power_supply_charger.h diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 74b297d..34850e4 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY if POWER_SUPPLY +config POWER_SUPPLY_CHARGER + bool "Power Supply Charger" + help + Say Y here to enable the power supply charger framework. Charger + framework 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 + config POWER_SUPPLY_BATTID bool "Power Supply Battery Identification Framework" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 6a63f45..ce8c230 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG power_supply-y := power_supply_core.o power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o +power_supply-$(CONFIG_POWER_SUPPLY_CHARGER) += power_supply_charger.o power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o diff --git a/drivers/power/power_supply_charger.c b/drivers/power/power_supply_charger.c new file mode 100644 index 000..413a26c --- /dev/null +++ b/drivers/power/power_supply_charger.c @@ -0,0 +1,634 @@ +#define DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "power_supply.h" +#include "power_supply_charger.h" + +#define MAX_CHARGER_COUNT 5 + +static LIST_HEAD(algo_list); + +struct power_supply_charger { + bool is_cable_evt_reg; + /*cache battery and charger properties */ + struct list_head chrgr_cache_lst; + struct list_head batt_cache_lst; + struct list_head evt_queue; + spinlock_t evt_lock; +}; + +struct charger_cable { + struct work_struct work; + struct notifier_block nb; + struct extcon_chrgr_cbl_props cable_props; + enum extcon_cable_name extcon_cable_type; + enum power_supply_charger_cable_type psy_cable_type; + struct extcon_specific_cable_nb extcon_dev; + struct extcon_dev *edev; +}; + +static struct power_supply_charg
[PATCH 6/7] power_supply: enable charger framework callbacks
The charger framework needs to be notified on registering a new charger, on power supply changed event or on a thermal throttle request. This patch enables support for the same Signed-off-by: Jenny TC --- drivers/power/power_supply.h | 20 drivers/power/power_supply_core.c | 12 2 files changed, 32 insertions(+) diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h index cc439fd..ae2d66c 100644 --- a/drivers/power/power_supply.h +++ b/drivers/power/power_supply.h @@ -40,3 +40,23 @@ static inline int power_supply_create_triggers(struct power_supply *psy) static inline void power_supply_remove_triggers(struct power_supply *psy) {} #endif /* CONFIG_LEDS_TRIGGERS */ +#ifdef CONFIG_POWER_SUPPLY_CHARGER + +extern void power_supply_trigger_charging_handler(struct power_supply *psy); +extern int power_supply_register_charger(struct power_supply *psy); +extern int power_supply_unregister_charger(struct power_supply *psy); +extern int psy_charger_throttle_charger(struct power_supply *psy, + unsigned long state); + +#else + +static inline void power_supply_trigger_charging_handler(struct power_supply *psy) { } +static inline int power_supply_register_charger(struct power_supply *psy) +{ return 0; } +static inline int power_supply_unregister_charger(struct power_supply *psy) +{ return 0; } +static inline int psy_charger_throttle_charger(struct power_supply *psy, + unsigned long state) +{ return 0; } + +#endif diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 3338d49..73ac6e4 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -19,6 +19,7 @@ #include #include #include "power_supply.h" +#include "power_supply_charger.h" /* exported for the APM Power driver, APM emulation */ struct class *power_supply_class; @@ -49,6 +50,7 @@ static void power_supply_changed_work(struct work_struct *work) class_for_each_device(power_supply_class, NULL, psy, __power_supply_changed_work); + power_supply_trigger_charging_handler(psy); power_supply_update_leds(psy); @@ -265,6 +267,8 @@ static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd, ret = psy->set_property(psy, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val); + psy_charger_throttle_charger(psy,state); + return ret; } @@ -360,10 +364,16 @@ int power_supply_register(struct device *parent, struct power_supply *psy) if (rc) goto create_triggers_failed; + if (IS_CHARGER(psy)) + rc = power_supply_register_charger(psy); + if (rc) + goto charger_register_failed; + power_supply_changed(psy); goto success; +charger_register_failed: create_triggers_failed: psy_unregister_cooler(psy); register_cooler_failed: @@ -382,6 +392,8 @@ void power_supply_unregister(struct power_supply *psy) { cancel_work_sync(&psy->changed_work); sysfs_remove_link(&psy->dev->kobj, "powers"); + if (IS_CHARGER(psy)) +power_supply_unregister_charger(psy); power_supply_remove_triggers(psy); psy_unregister_cooler(psy); psy_unregister_thermal(psy); -- 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 7/7] power_supply: Introduce PSE compliant algorithm
As per PSE standard 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 charging framework based on the type of the battery charging profile. Signed-off-by: Jenny TC --- drivers/power/Kconfig | 12 ++ drivers/power/Makefile|1 + drivers/power/charging_algo_pse.c | 79 + include/linux/power/battery_id.h | 47 ++ 4 files changed, 139 insertions(+) create mode 100644 drivers/power/charging_algo_pse.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 34850e4..e09be69 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -16,6 +16,18 @@ 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 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. The + algorithm can be selected by the charging framework based on the type + of the battery charging profile. + + depends on POWER_SUPPLY_CHARGER + config POWER_SUPPLY_BATTID bool "Power Supply Battery Identification Framework" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index ce8c230..8b250b2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -8,6 +8,7 @@ power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.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 diff --git a/drivers/power/charging_algo_pse.c b/drivers/power/charging_algo_pse.c new file mode 100644 index 000..66feff8 --- /dev/null +++ b/drivers/power/charging_algo_pse.c @@ -0,0 +1,79 @@ +#define DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "power_supply.h" +#include "power_supply_charger.h" + +static int get_tempzone(struct ps_pse_mod_prof *pse_mod_bprof, + int temp) +{ + + int i = 0; + int temp_range_cnt = pse_mod_bprof->temp_mon_ranges; + + 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; +} + +static int pse_get_next_cc_cv(struct batt_props bat_prop, + struct ps_batt_chg_prof bprof, unsigned long *cc, unsigned long *cv) +{ + int tzone; + struct ps_pse_mod_prof *pse_mod_bprof; + + + if (bprof.chrg_prof_type != PSE_MOD_CHRG_PROF) + return -EINVAL; + + pse_mod_bprof = (struct ps_pse_mod_prof *) bprof.batt_prof; + + if (!pse_mod_bprof) + return -EINVAL; + + tzone = get_tempzone(pse_mod_bprof, bat_prop.temperature); + + if (tzone < 0) + return -ENODATA; + + /* read cc and cv based on temperature and battery status*/ + + *cc = pse_mod_bprof->temp_mon_range[tzone].full_chrg_cur; + if (bat_prop.status == POWER_SUPPLY_STATUS_FULL) + *cv = pse_mod_bprof->temp_mon_range[tzone].maint_chrg_vol_ul; + else + *cv = pse_mod_bprof->temp_mon_range[tzone].full_chrg_vol; + + /* Software full detection: Set cc and cv to zero if FULL battery + * condition is met + */ + if ((bat_prop.current_now <= pse_mod_bprof->chrg_term_mA) && + (pse_mod_bprof->temp_mon_range[tzone].full_chrg_vol >= cv)) + *cc = *cv = 0; + return 0; +} + +static int __init pse_algo_init(void) +{ + struct charging_algo pse_algo; + pse_algo.chrg_prof_type = PSE_MOD_CHRG_PROF; + pse_algo.name = "pse_algo"; + pse_algo.get_next_cc_cv = pse_get_next_cc_cv; + power_supply_register_charging_algo(&pse_algo); + return 0; +} + +module_init(pse_algo_init); diff --git a/include/linux/power/battery_id.h b/include/linux/power/battery_id.h index 9a4832e..860a8b8 100644 --- a/include/linux/power/battery_id.h +++ b/include/linux/power/battery_id.h @@ -33,12 +33,59 @@
[PATCH 1/3] power_supply: Add charger control properties
The battery charger needs to have control path along with the reporting charger properties. In existing solutions this is implemented using regulator framework. A regulator framework doesn't fit a charger driver requirement because of the following reason Charger needs support two paths - charger path (charger to platform) and charging (charger to battery).Disabling the charging path alone (eg over battery temperature) will allow the platform to work with power from charger without discharging the battery. And the charger may need to be disabled completely based on the charger temperature or the platform temperature. Charger has more than one pair of voltage/current to control (CC,CV,INLMT).These features will not directly fit in the regulator framework. Since the charger driver sits in the power supply subsystem it make sense to add the properties to control the charger. Signed-off-by: Jenny TC --- drivers/power/power_supply_sysfs.c |8 include/linux/power_supply.h |8 2 files changed, 16 insertions(+) diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index 29178f7..643971c 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_cur_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(max_temp), + POWER_SUPPLY_ATTR(min_temp), POWER_SUPPLY_ATTR(temp_alert_min), POWER_SUPPLY_ATTR(temp_alert_max), POWER_SUPPLY_ATTR(temp_ambient), @@ -189,6 +192,11 @@ 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_cur), + POWER_SUPPLY_ATTR(enable_charging), + POWER_SUPPLY_ATTR(enable_charger), + POWER_SUPPLY_ATTR(cable_type), + POWER_SUPPLY_ATTR(priority), /* 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 804b906..1265131 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -118,6 +118,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_INLMT, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, POWER_SUPPLY_PROP_ENERGY_FULL, @@ -129,6 +130,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_MAX_TEMP, + POWER_SUPPLY_PROP_MIN_TEMP, POWER_SUPPLY_PROP_TEMP_ALERT_MIN, POWER_SUPPLY_PROP_TEMP_ALERT_MAX, POWER_SUPPLY_PROP_TEMP_AMBIENT, @@ -140,6 +143,11 @@ 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_CUR, + POWER_SUPPLY_PROP_ENABLE_CHARGING, + POWER_SUPPLY_PROP_ENABLE_CHARGER, + POWER_SUPPLY_PROP_CABLE_TYPE, + POWER_SUPPLY_PROP_PRIORITY, /* 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 3/3] power_supply: add throttle state
The charger and battery temperature contribute to the platform thermal. The only way to control the temperature is to control the charging. The charging can be controlled in different way. This could be disabling charger, disabling charging, adjusting CC, or by adjusting the INLMT. This patch adds a structure to define the charger throttle actions. Also this patch adds a throttle_states field to the struct power_supply which can be used by the charger driver to define it's throttle actions for different states Signed-off-by: Jenny TC --- include/linux/power_supply.h | 15 +++ 1 file changed, 15 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 5a24e10..516e4c4 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -209,6 +209,18 @@ union power_supply_propval { struct device_node; +enum psy_throttle_action { + + PSY_THROTTLE_DISABLE_CHARGER = 0, + PSY_THROTTLE_DISABLE_CHARGING, + PSY_THROTTLE_CC_LIMIT, + PSY_THROTTLE_INPUT_LIMIT, +}; + +struct psy_throttle_state { + enum psy_throttle_action throttle_action; + unsigned throttle_val; +}; struct power_supply { const char *name; enum power_supply_type type; @@ -223,6 +235,9 @@ struct power_supply { size_t num_supplies; struct device_node *of_node; + struct psy_throttle_state *throttle_states; + size_t num_throttle_states; + int (*get_property)(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val); -- 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 2/3] power_supply : add charger cable properties
Since the charger cables are related to power supply subsystem it makes sense to define the properties associate with charger cables. The properties include cable events and the input current. The cable properties may come from different sources. Since they are associated with power_supply subsystem, it make sense to unify the properties in the power supply susbsyem layer. Also a charger can support different types of charger sources (cables). It make sense to define a field to inform the power supply subsystem what kind of cable a charger driver supports. Since a bitmask would be the easy way to do define, it's good to have a enum which has the bitmask definition for each cable types Signed-off-by: Jenny TC --- include/linux/power_supply.h | 38 ++ 1 file changed, 38 insertions(+) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 1265131..5a24e10 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -165,6 +165,43 @@ enum power_supply_type { POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ }; +enum psy_charger_cable_event { + PSY_CHARGER_CABLE_EVENT_CONNECT = 0, + PSY_CHARGER_CABLE_EVENT_UPDATE, + PSY_CHARGER_CABLE_EVENT_RESUME, + PSY_CHARGER_CABLE_EVENT_SUSPEND, + PSY_CHARGER_CABLE_EVENT_DISCONNECT, +}; + +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, +}; + +struct psy_cable_props { + enum psy_charger_cable_eventchrg_evt; + enum psy_charger_cable_type chrg_type; + unsigned intmA; /* input current limit */ +}; + +#define PSY_CHARGER_CABLE_TYPE_USB \ + (PSY_CHARGER_CABLE_TYPE_USB_SDP | \ + PSY_CHARGER_CABLE_TYPE_USB_DCP | \ + PSY_CHARGER_CABLE_TYPE_USB_CDP | \ + PSY_CHARGER_CABLE_TYPE_USB_ACA | \ + PSY_CHARGER_CABLE_TYPE_ACA_DOCK) + union power_supply_propval { int intval; const char *strval; @@ -180,6 +217,7 @@ struct power_supply { char **supplied_to; size_t num_supplicants; + unsigned long supported_cables; char **supplied_from; size_t num_supplies; -- 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] power_supply: Add power_supply notifier
This patch adds a notifier chain to the power_supply. This notifier helps drivers in other subsystem to listen to changes in power supply subsystem. This would help to take some actions in those drivers on changing the power supply properties. One such scenario is to increase/decrease system performance based on the battery capacity/voltage. Another scenario is to adjust the h/w peak current detection voltage/current thresholds based on battery voltage/capacity. The notifier helps drivers to listen to changes in power_suppy susbystem without polling the power_supply properties Signed-off-by: Jenny TC --- drivers/power/power_supply_core.c | 18 ++ include/linux/power_supply.h |7 +++ 2 files changed, 25 insertions(+) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 3b2d5df..a5779b3 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -24,6 +24,9 @@ struct class *power_supply_class; EXPORT_SYMBOL_GPL(power_supply_class); +ATOMIC_NOTIFIER_HEAD(power_supply_notifier); +EXPORT_SYMBOL(power_supply_notifier); + static struct device_type power_supply_dev_type; static bool __power_supply_is_supplied_by(struct power_supply *supplier, @@ -76,6 +79,9 @@ static void power_supply_changed_work(struct work_struct *work) __power_supply_changed_work); power_supply_update_leds(psy); + + atomic_notifier_call_chain(&power_supply_notifier, + POWER_SUPPLY_PROP_CHANGED, psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); } @@ -328,6 +334,18 @@ static void power_supply_dev_release(struct device *dev) kfree(dev); } +int power_supply_reg_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_reg_notifier); + +void power_supply_unreg_notifier(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&power_supply_notifier, nb); +} +EXPORT_SYMBOL_GPL(power_supply_unreg_notifier); + #ifdef CONFIG_THERMAL static int power_supply_read_temp(struct thermal_zone_device *tzd, unsigned long *temp) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 516e4c4..32fae9c 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -217,6 +217,10 @@ enum psy_throttle_action { PSY_THROTTLE_INPUT_LIMIT, }; +enum power_supply_notifier_events { + POWER_SUPPLY_PROP_CHANGED, +}; + struct psy_throttle_state { enum psy_throttle_action throttle_action; unsigned throttle_val; @@ -293,6 +297,9 @@ struct power_supply_info { int use_for_apm; }; +extern struct atomic_notifier_headpower_supply_notifier; +extern int power_supply_reg_notifier(struct notifier_block *nb); +extern void power_supply_unreg_notifier(struct notifier_block *nb); extern struct power_supply *power_supply_get_by_name(const char *name); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); -- 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 v2 1/3] power_supply: Add charger control properties
The battery charger needs to have control path along with the reporting charger properties. In existing solutions this is implemented using regulator framework. A regulator framework doesn't fit a charger driver requirement because of the following reason Charger needs support two paths - charger path (charger to platform) and charging (charger to battery).Disabling the charging path alone (eg over battery temperature) will allow the platform to work with power from charger without discharging the battery. And the charger may need to be disabled completely based on the charger temperature or the platform temperature. Charger has more than one pair of voltage/current to control (CC,CV,INLMT) These features will not directly fit in the regulator framework Since the charger driver sits in the power supply subsystem it make sense to add the properties to control the charger. Signed-off-by: Jenny TC --- Documentation/power/power_supply_class.txt | 16 drivers/power/power_supply_sysfs.c |8 include/linux/power_supply.h |8 3 files changed, 32 insertions(+) diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt index 3f10b39..5a5e7fa 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_CUR - 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,12 +144,24 @@ TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade. TEMP_AMBIENT - ambient temperature. TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade. TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade. +MIN_TEMP - minimum operatable temperature +MAX_TEMP - maximum operatable temperature TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e. while battery powers a load) TIME_TO_FULL - seconds left for battery to be considered full (i.e. while battery is charging) +ENABLE_CHARGING - Enable/disable charging. Write is used to enable/disable charging. +Reading the interface indicates whether the charging is enabled/disabled by the charger h/w. +ENABLE_CHARGER - Enable/disable charger. Write is used to enable/disable charger. +Reading the interface indicates whether the charger is enabled/disabled. When charger +is disabled platform is not expected to draw current from charging source. + +CABLE_TYPE - Used to indicate the type of cable used for charging. +PRIORITY - Indicates the priority of a power supply charger object. Useful +to setup charging on platforms with multiple charger chips.(Wireless/USB/AC etc.) + Battery <-> external power supply interaction ~ diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index 29178f7..643971c 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_cur_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(max_temp), + POWER_SUPPLY_ATTR(min_temp), POWER_SUPPLY_ATTR(temp_alert_min), POWER_SUPPLY_ATTR(temp_alert_max), POWER_SUPPLY_ATTR(temp_ambient), @@ -189,6 +192,11 @@ 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_cur), + POWER_SUPPLY_ATTR(enable_charging), + POWER_SUPPLY_ATTR(enable_charger), + POWER_SUPPLY_ATTR(cable_type), + POWER_SUPPLY_ATTR(priority), /* 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 804b906..1265131 100644 --- a/include/linux/power_supply
[PATCH] kernel_notifier: register conditional raw notifier
Introduce a new API raw_notifier_chain_cond_register to add a notifier to a raw notifier chain, only if notifier not already present in the chain. Signed-off-by: Jenny TC --- kernel/notifier.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/kernel/notifier.c b/kernel/notifier.c index 2d5cc4c..267e26f 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c @@ -349,6 +349,24 @@ int raw_notifier_chain_register(struct raw_notifier_head *nh, EXPORT_SYMBOL_GPL(raw_notifier_chain_register); /** + * raw_notifier_chain_cond_register - Cond add notifier to a raw notifier chain + * @nh: Pointer to head of the raw notifier chain + * @n: New entry in notifier chain + * + * Adds a notifier to a raw notifier chain, only if not already + * present in the chain. + * All locking must be provided by the caller. + * + * Currently always returns zero. + */ +int raw_notifier_chain_cond_register(struct raw_notifier_head *nh, + struct notifier_block *n) +{ + return notifier_chain_cond_register(&nh->head, n); +} +EXPORT_SYMBOL_GPL(raw_notifier_chain_cond_register); + +/** * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain * @nh: Pointer to head of the raw notifier chain * @n: Entry to remove from notifier chain -- 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 v2] kernel_notifier: register conditional raw notifier
Introduce a new API raw_notifier_chain_cond_register to add a notifier to a raw notifier chain, only if notifier not already present in the chain. Signed-off-by: Jenny TC --- v1 * Added API definition v2 * Added API decalarion include/linux/notifier.h |2 ++ kernel/notifier.c| 18 ++ 2 files changed, 20 insertions(+) diff --git a/include/linux/notifier.h b/include/linux/notifier.h index d65746e..67895f0 100644 --- a/include/linux/notifier.h +++ b/include/linux/notifier.h @@ -124,6 +124,8 @@ extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh, extern int blocking_notifier_chain_cond_register( struct blocking_notifier_head *nh, struct notifier_block *nb); +extern int raw_notifier_chain_cond_register(struct raw_notifier_head *nh, + struct notifier_block *nb); extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, struct notifier_block *nb); diff --git a/kernel/notifier.c b/kernel/notifier.c index 2d5cc4c..267e26f 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c @@ -349,6 +349,24 @@ int raw_notifier_chain_register(struct raw_notifier_head *nh, EXPORT_SYMBOL_GPL(raw_notifier_chain_register); /** + * raw_notifier_chain_cond_register - Cond add notifier to a raw notifier chain + * @nh: Pointer to head of the raw notifier chain + * @n: New entry in notifier chain + * + * Adds a notifier to a raw notifier chain, only if not already + * present in the chain. + * All locking must be provided by the caller. + * + * Currently always returns zero. + */ +int raw_notifier_chain_cond_register(struct raw_notifier_head *nh, + struct notifier_block *n) +{ + return notifier_chain_cond_register(&nh->head, n); +} +EXPORT_SYMBOL_GPL(raw_notifier_chain_cond_register); + +/** * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain * @nh: Pointer to head of the raw notifier chain * @n: Entry to remove from notifier chain -- 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 V2] power_supply : Introduce battery identification framework
This patch introduces generic battid framework. Different battid drivers sitting on different linux kernel subsystem (1wire, I2C, SFI etc) can interface with the power supply susbsytem using the APIs exposed in the power supply usbsystem. The consumers (charger driver/battery driver/power management drivers) can register for notification from the battery id drivers using the APIs from this framework Signed-off-by: Jenny TC Signed-off-by: adavidra --- V1: Submitted the initialcode V2: Added file headers drivers/power/Kconfig|8 drivers/power/Makefile |1 + drivers/power/battery_id.c | 94 ++ include/linux/power/battery_id.h | 50 4 files changed, 153 insertions(+) create mode 100644 drivers/power/battery_id.c create mode 100644 include/linux/power/battery_id.h diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 49a8939..74b297d 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY if POWER_SUPPLY +config POWER_SUPPLY_BATTID + bool "Power Supply Battery Identification Framework" + help +Say Y here to enable the power supply battery idnetification +framework. The framework would allow different battery identification +drivers to interface with power supply subsystem. Also it allows consumer +drivers to register for notification from the power_supply subsystem. + config POWER_SUPPLY_DEBUG bool "Power supply debug" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index b949cf8..6a63f45 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG power_supply-y := power_supply_core.o power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o +power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o diff --git a/drivers/power/battery_id.c b/drivers/power/battery_id.c new file mode 100644 index 000..f6160b6 --- /dev/null +++ b/drivers/power/battery_id.c @@ -0,0 +1,94 @@ +/* + * battery_id.c - Power supply battery identification framework + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~ + * Author: Jenny TC + * Author: David Rajamanickam, Ajay Thomas + * + */ + +#include +#include +#include +#include +#include +#include + +ATOMIC_NOTIFIER_HEAD(batt_id_notifier); + +static struct ps_batt_chg_prof *batt_property; +static int batt_status; + +int batt_id_reg_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&batt_id_notifier, nb); +} +EXPORT_SYMBOL_GPL(batt_id_reg_notifier); + +void batt_id_unreg_notifier(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&batt_id_notifier, nb); +} +EXPORT_SYMBOL_GPL(batt_id_unreg_notifier); + + +/** + * battery_prop_changed - Update properties when battery connection status + *changes + * @battery_conn_stat : The current connection status of battery + * @batt_prop : Address of the ps_batt_chg_prof structure with the updated + * values passed from the calling function + * + * Whenever the battery connection status changes this function will be called + * to indicate a change in the status and to update the status and value of + * properties + */ +void battery_prop_changed(int battery_conn_stat, + struct ps_batt_chg_prof *batt_prop) +{ + if (batt_status != battery_conn_stat) { + if (battery_conn_stat == POWER_SUPPLY_BATTERY_INSERTED) + batt_property = batt_prop; + else + batt_property = NULL; + + batt_status = battery_conn_stat; + } + + atomic_notifier_call_chain(&batt_id_notifier, + 0, &(batt_property)); + +} +EX
Re: [PATCH 3.14] power_supply: don't export power_supply_notifier
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 4/4] power_supply: bq24261 charger driver
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
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/
[PATCH v7 1/4] power_supply: Add inlmt,iterm, min/max temp props
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
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
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
[PATCHv7 4/4] power_supply: bq24261 charger driver
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
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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
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 2/4] power_supply: Introduce generic psy charging driver
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_
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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 4/4] power_supply: bq24261 charger driver
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
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
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
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/
[PATCH 4/4] power_supply: bq24261 charger driver
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
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_mod_
Re: [PATCH v3 14/15] charger: max14577: Configure battery-dependent settings from DTS
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 v3 0/4] power_supply: Introduce power supply charging driver
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 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. At present 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 (BSI/SDQ/MIPI BIF). It become 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 arbitrates between different charger chip drivers based on their priority. 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. 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 Power Supply charging driver power_supply: Introduce PSE compliant algorithm power_supply: bq24261 charger driver Documentation/power/power_supply_charger.txt | 332 ++ Documentation/power/power_supply_class.txt |6 + drivers/power/Kconfig| 30 + drivers/power/Makefile |3 + drivers/power/bq24261_charger.c | 1447 ++ drivers/power/charging_algo_pse.c| 198 drivers/power/power_supply_charger.c | 1191 + 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| 33 + include/linux/power/power_supply_charger.h | 234 + include/linux/power_supply.h | 162 +++ 13 files changed, 3861 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
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 | 1447 + include/linux/power/bq24261_charger.h | 33 + 4 files changed, 1491 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 655457b..3f32f61 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -408,6 +408,16 @@ config BATTERY_GOLDFISH Say Y to enable support for the battery and AC power in the Goldfish emulator. +config BQ24261_CHARGER + 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..6d184c8 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_BQ24261_CHARGER) += 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..6ac063b --- /dev/null +++ b/drivers/power/bq24261_charger.c @@ -0,0 +1,1447 @@ +/* + * 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 + */ +#define DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define DEV_NAME "bq24261_charger" +#define DEV_MANUFACTURER "TI" +#define MODEL_NAME_SIZE 8 +#define DEV_MANUFACTURER_NAME_SIZE 4 + +#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 <&l
[PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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 | 12 ++ drivers/power/Makefile |1 + drivers/power/charging_algo_pse.c | 198 include/linux/power/power_supply_charger.h | 44 +++ 4 files changed, 255 insertions(+) create mode 100644 drivers/power/charging_algo_pse.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 7bfad7a..655457b 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -22,6 +22,18 @@ 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 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. The + algorithm can be selected by the charging framework 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..41c24c3 --- /dev/null +++ b/drivers/power/charging_algo_pse.c @@ -0,0 +1,198 @@ +/* + * 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_ps_pse_mod_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_ps_pse_mod_prof *pse_mod_bprof, unsigned long cv) +{ + + int i; + /* Software full detection. Check the bat
[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
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 Change-Id: Ifb40662bbfa24387ac7493ffa7ce01c6fae7e800 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..f7e06d7 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_CUR - 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..222dd78 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_cur_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_cur), /* 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..4dbb543 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_INLMT, 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_CUR, /* 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/
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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 2/4] power_supply: Introduce generic psy charging driver
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/
[PATCHv8 3/4] power_supply: Introduce PSE compliant algorithm
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
[PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props
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
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
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
Re: power_supply mailing list
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/
Re: [PATCHv8 1/4] power_supply: Add inlmt,iterm, min/max temp props
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 2/4] power_supply: Introduce generic psy charging driver
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
Re: [RFC] power_supply: Introduce generic psy charging driver
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/
[PATCHv9 0/4] power_supply: Introduce power supply charging driver
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
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
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 4/4] power_supply: bq24261 charger driver
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
Re: Power Supply Subsystem Maintainer
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/
[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
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
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
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 3/4] power_supply: Introduce PSE compliant algorithm
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
Power Supply Subsystem Maintainer
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 4/4] power_supply: bq24261 charger driver
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 1/4] power_supply: Add inlmt,iterm, min/max temp props
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
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
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,
Re: [jenny...@intel.com: [RFC] power_supply: Introduce generic psy charging driver]
> > +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: [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
On Fri, Jan 24, 2014 at 08:25:19AM -0700, Dmitry Eremin-Solenikov wrote: > On 22/01/14 21:19, 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 > > What is the difference from TEMP_ALERT_MIN/TEMP_ALERT_MAX ? > There is a difference in definitions, but what is the logical difference? TEMP_ALERT_MIN/MAX is to ALERT when temperature cross the threshold. TEMP_MIN/MAX is to stop charging/discharging when cross the threshold. > > > 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 > > For both of them: > > 1) Please don't use obscure abbreviations Agreed > 2) Is this generic enough? I.e. besides your charge manager who will > use that? Generic and all charger drivers can use this. > > -- > With best wishes > Dmitry -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
On Tue, Jan 28, 2014 at 07:14:45AM -0700, Pavel Machek wrote: > > +#define BQ24261_ICHRG_MASK (0x1F << 3) > > +#define BQ24261_ICHRG_100ma(0x01 << 3) > > +#define BQ24261_ICHRG_200ma(0x01 << 4) > > +#define BQ24261_ICHRG_400ma(0x01 << 5) > > +#define BQ24261_ICHRG_800ma(0x01 << 6) > > +#define BQ24261_ICHRG_1600ma (0x01 << 7) > > First, its mA, not ma. Camel Case allowed? Ignore Checkpatch.pl warning? > > +u16 bq24261_iterm[][2] = { > > + {0, 0x00} > > + , > > + {50, BQ24261_ITERM_50ma} > > + , > > + {100, BQ24261_ITERM_100ma} > > + , > > + {150, BQ24261_ITERM_100ma | BQ24261_ITERM_50ma} > > ...this is very obscure way to do with table what can be done with > > (x/50) << 3, right ? Few register settings need table mapping, but some can have logic as your comment say. Just wanted to keep same logic for all register settings. Doesn't it make more readable? > > +u16 bq24261_cc[][2] = { > > + > > + {500, 0x00} > > + , > > + {600, BQ24261_ICHRG_100ma} > > + , > > + {700, BQ24261_ICHRG_200ma} > > + , > > + {800, BQ24261_ICHRG_100ma | BQ24261_ICHRG_200ma} > > + , > > + {900, BQ24261_ICHRG_400ma} > > I suspect you can get rid of this, too, if you expand macros. Same as above comment. -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 2/4] power_supply: Introduce Generic Power Supply charging driver
On Sat, Jan 25, 2014 at 10:04:03AM -0700, Pavel Machek wrote: > > + * Write access using set_property > > + * Set Maximum charging current > > + * Action: Configure safety charging registers if any. If not no > > + actions expected for this. > > Having property that does nothing sounds evil to me. No h/w actions expected. But driver action expected. Will fix in next patch set > > +* POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGING > > + * Write access using set_property > > + * Enable/Disable charging. Charger supplies power to platform, > > + but charging is disabled > > This is unclear. Charging is always disabled? Writing 0, disables charger. Writing 1 enables charging. -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 v4 0/4] power_supply: Introduce power supply charging driver
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. 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 | 339 +++ Documentation/power/power_supply_class.txt |6 + drivers/power/Kconfig| 31 + drivers/power/Makefile |3 + drivers/power/bq24261_charger.c | 1364 ++ drivers/power/charging_algo_pse.c| 198 drivers/power/power_supply_charger.c | 1196 ++ 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| 32 + include/linux/power/power_supply_charger.h | 237 + include/linux/power_supply.h | 164 13 files changed, 3795 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
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 | 1364 + include/linux/power/bq24261_charger.h | 32 + 4 files changed, 1407 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..4fe29e7 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 BQ24261_CHARGER + 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..6d184c8 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_BQ24261_CHARGER) += 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..37485b0 --- /dev/null +++ b/drivers/power/bq24261_charger.c @@ -0,0 +1,1364 @@ +/* + * 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 DEV_MANUFACTURER "TI" +#define MODEL_NAME_SIZE 8 +#define DEV_MANUFACTURER_NAME_SIZE 4 + +#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_
[PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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 | 198 include/linux/power/power_supply_charger.h | 48 +++ 4 files changed, 260 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..0a0130a --- /dev/null +++ b/drivers/power/charging_algo_pse.c @@ -0,0 +1,198 @@ +/* + * 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_mod_bprof, unsigned long cv) +{ + + int i; +
[PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
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/
power_supply mailing list
Hi, Do we have any mailing list for power_supply subsystem? If not what about having one - linux-power-sup...@vger.kernel.org? 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: [PATCH 4/4] power_supply: bq24261 charger driver
On Thu, Jan 30, 2014 at 06:01:54PM +0100, Pavel Machek wrote: > Hi! > > > diff --git a/drivers/power/Makefile b/drivers/power/Makefile > > index 77535fd..6d184c8 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_BQ24261_CHARGER) += bq24261_charger.o > > obj-$(CONFIG_POWER_RESET) += reset/ > > I believe I commented on this one before. Spot two inconsistencies. Sorry, couldn't find two inconsistencies. One is use of _. And the other? -- 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 16/18] charger: max14577: Add support for MAX77836 charger
On Tue, Jan 28, 2014 at 01:18:40PM +0100, Krzysztof Kozlowski wrote: > - /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */ > + /* Battery-Charger Constant Voltage (CV) Mode, set to: 4.35V */ Does this charger chip support only 4.35V batteries? If the CV is hard coded to 4.35V, it's not safe for 4.2V batteries. > + /* End-of-Charge Current, set to 50mA (max14577) / 7.5mA (max77836) */ The End of charge current basically depend on battery and not on charger chip. > - /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */ > + /* Overvoltage-Protection Threshold, set to 6.5V */ 6.5V as over voltage for battery? A 4.35V battery would have exploded by that time! -- 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 v5 0/4] power_supply: Introduce power supply charging driver
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 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 | 339 +++ Documentation/power/power_supply_class.txt |6 + drivers/power/Kconfig| 31 + drivers/power/Makefile |3 + drivers/power/bq24261-charger.c | 1364 ++ drivers/power/charging_algo_pse.c| 198 drivers/power/power_supply_charger.c | 1196 ++ 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 | 237 + include/linux/power_supply.h | 164 13 files changed, 3788 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
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 4/4] power_supply: bq24261 charger driver
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 | 1358 + include/linux/power/bq24261-charger.h | 25 + 4 files changed, 1394 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..a87d1cc --- /dev/null +++ b/drivers/power/bq24261-charger.c @@ -0,0 +1,1358 @@ +/* + * 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 DEV_MANUFACTURER "TI" +#define MODEL_NAME_SIZE 8 +#define DEV_MANUFACTURER_NAME_SIZE 4 + +#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_
[PATCH 3/4] power_supply: Introduce PSE compliant algorithm
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 | 198 include/linux/power/power_supply_charger.h | 48 +++ 4 files changed, 260 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..0a0130a --- /dev/null +++ b/drivers/power/charging_algo_pse.c @@ -0,0 +1,198 @@ +/* + * 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_mod_bprof, unsigned long cv) +{ + + int i; +
Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver
On Tue, Feb 04, 2014 at 12:36:30PM +0100, Pavel Machek wrote: > > +struct psy_charger_context { > > + bool is_usb_cable_evt_reg; > > + int psyc_cnt; > > + int batt_status; > > + /*cache battery and charger properties */ > > Comment coding style. Please run you patches through checkpatch. checkpatch doesn't throw any error/warning. /* ... */ not allowed for single line comments? (will fix missing space after /*) -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/
[PATCHv12 0/3] power_supply: Introduce power supply charging driver
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
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
[PATCH 3/3] power_supply: bq24261 charger driver
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
[PATCH 2/3] power_supply: Introduce PSE compliant algorithm
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 -
[RFC 0/4] Enable power supply charging control
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 2/4] power: core: Add generic interface to get battery specification.
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(&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 , " "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_
[RFC 1/4] power_supply: Introduce charging object table
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 3/4] power_supply: Introduce charger control interface
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/