Skip to content

Commit 569b438

Browse files
author
Herton R. Krzesinski
committed
Merge: Update drivers/power in order to support Arm SystemReady IR platforms
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1531 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. These patches make sure that the core of drivers/power is consistent with upstream Linux 6.0. Since it is unclear which power supplies and chargers will be needed -- these could vary wildly from platform to platform -- the code for individual devices has remained mostly untouched; they will need backporting in order to support them. Regardless, OEMs and other partners will have a welcoming environment for their specific devices. NB: there are a couple of patches that touch specific power supplies; these have only been added if they were a necessary part of an update to the core routines. Signed-off-by: Al Stone <ahs3@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Craig Magina <cmagina@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 0d5453b + 2287d85 commit 569b438

29 files changed

+1941
-323
lines changed

Documentation/ABI/testing/sysfs-class-power

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,16 @@ Description:
380380
algorithm to adjust the charge rate dynamically, without
381381
any user configuration required. "Custom" means that the charger
382382
uses the charge_control_* properties as configuration for some
383-
different algorithm.
383+
different algorithm. "Bypass" means the charger bypasses the
384+
charging path around the integrated converter allowing for a
385+
"smart" wall adaptor to perform the power conversion
386+
externally.
384387

385388
Access: Read, Write
386389

387390
Valid values:
388391
"Unknown", "N/A", "Trickle", "Fast", "Standard",
389-
"Adaptive", "Custom"
392+
"Adaptive", "Custom", "Bypass"
390393

391394
What: /sys/class/power_supply/<supply_name>/charge_term_current
392395
Date: July 2014
@@ -413,7 +416,7 @@ Description:
413416
"Over voltage", "Unspecified failure", "Cold",
414417
"Watchdog timer expire", "Safety timer expire",
415418
"Over current", "Calibration required", "Warm",
416-
"Cool", "Hot"
419+
"Cool", "Hot", "No battery"
417420

418421
What: /sys/class/power_supply/<supply_name>/precharge_current
419422
Date: June 2017
@@ -455,6 +458,21 @@ Description:
455458
"Unknown", "Charging", "Discharging",
456459
"Not charging", "Full"
457460

461+
What: /sys/class/power_supply/<supply_name>/charge_behaviour
462+
Date: November 2021
463+
Contact: linux-pm@vger.kernel.org
464+
Description:
465+
Represents the charging behaviour.
466+
467+
Access: Read, Write
468+
469+
Valid values:
470+
================ ====================================
471+
auto: Charge normally, respect thresholds
472+
inhibit-charge: Do not charge while AC is attached
473+
force-discharge: Force discharge while AC is attached
474+
================ ====================================
475+
458476
What: /sys/class/power_supply/<supply_name>/technology
459477
Date: May 2007
460478
Contact: linux-pm@vger.kernel.org

drivers/power/supply/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ config BATTERY_OLPC
181181
help
182182
Say Y to enable support for the battery on the OLPC laptop.
183183

184+
config BATTERY_SAMSUNG_SDI
185+
bool "Samsung SDI batteries"
186+
help
187+
Say Y to enable support for Samsung SDI battery data.
188+
These batteries are used in Samsung mobile phones.
189+
184190
config BATTERY_TOSA
185191
tristate "Sharp SL-6000 (tosa) battery"
186192
depends on MACH_TOSA && MFD_TC6393XB && TOUCHSCREEN_WM97XX

drivers/power/supply/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o
3434
obj-$(CONFIG_BATTERY_LEGO_EV3) += lego_ev3_battery.o
3535
obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
3636
obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
37+
obj-$(CONFIG_BATTERY_SAMSUNG_SDI) += samsung-sdi-battery.o
3738
obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o
3839
obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o
3940
obj-$(CONFIG_BATTERY_INGENIC) += ingenic-battery.o

drivers/power/supply/ab8500-bm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ struct abx500_v_to_cap {
300300
int voltage;
301301
int capacity;
302302
};
303-
304303
/* Forward declaration */
305304
struct abx500_fg;
306305

