2 * phy.h -- generic phy header file
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.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>
25 * struct phy_ops - set of function pointers for performing phy operations
26 * @init: operation to be performed for initializing phy
27 * @exit: operation to be performed while exiting
28 * @power_on: powering on the phy
29 * @power_off: powering off the phy
30 * @owner: the module owner containing the ops
33 int (*init)(struct phy *phy);
34 int (*exit)(struct phy *phy);
35 int (*power_on)(struct phy *phy);
36 int (*power_off)(struct phy *phy);
41 * struct phy - represents the phy device
43 * @id: id of the phy device
44 * @ops: function pointers for performing phy operations
45 * @init_data: list of PHY consumers (non-dt only)
46 * @mutex: mutex to protect phy_ops
47 * @init_count: used to protect when the PHY is used by multiple consumers
48 * @power_count: used to protect when the PHY is used by multiple consumers
53 const struct phy_ops *ops;
54 struct phy_init_data *init_data;
61 * struct phy_provider - represents the phy provider
62 * @dev: phy provider device
63 * @owner: the module owner having of_xlate
64 * @of_xlate: function pointer to obtain phy instance from phy pointer
65 * @list: to maintain a linked list of PHY providers
70 struct list_head list;
71 struct phy * (*of_xlate)(struct device *dev,
72 struct of_phandle_args *args);
76 * struct phy_consumer - represents the phy consumer
77 * @dev_name: the device name of the controller that will use this PHY device
78 * @port: name given to the consumer port
86 * struct phy_init_data - contains the list of PHY consumers
87 * @num_consumers: number of consumers for this PHY device
88 * @consumers: list of PHY consumers
90 struct phy_init_data {
91 unsigned int num_consumers;
92 struct phy_consumer *consumers;
95 #define PHY_CONSUMER(_dev_name, _port) \
97 .dev_name = _dev_name, \
101 #define to_phy(dev) (container_of((dev), struct phy, dev))
103 #define of_phy_provider_register(dev, xlate) \
104 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
106 #define devm_of_phy_provider_register(dev, xlate) \
107 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
109 static inline void phy_set_drvdata(struct phy *phy, void *data)
111 dev_set_drvdata(&phy->dev, data);
114 static inline void *phy_get_drvdata(struct phy *phy)
116 return dev_get_drvdata(&phy->dev);
119 #if IS_ENABLED(CONFIG_GENERIC_PHY)
120 int phy_pm_runtime_get(struct phy *phy);
121 int phy_pm_runtime_get_sync(struct phy *phy);
122 int phy_pm_runtime_put(struct phy *phy);
123 int phy_pm_runtime_put_sync(struct phy *phy);
124 void phy_pm_runtime_allow(struct phy *phy);
125 void phy_pm_runtime_forbid(struct phy *phy);
126 int phy_init(struct phy *phy);
127 int phy_exit(struct phy *phy);
128 int phy_power_on(struct phy *phy);
129 int phy_power_off(struct phy *phy);
130 struct phy *phy_get(struct device *dev, const char *string);
131 struct phy *devm_phy_get(struct device *dev, const char *string);
132 void phy_put(struct phy *phy);
133 void devm_phy_put(struct device *dev, struct phy *phy);
134 struct phy *of_phy_simple_xlate(struct device *dev,
135 struct of_phandle_args *args);
136 struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
137 struct phy_init_data *init_data);
138 struct phy *devm_phy_create(struct device *dev,
139 const struct phy_ops *ops, struct phy_init_data *init_data);
140 void phy_destroy(struct phy *phy);
141 void devm_phy_destroy(struct device *dev, struct phy *phy);
142 struct phy_provider *__of_phy_provider_register(struct device *dev,
143 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
144 struct of_phandle_args *args));
145 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
146 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
147 struct of_phandle_args *args));
148 void of_phy_provider_unregister(struct phy_provider *phy_provider);
149 void devm_of_phy_provider_unregister(struct device *dev,
150 struct phy_provider *phy_provider);
152 static inline int phy_pm_runtime_get(struct phy *phy)
157 static inline int phy_pm_runtime_get_sync(struct phy *phy)
162 static inline int phy_pm_runtime_put(struct phy *phy)
167 static inline int phy_pm_runtime_put_sync(struct phy *phy)
172 static inline void phy_pm_runtime_allow(struct phy *phy)
177 static inline void phy_pm_runtime_forbid(struct phy *phy)
182 static inline int phy_init(struct phy *phy)
187 static inline int phy_exit(struct phy *phy)
192 static inline int phy_power_on(struct phy *phy)
197 static inline int phy_power_off(struct phy *phy)
202 static inline struct phy *phy_get(struct device *dev, const char *string)
204 return ERR_PTR(-ENOSYS);
207 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
209 return ERR_PTR(-ENOSYS);
212 static inline void phy_put(struct phy *phy)
216 static inline void devm_phy_put(struct device *dev, struct phy *phy)
220 static inline struct phy *of_phy_simple_xlate(struct device *dev,
221 struct of_phandle_args *args)
223 return ERR_PTR(-ENOSYS);
226 static inline struct phy *phy_create(struct device *dev,
227 const struct phy_ops *ops, struct phy_init_data *init_data)
229 return ERR_PTR(-ENOSYS);
232 static inline struct phy *devm_phy_create(struct device *dev,
233 const struct phy_ops *ops, struct phy_init_data *init_data)
235 return ERR_PTR(-ENOSYS);
238 static inline void phy_destroy(struct phy *phy)
242 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
246 static inline struct phy_provider *__of_phy_provider_register(
247 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
248 struct device *dev, struct of_phandle_args *args))
250 return ERR_PTR(-ENOSYS);
253 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
254 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
255 struct of_phandle_args *args))
257 return ERR_PTR(-ENOSYS);
260 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
264 static inline void devm_of_phy_provider_unregister(struct device *dev,
265 struct phy_provider *phy_provider)
270 #endif /* __DRIVERS_PHY_H */