1818#include <linux/device.h>
1919#include <linux/notifier.h>
2020#include <linux/err.h>
21- #include <linux/of.h>
2221#include <linux/power_supply.h>
2322#include <linux/property.h>
2423#include <linux/thermal.h>
@@ -196,24 +195,24 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,
196195 void * data )
197196{
198197 struct power_supply * psy = data ;
199- struct device_node * np ;
198+ struct fwnode_handle * np ;
200199 int i = 0 ;
201200
202201 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 ) )
205204 break ;
206205
207- if (np == epsy -> dev .of_node ) {
206+ if (np == epsy -> dev .fwnode ) {
208207 dev_dbg (& psy -> dev , "%s: Found supply : %s\n" ,
209208 psy -> desc -> name , epsy -> desc -> name );
210209 psy -> supplied_from [i - 1 ] = (char * )epsy -> desc -> name ;
211210 psy -> num_supplies ++ ;
212- of_node_put (np );
211+ fwnode_handle_put (np );
213212 break ;
214213 }
215- of_node_put (np );
216- } while (np );
214+ fwnode_handle_put (np );
215+ } while (! IS_ERR ( np ) );
217216
218217 return 0 ;
219218}
@@ -232,24 +231,24 @@ static int power_supply_populate_supplied_from(struct power_supply *psy)
232231static int __power_supply_find_supply_from_node (struct power_supply * epsy ,
233232 void * data )
234233{
235- struct device_node * np = data ;
234+ struct fwnode_handle * fwnode = data ;
236235
237236 /* 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 )
239238 return 1 ;
240239
241240 return 0 ;
242241}
243242
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 )
245244{
246245 int error ;
247246
248247 /*
249248 * power_supply_for_each_psy() either returns its own errors or values
250249 * returned by __power_supply_find_supply_from_node().
251250 *
252- * __power_supply_find_supply_from_node () will return 0 (no match)
251+ * __power_supply_find_supply_from_fwnode () will return 0 (no match)
253252 * or 1 (match).
254253 *
255254 * 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)
262261
263262static int power_supply_check_supplies (struct power_supply * psy )
264263{
265- struct device_node * np ;
264+ struct fwnode_handle * np ;
266265 int cnt = 0 ;
267266
268267 /* If there is already a list honor it */
269268 if (psy -> supplied_from && psy -> num_supplies > 0 )
270269 return 0 ;
271270
272271 /* No device node found, nothing to do */
273- if (!psy -> dev .of_node )
272+ if (!psy -> dev .fwnode )
274273 return 0 ;
275274
276275 do {
277276 int ret ;
278277
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 ) )
281280 break ;
282281
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 );
285284
286285 if (ret ) {
287286 dev_dbg (& psy -> dev , "Failed to find supply!\n" );
288287 return ret ;
289288 }
290- } while (np );
289+ } while (! IS_ERR ( np ) );
291290
292291 /* Missing valid "power-supplies" entries */
293292 if (cnt == 1 )
@@ -498,14 +497,14 @@ void power_supply_put(struct power_supply *psy)
498497EXPORT_SYMBOL_GPL (power_supply_put );
499498
500499#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 )
502501{
503- return dev -> parent && dev -> parent -> of_node == data ;
502+ return dev -> parent && dev_fwnode ( dev -> parent ) == data ;
504503}
505504
506505/**
507506 * 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
509508 * @property: Name of property holding a power supply name
510509 *
511510 * 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)
515514 * Return: On success returns a reference to a power supply with
516515 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
517516 */
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 )
520519{
521- struct device_node * power_supply_np ;
520+ struct fwnode_handle * power_supply_fwnode ;
522521 struct power_supply * psy = NULL ;
523522 struct device * dev ;
524523
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 );
528527
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 );
531530
532- of_node_put ( power_supply_np );
531+ fwnode_handle_put ( power_supply_fwnode );
533532
534533 if (dev ) {
535534 psy = dev_to_psy (dev );
@@ -561,14 +560,14 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
561560{
562561 struct power_supply * * ptr , * psy ;
563562
564- if (!dev -> of_node )
563+ if (!dev_fwnode ( dev ) )
565564 return ERR_PTR (- ENODEV );
566565
567566 ptr = devres_alloc (devm_power_supply_put , sizeof (* ptr ), GFP_KERNEL );
568567 if (!ptr )
569568 return ERR_PTR (- ENOMEM );
570569
571- psy = power_supply_get_by_phandle (dev -> of_node , property );
570+ psy = power_supply_get_by_phandle (dev_fwnode ( dev ) , property );
572571 if (IS_ERR_OR_NULL (psy )) {
573572 devres_free (ptr );
574573 } else {
0 commit comments