drivers/power/supply/ab8500_bmdata.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ static struct abx500_battery_type bat_type_thermistor[] = {
246246
.v_to_cap_tbl = cap_tbl_a_thermistor,
247247
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
248248
.batres_tbl = temp_to_batres_tbl_thermistor,
249-
250249
},
251250
{
252251
.name = POWER_SUPPLY_TECHNOLOGY_LIPO,
@@ -281,8 +280,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
281280
[BATTERY_UNKNOWN] = {
282281
/* First element always represent the UNKNOWN battery */
283282
.name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
284-
.resis_high = 0,
285-
.resis_low = 0,
283+
.resis_high = 0,
284+
.resis_low = 0,
286285
.battery_resistance = 300,
287286
.charge_full_design = 612,
288287
.nominal_voltage = 3700,
@@ -297,8 +296,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
297296
.maint_b_cur_lvl = 400,
298297
.maint_b_vol_lvl = 4000,
299298
.maint_b_chg_timer_h = 200,
300-
.low_high_cur_lvl = 300,
301-
.low_high_vol_lvl = 4000,
299+
.low_high_cur_lvl = 300,
300+
.low_high_vol_lvl = 4000,
302301
.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
303302
.r_to_t_tbl = temp_tbl,
304303
.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),

drivers/power/supply/ab8500_btemp.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "ab8500-bm.h"
3232

3333
#define VTVOUT_V 1800
34-
3534
#define BTEMP_THERMAL_LOW_LIMIT -10
3635
#define BTEMP_THERMAL_MED_LIMIT 0
3736
#define BTEMP_THERMAL_HIGH_LIMIT_52 52
@@ -135,7 +134,6 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
135134
int v_batctrl, int inst_curr)
136135
{
137136
int rbs;
138-
139137
if (is_ab8500_1p1_or_earlier(di->parent)) {
140138
/*
141139
* For ABB cut1.0 and 1.1 BAT_CTRL is internally
@@ -153,10 +151,10 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
153151
- di->bm->gnd_lift_resistance * inst_curr)
154152
/ di->curr_source;
155153
} else {
156-
/*
157-
* BAT_CTRL is internally
158-
* connected to 1.8V through a 80k resistor
159-
*/
154+
/*
155+
* BAT_CTRL is internally
156+
* connected to 1.8V through a 80k resistor
157+
*/
160158
rbs = (80000 * (v_batctrl)) / (1800 - v_batctrl);
161159
}
162160

@@ -358,7 +356,6 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
358356
dev_err(di->dev, "%s curr source enabled failed\n", __func__);
359357
return ret;
360358
}
361-
362359
if (!di->fg)
363360
di->fg = ab8500_fg_get();
364361
if (!di->fg) {
@@ -399,7 +396,6 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
399396
dev_err(di->dev, "%s curr source disable failed\n", __func__);
400397
return ret;
401398
}
402-
403399
dev_dbg(di->dev, "%s batctrl: %d res: %d inst_curr: %d samples: %d\n",
404400
__func__, batctrl, res, inst_curr, i);
405401

@@ -574,6 +570,7 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
574570
}
575571

