2 * phy.h -- generic phy header file
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #ifndef __DRIVERS_PHY_H
15 #define __DRIVERS_PHY_H
17 #include <linux/err.h>
19 #include <linux/device.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/regulator/consumer.h>
26 * struct phy_ops - set of function pointers for performing phy operations
27 * @init: operation to be performed for initializing phy
28 * @exit: operation to be performed while exiting
29 * @power_on: powering on the phy
30 * @power_off: powering off the phy
31 * @owner: the module owner containing the ops
34 int (*init)(struct phy *phy);
35 int (*exit)(struct phy *phy);
36 int (*power_on)(struct phy *phy);
37 int (*power_off)(struct phy *phy);
42 * struct phy_attrs - represents phy attributes
43 * @bus_width: Data path width implemented by PHY
50 * struct phy - represents the phy device
52 * @id: id of the phy device
53 * @ops: function pointers for performing phy operations
54 * @init_data: list of PHY consumers (non-dt only)
55 * @mutex: mutex to protect phy_ops
56 * @init_count: used to protect when the PHY is used by multiple consumers
57 * @power_count: used to protect when the PHY is used by multiple consumers
58 * @phy_attrs: used to specify PHY specific attributes
63 const struct phy_ops *ops;
67 struct phy_attrs attrs;
68 struct regulator *pwr;
72 * struct phy_provider - represents the phy provider
73 * @dev: phy provider device
74 * @owner: the module owner having of_xlate
75 * @of_xlate: function pointer to obtain phy instance from phy pointer
76 * @list: to maintain a linked list of PHY providers
81 struct list_head list;
82 struct phy * (*of_xlate)(struct device *dev,
83 struct of_phandle_args *args);
87 struct list_head node;
93 #define to_phy(a) (container_of((a), struct phy, dev))
95 #define of_phy_provider_register(dev, xlate) \
96 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
98 #define devm_of_phy_provider_register(dev, xlate) \
99 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
101 static inline void phy_set_drvdata(struct phy *phy, void *data)
103 dev_set_drvdata(&phy->dev, data);
106 static inline void *phy_get_drvdata(struct phy *phy)
108 return dev_get_drvdata(&phy->dev);
111 #if IS_ENABLED(CONFIG_GENERIC_PHY)
112 int phy_pm_runtime_get(struct phy *phy);
113 int phy_pm_runtime_get_sync(struct phy *phy);
114 int phy_pm_runtime_put(struct phy *phy);
115 int phy_pm_runtime_put_sync(struct phy *phy);
116 void phy_pm_runtime_allow(struct phy *phy);
117 void phy_pm_runtime_forbid(struct phy *phy);
118 int phy_init(struct phy *phy);
119 int phy_exit(struct phy *phy);
120 int phy_power_on(struct phy *phy);
121 int phy_power_off(struct phy *phy);
122 static inline int phy_get_bus_width(struct phy *phy)
124 return phy->attrs.bus_width;
126 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
128 phy->attrs.bus_width = bus_width;
130 struct phy *phy_get(struct device *dev, const char *string);
131 struct phy *phy_optional_get(struct device *dev, const char *string);
132 struct phy *devm_phy_get(struct device *dev, const char *string);
133 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
134 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
136 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
138 void phy_put(struct phy *phy);
139 void devm_phy_put(struct device *dev, struct phy *phy);
140 struct phy *of_phy_get(struct device_node *np, const char *con_id);
141 struct phy *of_phy_simple_xlate(struct device *dev,
142 struct of_phandle_args *args);
143 struct phy *phy_create(struct device *dev, struct device_node *node,
144 const struct phy_ops *ops);
145 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
146 const struct phy_ops *ops);
147 void phy_destroy(struct phy *phy);
148 void devm_phy_destroy(struct device *dev, struct phy *phy);
149 struct phy_provider *__of_phy_provider_register(struct device *dev,
150 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
151 struct of_phandle_args *args));
152 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
153 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
154 struct of_phandle_args *args));
155 void of_phy_provider_unregister(struct phy_provider *phy_provider);
156 void devm_of_phy_provider_unregister(struct device *dev,
157 struct phy_provider *phy_provider);
158 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
159 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
161 static inline int phy_pm_runtime_get(struct phy *phy)
168 static inline int phy_pm_runtime_get_sync(struct phy *phy)
175 static inline int phy_pm_runtime_put(struct phy *phy)
182 static inline int phy_pm_runtime_put_sync(struct phy *phy)
189 static inline void phy_pm_runtime_allow(struct phy *phy)
194 static inline void phy_pm_runtime_forbid(struct phy *phy)
199 static inline int phy_init(struct phy *phy)
206 static inline int phy_exit(struct phy *phy)
213 static inline int phy_power_on(struct phy *phy)
220 static inline int phy_power_off(struct phy *phy)
227 static inline int phy_get_bus_width(struct phy *phy)
232 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
237 static inline struct phy *phy_get(struct device *dev, const char *string)
239 return ERR_PTR(-ENOSYS);
242 static inline struct phy *phy_optional_get(struct device *dev,
245 return ERR_PTR(-ENOSYS);
248 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
250 return ERR_PTR(-ENOSYS);
253 static inline struct phy *devm_phy_optional_get(struct device *dev,
256 return ERR_PTR(-ENOSYS);
259 static inline struct phy *devm_of_phy_get(struct device *dev,
260 struct device_node *np,
263 return ERR_PTR(-ENOSYS);
266 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
267 struct device_node *np,
270 return ERR_PTR(-ENOSYS);
273 static inline void phy_put(struct phy *phy)
277 static inline void devm_phy_put(struct device *dev, struct phy *phy)
281 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
283 return ERR_PTR(-ENOSYS);
286 static inline struct phy *of_phy_simple_xlate(struct device *dev,
287 struct of_phandle_args *args)
289 return ERR_PTR(-ENOSYS);
292 static inline struct phy *phy_create(struct device *dev,
293 struct device_node *node,
294 const struct phy_ops *ops)
296 return ERR_PTR(-ENOSYS);
299 static inline struct phy *devm_phy_create(struct device *dev,
300 struct device_node *node,
301 const struct phy_ops *ops)
303 return ERR_PTR(-ENOSYS);
306 static inline void phy_destroy(struct phy *phy)
310 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
314 static inline struct phy_provider *__of_phy_provider_register(
315 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
316 struct device *dev, struct of_phandle_args *args))
318 return ERR_PTR(-ENOSYS);
321 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
322 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
323 struct of_phandle_args *args))
325 return ERR_PTR(-ENOSYS);
328 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
332 static inline void devm_of_phy_provider_unregister(struct device *dev,
333 struct phy_provider *phy_provider)
337 phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
341 static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
342 const char *dev_id) { }
345 #endif /* __DRIVERS_PHY_H */