1
2
3
4
5
6
7
8
9
10#ifndef __DRIVERS_PHY_H
11#define __DRIVERS_PHY_H
12
13#include <linux/err.h>
14#include <linux/of.h>
15#include <linux/device.h>
16#include <linux/pm_runtime.h>
17#include <linux/regulator/consumer.h>
18
19#include <linux/phy/phy-mipi-dphy.h>
20
21struct phy;
22
23enum phy_mode {
24 PHY_MODE_INVALID,
25 PHY_MODE_USB_HOST,
26 PHY_MODE_USB_HOST_LS,
27 PHY_MODE_USB_HOST_FS,
28 PHY_MODE_USB_HOST_HS,
29 PHY_MODE_USB_HOST_SS,
30 PHY_MODE_USB_DEVICE,
31 PHY_MODE_USB_DEVICE_LS,
32 PHY_MODE_USB_DEVICE_FS,
33 PHY_MODE_USB_DEVICE_HS,
34 PHY_MODE_USB_DEVICE_SS,
35 PHY_MODE_USB_OTG,
36 PHY_MODE_UFS_HS_A,
37 PHY_MODE_UFS_HS_B,
38 PHY_MODE_PCIE,
39 PHY_MODE_ETHERNET,
40 PHY_MODE_MIPI_DPHY,
41 PHY_MODE_SATA
42};
43
44
45
46
47
48
49
50union phy_configure_opts {
51 struct phy_configure_opts_mipi_dphy mipi_dphy;
52};
53
54
55
56
57
58
59
60
61
62
63
64
65
66struct phy_ops {
67 int (*init)(struct phy *phy);
68 int (*exit)(struct phy *phy);
69 int (*power_on)(struct phy *phy);
70 int (*power_off)(struct phy *phy);
71 int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
72
73
74
75
76
77
78
79
80
81
82
83 int (*configure)(struct phy *phy, union phy_configure_opts *opts);
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 int (*validate)(struct phy *phy, enum phy_mode mode, int submode,
102 union phy_configure_opts *opts);
103 int (*reset)(struct phy *phy);
104 int (*calibrate)(struct phy *phy);
105 void (*release)(struct phy *phy);
106 struct module *owner;
107};
108
109
110
111
112
113
114struct phy_attrs {
115 u32 bus_width;
116 enum phy_mode mode;
117};
118
119
120
121
122
123
124
125
126
127
128
129
130struct phy {
131 struct device dev;
132 int id;
133 const struct phy_ops *ops;
134 struct mutex mutex;
135 int init_count;
136 int power_count;
137 struct phy_attrs attrs;
138 struct regulator *pwr;
139};
140
141
142
143
144
145
146
147
148
149struct phy_provider {
150 struct device *dev;
151 struct device_node *children;
152 struct module *owner;
153 struct list_head list;
154 struct phy * (*of_xlate)(struct device *dev,
155 struct of_phandle_args *args);
156};
157
158
159
160
161
162
163
164
165struct phy_lookup {
166 struct list_head node;
167 const char *dev_id;
168 const char *con_id;
169 struct phy *phy;
170};
171
172#define to_phy(a) (container_of((a), struct phy, dev))
173
174#define of_phy_provider_register(dev, xlate) \
175 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
176
177#define devm_of_phy_provider_register(dev, xlate) \
178 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
179
180#define of_phy_provider_register_full(dev, children, xlate) \
181 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
182
183#define devm_of_phy_provider_register_full(dev, children, xlate) \
184 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
185
186static inline void phy_set_drvdata(struct phy *phy, void *data)
187{
188 dev_set_drvdata(&phy->dev, data);
189}
190
191static inline void *phy_get_drvdata(struct phy *phy)
192{
193 return dev_get_drvdata(&phy->dev);
194}
195
196#if IS_ENABLED(CONFIG_GENERIC_PHY)
197int phy_pm_runtime_get(struct phy *phy);
198int phy_pm_runtime_get_sync(struct phy *phy);
199int phy_pm_runtime_put(struct phy *phy);
200int phy_pm_runtime_put_sync(struct phy *phy);
201void phy_pm_runtime_allow(struct phy *phy);
202void phy_pm_runtime_forbid(struct phy *phy);
203int phy_init(struct phy *phy);
204int phy_exit(struct phy *phy);
205int phy_power_on(struct phy *phy);
206int phy_power_off(struct phy *phy);
207int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
208#define phy_set_mode(phy, mode) \
209 phy_set_mode_ext(phy, mode, 0)
210int phy_configure(struct phy *phy, union phy_configure_opts *opts);
211int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
212 union phy_configure_opts *opts);
213
214static inline enum phy_mode phy_get_mode(struct phy *phy)
215{
216 return phy->attrs.mode;
217}
218int phy_reset(struct phy *phy);
219int phy_calibrate(struct phy *phy);
220static inline int phy_get_bus_width(struct phy *phy)
221{
222 return phy->attrs.bus_width;
223}
224static inline void phy_set_bus_width(struct phy *phy, int bus_width)
225{
226 phy->attrs.bus_width = bus_width;
227}
228struct phy *phy_get(struct device *dev, const char *string);
229struct phy *phy_optional_get(struct device *dev, const char *string);
230struct phy *devm_phy_get(struct device *dev, const char *string);
231struct phy *devm_phy_optional_get(struct device *dev, const char *string);
232struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
233 const char *con_id);
234struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
235 int index);
236void phy_put(struct phy *phy);
237void devm_phy_put(struct device *dev, struct phy *phy);
238struct phy *of_phy_get(struct device_node *np, const char *con_id);
239struct phy *of_phy_simple_xlate(struct device *dev,
240 struct of_phandle_args *args);
241struct phy *phy_create(struct device *dev, struct device_node *node,
242 const struct phy_ops *ops);
243struct phy *devm_phy_create(struct device *dev, struct device_node *node,
244 const struct phy_ops *ops);
245void phy_destroy(struct phy *phy);
246void devm_phy_destroy(struct device *dev, struct phy *phy);
247struct phy_provider *__of_phy_provider_register(struct device *dev,
248 struct device_node *children, struct module *owner,
249 struct phy * (*of_xlate)(struct device *dev,
250 struct of_phandle_args *args));
251struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
252 struct device_node *children, struct module *owner,
253 struct phy * (*of_xlate)(struct device *dev,
254 struct of_phandle_args *args));
255void of_phy_provider_unregister(struct phy_provider *phy_provider);
256void devm_of_phy_provider_unregister(struct device *dev,
257 struct phy_provider *phy_provider);
258int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
259void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
260#else
261static inline int phy_pm_runtime_get(struct phy *phy)
262{
263 if (!phy)
264 return 0;
265 return -ENOSYS;
266}
267
268static inline int phy_pm_runtime_get_sync(struct phy *phy)
269{
270 if (!phy)
271 return 0;
272 return -ENOSYS;
273}
274
275static inline int phy_pm_runtime_put(struct phy *phy)
276{
277 if (!phy)
278 return 0;
279 return -ENOSYS;
280}
281
282static inline int phy_pm_runtime_put_sync(struct phy *phy)
283{
284 if (!phy)
285 return 0;
286 return -ENOSYS;
287}
288
289static inline void phy_pm_runtime_allow(struct phy *phy)
290{
291 return;
292}
293
294static inline void phy_pm_runtime_forbid(struct phy *phy)
295{
296 return;
297}
298
299static inline int phy_init(struct phy *phy)
300{
301 if (!phy)
302 return 0;
303 return -ENOSYS;
304}
305
306static inline int phy_exit(struct phy *phy)
307{
308 if (!phy)
309 return 0;
310 return -ENOSYS;
311}
312
313static inline int phy_power_on(struct phy *phy)
314{
315 if (!phy)
316 return 0;
317 return -ENOSYS;
318}
319
320static inline int phy_power_off(struct phy *phy)
321{
322 if (!phy)
323 return 0;
324 return -ENOSYS;
325}
326
327static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
328 int submode)
329{
330 if (!phy)
331 return 0;
332 return -ENOSYS;
333}
334
335#define phy_set_mode(phy, mode) \
336 phy_set_mode_ext(phy, mode, 0)
337
338static inline enum phy_mode phy_get_mode(struct phy *phy)
339{
340 return PHY_MODE_INVALID;
341}
342
343static inline int phy_reset(struct phy *phy)
344{
345 if (!phy)
346 return 0;
347 return -ENOSYS;
348}
349
350static inline int phy_calibrate(struct phy *phy)
351{
352 if (!phy)
353 return 0;
354 return -ENOSYS;
355}
356
357static inline int phy_configure(struct phy *phy,
358 union phy_configure_opts *opts)
359{
360 if (!phy)
361 return 0;
362
363 return -ENOSYS;
364}
365
366static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
367 union phy_configure_opts *opts)
368{
369 if (!phy)
370 return 0;
371
372 return -ENOSYS;
373}
374
375static inline int phy_get_bus_width(struct phy *phy)
376{
377 return -ENOSYS;
378}
379
380static inline void phy_set_bus_width(struct phy *phy, int bus_width)
381{
382 return;
383}
384
385static inline struct phy *phy_get(struct device *dev, const char *string)
386{
387 return ERR_PTR(-ENOSYS);
388}
389
390static inline struct phy *phy_optional_get(struct device *dev,
391 const char *string)
392{
393 return ERR_PTR(-ENOSYS);
394}
395
396static inline struct phy *devm_phy_get(struct device *dev, const char *string)
397{
398 return ERR_PTR(-ENOSYS);
399}
400
401static inline struct phy *devm_phy_optional_get(struct device *dev,
402 const char *string)
403{
404 return NULL;
405}
406
407static inline struct phy *devm_of_phy_get(struct device *dev,
408 struct device_node *np,
409 const char *con_id)
410{
411 return ERR_PTR(-ENOSYS);
412}
413
414static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
415 struct device_node *np,
416 int index)
417{
418 return ERR_PTR(-ENOSYS);
419}
420
421static inline void phy_put(struct phy *phy)
422{
423}
424
425static inline void devm_phy_put(struct device *dev, struct phy *phy)
426{
427}
428
429static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
430{
431 return ERR_PTR(-ENOSYS);
432}
433
434static inline struct phy *of_phy_simple_xlate(struct device *dev,
435 struct of_phandle_args *args)
436{
437 return ERR_PTR(-ENOSYS);
438}
439
440static inline struct phy *phy_create(struct device *dev,
441 struct device_node *node,
442 const struct phy_ops *ops)
443{
444 return ERR_PTR(-ENOSYS);
445}
446
447static inline struct phy *devm_phy_create(struct device *dev,
448 struct device_node *node,
449 const struct phy_ops *ops)
450{
451 return ERR_PTR(-ENOSYS);
452}
453
454static inline void phy_destroy(struct phy *phy)
455{
456}
457
458static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
459{
460}
461
462static inline struct phy_provider *__of_phy_provider_register(
463 struct device *dev, struct device_node *children, struct module *owner,
464 struct phy * (*of_xlate)(struct device *dev,
465 struct of_phandle_args *args))
466{
467 return ERR_PTR(-ENOSYS);
468}
469
470static inline struct phy_provider *__devm_of_phy_provider_register(struct device
471 *dev, struct device_node *children, struct module *owner,
472 struct phy * (*of_xlate)(struct device *dev,
473 struct of_phandle_args *args))
474{
475 return ERR_PTR(-ENOSYS);
476}
477
478static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
479{
480}
481
482static inline void devm_of_phy_provider_unregister(struct device *dev,
483 struct phy_provider *phy_provider)
484{
485}
486static inline int
487phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
488{
489 return 0;
490}
491static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
492 const char *dev_id) { }
493#endif
494
495#endif
496