Release 4.7 drivers/power/power_supply_core.c
/*
* Universal power supply monitor class
*
* Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
* Copyright © 2004 Szabolcs Gyurko
* Copyright © 2003 Ian Molton <spyro@f2s.com>
*
* Modified: 2004, Oct Szabolcs Gyurko
*
* You may use this code as per GPL version 2
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/notifier.h>
#include <linux/err.h>
#include <linux/power_supply.h>
#include <linux/thermal.h>
#include "power_supply.h"
/* exported for the APM Power driver, APM emulation */
struct class *power_supply_class;
EXPORT_SYMBOL_GPL(power_supply_class);
ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
EXPORT_SYMBOL_GPL(power_supply_notifier);
static struct device_type power_supply_dev_type;
#define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
static bool __power_supply_is_supplied_by(struct power_supply *supplier,
struct power_supply *supply)
{
int i;
if (!supply->supplied_from && !supplier->supplied_to)
return false;
/* Support both supplied_to and supplied_from modes */
if (supply->supplied_from) {
if (!supplier->desc->name)
return false;
for (i = 0; i < supply->num_supplies; i++)
if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
return true;
} else {
if (!supply->desc->name)
return false;
for (i = 0; i < supplier->num_supplicants; i++)
if (!strcmp(supplier->supplied_to[i], supply->desc->name))
return true;
}
return false;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 139 | 94.56% | 1 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 8 | 5.44% | 1 | 50.00% |
| Total | 147 | 100.00% | 2 | 100.00% |
static int __power_supply_changed_work(struct device *dev, void *data)
{
struct power_supply *psy = data;
struct power_supply *pst = dev_get_drvdata(dev);
if (__power_supply_is_supplied_by(psy, pst)) {
if (pst->desc->external_power_changed)
pst->desc->external_power_changed(pst);
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 37 | 58.73% | 1 | 25.00% |
dave young | dave young | 21 | 33.33% | 1 | 25.00% |
krzysztof kozlowski | krzysztof kozlowski | 4 | 6.35% | 1 | 25.00% |
rhyland klein | rhyland klein | 1 | 1.59% | 1 | 25.00% |
| Total | 63 | 100.00% | 4 | 100.00% |
static void power_supply_changed_work(struct work_struct *work)
{
unsigned long flags;
struct power_supply *psy = container_of(work, struct power_supply,
changed_work);
dev_dbg(&psy->dev, "%s\n", __func__);
spin_lock_irqsave(&psy->changed_lock, flags);
/*
* Check 'changed' here to avoid issues due to race between
* power_supply_changed() and this routine. In worst case
* power_supply_changed() can be called again just before we take above
* lock. During the first call of this routine we will mark 'changed' as
* false and it will stay false for the next call as well.
*/
if (likely(psy->changed)) {
psy->changed = false;
spin_unlock_irqrestore(&psy->changed_lock, flags);
class_for_each_device(power_supply_class, NULL, psy,
__power_supply_changed_work);
power_supply_update_leds(psy);
atomic_notifier_call_chain(&power_supply_notifier,
PSY_EVENT_PROP_CHANGED, psy);
kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
spin_lock_irqsave(&psy->changed_lock, flags);
}
/*
* Hold the wakeup_source until all events are processed.
* power_supply_changed() might have called again and have set 'changed'
* to true.
*/
if (likely(!psy->changed))
pm_relax(&psy->dev);
spin_unlock_irqrestore(&psy->changed_lock, flags);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
zoran markovic | zoran markovic | 72 | 45.86% | 1 | 12.50% |
dave young | dave young | 40 | 25.48% | 1 | 12.50% |
anton vorontsov | anton vorontsov | 21 | 13.38% | 1 | 12.50% |
pali rohar | pali rohar | 10 | 6.37% | 1 | 12.50% |
viresh kumar | viresh kumar | 8 | 5.10% | 1 | 12.50% |
krzysztof kozlowski | krzysztof kozlowski | 3 | 1.91% | 1 | 12.50% |
greg kroah-hartman | greg kroah-hartman | 2 | 1.27% | 1 | 12.50% |
harvey harrison | harvey harrison | 1 | 0.64% | 1 | 12.50% |
| Total | 157 | 100.00% | 8 | 100.00% |
void power_supply_changed(struct power_supply *psy)
{
unsigned long flags;
dev_dbg(&psy->dev, "%s\n", __func__);
spin_lock_irqsave(&psy->changed_lock, flags);
psy->changed = true;
pm_stay_awake(&psy->dev);
spin_unlock_irqrestore(&psy->changed_lock, flags);
schedule_work(&psy->changed_work);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
zoran markovic | zoran markovic | 37 | 54.41% | 1 | 25.00% |
anton vorontsov | anton vorontsov | 28 | 41.18% | 1 | 25.00% |
krzysztof kozlowski | krzysztof kozlowski | 2 | 2.94% | 1 | 25.00% |
harvey harrison | harvey harrison | 1 | 1.47% | 1 | 25.00% |
| Total | 68 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_changed);
/*
* 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)
{
struct power_supply *psy = container_of(work, struct power_supply,
deferred_register_work.work);
if (psy->dev.parent)
mutex_lock(&psy->dev.parent->mutex);
power_supply_changed(psy);
if (psy->dev.parent)
mutex_unlock(&psy->dev.parent->mutex);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 73 | 100.00% | 1 | 100.00% |
| Total | 73 | 100.00% | 1 | 100.00% |
#ifdef CONFIG_OF
#include <linux/of.h>
static int __power_supply_populate_supplied_from(struct device *dev,
void *data)
{
struct power_supply *psy = data;
struct power_supply *epsy = dev_get_drvdata(dev);
struct device_node *np;
int i = 0;
do {
np = of_parse_phandle(psy->of_node, "power-supplies", i++);
if (!np)
break;
if (np == epsy->of_node) {
dev_info(&psy->dev, "%s: Found supply : %s\n",
psy->desc->name, epsy->desc->name);
psy->supplied_from[i-1] = (char *)epsy->desc->name;
psy->num_supplies++;
of_node_put(np);
break;
}
of_node_put(np);
} while (np);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 132 | 94.29% | 2 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 7 | 5.00% | 1 | 25.00% |
viresh kumar | viresh kumar | 1 | 0.71% | 1 | 25.00% |
| Total | 140 | 100.00% | 4 | 100.00% |
static int power_supply_populate_supplied_from(struct power_supply *psy)
{
int error;
error = class_for_each_device(power_supply_class, NULL, psy,
__power_supply_populate_supplied_from);
dev_dbg(&psy->dev, "%s %d\n", __func__, error);
return error;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 43 | 97.73% | 1 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 1 | 2.27% | 1 | 50.00% |
| Total | 44 | 100.00% | 2 | 100.00% |
static int __power_supply_find_supply_from_node(struct device *dev,
void *data)
{
struct device_node *np = data;
struct power_supply *epsy = dev_get_drvdata(dev);
/* returning non-zero breaks out of class_for_each_device loop */
if (epsy->of_node == np)
return 1;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 45 | 95.74% | 1 | 50.00% |
viresh kumar | viresh kumar | 2 | 4.26% | 1 | 50.00% |
| Total | 47 | 100.00% | 2 | 100.00% |
static int power_supply_find_supply_from_node(struct device_node *supply_node)
{
int error;
/*
* class_for_each_device() either returns its own errors or values
* returned by __power_supply_find_supply_from_node().
*
* __power_supply_find_supply_from_node() will return 0 (no match)
* or 1 (match).
*
* We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
* it returned 0, or error as returned by it.
*/
error = class_for_each_device(power_supply_class, NULL, supply_node,
__power_supply_find_supply_from_node);
return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 35 | 79.55% | 1 | 50.00% |
viresh kumar | viresh kumar | 9 | 20.45% | 1 | 50.00% |
| Total | 44 | 100.00% | 2 | 100.00% |
static int power_supply_check_supplies(struct power_supply *psy)
{
struct device_node *np;
int cnt = 0;
/* If there is already a list honor it */
if (psy->supplied_from && psy->num_supplies > 0)
return 0;
/* No device node found, nothing to do */
if (!psy->of_node)
return 0;
do {
int ret;
np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
if (!np)
break;
ret = power_supply_find_supply_from_node(np);
of_node_put(np);
if (ret) {
dev_dbg(&psy->dev, "Failed to find supply!\n");
return ret;
}
} while (np);
/* Missing valid "power-supplies" entries */
if (cnt == 1)
return 0;
/* All supplies found, allocate char ** array for filling */
psy->supplied_from = devm_kzalloc(&psy->dev, sizeof(psy->supplied_from),
GFP_KERNEL);
if (!psy->supplied_from) {
dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
return -ENOMEM;
}
*psy->supplied_from = devm_kzalloc(&psy->dev,
sizeof(char *) * (cnt - 1),
GFP_KERNEL);
if (!*psy->supplied_from) {
dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
return -ENOMEM;
}
return power_supply_populate_supplied_from(psy);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 195 | 87.84% | 1 | 14.29% |
viresh kumar | viresh kumar | 22 | 9.91% | 5 | 71.43% |
krzysztof kozlowski | krzysztof kozlowski | 5 | 2.25% | 1 | 14.29% |
| Total | 222 | 100.00% | 7 | 100.00% |
#else
static inline int power_supply_check_supplies(struct power_supply *psy)
{
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rhyland klein | rhyland klein | 15 | 100.00% | 1 | 100.00% |
| Total | 15 | 100.00% | 1 | 100.00% |
#endif
static int __power_supply_am_i_supplied(struct device *dev, void *data)
{
union power_supply_propval ret = {0,};
struct power_supply *psy = data;
struct power_supply *epsy = dev_get_drvdata(dev);
if (__power_supply_is_supplied_by(epsy, psy))
if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
&ret))
return ret.intval;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 50 | 67.57% | 1 | 25.00% |
dave young | dave young | 20 | 27.03% | 1 | 25.00% |
rhyland klein | rhyland klein | 2 | 2.70% | 1 | 25.00% |
krzysztof kozlowski | krzysztof kozlowski | 2 | 2.70% | 1 | 25.00% |
| Total | 74 | 100.00% | 4 | 100.00% |
int power_supply_am_i_supplied(struct power_supply *psy)
{
int error;
error = class_for_each_device(power_supply_class, NULL, psy,
__power_supply_am_i_supplied);
dev_dbg(&psy->dev, "%s %d\n", __func__, error);
return error;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
dave young | dave young | 21 | 48.84% | 1 | 20.00% |
anton vorontsov | anton vorontsov | 18 | 41.86% | 1 | 20.00% |
greg kroah-hartman | greg kroah-hartman | 2 | 4.65% | 1 | 20.00% |
krzysztof kozlowski | krzysztof kozlowski | 1 | 2.33% | 1 | 20.00% |
harvey harrison | harvey harrison | 1 | 2.33% | 1 | 20.00% |
| Total | 43 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
static int __power_supply_is_system_supplied(struct device *dev, void *data)
{
union power_supply_propval ret = {0,};
struct power_supply *psy = dev_get_drvdata(dev);
unsigned int *count = data;
(*count)++;
if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
&ret))
return ret.intval;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew garrett | matthew garrett | 63 | 77.78% | 1 | 25.00% |
jean delvare | jean delvare | 13 | 16.05% | 1 | 25.00% |
krzysztof kozlowski | krzysztof kozlowski | 4 | 4.94% | 1 | 25.00% |
viresh kumar | viresh kumar | 1 | 1.23% | 1 | 25.00% |
| Total | 81 | 100.00% | 4 | 100.00% |
int power_supply_is_system_supplied(void)
{
int error;
unsigned int count = 0;
error = class_for_each_device(power_supply_class, NULL, &count,
__power_supply_is_system_supplied);
/*
* If no power class device was found at all, most probably we are
* running on a desktop system, so assume we are on mains power.
*/
if (count == 0)
return 1;
return error;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew garrett | matthew garrett | 25 | 58.14% | 1 | 50.00% |
jean delvare | jean delvare | 18 | 41.86% | 1 | 50.00% |
| Total | 43 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
int power_supply_set_battery_charged(struct power_supply *psy)
{
if (atomic_read(&psy->use_cnt) >= 0 &&
psy->desc->type == POWER_SUPPLY_TYPE_BATTERY &&
psy->desc->set_charged) {
psy->desc->set_charged(psy);
return 0;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
daniel mack | daniel mack | 38 | 70.37% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 16 | 29.63% | 2 | 66.67% |
| Total | 54 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
static int power_supply_match_device_by_name(struct device *dev, const void *data)
{
const char *name = data;
struct power_supply *psy = dev_get_drvdata(dev);
return strcmp(psy->desc->name, name) == 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
daniel mack | daniel mack | 44 | 93.62% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 2 | 4.26% | 1 | 33.33% |
michal miroslaw | michal miroslaw | 1 | 2.13% | 1 | 33.33% |
| Total | 47 | 100.00% | 3 | 100.00% |
/**
* 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)
{
struct power_supply *psy = NULL;
struct device *dev = class_find_device(power_supply_class, NULL, name,
power_supply_match_device_by_name);
if (dev) {
psy = dev_get_drvdata(dev);
atomic_inc(&psy->use_cnt);
}
return psy;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
daniel mack | daniel mack | 33 | 55.93% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 25 | 42.37% | 1 | 33.33% |
michal miroslaw | michal miroslaw | 1 | 1.69% | 1 | 33.33% |
| Total | 59 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_get_by_name);
/**
* 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)
{
might_sleep();
atomic_dec(&psy->use_cnt);
put_device(&psy->dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 29 | 100.00% | 2 | 100.00% |
| Total | 29 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_put);
#ifdef CONFIG_OF
static int power_supply_match_device_node(struct device *dev, const void *data)
{
return dev->parent && dev->parent->of_node == data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian reichel | sebastian reichel | 29 | 100.00% | 1 | 100.00% |
| Total | 29 | 100.00% | 1 | 100.00% |
/**
* power_supply_get_by_phandle() - Search for a power supply and returns its ref
* @np: Pointer to device node holding phandle property
* @phandle_name: 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)
{
struct device_node *power_supply_np;
struct power_supply *psy = NULL;
struct device *dev;
power_supply_np = of_parse_phandle(np, property, 0);
if (!power_supply_np)
return ERR_PTR(-ENODEV);
dev = class_find_device(power_supply_class, NULL, power_supply_np,
power_supply_match_device_node);
of_node_put(power_supply_np);
if (dev) {
psy = dev_get_drvdata(dev);
atomic_inc(&psy->use_cnt);
}
return psy;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian reichel | sebastian reichel | 74 | 74.75% | 1 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 25 | 25.25% | 1 | 50.00% |
| Total | 99 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
static void devm_power_supply_put(struct device *dev, void *res)
{
struct power_supply **psy = res;
power_supply_put(*psy);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans de goede | hans de goede | 29 | 100.00% | 1 | 100.00% |
| Total | 29 | 100.00% | 1 | 100.00% |
/**
* devm_power_supply_get_by_phandle() - Resource managed version of
* power_supply_get_by_phandle()
* @dev: Pointer to device holding phandle property
* @phandle_name: 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)
{
struct power_supply **ptr, *psy;
if (!dev->of_node)
return ERR_PTR(-ENODEV);
ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
psy = power_supply_get_by_phandle(dev->of_node, property);
if (IS_ERR_OR_NULL(psy)) {
devres_free(ptr);
} else {
*ptr = psy;
devres_add(dev, ptr);
}
return psy;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans de goede | hans de goede | 110 | 100.00% | 1 | 100.00% |
| Total | 110 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
#endif /* CONFIG_OF */
int power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
if (atomic_read(&psy->use_cnt) <= 0)
return -ENODEV;
return psy->desc->get_property(psy, psp, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 49 | 100.00% | 2 | 100.00% |
| Total | 49 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_get_property);
int power_supply_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
if (atomic_read(&psy->use_cnt) <= 0 || !psy->desc->set_property)
return -ENODEV;
return psy->desc->set_property(psy, psp, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 57 | 100.00% | 2 | 100.00% |
| Total | 57 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_set_property);
int power_supply_property_is_writeable(struct power_supply *psy,
enum power_supply_property psp)
{
if (atomic_read(&psy->use_cnt) <= 0 ||
!psy->desc->property_is_writeable)
return -ENODEV;
return psy->desc->property_is_writeable(psy, psp);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 49 | 100.00% | 2 | 100.00% |
| Total | 49 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
void power_supply_external_power_changed(struct power_supply *psy)
{
if (atomic_read(&psy->use_cnt) <= 0 ||
!psy->desc->external_power_changed)
return;
psy->desc->external_power_changed(psy);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 39 | 100.00% | 2 | 100.00% |
| Total | 39 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
int power_supply_powers(struct power_supply *psy, struct device *dev)
{
return sysfs_create_link(&psy->dev.kobj, &dev->kobj, "powers");
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jeremy fitzhardinge | jeremy fitzhardinge | 31 | 93.94% | 1 | 33.33% |
anton vorontsov | anton vorontsov | 1 | 3.03% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 1 | 3.03% | 1 | 33.33% |
| Total | 33 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_powers);
static void power_supply_dev_release(struct device *dev)
{
struct power_supply *psy = container_of(dev, struct power_supply, dev);
pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
kfree(psy);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 27 | 62.79% | 1 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 16 | 37.21% | 1 | 50.00% |
| Total | 43 | 100.00% | 2 | 100.00% |
int power_supply_reg_notifier(struct notifier_block *nb)
{
return atomic_notifier_chain_register(&power_supply_notifier, nb);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pali rohar | pali rohar | 19 | 100.00% | 1 | 100.00% |
| Total | 19 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
void power_supply_unreg_notifier(struct notifier_block *nb)
{
atomic_notifier_chain_unregister(&power_supply_notifier, nb);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pali rohar | pali rohar | 18 | 100.00% | 1 | 100.00% |
| Total | 18 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
#ifdef CONFIG_THERMAL
static int power_supply_read_temp(struct thermal_zone_device *tzd,
int *temp)
{
struct power_supply *psy;
union power_supply_propval val;
int ret;
WARN_ON(tzd == NULL);
psy = tzd->devdata;
ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
if (ret)
return ret;
/* Convert tenths of degree Celsius to milli degree Celsius. */
*temp = val.intval * 100;
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jenny tc | jenny tc | 66 | 91.67% | 1 | 33.33% |
rhyland klein | rhyland klein | 5 | 6.94% | 1 | 33.33% |
sascha hauer | sascha hauer | 1 | 1.39% | 1 | 33.33% |
| Total | 72 | 100.00% | 3 | 100.00% |
static struct thermal_zone_device_ops psy_tzd_ops = {
.get_temp = power_supply_read_temp,
};
static int psy_register_thermal(struct power_supply *psy)
{
int i;
if (psy->desc->no_thermal)
return 0;
/* Register battery zone device psy reports temperature */
for (i = 0; i < psy->desc->num_properties; i++) {
if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
psy->tzd = thermal_zone_device_register(psy->desc->name,
0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
return PTR_ERR_OR_ZERO(psy->tzd);
}
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jenny tc | jenny tc | 77 | 77.78% | 1 | 16.67% |
krzysztof kozlowski | krzysztof kozlowski | 17 | 17.17% | 2 | 33.33% |
durgadoss r | durgadoss r | 2 | 2.02% | 1 | 16.67% |
anton vorontsov | anton vorontsov | 2 | 2.02% | 1 | 16.67% |
viresh kumar | viresh kumar | 1 | 1.01% | 1 | 16.67% |
| Total | 99 | 100.00% | 6 | 100.00% |
static void psy_unregister_thermal(struct power_supply *psy)
{
if (IS_ERR_OR_NULL(psy->tzd))
return;
thermal_zone_device_unregister(psy->tzd);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jenny tc | jenny tc | 28 | 100.00% | 1 | 100.00% |
| Total | 28 | 100.00% | 1 | 100.00% |
/* thermal cooling device callbacks */
static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
unsigned long *state)
{
struct power_supply *psy;
union power_supply_propval val;
int ret;
psy = tcd->devdata;
ret = power_supply_get_property(psy,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
if (ret)
return ret;
*state = val.intval;
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 59 | 93.65% | 1 | 50.00% |
rhyland klein | rhyland klein | 4 | 6.35% | 1 | 50.00% |
| Total | 63 | 100.00% | 2 | 100.00% |
static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
unsigned long *state)
{
struct power_supply *psy;
union power_supply_propval val;
int ret;
psy = tcd->devdata;
ret = power_supply_get_property(psy,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
if (ret)
return ret;
*state = val.intval;
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 59 | 93.65% | 1 | 50.00% |
rhyland klein | rhyland klein | 4 | 6.35% | 1 | 50.00% |
| Total | 63 | 100.00% | 2 | 100.00% |
static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
unsigned long state)
{
struct power_supply *psy;
union power_supply_propval val;
int ret;
psy = tcd->devdata;
val.intval = state;
ret = psy->desc->set_property(psy,
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 56 | 96.55% | 1 | 50.00% |
krzysztof kozlowski | krzysztof kozlowski | 2 | 3.45% | 1 | 50.00% |
| Total | 58 | 100.00% | 2 | 100.00% |
static struct thermal_cooling_device_ops psy_tcd_ops = {
.get_max_state = ps_get_max_charge_cntl_limit,
.get_cur_state = ps_get_cur_chrage_cntl_limit,
.set_cur_state = ps_set_cur_charge_cntl_limit,
};
static int psy_register_cooler(struct power_supply *psy)
{
int i;
/* Register for cooling device if psy can control charging */
for (i = 0; i < psy->desc->num_properties; i++) {
if (psy->desc->properties[i] ==
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
psy->tcd = thermal_cooling_device_register(
(char *)psy->desc->name,
psy, &psy_tcd_ops);
return PTR_ERR_OR_ZERO(psy->tcd);
}
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 75 | 91.46% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 6 | 7.32% | 1 | 33.33% |
viresh kumar | viresh kumar | 1 | 1.22% | 1 | 33.33% |
| Total | 82 | 100.00% | 3 | 100.00% |
static void psy_unregister_cooler(struct power_supply *psy)
{
if (IS_ERR_OR_NULL(psy->tcd))
return;
thermal_cooling_device_unregister(psy->tcd);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 28 | 100.00% | 1 | 100.00% |
| Total | 28 | 100.00% | 1 | 100.00% |
#else
static int psy_register_thermal(struct power_supply *psy)
{
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jenny tc | jenny tc | 14 | 100.00% | 1 | 100.00% |
| Total | 14 | 100.00% | 1 | 100.00% |
static void psy_unregister_thermal(struct power_supply *psy)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jenny tc | jenny tc | 10 | 100.00% | 1 | 100.00% |
| Total | 10 | 100.00% | 1 | 100.00% |
static int psy_register_cooler(struct power_supply *psy)
{
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 14 | 100.00% | 1 | 100.00% |
| Total | 14 | 100.00% | 1 | 100.00% |
static void psy_unregister_cooler(struct power_supply *psy)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ramakrishna pallala | ramakrishna pallala | 10 | 100.00% | 1 | 100.00% |
| Total | 10 | 100.00% | 1 | 100.00% |
#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)
{
struct device *dev;
struct power_supply *psy;
int rc;
if (!parent)
pr_warn("%s: Expected proper parent device for '%s'\n",
__func__, desc->name);
psy = kzalloc(sizeof(*psy), GFP_KERNEL);
if (!psy)
return ERR_PTR(-ENOMEM);
dev = &psy->dev;
device_initialize(dev);
dev->class = power_supply_class;
dev->type = &power_supply_dev_type;
dev->parent = parent;
dev->release = power_supply_dev_release;
dev_set_drvdata(dev, psy);
psy->desc = desc;
if (cfg) {
psy->drv_data = cfg->drv_data;
psy->of_node = cfg->of_node;
psy->supplied_to = cfg->supplied_to;
psy->num_supplicants = cfg->num_supplicants;
}
rc = dev_set_name(dev, "%s", desc->name);
if (rc)
goto dev_set_name_failed;
INIT_WORK(&psy->changed_work, power_supply_changed_work);
INIT_DELAYED_WORK(&psy->deferred_register_work,
power_supply_deferred_register_work);
rc = power_supply_check_supplies(psy);
if (rc) {
dev_info(dev, "Not all required supplies found, defer probe\n");
goto check_supplies_failed;
}
spin_lock_init(&psy->changed_lock);
rc = device_init_wakeup(dev, ws);
if (rc)
goto wakeup_init_failed;
rc = device_add(dev);
if (rc)
goto device_add_failed;
rc = psy_register_thermal(psy);
if (rc)
goto register_thermal_failed;
rc = psy_register_cooler(psy);
if (rc)
goto register_cooler_failed;
rc = power_supply_create_triggers(psy);
if (rc)
goto create_triggers_failed;
/*
* Update use_cnt after any uevents (most notably from device_add()).
* We are here still during driver's probe but
* the power_supply_uevent() calls back driver's get_property
* method so:
* 1. Driver did not assigned the returned struct power_supply,
* 2. Driver could not finish initialization (anything in its probe
* after calling power_supply_register()).
*/
atomic_inc(&psy->use_cnt);
queue_delayed_work(system_power_efficient_wq,
&psy->deferred_register_work,
POWER_SUPPLY_DEFERRED_REGISTER_TIME);
return psy;
create_triggers_failed:
psy_unregister_cooler(psy);
register_cooler_failed:
psy_unregister_thermal(psy);
register_thermal_failed:
device_del(dev);
device_add_failed:
wakeup_init_failed:
check_supplies_failed:
dev_set_name_failed:
put_device(dev);
return ERR_PTR(rc);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 125 | 33.07% | 2 | 11.76% |
krzysztof kozlowski | krzysztof kozlowski | 119 | 31.48% | 4 | 23.53% |
rhyland klein | rhyland klein | 25 | 6.61% | 1 | 5.88% |
shuah khan | shuah khan | 23 | 6.08% | 1 | 5.88% |
zoran markovic | zoran markovic | 23 | 6.08% | 1 | 5.88% |
ramakrishna pallala | ramakrishna pallala | 21 | 5.56% | 1 | 5.88% |
jenny tc | jenny tc | 21 | 5.56% | 1 | 5.88% |
lars-peter clausen | lars-peter clausen | 10 | 2.65% | 1 | 5.88% |
rui zhang | rui zhang | 5 | 1.32% | 1 | 5.88% |
viresh kumar | viresh kumar | 2 | 0.53% | 1 | 5.88% |
vasiliy kulikov | vasiliy kulikov | 2 | 0.53% | 1 | 5.88% |
wei yongjun | wei yongjun | 1 | 0.26% | 1 | 5.88% |
greg kroah-hartman | greg kroah-hartman | 1 | 0.26% | 1 | 5.88% |
| Total | 378 | 100.00% | 17 | 100.00% |
/**
* 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)
{
return __power_supply_register(parent, desc, cfg, true);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rui zhang | rui zhang | 21 | 56.76% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 16 | 43.24% | 2 | 66.67% |
| Total | 37 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_register);
/**
* 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)
{
return __power_supply_register(parent, desc, cfg, false);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
rui zhang | rui zhang | 21 | 56.76% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 16 | 43.24% | 2 | 66.67% |
| Total | 37 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
static void devm_power_supply_release(struct device *dev, void *res)
{
struct power_supply **psy = res;
power_supply_unregister(*psy);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
neil brown | neil brown | 29 | 100.00% | 1 | 100.00% |
| Total | 29 | 100.00% | 1 | 100.00% |
/**
* 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)
{
struct power_supply **ptr, *psy;
ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
psy = __power_supply_register(parent, desc, cfg, true);
if (IS_ERR(psy)) {
devres_free(ptr);
} else {
*ptr = psy;
devres_add(parent, ptr);
}
return psy;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
neil brown | neil brown | 72 | 67.92% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 34 | 32.08% | 2 | 66.67% |
| Total | 106 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(devm_power_supply_register);
/**
* 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)
{
struct power_supply **ptr, *psy;
ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
psy = __power_supply_register(parent, desc, cfg, false);
if (IS_ERR(psy)) {
devres_free(ptr);
} else {
*ptr = psy;
devres_add(parent, ptr);
}
return psy;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
neil brown | neil brown | 72 | 67.92% | 1 | 33.33% |
krzysztof kozlowski | krzysztof kozlowski | 34 | 32.08% | 2 | 66.67% |
| Total | 106 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
/**
* 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)
{
WARN_ON(atomic_dec_return(&psy->use_cnt));
cancel_work_sync(&psy->changed_work);
cancel_delayed_work_sync(&psy->deferred_register_work);
sysfs_remove_link(&psy->dev.kobj, "powers");
power_supply_remove_triggers(psy);
psy_unregister_cooler(psy);
psy_unregister_thermal(psy);
device_init_wakeup(&psy->dev, false);
device_unregister(&psy->dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 23 | 28.05% | 1 | 11.11% |
krzysztof kozlowski | krzysztof kozlowski | 22 | 26.83% | 3 | 33.33% |
jeremy fitzhardinge | jeremy fitzhardinge | 11 | 13.41% | 1 | 11.11% |
zoran markovic | zoran markovic | 9 | 10.98% | 1 | 11.11% |
tejun heo | tejun heo | 7 | 8.54% | 1 | 11.11% |
jenny tc | jenny tc | 5 | 6.10% | 1 | 11.11% |
ramakrishna pallala | ramakrishna pallala | 5 | 6.10% | 1 | 11.11% |
| Total | 82 | 100.00% | 9 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_unregister);
void *power_supply_get_drvdata(struct power_supply *psy)
{
return psy->drv_data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 16 | 100.00% | 1 | 100.00% |
| Total | 16 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
static int __init power_supply_class_init(void)
{
power_supply_class = class_create(THIS_MODULE, "power_supply");
if (IS_ERR(power_supply_class))
return PTR_ERR(power_supply_class);
power_supply_class->dev_uevent = power_supply_uevent;
power_supply_init_attrs(&power_supply_dev_type);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 46 | 100.00% | 2 | 100.00% |
| Total | 46 | 100.00% | 2 | 100.00% |
static void __exit power_supply_class_exit(void)
{
class_destroy(power_supply_class);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anton vorontsov | anton vorontsov | 14 | 100.00% | 1 | 100.00% |
| Total | 14 | 100.00% | 1 | 100.00% |
subsys_initcall(power_supply_class_init);
module_exit(power_supply_class_exit);
MODULE_DESCRIPTION("Universal power supply monitor class");
MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, "
"Szabolcs Gyurko, "
"Anton Vorontsov <cbou@mail.ru>");
MODULE_LICENSE("GPL");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
krzysztof kozlowski | krzysztof kozlowski | 740 | 20.13% | 9 | 16.98% |
rhyland klein | rhyland klein | 655 | 17.81% | 4 | 7.55% |
anton vorontsov | anton vorontsov | 454 | 12.35% | 4 | 7.55% |
ramakrishna pallala | ramakrishna pallala | 350 | 9.52% | 1 | 1.89% |
jenny tc | jenny tc | 243 | 6.61% | 1 | 1.89% |
neil brown | neil brown | 183 | 4.98% | 1 | 1.89% |
daniel mack | daniel mack | 156 | 4.24% | 2 | 3.77% |
hans de goede | hans de goede | 145 | 3.94% | 1 | 1.89% |
zoran markovic | zoran markovic | 141 | 3.83% | 1 | 1.89% |
sebastian reichel | sebastian reichel | 114 | 3.10% | 1 | 1.89% |
dave young | dave young | 102 | 2.77% | 1 | 1.89% |
matthew garrett | matthew garrett | 88 | 2.39% | 1 | 1.89% |
pali rohar | pali rohar | 70 | 1.90% | 1 | 1.89% |
rui zhang | rui zhang | 52 | 1.41% | 1 | 1.89% |
jeremy fitzhardinge | jeremy fitzhardinge | 47 | 1.28% | 1 | 1.89% |
viresh kumar | viresh kumar | 47 | 1.28% | 10 | 18.87% |
jean delvare | jean delvare | 31 | 0.84% | 1 | 1.89% |
shuah khan | shuah khan | 23 | 0.63% | 1 | 1.89% |
lars-peter clausen | lars-peter clausen | 10 | 0.27% | 1 | 1.89% |
tejun heo | tejun heo | 7 | 0.19% | 1 | 1.89% |
greg kroah-hartman | greg kroah-hartman | 5 | 0.14% | 2 | 3.77% |
harvey harrison | harvey harrison | 3 | 0.08% | 1 | 1.89% |
bjorn andersson | bjorn andersson | 3 | 0.08% | 1 | 1.89% |
michal miroslaw | michal miroslaw | 2 | 0.05% | 1 | 1.89% |
durgadoss r | durgadoss r | 2 | 0.05% | 1 | 1.89% |
vasiliy kulikov | vasiliy kulikov | 2 | 0.05% | 1 | 1.89% |
sascha hauer | sascha hauer | 1 | 0.03% | 1 | 1.89% |
wei yongjun | wei yongjun | 1 | 0.03% | 1 | 1.89% |
| Total | 3677 | 100.00% | 53 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.