linux/drivers/power/supply/power_supply_core.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 *  Universal power supply monitor class
 *
 *  Copyright © 2007  Anton Vorontsov <[email protected]>
 *  Copyright © 2004  Szabolcs Gyurko
 *  Copyright © 2003  Ian Molton <[email protected]>
 *
 *  Modified: 2004, Oct     Szabolcs Gyurko
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/notifier.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/power_supply.h>
#include <linux/property.h>
#include <linux/thermal.h>
#include <linux/fixp-arith.h>
#include "power_supply.h"
#include "samsung-sdi-battery.h"

static const struct class power_supply_class =;

static BLOCKING_NOTIFIER_HEAD(power_supply_notifier);

static const struct device_type power_supply_dev_type =;

#define POWER_SUPPLY_DEFERRED_REGISTER_TIME

static bool __power_supply_is_supplied_by(struct power_supply *supplier,
					 struct power_supply *supply)
{}

static int __power_supply_changed_work(struct device *dev, void *data)
{}

static void power_supply_changed_work(struct work_struct *work)
{}

int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void *data))
{}
EXPORT_SYMBOL_GPL();

void power_supply_changed(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

/*
 * Notify that power supply was registered after parent finished the probing.
 *
 * Often power supply is registered from driver's probe function. However
 * calling power_supply_changed() directly from power_supply_register()
 * would lead to execution of get_property() function provided by the driver
 * too early - before the probe ends.
 *
 * Avoid that by waiting on parent's mutex.
 */
static void power_supply_deferred_register_work(struct work_struct *work)
{}

#ifdef CONFIG_OF
static int __power_supply_populate_supplied_from(struct device *dev,
						 void *data)
{}

static int power_supply_populate_supplied_from(struct power_supply *psy)
{}

static int  __power_supply_find_supply_from_node(struct device *dev,
						 void *data)
{}

static int power_supply_find_supply_from_node(struct device_node *supply_node)
{}

static int power_supply_check_supplies(struct power_supply *psy)
{}
#else
static int power_supply_check_supplies(struct power_supply *psy)
{
	int nval, ret;

	if (!psy->dev.parent)
		return 0;

	nval = device_property_string_array_count(psy->dev.parent, "supplied-from");
	if (nval <= 0)
		return 0;

	psy->supplied_from = devm_kmalloc_array(&psy->dev, nval,
						sizeof(char *), GFP_KERNEL);
	if (!psy->supplied_from)
		return -ENOMEM;

	ret = device_property_read_string_array(psy->dev.parent,
		"supplied-from", (const char **)psy->supplied_from, nval);
	if (ret < 0)
		return ret;

	psy->num_supplies = nval;

	return 0;
}
#endif

struct psy_am_i_supplied_data {};

static int __power_supply_am_i_supplied(struct device *dev, void *_data)
{}

int power_supply_am_i_supplied(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

static int __power_supply_is_system_supplied(struct device *dev, void *data)
{}

int power_supply_is_system_supplied(void)
{}
EXPORT_SYMBOL_GPL();

struct psy_get_supplier_prop_data {};

static int __power_supply_get_supplier_property(struct device *dev, void *_data)
{}

int power_supply_get_property_from_supplier(struct power_supply *psy,
					    enum power_supply_property psp,
					    union power_supply_propval *val)
{}
EXPORT_SYMBOL_GPL();

int power_supply_set_battery_charged(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

static int power_supply_match_device_by_name(struct device *dev, const void *data)
{}

/**
 * power_supply_get_by_name() - Search for a power supply and returns its ref
 * @name: Power supply name to fetch
 *
 * If power supply was found, it increases reference count for the
 * internal power supply's device. The user should power_supply_put()
 * after usage.
 *
 * Return: On success returns a reference to a power supply with
 * matching name equals to @name, a NULL otherwise.
 */
struct power_supply *power_supply_get_by_name(const char *name)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_put() - Drop reference obtained with power_supply_get_by_name
 * @psy: Reference to put
 *
 * The reference to power supply should be put before unregistering
 * the power supply.
 */
void power_supply_put(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

#ifdef CONFIG_OF
static int power_supply_match_device_node(struct device *dev, const void *data)
{}

/**
 * power_supply_get_by_phandle() - Search for a power supply and returns its ref
 * @np: Pointer to device node holding phandle property
 * @property: Name of property holding a power supply name
 *
 * If power supply was found, it increases reference count for the
 * internal power supply's device. The user should power_supply_put()
 * after usage.
 *
 * Return: On success returns a reference to a power supply with
 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
 */
struct power_supply *power_supply_get_by_phandle(struct device_node *np,
							const char *property)
{}
EXPORT_SYMBOL_GPL();

static void devm_power_supply_put(struct device *dev, void *res)
{}

/**
 * devm_power_supply_get_by_phandle() - Resource managed version of
 *  power_supply_get_by_phandle()
 * @dev: Pointer to device holding phandle property
 * @property: Name of property holding a power supply phandle
 *
 * Return: On success returns a reference to a power supply with
 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
 */
struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
						      const char *property)
{}
EXPORT_SYMBOL_GPL();
#endif /* CONFIG_OF */

int power_supply_get_battery_info(struct power_supply *psy,
				  struct power_supply_battery_info **info_out)
{}
EXPORT_SYMBOL_GPL();

void power_supply_put_battery_info(struct power_supply *psy,
				   struct power_supply_battery_info *info)
{}
EXPORT_SYMBOL_GPL();

const enum power_supply_property power_supply_battery_info_properties[] =;
EXPORT_SYMBOL_GPL();

const size_t power_supply_battery_info_properties_size =;
EXPORT_SYMBOL_GPL();

bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info,
					enum power_supply_property psp)
{}
EXPORT_SYMBOL_GPL();

int power_supply_battery_info_get_prop(struct power_supply_battery_info *info,
				       enum power_supply_property psp,
				       union power_supply_propval *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_temp2resist_simple() - find the battery internal resistance
 * percent from temperature
 * @table: Pointer to battery resistance temperature table
 * @table_len: The table length
 * @temp: Current temperature
 *
 * This helper function is used to look up battery internal resistance percent
 * according to current temperature value from the resistance temperature table,
 * and the table must be ordered descending. Then the actual battery internal
 * resistance = the ideal battery internal resistance * percent / 100.
 *
 * Return: the battery internal resistance percent
 */
int power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
				    int table_len, int temp)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_vbat2ri() - find the battery internal resistance
 * from the battery voltage
 * @info: The battery information container
 * @vbat_uv: The battery voltage in microvolt
 * @charging: If we are charging (true) or not (false)
 *
 * This helper function is used to look up battery internal resistance
 * according to current battery voltage. Depending on whether the battery
 * is currently charging or not, different resistance will be returned.
 *
 * Returns the internal resistance in microohm or negative error code.
 */
int power_supply_vbat2ri(struct power_supply_battery_info *info,
			 int vbat_uv, bool charging)
{}
EXPORT_SYMBOL_GPL();

const struct power_supply_maintenance_charge_table *
power_supply_get_maintenance_charging_setting(struct power_supply_battery_info *info,
					      int index)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_ocv2cap_simple() - find the battery capacity
 * @table: Pointer to battery OCV lookup table
 * @table_len: OCV table length
 * @ocv: Current OCV value
 *
 * This helper function is used to look up battery capacity according to
 * current OCV value from one OCV table, and the OCV table must be ordered
 * descending.
 *
 * Return: the battery capacity.
 */
int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
				int table_len, int ocv)
{}
EXPORT_SYMBOL_GPL();

struct power_supply_battery_ocv_table *
power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
				int temp, int *table_len)
{}
EXPORT_SYMBOL_GPL();

