mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-29 11:42:36 +00:00
power: supply: core: convert to fwnnode
Replace any DT specific code with fwnode in the power-supply core. Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Hans de Goede <hansg@kernel.org> Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-4-f9643b958677@collabora.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
570ba047a6
commit
f368f87b22
@ -1674,7 +1674,7 @@ static int bq2415x_probe(struct i2c_client *client)
|
|||||||
/* Query for initial reported_mode and set it */
|
/* Query for initial reported_mode and set it */
|
||||||
if (bq->nb.notifier_call) {
|
if (bq->nb.notifier_call) {
|
||||||
if (np) {
|
if (np) {
|
||||||
notify_psy = power_supply_get_by_phandle(np,
|
notify_psy = power_supply_get_by_phandle(of_fwnode_handle(np),
|
||||||
"ti,usb-charger-detection");
|
"ti,usb-charger-detection");
|
||||||
if (IS_ERR(notify_psy))
|
if (IS_ERR(notify_psy))
|
||||||
notify_psy = NULL;
|
notify_psy = NULL;
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/notifier.h>
|
#include <linux/notifier.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/of.h>
|
|
||||||
#include <linux/power_supply.h>
|
#include <linux/power_supply.h>
|
||||||
#include <linux/property.h>
|
#include <linux/property.h>
|
||||||
#include <linux/thermal.h>
|
#include <linux/thermal.h>
|
||||||
@ -196,24 +195,24 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,
|
|||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct power_supply *psy = data;
|
struct power_supply *psy = data;
|
||||||
struct device_node *np;
|
struct fwnode_handle *np;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
np = of_parse_phandle(psy->dev.of_node, "power-supplies", i++);
|
np = fwnode_find_reference(psy->dev.fwnode, "power-supplies", i++);
|
||||||
if (!np)
|
if (IS_ERR(np))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (np == epsy->dev.of_node) {
|
if (np == epsy->dev.fwnode) {
|
||||||
dev_dbg(&psy->dev, "%s: Found supply : %s\n",
|
dev_dbg(&psy->dev, "%s: Found supply : %s\n",
|
||||||
psy->desc->name, epsy->desc->name);
|
psy->desc->name, epsy->desc->name);
|
||||||
psy->supplied_from[i-1] = (char *)epsy->desc->name;
|
psy->supplied_from[i-1] = (char *)epsy->desc->name;
|
||||||
psy->num_supplies++;
|
psy->num_supplies++;
|
||||||
of_node_put(np);
|
fwnode_handle_put(np);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
of_node_put(np);
|
fwnode_handle_put(np);
|
||||||
} while (np);
|
} while (!IS_ERR(np));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -232,16 +231,16 @@ static int power_supply_populate_supplied_from(struct power_supply *psy)
|
|||||||
static int __power_supply_find_supply_from_node(struct power_supply *epsy,
|
static int __power_supply_find_supply_from_node(struct power_supply *epsy,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct device_node *np = data;
|
struct fwnode_handle *fwnode = data;
|
||||||
|
|
||||||
/* returning non-zero breaks out of power_supply_for_each_psy loop */
|
/* returning non-zero breaks out of power_supply_for_each_psy loop */
|
||||||
if (epsy->dev.of_node == np)
|
if (epsy->dev.fwnode == fwnode)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int power_supply_find_supply_from_node(struct device_node *supply_node)
|
static int power_supply_find_supply_from_fwnode(struct fwnode_handle *supply_node)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@ -249,7 +248,7 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
|
|||||||
* power_supply_for_each_psy() either returns its own errors or values
|
* power_supply_for_each_psy() either returns its own errors or values
|
||||||
* returned by __power_supply_find_supply_from_node().
|
* returned by __power_supply_find_supply_from_node().
|
||||||
*
|
*
|
||||||
* __power_supply_find_supply_from_node() will return 0 (no match)
|
* __power_supply_find_supply_from_fwnode() will return 0 (no match)
|
||||||
* or 1 (match).
|
* or 1 (match).
|
||||||
*
|
*
|
||||||
* We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if
|
* We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if
|
||||||
@ -262,7 +261,7 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
|
|||||||
|
|
||||||
static int power_supply_check_supplies(struct power_supply *psy)
|
static int power_supply_check_supplies(struct power_supply *psy)
|
||||||
{
|
{
|
||||||
struct device_node *np;
|
struct fwnode_handle *np;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
/* If there is already a list honor it */
|
/* If there is already a list honor it */
|
||||||
@ -270,24 +269,24 @@ static int power_supply_check_supplies(struct power_supply *psy)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* No device node found, nothing to do */
|
/* No device node found, nothing to do */
|
||||||
if (!psy->dev.of_node)
|
if (!psy->dev.fwnode)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
np = of_parse_phandle(psy->dev.of_node, "power-supplies", cnt++);
|
np = fwnode_find_reference(psy->dev.fwnode, "power-supplies", cnt++);
|
||||||
if (!np)
|
if (IS_ERR(np))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ret = power_supply_find_supply_from_node(np);
|
ret = power_supply_find_supply_from_fwnode(np);
|
||||||
of_node_put(np);
|
fwnode_handle_put(np);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_dbg(&psy->dev, "Failed to find supply!\n");
|
dev_dbg(&psy->dev, "Failed to find supply!\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
} while (np);
|
} while (!IS_ERR(np));
|
||||||
|
|
||||||
/* Missing valid "power-supplies" entries */
|
/* Missing valid "power-supplies" entries */
|
||||||
if (cnt == 1)
|
if (cnt == 1)
|
||||||
@ -498,14 +497,14 @@ void power_supply_put(struct power_supply *psy)
|
|||||||
EXPORT_SYMBOL_GPL(power_supply_put);
|
EXPORT_SYMBOL_GPL(power_supply_put);
|
||||||
|
|
||||||
#ifdef CONFIG_OF
|
#ifdef CONFIG_OF
|
||||||
static int power_supply_match_device_node(struct device *dev, const void *data)
|
static int power_supply_match_device_fwnode(struct device *dev, const void *data)
|
||||||
{
|
{
|
||||||
return dev->parent && dev->parent->of_node == data;
|
return dev->parent && dev_fwnode(dev->parent) == data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* power_supply_get_by_phandle() - Search for a power supply and returns its ref
|
* power_supply_get_by_phandle() - Search for a power supply and returns its ref
|
||||||
* @np: Pointer to device node holding phandle property
|
* @fwnode: Pointer to fwnode holding phandle property
|
||||||
* @property: Name of property holding a power supply name
|
* @property: Name of property holding a power supply name
|
||||||
*
|
*
|
||||||
* If power supply was found, it increases reference count for the
|
* If power supply was found, it increases reference count for the
|
||||||
@ -515,21 +514,21 @@ static int power_supply_match_device_node(struct device *dev, const void *data)
|
|||||||
* Return: On success returns a reference to a power supply with
|
* Return: On success returns a reference to a power supply with
|
||||||
* matching name equals to value under @property, NULL or ERR_PTR otherwise.
|
* matching name equals to value under @property, NULL or ERR_PTR otherwise.
|
||||||
*/
|
*/
|
||||||
struct power_supply *power_supply_get_by_phandle(struct device_node *np,
|
struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode,
|
||||||
const char *property)
|
const char *property)
|
||||||
{
|
{
|
||||||
struct device_node *power_supply_np;
|
struct fwnode_handle *power_supply_fwnode;
|
||||||
struct power_supply *psy = NULL;
|
struct power_supply *psy = NULL;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
|
||||||
power_supply_np = of_parse_phandle(np, property, 0);
|
power_supply_fwnode = fwnode_find_reference(fwnode, property, 0);
|
||||||
if (!power_supply_np)
|
if (IS_ERR(power_supply_fwnode))
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_CAST(power_supply_fwnode);
|
||||||
|
|
||||||
dev = class_find_device(&power_supply_class, NULL, power_supply_np,
|
dev = class_find_device(&power_supply_class, NULL, power_supply_fwnode,
|
||||||
power_supply_match_device_node);
|
power_supply_match_device_fwnode);
|
||||||
|
|
||||||
of_node_put(power_supply_np);
|
fwnode_handle_put(power_supply_fwnode);
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
psy = dev_to_psy(dev);
|
psy = dev_to_psy(dev);
|
||||||
@ -561,14 +560,14 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
|
|||||||
{
|
{
|
||||||
struct power_supply **ptr, *psy;
|
struct power_supply **ptr, *psy;
|
||||||
|
|
||||||
if (!dev->of_node)
|
if (!dev_fwnode(dev))
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
|
||||||
ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
|
ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
psy = power_supply_get_by_phandle(dev->of_node, property);
|
psy = power_supply_get_by_phandle(dev_fwnode(dev), property);
|
||||||
if (IS_ERR_OR_NULL(psy)) {
|
if (IS_ERR_OR_NULL(psy)) {
|
||||||
devres_free(ptr);
|
devres_free(ptr);
|
||||||
} else {
|
} else {
|
||||||
|
@ -808,7 +808,7 @@ static inline struct power_supply *power_supply_get_by_name(const char *name)
|
|||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_OF
|
#ifdef CONFIG_OF
|
||||||
extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
|
extern struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode,
|
||||||
const char *property);
|
const char *property);
|
||||||
extern struct power_supply *devm_power_supply_get_by_phandle(
|
extern struct power_supply *devm_power_supply_get_by_phandle(
|
||||||
struct device *dev, const char *property);
|
struct device *dev, const char *property);
|
||||||
|
Loading…
Reference in New Issue
Block a user