Commit 1a91d4e2 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

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
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ void __init acpi_watchdog_init(void)
{
	const struct acpi_wdat_entry *entries;
	const struct acpi_table_wdat *wdat;
	struct list_head resource_list;
	LIST_HEAD(resource_list);
	struct resource_entry *rentry;
	struct platform_device *pdev;
	struct resource *resources;
@@ -125,8 +125,6 @@ void __init acpi_watchdog_init(void)
	    wdat->pci_device != 0xff || wdat->pci_function != 0xff)
		goto fail_put_wdat;

	INIT_LIST_HEAD(&resource_list);

	entries = (struct acpi_wdat_entry *)(wdat + 1);
	for (i = 0; i < wdat->entries; i++) {
		const struct acpi_generic_address *gas;
+40 −40
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/suspend.h>
#include <linux/types.h>
@@ -211,7 +212,14 @@ static int acpi_battery_get_property(struct power_supply *psy,
		if (battery->state & ACPI_BATTERY_STATE_DISCHARGING)
			val->intval = acpi_battery_handle_discharging(battery);
		else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
			/* Validate the status by checking the current. */
			if (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
			    battery->rate_now == 0) {
				/* On charge but no current (0W/0mA). */
				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
			} else {
				val->intval = POWER_SUPPLY_STATUS_CHARGING;
			}
		else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
		else if (acpi_battery_is_charged(battery))
@@ -1054,8 +1062,8 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
/* Driver Interface */
static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
{
	struct acpi_device *device = data;
	struct acpi_battery *battery = acpi_driver_data(device);
	struct acpi_battery *battery = data;
	struct acpi_device *device = battery->device;
	struct power_supply *old;

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

static int acpi_battery_add(struct acpi_device *device)
static int acpi_battery_probe(struct platform_device *pdev)
{
	int result = 0;
	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
	struct acpi_battery *battery;

	if (!device)
		return -EINVAL;
	int result;

	if (device->dep_unmet)
		return -EPROBE_DEFER;

	battery = devm_kzalloc(&device->dev, sizeof(*battery), GFP_KERNEL);
	battery = devm_kzalloc(&pdev->dev, sizeof(*battery), GFP_KERNEL);
	if (!battery)
		return -ENOMEM;

	platform_set_drvdata(pdev, battery);

	battery->device = device;
	strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
	strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
	device->driver_data = battery;

	result = devm_mutex_init(&device->dev, &battery->update_lock);
	result = devm_mutex_init(&pdev->dev, &battery->update_lock);
	if (result)
		return result;

@@ -1246,17 +1254,17 @@ static int acpi_battery_add(struct acpi_device *device)
	if (result)
		goto fail;

	device_init_wakeup(&device->dev, 1);
	device_init_wakeup(&pdev->dev, true);

	result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
						 acpi_battery_notify, device);
						 acpi_battery_notify, battery);
	if (result)
		goto fail_pm;

	return 0;

fail_pm:
	device_init_wakeup(&device->dev, 0);
	device_init_wakeup(&pdev->dev, false);
	unregister_pm_notifier(&battery->pm_nb);
fail:
	sysfs_battery_cleanup(battery);
@@ -1264,35 +1272,28 @@ static int acpi_battery_add(struct acpi_device *device)
	return result;
}

static void acpi_battery_remove(struct acpi_device *device)
static void acpi_battery_remove(struct platform_device *pdev)
{
	struct acpi_battery *battery;
	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
	struct acpi_battery *battery = platform_get_drvdata(pdev);

	if (!device || !acpi_driver_data(device))
	if (!device || !battery)
		return;

	battery = acpi_driver_data(device);

	acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
				       acpi_battery_notify);

	device_init_wakeup(&device->dev, 0);
	device_init_wakeup(&pdev->dev, false);
	unregister_pm_notifier(&battery->pm_nb);

	guard(mutex)(&battery->update_lock);

	sysfs_remove_battery(battery);
	sysfs_battery_cleanup(battery);
}

/* this is needed to learn about changes made in suspended state */
static int acpi_battery_resume(struct device *dev)
{
	struct acpi_battery *battery;

	if (!dev)
		return -EINVAL;
	struct acpi_battery *battery = dev_get_drvdata(dev);

	battery = acpi_driver_data(to_acpi_device(dev));
	if (!battery)
		return -EINVAL;

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

static DEFINE_SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume);

static struct acpi_driver acpi_battery_driver = {
	.name = "battery",
	.class = ACPI_BATTERY_CLASS,
	.ids = battery_device_ids,
	.ops = {
		.add = acpi_battery_add,
static struct platform_driver acpi_battery_driver = {
	.probe = acpi_battery_probe,
	.remove = acpi_battery_remove,
	.driver = {
		.name = "acpi-battery",
		.acpi_match_table = battery_device_ids,
		.pm = pm_sleep_ptr(&acpi_battery_pm),
		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
	},
	.drv.pm = pm_sleep_ptr(&acpi_battery_pm),
	.drv.probe_type = PROBE_PREFER_ASYNCHRONOUS,
};

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

	dmi_check_system(bat_dmi_table);

	return acpi_bus_register_driver(&acpi_battery_driver);
	return platform_driver_register(&acpi_battery_driver);
}

static void __exit acpi_battery_exit(void)
{
	acpi_bus_unregister_driver(&acpi_battery_driver);
	platform_driver_unregister(&acpi_battery_driver);
	battery_hook_exit();
}