int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
				 int ocv, int temp)
{}
EXPORT_SYMBOL_GPL();

bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
				       int resistance)
{}
EXPORT_SYMBOL_GPL();

static bool psy_has_property(const struct power_supply_desc *psy_desc,
			     enum power_supply_property psp)
{}

int power_supply_get_property(struct power_supply *psy,
			    enum power_supply_property psp,
			    union power_supply_propval *val)
{}
EXPORT_SYMBOL_GPL();

int power_supply_set_property(struct power_supply *psy,
			    enum power_supply_property psp,
			    const union power_supply_propval *val)
{}
EXPORT_SYMBOL_GPL();

int power_supply_property_is_writeable(struct power_supply *psy,
					enum power_supply_property psp)
{}
EXPORT_SYMBOL_GPL();

void power_supply_external_power_changed(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

int power_supply_powers(struct power_supply *psy, struct device *dev)
{}
EXPORT_SYMBOL_GPL();

static void power_supply_dev_release(struct device *dev)
{}

int power_supply_reg_notifier(struct notifier_block *nb)
{}
EXPORT_SYMBOL_GPL();

void power_supply_unreg_notifier(struct notifier_block *nb)
{}
EXPORT_SYMBOL_GPL();

#ifdef CONFIG_THERMAL
static int power_supply_read_temp(struct thermal_zone_device *tzd,
		int *temp)
{}

static struct thermal_zone_device_ops psy_tzd_ops =;

static int psy_register_thermal(struct power_supply *psy)
{}

static void psy_unregister_thermal(struct power_supply *psy)
{}

#else
static int psy_register_thermal(struct power_supply *psy)
{
	return 0;
}

static void psy_unregister_thermal(struct power_supply *psy)
{
}
#endif

static struct power_supply *__must_check
__power_supply_register(struct device *parent,
				   const struct power_supply_desc *desc,
				   const struct power_supply_config *cfg,
				   bool ws)
{}

/**
 * power_supply_register() - Register new power supply
 * @parent:	Device to be a parent of power supply's device, usually
 *		the device which probe function calls this
 * @desc:	Description of power supply, must be valid through whole
 *		lifetime of this power supply
 * @cfg:	Run-time specific configuration accessed during registering,
 *		may be NULL
 *
 * Return: A pointer to newly allocated power_supply on success
 * or ERR_PTR otherwise.
 * Use power_supply_unregister() on returned power_supply pointer to release
 * resources.
 */
struct power_supply *__must_check power_supply_register(struct device *parent,
		const struct power_supply_desc *desc,
		const struct power_supply_config *cfg)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_register_no_ws() - Register new non-waking-source power supply
 * @parent:	Device to be a parent of power supply's device, usually
 *		the device which probe function calls this
 * @desc:	Description of power supply, must be valid through whole
 *		lifetime of this power supply
 * @cfg:	Run-time specific configuration accessed during registering,
 *		may be NULL
 *
 * Return: A pointer to newly allocated power_supply on success
 * or ERR_PTR otherwise.
 * Use power_supply_unregister() on returned power_supply pointer to release
 * resources.
 */
struct power_supply *__must_check
power_supply_register_no_ws(struct device *parent,
		const struct power_supply_desc *desc,
		const struct power_supply_config *cfg)
{}
EXPORT_SYMBOL_GPL();

static void devm_power_supply_release(struct device *dev, void *res)
{}

/**
 * devm_power_supply_register() - Register managed power supply
 * @parent:	Device to be a parent of power supply's device, usually
 *		the device which probe function calls this
 * @desc:	Description of power supply, must be valid through whole
 *		lifetime of this power supply
 * @cfg:	Run-time specific configuration accessed during registering,
 *		may be NULL
 *
 * Return: A pointer to newly allocated power_supply on success
 * or ERR_PTR otherwise.
 * The returned power_supply pointer will be automatically unregistered
 * on driver detach.
 */
struct power_supply *__must_check
devm_power_supply_register(struct device *parent,
		const struct power_supply_desc *desc,
		const struct power_supply_config *cfg)
{}
EXPORT_SYMBOL_GPL();

/**
 * devm_power_supply_register_no_ws() - Register managed non-waking-source power supply
 * @parent:	Device to be a parent of power supply's device, usually
 *		the device which probe function calls this
 * @desc:	Description of power supply, must be valid through whole
 *		lifetime of this power supply
 * @cfg:	Run-time specific configuration accessed during registering,
 *		may be NULL
 *
 * Return: A pointer to newly allocated power_supply on success
 * or ERR_PTR otherwise.
 * The returned power_supply pointer will be automatically unregistered
 * on driver detach.
 */
struct power_supply *__must_check
devm_power_supply_register_no_ws(struct device *parent,
		const struct power_supply_desc *desc,
		const struct power_supply_config *cfg)
{}
EXPORT_SYMBOL_GPL();

/**
 * power_supply_unregister() - Remove this power supply from system
 * @psy:	Pointer to power supply to unregister
 *
 * Remove this power supply from the system. The resources of power supply
 * will be freed here or on last power_supply_put() call.
 */
void power_supply_unregister(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

void *power_supply_get_drvdata(struct power_supply *psy)
{}
EXPORT_SYMBOL_GPL();

static int __init power_supply_class_init(void)
{}

static void __exit power_supply_class_exit(void)
{}

subsys_initcall(power_supply_class_init);
module_exit(power_supply_class_exit);

MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_AUTHOR();