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>
21 #include <linux/regulator/consumer.h>
33 PHY_MODE_USB_DEVICE_LS,
34 PHY_MODE_USB_DEVICE_FS,
35 PHY_MODE_USB_DEVICE_HS,
36 PHY_MODE_USB_DEVICE_SS,
48 * struct phy_ops - set of function pointers for performing phy operations
49 * @init: operation to be performed for initializing phy
50 * @exit: operation to be performed while exiting
51 * @power_on: powering on the phy
52 * @power_off: powering off the phy
53 * @set_mode: set the mode of the phy
54 * @reset: resetting the phy
55 * @calibrate: calibrate the phy
56 * @owner: the module owner containing the ops
59 int (*init)(struct phy *phy);
60 int (*exit)(struct phy *phy);
61 int (*power_on)(struct phy *phy);
62 int (*power_off)(struct phy *phy);
63 int (*set_mode)(struct phy *phy, enum phy_mode mode);
64 int (*reset)(struct phy *phy);
65 int (*calibrate)(struct phy *phy);
70 * struct phy_attrs - represents phy attributes
71 * @bus_width: Data path width implemented by PHY
79 * struct phy - represents the phy device
81 * @id: id of the phy device
82 * @ops: function pointers for performing phy operations
83 * @init_data: list of PHY consumers (non-dt only)
84 * @mutex: mutex to protect phy_ops
85 * @init_count: used to protect when the PHY is used by multiple consumers
86 * @power_count: used to protect when the PHY is used by multiple consumers
87 * @attrs: used to specify PHY specific attributes
88 * @pwr: power regulator associated with the phy
93 const struct phy_ops *ops;
97 struct phy_attrs attrs;
98 struct regulator *pwr;
102 * struct phy_provider - represents the phy provider
103 * @dev: phy provider device
104 * @children: can be used to override the default (dev->of_node) child node
105 * @owner: the module owner having of_xlate
106 * @list: to maintain a linked list of PHY providers
107 * @of_xlate: function pointer to obtain phy instance from phy pointer
109 struct phy_provider {
111 struct device_node *children;
112 struct module *owner;
113 struct list_head list;
114 struct phy * (*of_xlate)(struct device *dev,
115 struct of_phandle_args *args);
119 * struct phy_lookup - PHY association in list of phys managed by the phy driver
121 * @dev_id: the device of the association
122 * @con_id: connection ID string on device
123 * @phy: the phy of the association
126 struct list_head node;
132 #define to_phy(a) (container_of((a), struct phy, dev))
134 #define of_phy_provider_register(dev, xlate) \
135 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
137 #define devm_of_phy_provider_register(dev, xlate) \
138 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
140 #define of_phy_provider_register_full(dev, children, xlate) \
141 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
143 #define devm_of_phy_provider_register_full(dev, children, xlate) \
144 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
146 static inline void phy_set_drvdata(struct phy *phy, void *data)
148 dev_set_drvdata(&phy->dev, data);
151 static inline void *phy_get_drvdata(struct phy *phy)
153 return dev_get_drvdata(&phy->dev);
156 #if IS_ENABLED(CONFIG_GENERIC_PHY)
157 int phy_pm_runtime_get(struct phy *phy);
158 int phy_pm_runtime_get_sync(struct phy *phy);
159 int phy_pm_runtime_put(struct phy *phy);
160 int phy_pm_runtime_put_sync(struct phy *phy);
161 void phy_pm_runtime_allow(struct phy *phy);
162 void phy_pm_runtime_forbid(struct phy *phy);
163 int phy_init(struct phy *phy);
164 int phy_exit(struct phy *phy);
165 int phy_power_on(struct phy *phy);
166 int phy_power_off(struct phy *phy);
167 int phy_set_mode(struct phy *phy, enum phy_mode mode);
168 static inline enum phy_mode phy_get_mode(struct phy *phy)
170 return phy->attrs.mode;
172 int phy_reset(struct phy *phy);
173 int phy_calibrate(struct phy *phy);
174 static inline int phy_get_bus_width(struct phy *phy)
176 return phy->attrs.bus_width;
178 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
180 phy->attrs.bus_width = bus_width;
182 struct phy *phy_get(struct device *dev, const char *string);
183 struct phy *phy_optional_get(struct device *dev, const char *string);
184 struct phy *devm_phy_get(struct device *dev, const char *string);
185 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
186 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
188 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
190 void phy_put(struct phy *phy);
191 void devm_phy_put(struct device *dev, struct phy *phy);
192 struct phy *of_phy_get(struct device_node *np, const char *con_id);
193 struct phy *of_phy_simple_xlate(struct device *dev,
194 struct of_phandle_args *args);
195 struct phy *phy_create(struct device *dev, struct device_node *node,
196 const struct phy_ops *ops);
197 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
198 const struct phy_ops *ops);
199 void phy_destroy(struct phy *phy);
200 void devm_phy_destroy(struct device *dev, struct phy *phy);
201 struct phy_provider *__of_phy_provider_register(struct device *dev,
202 struct device_node *children, struct module *owner,
203 struct phy * (*of_xlate)(struct device *dev,
204 struct of_phandle_args *args));
205 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
206 struct device_node *children, struct module *owner,
207 struct phy * (*of_xlate)(struct device *dev,
208 struct of_phandle_args *args));
209 void of_phy_provider_unregister(struct phy_provider *phy_provider);
210 void devm_of_phy_provider_unregister(struct device *dev,
211 struct phy_provider *phy_provider);
212 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
213 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
215 static inline int phy_pm_runtime_get(struct phy *phy)
222 static inline int phy_pm_runtime_get_sync(struct phy *phy)
229 static inline int phy_pm_runtime_put(struct phy *phy)
236 static inline int phy_pm_runtime_put_sync(struct phy *phy)
243 static inline void phy_pm_runtime_allow(struct phy *phy)
248 static inline void phy_pm_runtime_forbid(struct phy *phy)
253 static inline int phy_init(struct phy *phy)
260 static inline int phy_exit(struct phy *phy)
267 static inline int phy_power_on(struct phy *phy)
274 static inline int phy_power_off(struct phy *phy)
281 static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
288 static inline enum phy_mode phy_get_mode(struct phy *phy)
290 return PHY_MODE_INVALID;
293 static inline int phy_reset(struct phy *phy)
300 static inline int phy_calibrate(struct phy *phy)
307 static inline int phy_get_bus_width(struct phy *phy)
312 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
317 static inline struct phy *phy_get(struct device *dev, const char *string)
319 return ERR_PTR(-ENOSYS);
322 static inline struct phy *phy_optional_get(struct device *dev,
325 return ERR_PTR(-ENOSYS);
328 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
330 return ERR_PTR(-ENOSYS);
333 static inline struct phy *devm_phy_optional_get(struct device *dev,
339 static inline struct phy *devm_of_phy_get(struct device *dev,
340 struct device_node *np,
343 return ERR_PTR(-ENOSYS);
346 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
347 struct device_node *np,
350 return ERR_PTR(-ENOSYS);
353 static inline void phy_put(struct phy *phy)
357 static inline void devm_phy_put(struct device *dev, struct phy *phy)
361 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
363 return ERR_PTR(-ENOSYS);
366 static inline struct phy *of_phy_simple_xlate(struct device *dev,
367 struct of_phandle_args *args)
369 return ERR_PTR(-ENOSYS);
372 static inline struct phy *phy_create(struct device *dev,
373 struct device_node *node,
374 const struct phy_ops *ops)
376 return ERR_PTR(-ENOSYS);
379 static inline struct phy *devm_phy_create(struct device *dev,
380 struct device_node *node,
381 const struct phy_ops *ops)
383 return ERR_PTR(-ENOSYS);
386 static inline void phy_destroy(struct phy *phy)
390 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
394 static inline struct phy_provider *__of_phy_provider_register(
395 struct device *dev, struct device_node *children, struct module *owner,
396 struct phy * (*of_xlate)(struct device *dev,
397 struct of_phandle_args *args))
399 return ERR_PTR(-ENOSYS);
402 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
403 *dev, struct device_node *children, struct module *owner,
404 struct phy * (*of_xlate)(struct device *dev,
405 struct of_phandle_args *args))
407 return ERR_PTR(-ENOSYS);
410 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
414 static inline void devm_of_phy_provider_unregister(struct device *dev,
415 struct phy_provider *phy_provider)
419 phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
423 static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
424 const char *dev_id) { }
427 #endif /* __DRIVERS_PHY_H */