]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/phy/phy.h
wil6210: rate limit wil_rx_refill error
[linux.git] / include / linux / phy / phy.h
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>
21 #include <linux/regulator/consumer.h>
22
23 struct phy;
24
25 enum phy_mode {
26         PHY_MODE_INVALID,
27         PHY_MODE_USB_HOST,
28         PHY_MODE_USB_HOST_LS,
29         PHY_MODE_USB_HOST_FS,
30         PHY_MODE_USB_HOST_HS,
31         PHY_MODE_USB_HOST_SS,
32         PHY_MODE_USB_DEVICE,
33         PHY_MODE_USB_DEVICE_LS,
34         PHY_MODE_USB_DEVICE_FS,
35         PHY_MODE_USB_DEVICE_HS,
36         PHY_MODE_USB_DEVICE_SS,
37         PHY_MODE_USB_OTG,
38         PHY_MODE_SGMII,
39         PHY_MODE_10GKR,
40         PHY_MODE_UFS_HS_A,
41         PHY_MODE_UFS_HS_B,
42 };
43
44 /**
45  * struct phy_ops - set of function pointers for performing phy operations
46  * @init: operation to be performed for initializing phy
47  * @exit: operation to be performed while exiting
48  * @power_on: powering on the phy
49  * @power_off: powering off the phy
50  * @set_mode: set the mode of the phy
51  * @reset: resetting the phy
52  * @calibrate: calibrate the phy
53  * @owner: the module owner containing the ops
54  */
55 struct phy_ops {
56         int     (*init)(struct phy *phy);
57         int     (*exit)(struct phy *phy);
58         int     (*power_on)(struct phy *phy);
59         int     (*power_off)(struct phy *phy);
60         int     (*set_mode)(struct phy *phy, enum phy_mode mode);
61         int     (*reset)(struct phy *phy);
62         int     (*calibrate)(struct phy *phy);
63         struct module *owner;
64 };
65
66 /**
67  * struct phy_attrs - represents phy attributes
68  * @bus_width: Data path width implemented by PHY
69  */
70 struct phy_attrs {
71         u32                     bus_width;
72         enum phy_mode           mode;
73 };
74
75 /**
76  * struct phy - represents the phy device
77  * @dev: phy device
78  * @id: id of the phy device
79  * @ops: function pointers for performing phy operations
80  * @init_data: list of PHY consumers (non-dt only)
81  * @mutex: mutex to protect phy_ops
82  * @init_count: used to protect when the PHY is used by multiple consumers
83  * @power_count: used to protect when the PHY is used by multiple consumers
84  * @attrs: used to specify PHY specific attributes
85  * @pwr: power regulator associated with the phy
86  */
87 struct phy {
88         struct device           dev;
89         int                     id;
90         const struct phy_ops    *ops;
91         struct mutex            mutex;
92         int                     init_count;
93         int                     power_count;
94         struct phy_attrs        attrs;
95         struct regulator        *pwr;
96 };
97
98 /**
99  * struct phy_provider - represents the phy provider
100  * @dev: phy provider device
101  * @children: can be used to override the default (dev->of_node) child node
102  * @owner: the module owner having of_xlate
103  * @list: to maintain a linked list of PHY providers
104  * @of_xlate: function pointer to obtain phy instance from phy pointer
105  */
106 struct phy_provider {
107         struct device           *dev;
108         struct device_node      *children;
109         struct module           *owner;
110         struct list_head        list;
111         struct phy * (*of_xlate)(struct device *dev,
112                 struct of_phandle_args *args);
113 };
114
115 /**
116  * struct phy_lookup - PHY association in list of phys managed by the phy driver
117  * @node: list node
118  * @dev_id: the device of the association
119  * @con_id: connection ID string on device
120  * @phy: the phy of the association
121  */
122 struct phy_lookup {
123         struct list_head node;
124         const char *dev_id;
125         const char *con_id;
126         struct phy *phy;
127 };
128
129 #define to_phy(a)       (container_of((a), struct phy, dev))
130
131 #define of_phy_provider_register(dev, xlate)    \
132         __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
133
134 #define devm_of_phy_provider_register(dev, xlate)       \
135         __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
136
137 #define of_phy_provider_register_full(dev, children, xlate) \
138         __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
139
140 #define devm_of_phy_provider_register_full(dev, children, xlate) \
141         __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
142
143 static inline void phy_set_drvdata(struct phy *phy, void *data)
144 {
145         dev_set_drvdata(&phy->dev, data);
146 }
147
148 static inline void *phy_get_drvdata(struct phy *phy)
149 {
150         return dev_get_drvdata(&phy->dev);
151 }
152
153 #if IS_ENABLED(CONFIG_GENERIC_PHY)
154 int phy_pm_runtime_get(struct phy *phy);
155 int phy_pm_runtime_get_sync(struct phy *phy);
156 int phy_pm_runtime_put(struct phy *phy);
157 int phy_pm_runtime_put_sync(struct phy *phy);
158 void phy_pm_runtime_allow(struct phy *phy);
159 void phy_pm_runtime_forbid(struct phy *phy);
160 int phy_init(struct phy *phy);
161 int phy_exit(struct phy *phy);
162 int phy_power_on(struct phy *phy);
163 int phy_power_off(struct phy *phy);
164 int phy_set_mode(struct phy *phy, enum phy_mode mode);
165 static inline enum phy_mode phy_get_mode(struct phy *phy)
166 {
167         return phy->attrs.mode;
168 }
169 int phy_reset(struct phy *phy);
170 int phy_calibrate(struct phy *phy);
171 static inline int phy_get_bus_width(struct phy *phy)
172 {
173         return phy->attrs.bus_width;
174 }
175 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
176 {
177         phy->attrs.bus_width = bus_width;
178 }
179 struct phy *phy_get(struct device *dev, const char *string);
180 struct phy *phy_optional_get(struct device *dev, const char *string);
181 struct phy *devm_phy_get(struct device *dev, const char *string);
182 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
183 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
184                             const char *con_id);
185 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
186                                      int index);
187 void phy_put(struct phy *phy);
188 void devm_phy_put(struct device *dev, struct phy *phy);
189 struct phy *of_phy_get(struct device_node *np, const char *con_id);
190 struct phy *of_phy_simple_xlate(struct device *dev,
191         struct of_phandle_args *args);
192 struct phy *phy_create(struct device *dev, struct device_node *node,
193                        const struct phy_ops *ops);
194 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
195                             const struct phy_ops *ops);
196 void phy_destroy(struct phy *phy);
197 void devm_phy_destroy(struct device *dev, struct phy *phy);
198 struct phy_provider *__of_phy_provider_register(struct device *dev,
199         struct device_node *children, struct module *owner,
200         struct phy * (*of_xlate)(struct device *dev,
201                                  struct of_phandle_args *args));
202 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
203         struct device_node *children, struct module *owner,
204         struct phy * (*of_xlate)(struct device *dev,
205                                  struct of_phandle_args *args));
206 void of_phy_provider_unregister(struct phy_provider *phy_provider);
207 void devm_of_phy_provider_unregister(struct device *dev,
208         struct phy_provider *phy_provider);
209 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
210 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
211 #else
212 static inline int phy_pm_runtime_get(struct phy *phy)
213 {
214         if (!phy)
215                 return 0;
216         return -ENOSYS;
217 }
218
219 static inline int phy_pm_runtime_get_sync(struct phy *phy)
220 {
221         if (!phy)
222                 return 0;
223         return -ENOSYS;
224 }
225
226 static inline int phy_pm_runtime_put(struct phy *phy)
227 {
228         if (!phy)
229                 return 0;
230         return -ENOSYS;
231 }
232
233 static inline int phy_pm_runtime_put_sync(struct phy *phy)
234 {
235         if (!phy)
236                 return 0;
237         return -ENOSYS;
238 }
239
240 static inline void phy_pm_runtime_allow(struct phy *phy)
241 {
242         return;
243 }
244
245 static inline void phy_pm_runtime_forbid(struct phy *phy)
246 {
247         return;
248 }
249
250 static inline int phy_init(struct phy *phy)
251 {
252         if (!phy)
253                 return 0;
254         return -ENOSYS;
255 }
256
257 static inline int phy_exit(struct phy *phy)
258 {
259         if (!phy)
260                 return 0;
261         return -ENOSYS;
262 }
263
264 static inline int phy_power_on(struct phy *phy)
265 {
266         if (!phy)
267                 return 0;
268         return -ENOSYS;
269 }
270
271 static inline int phy_power_off(struct phy *phy)
272 {
273         if (!phy)
274                 return 0;
275         return -ENOSYS;
276 }
277
278 static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
279 {
280         if (!phy)
281                 return 0;
282         return -ENOSYS;
283 }
284
285 static inline enum phy_mode phy_get_mode(struct phy *phy)
286 {
287         return PHY_MODE_INVALID;
288 }
289
290 static inline int phy_reset(struct phy *phy)
291 {
292         if (!phy)
293                 return 0;
294         return -ENOSYS;
295 }
296
297 static inline int phy_calibrate(struct phy *phy)
298 {
299         if (!phy)
300                 return 0;
301         return -ENOSYS;
302 }
303
304 static inline int phy_get_bus_width(struct phy *phy)
305 {
306         return -ENOSYS;
307 }
308
309 static inline void phy_set_bus_width(struct phy *phy, int bus_width)
310 {
311         return;
312 }
313
314 static inline struct phy *phy_get(struct device *dev, const char *string)
315 {
316         return ERR_PTR(-ENOSYS);
317 }
318
319 static inline struct phy *phy_optional_get(struct device *dev,
320                                            const char *string)
321 {
322         return ERR_PTR(-ENOSYS);
323 }
324
325 static inline struct phy *devm_phy_get(struct device *dev, const char *string)
326 {
327         return ERR_PTR(-ENOSYS);
328 }
329
330 static inline struct phy *devm_phy_optional_get(struct device *dev,
331                                                 const char *string)
332 {
333         return NULL;
334 }
335
336 static inline struct phy *devm_of_phy_get(struct device *dev,
337                                           struct device_node *np,
338                                           const char *con_id)
339 {
340         return ERR_PTR(-ENOSYS);
341 }
342
343 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
344                                                    struct device_node *np,
345                                                    int index)
346 {
347         return ERR_PTR(-ENOSYS);
348 }
349
350 static inline void phy_put(struct phy *phy)
351 {
352 }
353
354 static inline void devm_phy_put(struct device *dev, struct phy *phy)
355 {
356 }
357
358 static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
359 {
360         return ERR_PTR(-ENOSYS);
361 }
362
363 static inline struct phy *of_phy_simple_xlate(struct device *dev,
364         struct of_phandle_args *args)
365 {
366         return ERR_PTR(-ENOSYS);
367 }
368
369 static inline struct phy *phy_create(struct device *dev,
370                                      struct device_node *node,
371                                      const struct phy_ops *ops)
372 {
373         return ERR_PTR(-ENOSYS);
374 }
375
376 static inline struct phy *devm_phy_create(struct device *dev,
377                                           struct device_node *node,
378                                           const struct phy_ops *ops)
379 {
380         return ERR_PTR(-ENOSYS);
381 }
382
383 static inline void phy_destroy(struct phy *phy)
384 {
385 }
386
387 static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
388 {
389 }
390
391 static inline struct phy_provider *__of_phy_provider_register(
392         struct device *dev, struct device_node *children, struct module *owner,
393         struct phy * (*of_xlate)(struct device *dev,
394                                  struct of_phandle_args *args))
395 {
396         return ERR_PTR(-ENOSYS);
397 }
398
399 static inline struct phy_provider *__devm_of_phy_provider_register(struct device
400         *dev, struct device_node *children, struct module *owner,
401         struct phy * (*of_xlate)(struct device *dev,
402                                  struct of_phandle_args *args))
403 {
404         return ERR_PTR(-ENOSYS);
405 }
406
407 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
408 {
409 }
410
411 static inline void devm_of_phy_provider_unregister(struct device *dev,
412         struct phy_provider *phy_provider)
413 {
414 }
415 static inline int
416 phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
417 {
418         return 0;
419 }
420 static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
421                                      const char *dev_id) { }
422 #endif
423
424 #endif /* __DRIVERS_PHY_H */