Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c9ed61b authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge branches 'acpi-battery', 'acpi-doc' and 'acpi-pmic'

* acpi-battery:
  Revert "ACPI: battery: Add the ThinkPad "Not Charging" quirk"
  ACPI: battery: do not export degraded capacity values over 100
  ACPI: battery: make function __battery_hook_unregister() static
  ACPI: battery: Add the ThinkPad "Not Charging" quirk
  thinkpad_acpi: Add support for battery thresholds
  power: add to_power_supply macro to the API
  battery: Add the battery hooking API

* acpi-doc:
  ACPI: sysfs: Update device object sysfs documentation

* acpi-pmic:
  ACPI / PMIC: Replace license boilerplate with SPDX license identifier
Loading
Loading
Loading
Loading
+37 −0
Original line number Original line Diff line number Diff line
@@ -56,3 +56,40 @@ Description:
		Writing 1 to this attribute will trigger hot removal of
		Writing 1 to this attribute will trigger hot removal of
		this device object.  This file exists for every device
		this device object.  This file exists for every device
		object that has _EJ0 method.
		object that has _EJ0 method.

What:		/sys/bus/acpi/devices/.../status
Date:		Jan, 2014
Contact:	Rafael J. Wysocki <rjw@rjwysocki.net>
Description:
		(RO) Returns the ACPI device status: enabled, disabled or
		functioning or present, if the method _STA is present.

		The return value is a decimal integer representing the device's
		status bitmap:

		Bit [0] –  Set if the device is present.
		Bit [1] –  Set if the device is enabled and decoding its
		           resources.
		Bit [2] –  Set if the device should be shown in the UI.
		Bit [3] –  Set if the device is functioning properly (cleared if
		           device failed its diagnostics).
		Bit [4] –  Set if the battery is present.
		Bits [31:5] –  Reserved (must be cleared)

		If bit [0] is clear, then bit 1 must also be clear (a device
		that is not present cannot be enabled).

		Bit 0 can be clear (not present) with bit [3] set (device is
		functional).  This case is used to indicate a valid device for
		which no device driver should be loaded.

		More special cases are covered in the ACPI specification.

What:		/sys/bus/acpi/devices/.../hrv
Date:		Apr, 2016
Contact:	Rafael J. Wysocki <rjw@rjwysocki.net>
Description:
		(RO) Allows users to read the hardware version of non-PCI
		hardware, if the _HRV control method is present.  It is mostly
		useful for non-PCI devices because lspci can list the hardware
		version for PCI devices.
+1 −1
Original line number Original line Diff line number Diff line
@@ -33,7 +33,7 @@
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/power_supply.h>
#include <linux/acpi.h>
#include <linux/acpi.h>
#include "battery.h"
#include <acpi/battery.h>


#define PREFIX "ACPI: "
#define PREFIX "ACPI: "


+171 −3
Original line number Original line Diff line number Diff line
@@ -21,8 +21,12 @@
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/jiffies.h>
#include <linux/jiffies.h>
@@ -42,7 +46,7 @@
#include <linux/acpi.h>
#include <linux/acpi.h>
#include <linux/power_supply.h>
#include <linux/power_supply.h>


#include "battery.h"
#include <acpi/battery.h>


#define PREFIX "ACPI: "
#define PREFIX "ACPI: "


@@ -115,6 +119,10 @@ enum {
	   post-1.29 BIOS), but as of Nov. 2012, no such update is
	   post-1.29 BIOS), but as of Nov. 2012, no such update is
	   available for the 2010 models.  */
	   available for the 2010 models.  */
	ACPI_BATTERY_QUIRK_THINKPAD_MAH,
	ACPI_BATTERY_QUIRK_THINKPAD_MAH,
	/* for batteries reporting current capacity with design capacity
	 * on a full charge, but showing degradation in full charge cap.
	 */
	ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE,
};
};


