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>
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_attrs - represents phy attributes
42 * @bus_width: Data path width implemented by PHY
49 * struct phy - represents the phy device
51 * @id: id of the phy device
52 * @ops: function pointers for performing phy operations
53 * @init_data: list of PHY consumers (non-dt only)
54 * @mutex: mutex to protect phy_ops
55 * @init_count: used to protect when the PHY is used by multiple consumers
56 * @power_count: used to protect when the PHY is used by multiple consumers
57 * @phy_attrs: used to specify PHY specific attributes
62 const struct phy_ops *ops;
63 struct phy_init_data *init_data;
67 struct phy_attrs attrs;
71 * struct phy_provider - represents the phy provider
72 * @dev: phy provider device
73 * @owner: the module owner having of_xlate
74 * @of_xlate: function pointer to obtain phy instance from phy pointer
75 * @list: to maintain a linked list of PHY providers
80 struct list_head list;
81 struct phy * (*of_xlate)(struct device *dev,
82 struct of_phandle_args *args);
86 * struct phy_consumer - represents the phy consumer
87 * @dev_name: the device name of the controller that will use this PHY device
88 * @port: name given to the consumer port
96 * struct phy_init_data - contains the list of PHY consumers
97 * @num_consumers: number of consumers for this PHY device
98 * @consumers: list of PHY consumers
100 struct phy_init_data {
101 unsigned int num_consumers;
102 struct phy_consumer *consumers;
105 #define PHY_CONSUMER(_dev_name, _port) \
107 .dev_name = _dev_name, \
111 #define to_phy(dev) (container_of((dev), struct phy, dev))
113 #define of_phy_provider_register(dev, xlate) \
114 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
116 #define devm_of_phy_provider_register(dev, xlate) \
117 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
119 static inline void phy_set_drvdata(struct phy *phy, void *data)
121 dev_set_drvdata(&phy->dev, data);
124 static inline void *phy_get_drvdata(struct phy *phy)
126 return dev_get_drvdata(&phy->dev);
129 #if IS_ENABLED(CONFIG_GENERIC_PHY)
130 int phy_pm_runtime_get(struct phy *phy);
131 int phy_pm_runtime_get_sync(struct phy *phy);
132 int phy_pm_runtime_put(struct phy *phy);
133 int phy_pm_runtime_put_sync(struct phy *phy);
134 void phy_pm_runtime_allow(struct phy *phy);
135 void phy_pm_runtime_forbid(struct phy *phy);
136 int phy_init(struct phy *phy);
137 int phy_exit(struct phy *phy);
138 int phy_power_on(struct phy *phy);
139 int phy_power_off(struct phy *phy);
140 static inline int phy_get_bus_width(struct phy *phy)
142 return phy->attrs.bus_width;
144 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
146 phy->attrs.bus_width = bus_width;
148 struct phy *phy_get(struct device *dev, const char *string);
149 struct phy *phy_optional_get(struct device *dev, const char *string);
150 struct phy *devm_phy_get(struct device *dev, const char *string);
151 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
152 void phy_put(struct phy *phy);
153 void devm_phy_put(struct device *dev, struct phy *phy);
154 struct phy *of_phy_simple_xlate(struct device *dev,
155 struct of_phandle_args *args);
156 struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
157 struct phy_init_data *init_data);
158 struct phy *devm_phy_create(struct device *dev,
159 const struct phy_ops *ops, struct phy_init_data *init_data);
160 void phy_destroy(struct phy *phy);
161 void devm_phy_destroy(struct device *dev, struct phy *phy);
162 struct phy_provider *__of_phy_provider_register(struct device *dev,
163 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
164 struct of_phandle_args *args));
165 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
166 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
167 struct of_phandle_args *args));
168 void of_phy_provider_unregister(struct phy_provider *phy_provider);
169 void devm_of_phy_provider_unregister(struct device *dev,
170 struct phy_provider *phy_provider);
172 static inline int phy_pm_runtime_get(struct phy *phy)
177 static inline int phy_pm_runtime_get_sync(struct phy *phy)
182 static inline int phy_pm_runtime_put(struct phy *phy)
187 static inline int phy_pm_runtime_put_sync(struct phy *phy)
192 static inline void phy_pm_runtime_allow(struct phy *phy)
197 static inline void phy_pm_runtime_forbid(struct phy *phy)
202 static inline int phy_init(struct phy *phy)
207 static inline int phy_exit(struct phy *phy)
212 static inline int phy_power_on(struct phy *phy)
217 static inline int phy_power_off(struct phy *phy)
222 static inline int phy_get_bus_width(struct phy *phy)
227 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
232 static inline struct phy *phy_get(struct device *dev, const char *string)
234 return ERR_PTR(-ENOSYS);
237 static inline struct phy *phy_optional_get(struct device *dev,
240 return ERR_PTR(-ENOSYS);
243 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
245 return ERR_PTR(-ENOSYS);
248 static inline struct phy *devm_phy_optional_get(struct device *dev,
251 return ERR_PTR(-ENOSYS);
254 static inline void phy_put(struct phy *phy)
258 static inline void devm_phy_put(struct device *dev, struct phy *phy)
262 static inline struct phy *of_phy_simple_xlate(struct device *dev,
263 struct of_phandle_args *args)
265 return ERR_PTR(-ENOSYS);
268 static inline struct phy *phy_create(struct device *dev,
269 const struct phy_ops *ops, struct phy_init_data *init_data)
271 return ERR_PTR(-ENOSYS);
274 static inline struct phy *devm_phy_create(struct device *dev,
275 const struct phy_ops *ops, struct phy_init_data *init_data)
277 return ERR_PTR(-ENOSYS);
280 static inline void phy_destroy(struct phy *phy)
284 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
288 static inline struct phy_provider *__of_phy_provider_register(
289 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
290 struct device *dev, struct of_phandle_args *args))
292 return ERR_PTR(-ENOSYS);
295 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
296 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
297 struct of_phandle_args *args))
299 return ERR_PTR(-ENOSYS);
302 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
306 static inline void devm_of_phy_provider_unregister(struct device *dev,
307 struct phy_provider *phy_provider)
312 #endif /* __DRIVERS_PHY_H */