Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: core: Allow children node to be overridden

In order to more flexibly support device tree bindings, allow drivers to
override the container of the child nodes. By default the device node of
the PHY provider is assumed to be the parent for children, but bindings
may decide to add additional levels for better organization.

Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>

+79 -18
+14 -2
Documentation/phy.txt
··· 31 31 dt boot case. 32 32 33 33 #define of_phy_provider_register(dev, xlate) \ 34 - __of_phy_provider_register((dev), THIS_MODULE, (xlate)) 34 + __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) 35 35 36 36 #define devm_of_phy_provider_register(dev, xlate) \ 37 - __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) 37 + __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) 38 38 39 39 of_phy_provider_register and devm_of_phy_provider_register macros can be used to 40 40 register the phy_provider and it takes device and of_xlate as 41 41 arguments. For the dt boot case, all PHY providers should use one of the above 42 42 2 macros to register the PHY provider. 43 + 44 + Often the device tree nodes associated with a PHY provider will contain a set 45 + of children that each represent a single PHY. Some bindings may nest the child 46 + nodes within extra levels for context and extensibility, in which case the low 47 + level of_phy_provider_register_full() and devm_of_phy_provider_register_full() 48 + macros can be used to override the node containing the children. 49 + 50 + #define of_phy_provider_register_full(dev, children, xlate) \ 51 + __of_phy_provider_register(dev, children, THIS_MODULE, xlate) 52 + 53 + #define devm_of_phy_provider_register_full(dev, children, xlate) \ 54 + __devm_of_phy_provider_register_full(dev, children, THIS_MODULE, xlate) 43 55 44 56 void devm_of_phy_provider_unregister(struct device *dev, 45 57 struct phy_provider *phy_provider);
+44 -6
drivers/phy/phy-core.c
··· 141 141 if (phy_provider->dev->of_node == node) 142 142 return phy_provider; 143 143 144 - for_each_child_of_node(phy_provider->dev->of_node, child) 144 + for_each_child_of_node(phy_provider->children, child) 145 145 if (child == node) 146 146 return phy_provider; 147 147 } ··· 811 811 /** 812 812 * __of_phy_provider_register() - create/register phy provider with the framework 813 813 * @dev: struct device of the phy provider 814 + * @children: device node containing children (if different from dev->of_node) 814 815 * @owner: the module owner containing of_xlate 815 816 * @of_xlate: function pointer to obtain phy instance from phy provider 816 817 * 817 818 * Creates struct phy_provider from dev and of_xlate function pointer. 818 819 * This is used in the case of dt boot for finding the phy instance from 819 820 * phy provider. 821 + * 822 + * If the PHY provider doesn't nest children directly but uses a separate 823 + * child node to contain the individual children, the @children parameter 824 + * can be used to override the default. If NULL, the default (dev->of_node) 825 + * will be used. If non-NULL, the device node must be a child (or further 826 + * descendant) of dev->of_node. Otherwise an ERR_PTR()-encoded -EINVAL 827 + * error code is returned. 820 828 */ 821 829 struct phy_provider *__of_phy_provider_register(struct device *dev, 822 - struct module *owner, struct phy * (*of_xlate)(struct device *dev, 823 - struct of_phandle_args *args)) 830 + struct device_node *children, struct module *owner, 831 + struct phy * (*of_xlate)(struct device *dev, 832 + struct of_phandle_args *args)) 824 833 { 825 834 struct phy_provider *phy_provider; 835 + 836 + /* 837 + * If specified, the device node containing the children must itself 838 + * be the provider's device node or a child (or further descendant) 839 + * thereof. 840 + */ 841 + if (children) { 842 + struct device_node *parent = of_node_get(children), *next; 843 + 844 + while (parent) { 845 + if (parent == dev->of_node) 846 + break; 847 + 848 + next = of_get_parent(parent); 849 + of_node_put(parent); 850 + parent = next; 851 + } 852 + 853 + if (!parent) 854 + return ERR_PTR(-EINVAL); 855 + 856 + of_node_put(parent); 857 + } else { 858 + children = dev->of_node; 859 + } 826 860 827 861 phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL); 828 862 if (!phy_provider) 829 863 return ERR_PTR(-ENOMEM); 830 864 831 865 phy_provider->dev = dev; 866 + phy_provider->children = of_node_get(children); 832 867 phy_provider->owner = owner; 833 868 phy_provider->of_xlate = of_xlate; 834 869 ··· 889 854 * on the devres data, then, devres data is freed. 890 855 */ 891 856 struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 892 - struct module *owner, struct phy * (*of_xlate)(struct device *dev, 893 - struct of_phandle_args *args)) 857 + struct device_node *children, struct module *owner, 858 + struct phy * (*of_xlate)(struct device *dev, 859 + struct of_phandle_args *args)) 894 860 { 895 861 struct phy_provider **ptr, *phy_provider; 896 862 ··· 899 863 if (!ptr) 900 864 return ERR_PTR(-ENOMEM); 901 865 902 - phy_provider = __of_phy_provider_register(dev, owner, of_xlate); 866 + phy_provider = __of_phy_provider_register(dev, children, owner, 867 + of_xlate); 903 868 if (!IS_ERR(phy_provider)) { 904 869 *ptr = phy_provider; 905 870 devres_add(dev, ptr); ··· 925 888 926 889 mutex_lock(&phy_provider_mutex); 927 890 list_del(&phy_provider->list); 891 + of_node_put(phy_provider->children); 928 892 kfree(phy_provider); 929 893 mutex_unlock(&phy_provider_mutex); 930 894 }
+21 -10
include/linux/phy/phy.h
··· 77 77 */ 78 78 struct phy_provider { 79 79 struct device *dev; 80 + struct device_node *children; 80 81 struct module *owner; 81 82 struct list_head list; 82 83 struct phy * (*of_xlate)(struct device *dev, ··· 94 93 #define to_phy(a) (container_of((a), struct phy, dev)) 95 94 96 95 #define of_phy_provider_register(dev, xlate) \ 97 - __of_phy_provider_register((dev), THIS_MODULE, (xlate)) 96 + __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) 98 97 99 98 #define devm_of_phy_provider_register(dev, xlate) \ 100 - __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) 99 + __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) 100 + 101 + #define of_phy_provider_register_full(dev, children, xlate) \ 102 + __of_phy_provider_register(dev, children, THIS_MODULE, xlate) 103 + 104 + #define devm_of_phy_provider_register_full(dev, children, xlate) \ 105 + __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate) 101 106 102 107 static inline void phy_set_drvdata(struct phy *phy, void *data) 103 108 { ··· 154 147 void phy_destroy(struct phy *phy); 155 148 void devm_phy_destroy(struct device *dev, struct phy *phy); 156 149 struct phy_provider *__of_phy_provider_register(struct device *dev, 157 - struct module *owner, struct phy * (*of_xlate)(struct device *dev, 158 - struct of_phandle_args *args)); 150 + struct device_node *children, struct module *owner, 151 + struct phy * (*of_xlate)(struct device *dev, 152 + struct of_phandle_args *args)); 159 153 struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 160 - struct module *owner, struct phy * (*of_xlate)(struct device *dev, 161 - struct of_phandle_args *args)); 154 + struct device_node *children, struct module *owner, 155 + struct phy * (*of_xlate)(struct device *dev, 156 + struct of_phandle_args *args)); 162 157 void of_phy_provider_unregister(struct phy_provider *phy_provider); 163 158 void devm_of_phy_provider_unregister(struct device *dev, 164 159 struct phy_provider *phy_provider); ··· 321 312 } 322 313 323 314 static inline struct phy_provider *__of_phy_provider_register( 324 - struct device *dev, struct module *owner, struct phy * (*of_xlate)( 325 - struct device *dev, struct of_phandle_args *args)) 315 + struct device *dev, struct device_node *children, struct module *owner, 316 + struct phy * (*of_xlate)(struct device *dev, 317 + struct of_phandle_args *args)) 326 318 { 327 319 return ERR_PTR(-ENOSYS); 328 320 } 329 321 330 322 static inline struct phy_provider *__devm_of_phy_provider_register(struct device 331 - *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, 332 - struct of_phandle_args *args)) 323 + *dev, struct device_node *children, struct module *owner, 324 + struct phy * (*of_xlate)(struct device *dev, 325 + struct of_phandle_args *args)) 333 326 { 334 327 return ERR_PTR(-ENOSYS); 335 328 }