aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2016-04-05 11:17:34 -0400
committerThierry Reding <treding@nvidia.com>2016-04-29 10:39:39 -0400
commit1140f7c8994a3a2a0d7c4972509d98b792617d39 (patch)
tree2c22ea1a570a2e706bb863053b10584a3aa29b92
parent0e55714902857f71ce3f9144f6a73fb8321229ef (diff)
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>
-rw-r--r--Documentation/phy.txt16
-rw-r--r--drivers/phy/phy-core.c50
-rw-r--r--include/linux/phy/phy.h31
3 files changed, 79 insertions, 18 deletions
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
index b388c5af9e72..0aa994bd9a91 100644
--- a/Documentation/phy.txt
+++ b/Documentation/phy.txt
@@ -31,16 +31,28 @@ should provide its own implementation of of_xlate. of_xlate is used only for
31dt boot case. 31dt boot case.
32 32
33#define of_phy_provider_register(dev, xlate) \ 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#define devm_of_phy_provider_register(dev, xlate) \ 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
39of_phy_provider_register and devm_of_phy_provider_register macros can be used to 39of_phy_provider_register and devm_of_phy_provider_register macros can be used to
40register the phy_provider and it takes device and of_xlate as 40register the phy_provider and it takes device and of_xlate as
41arguments. For the dt boot case, all PHY providers should use one of the above 41arguments. For the dt boot case, all PHY providers should use one of the above
422 macros to register the PHY provider. 422 macros to register the PHY provider.
43 43
44Often the device tree nodes associated with a PHY provider will contain a set
45of children that each represent a single PHY. Some bindings may nest the child
46nodes within extra levels for context and extensibility, in which case the low
47level of_phy_provider_register_full() and devm_of_phy_provider_register_full()
48macros 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)
55
44void devm_of_phy_provider_unregister(struct device *dev, 56void devm_of_phy_provider_unregister(struct device *dev,
45 struct phy_provider *phy_provider); 57 struct phy_provider *phy_provider);
46void of_phy_provider_unregister(struct phy_provider *phy_provider); 58void of_phy_provider_unregister(struct phy_provider *phy_provider);
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index e7e574dc667a..b72e9a3b6429 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -141,7 +141,7 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
141 if (phy_provider->dev->of_node == node) 141 if (phy_provider->dev->of_node == node)
142 return phy_provider; 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 if (child == node) 145 if (child == node)
146 return phy_provider; 146 return phy_provider;
147 } 147 }
@@ -811,24 +811,59 @@ EXPORT_SYMBOL_GPL(devm_phy_destroy);
811/** 811/**
812 * __of_phy_provider_register() - create/register phy provider with the framework 812 * __of_phy_provider_register() - create/register phy provider with the framework
813 * @dev: struct device of the phy provider 813 * @dev: struct device of the phy provider
814 * @children: device node containing children (if different from dev->of_node)
814 * @owner: the module owner containing of_xlate 815 * @owner: the module owner containing of_xlate
815 * @of_xlate: function pointer to obtain phy instance from phy provider 816 * @of_xlate: function pointer to obtain phy instance from phy provider
816 * 817 *
817 * Creates struct phy_provider from dev and of_xlate function pointer. 818 * Creates struct phy_provider from dev and of_xlate function pointer.
818 * This is used in the case of dt boot for finding the phy instance from 819 * This is used in the case of dt boot for finding the phy instance from
819 * phy provider. 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 */
821struct phy_provider *__of_phy_provider_register(struct device *dev, 829struct phy_provider *__of_phy_provider_register(struct device *dev,
822 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 830 struct device_node *children, struct module *owner,
823 struct of_phandle_args *args)) 831 struct phy * (*of_xlate)(struct device *dev,
832 struct of_phandle_args *args))
824{ 833{
825 struct phy_provider *phy_provider; 834 struct phy_provider *phy_provider;
826 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 }
860
827 phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL); 861 phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL);
828 if (!phy_provider) 862 if (!phy_provider)
829 return ERR_PTR(-ENOMEM); 863 return ERR_PTR(-ENOMEM);
830 864
831 phy_provider->dev = dev; 865 phy_provider->dev = dev;
866 phy_provider->children = of_node_get(children);
832 phy_provider->owner = owner; 867 phy_provider->owner = owner;
833 phy_provider->of_xlate = of_xlate; 868 phy_provider->of_xlate = of_xlate;
834 869
@@ -854,8 +889,9 @@ EXPORT_SYMBOL_GPL(__of_phy_provider_register);
854 * on the devres data, then, devres data is freed. 889 * on the devres data, then, devres data is freed.
855 */ 890 */
856struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 891struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
857 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 892 struct device_node *children, struct module *owner,
858 struct of_phandle_args *args)) 893 struct phy * (*of_xlate)(struct device *dev,
894 struct of_phandle_args *args))
859{ 895{
860 struct phy_provider **ptr, *phy_provider; 896 struct phy_provider **ptr, *phy_provider;
861 897
@@ -863,7 +899,8 @@ struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
863 if (!ptr) 899 if (!ptr)
864 return ERR_PTR(-ENOMEM); 900 return ERR_PTR(-ENOMEM);
865 901
866 phy_provider = __of_phy_provider_register(dev, owner, of_xlate); 902 phy_provider = __of_phy_provider_register(dev, children, owner,
903 of_xlate);
867 if (!IS_ERR(phy_provider)) { 904 if (!IS_ERR(phy_provider)) {
868 *ptr = phy_provider; 905 *ptr = phy_provider;
869 devres_add(dev, ptr); 906 devres_add(dev, ptr);
@@ -888,6 +925,7 @@ void of_phy_provider_unregister(struct phy_provider *phy_provider)
888 925
889 mutex_lock(&phy_provider_mutex); 926 mutex_lock(&phy_provider_mutex);
890 list_del(&phy_provider->list); 927 list_del(&phy_provider->list);
928 of_node_put(phy_provider->children);
891 kfree(phy_provider); 929 kfree(phy_provider);
892 mutex_unlock(&phy_provider_mutex); 930 mutex_unlock(&phy_provider_mutex);
893} 931}
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 8cf05e341cff..a810f2a18842 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -77,6 +77,7 @@ struct phy {
77 */ 77 */
78struct phy_provider { 78struct phy_provider {
79 struct device *dev; 79 struct device *dev;
80 struct device_node *children;
80 struct module *owner; 81 struct module *owner;
81 struct list_head list; 82 struct list_head list;
82 struct phy * (*of_xlate)(struct device *dev, 83 struct phy * (*of_xlate)(struct device *dev,
@@ -93,10 +94,16 @@ struct phy_lookup {
93#define to_phy(a) (container_of((a), struct phy, dev)) 94#define to_phy(a) (container_of((a), struct phy, dev))
94 95
95#define of_phy_provider_register(dev, xlate) \ 96#define of_phy_provider_register(dev, xlate) \
96 __of_phy_provider_register((dev), THIS_MODULE, (xlate)) 97 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
97 98
98#define devm_of_phy_provider_register(dev, xlate) \ 99#define devm_of_phy_provider_register(dev, xlate) \
99 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) 100 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
101
102#define of_phy_provider_register_full(dev, children, xlate) \
103 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
104
105#define devm_of_phy_provider_register_full(dev, children, xlate) \
106 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
100 107
101static inline void phy_set_drvdata(struct phy *phy, void *data) 108static inline void phy_set_drvdata(struct phy *phy, void *data)
102{ 109{
@@ -147,11 +154,13 @@ struct phy *devm_phy_create(struct device *dev, struct device_node *node,
147void phy_destroy(struct phy *phy); 154void phy_destroy(struct phy *phy);
148void devm_phy_destroy(struct device *dev, struct phy *phy); 155void devm_phy_destroy(struct device *dev, struct phy *phy);
149struct phy_provider *__of_phy_provider_register(struct device *dev, 156struct phy_provider *__of_phy_provider_register(struct device *dev,
150 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 157 struct device_node *children, struct module *owner,
151 struct of_phandle_args *args)); 158 struct phy * (*of_xlate)(struct device *dev,
159 struct of_phandle_args *args));
152struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 160struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
153 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 161 struct device_node *children, struct module *owner,
154 struct of_phandle_args *args)); 162 struct phy * (*of_xlate)(struct device *dev,
163 struct of_phandle_args *args));
155void of_phy_provider_unregister(struct phy_provider *phy_provider); 164void of_phy_provider_unregister(struct phy_provider *phy_provider);
156void devm_of_phy_provider_unregister(struct device *dev, 165void devm_of_phy_provider_unregister(struct device *dev,
157 struct phy_provider *phy_provider); 166 struct phy_provider *phy_provider);
@@ -312,15 +321,17 @@ static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
312} 321}
313 322
314static inline struct phy_provider *__of_phy_provider_register( 323static inline struct phy_provider *__of_phy_provider_register(
315 struct device *dev, struct module *owner, struct phy * (*of_xlate)( 324 struct device *dev, struct device_node *children, struct module *owner,
316 struct device *dev, struct of_phandle_args *args)) 325 struct phy * (*of_xlate)(struct device *dev,
326 struct of_phandle_args *args))
317{ 327{
318 return ERR_PTR(-ENOSYS); 328 return ERR_PTR(-ENOSYS);
319} 329}
320 330
321static inline struct phy_provider *__devm_of_phy_provider_register(struct device 331static inline struct phy_provider *__devm_of_phy_provider_register(struct device
322 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, 332 *dev, struct device_node *children, struct module *owner,
323 struct of_phandle_args *args)) 333 struct phy * (*of_xlate)(struct device *dev,
334 struct of_phandle_args *args))
324{ 335{
325 return ERR_PTR(-ENOSYS); 336 return ERR_PTR(-ENOSYS);
326} 337}