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