18
18
#include <linux/device.h>
19
19
#include <linux/notifier.h>
20
20
#include <linux/err.h>
21
- #include <linux/of.h>
22
21
#include <linux/power_supply.h>
23
22
#include <linux/property.h>
24
23
#include <linux/thermal.h>
@@ -196,24 +195,24 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,
196
195
void * data )
197
196
{
198
197
struct power_supply * psy = data ;
199
- struct device_node * np ;
198
+ struct fwnode_handle * np ;
200
199
int i = 0 ;
201
200
202
201
do {
203
- np = of_parse_phandle (psy -> dev .of_node , "power-supplies" , i ++ );
204
- if (! np )
202
+ np = fwnode_find_reference (psy -> dev .fwnode , "power-supplies" , i ++ );
203
+ if (IS_ERR ( np ) )
205
204
break ;
206
205
207
- if (np == epsy -> dev .of_node ) {
206
+ if (np == epsy -> dev .fwnode ) {
208
207
dev_dbg (& psy -> dev , "%s: Found supply : %s\n" ,
209
208
psy -> desc -> name , epsy -> desc -> name );
210
209
psy -> supplied_from [i - 1 ] = (char * )epsy -> desc -> name ;
211
210
psy -> num_supplies ++ ;
212
- of_node_put (np );
211
+ fwnode_handle_put (np );
213
212
break ;
214
213
}
215
- of_node_put (np );
216
- } while (np );
214
+ fwnode_handle_put (np );
215
+ } while (! IS_ERR ( np ) );
217
216
218
217
return 0 ;
219
218
}
@@ -232,24 +231,24 @@ static int power_supply_populate_supplied_from(struct power_supply *psy)
232
231
static int __power_supply_find_supply_from_node (struct power_supply * epsy ,
233
232
void * data )
234
233
{
235
- struct device_node * np = data ;
234
+ struct fwnode_handle * fwnode = data ;
236
235
237
236
/* returning non-zero breaks out of power_supply_for_each_psy loop */
238
- if (epsy -> dev .of_node == np )
237
+ if (epsy -> dev .fwnode == fwnode )
239
238
return 1 ;
240
239
241
240
return 0 ;
242
241
}
243
242
244
- static int power_supply_find_supply_from_node (struct device_node * supply_node )
243
+ static int power_supply_find_supply_from_fwnode (struct fwnode_handle * supply_node )
245
244
{
246
245
int error ;
247
246
248
247
/*
249
248
* power_supply_for_each_psy() either returns its own errors or values
250
249
* returned by __power_supply_find_supply_from_node().
251
250
*
252
- * __power_supply_find_supply_from_node () will return 0 (no match)
251
+ * __power_supply_find_supply_from_fwnode () will return 0 (no match)
253
252
* or 1 (match).
254
253
*
255
254
* We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if
@@ -262,32 +261,32 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
262
261
263
262
static int power_supply_check_supplies (struct power_supply * psy )
264
263
{
265
- struct device_node * np ;
264
+ struct fwnode_handle * np ;
266
265
int cnt = 0 ;
267
266
268
267
/* If there is already a list honor it */
269
268
if (psy -> supplied_from && psy -> num_supplies > 0 )
270
269
return 0 ;
271
270
272
271
/* No device node found, nothing to do */
273
- if (!psy -> dev .of_node )
272
+ if (!psy -> dev .fwnode )
274
273
return 0 ;
275
274
276
275
do {
277
276
int ret ;
278
277
279
- np = of_parse_phandle (psy -> dev .of_node , "power-supplies" , cnt ++ );
280
- if (! np )
278
+ np = fwnode_find_reference (psy -> dev .fwnode , "power-supplies" , cnt ++ );
279
+ if (IS_ERR ( np ) )
281
280
break ;
282
281
283
- ret = power_supply_find_supply_from_node (np );
284
- of_node_put (np );
282
+ ret = power_supply_find_supply_from_fwnode (np );
283
+ fwnode_handle_put (np );
285
284
286
285
if (ret ) {
287
286
dev_dbg (& psy -> dev , "Failed to find supply!\n" );
288
287
return ret ;
289
288
}
290
- } while (np );
289
+ } while (! IS_ERR ( np ) );
291
290
292
291
/* Missing valid "power-supplies" entries */
293
292
if (cnt == 1 )
@@ -498,14 +497,14 @@ void power_supply_put(struct power_supply *psy)
498
497
EXPORT_SYMBOL_GPL (power_supply_put );
499
498
500
499
#ifdef CONFIG_OF
501
- static int power_supply_match_device_node (struct device * dev , const void * data )
500
+ static int power_supply_match_device_fwnode (struct device * dev , const void * data )
502
501
{
503
- return dev -> parent && dev -> parent -> of_node == data ;
502
+ return dev -> parent && dev_fwnode ( dev -> parent ) == data ;
504
503
}
505
504
506
505
/**
507
506
* power_supply_get_by_phandle() - Search for a power supply and returns its ref
508
- * @np : Pointer to device node holding phandle property
507
+ * @fwnode : Pointer to fwnode holding phandle property
509
508
* @property: Name of property holding a power supply name
510
509
*
511
510
* 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)
515
514
* Return: On success returns a reference to a power supply with
516
515
* matching name equals to value under @property, NULL or ERR_PTR otherwise.
517
516
*/
518
- struct power_supply * power_supply_get_by_phandle (struct device_node * np ,
519
- const char * property )
517
+ struct power_supply * power_supply_get_by_phandle (struct fwnode_handle * fwnode ,
518
+ const char * property )
520
519
{
521
- struct device_node * power_supply_np ;
520
+ struct fwnode_handle * power_supply_fwnode ;
522
521
struct power_supply * psy = NULL ;
523
522
struct device * dev ;
524
523
525
- power_supply_np = of_parse_phandle ( np , property , 0 );
526
- if (! power_supply_np )
527
- return ERR_PTR ( - ENODEV );
524
+ power_supply_fwnode = fwnode_find_reference ( fwnode , property , 0 );
525
+ if (IS_ERR ( power_supply_fwnode ) )
526
+ return ERR_CAST ( power_supply_fwnode );
528
527
529
- dev = class_find_device (& power_supply_class , NULL , power_supply_np ,
530
- power_supply_match_device_node );
528
+ dev = class_find_device (& power_supply_class , NULL , power_supply_fwnode ,
529
+ power_supply_match_device_fwnode );
531
530
532
- of_node_put ( power_supply_np );
531
+ fwnode_handle_put ( power_supply_fwnode );
533
532
534
533
if (dev ) {
535
534
psy = dev_to_psy (dev );
@@ -561,14 +560,14 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
561
560
{
562
561
struct power_supply * * ptr , * psy ;
563
562
564
- if (!dev -> of_node )
563
+ if (!dev_fwnode ( dev ) )
565
564
return ERR_PTR (- ENODEV );
566
565
567
566
ptr = devres_alloc (devm_power_supply_put , sizeof (* ptr ), GFP_KERNEL );
568
567
if (!ptr )
569
568
return ERR_PTR (- ENOMEM );
570
569
571
- psy = power_supply_get_by_phandle (dev -> of_node , property );
570
+ psy = power_supply_get_by_phandle (dev_fwnode ( dev ) , property );
572
571
if (IS_ERR_OR_NULL (psy )) {
573
572
devres_free (ptr );
574
573
} else {
0 commit comments