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>
23 #include <linux/phy/phy-mipi-dphy.h>
35 PHY_MODE_USB_DEVICE_LS,
36 PHY_MODE_USB_DEVICE_FS,
37 PHY_MODE_USB_DEVICE_HS,
38 PHY_MODE_USB_DEVICE_SS,
49 * union phy_configure_opts - Opaque generic phy configuration
51 * @mipi_dphy: Configuration set applicable for phys supporting
52 * the MIPI_DPHY phy mode.
54 union phy_configure_opts {
55 struct phy_configure_opts_mipi_dphy mipi_dphy;
59 * struct phy_ops - set of function pointers for performing phy operations
60 * @init: operation to be performed for initializing phy
61 * @exit: operation to be performed while exiting
62 * @power_on: powering on the phy
63 * @power_off: powering off the phy
64 * @set_mode: set the mode of the phy
65 * @reset: resetting the phy
66 * @calibrate: calibrate the phy
67 * @owner: the module owner containing the ops
70 int (*init)(struct phy *phy);
71 int (*exit)(struct phy *phy);
72 int (*power_on)(struct phy *phy);
73 int (*power_off)(struct phy *phy);
74 int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
81 * Used to change the PHY parameters. phy_init() must have
82 * been called on the phy.
84 * Returns: 0 if successful, an negative error code otherwise
86 int (*configure)(struct phy *phy, union phy_configure_opts *opts);
93 * Used to check that the current set of parameters can be
94 * handled by the phy. Implementations are free to tune the
95 * parameters passed as arguments if needed by some
96 * implementation detail or constraints. It must not change
97 * any actual configuration of the PHY, so calling it as many
98 * times as deemed fit by the consumer must have no side
101 * Returns: 0 if the configuration can be applied, an negative
102 * error code otherwise
104 int (*validate)(struct phy *phy, enum phy_mode mode, int submode,
105 union phy_configure_opts *opts);
106 int (*reset)(struct phy *phy);
107 int (*calibrate)(struct phy *phy);
108 struct module *owner;
112 * struct phy_attrs - represents phy attributes
113 * @bus_width: Data path width implemented by PHY
122 * struct phy - represents the phy device
124 * @id: id of the phy device
125 * @ops: function pointers for performing phy operations
126 * @mutex: mutex to protect phy_ops
127 * @init_count: used to protect when the PHY is used by multiple consumers
128 * @power_count: used to protect when the PHY is used by multiple consumers
129 * @attrs: used to specify PHY specific attributes
130 * @pwr: power regulator associated with the phy
135 const struct phy_ops *ops;
139 struct phy_attrs attrs;
140 struct regulator *pwr;
144 * struct phy_provider - represents the phy provider
145 * @dev: phy provider device
146 * @children: can be used to override the default (dev->of_node) child node
147 * @owner: the module owner having of_xlate
148 * @list: to maintain a linked list of PHY providers
149 * @of_xlate: function pointer to obtain phy instance from phy pointer
151 struct phy_provider {
153 struct device_node *children;
154 struct module *owner;
155 struct list_head list;
156 struct phy * (*of_xlate)(struct device *dev,
157 struct of_phandle_args *args);
161 * struct phy_lookup - PHY association in list of phys managed by the phy driver
163 * @dev_id: the device of the association
164 * @con_id: connection ID string on device
165 * @phy: the phy of the association
168 struct list_head node;
174 #define to_phy(a) (container_of((a), struct phy, dev))
176 #define of_phy_provider_register(dev, xlate) \
177 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
179 #define devm_of_phy_provider_register(dev, xlate) \
180 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
182 #define of_phy_provider_register_full(dev, children, xlate) \
183 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
185 #define devm_of_phy_provider_register_full(dev, children, xlate) \
186 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
188 static inline void phy_set_drvdata(struct phy *phy, void *data)
190 dev_set_drvdata(&phy->dev, data);
193 static inline void *phy_get_drvdata(struct phy *phy)
195 return dev_get_drvdata(&phy->dev);
198 #if IS_ENABLED(CONFIG_GENERIC_PHY)
199 int phy_pm_runtime_get(struct phy *phy);
200 int phy_pm_runtime_get_sync(struct phy *phy);
201 int phy_pm_runtime_put(struct phy *phy);
202 int phy_pm_runtime_put_sync(struct phy *phy);
203 void phy_pm_runtime_allow(struct phy *phy);
204 void phy_pm_runtime_forbid(struct phy *phy);
205 int phy_init(struct phy *phy);
206 int phy_exit(struct phy *phy);
207 int phy_power_on(struct phy *phy);
208 int phy_power_off(struct phy *phy);
209 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
210 #define phy_set_mode(phy, mode) \
211 phy_set_mode_ext(phy, mode, 0)
212 int phy_configure(struct phy *phy, union phy_configure_opts *opts);
213 int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
214 union phy_configure_opts *opts);
216 static inline enum phy_mode phy_get_mode(struct phy *phy)
218 return phy->attrs.mode;
220 int phy_reset(struct phy *phy);
221 int phy_calibrate(struct phy *phy);
222 static inline int phy_get_bus_width(struct phy *phy)
224 return phy->attrs.bus_width;
226 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
228 phy->attrs.bus_width = bus_width;
230 struct phy *phy_get(struct device *dev, const char *string);
231 struct phy *phy_optional_get(struct device *dev, const char *string);
232 struct phy *devm_phy_get(struct device *dev, const char *string);
233 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
234 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
236 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
238 void phy_put(struct phy *phy);
239 void devm_phy_put(struct device *dev, struct phy *phy);
240 struct phy *of_phy_get(struct device_node *np, const char *con_id);
241 struct phy *of_phy_simple_xlate(struct device *dev,
242 struct of_phandle_args *args);
243 struct phy *phy_create(struct device *dev, struct device_node *node,
244 const struct phy_ops *ops);
245 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
246 const struct phy_ops *ops);
247 void phy_destroy(struct phy *phy);
248 void devm_phy_destroy(struct device *dev, struct phy *phy);
249 struct phy_provider *__of_phy_provider_register(struct device *dev,
250 struct device_node *children, struct module *owner,
251 struct phy * (*of_xlate)(struct device *dev,
252 struct of_phandle_args *args));
253 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
254 struct device_node *children, struct module *owner,
255 struct phy * (*of_xlate)(struct device *dev,
256 struct of_phandle_args *args));
257 void of_phy_provider_unregister(struct phy_provider *phy_provider);
258 void devm_of_phy_provider_unregister(struct device *dev,
259 struct phy_provider *phy_provider);
260 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
261 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
263 static inline int phy_pm_runtime_get(struct phy *phy)
270 static inline int phy_pm_runtime_get_sync(struct phy *phy)
277 static inline int phy_pm_runtime_put(struct phy *phy)
284 static inline int phy_pm_runtime_put_sync(struct phy *phy)
291 static inline void phy_pm_runtime_allow(struct phy *phy)
296 static inline void phy_pm_runtime_forbid(struct phy *phy)
301 static inline int phy_init(struct phy *phy)
308 static inline int phy_exit(struct phy *phy)
315 static inline int phy_power_on(struct phy *phy)
322 static inline int phy_power_off(struct phy *phy)
329 static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
337 #define phy_set_mode(phy, mode) \
338 phy_set_mode_ext(phy, mode, 0)
340 static inline enum phy_mode phy_get_mode(struct phy *phy)
342 return PHY_MODE_INVALID;
345 static inline int phy_reset(struct phy *phy)
352 static inline int phy_calibrate(struct phy *phy)
359 static inline int phy_configure(struct phy *phy,
360 union phy_configure_opts *opts)
368 static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
369 union phy_configure_opts *opts)
377 static inline int phy_get_bus_width(struct phy *phy)
382 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
387 static inline struct phy *phy_get(struct device *dev, const char *string)
389 return ERR_PTR(-ENOSYS);
392 static inline struct phy *phy_optional_get(struct device *dev,
395 return ERR_PTR(-ENOSYS);
398 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
400 return ERR_PTR(-ENOSYS);
403 static inline struct phy *devm_phy_optional_get(struct device *dev,
409 static inline struct phy *devm_of_phy_get(struct device *dev,
410 struct device_node *np,
413 return ERR_PTR(-ENOSYS);
416 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
417 struct device_node *np,
420 return ERR_PTR(-ENOSYS);
423 static inline void phy_put(struct phy *phy)
427 static inline void devm_phy_put(struct device *dev, struct phy *phy)
431 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
433 return ERR_PTR(-ENOSYS);
436 static inline struct phy *of_phy_simple_xlate(struct device *dev,
437 struct of_phandle_args *args)
439 return ERR_PTR(-ENOSYS);
442 static inline struct phy *phy_create(struct device *dev,
443 struct device_node *node,
444 const struct phy_ops *ops)
446 return ERR_PTR(-ENOSYS);
449 static inline struct phy *devm_phy_create(struct device *dev,
450 struct device_node *node,
451 const struct phy_ops *ops)
453 return ERR_PTR(-ENOSYS);
456 static inline void phy_destroy(struct phy *phy)
460 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
464 static inline struct phy_provider *__of_phy_provider_register(
465 struct device *dev, struct device_node *children, struct module *owner,
466 struct phy * (*of_xlate)(struct device *dev,
467 struct of_phandle_args *args))
469 return ERR_PTR(-ENOSYS);
472 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
473 *dev, struct device_node *children, struct module *owner,
474 struct phy * (*of_xlate)(struct device *dev,
475 struct of_phandle_args *args))
477 return ERR_PTR(-ENOSYS);
480 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
484 static inline void devm_of_phy_provider_unregister(struct device *dev,
485 struct phy_provider *phy_provider)
489 phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
493 static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
494 const char *dev_id) { }
497 #endif /* __DRIVERS_PHY_H */