struct acpi_battery {
struct acpi_battery {
@@ -124,6 +132,7 @@ struct acpi_battery {
	struct power_supply_desc bat_desc;
	struct power_supply_desc bat_desc;
	struct acpi_device *device;
	struct acpi_device *device;
	struct notifier_block pm_nb;
	struct notifier_block pm_nb;
	struct list_head list;
	unsigned long update_time;
	unsigned long update_time;
	int revision;
	int revision;
	int rate_now;
	int rate_now;
@@ -200,6 +209,12 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
	return 0;
	return 0;
}
}


static bool acpi_battery_is_degraded(struct acpi_battery *battery)
{
	return battery->full_charge_capacity && battery->design_capacity &&
		battery->full_charge_capacity < battery->design_capacity;
}

static int acpi_battery_get_property(struct power_supply *psy,
static int acpi_battery_get_property(struct power_supply *psy,
				     enum power_supply_property psp,
				     enum power_supply_property psp,
				     union power_supply_propval *val)
				     union power_supply_propval *val)
@@ -471,6 +486,10 @@ static int extract_battery_info(const int use_bix,
		   it's impossible to tell if they would need an adjustment
		   it's impossible to tell if they would need an adjustment
		   or not if their values were higher.  */
		   or not if their values were higher.  */
	}
	}
	if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) &&
	    battery->capacity_now > battery->full_charge_capacity)
		battery->capacity_now = battery->full_charge_capacity;

	return result;
	return result;
}
}


@@ -563,6 +582,10 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
		battery->capacity_now = battery->capacity_now *
		battery->capacity_now = battery->capacity_now *
		    10000 / battery->design_voltage;
		    10000 / battery->design_voltage;
	}
	}
	if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) &&
	    battery->capacity_now > battery->full_charge_capacity)
		battery->capacity_now = battery->full_charge_capacity;

	return result;
	return result;
}
}


@@ -626,6 +649,139 @@ static const struct device_attribute alarm_attr = {
	.store = acpi_battery_alarm_store,
	.store = acpi_battery_alarm_store,
};
};


/*
 * The Battery Hooking API
 *
 * This API is used inside other drivers that need to expose
 * platform-specific behaviour within the generic driver in a
 * generic way.
 *
 */

static LIST_HEAD(acpi_battery_list);
static LIST_HEAD(battery_hook_list);
static DEFINE_MUTEX(hook_mutex);

static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
{
	struct acpi_battery *battery;
	/*
	 * In order to remove a hook, we first need to
	 * de-register all the batteries that are registered.
	 */
	if (lock)
		mutex_lock(&hook_mutex);
	list_for_each_entry(battery, &acpi_battery_list, list) {
		hook->remove_battery(battery->bat);
	}
	list_del(&hook->list);
	if (lock)
		mutex_unlock(&hook_mutex);
	pr_info("extension unregistered: %s\n", hook->name);
}

void battery_hook_unregister(struct acpi_battery_hook *hook)
{
	__battery_hook_unregister(hook, 1);
}
EXPORT_SYMBOL_GPL(battery_hook_unregister);

void battery_hook_register(struct acpi_battery_hook *hook)
{
	struct acpi_battery *battery;

	mutex_lock(&hook_mutex);
	INIT_LIST_HEAD(&hook->list);
	list_add(&hook->list, &battery_hook_list);
	/*
	 * Now that the driver is registered, we need
	 * to notify the hook that a battery is available
	 * for each battery, so that the driver may add
	 * its attributes.
	 */
	list_for_each_entry(battery, &acpi_battery_list, list) {
		if (hook->add_battery(battery->bat)) {
			/*
			 * If a add-battery returns non-zero,
			 * the registration of the extension has failed,
			 * and we will not add it to the list of loaded
			 * hooks.
			 */
			pr_err("extension failed to load: %s", hook->name);
			__battery_hook_unregister(hook, 0);
			return;
		}
	}
	pr_info("new extension: %s\n", hook->name);
	mutex_unlock(&hook_mutex);
}
EXPORT_SYMBOL_GPL(battery_hook_register);

/*
 * This function gets called right after the battery sysfs
 * attributes have been added, so that the drivers that
 * define custom sysfs attributes can add their own.
*/
static void battery_hook_add_battery(struct acpi_battery *battery)
{
	struct acpi_battery_hook *hook_node;

	mutex_lock(&hook_mutex);
	INIT_LIST_HEAD(&battery->list);
	list_add(&battery->list, &acpi_battery_list);
	/*
	 * Since we added a new battery to the list, we need to
	 * iterate over the hooks and call add_battery for each
	 * hook that was registered. This usually happens
	 * when a battery gets hotplugged or initialized
	 * during the battery module initialization.
	 */
	list_for_each_entry(hook_node, &battery_hook_list, list) {
		if (hook_node->add_battery(battery->bat)) {
			/*
			 * The notification of the extensions has failed, to
			 * prevent further errors we will unload the extension.
			 */
			__battery_hook_unregister(hook_node, 0);
			pr_err("error in extension, unloading: %s",
					hook_node->name);
		}
	}
	mutex_unlock(&hook_mutex);
}

