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>
33 * struct phy_ops - set of function pointers for performing phy operations
34 * @init: operation to be performed for initializing phy
35 * @exit: operation to be performed while exiting
36 * @power_on: powering on the phy
37 * @power_off: powering off the phy
38 * @set_mode: set the mode of the phy
39 * @owner: the module owner containing the ops
42 int (*init
)(struct phy
*phy
);
43 int (*exit
)(struct phy
*phy
);
44 int (*power_on
)(struct phy
*phy
);
45 int (*power_off
)(struct phy
*phy
);
46 int (*set_mode
)(struct phy
*phy
, enum phy_mode mode
);
51 * struct phy_attrs - represents phy attributes
52 * @bus_width: Data path width implemented by PHY
59 * struct phy - represents the phy device
61 * @id: id of the phy device
62 * @ops: function pointers for performing phy operations
63 * @init_data: list of PHY consumers (non-dt only)
64 * @mutex: mutex to protect phy_ops
65 * @init_count: used to protect when the PHY is used by multiple consumers
66 * @power_count: used to protect when the PHY is used by multiple consumers
67 * @phy_attrs: used to specify PHY specific attributes
72 const struct phy_ops
*ops
;
76 struct phy_attrs attrs
;
77 struct regulator
*pwr
;
81 * struct phy_provider - represents the phy provider
82 * @dev: phy provider device
83 * @owner: the module owner having of_xlate
84 * @of_xlate: function pointer to obtain phy instance from phy pointer
85 * @list: to maintain a linked list of PHY providers
89 struct device_node
*children
;
91 struct list_head list
;
92 struct phy
* (*of_xlate
)(struct device
*dev
,
93 struct of_phandle_args
*args
);
97 struct list_head node
;
103 #define to_phy(a) (container_of((a), struct phy, dev))
105 #define of_phy_provider_register(dev, xlate) \
106 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
108 #define devm_of_phy_provider_register(dev, xlate) \
109 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
111 #define of_phy_provider_register_full(dev, children, xlate) \
112 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
114 #define devm_of_phy_provider_register_full(dev, children, xlate) \
115 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
117 static inline void phy_set_drvdata(struct phy
*phy
, void *data
)
119 dev_set_drvdata(&phy
->dev
, data
);
122 static inline void *phy_get_drvdata(struct phy
*phy
)
124 return dev_get_drvdata(&phy
->dev
);
127 #if IS_ENABLED(CONFIG_GENERIC_PHY)
128 int phy_pm_runtime_get(struct phy
*phy
);
129 int phy_pm_runtime_get_sync(struct phy
*phy
);
130 int phy_pm_runtime_put(struct phy
*phy
);
131 int phy_pm_runtime_put_sync(struct phy
*phy
);
132 void phy_pm_runtime_allow(struct phy
*phy
);
133 void phy_pm_runtime_forbid(struct phy
*phy
);
134 int phy_init(struct phy
*phy
);
135 int phy_exit(struct phy
*phy
);
136 int phy_power_on(struct phy
*phy
);
137 int phy_power_off(struct phy
*phy
);
138 int phy_set_mode(struct phy
*phy
, enum phy_mode mode
);
139 static inline int phy_get_bus_width(struct phy
*phy
)
141 return phy
->attrs
.bus_width
;
143 static inline void phy_set_bus_width(struct phy
*phy
, int bus_width
)
145 phy
->attrs
.bus_width
= bus_width
;
147 struct phy
*phy_get(struct device
*dev
, const char *string
);
148 struct phy
*phy_optional_get(struct device
*dev
, const char *string
);
149 struct phy
*devm_phy_get(struct device
*dev
, const char *string
);
150 struct phy
*devm_phy_optional_get(struct device
*dev
, const char *string
);
151 struct phy
*devm_of_phy_get(struct device
*dev
, struct device_node
*np
,
153 struct phy
*devm_of_phy_get_by_index(struct device
*dev
, struct device_node
*np
,
155 void phy_put(struct phy
*phy
);
156 void devm_phy_put(struct device
*dev
, struct phy
*phy
);
157 struct phy
*of_phy_get(struct device_node
*np
, const char *con_id
);
158 struct phy
*of_phy_simple_xlate(struct device
*dev
,
159 struct of_phandle_args
*args
);
160 struct phy
*phy_create(struct device
*dev
, struct device_node
*node
,
161 const struct phy_ops
*ops
);
162 struct phy
*devm_phy_create(struct device
*dev
, struct device_node
*node
,
163 const struct phy_ops
*ops
);
164 void phy_destroy(struct phy
*phy
);
165 void devm_phy_destroy(struct device
*dev
, struct phy
*phy
);
166 struct phy_provider
*__of_phy_provider_register(struct device
*dev
,
167 struct device_node
*children
, struct module
*owner
,
168 struct phy
* (*of_xlate
)(struct device
*dev
,
169 struct of_phandle_args
*args
));
170 struct phy_provider
*__devm_of_phy_provider_register(struct device
*dev
,
171 struct device_node
*children
, struct module
*owner
,
172 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
);
177 int phy_create_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
);
178 void phy_remove_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
);
180 static inline int phy_pm_runtime_get(struct phy
*phy
)
187 static inline int phy_pm_runtime_get_sync(struct phy
*phy
)
194 static inline int phy_pm_runtime_put(struct phy
*phy
)
201 static inline int phy_pm_runtime_put_sync(struct phy
*phy
)
208 static inline void phy_pm_runtime_allow(struct phy
*phy
)
213 static inline void phy_pm_runtime_forbid(struct phy
*phy
)
218 static inline int phy_init(struct phy
*phy
)
225 static inline int phy_exit(struct phy
*phy
)
232 static inline int phy_power_on(struct phy
*phy
)
239 static inline int phy_power_off(struct phy
*phy
)
246 static inline int phy_set_mode(struct phy
*phy
, enum phy_mode mode
)
253 static inline int phy_get_bus_width(struct phy
*phy
)
258 static inline void phy_set_bus_width(struct phy
*phy
, int bus_width
)
263 static inline struct phy
*phy_get(struct device
*dev
, const char *string
)
265 return ERR_PTR(-ENOSYS
);
268 static inline struct phy
*phy_optional_get(struct device
*dev
,
271 return ERR_PTR(-ENOSYS
);
274 static inline struct phy
*devm_phy_get(struct device
*dev
, const char *string
)
276 return ERR_PTR(-ENOSYS
);
279 static inline struct phy
*devm_phy_optional_get(struct device
*dev
,
282 return ERR_PTR(-ENOSYS
);
285 static inline struct phy
*devm_of_phy_get(struct device
*dev
,
286 struct device_node
*np
,
289 return ERR_PTR(-ENOSYS
);
292 static inline struct phy
*devm_of_phy_get_by_index(struct device
*dev
,
293 struct device_node
*np
,
296 return ERR_PTR(-ENOSYS
);
299 static inline void phy_put(struct phy
*phy
)
303 static inline void devm_phy_put(struct device
*dev
, struct phy
*phy
)
307 static inline struct phy
*of_phy_get(struct device_node
*np
, const char *con_id
)
309 return ERR_PTR(-ENOSYS
);
312 static inline struct phy
*of_phy_simple_xlate(struct device
*dev
,
313 struct of_phandle_args
*args
)
315 return ERR_PTR(-ENOSYS
);
318 static inline struct phy
*phy_create(struct device
*dev
,
319 struct device_node
*node
,
320 const struct phy_ops
*ops
)
322 return ERR_PTR(-ENOSYS
);
325 static inline struct phy
*devm_phy_create(struct device
*dev
,
326 struct device_node
*node
,
327 const struct phy_ops
*ops
)
329 return ERR_PTR(-ENOSYS
);
332 static inline void phy_destroy(struct phy
*phy
)
336 static inline void devm_phy_destroy(struct device
*dev
, struct phy
*phy
)
340 static inline struct phy_provider
*__of_phy_provider_register(
341 struct device
*dev
, struct device_node
*children
, struct module
*owner
,
342 struct phy
* (*of_xlate
)(struct device
*dev
,
343 struct of_phandle_args
*args
))
345 return ERR_PTR(-ENOSYS
);
348 static inline struct phy_provider
*__devm_of_phy_provider_register(struct device
349 *dev
, struct device_node
*children
, struct module
*owner
,
350 struct phy
* (*of_xlate
)(struct device
*dev
,
351 struct of_phandle_args
*args
))
353 return ERR_PTR(-ENOSYS
);
356 static inline void of_phy_provider_unregister(struct phy_provider
*phy_provider
)
360 static inline void devm_of_phy_provider_unregister(struct device
*dev
,
361 struct phy_provider
*phy_provider
)
365 phy_create_lookup(struct phy
*phy
, const char *con_id
, const char *dev_id
)
369 static inline void phy_remove_lookup(struct phy
*phy
, const char *con_id
,
370 const char *dev_id
) { }
373 #endif /* __DRIVERS_PHY_H */
This page took 0.058783 seconds and 5 git commands to generate.