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
23struct phy;
24
25enum phy_mode {
26 PHY_MODE_INVALID,
27 PHY_MODE_USB_HOST,
28 PHY_MODE_USB_DEVICE,
29 PHY_MODE_USB_OTG,
30};
31
32
33
34
35
36
37
38
39
40
41
42struct phy_ops {
43 int (*init)(struct phy *phy);
44 int (*exit)(struct phy *phy);
45 int (*power_on)(struct phy *phy);
46 int (*power_off)(struct phy *phy);
47 int (*set_mode)(struct phy *phy, enum phy_mode mode);
48 int (*reset)(struct phy *phy);
49 struct module *owner;
50};
51
52
53
54
55
56struct phy_attrs {
57 u32 bus_width;
58};
59
60
61
62
63
64
65
66
67
68
69
70
71struct phy {
72 struct device dev;
73 int id;
74 const struct phy_ops *ops;
75 struct mutex mutex;
76 int init_count;
77 int power_count;
78 struct phy_attrs attrs;
79 struct regulator *pwr;
80};
81
82
83
84
85
86
87
88
89struct phy_provider {
90 struct device *dev;
91 struct device_node *children;
92 struct module *owner;
93 struct list_head list;
94 struct phy * (*of_xlate)(struct device *dev,
95 struct of_phandle_args *args);
96};
97
98struct phy_lookup {
99 struct list_head node;
100 const char *dev_id;
101 const char *con_id;
102 struct phy *phy;
103};
104
105#define to_phy(a) (container_of((a), struct phy, dev))
106
107#define of_phy_provider_register(dev, xlate) \
108 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
109
110#define devm_of_phy_provider_register(dev, xlate) \
111 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
112
113#define of_phy_provider_register_full(dev, children, xlate) \
114 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
115
116#define devm_of_phy_provider_register_full(dev, children, xlate) \
117 __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
118
119static inline void phy_set_drvdata(struct phy *phy, void *data)
120{
121 dev_set_drvdata(&phy->dev, data);
122}
123
124static inline void *phy_get_drvdata(struct phy *phy)
125{
126 return dev_get_drvdata(&phy->dev);
127}
128
129#if IS_ENABLED(CONFIG_GENERIC_PHY)
130int phy_pm_runtime_get(struct phy *phy);
131int phy_pm_runtime_get_sync(struct phy *phy);
132int phy_pm_runtime_put(struct phy *phy);
133int phy_pm_runtime_put_sync(struct phy *phy);
134void phy_pm_runtime_allow(struct phy *phy);
135void phy_pm_runtime_forbid(struct phy *phy);
136int phy_init(struct phy *phy);
137int phy_exit(struct phy *phy);
138int phy_power_on(struct phy *phy);
139int phy_power_off(struct phy *phy);
140int phy_set_mode(struct phy *phy, enum phy_mode mode);
141int phy_reset(struct phy *phy);
142static inline int phy_get_bus_width(struct phy *phy)
143{
144 return phy->attrs.bus_width;
145}
146static inline void phy_set_bus_width(struct phy *phy, int bus_width)
147{
148 phy->attrs.bus_width = bus_width;
149}
150struct phy *phy_get(struct device *dev, const char *string);
151struct phy *phy_optional_get(struct device *dev, const char *string);
152struct phy *devm_phy_get(struct device *dev, const char *string);
153struct phy *devm_phy_optional_get(struct device *dev, const char *string);
154struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
155 const char *con_id);
156struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
157 int index);
158void phy_put(struct phy *phy);
159void devm_phy_put(struct device *dev, struct phy *phy);
160struct phy *of_phy_get(struct device_node *np, const char *con_id);
161struct phy *of_phy_simple_xlate(struct device *dev,
162 struct of_phandle_args *args);
163struct phy *phy_create(struct device *dev, struct device_node *node,
164 const struct phy_ops *ops);
165struct phy *devm_phy_create(struct device *dev, struct device_node *node,
166 const struct phy_ops *ops);
167void phy_destroy(struct phy *phy);
168void devm_phy_destroy(struct device *dev, struct phy *phy);
169struct phy_provider *__of_phy_provider_register(struct device *dev,
170 struct device_node *children, struct module *owner,
171 struct phy * (*of_xlate)(struct device *dev,
172 struct of_phandle_args *args));
173struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
174 struct device_node *children, struct module *owner,
175 struct phy * (*of_xlate)(struct device *dev,
176 struct of_phandle_args *args));
177void of_phy_provider_unregister(struct phy_provider *phy_provider);
178void devm_of_phy_provider_unregister(struct device *dev,
179 struct phy_provider *phy_provider);
180int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
181void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
182#else
183static inline int phy_pm_runtime_get(struct phy *phy)
184{
185 if (!phy)
186 return 0;
187 return -ENOSYS;
188}
189
190static inline int phy_pm_runtime_get_sync(struct phy *phy)
191{
192 if (!phy)
193 return 0;
194 return -ENOSYS;
195}
196
197static inline int phy_pm_runtime_put(struct phy *phy)
198{
199 if (!phy)
200 return 0;
201 return -ENOSYS;
202}
203
204static inline int phy_pm_runtime_put_sync(struct phy *phy)
205{
206 if (!phy)
207 return 0;
208 return -ENOSYS;
209}
210
211static inline void phy_pm_runtime_allow(struct phy *phy)
212{
213 return;
214}
215
216static inline void phy_pm_runtime_forbid(struct phy *phy)
217{
218 return;
219}
220
221static inline int phy_init(struct phy *phy)
222{
223 if (!phy)
224 return 0;
225 return -ENOSYS;
226}
227
228static inline int phy_exit(struct phy *phy)
229{
230 if (!phy)
231 return 0;
232 return -ENOSYS;
233}
234
235static inline int phy_power_on(struct phy *phy)
236{
237 if (!phy)
238 return 0;
239 return -ENOSYS;
240}
241
242static inline int phy_power_off(struct phy *phy)
243{
244 if (!phy)
245 return 0;
246 return -ENOSYS;
247}
248
249static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
250{
251 if (!phy)
252 return 0;
253 return -ENOSYS;
254}
255
256static inline int phy_reset(struct phy *phy)
257{
258 if (!phy)
259 return 0;
260 return -ENOSYS;
261}
262
263static inline int phy_get_bus_width(struct phy *phy)
264{
265 return -ENOSYS;
266}
267
268static inline void phy_set_bus_width(struct phy *phy, int bus_width)
269{
270 return;
271}
272
273static inline struct phy *phy_get(struct device *dev, const char *string)
274{
275 return ERR_PTR(-ENOSYS);
276}
277
278static inline struct phy *phy_optional_get(struct device *dev,
279 const char *string)
280{
281 return ERR_PTR(-ENOSYS);
282}
283
284static inline struct phy *devm_phy_get(struct device *dev, const char *string)
285{
286 return ERR_PTR(-ENOSYS);
287}
288
289static inline struct phy *devm_phy_optional_get(struct device *dev,
290 const char *string)
291{
292 return ERR_PTR(-ENOSYS);
293}
294
295static inline struct phy *devm_of_phy_get(struct device *dev,
296 struct device_node *np,
297 const char *con_id)
298{
299 return ERR_PTR(-ENOSYS);
300}
301
302static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
303 struct device_node *np,
304 int index)
305{
306 return ERR_PTR(-ENOSYS);
307}
308
309static inline void phy_put(struct phy *phy)
310{
311}
312
313static inline void devm_phy_put(struct device *dev, struct phy *phy)
314{
315}
316
317static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
318{
319 return ERR_PTR(-ENOSYS);
320}
321
322static inline struct phy *of_phy_simple_xlate(struct device *dev,
323 struct of_phandle_args *args)
324{
325 return ERR_PTR(-ENOSYS);
326}
327
328static inline struct phy *phy_create(struct device *dev,
329 struct device_node *node,
330 const struct phy_ops *ops)
331{
332 return ERR_PTR(-ENOSYS);
333}
334
335static inline struct phy *devm_phy_create(struct device *dev,
336 struct device_node *node,
337 const struct phy_ops *ops)
338{
339 return ERR_PTR(-ENOSYS);
340}
341
342static inline void phy_destroy(struct phy *phy)
343{
344}
345
346static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
347{
348}
349
350static inline struct phy_provider *__of_phy_provider_register(
351 struct device *dev, struct device_node *children, struct module *owner,
352 struct phy * (*of_xlate)(struct device *dev,
353 struct of_phandle_args *args))
354{
355 return ERR_PTR(-ENOSYS);
356}
357
358static inline struct phy_provider *__devm_of_phy_provider_register(struct device
359 *dev, struct device_node *children, struct module *owner,
360 struct phy * (*of_xlate)(struct device *dev,
361 struct of_phandle_args *args))
362{
363 return ERR_PTR(-ENOSYS);
364}
365
366static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
367{
368}
369
370static inline void devm_of_phy_provider_unregister(struct device *dev,
371 struct phy_provider *phy_provider)
372{
373}
374static inline int
375phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
376{
377 return 0;
378}
379static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
380 const char *dev_id) { }
381#endif
382
383#endif
384