@@ -588,23 +588,25 @@ static struct device_node *of_get_child_regulator(struct device_node *parent,
588588
589589/**
590590 * of_get_regulator - get a regulator device node based on supply name
591- * @dev: Device pointer for the consumer (of regulator) device
591+ * @dev: Device pointer for dev_printk() messages
592+ * @node: Device node pointer for supply property lookup
592593 * @supply: regulator supply name
593594 *
594595 * Extract the regulator device node corresponding to the supply name.
595596 *
596597 * Return: Pointer to the &struct device_node corresponding to the regulator
597598 * if found, or %NULL if not found.
598599 */
599- static struct device_node * of_get_regulator (struct device * dev , const char * supply )
600+ static struct device_node * of_get_regulator (struct device * dev , struct device_node * node ,
601+ const char * supply )
600602{
601603 struct device_node * regnode = NULL ;
602604 char prop_name [64 ]; /* 64 is max size of property name */
603605
604- dev_dbg (dev , "Looking up %s-supply from device tree \n" , supply );
606+ dev_dbg (dev , "Looking up %s-supply from device node %pOF \n" , supply , node );
605607
606608 snprintf (prop_name , 64 , "%s-supply" , supply );
607- regnode = of_parse_phandle (dev -> of_node , prop_name , 0 );
609+ regnode = of_parse_phandle (node , prop_name , 0 );
608610 if (regnode )
609611 return regnode ;
610612
@@ -628,6 +630,7 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
628630/**
629631 * of_regulator_dev_lookup - lookup a regulator device with device tree only
630632 * @dev: Device pointer for regulator supply lookup.
633+ * @np: Device node pointer for regulator supply lookup.
631634 * @supply: Supply name or regulator ID.
632635 *
633636 * Return: Pointer to the &struct regulator_dev on success, or ERR_PTR()
@@ -642,13 +645,13 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
642645 * * -%ENODEV if lookup fails permanently.
643646 * * -%EPROBE_DEFER if lookup could succeed in the future.
644647 */
645- struct regulator_dev * of_regulator_dev_lookup (struct device * dev ,
648+ struct regulator_dev * of_regulator_dev_lookup (struct device * dev , struct device_node * np ,
646649 const char * supply )
647650{
648651 struct regulator_dev * r ;
649652 struct device_node * node ;
650653
651- node = of_get_regulator (dev , supply );
654+ node = of_get_regulator (dev , np , supply );
652655 if (node ) {
653656 r = of_find_regulator_by_node (node );
654657 of_node_put (node );
@@ -665,6 +668,42 @@ struct regulator_dev *of_regulator_dev_lookup(struct device *dev,
665668 return ERR_PTR (- ENODEV );
666669}
667670
671+ struct regulator * _of_regulator_get (struct device * dev , struct device_node * node ,
672+ const char * id , enum regulator_get_type get_type )
673+ {
674+ struct regulator_dev * r ;
675+ int ret ;
676+
677+ ret = _regulator_get_common_check (dev , id , get_type );
678+ if (ret )
679+ return ERR_PTR (ret );
680+
681+ r = of_regulator_dev_lookup (dev , node , id );
682+ return _regulator_get_common (r , dev , id , get_type );
683+ }
684+
685+ /**
686+ * of_regulator_get_optional - get optional regulator via device tree lookup
687+ * @dev: device used for dev_printk() messages
688+ * @node: device node for regulator "consumer"
689+ * @id: Supply name
690+ *
691+ * Return: pointer to struct regulator corresponding to the regulator producer,
692+ * or PTR_ERR() encoded error number.
693+ *
694+ * This is intended for use by consumers that want to get a regulator
695+ * supply directly from a device node, and can and want to deal with
696+ * absence of such supplies. This will _not_ consider supply aliases.
697+ * See regulator_dev_lookup().
698+ */
699+ struct regulator * of_regulator_get_optional (struct device * dev ,
700+ struct device_node * node ,
701+ const char * id )
702+ {
703+ return _of_regulator_get (dev , node , id , OPTIONAL_GET );
704+ }
705+ EXPORT_SYMBOL_GPL (of_regulator_get_optional );
706+
668707/*
669708 * Returns number of regulators coupled with rdev.
670709 */
0 commit comments