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>
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,
48 * union phy_configure_opts - Opaque generic phy configuration
50 * @mipi_dphy: Configuration set applicable for phys supporting
51 * the MIPI_DPHY phy mode.
53 union phy_configure_opts {
54 struct phy_configure_opts_mipi_dphy mipi_dphy;
58 * struct phy_ops - set of function pointers for performing phy operations
59 * @init: operation to be performed for initializing phy
60 * @exit: operation to be performed while exiting
61 * @power_on: powering on the phy
62 * @power_off: powering off the phy
63 * @set_mode: set the mode of the phy
64 * @reset: resetting the phy
65 * @calibrate: calibrate the phy
66 * @owner: the module owner containing the ops
69 int (*init)(struct phy *phy);
70 int (*exit)(struct phy *phy);
71 int (*power_on)(struct phy *phy);
72 int (*power_off)(struct phy *phy);
73 int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
80 * Used to change the PHY parameters. phy_init() must have
81 * been called on the phy.
83 * Returns: 0 if successful, an negative error code otherwise
85 int (*configure)(struct phy *phy, union phy_configure_opts *opts);
92 * Used to check that the current set of parameters can be
93 * handled by the phy. Implementations are free to tune the
94 * parameters passed as arguments if needed by some
95 * implementation detail or constraints. It must not change
96 * any actual configuration of the PHY, so calling it as many
97 * times as deemed fit by the consumer must have no side
100 * Returns: 0 if the configuration can be applied, an negative
101 * error code otherwise
103 int (*validate)(struct phy *phy, enum phy_mode mode, int submode,
104 union phy_configure_opts *opts);
105 int (*reset)(struct phy *phy);
106 int (*calibrate)(struct phy *phy);
107 struct module *owner;
111 * struct phy_attrs - represents phy attributes
112 * @bus_width: Data path width implemented by PHY
121 * struct phy - represents the phy device
123 * @id: id of the phy device
124 * @ops: function pointers for performing phy operations
125 * @mutex: mutex to protect phy_ops
126 * @init_count: used to protect when the PHY is used by multiple consumers
127 * @power_count: used to protect when the PHY is used by multiple consumers
128 * @attrs: used to specify PHY specific attributes
129 * @pwr: power regulator associated with the phy
134 const struct phy_ops *ops;
138 struct phy_attrs attrs;
139 struct regulator *pwr;
143 * struct phy_provider - represents the phy provider
144 * @dev: phy provider device
145 * @children: can be used to override the default (dev->of_node) child node
146 * @owner: the module owner having of_xlate
147 * @list: to maintain a linked list of PHY providers
148 * @of_xlate: function pointer to obtain phy instance from phy pointer
150 struct phy_provider {
152 struct device_node *children;
153 struct module *owner;
154 struct list_head list;
155 struct phy * (*of_xlate)(struct device *dev,
156 struct of_phandle_args *args);
160 * struct phy_lookup - PHY association in list of phys managed by the phy driver
162 * @dev_id: the device of the association
163 * @con_id: connection ID string on device
164 * @phy: the phy of the association
167 struct list_head node;
173 #define to_phy(a) (container_of((a), struct phy, dev))
175 #define of_phy_provider_register(dev, xlate) \
176 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
178 #define devm_of_phy_provider_register(dev, xlate) \
179 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
181 #define of_phy_provider_register_full(dev, children, xlate) \
182 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
184 #define devm_of_phy_provider_register_full(dev, children, xlate) \
185 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
187 static inline void phy_set_drvdata(struct phy *phy, void *data)
189 dev_set_drvdata(&phy->dev, data);
192 static inline void *phy_get_drvdata(struct phy *phy)
194 return dev_get_drvdata(&phy->dev);
197 #if IS_ENABLED(CONFIG_GENERIC_PHY)
198 int phy_pm_runtime_get(struct phy *phy);
199 int phy_pm_runtime_get_sync(struct phy *phy);
200 int phy_pm_runtime_put(struct phy *phy);
201 int phy_pm_runtime_put_sync(struct phy *phy);
202 void phy_pm_runtime_allow(struct phy *phy);
203 void phy_pm_runtime_forbid(struct phy *phy);
204 int phy_init(struct phy *phy);
205 int phy_exit(struct phy *phy);
206 int phy_power_on(struct phy *phy);
207 int phy_power_off(struct phy *phy);
208 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
209 #define phy_set_mode(phy, mode) \
210 phy_set_mode_ext(phy, mode, 0)
211 int phy_configure(struct phy *phy, union phy_configure_opts *opts);
212 int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
213 union phy_configure_opts *opts);
215 static inline enum phy_mode phy_get_mode(struct phy *phy)
217 return phy->attrs.mode;
219 int phy_reset(struct phy *phy);
220 int phy_calibrate(struct phy *phy);
221 static inline int phy_get_bus_width(struct phy *phy)
223 return phy->attrs.bus_width;
225 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
227 phy->attrs.bus_width = bus_width;
229 struct phy *phy_get(struct device *dev, const char *string);
230 struct phy *phy_optional_get(struct device *dev, const char *string);
231 struct phy *devm_phy_get(struct device *dev, const char *string);
232 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
233 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
235 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
237 void phy_put(struct phy *phy);
238 void devm_phy_put(struct device *dev, struct phy *phy);
239 struct phy *of_phy_get(struct device_node *np, const char *con_id);
240 struct phy *of_phy_simple_xlate(struct device *dev,
241 struct of_phandle_args *args);
242 struct phy *phy_create(struct device *dev, struct device_node *node,
243 const struct phy_ops *ops);
244 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
245 const struct phy_ops *ops);
246 void phy_destroy(struct phy *phy);
247 void devm_phy_destroy(struct device *dev, struct phy *phy);
248 struct phy_provider *__of_phy_provider_register(struct device *dev,
249 struct device_node *children, struct module *owner,
250 struct phy * (*of_xlate)(struct device *dev,
251 struct of_phandle_args *args));
252 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
253 struct device_node *children, struct module *owner,
254 struct phy * (*of_xlate)(struct device *dev,
255 struct of_phandle_args *args));
256 void of_phy_provider_unregister(struct phy_provider *phy_provider);
257 void devm_of_phy_provider_unregister(struct device *dev,
258 struct phy_provider *phy_provider);
259 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
260 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
262 static inline int phy_pm_runtime_get(struct phy *phy)
269 static inline int phy_pm_runtime_get_sync(struct phy *phy)
276 static inline int phy_pm_runtime_put(struct phy *phy)
283 static inline int phy_pm_runtime_put_sync(struct phy *phy)
290 static inline void phy_pm_runtime_allow(struct phy *phy)
295 static inline void phy_pm_runtime_forbid(struct phy *phy)
300 static inline int phy_init(struct phy *phy)
307 static inline int phy_exit(struct phy *phy)
314 static inline int phy_power_on(struct phy *phy)
321 static inline int phy_power_off(struct phy *phy)
328 static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
336 #define phy_set_mode(phy, mode) \
337 phy_set_mode_ext(phy, mode, 0)
339 static inline enum phy_mode phy_get_mode(struct phy *phy)
341 return PHY_MODE_INVALID;
344 static inline int phy_reset(struct phy *phy)
351 static inline int phy_calibrate(struct phy *phy)
358 static inline int phy_configure(struct phy *phy,
359 union phy_configure_opts *opts)
367 static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
368 union phy_configure_opts *opts)
376 static inline int phy_get_bus_width(struct phy *phy)
381 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
386 static inline struct phy *phy_get(struct device *dev, const char *string)
388 return ERR_PTR(-ENOSYS);
391 static inline struct phy *phy_optional_get(struct device *dev,
394 return ERR_PTR(-ENOSYS);
397 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
399 return ERR_PTR(-ENOSYS);
402 static inline struct phy *devm_phy_optional_get(struct device *dev,
408 static inline struct phy *devm_of_phy_get(struct device *dev,
409 struct device_node *np,
412 return ERR_PTR(-ENOSYS);
415 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
416 struct device_node *np,
419 return ERR_PTR(-ENOSYS);
422 static inline void phy_put(struct phy *phy)
426 static inline void devm_phy_put(struct device *dev, struct phy *phy)
430 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
432 return ERR_PTR(-ENOSYS);
435 static inline struct phy *of_phy_simple_xlate(struct device *dev,
436 struct of_phandle_args *args)
438 return ERR_PTR(-ENOSYS);
441 static inline struct phy *phy_create(struct device *dev,
442 struct device_node *node,
443 const struct phy_ops *ops)
445 return ERR_PTR(-ENOSYS);
448 static inline struct phy *devm_phy_create(struct device *dev,
449 struct device_node *node,
450 const struct phy_ops *ops)
452 return ERR_PTR(-ENOSYS);
455 static inline void phy_destroy(struct phy *phy)
459 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
463 static inline struct phy_provider *__of_phy_provider_register(
464 struct device *dev, struct device_node *children, struct module *owner,
465 struct phy * (*of_xlate)(struct device *dev,
466 struct of_phandle_args *args))
468 return ERR_PTR(-ENOSYS);
471 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
472 *dev, struct device_node *children, struct module *owner,
473 struct phy * (*of_xlate)(struct device *dev,
474 struct of_phandle_args *args))
476 return ERR_PTR(-ENOSYS);
479 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
483 static inline void devm_of_phy_provider_unregister(struct device *dev,
484 struct phy_provider *phy_provider)
488 phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
492 static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
493 const char *dev_id) { }
496 #endif /* __DRIVERS_PHY_H */