Skip to content

Commit 1a91d4e

Browse files
committed
Merge branches 'acpi-battery' and 'acpi-misc'
Merge ACPI battery driver changes and a generic ACPI watchdog device driver change for 6.20-rc1/7.0-rc1: - Convert the generic ACPI battery driver to a proper platform driver using struct platform_driver for device binding (Rafael Wysocki) - Fix incorrect charging status when current is zero in the generic ACPI battery driver (Ata İlhan Köktürk) - Use LIST_HEAD() for initializing a stack-allocated list in the generic ACPI watchdog device driver (Can Peng) * acpi-battery: ACPI: battery: fix incorrect charging status when current is zero ACPI: battery: Convert the driver to a platform one ACPI: battery: Reduce code duplication related to cleanup ACPI: battery: Adjust event notification routine * acpi-misc: ACPI: acpi_watchdog: use LIST_HEAD for stack-allocated list
3 parents 7c8b81f + bb1256e + b0c8ac5 commit 1a91d4e

2 files changed

Lines changed: 41 additions & 43 deletions

File tree

drivers/acpi/acpi_watchdog.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void __init acpi_watchdog_init(void)
103103
{
104104
const struct acpi_wdat_entry *entries;
105105
const struct acpi_table_wdat *wdat;
106-
struct list_head resource_list;
106+
LIST_HEAD(resource_list);
107107
struct resource_entry *rentry;
108108
struct platform_device *pdev;
109109
struct resource *resources;
@@ -125,8 +125,6 @@ void __init acpi_watchdog_init(void)
125125
wdat->pci_device != 0xff || wdat->pci_function != 0xff)
126126
goto fail_put_wdat;
127127

128-
INIT_LIST_HEAD(&resource_list);
129-
130128
entries = (struct acpi_wdat_entry *)(wdat + 1);
131129
for (i = 0; i < wdat->entries; i++) {
132130
const struct acpi_generic_address *gas;

drivers/acpi/battery.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/list.h>
1818
#include <linux/module.h>
1919
#include <linux/mutex.h>
20+
#include <linux/platform_device.h>
2021
#include <linux/slab.h>
2122
#include <linux/suspend.h>
2223
#include <linux/types.h>
@@ -211,7 +212,14 @@ static int acpi_battery_get_property(struct power_supply *psy,
211212
if (battery->state & ACPI_BATTERY_STATE_DISCHARGING)
212213
val->intval = acpi_battery_handle_discharging(battery);
213214
else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
214-
val->intval = POWER_SUPPLY_STATUS_CHARGING;
215+
/* Validate the status by checking the current. */
216+
if (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
217+
battery->rate_now == 0) {
218+
/* On charge but no current (0W/0mA). */
219+
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
220+
} else {
221+
val->intval = POWER_SUPPLY_STATUS_CHARGING;
222+
}
215223
else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
216224
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
217225
else if (acpi_battery_is_charged(battery))
@@ -1054,8 +1062,8 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
10541062
/* Driver Interface */
10551063
static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
10561064
{
1057-
struct acpi_device *device = data;
1058-
struct acpi_battery *battery = acpi_driver_data(device);
1065+
struct acpi_battery *battery = data;
1066+
struct acpi_device *device = battery->device;
10591067
struct power_supply *old;
10601068

10611069
if (!battery)
@@ -1208,26 +1216,26 @@ static void sysfs_battery_cleanup(struct acpi_battery *battery)
12081216
sysfs_remove_battery(battery);
12091217
}
12101218

1211-
static int acpi_battery_add(struct acpi_device *device)
1219+
static int acpi_battery_probe(struct platform_device *pdev)
12121220
{
1213-
int result = 0;
1221+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
12141222
struct acpi_battery *battery;
1215-
1216-
if (!device)
1217-
return -EINVAL;
1223+
int result;
12181224

12191225
if (device->dep_unmet)
12201226
return -EPROBE_DEFER;
12211227

1222-
battery = devm_kzalloc(&device->dev, sizeof(*battery), GFP_KERNEL);
1228+
battery = devm_kzalloc(&pdev->dev, sizeof(*battery), GFP_KERNEL);
12231229
if (!battery)
12241230
return -ENOMEM;
1231+
1232+
platform_set_drvdata(pdev, battery);
1233+
12251234
battery->device = device;
12261235
strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
12271236
strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
1228-
device->driver_data = battery;
12291237

1230-
result = devm_mutex_init(&device->dev, &battery->update_lock);
1238+
result = devm_mutex_init(&pdev->dev, &battery->update_lock);
12311239
if (result)
12321240
return result;
12331241

@@ -1246,53 +1254,46 @@ static int acpi_battery_add(struct acpi_device *device)
12461254
if (result)
12471255
goto fail;
12481256

1249-
device_init_wakeup(&device->dev, 1);
1257+
device_init_wakeup(&pdev->dev, true);
12501258

12511259
result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
1252-
acpi_battery_notify, device);
1260+
acpi_battery_notify, battery);
12531261
if (result)
12541262
goto fail_pm;
12551263

12561264
return 0;
12571265

12581266
fail_pm:
1259-
device_init_wakeup(&device->dev, 0);
1267+
device_init_wakeup(&pdev->dev, false);
12601268
unregister_pm_notifier(&battery->pm_nb);
12611269
fail:
12621270
sysfs_battery_cleanup(battery);
12631271

12641272
return result;
12651273
}
12661274

