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 | ||
300eb013 DL |
25 | enum phy_mode { |
26 | PHY_MODE_INVALID, | |
27 | PHY_MODE_USB_HOST, | |
28 | PHY_MODE_USB_DEVICE, | |
29 | PHY_MODE_USB_OTG, | |
30 | }; | |
31 | ||
ff764963 KVA |
32 | /** |
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 | |
300eb013 | 38 | * @set_mode: set the mode of the phy |
ff764963 KVA |
39 | * @owner: the module owner containing the ops |
40 | */ | |
41 | struct phy_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); | |
300eb013 | 46 | int (*set_mode)(struct phy *phy, enum phy_mode mode); |
ff764963 KVA |
47 | struct module *owner; |
48 | }; | |
49 | ||
8feed347 MP |
50 | /** |
51 | * struct phy_attrs - represents phy attributes | |
52 | * @bus_width: Data path width implemented by PHY | |
53 | */ | |
54 | struct phy_attrs { | |
55 | u32 bus_width; | |
56 | }; | |
57 | ||
ff764963 KVA |
58 | /** |
59 | * struct phy - represents the phy device | |
60 | * @dev: 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 | |
8feed347 | 67 | * @phy_attrs: used to specify PHY specific attributes |
ff764963 KVA |
68 | */ |
69 | struct phy { | |
70 | struct device dev; | |
71 | int id; | |
72 | const struct phy_ops *ops; | |
ff764963 KVA |
73 | struct mutex mutex; |
74 | int init_count; | |
75 | int power_count; | |
8feed347 | 76 | struct phy_attrs attrs; |
3be88125 | 77 | struct regulator *pwr; |
ff764963 KVA |
78 | }; |
79 | ||
80 | /** | |
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 | |
86 | */ | |
87 | struct phy_provider { | |
88 | struct device *dev; | |
1140f7c8 | 89 | struct device_node *children; |
ff764963 KVA |
90 | struct module *owner; |
91 | struct list_head list; | |
92 | struct phy * (*of_xlate)(struct device *dev, | |
93 | struct of_phandle_args *args); | |
94 | }; | |
95 | ||
b7bc15b9 HK |
96 | struct phy_lookup { |
97 | struct list_head node; | |
98 | const char *dev_id; | |
99 | const char *con_id; | |
100 | struct phy *phy; | |
101 | }; | |
102 | ||
d4510574 | 103 | #define to_phy(a) (container_of((a), struct phy, dev)) |
ff764963 KVA |
104 | |
105 | #define of_phy_provider_register(dev, xlate) \ | |
1140f7c8 | 106 | __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) |
ff764963 KVA |
107 | |
108 | #define devm_of_phy_provider_register(dev, xlate) \ | |
1140f7c8 TR |
109 | __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) |
110 | ||
111 | #define of_phy_provider_register_full(dev, children, xlate) \ | |
112 | __of_phy_provider_register(dev, children, THIS_MODULE, xlate) | |
113 | ||
114 | #define devm_of_phy_provider_register_full(dev, children, xlate) \ | |
115 | __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate) | |
ff764963 KVA |
116 | |
117 | static inline void phy_set_drvdata(struct phy *phy, void *data) | |
118 | { | |
119 | dev_set_drvdata(&phy->dev, data); | |
120 | } | |
121 | ||
122 | static inline void *phy_get_drvdata(struct phy *phy) | |
123 | { | |
124 | return dev_get_drvdata(&phy->dev); | |
125 | } | |
126 | ||
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); | |
300eb013 | 138 | int phy_set_mode(struct phy *phy, enum phy_mode mode); |
8feed347 MP |
139 | static inline int phy_get_bus_width(struct phy *phy) |
140 | { | |
141 | return phy->attrs.bus_width; | |
142 | } | |
143 | static inline void phy_set_bus_width(struct phy *phy, int bus_width) | |
144 | { | |
145 | phy->attrs.bus_width = bus_width; | |
146 | } | |
ff764963 | 147 | struct phy *phy_get(struct device *dev, const char *string); |
788a4d56 | 148 | struct phy *phy_optional_get(struct device *dev, const char *string); |
ff764963 | 149 | struct phy *devm_phy_get(struct device *dev, const char *string); |
788a4d56 | 150 | struct phy *devm_phy_optional_get(struct device *dev, const char *string); |
b5d682f4 KD |
151 | struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, |
152 | const char *con_id); | |
6be109b3 AR |
153 | struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, |
154 | int index); | |
ff764963 KVA |
155 | void phy_put(struct phy *phy); |
156 | void devm_phy_put(struct device *dev, struct phy *phy); | |
0b3f3b2c | 157 | struct phy *of_phy_get(struct device_node *np, const char *con_id); |
ff764963 KVA |
158 | struct phy *of_phy_simple_xlate(struct device *dev, |
159 | struct of_phandle_args *args); | |
f0ed8176 | 160 | struct phy *phy_create(struct device *dev, struct device_node *node, |
dbc98635 | 161 | const struct phy_ops *ops); |
f0ed8176 | 162 | struct phy *devm_phy_create(struct device *dev, struct device_node *node, |
dbc98635 | 163 | const struct phy_ops *ops); |
ff764963 KVA |
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, | |
1140f7c8 TR |
167 | struct device_node *children, struct module *owner, |
168 | struct phy * (*of_xlate)(struct device *dev, | |
169 | struct of_phandle_args *args)); | |
ff764963 | 170 | struct phy_provider *__devm_of_phy_provider_register(struct device *dev, |
1140f7c8 TR |
171 | struct device_node *children, struct module *owner, |
172 | struct phy * (*of_xlate)(struct device *dev, | |
173 | struct of_phandle_args *args)); | |
ff764963 KVA |
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); | |
b7bc15b9 HK |
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); | |
ff764963 KVA |
179 | #else |
180 | static inline int phy_pm_runtime_get(struct phy *phy) | |
181 | { | |
2b97789f GS |
182 | if (!phy) |
183 | return 0; | |
ff764963 KVA |
184 | return -ENOSYS; |
185 | } | |
186 | ||
187 | static inline int phy_pm_runtime_get_sync(struct phy *phy) | |
188 | { | |
2b97789f GS |
189 | if (!phy) |
190 | return 0; | |
ff764963 KVA |
191 | return -ENOSYS; |
192 | } | |
193 | ||
194 | static inline int phy_pm_runtime_put(struct phy *phy) | |
195 | { | |
2b97789f GS |
196 | if (!phy) |
197 | return 0; | |
ff764963 KVA |
198 | return -ENOSYS; |
199 | } | |
200 | ||
201 | static inline int phy_pm_runtime_put_sync(struct phy *phy) | |
202 | { | |
2b97789f GS |
203 | if (!phy) |
204 | return 0; | |
ff764963 KVA |
205 | return -ENOSYS; |
206 | } | |
207 | ||
208 | static inline void phy_pm_runtime_allow(struct phy *phy) | |
209 | { | |
210 | return; | |
211 | } | |
212 | ||
213 | static inline void phy_pm_runtime_forbid(struct phy *phy) | |
214 | { | |
215 | return; | |
216 | } | |
217 | ||
218 | static inline int phy_init(struct phy *phy) | |
219 | { | |
2b97789f GS |
220 | if (!phy) |
221 | return 0; | |
ff764963 KVA |
222 | return -ENOSYS; |
223 | } | |
224 | ||
225 | static inline int phy_exit(struct phy *phy) | |
226 | { | |
2b97789f GS |
227 | if (!phy) |
228 | return 0; | |
ff764963 KVA |
229 | return -ENOSYS; |
230 | } | |
231 | ||
232 | static inline int phy_power_on(struct phy *phy) | |
233 | { | |
2b97789f GS |
234 | if (!phy) |
235 | return 0; | |
ff764963 KVA |
236 | return -ENOSYS; |
237 | } | |
238 | ||
239 | static inline int phy_power_off(struct phy *phy) | |
240 | { | |
2b97789f GS |
241 | if (!phy) |
242 | return 0; | |
ff764963 KVA |
243 | return -ENOSYS; |
244 | } | |
245 | ||
300eb013 DL |
246 | static inline int phy_set_mode(struct phy *phy, enum phy_mode mode) |
247 | { | |
248 | if (!phy) | |
249 | return 0; | |
250 | return -ENOSYS; | |
251 | } | |
252 | ||
8feed347 MP |
253 | static inline int phy_get_bus_width(struct phy *phy) |
254 | { | |
255 | return -ENOSYS; | |
256 | } | |
257 | ||
258 | static inline void phy_set_bus_width(struct phy *phy, int bus_width) | |
259 | { | |
260 | return; | |
261 | } | |
262 | ||
ff764963 KVA |
263 | static inline struct phy *phy_get(struct device *dev, const char *string) |
264 | { | |
265 | return ERR_PTR(-ENOSYS); | |
266 | } | |
267 | ||
788a4d56 AL |
268 | static inline struct phy *phy_optional_get(struct device *dev, |
269 | const char *string) | |
270 | { | |
271 | return ERR_PTR(-ENOSYS); | |
272 | } | |
273 | ||
ff764963 KVA |
274 | static inline struct phy *devm_phy_get(struct device *dev, const char *string) |
275 | { | |
276 | return ERR_PTR(-ENOSYS); | |
277 | } | |
278 | ||
788a4d56 AL |
279 | static inline struct phy *devm_phy_optional_get(struct device *dev, |
280 | const char *string) | |
281 | { | |
282 | return ERR_PTR(-ENOSYS); | |
283 | } | |
284 | ||
b5d682f4 KD |
285 | static inline struct phy *devm_of_phy_get(struct device *dev, |
286 | struct device_node *np, | |
287 | const char *con_id) | |
288 | { | |
289 | return ERR_PTR(-ENOSYS); | |
290 | } | |
291 | ||
6be109b3 AR |
292 | static inline struct phy *devm_of_phy_get_by_index(struct device *dev, |
293 | struct device_node *np, | |
294 | int index) | |
295 | { | |
296 | return ERR_PTR(-ENOSYS); | |
297 | } | |
298 | ||
ff764963 KVA |
299 | static inline void phy_put(struct phy *phy) |
300 | { | |
301 | } | |
302 | ||
303 | static inline void devm_phy_put(struct device *dev, struct phy *phy) | |
304 | { | |
305 | } | |
306 | ||
0b3f3b2c KD |
307 | static inline struct phy *of_phy_get(struct device_node *np, const char *con_id) |
308 | { | |
309 | return ERR_PTR(-ENOSYS); | |
310 | } | |
311 | ||
ff764963 KVA |
312 | static inline struct phy *of_phy_simple_xlate(struct device *dev, |
313 | struct of_phandle_args *args) | |
314 | { | |
315 | return ERR_PTR(-ENOSYS); | |
316 | } | |
317 | ||
318 | static inline struct phy *phy_create(struct device *dev, | |
f0ed8176 | 319 | struct device_node *node, |
dbc98635 | 320 | const struct phy_ops *ops) |
ff764963 KVA |
321 | { |
322 | return ERR_PTR(-ENOSYS); | |
323 | } | |
324 | ||
325 | static inline struct phy *devm_phy_create(struct device *dev, | |
f0ed8176 | 326 | struct device_node *node, |
dbc98635 | 327 | const struct phy_ops *ops) |
ff764963 KVA |
328 | { |
329 | return ERR_PTR(-ENOSYS); | |
330 | } | |
331 | ||
332 | static inline void phy_destroy(struct phy *phy) | |
333 | { | |
334 | } | |
335 | ||
336 | static inline void devm_phy_destroy(struct device *dev, struct phy *phy) | |
337 | { | |
338 | } | |
339 | ||
340 | static inline struct phy_provider *__of_phy_provider_register( | |
1140f7c8 TR |
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)) | |
ff764963 KVA |
344 | { |
345 | return ERR_PTR(-ENOSYS); | |
346 | } | |
347 | ||
348 | static inline struct phy_provider *__devm_of_phy_provider_register(struct device | |
1140f7c8 TR |
349 | *dev, struct device_node *children, struct module *owner, |
350 | struct phy * (*of_xlate)(struct device *dev, | |
351 | struct of_phandle_args *args)) | |
ff764963 KVA |
352 | { |
353 | return ERR_PTR(-ENOSYS); | |
354 | } | |
355 | ||
356 | static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) | |
357 | { | |
358 | } | |
359 | ||
360 | static inline void devm_of_phy_provider_unregister(struct device *dev, | |
361 | struct phy_provider *phy_provider) | |
362 | { | |
363 | } | |
b7bc15b9 HK |
364 | static inline int |
365 | phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) | |
366 | { | |
367 | return 0; | |
368 | } | |
369 | static inline void phy_remove_lookup(struct phy *phy, const char *con_id, | |
370 | const char *dev_id) { } | |
ff764963 KVA |
371 | #endif |
372 | ||
373 | #endif /* __DRIVERS_PHY_H */ |