576572
bat_temp = ab8500_btemp_measure_temp(di);
573+
577574
/*
578575
* Filter battery temperature.
579576
* Allow direct updates on temperature only if two samples result in

drivers/power/supply/ab8500_fg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ static int ab8500_fg_calc_cap_discharge_voltage(struct ab8500_fg *di, bool comp)
10771077
int permille, mah;
10781078

10791079
if (comp)
1080-
permille = ab8500_fg_load_comp_volt_to_capacity(di);
1080+
permille = ab8500_fg_load_comp_volt_to_capacity(di);
10811081
else
10821082
permille = ab8500_fg_uncomp_volt_to_capacity(di);
10831083

drivers/power/supply/abx500_chargalg.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,12 @@ static void abx500_chargalg_check_temp(struct abx500_chargalg *di)
731731
di->t_hyst_norm = 0;
732732
di->t_hyst_lowhigh = 0;
733733
} else {
734-
if (((di->batt_data.temp >= di->bm->temp_high) &&
734+
if (((di->batt_data.temp >= bi->temp_alert_max) &&
735735
(di->batt_data.temp <
736-
(di->bm->temp_over - di->t_hyst_lowhigh))) ||
736+
(bi->temp_max - di->t_hyst_lowhigh))) ||
737737
((di->batt_data.temp >
738-
(di->bm->temp_under + di->t_hyst_lowhigh)) &&
739-
(di->batt_data.temp <= di->bm->temp_low))) {
738+
(bi->temp_min + di->t_hyst_lowhigh)) &&
739+
(di->batt_data.temp <= bi->temp_alert_min))) {
740740
/* TEMP minor!!!!! */
741741
di->events.btemp_underover = false;
742742
di->events.btemp_lowhigh = true;
@@ -888,7 +888,7 @@ static enum maxim_ret abx500_chargalg_chg_curr_maxim(struct abx500_chargalg *di)
888888
di->ccm.max_current) {
889889
if (di->ccm.condition_cnt-- == 0) {
890890
/* Increse the iset with cco.test_delta_i */
891-
di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
891+
di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
892892
di->ccm.current_iset += di->ccm.test_delta_i;
893893
di->ccm.level++;
894894
dev_dbg(di->dev, " Maximization needed, increase"
@@ -900,8 +900,8 @@ static enum maxim_ret abx500_chargalg_chg_curr_maxim(struct abx500_chargalg *di)
900900
di->ccm.level);
901901
return MAXIM_RET_CHANGE;
902902
} else {
903-
return MAXIM_RET_NOACTION;
904-
}
903+
return MAXIM_RET_NOACTION;
904+
}
905905
} else {
906906
di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
907907
return MAXIM_RET_NOACTION;
@@ -1329,7 +1329,6 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
13291329
di->charge_state == STATE_SUSPENDED) {
13301330
/* We don't do anything here, just don,t continue */
13311331
}
1332-
13331332
/* Safety timer expiration */
13341333
else if (di->events.safety_timer_expired) {
13351334
if (di->charge_state != STATE_SAFETY_TIMER_EXPIRED)
@@ -1443,7 +1442,6 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
14431442
case STATE_SUSPENDED:
14441443
/* CHARGING is suspended */
14451444
break;
1446-
14471445
case STATE_BATT_REMOVED_INIT:
14481446
abx500_chargalg_stop_charging(di);
14491447
abx500_chargalg_state_to(di, STATE_BATT_REMOVED);
@@ -1591,12 +1589,10 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
15911589
break;
15921590

15931591
case STATE_TEMP_LOWHIGH_INIT:
1594-
abx500_chargalg_start_charging(di,
1595-
di->bm->bat_type[
1596-
di->bm->batt_id].low_high_vol_lvl,
1597-
di->bm->bat_type[
1598-
di->bm->batt_id].low_high_cur_lvl);
1599-
abx500_chargalg_stop_maintenance_timer(di);
1592+
ab8500_chargalg_start_charging(di,
1593+
di->bm->bat_type->low_high_vol_lvl,
1594+
di->bm->bat_type->low_high_cur_lvl);
1595+
ab8500_chargalg_stop_maintenance_timer(di);
16001596
di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
16011597
abx500_chargalg_state_to(di, STATE_TEMP_LOWHIGH);
16021598
power_supply_changed(di->chargalg_psy);
@@ -2060,7 +2056,6 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
20602056
return ret;
20612057
}
20622058
di->curr_status.curr_step = CHARGALG_CURR_STEP_HIGH;
2063-
20642059
dev_info(di->dev, "probe success\n");
20652060
return component_add(dev, &abx500_chargalg_component_ops);
20662061
}

drivers/power/supply/axp20x_battery.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ static int axp20x_power_probe(struct platform_device *pdev)
561561
{
562562
struct axp20x_batt_ps *axp20x_batt;
563563
struct power_supply_config psy_cfg = {};
564-
struct power_supply_battery_info info;
564+
struct power_supply_battery_info *info;
565565
struct device *dev = &pdev->dev;
566566

567567
if (!of_device_is_available(pdev->dev.of_node))
@@ -615,8 +615,8 @@ static int axp20x_power_probe(struct platform_device *pdev)
615615
}
616616

617617
if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
618-
int vmin = info.voltage_min_design_uv;
619-
int ccc = info.constant_charge_current_max_ua;
618+
int vmin = info->voltage_min_design_uv;
619+
int ccc = info->constant_charge_current_max_ua;
620620

621621
if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
622622
vmin))