static void battery_hook_remove_battery(struct acpi_battery *battery)
{
	struct acpi_battery_hook *hook;

	mutex_lock(&hook_mutex);
	/*
	 * Before removing the hook, we need to remove all
	 * custom attributes from the battery.
	 */
	list_for_each_entry(hook, &battery_hook_list, list) {
		hook->remove_battery(battery->bat);
	}
	/* Then, just remove the battery from the list */
	list_del(&battery->list);
	mutex_unlock(&hook_mutex);
}

static void __exit battery_hook_exit(void)
{
	struct acpi_battery_hook *hook;
	struct acpi_battery_hook *ptr;
	/*
	 * At this point, the acpi_bus_unregister_driver()
	 * has called remove for all batteries. We just
	 * need to remove the hooks.
	 */
	list_for_each_entry_safe(hook, ptr, &battery_hook_list, list) {
		__battery_hook_unregister(hook, 1);
	}
	mutex_destroy(&hook_mutex);
}

static int sysfs_add_battery(struct acpi_battery *battery)
static int sysfs_add_battery(struct acpi_battery *battery)
{
{
	struct power_supply_config psy_cfg = { .drv_data = battery, };
	struct power_supply_config psy_cfg = { .drv_data = battery, };
@@ -653,6 +809,7 @@ static int sysfs_add_battery(struct acpi_battery *battery)
		battery->bat = NULL;
		battery->bat = NULL;
		return result;
		return result;
	}
	}
	battery_hook_add_battery(battery);
	return device_create_file(&battery->bat->dev, &alarm_attr);
	return device_create_file(&battery->bat->dev, &alarm_attr);
}
}


@@ -663,7 +820,7 @@ static void sysfs_remove_battery(struct acpi_battery *battery)
		mutex_unlock(&battery->sysfs_lock);
		mutex_unlock(&battery->sysfs_lock);
		return;
		return;
	}
	}

	battery_hook_remove_battery(battery);
	device_remove_file(&battery->bat->dev, &alarm_attr);
	device_remove_file(&battery->bat->dev, &alarm_attr);
	power_supply_unregister(battery->bat);
	power_supply_unregister(battery->bat);
	battery->bat = NULL;
	battery->bat = NULL;
@@ -739,6 +896,15 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
			}
			}
		}
		}
	}
	}

	if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags))
		return;

	if (acpi_battery_is_degraded(battery) &&
	    battery->capacity_now > battery->full_charge_capacity) {
		set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags);
		battery->capacity_now = battery->full_charge_capacity;
	}
}
}


static int acpi_battery_update(struct acpi_battery *battery, bool resume)
static int acpi_battery_update(struct acpi_battery *battery, bool resume)
@@ -1357,8 +1523,10 @@ static int __init acpi_battery_init(void)
static void __exit acpi_battery_exit(void)
static void __exit acpi_battery_exit(void)
{
{
	async_synchronize_cookie(async_cookie + 1);
	async_synchronize_cookie(async_cookie + 1);
	if (battery_driver_registered)
	if (battery_driver_registered) {
		acpi_bus_unregister_driver(&acpi_battery_driver);
		acpi_bus_unregister_driver(&acpi_battery_driver);
		battery_hook_exit();
	}
#ifdef CONFIG_ACPI_PROCFS_POWER
#ifdef CONFIG_ACPI_PROCFS_POWER
	if (acpi_battery_dir)
	if (acpi_battery_dir)
		acpi_unlock_battery_dir(acpi_battery_dir);
		acpi_unlock_battery_dir(acpi_battery_dir);
+1 −9
Original line number Original line Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
/*
 * TI TPS68470 PMIC operation region driver
 * TI TPS68470 PMIC operation region driver
 *
 *
@@ -5,15 +6,6 @@
 *
 *
 * Author: Rajmohan Mani <rajmohan.mani@intel.com>
 * Author: Rajmohan Mani <rajmohan.mani@intel.com>
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 as published by the Free Software Foundation.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Based on drivers/acpi/pmic/intel_pmic* drivers
 * Based on drivers/acpi/pmic/intel_pmic* drivers
 */
 */


+1 −1
Original line number Original line Diff line number Diff line
@@ -32,9 +32,9 @@
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/power_supply.h>
#include <linux/power_supply.h>
#include <linux/platform_data/x86/apple.h>
#include <linux/platform_data/x86/apple.h>
#include <acpi/battery.h>


#include "sbshc.h"
#include "sbshc.h"
#include "battery.h"


#define PREFIX "ACPI: "
#define PREFIX "ACPI: "


Loading