mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 13:53:33 +00:00
ACPI: battery: Pass battery hook pointer to hook callbacks
Right now, is impossible for battery hook callbacks to access instance-specific data, forcing most drivers to provide some sort of global state. This however is difficult for drivers which can be instantiated multiple times and/or are hotplug-capable. Pass a pointer to the battery hook to those callbacks for usage with container_of(). Signed-off-by: Armin Wolf <W_Armin@gmx.de> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/20220927204521.601887-2-W_Armin@gmx.de Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
19c8b52414
commit
878a82c234
8 changed files with 18 additions and 18 deletions
|
@ -696,7 +696,7 @@ static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
|
||||||
if (lock)
|
if (lock)
|
||||||
mutex_lock(&hook_mutex);
|
mutex_lock(&hook_mutex);
|
||||||
list_for_each_entry(battery, &acpi_battery_list, list) {
|
list_for_each_entry(battery, &acpi_battery_list, list) {
|
||||||
hook->remove_battery(battery->bat);
|
hook->remove_battery(battery->bat, hook);
|
||||||
}
|
}
|
||||||
list_del(&hook->list);
|
list_del(&hook->list);
|
||||||
if (lock)
|
if (lock)
|
||||||
|
@ -724,7 +724,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)
|
||||||
* its attributes.
|
* its attributes.
|
||||||
*/
|
*/
|
||||||
list_for_each_entry(battery, &acpi_battery_list, list) {
|
list_for_each_entry(battery, &acpi_battery_list, list) {
|
||||||
if (hook->add_battery(battery->bat)) {
|
if (hook->add_battery(battery->bat, hook)) {
|
||||||
/*
|
/*
|
||||||
* If a add-battery returns non-zero,
|
* If a add-battery returns non-zero,
|
||||||
* the registration of the extension has failed,
|
* the registration of the extension has failed,
|
||||||
|
@ -762,7 +762,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)
|
||||||
* during the battery module initialization.
|
* during the battery module initialization.
|
||||||
*/
|
*/
|
||||||
list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) {
|
list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) {
|
||||||
if (hook_node->add_battery(battery->bat)) {
|
if (hook_node->add_battery(battery->bat, hook_node)) {
|
||||||
/*
|
/*
|
||||||
* The notification of the extensions has failed, to
|
* The notification of the extensions has failed, to
|
||||||
* prevent further errors we will unload the extension.
|
* prevent further errors we will unload the extension.
|
||||||
|
@ -785,7 +785,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery)
|
||||||
* custom attributes from the battery.
|
* custom attributes from the battery.
|
||||||
*/
|
*/
|
||||||
list_for_each_entry(hook, &battery_hook_list, list) {
|
list_for_each_entry(hook, &battery_hook_list, list) {
|
||||||
hook->remove_battery(battery->bat);
|
hook->remove_battery(battery->bat, hook);
|
||||||
}
|
}
|
||||||
/* Then, just remove the battery from the list */
|
/* Then, just remove the battery from the list */
|
||||||
list_del(&battery->list);
|
list_del(&battery->list);
|
||||||
|
|
|
@ -883,7 +883,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
|
||||||
|
|
||||||
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
||||||
|
|
||||||
static int asus_wmi_battery_add(struct power_supply *battery)
|
static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
/* The WMI method does not provide a way to specific a battery, so we
|
/* The WMI method does not provide a way to specific a battery, so we
|
||||||
* just assume it is the first battery.
|
* just assume it is the first battery.
|
||||||
|
@ -910,7 +910,7 @@ static int asus_wmi_battery_add(struct power_supply *battery)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int asus_wmi_battery_remove(struct power_supply *battery)
|
static int asus_wmi_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_file(&battery->dev,
|
device_remove_file(&battery->dev,
|
||||||
&dev_attr_charge_control_end_threshold);
|
&dev_attr_charge_control_end_threshold);
|
||||||
|
|
|
@ -468,7 +468,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold);
|
||||||
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
||||||
static DEVICE_ATTR_RW(charge_control_thresholds);
|
static DEVICE_ATTR_RW(charge_control_thresholds);
|
||||||
|
|
||||||
static int huawei_wmi_battery_add(struct power_supply *battery)
|
static int huawei_wmi_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int huawei_wmi_battery_remove(struct power_supply *battery)
|
static int huawei_wmi_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold);
|
device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold);
|
||||||
device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold);
|
device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold);
|
||||||
|
|
|
@ -546,7 +546,7 @@ static DEVICE_ATTR_RW(fn_lock);
|
||||||
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
static DEVICE_ATTR_RW(charge_control_end_threshold);
|
||||||
static DEVICE_ATTR_RW(battery_care_limit);
|
static DEVICE_ATTR_RW(battery_care_limit);
|
||||||
|
|
||||||
static int lg_battery_add(struct power_supply *battery)
|
static int lg_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
if (device_create_file(&battery->dev,
|
if (device_create_file(&battery->dev,
|
||||||
&dev_attr_charge_control_end_threshold))
|
&dev_attr_charge_control_end_threshold))
|
||||||
|
@ -555,7 +555,7 @@ static int lg_battery_add(struct power_supply *battery)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lg_battery_remove(struct power_supply *battery)
|
static int lg_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_file(&battery->dev,
|
device_remove_file(&battery->dev,
|
||||||
&dev_attr_charge_control_end_threshold);
|
&dev_attr_charge_control_end_threshold);
|
||||||
|
|
|
@ -254,7 +254,7 @@ static struct attribute *system76_battery_attrs[] = {
|
||||||
|
|
||||||
ATTRIBUTE_GROUPS(system76_battery);
|
ATTRIBUTE_GROUPS(system76_battery);
|
||||||
|
|
||||||
static int system76_battery_add(struct power_supply *battery)
|
static int system76_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
// System76 EC only supports 1 battery
|
// System76 EC only supports 1 battery
|
||||||
if (strcmp(battery->desc->name, "BAT0") != 0)
|
if (strcmp(battery->desc->name, "BAT0") != 0)
|
||||||
|
@ -266,7 +266,7 @@ static int system76_battery_add(struct power_supply *battery)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int system76_battery_remove(struct power_supply *battery)
|
static int system76_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_groups(&battery->dev, system76_battery_groups);
|
device_remove_groups(&battery->dev, system76_battery_groups);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -9907,7 +9907,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery);
|
||||||
|
|
||||||
/* ACPI battery hooking */
|
/* ACPI battery hooking */
|
||||||
|
|
||||||
static int tpacpi_battery_add(struct power_supply *battery)
|
static int tpacpi_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
int batteryid = tpacpi_battery_get_id(battery->desc->name);
|
int batteryid = tpacpi_battery_get_id(battery->desc->name);
|
||||||
|
|
||||||
|
@ -9918,7 +9918,7 @@ static int tpacpi_battery_add(struct power_supply *battery)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tpacpi_battery_remove(struct power_supply *battery)
|
static int tpacpi_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_groups(&battery->dev, tpacpi_battery_groups);
|
device_remove_groups(&battery->dev, tpacpi_battery_groups);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -3113,7 +3113,7 @@ static struct attribute *toshiba_acpi_battery_attrs[] = {
|
||||||
|
|
||||||
ATTRIBUTE_GROUPS(toshiba_acpi_battery);
|
ATTRIBUTE_GROUPS(toshiba_acpi_battery);
|
||||||
|
|
||||||
static int toshiba_acpi_battery_add(struct power_supply *battery)
|
static int toshiba_acpi_battery_add(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
if (toshiba_acpi == NULL) {
|
if (toshiba_acpi == NULL) {
|
||||||
pr_err("Init order issue\n");
|
pr_err("Init order issue\n");
|
||||||
|
@ -3126,7 +3126,7 @@ static int toshiba_acpi_battery_add(struct power_supply *battery)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int toshiba_acpi_battery_remove(struct power_supply *battery)
|
static int toshiba_acpi_battery_remove(struct power_supply *battery, struct acpi_battery_hook *hook)
|
||||||
{
|
{
|
||||||
device_remove_groups(&battery->dev, toshiba_acpi_battery_groups);
|
device_remove_groups(&battery->dev, toshiba_acpi_battery_groups);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
struct acpi_battery_hook {
|
struct acpi_battery_hook {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*add_battery)(struct power_supply *battery);
|
int (*add_battery)(struct power_supply *battery, struct acpi_battery_hook *hook);
|
||||||
int (*remove_battery)(struct power_supply *battery);
|
int (*remove_battery)(struct power_supply *battery, struct acpi_battery_hook *hook);
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue