Skip to content

Commit f8c4292

Browse files
author
Al Stone
committed
power: supply: core: Add kerneldoc to battery struct
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071846 Tested: This is one of a series of patch sets to enable Arm SystemReady IR support in the kernel for NXP i.MX8 platforms. This set updates the power subsystem. This set has been tested via simple boot tests and the CI loop. commit e0dbd7b Author: Linus Walleij <linus.walleij@linaro.org> Date: Tue Nov 16 23:44:28 2021 +0100 power: supply: core: Add kerneldoc to battery struct This complements the struct power_supply_battery_info with extensive kerneldoc explaining the different semantics of the fields, including an overview of the CC/CV charging concepts implicit in some of the struct members. This is done to first establish semantics before I can add more charging methods by breaking out the CC/CV parameters to its own struct. Tested-by: Randy Dunlap <rdunlap@infradead.org> Acked-by: Randy Dunlap <rdunlap@infradead.org> Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> (cherry picked from commit e0dbd7b) Signed-off-by: Al Stone <ahs3@redhat.com>
1 parent f132271 commit f8c4292

File tree

1 file changed

+192
-23
lines changed

1 file changed

+192
-23
lines changed

include/linux/power_supply.h

Lines changed: 192 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -351,37 +351,206 @@ struct power_supply_resistance_temp_table {
351351

352352
#define POWER_SUPPLY_OCV_TEMP_MAX 20
353353

354-
/*
354+
/**
355+
* struct power_supply_battery_info - information about batteries
356+
* @technology: from the POWER_SUPPLY_TECHNOLOGY_* enum
357+
* @energy_full_design_uwh: energy content when fully charged in microwatt
358+
* hours
359+
* @charge_full_design_uah: charge content when fully charged in microampere
360+
* hours
361+
* @voltage_min_design_uv: minimum voltage across the poles when the battery
362+
* is at minimum voltage level in microvolts. If the voltage drops below this
363+
* level the battery will need precharging when using CC/CV charging.
364+
* @voltage_max_design_uv: voltage across the poles when the battery is fully
365+
* charged in microvolts. This is the "nominal voltage" i.e. the voltage
366+
* printed on the label of the battery.
367+
* @tricklecharge_current_ua: the tricklecharge current used when trickle
368+
* charging the battery in microamperes. This is the charging phase when the
369+
* battery is completely empty and we need to carefully trickle in some
370+
* charge until we reach the precharging voltage.
371+
* @precharge_current_ua: current to use in the precharge phase in microamperes,
372+
* the precharge rate is limited by limiting the current to this value.
373+
* @precharge_voltage_max_uv: the maximum voltage allowed when precharging in
374+
* microvolts. When we pass this voltage we will nominally switch over to the
375+
* CC (constant current) charging phase defined by constant_charge_current_ua
376+
* and constant_charge_voltage_max_uv.
377+
* @charge_term_current_ua: when the current in the CV (constant voltage)
378+
* charging phase drops below this value in microamperes the charging will
379+
* terminate completely and not restart until the voltage over the battery
380+
* poles reach charge_restart_voltage_uv unless we use maintenance charging.
381+
* @charge_restart_voltage_uv: when the battery has been fully charged by
382+
* CC/CV charging and charging has been disabled, and the voltage subsequently
383+
* drops below this value in microvolts, the charging will be restarted
384+
* (typically using CV charging).
385+
* @overvoltage_limit_uv: If the voltage exceeds the nominal voltage
386+
* voltage_max_design_uv and we reach this voltage level, all charging must
387+
* stop and emergency procedures take place, such as shutting down the system
388+
* in some cases.
389+
* @constant_charge_current_max_ua: current in microamperes to use in the CC
390+
* (constant current) charging phase. The charging rate is limited
391+
* by this current. This is the main charging phase and as the current is
392+
* constant into the battery the voltage slowly ascends to
393+
* constant_charge_voltage_max_uv.
394+
* @constant_charge_voltage_max_uv: voltage in microvolts signifying the end of
395+
* the CC (constant current) charging phase and the beginning of the CV
396+
* (constant voltage) charging phase.
397+
* @factory_internal_resistance_uohm: the internal resistance of the battery
398+
* at fabrication time, expressed in microohms. This resistance will vary
399+
* depending on the lifetime and charge of the battery, so this is just a
400+
* nominal ballpark figure.
401+
* @ocv_temp: array indicating the open circuit voltage (OCV) capacity
402+
* temperature indices. This is an array of temperatures in degrees Celsius
403+
* indicating which capacity table to use for a certain temperature, since
404+
* the capacity for reasons of chemistry will be different at different
405+
* temperatures. Determining capacity is a multivariate problem and the
406+
* temperature is the first variable we determine.
407+
* @temp_ambient_alert_min: the battery will go outside of operating conditions
408+
* when the ambient temperature goes below this temperature in degrees
409+
* Celsius.
410+
* @temp_ambient_alert_max: the battery will go outside of operating conditions
411+
* when the ambient temperature goes above this temperature in degrees
412+
* Celsius.
413+
* @temp_alert_min: the battery should issue an alert if the internal
414+
* temperature goes below this temperature in degrees Celsius.
415+
* @temp_alert_max: the battery should issue an alert if the internal
416+
* temperature goes above this temperature in degrees Celsius.
417+
* @temp_min: the battery will go outside of operating conditions when
418+
* the internal temperature goes below this temperature in degrees Celsius.
419+
* Normally this means the system should shut down.
420+
* @temp_max: the battery will go outside of operating conditions when
421+
* the internal temperature goes above this temperature in degrees Celsius.
422+
* Normally this means the system should shut down.
423+
* @ocv_table: for each entry in ocv_temp there is a corresponding entry in
424+
* ocv_table and a size for each entry in ocv_table_size. These arrays
425+
* determine the capacity in percent in relation to the voltage in microvolts
426+
* at the indexed temperature.
427+
* @ocv_table_size: for each entry in ocv_temp this array is giving the size of
428+
* each entry in the array of capacity arrays in ocv_table.
429+
* @resist_table: this is a table that correlates a battery temperature to the
430+
* expected internal resistance at this temperature. The resistance is given
431+
* as a percentage of factory_internal_resistance_uohm. Knowing the
432+
* resistance of the battery is usually necessary for calculating the open
433+
* circuit voltage (OCV) that is then used with the ocv_table to calculate
434+
* the capacity of the battery. The resist_table must be ordered descending
435+
* by temperature: highest temperature with lowest resistance first, lowest
436+
* temperature with highest resistance last.
437+
* @resist_table_size: the number of items in the resist_table.
438+
*
355439
* This is the recommended struct to manage static battery parameters,
356440
* populated by power_supply_get_battery_info(). Most platform drivers should
357441
* use these for consistency.
442+
*
358443
* Its field names must correspond to elements in enum power_supply_property.
359444
* The default field value is -EINVAL.
360-
* Power supply class itself doesn't use this.
445+
*
446+
* The charging parameters here assume a CC/CV charging scheme. This method
447+
* is most common with Lithium Ion batteries (other methods are possible) and
448+
* looks as follows:
449+
*
450+
* ^ Battery voltage
451+
* | --- overvoltage_limit_uv
452+
* |
453+
* | ...................................................
454+
* | .. constant_charge_voltage_max_uv
455+
* | ..
456+
* | .
457+
* | .
458+
* | .
459+
* | .
460+
* | .
461+
* | .. precharge_voltage_max_uv
462+
* | ..
463+
* |. (trickle charging)
464+
* +------------------------------------------------------------------> time
465+
*
466+
* ^ Current into the battery
467+
* |
468+
* | ............. constant_charge_current_max_ua
469+
* | . .
470+
* | . .
471+
* | . .
472+
* | . .
473+
* | . ..
474+
* | . ....
475+
* | . .....
476+
* | ... precharge_current_ua ....... charge_term_current_ua
477+
* | . .
478+
* | . .
479+
* |.... tricklecharge_current_ua .
480+
* | .
481+
* +-----------------------------------------------------------------> time
482+
*
483+
* These diagrams are synchronized on time and the voltage and current
484+
* follow each other.
485+
*
486+
* With CC/CV charging commence over time like this for an empty battery:
487+
*
488+
* 1. When the battery is completely empty it may need to be charged with
489+
* an especially small current so that electrons just "trickle in",
490+
* this is the tricklecharge_current_ua.
491+
*
492+
* 2. Next a small initial pre-charge current (precharge_current_ua)
493+
* is applied if the voltage is below precharge_voltage_max_uv until we
494+
* reach precharge_voltage_max_uv. CAUTION: in some texts this is referred
495+
* to as "trickle charging" but the use in the Linux kernel is different
496+
* see below!
497+
*
498+
* 3. Then the main charging current is applied, which is called the constant
499+
* current (CC) phase. A current regulator is set up to allow
500+
* constant_charge_current_max_ua of current to flow into the battery.
501+
* The chemical reaction in the battery will make the voltage go up as
502+
* charge goes into the battery. This current is applied until we reach
503+
* the constant_charge_voltage_max_uv voltage.
504+
*
505+
* 4. At this voltage we switch over to the constant voltage (CV) phase. This
506+
* means we allow current to go into the battery, but we keep the voltage
507+
* fixed. This current will continue to charge the battery while keeping
508+
* the voltage the same. A chemical reaction in the battery goes on
509+
* storing energy without affecting the voltage. Over time the current
510+
* will slowly drop and when we reach charge_term_current_ua we will
511+
* end the constant voltage phase.
512+
*
513+
* After this the battery is fully charged, and if we do not support maintenance
514+
* charging, the charging will not restart until power dissipation makes the
515+
* voltage fall so that we reach charge_restart_voltage_uv and at this point
516+
* we restart charging at the appropriate phase, usually this will be inside
517+
* the CV phase.
518+
*
519+
* If we support maintenance charging the voltage is however kept high after
520+
* the CV phase with a very low current. This is meant to let the same charge
521+
* go in for usage while the charger is still connected, mainly for
522+
* dissipation for the power consuming entity while connected to the
523+
* charger.
524+
*
525+
* All charging MUST terminate if the overvoltage_limit_uv is ever reached.
526+
* Overcharging Lithium Ion cells can be DANGEROUS and lead to fire or
527+
* explosions.
528+
*
529+
* The power supply class itself doesn't use this struct as of now.
361530
*/
362531

363532
struct power_supply_battery_info {
364-
unsigned int technology; /* from the enum above */
365-
int energy_full_design_uwh; /* microWatt-hours */
366-
int charge_full_design_uah; /* microAmp-hours */
367-
int voltage_min_design_uv; /* microVolts */
368-
int voltage_max_design_uv; /* microVolts */
369-
int tricklecharge_current_ua; /* microAmps */
370-
int precharge_current_ua; /* microAmps */
371-
int precharge_voltage_max_uv; /* microVolts */
372-
int charge_term_current_ua; /* microAmps */
373-
int charge_restart_voltage_uv; /* microVolts */
374-
int overvoltage_limit_uv; /* microVolts */
375-
int constant_charge_current_max_ua; /* microAmps */
376-
int constant_charge_voltage_max_uv; /* microVolts */
377-
int factory_internal_resistance_uohm; /* microOhms */
378-
int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */
379-
int temp_ambient_alert_min; /* celsius */
380-
int temp_ambient_alert_max; /* celsius */
381-
int temp_alert_min; /* celsius */
382-
int temp_alert_max; /* celsius */
383-
int temp_min; /* celsius */
384-
int temp_max; /* celsius */
533+
unsigned int technology;
534+
int energy_full_design_uwh;
535+
int charge_full_design_uah;
536+
int voltage_min_design_uv;
537+
int voltage_max_design_uv;
538+
int tricklecharge_current_ua;
539+
int precharge_current_ua;
540+
int precharge_voltage_max_uv;
541+
int charge_term_current_ua;
542+
int charge_restart_voltage_uv;
543+
int overvoltage_limit_uv;
544+
int constant_charge_current_max_ua;
545+
int constant_charge_voltage_max_uv;
546+
int factory_internal_resistance_uohm;
547+
int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];
548+
int temp_ambient_alert_min;
549+
int temp_ambient_alert_max;
550+
int temp_alert_min;
551+
int temp_alert_max;
552+
int temp_min;
553+
int temp_max;
385554
struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX];
386555
int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
387556
struct power_supply_resistance_temp_table *resist_table;

0 commit comments

Comments
 (0)