power_supply: Introduce power supply charging driver
Subsystems (2)
v3 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
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
Signature · 1 line
1.7.9.5
PATCH v3 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_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)
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_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),
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_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,
Signature · 1 line
1.7.9.5
RE: [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
Quoted 7 lines · Jenny TC
Add new power supply properties for input current, charge termination current, min and max temperature
POWER_SUPPLY_PROP_TEMP_MIN- minimum operatable temperaturePOWER_SUPPLY_PROP_TEMP_MAX- maximum operatable temperature
Quoted 7 lines
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 conditionChange-Id: Ifb40662bbfa24387ac7493ffa7ce01c6fae7e800
Please remove this 'Change-Id' from the commit message.
Best regards,
Jingoo Han
Quoted 6 lines
Signed-off-by Jenny TC <[email protected]>--- 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(+)
Re: [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
In reply to Jenny TCHi!
Quoted 8 lines
Add new power supply properties for input current, charge termination current, min and max temperature
POWER_SUPPLY_PROP_TEMP_MIN- minimum operatable temperaturePOWER_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.
This is pretty cryptic. Maybe the prefix should be shortened so that we get enough space for INPUT_LIMIT?
Re: [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
In reply to Jenny TCQuoted 5 lines · Jenny TC
Add new power supply properties for input current, charge termination current, min and max temperature
POWER_SUPPLY_PROP_TEMP_MIN- minimum operatable temperaturePOWER_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?
Quoted 4 lines
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
2) Is this generic enough? I.e. besides your charge manager who will use that?
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props
Quoted 9 lines · Dmitry Eremin-Solenikov
Quoted 5 lines · Jenny TC
Add new power supply properties for input current, charge termination current, min and max temperature
POWER_SUPPLY_PROP_TEMP_MIN- minimum operatable temperaturePOWER_SUPPLY_PROP_TEMP_MAX- maximum operatable temperatureWhat 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.
Quoted 9 lines
Quoted 5 lines
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 conditionFor both of them:
1) Please don't use obscure abbreviations
Agreed
Quoted 2 lines
2) Is this generic enough? I.e. besides your charge manager who will use that?
Generic and all charger drivers can use this.
Quoted 3 lines
Quoted 1 line
With best wishes
Dmitry
-Jenny
PATCH v3 2/4 power_supply: Introduce Generic Power Supply 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.
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.
--- Documentation/power/power_supply_charger.txt | 332 +++++++ drivers/power/Kconfig | 8 + drivers/power/Makefile | 1 + drivers/power/power_supply_charger.c | 1191 ++++++++++++++++++++++++++ drivers/power/power_supply_charger.h | 218 +++++ drivers/power/power_supply_core.c | 3 + include/linux/power/power_supply_charger.h | 190 ++++ include/linux/power_supply.h | 158 ++++ 8 files changed, 2101 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 +332 -0
@@ -0,0 +1,332 @@ +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 sAPIs 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_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() + +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_registe(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_fucntion. +* 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_fucntion. +* 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_INLMT + * 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_CUR + * 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 not no + actions expected for this. +* 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 +* 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 +* 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 process 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 +1191 -0
1,191 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 +190 -0
190 lines not on this page · raw message
include/linux/power_supply.h +158 -0
168 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 2/4] power_supply: Introduce Generic Power Supply charging driver
Hi!
Quoted 4 lines
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.
...do we really need copy of documentation file in changelog?
Review
Quoted 4 lines
+2. Reading Battery charging profile
+===================================(quoted diff) +2
-0+ +Power Supply charging driver expose sAPIs to retrieve battery profile of a
typo sAPI.
Documentation/power/power_supply_charger.txt line 52
Quoted 5 lines
Documentation/power/power_supply_charger.txt new file +5
-0+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_batt_prop() to retrieve the battery profile which can be
Please be consistent. _get_battery_pro_ ?
Documentation/power/power_supply_charger.txt line 91
Quoted 6 lines
Documentation/power/power_supply_charger.txt new file +5
-0+used by power supply drivers to setup the charging. Also drivers +can register for battery removal/insertion notifications using +power_supply_reg_notifier() +/* register with power_supply subsystem */ +power_supply_registe(device, &psy_usb);
"r("
Documentation/power/power_supply_charger.txt line 123
Quoted 5 lines
Documentation/power/power_supply_charger.txt new file +5
-0+ * 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_fucntion.
typo "function"
Documentation/power/power_supply_charger.txt line 129
Quoted 6 lines
Documentation/power/power_supply_charger.txt new file +6
-0+* 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_fucntion.
here too.
Documentation/power/power_supply_charger.txt line 206
Quoted 4 lines
Documentation/power/power_supply_charger.txt new file +4
-0+ * 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.
Documentation/power/power_supply_charger.txt line 222
Quoted 4 lines
Documentation/power/power_supply_charger.txt new file +4
-0+* 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?
Documentation/power/power_supply_charger.txt line 238
Quoted 3 lines
Documentation/power/power_supply_charger.txt new file +3
-0+ * Write access using set_property + * Reset charger Watch Dog Timer + * Action: Reset charger Watch dog timer.
IntereSting caPitalization.
Also how do higher levels know how often to reset wdt?
Documentation/power/power_supply_charger.txt line 250
Quoted 7 lines
+3.4 Throttling data configuration
+=============================Documentation/power/power_supply_charger.txt new file +5
-0+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
missing :
Documentation/power/power_supply_charger.txt line 304
Quoted 2 lines
Documentation/power/power_supply_charger.txt new file +2
-0+Power supply charging driver process this event and takes actions to setup +charging
Missing .
Documentation/power/power_supply_charger.txt line 309
Quoted 2 lines
Documentation/power/power_supply_charger.txt new file +2
-0+Power supply charging driver supports pluggable charging algorithms. Charging +algorithms process charging profile and/or applies different logic (pulse
"processes".
Documentation/power/power_supply_charger.txt line 321
Quoted 2 lines
Documentation/power/power_supply_charger.txt new file +2
-0+ /* callback function to retreive battery thresholds */ + pse_algo.get_batt_thresholds = my_algo__get_bat_thresholds;
Too many __s.
drivers/power/Kconfig config POWER_SUPPLY_DEBUG · line 23
Quoted 7 lines
drivers/power/Kconfig +7
-0+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
Missing .
drivers/power/power_supply_charger.c line 42
Quoted 6 lines
drivers/power/power_supply_charger.c new file +6
-0+struct psy_event_node { +struct list_head node; +unsigned long event; +struct psy_cable_props cap; +struct power_supply *psy; +struct psy_ps_batt_chg_prof batt_property;
Pls gt sm readable identfrs.
Quoted 1 line
+struct
power_supply_charger_cxt{
ps_charger_context ?
Pavel
Re: [PATCH 2/4] power_supply: Introduce Generic Power Supply charging driver
Quoted 6 lines · Pavel Machek
Documentation/power/power_supply_charger.txt line 206
Quoted 4 lines
Documentation/power/power_supply_charger.txt new file +4
-0+ * 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
Quoted 6 lines
Documentation/power/power_supply_charger.txt line 222
Quoted 4 lines
Documentation/power/power_supply_charger.txt new file +4
-0+* POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGING + * Write access using set_property + * Enable/Disable charging. Charger supplies power to platform, + but charging is disabledThis is unclear. Charging is always disabled?
Writing 0, disables charger. Writing 1 enables charging.
-Jenny
PATCH v3 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 | 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
drivers/power/Kconfig +12 -0
@@ -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
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 +44 -0
52 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!
drivers/power/Kconfig config POWER_SUPPLY_CHARGER · line 29
Quoted 5 lines
drivers/power/Kconfig +5
-0+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
It would be good to explain PSE here.
Quoted 1 line
+#define
MAINT_EXIT_OFFSET50 /* mv */
mV
include/linux/power/power_supply_charger.h enum { · line 91
Quoted 8 lines
include/linux/power/power_supply_charger.h +8
-0+/* PSE Modified Algo Structure */ +/* Parameters defining the charging range */ +struct psy_ps_temp_chg_table { +/* upper temperature limit for each zone */ +short int temp_up_lim; +/* charge current and voltage */ +short int full_chrg_vol; +short int full_chrg_cur;
It would be good to add units here. And vowels.
include/linux/power/power_supply_charger.h enum { · line 119
Quoted 11 lines
include/linux/power/power_supply_charger.h +11
-0+/* type of battery */ +u16 battery_type; +u16 capacity; +u16 voltage_max; +/* charge termination current */ +u16 chrg_term_ma; +/* Low battery level voltage */ +u16 low_batt_mv; +/* upper and lower temperature limits on discharging */ +u8 disch_tmp_ul; +u8 disch_tmp_ll;
tmp sounds like temporary, not temperature. just use full words.
Add units. And u8 is probably not right type for temperature.
include/linux/power/power_supply_charger.h enum { · line 124
Quoted 5 lines
include/linux/power/power_supply_charger.h +5
-0+/* 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 */ +short int temp_low_lim;
Add units.
Also check multiline comment codingstyle.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH v3 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 | 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
drivers/power/Kconfig +10 -0
@@ -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
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_BQ24261_CHARGER) += bq24261_charger.o obj-$(CONFIG_POWER_RESET) += reset/
drivers/power/bq24261_charger.c new file +1447 -0
1,447 lines not on this page · raw message
include/linux/power/bq24261_charger.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* 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; + +int (*enable_charging) (bool val); +int (*enable_charger) (bool val); +int (*set_inlmt) (int val); +int (*set_cc) (int val); +int (*set_cv) (int val); +int (*set_iterm) (int val); +int (*enable_vbus) (int val); +}; + + +#endif
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Quoted 7 lines · Jenny TC
This patch introduces BQ24261 charger driver. The driver makes use of power supply charging driver to setup charging. So the driver does hardware abstraction and handles h/w specific corner cases. The charging logic resides with power supply charging driver
Signed-off-by Jenny TC <[email protected]>
Hi Jenny,
Thank you for including me.
I added some minor comments. :-)
Quoted 56 lines
--- 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.hdrivers/power/Kconfig +10
-0@@ -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_SUPPLYdrivers/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_BQ24261_CHARGER) += bq24261_charger.o obj-$(CONFIG_POWER_RESET) += reset/drivers/power/bq24261_charger.c new file +10
-0@@ -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.
drivers/power/bq24261_charger.c line 20
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+* +* 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 <[email protected]> +*/ +#define DEBUG
Please insert one line between the comment and the "#define".
Quoted 8 lines
drivers/power/bq24261_charger.c new file +8
-0+#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/slab.h> +#include <linux/device.h>
drivers/power/bq24261_charger.c line 38
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+#include <linux/i2c.h> +#include <linux/power_supply.h> +#include <linux/pm_runtime.h> +#include <linux/io.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/usb/otg.h> +#include <linux/power/power_supply_charger.h> +#include <linux/power/bq24261_charger.h> +#include <linux/seq_file.h>
Would you re-order these headers alphabetically?
It enhances the readability.
Quoted 179 lines
drivers/power/bq24261_charger.c new file +179
-0+ +#include <asm/intel_scu_ipc.h> + +#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_ADDR 0x00 +#define BQ24261_CTRL_ADDR 0x01 +#define BQ24261_BATT_VOL_CTRL_ADDR 0x02 +#define BQ24261_VENDOR_REV_ADDR 0x03 +#define BQ24261_TERM_FCC_ADDR 0x04 +#define BQ24261_VINDPM_STAT_ADDR 0x05 +#define BQ24261_ST_NTC_MON_ADDR 0x06 + +#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_FAULT 0x04 +#define BQ24261_TIMER_FAULT 0x05 +#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_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) + +#define BQ24261_ITERM_MASK (0x03) +#define BQ24261_ITERM_50ma (0x01 << 0) +#define BQ24261_ITERM_100ma (0x01 << 1) +#define BQ24261_ITERM_200ma (0x01 << 2) + +#define BQ24261_VBREG_MASK (0x3F << 2) + +#define BQ24261_INLMT_MASK (0x03 << 4) +#define BQ24261_INLMT_100 0x00 +#define BQ24261_INLMT_150 (0x01 << 4) +#define BQ24261_INLMT_500 (0x02 << 4) +#define BQ24261_INLMT_900 (0x03 << 4) +#define BQ24261_INLMT_1500 (0x04 << 4) +#define BQ24261_INLMT_2500 (0x06 << 4) + +#define BQ24261_TE_MASK (0x01 << 2) +#define BQ24261_TE_ENABLE (0x01 << 2) +#define BQ24261_STAT_ENABLE_MASK (0x01 << 3) +#define BQ24261_STAT_ENABLE (0x01 << 3) + +#define BQ24261_VENDOR_MASK (0x07 << 5) +#define BQ24261_VENDOR (0x02 << 5) +#define BQ24261_REV_MASK (0x07) +#define BQ24261_REV (0x02) +#define BQ24260_REV (0x01) + +#define BQ24261_TS_MASK (0x01 << 3) +#define BQ24261_TS_ENABLED (0x01 << 3) +#define BQ24261_BOOST_ILIM_MASK (0x01 << 4) +#define BQ24261_BOOST_ILIM_500ma (0x0) +#define BQ24261_BOOST_ILIM_1A (0x01 << 4) + +#define BQ24261_SAFETY_TIMER_MASK (0x03 << 5) +#define BQ24261_SAFETY_TIMER_40MIN 0x00 +#define BQ24261_SAFETY_TIMER_6HR (0x01 << 5) +#define BQ24261_SAFETY_TIMER_9HR (0x02 << 5) +#define BQ24261_SAFETY_TIMER_DISABLED (0x03 << 5) + +/* 1% above voltage max design to report over voltage */ +#define BQ24261_OVP_MULTIPLIER 1010 +#define BQ24261_OVP_RECOVER_MULTIPLIER 990 +#define BQ24261_DEF_BAT_VOLT_MAX_DESIGN 4200000 + +/* Settings for Voltage / DPPM Register (05) */ +#define BQ24261_VBATT_LEVEL1 3700000 +#define BQ24261_VBATT_LEVEL2 3960000 +#define BQ24261_VINDPM_MASK (0x07) +#define BQ24261_VINDPM_320MV (0x01 << 2) +#define BQ24261_VINDPM_160MV (0x01 << 1) +#define BQ24261_VINDPM_80MV (0x01 << 0) +#define BQ24261_CD_STATUS_MASK (0x01 << 3) +#define BQ24261_DPM_EN_MASK (0x01 << 4) +#define BQ24261_DPM_EN_FORCE (0x01 << 4) +#define BQ24261_LOW_CHG_MASK (0x01 << 5) +#define BQ24261_LOW_CHG_EN (0x01 << 5) +#define BQ24261_LOW_CHG_DIS (~BQ24261_LOW_CHG_EN) +#define BQ24261_DPM_STAT_MASK (0x01 << 6) +#define BQ24261_MINSYS_STAT_MASK (0x01 << 7) + +#define BQ24261_MIN_CC 500 + +u16 bq24261_sfty_tmr[][2 ] = { + {0 ,BQ24261_SAFETY_TIMER_DISABLED } + , + {40 ,BQ24261_SAFETY_TIMER_40MIN } + , + {360 ,BQ24261_SAFETY_TIMER_6HR } + , + {540 ,BQ24261_SAFETY_TIMER_9HR } + , +}; + + +u16 bq24261_inlmt[][2 ] = { + {100 ,BQ24261_INLMT_100 } + , + {150 ,BQ24261_INLMT_150 } + , + {500 ,BQ24261_INLMT_500 } + , + {900 ,BQ24261_INLMT_900 } + , + {1500 ,BQ24261_INLMT_1500 } + , + {2500 ,BQ24261_INLMT_2500 } + , +}; + +u16 bq24261_iterm[][2 ] = { + {0 ,0x00 } + , + {50 , BQ24261_ITERM_50ma} + , + {100 , BQ24261_ITERM_100ma} + , + {150 , BQ24261_ITERM_100ma | BQ24261_ITERM_50ma} + , + {200 , BQ24261_ITERM_200ma} + , + {250 , BQ24261_ITERM_200ma | BQ24261_ITERM_50ma} + , + {300 , BQ24261_ITERM_200ma | BQ24261_ITERM_100ma} + , + {350 , BQ24261_ITERM_200ma | BQ24261_ITERM_100ma | BQ24261_ITERM_50ma} + , +}; + +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} + , + {1000 , BQ24261_ICHRG_400ma | BQ24261_ICHRG_100ma} + , + {1100 , BQ24261_ICHRG_400ma | BQ24261_ICHRG_200ma}
drivers/power/bq24261_charger.c line 227
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+ , + {1200, BQ24261_ICHRG_400ma | BQ24261_ICHRG_200ma | BQ24261_ICHRG_100ma} + , + {1300, BQ24261_ICHRG_800ma} + , + {1400, BQ24261_ICHRG_800ma | BQ24261_ICHRG_100ma} + , + {1500, BQ24261_ICHRG_800ma | BQ24261_ICHRG_200ma} + , +};
These 'u16 bq24261_*' looks to be used in only this file. Would you change these 'u16 bq24261_*' to 'static u16 bq24261_*'?
For example,
static u16 bq24261_sfty_tmr[][2] = {
[.....]
drivers/power/bq24261_charger.c line 348
Quoted 4 lines
drivers/power/bq24261_charger.c new file +4
-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)
Please insert one line between variable and 'for' loop.
Quoted 17 lines
drivers/power/bq24261_charger.c new file +17
-0+if (in_val < tbl[i][0 ]) +break ; + + *out_val = (u8 ) tbl[i -1 ][1 ]; +} + +void bq24261_cc_to_reg (int cc,u8 *reg_val) +{ +return lookup_regval (bq24261_cc,ARRAY_SIZE (bq24261_cc), cc, reg_val); + +} + +void bq24261_cv_to_reg (int cv,u8 *reg_val) +{ +int val; + + val =clamp_t (int, cv,BQ24261_MIN_CV ,BQ24261_MAX_CV );
drivers/power/bq24261_charger.c line 375
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+ *reg_val = + (((val -BQ24261_MIN_CV ) /BQ24261_CV_DIV ) + <<BQ24261_CV_BIT_POS ); +} + +void bq24261_inlmt_to_reg (int inlmt,u8 *regval) +{ +return lookup_regval (bq24261_inlmt,ARRAY_SIZE (bq24261_inlmt), + inlmt, regval); +}
How about making these functions static? For instance,
static void bq24261_cc_to_reg(int cc, u8 *reg_val)
Quoted 124 lines
drivers/power/bq24261_charger.c new file +124
-0+ +static inline void bq24261_iterm_to_reg (int iterm,u8 *regval) +{ +return lookup_regval (bq24261_iterm,ARRAY_SIZE (bq24261_iterm), + iterm, regval); +} + +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); +} + +static inline int bq24261_read_reg (struct i2c_client *client,u8 reg) +{ +int ret; + + ret =i2c_smbus_read_byte_data (client, reg); +if (ret <0 ) +dev_err (&client->dev,"Error(%d) in reading reg %d\n" , ret, + reg); + +return ret; +} + +static inline int bq24261_write_reg (struct i2c_client *client,u8 reg,u8 data) +{ +int ret; + + ret =i2c_smbus_write_byte_data (client, reg, data); +if (ret <0 ) +dev_err (&client->dev,"Error(%d) in writing %d to reg %d\n" , + ret, data, reg); + +return ret; +} + +static inline int bq24261_read_modify_reg (struct i2c_client *client,u8 reg, +u8 mask,u8 val) +{ +int ret; + + ret =bq24261_read_reg (client, reg); +if (ret <0 ) +return ret; + ret = (ret & ~mask) | (mask & val); +return bq24261_write_reg (client, reg, ret); +} + +static inline int bq24261_tmr_ntc_init (struct bq24261_charger *chip) +{ +u8 reg_val; +int ret; + +bq24261_sfty_tmr_to_reg (chip->pdata->safety_timer, ®_val); + +if (chip->pdata->is_ts_enabled) + reg_val |=BQ24261_TS_ENABLED ; + + ret =bq24261_read_modify_reg (chip->client,BQ24261_ST_NTC_MON_ADDR , +BQ24261_TS_MASK |BQ24261_SAFETY_TIMER_MASK | +BQ24261_BOOST_ILIM_MASK , reg_val); + +return ret; +} + +static inline int bq24261_enable_charging ( +struct bq24261_charger *chip,bool val) +{ +int ret; +u8 reg_val; +bool is_ready; + + ret =bq24261_read_reg (chip->client, +BQ24261_STAT_CTRL0_ADDR ); +if (ret <0 ) { +dev_err (&chip->client->dev, +"Error(%d) in reading BQ24261_STAT_CTRL0_ADDR\n" , ret); + } + + is_ready = (ret &BQ24261_STAT_MASK ) !=BQ24261_STAT_FAULT ; + +/* 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" ); + } + } + +if (val) { + reg_val = (~BQ24261_CE_DISABLE &BQ24261_CE_MASK ); +if (chip->is_hw_chrg_term) + reg_val |=BQ24261_TE_ENABLE ; + }else { + reg_val =BQ24261_CE_DISABLE ; + } + + reg_val |=BQ24261_STAT_ENABLE ; + + ret =bq24261_read_modify_reg (chip->client,BQ24261_CTRL_ADDR , +BQ24261_STAT_ENABLE_MASK |BQ24261_RESET_MASK | +BQ24261_CE_MASK |BQ24261_TE_MASK , + reg_val); +if (ret || !val) { +cancel_delayed_work_sync (&chip->notify_work); +return ret; + } + +bq24261_set_iterm (chip, chip->iterm); +schedule_delayed_work (&chip->notify_work,0 ); +bq24261_enable_hw_charge_term (chip, true); +return bq24261_tmr_ntc_init (chip); +} + +static inline int bq24261_reset_timer (struct bq24261_charger *chip) +{ + return bq24261_read_modify_reg(chip->client, BQ24261_STAT_CTRL0_ADDR,
drivers/power/bq24261_charger.c line 509
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+ BQ24261_TMR_RST_MASK, BQ24261_TMR_RST); +} + +static inline int bq24261_enable_charger ( +struct bq24261_charger *chip,int val) +{ + +/* TODO: Implement enable/disable HiZ mode to enable/ +* disable charger +*/
According to the Coding Style, the preferred style for long (multi-line) comments is:
+ /*
+ * TODO: Implement enable/disable HiZ mode to enable/
+ * disable charger
+ */
Quoted 131 lines
drivers/power/bq24261_charger.c new file +131
-0+u8 reg_val; +int ret; + + reg_val = val ? (~BQ24261_HZ_ENABLE &BQ24261_HZ_MASK ) : +BQ24261_HZ_ENABLE ; + + ret =bq24261_read_modify_reg (chip->client,BQ24261_CTRL_ADDR , +BQ24261_HZ_MASK |BQ24261_RESET_MASK , reg_val); +if (ret) +return ret; + +return bq24261_reset_timer (chip); +} + +static inline int bq24261_set_cc (struct bq24261_charger *chip,int cc) +{ +u8 reg_val; +int ret; + +dev_dbg (&chip->client->dev,"cc=%d\n" , cc); + +if (cc && (cc <BQ24261_MIN_CC )) { +dev_dbg (&chip->client->dev,"Set LOW_CHG bit\n" ); + reg_val =BQ24261_LOW_CHG_EN ; + ret =bq24261_read_modify_reg (chip->client, +BQ24261_VINDPM_STAT_ADDR , +BQ24261_LOW_CHG_MASK , reg_val); + }else { +dev_dbg (&chip->client->dev,"Clear LOW_CHG bit\n" ); + reg_val =BQ24261_LOW_CHG_DIS ; + ret =bq24261_read_modify_reg (chip->client, +BQ24261_VINDPM_STAT_ADDR , +BQ24261_LOW_CHG_MASK , reg_val); + } + +bq24261_cc_to_reg (cc, ®_val); + +return bq24261_read_modify_reg (chip->client,BQ24261_TERM_FCC_ADDR , +BQ24261_ICHRG_MASK , reg_val); +} + +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 +*/ + ret =get_battery_voltage (&bat_volt); +if (ret) { +dev_err (&chip->client->dev, +"Error getting battery voltage!!\n" ); + }else { +if (bat_volt >BQ24261_VBATT_LEVEL2 ) + vindpm_val = + (BQ24261_VINDPM_320MV |BQ24261_VINDPM_80MV ); +else if (bat_volt >BQ24261_VBATT_LEVEL1 ) + vindpm_val =BQ24261_VINDPM_160MV ; + } + + ret =bq24261_read_modify_reg (chip->client, +BQ24261_VINDPM_STAT_ADDR , +BQ24261_VINDPM_MASK , + vindpm_val); +if (ret) { +dev_err (&chip->client->dev, +"Error setting VINDPM setting!!\n" ); +return ret; + } + + +bq24261_cv_to_reg (cv, ®_val); + +return bq24261_read_modify_reg (chip->client,BQ24261_BATT_VOL_CTRL_ADDR , +BQ24261_VBREG_MASK , reg_val); +} + +static inline int bq24261_set_inlmt (struct bq24261_charger *chip,int inlmt) +{ +u8 reg_val; + +bq24261_inlmt_to_reg (inlmt, ®_val); + +return bq24261_read_modify_reg (chip->client,BQ24261_CTRL_ADDR , +BQ24261_RESET_MASK |BQ24261_INLMT_MASK , reg_val); + +} + +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); +} + +static inline int bq24261_set_iterm (struct bq24261_charger *chip,int iterm) +{ +u8 reg_val; + +bq24261_iterm_to_reg (iterm, ®_val); + +return bq24261_read_modify_reg (chip->client,BQ24261_TERM_FCC_ADDR , +BQ24261_ITERM_MASK , reg_val); +} + +static inline int bq24261_enable_hw_charge_term ( +struct bq24261_charger *chip,bool val) +{ +u8 data; +int ret; + + data = val ?BQ24261_TE_ENABLE : (~BQ24261_TE_ENABLE &BQ24261_TE_MASK ); + + + ret =bq24261_read_modify_reg (chip->client,BQ24261_CTRL_ADDR , +BQ24261_RESET_MASK |BQ24261_TE_MASK , data);
drivers/power/bq24261_charger.c line 650
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+ +if (ret) +return ret; + + chip->is_hw_chrg_term = val ? true : false; + +return ret; +} + +
Remove unnecessary line.
Quoted 24 lines
drivers/power/bq24261_charger.c new file +24
-0+static inline bool bq24261_is_vsys_on (struct bq24261_charger *chip) +{ +int ret; +struct i2c_client *client = chip->client; + + ret =bq24261_read_reg (client,BQ24261_CTRL_ADDR ); +if (ret <0 ) { +dev_err (&client->dev, +"Error(%d) in reading BQ24261_CTRL_ADDR\n" , ret); +return false; + } + +if (((ret &BQ24261_HZ_MASK ) ==BQ24261_HZ_ENABLE ) && + chip->is_charger_enabled) { +dev_err (&client->dev,"Charger in Hi Z Mode\n" ); +return false; + } + + ret =bq24261_read_reg (client,BQ24261_VINDPM_STAT_ADDR ); +if (ret <0 ) { +dev_err (&client->dev, +"Error(%d) in reading BQ24261_VINDPM_STAT_ADDR\n" , ret); +return false; + }
drivers/power/bq24261_charger.c line 684
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+ +if (ret &BQ24261_CD_STATUS_MASK ) { +dev_err (&client->dev,"CD line asserted\n" ); +return false; + } + +return true; +} + +
Remove unnecessary line.
drivers/power/bq24261_charger.c line 694
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-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; +/* BQ24261 gives interrupt only on stop/resume charging. +* If charging is already stopped, we need to query the hardware +* to see charger is still active and can supply vsys or not. +*/
According to the Coding Style, the preferred style for long (multi-line) comments is:
+ /*
+ * BQ24261 gives interrupt only on stop/resume charging.
+ * If charging is already stopped, we need to query the hardware
+ * to see charger is still active and can supply vsys or not.
+ */
Quoted 5 lines
drivers/power/bq24261_charger.c new file +5
-0+else if ((chip->chrgr_stat ==BQ24261_CHRGR_STAT_FAULT ) || + (!chip->is_charging_enabled)) +return bq24261_is_vsys_on (chip); +else +return chip->is_vsys_on;
drivers/power/bq24261_charger.c line 709
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+} + +static int bq24261_usb_psyc_set_property (struct power_supply_charger *psyc, +enum power_supply_charger_property pscp, +const union power_supply_propval *val) +{ +struct bq24261_charger *chip =container_of (psyc, + struct bq24261_charger, + psyc_usb); +int ret =0 ;
For the readability, how about the following?
struct bq24261_charger *chip; int ret = 0; chip = container_of(psyc, struct bq24261_charger, psyc_usb);
Quoted 67 lines
drivers/power/bq24261_charger.c new file +67
-0+ +mutex_lock (&chip->lock); +dev_dbg (&chip->client->dev,"%s: prop=%d, val=%d\n" , + __func__, pscp, val->intval); + +switch (pscp) { + +case POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGING : + ret =bq24261_enable_charging (chip, val->intval); + +if (ret) +dev_err (&chip->client->dev, +"Error(%d) in %s charging" , ret, + (val->intval ?"enable" :"disable" )); +else + chip->is_charging_enabled = val->intval; + +break ; +case POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGER : +/* Don't enable the charger unless overvoltage is recovered */ + +if (chip->bat_health !=POWER_SUPPLY_HEALTH_OVERVOLTAGE ) { + ret =bq24261_enable_charger (chip, val->intval); + +if (ret) +dev_err (&chip->client->dev, +"Error(%d) in %s charger" , ret, + (val->intval ?"enable" :"disable" )); +else + chip->is_charger_enabled = val->intval; + }else { +dev_info (&chip->client->dev,"Battery Over Voltage. Charger will be disabled\n" ); + } +break ; +case POWER_SUPPLY_CHARGER_PROP_CABLE_TYPE : + chip->cable_type = val->intval; + chip->psy_usb.type =get_power_supply_type (chip->cable_type); +if (chip->cable_type !=PSY_CHARGER_CABLE_TYPE_NONE ) { + chip->chrgr_health =POWER_SUPPLY_HEALTH_GOOD ; + chip->chrgr_stat =BQ24261_CHRGR_STAT_UNKNOWN ; + +/* Adding this processing in order to check +for any faults during connect */ + + ret =bq24261_read_reg (chip->client, +BQ24261_STAT_CTRL0_ADDR ); +if (ret <0 ) +dev_err (&chip->client->dev, +"Error (%d) in reading status register(0x00)\n" , + ret); +else +bq24261_handle_irq (chip, ret); + }else { + chip->chrgr_stat =BQ24261_CHRGR_STAT_UNKNOWN ; + chip->chrgr_health =POWER_SUPPLY_HEALTH_UNKNOWN ; +cancel_delayed_work_sync (&chip->low_supply_fault_work); + } +break ; +case POWER_SUPPLY_CHARGER_PROP_RESET_WDT : +bq24261_reset_timer (chip); +break ; +default : + ret = -ENODATA ; + } + +mutex_unlock (&chip->lock); +return ret;
drivers/power/bq24261_charger.c line 786
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+} + +static int bq24261_usb_set_property (struct power_supply *psy, +enum power_supply_property psp, +const union power_supply_propval *val) +{ +struct bq24261_charger *chip =container_of (psy, + struct bq24261_charger, + psy_usb); +int ret =0 ;
For the readability, how about the following?
struct bq24261_charger *chip; int ret = 0; chip = container_of(psyc, struct bq24261_charger, psyc_usb);
Quoted 52 lines
drivers/power/bq24261_charger.c new file +52
-0+ +mutex_lock (&chip->lock); + +switch (psp) { + +case POWER_SUPPLY_PROP_PRESENT : + chip->present = val->intval; +break ; +case POWER_SUPPLY_PROP_ONLINE : + chip->online = val->intval; +break ; +case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT : + ret =bq24261_set_cc (chip, val->intval); +if (!ret) + chip->cc = val->intval; +break ; +case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE : + ret =bq24261_set_cv (chip, val->intval); +if (!ret) + chip->cv = val->intval; +break ; +case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX : + chip->max_cc = val->intval; +break ; +case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX : + chip->max_cv = val->intval; +break ; +case POWER_SUPPLY_PROP_CHARGE_TERM_CUR : + ret =bq24261_set_iterm (chip, val->intval); +if (!ret) + chip->iterm = val->intval; +break ; +case POWER_SUPPLY_PROP_INLMT : + ret =bq24261_set_inlmt (chip, val->intval); +if (!ret) + chip->inlmt = val->intval; +break ; +case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT : + chip->cntl_state = val->intval; +break ; +case POWER_SUPPLY_PROP_TEMP_MAX : + chip->max_temp = val->intval; +break ; +case POWER_SUPPLY_PROP_TEMP_MIN : + chip->min_temp = val->intval; +break ; +default : + ret = -ENODATA ; + } + +mutex_unlock (&chip->lock); +return ret;
drivers/power/bq24261_charger.c line 848
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+} + +static int bq24261_usb_psyc_get_property (struct power_supply_charger *psyc, +enum power_supply_charger_property pscp, +union power_supply_propval *val) +{ +struct bq24261_charger *chip =container_of (psyc, + struct bq24261_charger, + psyc_usb); +
For the readability, how about the following?
struct bq24261_charger *chip; chip = container_of(psyc, struct bq24261_charger, psyc_usb);
Quoted 21 lines
drivers/power/bq24261_charger.c new file +21
-0+mutex_lock (&chip->lock); + +switch (pscp) { +case POWER_SUPPLY_CHARGER_PROP_CABLE_TYPE : + val->intval = chip->cable_type; +break ; +case POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGING : + val->intval = (chip->is_charging_enabled && + (chip->chrgr_stat ==BQ24261_CHRGR_STAT_CHARGING )); + +break ; +case POWER_SUPPLY_CHARGER_PROP_ENABLE_CHARGER : + val->intval =is_bq24261_enabled (chip); +break ; +default : +mutex_unlock (&chip->lock); +return -EINVAL ; + } + +mutex_unlock (&chip->lock); +return 0 ;
drivers/power/bq24261_charger.c line 879
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+} + +static int bq24261_usb_get_property (struct power_supply *psy, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct bq24261_charger *chip =container_of (psy, + struct bq24261_charger, + psy_usb); +
For the readability, how about the following?
struct bq24261_charger *chip; chip = container_of(psyc, struct bq24261_charger, psyc_usb);
[.....]
drivers/power/bq24261_charger.c line 1425
Quoted 7 lines
drivers/power/bq24261_charger.c new file +7
-0+ +MODULE_DEVICE_TABLE (i2c, bq24261_id); + +static struct i2c_driver bq24261_driver = { + .driver = { + .name =DEV_NAME , + },
Please fix indent problem as below:
+ },
Quoted 8 lines
drivers/power/bq24261_charger.c new file +8
-0+ .probe = bq24261_probe, + .remove = bq24261_remove, + .id_table = bq24261_id, +}; + +static int __init bq24261_init (void ) +{ +return i2c_add_driver (&bq24261_driver);
drivers/power/bq24261_charger.c line 1443
Quoted 10 lines
drivers/power/bq24261_charger.c new file +10
-0+} + +module_init (bq24261_init); + +static void __exit bq24261_exit(void) +{ +i2c_del_driver (&bq24261_driver); +} + +module_exit (bq24261_exit);
Please use module_i2c_driver() macro in order to make the code simpler. Then, above 13 lines can be one line as below.
module_i2c_driver(bq24261_driver);
Quoted 32 lines
drivers/power/bq24261_charger.c new file +4
-0+ +MODULE_AUTHOR ("Jenny TC <[email protected]>" ); +MODULE_DESCRIPTION ("BQ24261 Charger Driver" ); +MODULE_LICENSE ("GPL" );include/linux/power/bq24261_charger.h new file +22
-0@@ -0,0 +1,33 @@ +/* +* 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; +
include/linux/power/bq24261_charger.h line 32
Quoted 10 lines
include/linux/power/bq24261_charger.h new file +10
-0+int (*enable_charging) (bool val); +int (*enable_charger) (bool val); +int (*set_inlmt) (int val); +int (*set_cc) (int val); +int (*set_cv) (int val); +int (*set_iterm) (int val); +int (*enable_vbus) (int val); +}; + +
Remove unnecessary line. One line is good.
Quoted 3 lines
include/linux/power/bq24261_charger.h new file +1
-1+#endif --1.7.9.5
Re: [PATCH 4/4] power_supply: bq24261 charger driver
In reply to Jenny TCHi!
drivers/power/Makefile obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o · line 63
Quoted 7 lines
+++ b/drivers/power/Makefile
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_BQ24261_CHARGER) += bq24261_charger.o obj-$(CONFIG_POWER_RESET) += reset/
Spot two inconsistencies.
drivers/power/bq24261_charger.c line 759
Quoted 4 lines
drivers/power/bq24261_charger.c new file +4
-0+if (ret <0 ) +dev_err (&chip->client->dev, +"Error (%d) in reading status register(0x00)\n" , + ret);
If you have code indented 10 levels like this, you are doing something wrong.
Check codingstyle.
Maybe Rafael should be cced on the series?
Pavel
Re: [PATCH 4/4] power_supply: bq24261 charger driver
In reply to Jenny TCHi!
drivers/power/bq24261_charger.c line 94
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+#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.
And second:
drivers/power/bq24261_charger.c line 145
Quoted 3 lines
drivers/power/bq24261_charger.c new file +3
-0+#define BQ24261_VINDPM_320MV (0x01 << 2) +#define BQ24261_VINDPM_160MV (0x01 << 1) +#define BQ24261_VINDPM_80MV (0x01 << 0)
(Same here).
drivers/power/bq24261_charger.c line 191
Quoted 8 lines
drivers/power/bq24261_charger.c new file +8
-0+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 ?
drivers/power/bq24261_charger.c line 213
Quoted 11 lines
drivers/power/bq24261_charger.c new file +11
-0+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.
drivers/power/bq24261_charger.c line 690
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;
No need to do elses if all you do is return...
drivers/power/bq24261_charger.c line 1004
Quoted 7 lines
drivers/power/bq24261_charger.c new file +7
-0+return -EINVAL ; + + ret = psy->get_property (psy,POWER_SUPPLY_PROP_CURRENT_NOW , &val); +if (!ret) + *cur = val.intval; + +return ret;
You can merge two very similar functions here, AFAICT.
drivers/power/bq24261_charger.c line 1083
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+if (verify_recovery) { +if ((bat_volt) <= (bat_volt_max_des /1000 * +BQ24261_OVP_RECOVER_MULTIPLIER )) +return true; +else +return false;
Do this without if().
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 8 lines · Pavel Machek
drivers/power/bq24261_charger.c line 94
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+#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?
Quoted 11 lines
drivers/power/bq24261_charger.c line 191
Quoted 8 lines
drivers/power/bq24261_charger.c new file +8
-0+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
Quoted 1 line
(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?
Quoted 5 lines
Quoted 5 lines
drivers/power/bq24261_charger.c new file +5
-0+u16 bq24261_cc[][2 ] = { + + {500 ,0x00 } + , + {600 , BQ24261_ICHRG_100ma}
Quoted 8 lines
drivers/power/bq24261_charger.c line 213
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+ , + {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
Re: [PATCH 4/4] power_supply: bq24261 charger driver
Quoted 11 lines · Jenny Tc
Quoted 8 lines · Pavel Machek
drivers/power/bq24261_charger.c line 94
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+#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?
Yep, Camel Case is allowed by the commit d8b0771 "checkpatch:
extend CamelCase types and ignore existing CamelCase uses in a patch".
Thus, the following cases are currently allowed.
#define BQ24261_ICHRG_1600ma (0x01 << 7) #define BQ24261_ICHRG_1600MA (0x01 << 7) #define BQ24261_ICHRG_1600mA (0x01 << 7)
....
Best regards,
Jingoo Han
Quoted 33 lines
Quoted 11 lines
drivers/power/bq24261_charger.c line 191
Quoted 8 lines
drivers/power/bq24261_charger.c new file +8
-0+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
Quoted 1 line
(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?
Quoted 5 lines
Quoted 5 lines
drivers/power/bq24261_charger.c new file +5
-0+u16 bq24261_cc[][2 ] = { + + {500 ,0x00 } + , + {600 , BQ24261_ICHRG_100ma}Quoted 8 lines
drivers/power/bq24261_charger.c line 213
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+ , + {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
Re: [PATCH 4/4] power_supply: bq24261 charger driver
In reply to Jenny TcQuoted 11 lines · Jenny Tc
Quoted 8 lines · Pavel Machek
drivers/power/bq24261_charger.c line 94
Quoted 6 lines
drivers/power/bq24261_charger.c new file +6
-0+#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?
This is not camel case, this is mili ampers.
Quoted 5 lines
Quoted 1 line
(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?
No, it is definitely not readable. Please use logic where you can.
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html