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>
37 * struct phy_ops - set of function pointers for performing phy operations
38 * @init: operation to be performed for initializing phy
39 * @exit: operation to be performed while exiting
40 * @power_on: powering on the phy
41 * @power_off: powering off the phy
42 * @set_mode: set the mode of the phy
43 * @reset: resetting the phy
44 * @calibrate: calibrate the phy
45 * @owner: the module owner containing the ops
48 int (*init
)(struct phy
*phy
);
49 int (*exit
)(struct phy
*phy
);
50 int (*power_on
)(struct phy
*phy
);
51 int (*power_off
)(struct phy
*phy
);
52 int (*set_mode
)(struct phy
*phy
, enum phy_mode mode
);
53 int (*reset
)(struct phy
*phy
);
54 int (*calibrate
)(struct phy
*phy
);
59 * struct phy_attrs - represents phy attributes
60 * @bus_width: Data path width implemented by PHY
67 * struct phy - represents the phy device
69 * @id: id of the phy device
70 * @ops: function pointers for performing phy operations
71 * @init_data: list of PHY consumers (non-dt only)
72 * @mutex: mutex to protect phy_ops
73 * @init_count: used to protect when the PHY is used by multiple consumers
74 * @power_count: used to protect when the PHY is used by multiple consumers
75 * @phy_attrs: used to specify PHY specific attributes
80 const struct phy_ops
*ops
;
84 struct phy_attrs attrs
;
85 struct regulator
*pwr
;
89 * struct phy_provider - represents the phy provider
90 * @dev: phy provider device
91 * @owner: the module owner having of_xlate
92 * @of_xlate: function pointer to obtain phy instance from phy pointer
93 * @list: to maintain a linked list of PHY providers
97 struct device_node
*children
;
99 struct list_head list
;
100 struct phy
* (*of_xlate
)(struct device
*dev
,
101 struct of_phandle_args
*args
);
105 struct list_head node
;
111 #define to_phy(a) (container_of((a), struct phy, dev))
113 #define of_phy_provider_register(dev, xlate) \
114 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
116 #define devm_of_phy_provider_register(dev, xlate) \
117 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
119 #define of_phy_provider_register_full(dev, children, xlate) \
120 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
122 #define devm_of_phy_provider_register_full(dev, children, xlate) \
123 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
125 static inline void phy_set_drvdata(struct phy
*phy
, void *data
)
127 dev_set_drvdata(&phy
->dev
, data
);
130 static inline void *phy_get_drvdata(struct phy
*phy
)
132 return dev_get_drvdata(&phy
->dev
);
135 #if IS_ENABLED(CONFIG_GENERIC_PHY)
136 int phy_pm_runtime_get(struct phy
*phy
);
137 int phy_pm_runtime_get_sync(struct phy
*phy
);
138 int phy_pm_runtime_put(struct phy
*phy
);
139 int phy_pm_runtime_put_sync(struct phy
*phy
);
140 void phy_pm_runtime_allow(struct phy
*phy
);
141 void phy_pm_runtime_forbid(struct phy
*phy
);
142 int phy_init(struct phy
*phy
);
143 int phy_exit(struct phy
*phy
);
144 int phy_power_on(struct phy
*phy
);
145 int phy_power_off(struct phy
*phy
);
146 int phy_set_mode(struct phy
*phy
, enum phy_mode mode
);
147 int phy_reset(struct phy
*phy
);
148 int phy_calibrate(struct phy
*phy
);
149 static inline int phy_get_bus_width(struct phy
*phy
)
151 return phy
->attrs
.bus_width
;
153 static inline void phy_set_bus_width(struct phy
*phy
, int bus_width
)
155 phy
->attrs
.bus_width
= bus_width
;
157 struct phy
*phy_get(struct device
*dev
, const char *string
);
158 struct phy
*phy_optional_get(struct device
*dev
, const char *string
);
159 struct phy
*devm_phy_get(struct device
*dev
, const char *string
);
160 struct phy
*devm_phy_optional_get(struct device
*dev
, const char *string
);
161 struct phy
*devm_of_phy_get(struct device
*dev
, struct device_node
*np
,
163 struct phy
*devm_of_phy_get_by_index(struct device
*dev
, struct device_node
*np
,
165 void phy_put(struct phy
*phy
);
166 void devm_phy_put(struct device
*dev
, struct phy
*phy
);
167 struct phy
*of_phy_get(struct device_node
*np
, const char *con_id
);
168 struct phy
*of_phy_simple_xlate(struct device
*dev
,
169 struct of_phandle_args
*args
);
170 struct phy
*phy_create(struct device
*dev
, struct device_node
*node
,
171 const struct phy_ops
*ops
);
172 struct phy
*devm_phy_create(struct device
*dev
, struct device_node
*node
,
173 const struct phy_ops
*ops
);
174 void phy_destroy(struct phy
*phy
);
175 void devm_phy_destroy(struct device
*dev
, struct phy
*phy
);
176 struct phy_provider
*__of_phy_provider_register(struct device
*dev
,
177 struct device_node
*children
, struct module
*owner
,
178 struct phy
* (*of_xlate
)(struct device
*dev
,
179 struct of_phandle_args
*args
));
180 struct phy_provider
*__devm_of_phy_provider_register(struct device
*dev
,
181 struct device_node
*children
, struct module
*owner
,
182 struct phy
* (*of_xlate
)(struct device
*dev
,
183 struct of_phandle_args
*args
));
184 void of_phy_provider_unregister(struct phy_provider
*phy_provider
);
185 void devm_of_phy_provider_unregister(struct device
*dev
,
186 struct phy_provider
*phy_provider
);
187 int phy_create_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
);
188 void phy_remove_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
);
190 static inline int phy_pm_runtime_get(struct phy
*phy
)
197 static inline int phy_pm_runtime_get_sync(struct phy
*phy
)
204 static inline int phy_pm_runtime_put(struct phy
*phy
)
211 static inline int phy_pm_runtime_put_sync(struct phy
*phy
)
218 static inline void phy_pm_runtime_allow(struct phy
*phy
)
223 static inline void phy_pm_runtime_forbid(struct phy
*phy
)
228 static inline int phy_init(struct phy
*phy
)
235 static inline int phy_exit(struct phy
*phy
)
242 static inline int phy_power_on(struct phy
*phy
)
249 static inline int phy_power_off(struct phy
*phy
)
256 static inline int phy_set_mode(struct phy
*phy
, enum phy_mode mode
)
263 static inline int phy_reset(struct phy
*phy
)
270 static inline int phy_calibrate(struct phy
*phy
)
277 static inline int phy_get_bus_width(struct phy
*phy
)
282 static inline void phy_set_bus_width(struct phy
*phy
, int bus_width
)
287 static inline struct phy
*phy_get(struct device
*dev
, const char *string
)
289 return ERR_PTR(-ENOSYS
);
292 static inline struct phy
*phy_optional_get(struct device
*dev
,
295 return ERR_PTR(-ENOSYS
);
298 static inline struct phy
*devm_phy_get(struct device
*dev
, const char *string
)
300 return ERR_PTR(-ENOSYS
);
303 static inline struct phy
*devm_phy_optional_get(struct device
*dev
,
309 static inline struct phy
*devm_of_phy_get(struct device
*dev
,
310 struct device_node
*np
,
313 return ERR_PTR(-ENOSYS
);
316 static inline struct phy
*devm_of_phy_get_by_index(struct device
*dev
,
317 struct device_node
*np
,
320 return ERR_PTR(-ENOSYS
);
323 static inline void phy_put(struct phy
*phy
)
327 static inline void devm_phy_put(struct device
*dev
, struct phy
*phy
)
331 static inline struct phy
*of_phy_get(struct device_node
*np
, const char *con_id
)
333 return ERR_PTR(-ENOSYS
);
336 static inline struct phy
*of_phy_simple_xlate(struct device
*dev
,
337 struct of_phandle_args
*args
)
339 return ERR_PTR(-ENOSYS
);
342 static inline struct phy
*phy_create(struct device
*dev
,
343 struct device_node
*node
,
344 const struct phy_ops
*ops
)
346 return ERR_PTR(-ENOSYS
);
349 static inline struct phy
*devm_phy_create(struct device
*dev
,
350 struct device_node
*node
,
351 const struct phy_ops
*ops
)
353 return ERR_PTR(-ENOSYS
);
356 static inline void phy_destroy(struct phy
*phy
)
360 static inline void devm_phy_destroy(struct device
*dev
, struct phy
*phy
)
364 static inline struct phy_provider
*__of_phy_provider_register(
365 struct device
*dev
, struct device_node
*children
, struct module
*owner
,
366 struct phy
* (*of_xlate
)(struct device
*dev
,
367 struct of_phandle_args
*args
))
369 return ERR_PTR(-ENOSYS
);
372 static inline struct phy_provider
*__devm_of_phy_provider_register(struct device
373 *dev
, struct device_node
*children
, struct module
*owner
,
374 struct phy
* (*of_xlate
)(struct device
*dev
,
375 struct of_phandle_args
*args
))
377 return ERR_PTR(-ENOSYS
);
380 static inline void of_phy_provider_unregister(struct phy_provider
*phy_provider
)
384 static inline void devm_of_phy_provider_unregister(struct device
*dev
,
385 struct phy_provider
*phy_provider
)
389 phy_create_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
)
393 static inline void phy_remove_lookup(struct phy
*phy
, const char *con_id
,
394 const char *dev_id
) { }
397 #endif /* __DRIVERS_PHY_H */