1267-
static void acpi_battery_remove(struct acpi_device *device)
1275+
static void acpi_battery_remove(struct platform_device *pdev)
12681276
{
1269-
struct acpi_battery *battery;
1277+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
1278+
struct acpi_battery *battery = platform_get_drvdata(pdev);
12701279

1271-
if (!device || !acpi_driver_data(device))
1280+
if (!device || !battery)
12721281
return;
12731282

1274-
battery = acpi_driver_data(device);
1275-
12761283
acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
12771284
acpi_battery_notify);
12781285

1279-
device_init_wakeup(&device->dev, 0);
1286+
device_init_wakeup(&pdev->dev, false);
12801287
unregister_pm_notifier(&battery->pm_nb);
12811288

1282-
guard(mutex)(&battery->update_lock);
1283-
1284-
sysfs_remove_battery(battery);
1289+
sysfs_battery_cleanup(battery);
12851290
}
12861291

12871292
/* this is needed to learn about changes made in suspended state */
12881293
static int acpi_battery_resume(struct device *dev)
12891294
{
1290-
struct acpi_battery *battery;
1295+
struct acpi_battery *battery = dev_get_drvdata(dev);
12911296

1292-
if (!dev)
1293-
return -EINVAL;
1294-
1295-
battery = acpi_driver_data(to_acpi_device(dev));
12961297
if (!battery)
12971298
return -EINVAL;
12981299

@@ -1306,16 +1307,15 @@ static int acpi_battery_resume(struct device *dev)
13061307

13071308
static DEFINE_SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume);
13081309

1309-
static struct acpi_driver acpi_battery_driver = {
1310-
.name = "battery",
1311-
.class = ACPI_BATTERY_CLASS,
1312-
.ids = battery_device_ids,
1313-
.ops = {
1314-
.add = acpi_battery_add,
1315-
.remove = acpi_battery_remove,
1316-
},
1317-
.drv.pm = pm_sleep_ptr(&acpi_battery_pm),
1318-
.drv.probe_type = PROBE_PREFER_ASYNCHRONOUS,
1310+
static struct platform_driver acpi_battery_driver = {
1311+
.probe = acpi_battery_probe,
1312+
.remove = acpi_battery_remove,
1313+
.driver = {
1314+
.name = "acpi-battery",
1315+
.acpi_match_table = battery_device_ids,
1316+
.pm = pm_sleep_ptr(&acpi_battery_pm),
1317+
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
1318+
},
13191319
};
13201320

13211321
static int __init acpi_battery_init(void)
@@ -1325,12 +1325,12 @@ static int __init acpi_battery_init(void)
13251325

13261326
dmi_check_system(bat_dmi_table);
13271327

1328-
return acpi_bus_register_driver(&acpi_battery_driver);
1328+
return platform_driver_register(&acpi_battery_driver);
13291329
}
13301330

13311331
static void __exit acpi_battery_exit(void)
13321332
{
1333-
acpi_bus_unregister_driver(&acpi_battery_driver);
1333+
platform_driver_unregister(&acpi_battery_driver);
13341334
battery_hook_exit();
13351335
}
13361336

0 commit comments

Comments
 (0)