Commit | Line | Data |
---|---|---|
ff764963 KVA |
1 | /* |
2 | * phy.h -- generic phy header file | |
3 | * | |
4 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com | |
5 | * | |
6 | * Author: Kishon Vijay Abraham I <kishon@ti.com> | |
7 | * | |
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. | |
12 | */ | |
13 | ||
14 | #ifndef __DRIVERS_PHY_H | |
15 | #define __DRIVERS_PHY_H | |
16 | ||
17 | #include <linux/err.h> | |
18 | #include <linux/of.h> | |
19 | #include <linux/device.h> | |
20 | #include <linux/pm_runtime.h> | |
3be88125 | 21 | #include <linux/regulator/consumer.h> |
ff764963 KVA |
22 | |
23 | struct phy; | |
24 | ||
25 | /** | |
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 | |
32 | */ | |
33 | struct phy_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); | |
38 | struct module *owner; | |
39 | }; | |
40 | ||
8feed347 MP |
41 | /** |
42 | * struct phy_attrs - represents phy attributes | |
43 | * @bus_width: Data path width implemented by PHY | |
44 | */ | |
45 | struct phy_attrs { | |
46 | u32 bus_width; | |
47 | }; | |
48 | ||
ff764963 KVA |
49 | /** |
50 | * struct phy - represents the phy device | |
51 | * @dev: 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 | |
8feed347 | 58 | * @phy_attrs: used to specify PHY specific attributes |
ff764963 KVA |
59 | */ |
60 | struct phy { | |
61 | struct device dev; | |
62 | int id; | |
63 | const struct phy_ops *ops; | |
64 | struct phy_init_data *init_data; | |
65 | struct mutex mutex; | |
66 | int init_count; | |
67 | int power_count; | |
8feed347 | 68 | struct phy_attrs attrs; |
3be88125 | 69 | struct regulator *pwr; |
ff764963 KVA |
70 | }; |
71 | ||
72 | /** | |
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 | |
78 | */ | |
79 | struct phy_provider { | |
80 | struct device *dev; | |
81 | struct module *owner; | |
82 | struct list_head list; | |
83 | struct phy * (*of_xlate)(struct device *dev, | |
84 | struct of_phandle_args *args); | |
85 | }; | |
86 | ||
87 | /** | |
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 | |
91 | */ | |
92 | struct phy_consumer { | |
93 | const char *dev_name; | |
94 | const char *port; | |
95 | }; | |
96 | ||
97 | /** | |
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 | |
101 | */ | |
102 | struct phy_init_data { | |
103 | unsigned int num_consumers; | |
104 | struct phy_consumer *consumers; | |
105 | }; | |
106 | ||
107 | #define PHY_CONSUMER(_dev_name, _port) \ | |
108 | { \ | |
109 | .dev_name = _dev_name, \ | |
110 | .port = _port, \ | |
111 | } | |
112 | ||
113 | #define to_phy(dev) (container_of((dev), struct phy, dev)) | |
114 | ||
115 | #define of_phy_provider_register(dev, xlate) \ | |
116 | __of_phy_provider_register((dev), THIS_MODULE, (xlate)) | |
117 | ||
118 | #define devm_of_phy_provider_register(dev, xlate) \ | |
119 | __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) | |
120 | ||
121 | static inline void phy_set_drvdata(struct phy *phy, void *data) | |
122 | { | |
123 | dev_set_drvdata(&phy->dev, data); | |
124 | } | |
125 | ||
126 | static inline void *phy_get_drvdata(struct phy *phy) | |
127 | { | |
128 | return dev_get_drvdata(&phy->dev); | |
129 | } | |
130 | ||
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); | |
8feed347 MP |
142 | static inline int phy_get_bus_width(struct phy *phy) |
143 | { | |
144 | return phy->attrs.bus_width; | |
145 | } | |
146 | static inline void phy_set_bus_width(struct phy *phy, int bus_width) | |
147 | { | |
148 | phy->attrs.bus_width = bus_width; | |
149 | } | |
ff764963 | 150 | struct phy *phy_get(struct device *dev, const char *string); |
788a4d56 | 151 | struct phy *phy_optional_get(struct device *dev, const char *string); |
ff764963 | 152 | struct phy *devm_phy_get(struct device *dev, const char *string); |
788a4d56 | 153 | struct phy *devm_phy_optional_get(struct device *dev, const char *string); |
b5d682f4 KD |
154 | struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, |
155 | const char *con_id); | |
ff764963 KVA |
156 | void phy_put(struct phy *phy); |
157 | void devm_phy_put(struct device *dev, struct phy *phy); | |
0b3f3b2c | 158 | struct phy *of_phy_get(struct device_node *np, const char *con_id); |
ff764963 KVA |
159 | struct phy *of_phy_simple_xlate(struct device *dev, |
160 | struct of_phandle_args *args); | |
161 | struct phy *phy_create(struct device *dev, const struct phy_ops *ops, | |
162 | struct phy_init_data *init_data); | |
163 | struct phy *devm_phy_create(struct device *dev, | |
164 | const struct phy_ops *ops, struct phy_init_data *init_data); | |
165 | void phy_destroy(struct phy *phy); | |
166 | void devm_phy_destroy(struct device *dev, struct phy *phy); | |
167 | struct phy_provider *__of_phy_provider_register(struct device *dev, | |
168 | struct module *owner, 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 module *owner, struct phy * (*of_xlate)(struct device *dev, | |
172 | struct of_phandle_args *args)); | |
173 | void of_phy_provider_unregister(struct phy_provider *phy_provider); | |
174 | void devm_of_phy_provider_unregister(struct device *dev, | |
175 | struct phy_provider *phy_provider); | |
176 | #else | |
177 | static inline int phy_pm_runtime_get(struct phy *phy) | |
178 | { | |
2b97789f GS |
179 | if (!phy) |
180 | return 0; | |
ff764963 KVA |
181 | return -ENOSYS; |
182 | } | |
183 | ||
184 | static inline int phy_pm_runtime_get_sync(struct phy *phy) | |
185 | { | |
2b97789f GS |
186 | if (!phy) |
187 | return 0; | |
ff764963 KVA |
188 | return -ENOSYS; |
189 | } | |
190 | ||
191 | static inline int phy_pm_runtime_put(struct phy *phy) | |
192 | { | |
2b97789f GS |
193 | if (!phy) |
194 | return 0; | |
ff764963 KVA |
195 | return -ENOSYS; |
196 | } | |
197 | ||
198 | static inline int phy_pm_runtime_put_sync(struct phy *phy) | |
199 | { | |
2b97789f GS |
200 | if (!phy) |
201 | return 0; | |
ff764963 KVA |
202 | return -ENOSYS; |
203 | } | |
204 | ||
205 | static inline void phy_pm_runtime_allow(struct phy *phy) | |
206 | { | |
207 | return; | |
208 | } | |
209 | ||
210 | static inline void phy_pm_runtime_forbid(struct phy *phy) | |
211 | { | |
212 | return; | |
213 | } | |
214 | ||
215 | static inline int phy_init(struct phy *phy) | |
216 | { | |
2b97789f GS |
217 | if (!phy) |
218 | return 0; | |
ff764963 KVA |
219 | return -ENOSYS; |
220 | } | |
221 | ||
222 | static inline int phy_exit(struct phy *phy) | |
223 | { | |
2b97789f GS |
224 | if (!phy) |
225 | return 0; | |
ff764963 KVA |
226 | return -ENOSYS; |
227 | } | |
228 | ||
229 | static inline int phy_power_on(struct phy *phy) | |
230 | { | |
2b97789f GS |
231 | if (!phy) |
232 | return 0; | |
ff764963 KVA |
233 | return -ENOSYS; |
234 | } | |
235 | ||
236 | static inline int phy_power_off(struct phy *phy) | |
237 | { | |
2b97789f GS |
238 | if (!phy) |
239 | return 0; | |
ff764963 KVA |
240 | return -ENOSYS; |
241 | } | |
242 | ||
8feed347 MP |
243 | static inline int phy_get_bus_width(struct phy *phy) |
244 | { | |
245 | return -ENOSYS; | |
246 | } | |
247 | ||
248 | static inline void phy_set_bus_width(struct phy *phy, int bus_width) | |
249 | { | |
250 | return; | |
251 | } | |
252 | ||
ff764963 KVA |
253 | static inline struct phy *phy_get(struct device *dev, const char *string) |
254 | { | |
255 | return ERR_PTR(-ENOSYS); | |
256 | } | |
257 | ||
788a4d56 AL |
258 | static inline struct phy *phy_optional_get(struct device *dev, |
259 | const char *string) | |
260 | { | |
261 | return ERR_PTR(-ENOSYS); | |
262 | } | |
263 | ||
ff764963 KVA |
264 | static inline struct phy *devm_phy_get(struct device *dev, const char *string) |
265 | { | |
266 | return ERR_PTR(-ENOSYS); | |
267 | } | |
268 | ||
788a4d56 AL |
269 | static inline struct phy *devm_phy_optional_get(struct device *dev, |
270 | const char *string) | |
271 | { | |
272 | return ERR_PTR(-ENOSYS); | |
273 | } | |
274 | ||
b5d682f4 KD |
275 | static inline struct phy *devm_of_phy_get(struct device *dev, |
276 | struct device_node *np, | |
277 | const char *con_id) | |
278 | { | |
279 | return ERR_PTR(-ENOSYS); | |
280 | } | |
281 | ||
ff764963 KVA |
282 | static inline void phy_put(struct phy *phy) |
283 | { | |
284 | } | |
285 | ||
286 | static inline void devm_phy_put(struct device *dev, struct phy *phy) | |
287 | { | |
288 | } | |
289 | ||
0b3f3b2c KD |
290 | static inline struct phy *of_phy_get(struct device_node *np, const char *con_id) |
291 | { | |
292 | return ERR_PTR(-ENOSYS); | |
293 | } | |
294 | ||
ff764963 KVA |
295 | static inline struct phy *of_phy_simple_xlate(struct device *dev, |
296 | struct of_phandle_args *args) | |
297 | { | |
298 | return ERR_PTR(-ENOSYS); | |
299 | } | |
300 | ||
301 | static inline struct phy *phy_create(struct device *dev, | |
302 | const struct phy_ops *ops, struct phy_init_data *init_data) | |
303 | { | |
304 | return ERR_PTR(-ENOSYS); | |
305 | } | |
306 | ||
307 | static inline struct phy *devm_phy_create(struct device *dev, | |
308 | const struct phy_ops *ops, struct phy_init_data *init_data) | |
309 | { | |
310 | return ERR_PTR(-ENOSYS); | |
311 | } | |
312 | ||
313 | static inline void phy_destroy(struct phy *phy) | |
314 | { | |
315 | } | |
316 | ||
317 | static inline void devm_phy_destroy(struct device *dev, struct phy *phy) | |
318 | { | |
319 | } | |
320 | ||
321 | static inline struct phy_provider *__of_phy_provider_register( | |
322 | struct device *dev, struct module *owner, struct phy * (*of_xlate)( | |
323 | struct device *dev, struct of_phandle_args *args)) | |
324 | { | |
325 | return ERR_PTR(-ENOSYS); | |
326 | } | |
327 | ||
328 | static inline struct phy_provider *__devm_of_phy_provider_register(struct device | |
329 | *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, | |
330 | struct of_phandle_args *args)) | |
331 | { | |
332 | return ERR_PTR(-ENOSYS); | |
333 | } | |
334 | ||
335 | static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) | |
336 | { | |
337 | } | |
338 | ||
339 | static inline void devm_of_phy_provider_unregister(struct device *dev, | |
340 | struct phy_provider *phy_provider) | |
341 | { | |
342 | } | |
343 | #endif | |
344 | ||
345 | #endif /* __DRIVERS_PHY_H */ |