Commit 68ade097 authored by Sebastian Reichel's avatar Sebastian Reichel
Browse files

power: supply: core: add power_supply_for_each_device()



Introduce power_supply_for_each_device(), which is a wrapper
for class_for_each_device() using the power_supply_class and
going through all devices.

This allows making the power_supply_class itself a local
variable, so that drivers cannot mess with it and simplifies
the code slightly.

Reviewed-by: default avatarRicardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240301-psy-class-cleanup-v1-1-aebe8c4b6b08@collabora.com


Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 71c2cc5c
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -617,8 +617,7 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
 */
static void ab8500_btemp_external_power_changed(struct power_supply *psy)
{
	class_for_each_device(&power_supply_class, NULL, psy,
			      ab8500_btemp_get_ext_psy_data);
	power_supply_for_each_device(psy, ab8500_btemp_get_ext_psy_data);
}

/* ab8500 btemp driver interrupts and their respective isr */
+1 −2
Original line number Diff line number Diff line
@@ -1231,8 +1231,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
	int ret;

	/* Collect data from all power_supply class devices */
	class_for_each_device(&power_supply_class, NULL,
		di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);
	power_supply_for_each_device(di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);

	ab8500_chargalg_end_of_charge(di);
	ab8500_chargalg_check_temp(di);
+1 −2
Original line number Diff line number Diff line
@@ -1949,8 +1949,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)
	struct ab8500_charger *di = container_of(work,
		struct ab8500_charger, check_vbat_work.work);

	class_for_each_device(&power_supply_class, NULL,
			      &di->usb_chg, ab8500_charger_get_ext_psy_data);
	power_supply_for_each_device(&di->usb_chg, ab8500_charger_get_ext_psy_data);

	/* First run old_vbat is 0. */
	if (di->old_vbat == 0)
+1 −2
Original line number Diff line number Diff line
@@ -2407,8 +2407,7 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)
 */
static void ab8500_fg_external_power_changed(struct power_supply *psy)
{
	class_for_each_device(&power_supply_class, NULL, psy,
			      ab8500_fg_get_ext_psy_data);
	power_supply_for_each_device(psy, ab8500_fg_get_ext_psy_data);
}

/**
+1 −2
Original line number Diff line number Diff line
@@ -79,8 +79,7 @@ static void find_main_battery(void)
	main_battery = NULL;
	bp.main = main_battery;

	error = class_for_each_device(&power_supply_class, NULL, &bp,
				      __find_main_battery);
	error = power_supply_for_each_device(&bp, __find_main_battery);
	if (error) {
		main_battery = bp.main;
		return;
Loading