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