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;
64 struct phy_init_data *init_data;
68 struct phy_attrs attrs;
69 struct regulator *pwr;
73 * struct phy_provider - represents the phy provider
74 * @dev: phy provider device
75 * @owner: the module owner having of_xlate
76 * @of_xlate: function pointer to obtain phy instance from phy pointer
77 * @list: to maintain a linked list of PHY providers
82 struct list_head list;
83 struct phy * (*of_xlate)(struct device *dev,
84 struct of_phandle_args *args);
88 * struct phy_consumer - represents the phy consumer
89 * @dev_name: the device name of the controller that will use this PHY device
90 * @port: name given to the consumer port
98 * struct phy_init_data - contains the list of PHY consumers
99 * @num_consumers: number of consumers for this PHY device
100 * @consumers: list of PHY consumers
102 struct phy_init_data {
103 unsigned int num_consumers;
104 struct phy_consumer *consumers;
107 #define PHY_CONSUMER(_dev_name, _port) \
109 .dev_name = _dev_name, \
113 #define to_phy(dev) (container_of((dev), struct phy, dev))
115 #define of_phy_provider_register(dev, xlate) \
116 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
118 #define devm_of_phy_provider_register(dev, xlate) \
119 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
121 static inline void phy_set_drvdata(struct phy *phy, void *data)
123 dev_set_drvdata(&phy->dev, data);
126 static inline void *phy_get_drvdata(struct phy *phy)
128 return dev_get_drvdata(&phy->dev);
131 #if IS_ENABLED(CONFIG_GENERIC_PHY)
132 int phy_pm_runtime_get(struct phy *phy);
133 int phy_pm_runtime_get_sync(struct phy *phy);
134 int phy_pm_runtime_put(struct phy *phy);
135 int phy_pm_runtime_put_sync(struct phy *phy);
136 void phy_pm_runtime_allow(struct phy *phy);
137 void phy_pm_runtime_forbid(struct phy *phy);
138 int phy_init(struct phy *phy);
139 int phy_exit(struct phy *phy);
140 int phy_power_on(struct phy *phy);
141 int phy_power_off(struct phy *phy);
142 static inline int phy_get_bus_width(struct phy *phy)
144 return phy->attrs.bus_width;
146 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
148 phy->attrs.bus_width = bus_width;
150 struct phy *phy_get(struct device *dev, const char *string);
151 struct phy *phy_optional_get(struct device *dev, const char *string);
152 struct phy *devm_phy_get(struct device *dev, const char *string);
153 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
154 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
156 void phy_put(struct phy *phy);
157 void devm_phy_put(struct device *dev, struct phy *phy);
158 struct phy *of_phy_get(struct device_node *np, const char *con_id);
159 struct phy *of_phy_simple_xlate(struct device *dev,
160 struct of_phandle_args *args);
161 struct phy *phy_create(struct device *dev, struct device_node *node,
162 const struct phy_ops *ops,
163 struct phy_init_data *init_data);
164 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
165 const struct phy_ops *ops, struct phy_init_data *init_data);
166 void phy_destroy(struct phy *phy);
167 void devm_phy_destroy(struct device *dev, struct phy *phy);
168 struct phy_provider *__of_phy_provider_register(struct device *dev,
169 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
170 struct of_phandle_args *args));
171 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
172 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
173 struct of_phandle_args *args));
174 void of_phy_provider_unregister(struct phy_provider *phy_provider);
175 void devm_of_phy_provider_unregister(struct device *dev,
176 struct phy_provider *phy_provider);
178 static inline int phy_pm_runtime_get(struct phy *phy)
185 static inline int phy_pm_runtime_get_sync(struct phy *phy)
192 static inline int phy_pm_runtime_put(struct phy *phy)
199 static inline int phy_pm_runtime_put_sync(struct phy *phy)
206 static inline void phy_pm_runtime_allow(struct phy *phy)
211 static inline void phy_pm_runtime_forbid(struct phy *phy)
216 static inline int phy_init(struct phy *phy)
223 static inline int phy_exit(struct phy *phy)
230 static inline int phy_power_on(struct phy *phy)
237 static inline int phy_power_off(struct phy *phy)
244 static inline int phy_get_bus_width(struct phy *phy)
249 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
254 static inline struct phy *phy_get(struct device *dev, const char *string)
256 return ERR_PTR(-ENOSYS);
259 static inline struct phy *phy_optional_get(struct device *dev,
262 return ERR_PTR(-ENOSYS);
265 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
267 return ERR_PTR(-ENOSYS);
270 static inline struct phy *devm_phy_optional_get(struct device *dev,
273 return ERR_PTR(-ENOSYS);
276 static inline struct phy *devm_of_phy_get(struct device *dev,
277 struct device_node *np,
280 return ERR_PTR(-ENOSYS);
283 static inline void phy_put(struct phy *phy)
287 static inline void devm_phy_put(struct device *dev, struct phy *phy)
291 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
293 return ERR_PTR(-ENOSYS);
296 static inline struct phy *of_phy_simple_xlate(struct device *dev,
297 struct of_phandle_args *args)
299 return ERR_PTR(-ENOSYS);
302 static inline struct phy *phy_create(struct device *dev,
303 struct device_node *node,
304 const struct phy_ops *ops,
305 struct phy_init_data *init_data)
307 return ERR_PTR(-ENOSYS);
310 static inline struct phy *devm_phy_create(struct device *dev,
311 struct device_node *node,
312 const struct phy_ops *ops,
313 struct phy_init_data *init_data)
315 return ERR_PTR(-ENOSYS);
318 static inline void phy_destroy(struct phy *phy)
322 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
326 static inline struct phy_provider *__of_phy_provider_register(
327 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
328 struct device *dev, struct of_phandle_args *args))
330 return ERR_PTR(-ENOSYS);
333 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
334 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
335 struct of_phandle_args *args))
337 return ERR_PTR(-ENOSYS);
340 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
344 static inline void devm_of_phy_provider_unregister(struct device *dev,
345 struct phy_provider *phy_provider)
350 #endif /* __DRIVERS_PHY_H */