power_supply: Introduce power supply charging driver
Subsystems (2)
v5 cover 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
Signature · 1 line
1.7.9.5
PATCH v5 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
--- 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(+)
Documentation/power/power_supply_class.txt +6 -0
@@ -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)
drivers/power/power_supply_sysfs.c +4 -0
@@ -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),
include/linux/power_supply.h +4 -0
@@ -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,
Signature · 1 line
1.7.9.5
PATCH v5 2/4 power_supply: Introduce generic psy charging driver
In reply to Jenny TCThe 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.
--- Documentation/power/power_supply_charger.txt | 339 ++++++++ drivers/power/Kconfig | 8 + drivers/power/Makefile | 1 + drivers/power/power_supply_charger.c | 1196 ++++++++++++++++++++++++++ drivers/power/power_supply_charger.h | 218 +++++ drivers/power/power_supply_core.c | 3 + include/linux/power/power_supply_charger.h | 189 ++++ include/linux/power_supply.h | 160 ++++ 8 files changed, 2114 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
Documentation/power/power_supply_charger.txt new file +339 -0
@@ -0,0 +1,339 @@ +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 (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 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 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 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. + +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_prop_changed(). The driver also exposes API +psy_get_battery_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() + +3. Use Charging Driver to setup charging +=========================================== + +* Register the driver with the power_supply class +* Register the driver with the power supply charging driver +* Expose set_property and get_property functions so that charging + framework can control the charging + +3.1 Registering charger chip driver with power supply charging driver +================================================================ + +struct power_supply_class psy_usb; +struct power_supply_charger psyc_usb; + +/* register with power supply subsystem */ +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; + +/* register with power_supply subsystem */ +power_supply_register(device, &psy_usb); + +/* Register with power supply charging driver */ + +/* Assign psy pointer to power supply charger */ +psyc_usb.psy = &chip->psy_usb; + +/* define supported cable types for this driver */ +psyc_usb.supported_cables = POWER_SUPPLY_CHARGER_TYPE_USB; + +/* pointer to power supply charger get property function */ +psyc_usb.get_property = bq24261_usb_psyc_get_property; + +/* pointer to power supply charger set property function */ +psyc_usb.set_property = bq24261_usb_psyc_set_property; + +/* pointer to throttle states */ +psyc_usb.throttle_states = chip->pdata->throttle_states; + +/* Number of throttle states */ +psyc_usb.num_throttle_states = chip->pdata->num_throttle_states; + +/*register with power supply charging */ +power_supply_register_charger(&chip->psyc_usb); + +3.2 Properties exposed to power supply class driver +================================================== +* POWER_SUPPLY_PROP_ONLINE + * Read access using get_property_function + * Returns the online property set using the set_property + function + * Write access using set_property function + * Expose the value through get_property_function. +* POWER_SUPPLY_PROP_PRESENT + * Read access using get_property_function + * Returns the present property set using the set_property + function + * Write access using set_property function + * Expose the value through get_property_function. +* POWER_SUPPLY_PROP_HEALTH + * Read access using get_property_function + * Returns charger health +* POWER_SUPPLY_PROP_TYPE + * Read access using power_supply structure + * Returns charger type +* POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT + * Read access using get property + * Returns the present charge control limit + * Write access using set property + * Set charge control limit. + * Action: Driver is not expected to take any actions on this. + Instead need to expose this on the read interface. + Charging framework process this and notifies the + charging parameters accordingly. +* POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX + * Read access using get property + * Returns the maximum charge control limit +* POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT + * Read access using get property + * Returns the input current limit passed by set_property + function + * Default value : 0 + * Write access using set property + * Set input current limit + * Action : Write h/w register to set the input current limit + based on the value +* POWER_SUPPLY_PROP_CHARGE_CURRENT + * Read access using get property + * Returns charge current passed by set_property function + * Default value : 0 + * Write access using set property + * Set charge current + * Action : Write h/w register to set the charge current based + on the value +* POWER_SUPPLY_PROP_CHARGE_VOLTAGE + * Read access using get property + * Returns charge voltage passed by set_property function + * Default value: 0 + * Write access using set property + * Set charge voltage + * Action : Write h/w register to set the charge voltage based + on the value +* POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT + * Read access using get property + * Returns charge termination current passed by set_property + function + * Default value : 0 + * Write access using set property + * Set charge termination current + * Action : Write h/w register to set the charge termination + current + based on the value +* POWER_SUPPLY_PROP_TEMP_MIN + * Read access using get property + * Returns minimum charging temperature passed by set_property + * Default value : Platform dependant + * Write access using set_property + * Set Minimum charging temperature + * Action : Write h/w register to set the minimum charging + temperature based on the value +* POWER_SUPPLY_PROP_TEMP_MAX + * Write access using set_property + * Set Maximum charging temperature + * Action : Write h/w register to set the maximum charging + temperature based on the value + * Read access using get property + * Returns maximum charging temperature passed by set_property + * Default value : Platform dependent +* POWER_SUPPLY_PROP_MAX_CHARGE_CURRENT + * Read access using get property + * Returns maximum charging current passed by set_property + * Default value : Platform dependent + * Write access using set_property + * Set Maximum charging current + * Action: Configure safety charging registers if any. If no h/w + actions expected, report the value on the + get_property interface. +* POWER_SUPPLY_PROP_MAX_CHARGE_VOLTAGE + * Read access using get property + * Returns maximum charging current passed by set_property + * Default value : Platform dependent + * Write access using set_property + * Set Maximum charging voltage + * Action: Configure safety charging registers if any. If not, + no actions expected for this. + +3.3 Properties exposed to power supply charging driver +===================================================== + +* POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGING + * Write access using set_property + * Enable/Disable charging. Charger supplies power to platform, + but charging is disabled + * Action: Configure charger chip registers to enable/disable + charging. Writing 0, disables charging, writing 1 enables + charging +* POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGER + * Write access using set_property + * Enable/Disable charger. Charger doesn't supply power to + platform or battery and battery start to discharge. + * Action: Configure charger chip registers to enable/disable + charger. Writing 0 disables charger, writing 1 enables + charger +* POWER_SUPPLY_CHARGER_PROP_CABLE_TYPE + * Write access using set_property + * Set charger cable type. + * Action: Report power supply type based on cable type +* POWER_SUPPLY_CHARGER_PROP_RESET_WDT + * Write access using set_property + * Reset charger Watch Dog Timer + * Action: Reset charger Watch Dog Timer. +* POWER_SUPPLY_CHARGER_PROP_PRIORITY + * Read access using get property + * Expose charger driver/chips priority if platform has multiple + charger chip/drivers. + +3.4 Throttling data configuration +============================= +Power supply charging driver can take actions for Thermal throttling requests. +Power supply core sends event PSY_EVENT_THROTTLE on power_supply_notifier +chain. Power supply charging driver handle this event and takes throttling +actions as in the throttling configuration structure. The throttling +configuration structure has the following format: + +struct psy_throttle_state { + enum psy_throttle_action throttle_action; + unsigned throttle_val; +}; + +Throttling configuration example: + +struct psy_throttle_state my_throttle_states[] = { + + /* Level 0: Limit charge current to 1500mA. Normal Level */ + { + .throttle_action = PSY_THROTTLE_CC_LIMIT, + .throttle_val = 1500, + }, + + /* Level 1: Limit charge current to 500mA */ + { + .throttle_action = PSY_THROTTLE_CC_LIMIT, + .throttle_val = 500, + }, + + /* + * Level 2: Disable charging: Stop charging, charger supply power to + * platform. + */ + { + .throttle_action = PSY_THROTTLE_DISABLE_CHARGING, + }, + + /* Level 3: Disable charger: Battery start discharging */ + { + .throttle_action = PSY_THROTTLE_DISABLE_CHARGER, + }, + +}; + +4. Charger Cable notifications +============================== + +Charger cables can have different charging capabilities (current) depending on +platform and cable type. The cable provider drivers detect and identify the +cable types and notifies the power supply subsystem by posting an event +PSY_EVENT_CABLE on the power_supply_notifier chain. The event notification +should have a property structure pointer which indicates the cable type, event +and capability. + +struct psy_cable_props cable; +cable.chrg_evt = PSY_CHARGER_CABLE_EVENT_CONNECT; +cable.chrg_type = PSY_CHARGER_CABLE_TYPE_USB_DCP; +cable.ma = 1500; + +atomic_notifier_call_chain(&power_supply_notifier, + PSY_EVENT_CABLE, &cable); + +Power supply charging driver process this event and takes actions to setup +charging. + +5. Registering new charging algorithm +=================================== +Power supply charging driver supports pluggable charging algorithms. Charging +algorithms processes charging profile and/or applies different logic (pulse +charging/fast charging/relaxed charging) to decide the charging parameters (CC +and CV). + +* Populate algorithm structure + struct psy_charging_algo new_algo; + /* populate the type charging profile the algorithm handles */ + pse_algo.chrg_prof_type = PSY_CHRG_PROF_PSE; + pse_algo.name = "my_algo"; + /* callback function to retrieve CC and CV */ + pse_algo.get_next_cc_cv = my_algo_get_next_cc_cv; + /* callback function to retreive battery thresholds */ + pse_algo.get_batt_thresholds = my_algo_get_bat_thresholds; + /* register charging algorithm */ + power_supply_register_charging_algo(&pse_algo); + +When the type of charging profile reported by battery and algorithm matches, +the algorithm will be invoked to get the charging parameters. + +6. TODO +======= +* Replace static cable array with dynamic list +* Implement safety timer and watch dog timer features with more monitoring +* Move charge full detection logic to psy charging driver from algorithm driver
drivers/power/Kconfig +8 -0
@@ -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. + config PDA_POWER tristate "Generic PDA/phone power driver" depends on !S390
drivers/power/Makefile +1 -0
@@ -7,6 +7,7 @@ power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o 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_PDA_POWER) += pda_power.o obj-$(CONFIG_APM_POWER) += apm_power.o obj-$(CONFIG_MAX8925_POWER) += max8925_power.o
drivers/power/power_supply_charger.c new file +1196 -0
1,196 lines not on this page · raw message
drivers/power/power_supply_charger.h new file +218 -0
218 lines not on this page · raw message
drivers/power/power_supply_core.c +3 -0
@@ -483,6 +483,9 @@ 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); +atomic_notifier_call_chain (&power_supply_notifier, +PSY_EVENT_THROTTLE , psy); +return ret; }
include/linux/power/power_supply_charger.h new file +189 -0
189 lines not on this page · raw message
include/linux/power_supply.h +160 -0
170 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver
Hi!
Quoted 20 lines
Documentation/power/power_supply_charger.txt new file +20
-0+Throttling configuration example: + +struct psy_throttle_state my_throttle_states[] = { + + /* Level 0: Limit charge current to 1500mA. Normal Level */ + { + .throttle_action = PSY_THROTTLE_CC_LIMIT, + .throttle_val = 1500, + }, + + /* Level 1: Limit charge current to 500mA */ + { + .throttle_action = PSY_THROTTLE_CC_LIMIT, + .throttle_val = 500, + }, + + /* + * Level 2: Disable charging: Stop charging, charger supply power to + * platform. + */
Documentation/power/power_supply_charger.txt line 290
Quoted 10 lines
Documentation/power/power_supply_charger.txt new file +10
-0+ { + .throttle_action = PSY_THROTTLE_DISABLE_CHARGING, + }, + + /* Level 3: Disable charger: Battery start discharging */ + { + .throttle_action = PSY_THROTTLE_DISABLE_CHARGER, + }, + +};
Does it make sense to have throttling description as a data, as opposed to normal C code?
drivers/power/power_supply_charger.c line 49
Quoted 5 lines
drivers/power/power_supply_charger.c new file +5
-0+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.
drivers/power/power_supply_charger.c line 55
Quoted 4 lines
drivers/power/power_supply_charger.c new file +4
-0+struct list_head evt_queue; +struct mutex evt_lock; +struct list_head event_queue; +struct psy_batt_chrg_prof batt_property;
Again, please use full words in variable names. How am I supposed to know what evt_queue is? Especially when you have event_queue, also?!
And please do it globally.
Quoted 26 lines
drivers/power/power_supply_charger.c new file +26
-0+static void __power_supply_trigger_charging_handler (struct power_supply *psy) +{ +int i; +struct power_supply *psb =NULL ; + + +if (is_trigger_charging_algo (psy)) { +if (psy_is_battery (psy)) { +if (trigger_algo (psy)) +enable_supplied_by_charging (psy, false); +else +enable_supplied_by_charging (psy, true); + }else if (psy_is_charger (psy)) { +for (i =0 ; i < psy->num_supplicants; i++) { + psb = +power_supply_get_by_name (psy-> + supplied_to[i]); + +if (psb &&psy_is_battery (psb) && +psy_is_present (psb)) { +if (trigger_algo (psb)) { +psy_disable_charging (psy); +break ; + }else if + (psy_is_charging_can_be_enabled + (psy)) {
drivers/power/power_supply_charger.c line 833
Quoted 10 lines
drivers/power/power_supply_charger.c new file +10
-0+psy_enable_charging (psy); +wait_for_charging_enabled (psy); + } + } + } + } +update_sysfs (psy); +power_supply_changed (psy); + } +}
See coding style about excessive nesting. Please fix it globally.
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver
Quoted 7 lines · Pavel Machek
drivers/power/power_supply_charger.c line 49
Quoted 5 lines
drivers/power/power_supply_charger.c new file +5
-0+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
Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver
Quoted 11 lines · Jenny Tc
Quoted 7 lines · Pavel Machek
drivers/power/power_supply_charger.c line 49
Quoted 5 lines
drivers/power/power_supply_charger.c new file +5
-0+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 /*)
I meant the space after /*. Maybe checkpatch does not report anything here, but I guess there are other places where it will comment :-).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 2/4] power_supply: Introduce generic psy charging driver
Quoted 10 lines · Pavel Machek
Quoted 9 lines · Jenny Tc
Quoted 7 lines · Pavel Machek
drivers/power/power_supply_charger.c line 49
Quoted 5 lines
drivers/power/power_supply_charger.c new file +5
-0+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.
Quoted 5 lines
Quoted 2 lines
checkpatch doesn't throw any error/warning. /* ... */ not allowed for single line comments? (will fix missing space after /*)
I meant the space after /*. Maybe checkpatch does not report anything here, but I guess there are other places where it will comment :-).
Yes, right.
+ /*cache battery and charger properties */
^
'one space' is necessary between '/*' and 'cache'. This can be fixed as below.
+ /* cache battery and charger properties */
Best regards,
Jingoo Han
PATCH v5 3/4 power_supply: Introduce PSE compliant algorithm
In reply to Jenny TCAs 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.
--- 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
drivers/power/Kconfig +13 -0
@@ -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
drivers/power/Makefile +1 -0
@@ -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
drivers/power/charging_algo_pse.c new file +198 -0
198 lines not on this page · raw message
include/linux/power/power_supply_charger.h +48 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Hi!
Quoted 6 lines
drivers/power/Kconfig +0
-0@@ -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.
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 34
Quoted 10 lines
drivers/power/Kconfig +10
-0+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.
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 37
Quoted 3 lines
drivers/power/Kconfig +3
-0+static inline bool __is_battery_full + (long volt, long cur, long iterm, unsigned long cv) +{
codingstyle.
drivers/power/Kconfig config POWER_SUPPLY_CHARGER
Quoted 5 lines
drivers/power/Kconfig +5
-0+ 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));
Codingstyle. Just run checkpatch.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 6 lines · Pavel Machek
Quoted 6 lines
drivers/power/Kconfig +0
-0@@ -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.
Quoted 12 lines
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 34
Quoted 10 lines
drivers/power/Kconfig +10
-0+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
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 20 lines · Jenny Tc
Quoted 6 lines · Pavel Machek
Quoted 6 lines
drivers/power/Kconfig +0
-0@@ -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.Quoted 12 lines
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 34
Quoted 10 lines
drivers/power/Kconfig +10
-0+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.
Quoted 2 lines
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?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 21 lines · Pavel Machek
Quoted 20 lines · Jenny Tc
Quoted 18 lines · Pavel Machek
Quoted 6 lines
drivers/power/Kconfig +0
-0@@ -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.drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 34
Quoted 10 lines
drivers/power/Kconfig +10
-0+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.
Quoted 8 lines
Quoted 2 lines
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.
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 5 lines · Jenny Tc
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.
Yours,
Linus Walleij
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 15 lines · Linus Walleij
Quoted 5 lines · Jenny Tc
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.cdrivers/power/ab8500_charger.cetc, or do you envision a set of pluggable algorithms for this one hardware?
Quoted 3 lines
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
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
In reply to Jenny TcQuoted 28 lines · Jenny Tc
Quoted 27 lines · Pavel Machek
Quoted 20 lines · Jenny Tc
Quoted 6 lines · Pavel Machek
Quoted 6 lines
drivers/power/Kconfig +0
-0@@ -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.Quoted 12 lines
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 34
Quoted 10 lines
drivers/power/Kconfig +10
-0+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.
Quoted 2 lines
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...
Quoted 8 lines
Quoted 2 lines
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.
Yes please. Because with current description, user has no chance.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
In reply to Jenny TCdrivers/power/charging_algo_pse.c line 58
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+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?
(...)
Quoted 10 lines
include/linux/power/power_supply_charger.h +10
-0+/* 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 */ + +/*
include/linux/power/power_supply_charger.h enum { · line 106
Quoted 10 lines
include/linux/power/power_supply_charger.h +10
-0+* 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.
Convert all comments to kerneldoc.
include/linux/power/power_supply_charger.h enum { · line 115
Quoted 7 lines
include/linux/power/power_supply_charger.h +7
-0+#define BATTID_STR_LEN 8 +#define BATT_TEMP_NR_RNG 6 + +struct psy_pse_chrg_prof { +/* battery id */ +char batt_id[BATTID_STR_LEN ]; +u16 battery_type;/* Defined as POWER_SUPPLY_TECHNOLOGY_* */
Use a named enum by patching that in <linux/power_supply.h>?
Quoted 5 lines
include/linux/power/power_supply_charger.h +5
-0+u16 capacity;/* mAh */ +u16 voltage_max;/* mV */ +/* charge termination current */ +u16 chrg_term_mA; +/* Low battery level voltage */
include/linux/power/power_supply_charger.h enum { · line 130
Quoted 10 lines
include/linux/power/power_supply_charger.h +10
-0+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.
Yours,
Linus Walleij
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 8 lines · Linus Walleij
drivers/power/charging_algo_pse.c line 58
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+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? Justis_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?
Quoted 16 lines
(...)
Quoted 15 lines
include/linux/power/power_supply_charger.h +15
-0+/* 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 */
Quoted 8 lines
include/linux/power/power_supply_charger.h enum { · line 106
Quoted 5 lines
include/linux/power/power_supply_charger.h +5
-0+ +/* 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.
Quoted 9 lines
include/linux/power/power_supply_charger.h enum { · line 115
Quoted 7 lines
include/linux/power/power_supply_charger.h +7
-0+#define BATTID_STR_LEN 8 +#define BATT_TEMP_NR_RNG 6 + +struct psy_pse_chrg_prof { +/* battery id */ +char batt_id[BATTID_STR_LEN ]; +u16 battery_type;/* Defined as POWER_SUPPLY_TECHNOLOGY_* */ Use a named enum by patching that in <
linux/power_supply.h>?
This is to convey that battery_type takes value as defined by POWER_SUPPLY_TECHNOLOGY_*
Quoted 17 lines
Quoted 6 lines
include/linux/power/power_supply_charger.h +5
-0+u16 capacity;/* mAh */ +u16 voltage_max;/* mV */ +/* charge termination current */ +u16 chrg_term_mA; +/* Low battery level voltage */ include/linux/power/power_supply_charger.h enum { · line 130
Quoted 10 lines
include/linux/power/power_supply_charger.h +10
-0+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;
Quoted 1 line
Why packed, and convert to kerneldoc for this struct.
Battery charging profile, may come from EEPROM/emmc which would be packed.
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 6 lines · Jenny Tc
Quoted 5 lines · Linus Walleij
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+static inline bool __is_battery_full + (long volt,long cur,long iterm,unsigned long cv)
Quoted 7 lines
Quoted 3 lines
Overall I wonder if you've run checkpatch on these patches, but why are you naming this one function with a double
__underscore? Justis_battery_full_check()or something would work fine I guess?Just to convey that
is_battery_fullis a local function and not generic. You can find similar usage inpower_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.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
include/linux/power/power_supply_charger.h +15
-0+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;
Quoted 3 lines
Quoted 1 line
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?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Jenny Tc
Quoted 8 lines · Linus Walleij
drivers/power/charging_algo_pse.c line 58
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+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? Justis_battery_full_check()or something would work fine I guess?
Quoted 6 lines
Quoted 3 lines
Just to convey that
is_battery_fullis a local function and not generic. You can find similar usage inpower_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.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
include/linux/power/power_supply_charger.h +15
-0+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;
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
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.
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Hi!
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Just to convey that
is_battery_fullis a local function and not generic. You can find similar usage inpower_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.
If you have __foo() and foo(), the __foo() is typically worker function, where foo() provides locking around it etc.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
In reply to Jenny TcQuoted 6 lines · Jenny Tc
Quoted 5 lines · Linus Walleij
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+static inline bool __is_battery_full + (long volt,long cur,long iterm,unsigned long cv)
Quoted 7 lines
Quoted 3 lines
Overall I wonder if you've run checkpatch on these patches, but why are you naming this one function with a double
__underscore? Justis_battery_full_check()or something would work fine I guess?Just to convey that
is_battery_fullis a local function and not generic. You can find similar usage inpower_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.
Quoted 6 lines
Quoted 2 lines
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.
OK I buy that. Make sure this is noted somewhere (or maybe I missed it).
Yours,
Linus Walleij
Re: [PATCH 3/4] power_supply: Introduce PSE compliant algorithm
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Jenny Tc
Quoted 8 lines · Linus Walleij
drivers/power/charging_algo_pse.c line 58
Quoted 2 lines · Jenny TC
drivers/power/charging_algo_pse.c new file +2
-0+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? Justis_battery_full_check()or something would work fine I guess?
Quoted 6 lines
Quoted 3 lines
Just to convey that
is_battery_fullis a local function and not generic. You can find similar usage inpower_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
PATCH v5 4/4 power_supply: bq24261 charger driver
In reply to Jenny TCThis 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
--- 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
drivers/power/Kconfig +10 -0
@@ -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
drivers/power/Makefile +1 -0
@@ -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/
drivers/power/bq24261-charger.c new file +1358 -0
1,358 lines not on this page · raw message
include/linux/power/bq24261-charger.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* bq24261_charger.h: platform data structure for bq24261 driver +* +* (C) Copyright 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. +*/ + +#ifndef __BQ24261_CHARGER_H__ +#define __BQ24261_CHARGER_H__ + +struct bq24261_plat_data { +char **supplied_to; +size_t num_supplicants; +struct psy_throttle_state *throttle_states; +size_t num_throttle_states; +int safety_timer; +bool is_ts_enabled; + +}; + +#endif
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Hi!
drivers/power/bq24261-charger.c line 44
Quoted 2 lines
drivers/power/bq24261-charger.c new file +2
-0+#define DEV_MANUFACTURER "TI" +#define DEV_MANUFACTURER_NAME_SIZE 4
This is unneccessarily complicated for no reason. You copy "TI" to struct, just so that ou can return pointer to the field on get_property.
What about simply returning "TI" from get_property, without defines and copying?
drivers/power/bq24261-charger.c line 180
Quoted 2 lines
drivers/power/bq24261-charger.c new file +2
-0+#define BQ24261_MIN_CV 3500 +#define BQ24261_MAX_CV 4440
Other defines use uV as an unit :-(.
drivers/power/bq24261-charger.c line 303
Quoted 10 lines
drivers/power/bq24261-charger.c new file +10
-0+static void lookup_regval (u16 tbl[][2 ],size_t size,u16 in_val,u8 *out_val) +{ +int i; + +for (i =1 ; i < size; ++i) +if (in_val < tbl[i][0 ]) +break ; + + *out_val = (u8 ) tbl[i -1 ][1 ]; +}
Umm. Could we simply return the value?
drivers/power/bq24261-charger.c line 309
Quoted 5 lines
drivers/power/bq24261-charger.c new file +5
-0+static void bq24261_cc_to_reg (int cc,u8 *reg_val) +{ + + cc = cc <BQ24261_MAX_CC ? cc :BQ24261_MAX_CC ; + cc = cc -BQ24261_MIN_CC ;
clamp_t?
Review
Quoted 2 lines
(quoted diff) +2
-0+ *reg_val = cc > 0 ? ((cc/100) << 3) & 0xFF : 0; +}
Just return the value?
drivers/power/bq24261-charger.c line 321
Quoted 9 lines
drivers/power/bq24261-charger.c new file +9
-0+static void bq24261_cv_to_reg (int cv,u8 *reg_val) +{ +int val; + + val =clamp_t (int, cv,BQ24261_MIN_CV ,BQ24261_MAX_CV ); + *reg_val = + (((val -BQ24261_MIN_CV ) /BQ24261_CV_DIV ) + <<BQ24261_CV_BIT_POS ); +}
Not sure if the defines really make it more readable. It should be consistent with the above/below functions...
drivers/power/bq24261-charger.c line 332
Quoted 4 lines
drivers/power/bq24261-charger.c new file +4
-0+static inline void bq24261_iterm_to_reg (int iterm,u8 *regval) +{ + iterm = iterm <BQ24261_MAX_ITERM ? iterm :BQ24261_MAX_ITERM ; + iterm = iterm -BQ24261_MIN_ITERM ;
clamp_t?
Review
Quoted 2 lines
(quoted diff) +2
-0+ *regval = iterm > 0 ? (iterm/50) & 0xFF : 0; +}
Just return the value.
drivers/power/bq24261-charger.c line 341
Quoted 5 lines
drivers/power/bq24261-charger.c new file +5
-0+static inline void bq24261_sfty_tmr_to_reg (int tmr,u8 *regval) +{ +return lookup_regval (bq24261_sfty_tmr,ARRAY_SIZE (bq24261_sfty_tmr), + tmr, regval); +}
Just return the value... returning void values with explicit return is "interesting".
drivers/power/bq24261-charger.c line 424
Quoted 13 lines
drivers/power/bq24261-charger.c new file +13
-0+/* 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 ".".
Quoted 9 lines
drivers/power/bq24261-charger.c new file +9
-0+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
drivers/power/bq24261-charger.c line 520
Quoted 10 lines
drivers/power/bq24261-charger.c new file +10
-0+* VBatt Vindpm Register Setting +* < 3.7v 4.2v 0x0 (default) +* 3.71v - 3.96v 4.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.
drivers/power/bq24261-charger.c line 568
Quoted 13 lines
drivers/power/bq24261-charger.c new file +13
-0+static inline void resume_charging (struct bq24261_charger *chip) +{ + +if (chip->is_charger_enabled) +bq24261_enable_charger (chip, true); +if (chip->inlmt) +bq24261_set_inlmt (chip, chip->inlmt); +if (chip->cc) +bq24261_set_cc (chip, chip->cc); +if (chip->cv) +bq24261_set_cv (chip, chip->cv); +if (chip->is_charging_enabled) +bq24261_enable_charging (chip, true);
What about some error checking?
Is it wise to enable charging when setting voltage failed?
drivers/power/bq24261-charger.c line 639
Quoted 6 lines
drivers/power/bq24261-charger.c new file +6
-0+static inline bool is_bq24261_enabled (struct bq24261_charger *chip) +{ +if (chip->cable_type ==PSY_CHARGER_CABLE_TYPE_NONE ) +return false; +else if (!chip->is_charger_enabled) +return false;
Kill the else.
drivers/power/bq24261-charger.c line 915
Quoted 9 lines
drivers/power/bq24261-charger.c new file +9
-0+static inline int get_battery_voltage (int *volt) +{ +struct power_supply *psy; +union power_supply_propval val; +int ret; + + psy =get_psy_battery (); +if (!psy) +return -EINVAL ;
Hmm. Does this assume just one battery in the system?
Is it good idea? Older machines contain main and memory backup batteries. Newer machines contain keyboard and display battery....
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Quoted 4 lines · Pavel Machek
drivers/power/bq24261-charger.c line 180
Quoted 2 lines
drivers/power/bq24261-charger.c new file +2
-0+#define BQ24261_MIN_CV 3500 +#define BQ24261_MAX_CV 4440Other 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
Quoted 8 lines
Quoted 8 lines
drivers/power/bq24261-charger.c new file +8
-0+/* 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);
Quoted 8 lines
drivers/power/bq24261-charger.c line 424
Quoted 5 lines
drivers/power/bq24261-charger.c new file +5
-0+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.
Quoted 14 lines
Quoted 14 lines
drivers/power/bq24261-charger.c new file +13
-0+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.96v 4.36v 0x2 +* > 3.96v 4.6v 0x5
Quoted 8 lines
drivers/power/bq24261-charger.c line 520
Quoted 6 lines
drivers/power/bq24261-charger.c new file +6
-0+*/ + 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
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Hi!
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/power/bq24261-charger.c new file +13
-0+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.96v 4.36v 0x2 +* > 3.96v 4.6v 0x5 Quoted 8 lines
drivers/power/bq24261-charger.c line 520
Quoted 6 lines
drivers/power/bq24261-charger.c new file +6
-0+*/ + 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.
Quoted 1 line
On error, throw the error and program default VINDPM value.
Is it good idea to attempt charging when we can't read battery voltage?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Quoted 24 lines · Pavel Machek
Hi!
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
drivers/power/bq24261-charger.c new file +9
-0+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 drivers/power/bq24261-charger.c line 520
Quoted 10 lines
drivers/power/bq24261-charger.c new file +10
-0+* VBatt Vindpm Register Setting +* < 3.7v 4.2v 0x0 (default) +* 3.71v - 3.96v 4.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.
Quoted 4 lines
Quoted 1 line
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