drivers/power/supply/bd99954-charger.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ struct dt_init {
882882
static int bd9995x_fw_probe(struct bd9995x_device *bd)
883883
{
884884
int ret;
885-
struct power_supply_battery_info info;
885+
struct power_supply_battery_info *info;
886886
u32 property;
887887
int i;
888888
int regval;
@@ -891,49 +891,41 @@ static int bd9995x_fw_probe(struct bd9995x_device *bd)
891891
struct battery_init battery_inits[] = {
892892
{
893893
.name = "trickle-charging current",
894-
.info_data = &info.tricklecharge_current_ua,
895894
.range = &charging_current_ranges[0],
896895
.ranges = 2,
897896
.data = &init->itrich_set,
898897
}, {
899898
.name = "pre-charging current",
900-
.info_data = &info.precharge_current_ua,
901899
.range = &charging_current_ranges[0],
902900
.ranges = 2,
903901
.data = &init->iprech_set,
904902
}, {
905903
.name = "pre-to-trickle charge voltage threshold",
906-
.info_data = &info.precharge_voltage_max_uv,
907904
.range = &trickle_to_pre_threshold_ranges[0],
908905
.ranges = 2,
909906
.data = &init->vprechg_th_set,
910907
}, {
911908
.name = "charging termination current",
912-
.info_data = &info.charge_term_current_ua,
913909
.range = &charging_current_ranges[0],
914910
.ranges = 2,
915911
.data = &init->iterm_set,
916912
}, {
917913
.name = "charging re-start voltage",
918-
.info_data = &info.charge_restart_voltage_uv,
919914
.range = &charge_voltage_regulation_ranges[0],
920915
.ranges = 2,
921916
.data = &init->vrechg_set,
922917
}, {
923918
.name = "battery overvoltage limit",
924-
.info_data = &info.overvoltage_limit_uv,
925919
.range = &charge_voltage_regulation_ranges[0],
926920
.ranges = 2,
927921
.data = &init->vbatovp_set,
928922
}, {
929923
.name = "fast-charging max current",
930-
.info_data = &info.constant_charge_current_max_ua,
931924
.range = &fast_charge_current_ranges[0],
932925
.ranges = 1,
933926
.data = &init->ichg_set,
934927
}, {
935928
.name = "fast-charging voltage",
936-
.info_data = &info.constant_charge_voltage_max_uv,
937929
.range = &charge_voltage_regulation_ranges[0],
938930
.ranges = 2,
939931
.data = &init->vfastchg_reg_set1,
@@ -966,6 +958,16 @@ static int bd9995x_fw_probe(struct bd9995x_device *bd)
966958
if (ret < 0)
967959
return ret;
968960

961+
/* Put pointers to the generic battery info */
962+
battery_inits[0].info_data = &info->tricklecharge_current_ua;
963+
battery_inits[1].info_data = &info->precharge_current_ua;
964+
battery_inits[2].info_data = &info->precharge_voltage_max_uv;
965+
battery_inits[3].info_data = &info->charge_term_current_ua;
966+
battery_inits[4].info_data = &info->charge_restart_voltage_uv;
967+
battery_inits[5].info_data = &info->overvoltage_limit_uv;
968+
battery_inits[6].info_data = &info->constant_charge_current_max_ua;
969+
battery_inits[7].info_data = &info->constant_charge_voltage_max_uv;
970+
969971
for (i = 0; i < ARRAY_SIZE(battery_inits); i++) {
970972
int val = *battery_inits[i].info_data;
971973
const struct linear_range *range = battery_inits[i].range;
@@ -980,7 +982,7 @@ static int bd9995x_fw_probe(struct bd9995x_device *bd)
980982
dev_err(bd->dev, "Unsupported value for %s\n",
981983
battery_inits[i].name);
982984

983-
power_supply_put_battery_info(bd->charger, &info);
985+
power_supply_put_battery_info(bd->charger, info);
984986
return -EINVAL;
985987
}
986988
if (!found) {
@@ -991,7 +993,7 @@ static int bd9995x_fw_probe(struct bd9995x_device *bd)
991993
*(battery_inits[i].data) = regval;
992994
}
993995

994-
power_supply_put_battery_info(bd->charger, &info);
996+
power_supply_put_battery_info(bd->charger, info);
995997

996998
for (i = 0; i < ARRAY_SIZE(props); i++) {
997999
ret = device_property_read_u32(bd->dev, props[i].prop,

0 commit comments

Comments
 (0)